"Ronald S. Bultje" <rsbul...@gmail.com> writes:

> Hi,
>
> On Mon, Aug 29, 2011 at 8:16 PM, Uoti Urpala <uoti.urp...@pp1.inet.fi> wrote:
>> On Mon, 2011-08-29 at 19:48 -0700, Ronald S. Bultje wrote:
>>> On Mon, Aug 29, 2011 at 7:06 PM, Uoti Urpala <uoti.urp...@pp1.inet.fi> 
>>> wrote:
>>
>>> > The actual problem here was that an application was using avctx->height
>>> > immediately after avcodec_open2(). The h264 decoder and others do not
>>> > set width/height until after at least one frame has been decoded. The
>>> > only reason the subject commit made a difference was that without it an
>>> > initial value from before avcodec_open2() remained in the field until it
>>> > was actually initialized, and it was correct in this case.
>>>
>>> That's not true. av_find_stream_info() assures that these values are set.
>>
>> Which part is not true?
>>
>> av_find_stream_info() is a libavformat function. What's being discussed
>> here is libavcodec functionality, and nothing here will call
>> av_find_stream_info().
>>
>> If you assume an usage pattern where the initial value in the context
>> (_before_ calling avcodec_open2) comes from an earlier call to
>> av_find_stream_info() then it'll likely be correct. But libavcodec will
>> not initialize it until at least one frame has been decoded, and the
>> fields are documented as "decoding: Set by libavcodec".
>
> The delay is indeed true if threading is used.

Threading is irrelevant.  Some codecs don't set (or know) the dimensions
until the first frame is returned.  With threading there might be a
delay before that happens, but this is beside the point.

> Libavcodec expects values to be set as they would be by libavformat,

Untrue.  If a decoder expects this, it is horribly broken.  The reason
is simple: libavformat uses libavcodec to set the fields not provided by
the container.  Some decoders do require the caller to set correct
values, usually provided by the container, before avcodec_open().

> be that in practice done by mplayer or libavformat or whatever the
> demuxer-of-the-day is. It's probably underdocumented, but that doesn't
> make it any less true.

It is undocumented which decoders require what information.  In practice
it works to fill in all fields with known values before avcodec_open(),
after which the decoder will do the rest, either parsing them from
extradata in open() or from the first frame in decode().

> My point was: the value is correct before avcodec_open() is called.

If find_stream_info() was called, yes.  This function uses
avcodec_open() and decode() internally, so at some point avcodec_open()
is called with incomplete parameters (when container doesn't specify all).

> After that it's wrong, and then correct again. Even in the case where
> you don't set it, it's zero until set. This code sets it __wrong__.
> That is always bad.

I agree, setting an incorrect value is always wrong in every possible way.

-- 
Måns Rullgård
m...@mansr.com
_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to