[FFmpeg-devel] [PATCH] FLAC parser

Michael Niedermayer michaelni
Thu Oct 14 22:25:59 CEST 2010


On Wed, Oct 13, 2010 at 02:26:13AM +0200, Michael Chinen wrote:
[...]
> +static void update_sequences_header(FLACParseContext *fpc,
> +                                    FLACHeaderMarker *mid,
> +                                    FLACHeaderMarker *end, int distance)
> +{
> +    FLACHeaderMarker *child = mid;
> +    int dist_from_start = 0;
> +    uint8_t *buf;
> +    /* CRC verify the children first to find out where they connect to */
> +    if (!mid->next)
> +        return;
> +    update_sequences_header(fpc, mid->next, end, distance - 1);
> +
> +    for (child = mid->next; end != child; child = child->next) {
> +        /* If mid is CRC verified to a child verified to end then mid is
> +           verified till end.  Also if mid is not verified to a child
> +           that is verified to the end then mid will fail the CRC check. */
> +        if (child->crc_valid & 1 << (distance - dist_from_start)) {
> +            if (mid->crc_valid & 1 << dist_from_start)
> +                mid->crc_valid |= 1 << distance;
> +            return;
> +        }
> +        dist_from_start++;
> +    }
> +

> +    /* Set a bit showing the validity at this distance if CRC is ok.
> +       (distance variable is really one less than linked list distance) */
> +    buf = flac_fifo_read(fpc, mid->offset, end->offset - mid->offset,
> +                         &fpc->crc_buf, &fpc->crc_buf_allocated_size);
> +    if (!av_crc(av_crc_get_table(AV_CRC_16_ANSI), 0,
> +                buf, end->offset - mid->offset)) {

crc calculation does not need a "flat" buffer, the memcpy this includes and
code complexity is unneeded


    
> +        mid->crc_valid |= 1 << distance;
> +    } else {
> +        av_log(fpc->avctx, AV_LOG_DEBUG,
> +               "update_sequence CRC failed at dist %i from %i to %i\n",
> +               distance, mid->offset, end->offset);
> +    }
> +}
> +
> +static void update_sequences(FLACParseContext *fpc, int start_index,
> +                             int start_distance, FLACHeaderMarker *end)
> +{
> +    FLACHeaderMarker *mid = fpc->headers;
> +
> +    while (start_index-- > 0)
> +        mid = mid->next;
> +
> +    update_sequences_header(fpc, mid, end, start_distance - 1);
> +}
> +

> +static int find_new_headers(FLACParseContext *fpc, int search_start)
> +{
> +    FLACFrameInfo fi;
> +    FLACHeaderMarker *end;
> +    int i, search_end, end_offset = -1, size = 0;
> +    uint8_t *buf;
> +    fpc->nb_headers_found = 0;
> +
> +    /* Search for a new header of at most 16 bytes. */
> +    search_end = av_fifo_size(fpc->fifo_buf) - (MAX_FRAME_HEADER_SIZE - 1);
> +    buf = flac_fifo_read(fpc, search_start,
> +                         search_end + (MAX_FRAME_HEADER_SIZE - 1) - search_start,
> +                         &fpc->wrap_buf, &fpc->wrap_buf_allocated_size);
> +    for (i = 0; i < search_end - search_start; i++) {
> +        if ((AV_RB16(buf + i) & 0xFFFE) == 0xFFF8 &&

This code does not need a flat buffer.
only frame_header_is_valid needs a max of 16 bytes flat buffer

also parser+decoder->pcm should be benchmarked against the current SVN


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Frequently ignored awnser#1 FFmpeg bugs should be sent to our bugtracker. User
questions about the command line tools should be sent to the ffmpeg-user ML.
And questions about how to use libav* should be sent to the libav-user ML.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20101014/3cd5abee/attachment.pgp>



More information about the ffmpeg-devel mailing list