[FFmpeg-devel] [PATCH] videotoolbox: allow to enable the async decoding.

Zhang Rui bbcallen at gmail.com
Thu Aug 13 07:07:38 CEST 2015


>      status = VTDecompressionSessionDecodeFrame(videotoolbox->session,
>                                                 sample_buf,
> -                                               0,       // decodeFlags
> +                                               decodeFlags,
>                                                 NULL,    // sourceFrameRefCon
>                                                 0);      // infoFlagsOut

Better keep tracking how many decoding samples,
that are passed in and not yet received in callback.

VideoToolbox doesn't limit the number of frames in callback thread in
async mode.
It could be out of memory soon on iPhone without limit, and sooner
when application is in background.

> @@ -586,6 +686,15 @@ static void videotoolbox_default_free(AVCodecContext *avctx)
>         if (videotoolbox->cm_fmt_desc)
>             CFRelease(videotoolbox->cm_fmt_desc);
>
> +        if (videotoolbox->useAsyncDecoding) {
> +            VTDecompressionSessionWaitForAsynchronousFrames(videotoolbox->session);

I doubt if VTDecompressionSessionWaitForAsynchronousFrames guarantee
there are no more callback. Doc only says all samples are emitted.

Better wait all samples received in callback,
or add some check in callback to disable further access to context.

> +
> +            videotoolbox_clear_queue(videotoolbox);
> +
> +            if (videotoolbox->queue_mutex != NULL)
> +                videotoolbox_lock_operation(&videotoolbox->queue_mutex, AV_LOCK_DESTROY);
> +        }
> +
>         if (videotoolbox->session)
>             VTDecompressionSessionInvalidate(videotoolbox->session);
>     }


More information about the ffmpeg-devel mailing list