[FFmpeg-devel] [PATCHv6 4/4] libavcodec: v4l2: add support for v4l2 mem2mem codecs

Jorge Ramirez jorge.ramirez-ortiz at linaro.org
Tue Aug 29 15:23:23 EEST 2017


On 08/29/2017 01:50 PM, wm4 wrote:
>> static void free_v4l2buf_cb(void *opaque, uint8_t *unused)
>> {
>>       V4L2Buffer* avbuf = opaque;
>>       V4L2m2mContext *s = container_of(avbuf->context, V4L2m2mContext,
>> capture);
>>
>>       atomic_fetch_sub_explicit(&s->refcount, 1, memory_order_acq_rel);
>>
>>       if (s->reinit) {
>>           if (!atomic_load(&s->refcount))
>>               sem_post(&s->refsync);
>>           return;
>>       }
>>
>>       if (avbuf->context->streamon) {
>>           avbuf->context->ops.enqueue(avbuf);
>>           return;
>>       }
>>
>>       if (!atomic_load(&s->refcount))
>>           avpriv_v4l2m2m_end(s);
>> }
>>
>> The only case where I can't get away without waiting for the AVBufferRef
>> to be released is when re-initializing the frame dimensions (ie,
>> resolution changes/format)_during_  streaming since I need to release
>> _all_  hardware buffers and queue them again.
>>
>> will this be acceptable?
>> I have just tested these changes and works as expected.
> The implementation seems rather roundabout and complex - why not use
> AVBufferRef? But apart from that, yes.
>

I thought about using an AVBufferRef for this but really all I need are 
an atomic_uint (refcount), the atomic operations and a sem_t (refsync).
then it is pretty straight forward.

I'll post it like it is in v7 and if you still believe an AVBufferRef is 
a more maintainable solution I'll change it, is not a big deal (although 
I'll still need the sem_t).


More information about the ffmpeg-devel mailing list