[FFmpeg-devel] [PATCHv8] libavcodec: v4l2: add support for v4l2 mem2mem codecs

Mark Thompson sw at jkqxz.net
Tue Sep 5 01:16:13 EEST 2017

On 04/09/17 22:55, Jorge Ramirez wrote:
> On 09/04/2017 11:29 PM, Mark Thompson wrote:
>>> ... stuff ...
>> So the sequence of calls is:
>> send_frame(frame 0) -> success
>> receive_packet() -> EAGAIN
>> send_frame(frame 1) -> success
>> receive_packet() -> EAGAIN
>> ...
>> send_frame(frame 15) -> success
>> receive_packet() -> EAGAIN
>> send_frame(frame 16) -> success
>> receive_packet() -> packet 0
>> receive_packet() -> packet 1
>> ...
>> receive_packet() -> packet 15
>> receive_packet() -> packet 16
>> receive_packet() -> blocks
>> This appears correct to me - since EAGAIN has not been returned by a receive_packet() call, it can be called again repeatedly (as documented in avcodec.h).   Do you disagree?
> I would have expected that after a packet is received, a new frame is enqueued instead of executing again receive_packet (why do we that? what is the benefit?)
> under these circumsntances I can't block in receive_packet blindly, I have to track in user-space what the driver has in its guts and predict how much it needs to keep working....I dont think it is a good idea.

Feel free to submit a patch to avcodec.h which changes the definition of the API.

>> I think that the problem is that you are only polling on the frame buffer queue when blocking, so you don't see the packet buffers becoming free in the packet buffer queue - if you did see and dequeue them, you would then return EAGAIN to indicate that more input is needed.  (See comments in <e4c6a8d7-798a-dfdb-b748-42936e944829 at jkqxz.net>.)
> I could manually track it that way with additional counters - so before blocking  I could see count many frames are enqueued in the input and if there is not at least one I could just return EAGAIN.
> but the behaviour differs from encoding.

The behaviour is identical.  You return the output buffer if there is one available on the output queue, otherwise you return EAGAIN if there is any space on the input queue, otherwise you block waiting for either of those to become possible.

> in decoding I queue all buffers and then block in capture; everytime it unblocks and returns a new frame back to ffmpeg, the next call just enqueues a packet (it doesnt try to dequeue another frame) so the pipeline never stops.
> I think the code should to be symmetrical for encoding and decoding...


More information about the ffmpeg-devel mailing list