On Mon, 28 Aug 2017 10:21:54 +0200 Jorge Ramirez <jorge.ramirez-or...@linaro.org> wrote:
> On 08/25/2017 05:35 PM, wm4 wrote: > >> +int avpriv_v4l2m2m_reinit(V4L2Context* ctx) > >> +{ > >> + V4L2m2mContext *s = container_of(ctx, V4L2m2mContext, capture); > >> + int ret; > >> + > >> + av_log(ctx->log_ctx, AV_LOG_DEBUG, "%s reinit context\n", ctx->name); > >> + > >> + /* 1. streamoff */ > >> + ret = avpriv_v4l2_context_set_status(ctx, VIDIOC_STREAMOFF); > >> + if (ret) > >> + av_log(ctx->log_ctx, AV_LOG_ERROR, "VIDIOC_STREAMOFF %s\n", > >> ctx->name); > >> + > >> + /* 2. unmap the buffers (v4l2 and ffmpeg) */ > >> + avpriv_v4l2_context_release(ctx); > > What happens to AVFrames or AVPackets that are still referenced? > > > > yes in response to your previous comment on the subject, I am trying to > address that in v7 not releasing the context while there are buffers on > the fly.... > This is what I came up with (if you can suggest something better - ie, a > way to block until the AVBufferRefs are unref- please let me know) > > void avpriv_v4l2_context_release(V4L2Context* ctx) > { > int i, ret; > > if (!ctx->buffers) > return; > > /* wait until all buffers are no longer in use */ > for (i = 0; i < ctx->num_buffers; i++) { > > if (ctx->buffers[i].status & (V4L2BUF_IN_DRIVER | > V4L2BUF_AVAILABLE)) > continue; > > while (ctx->buffers[i].status & V4L2BUF_RET_USER) > usleep(100); > } > > ret = ctx->ops.release_buffers(ctx); > if (ret) > av_log(ctx->log_ctx, AV_LOG_WARNING, "V4L2 failed to unmap the > %s buffers\n", ctx->name); > else > av_log(ctx->log_ctx, AV_LOG_DEBUG, "%s buffers unmapped\n", > ctx->name); > > av_free(ctx->buffers); > ctx->buffers = NULL; > ctx->num_queued = 0; > } > No, this is not possible. You must make the V4L state reference counted, and AVBufferRefs must implicitly reference this context. AVHWFramesContext does this in a more elegant way - it's a frame pool specifically made for hw decoders. I suspect the V4L code should be ported to that. I hope Mark Thompson has some helpful remarks on this. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org http://ffmpeg.org/mailman/listinfo/ffmpeg-devel