On Tue, 12 Apr 2011, Luca Barbato wrote:

> On 4/12/11 12:59 PM, Martin Storsjö wrote:
> > On Tue, 12 Apr 2011, Anton Khirnov wrote:
> > 
> > > On Tue, Apr 12, 2011 at 12:43:23PM +0300, Martin Storsjö wrote:
> > > > From: Michael Niedermayer<michae...@gmx.at>
> > > > 
> > > > Reading the index currently requires seeking.
> > > > ---
> > > >   libavformat/flvdec.c |    2 +-
> > > >   1 files changed, 1 insertions(+), 1 deletions(-)
> > > > 
> > > > diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
> > > > index 62d25c8..1a827fd 100644
> > > > --- a/libavformat/flvdec.c
> > > > +++ b/libavformat/flvdec.c
> > > > @@ -212,7 +212,7 @@ static int amf_parse_object(AVFormatContext *s,
> > > > AVStream *astream, AVStream *vst
> > > >           case AMF_DATA_TYPE_OBJECT: {
> > > >               unsigned int keylen;
> > > > 
> > > > -            if (key&&  !strcmp(KEYFRAMES_TAG, key)&&  depth == 1)
> > > > +            if (ioc->seekable&&  key&&  !strcmp(KEYFRAMES_TAG, key)&&
> > > > depth == 1)
> > > >                   if (parse_keyframes_index(s, ioc, vstream, max_pos)<
> > > > 0)
> > > >                       return -1;
> > > > 
> > > > --
> > > > 1.7.3.1
> > > > 
> > > 
> > > Ok
> > 
> > Queued.
> 
> Dequeue

Ok, dequeing it for now

> there is a simpler solution for that.

No, it isn't fully as simple as you think.

> Right now what we should decide is if we want to error out if we don't have
> enough memory for the index or keep going.
> 
> I'd just error out if I cannot parse an element as before.
> 
> Here an untested tentative patch, point me to a sample file and I'll 
> make sure it works as should.

As I said in the other thread, if you return from parse_keyframes_index 
without seeking - like you propose, you need to parse in exactly the same 
way as what amf_parse_object does.

There's no requirement on exactly what kind of data you can put in AMF, 
it's a freeform structure as far as I know. The structure currently is 
something like this:

keyframes: { times: [ 1, 2, 3, 4 ], filepositions: [ 100, 200, 300, 400 ] 
}

Now what if the keyframes struct (or object in AMR vocabulary) contains an 
additional key/value, like this:
keyframes: { times: [ ... ], foo: 123, filepositions: [ ... ] }

The generic parser in amf_parse_object handles this - whenever a generic 
data value is expected, it parses that data value according to the type 
identifier (which in most cases just is skipping past the value).

parse_keyframes_index only works with this one fixed structure, if it sees 
something else - anything else than what it expects, it aborts. And then 
the rest of amr_parse_object can't reliably continue parsing the AMF tree, 
since parse_keyframes_index possibly left the reader at any undefined 
position within the keyframes struct.

So if we want to parse this in a simple one-pass fashion, we need to 
integrate the content from parse_keyframes_index into the generic 
recursive parser in amr_parse_object, so that the parser can iterate 
through whatever AMF values there are. Or call into amf_parse_object for 
anything that can be found which isn't specifically parsed by 
parse_keyframes_index.

// Martin
_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to