[FFmpeg-devel] [PATCH] LATM Bitstream Filter & Parser

Paul Kendall paul
Fri May 29 01:51:29 CEST 2009


On Thursday 28 May 2009 08:52:44 pm Peter Holik wrote:
> > On Tuesday 26 May 2009 07:52:36 pm Paul Kendall wrote:
> >> On Tuesday 26 May 2009 07:30:30 pm Reimar D?ffinger wrote:
> >> > On Tue, May 26, 2009 at 06:51:30PM +1200, Paul Kendall wrote:
> >> > > > > +    /* parser only codecs */
> >> > > >
> >> > > > parser-only
> >> > >
> >> > > Yes, the comment relates to the other patch I mentioned about
> >> > > separate parser selection.
> >> >
> >> > You misunderstood, you need a "-" between parser and only, I think
> >> > otherwise the statement does not make sense.
> >>
> >> Sorry, have added the dash.
> >
> > Latest patch included, I also also changed the parser to that when it
> > returns packets it sets the codec_id to CODEC_ID_AAC, which means that
> > the AAC codec is used.
>
> Please help me to understand:
>
> latm_find_frame_end is called with a AVPacket read from a Stream.
>
> What is if the size of the Packet is smaller than a frame?
>
>
> +static int latm_find_frame_end(AVCodecParserContext *s1, const uint8_t
> *buf, +                               int buf_size)
> +{
> +    LATMParseContext *s = s1->priv_data;
> +    ParseContext *pc = &s->pc;
> +    int pic_found, i;
> +    uint32_t state;
> +
> +    pic_found = pc->frame_start_found;
> +    state     = pc->state;
> +
> +    for (i = 0; !pic_found && i < buf_size; i++) {
> +        state = (state<<8) | buf[i];
> +        if ((state & LATM_MASK) == LATM_HEADER) {
> +            pic_found = 1;
> +            s->count  = i - 2;
> +            break;
> +        }
> +    }
> +
> +    if (pic_found) {
> +        /* EOF considered as end of frame */
> +        if (buf_size == 0)
> +            return 0;
> +        if ((state & LATM_SIZE_MASK) + s->count + 3 <= buf_size) {
>
> if the Packet is smaller (buf_size is the size of the Packet) then
> "(state & LATM_SIZE_MASK) + s->count + 3 <= buf_size" can not be true?
>
> +            pc->frame_start_found = 0;
> +            pc->state             = -1;
> +            return (state & LATM_SIZE_MASK) + s->count + 3;
>
> thanks Peter

Sure,
If the packet is smaller than the frame size, then s->count is decremented
by buf_size and EOF_NOT_FOUND is returned at the end of the function.

s->count is then used in the calculation in the when the next packet is
processed. So, for example.

s->count is zero to start. s->count is set to where the header is found by
scanning the buffer. Lets say its at position 5, so s->count = 5.

1st packet is 200bytes has header and says the mux length is 300bytes
so s->count is set to -200 and EOF_NOT_FOUND is returned because 
300 + 5 + 3 <= 200 is false. So s->count is updated to 5 - 200 = -195.

2nd packet is 180bytes and pic_found is set, so only the if is executed. 
Now, 300 + -195 + 3 <= 180 is true so it returns the size of the
data.

After re-reading this and the ff_combine_frame function I think that updating
s->count (5-200 = -195) is not necessary as current buffer is merged with the
next lot of data and passed back in as a larger buffer.

Is this right?

If so, then I just need to remove the assignment to s->count at the end of
latm_find_frame_end and perhaps rename it to something better like
s->header_start.

Hope this makes things clearer. Thanks for your feedback.
Paul




More information about the ffmpeg-devel mailing list