Commit ab4f94e2 authored by François Grisez's avatar François Grisez
Browse files

VideoToobloxH264Decoder: use filter mutex to protect the queue holding the decoded frames

parent 6b1515fb
...@@ -592,7 +592,6 @@ typedef struct _VTH264DecCtx { ...@@ -592,7 +592,6 @@ typedef struct _VTH264DecCtx {
VTDecompressionSessionRef session; VTDecompressionSessionRef session;
CMFormatDescriptionRef format_desc; CMFormatDescriptionRef format_desc;
Rfc3984Context unpacker; Rfc3984Context unpacker;
ms_mutex_t mutex;
MSQueue queue; MSQueue queue;
MSYuvBufAllocator *pixbuf_allocator; MSYuvBufAllocator *pixbuf_allocator;
MSVideoSize vsize; MSVideoSize vsize;
...@@ -644,14 +643,11 @@ static void h264_dec_output_cb(VTH264DecCtx *ctx, void *sourceFrameRefCon, ...@@ -644,14 +643,11 @@ static void h264_dec_output_cb(VTH264DecCtx *ctx, void *sourceFrameRefCon,
if(status != noErr || imageBuffer == NULL) { if(status != noErr || imageBuffer == NULL) {
vth264dec_error("fail to decode one frame: %s", os_status_to_string(status)); vth264dec_error("fail to decode one frame: %s", os_status_to_string(status));
ms_filter_lock(ctx->f);
if(ctx->enable_avpf) { if(ctx->enable_avpf) {
ms_filter_notify_no_arg(ctx->f, MS_VIDEO_DECODER_SEND_PLI); ms_filter_notify_no_arg(ctx->f, MS_VIDEO_DECODER_SEND_PLI);
}else{ }else{
ms_filter_notify_no_arg(ctx->f, MS_VIDEO_DECODER_DECODING_ERRORS); ms_filter_notify_no_arg(ctx->f, MS_VIDEO_DECODER_DECODING_ERRORS);
} }
ms_filter_unlock(ctx->f);
return; return;
} }
...@@ -668,9 +664,9 @@ static void h264_dec_output_cb(VTH264DecCtx *ctx, void *sourceFrameRefCon, ...@@ -668,9 +664,9 @@ static void h264_dec_output_cb(VTH264DecCtx *ctx, void *sourceFrameRefCon,
ms_yuv_buf_copy(src_planes, src_strides, pixbuf_desc.planes, pixbuf_desc.strides, ctx->vsize); ms_yuv_buf_copy(src_planes, src_strides, pixbuf_desc.planes, pixbuf_desc.strides, ctx->vsize);
CVPixelBufferUnlockBaseAddress(imageBuffer, kCVPixelBufferLock_ReadOnly); CVPixelBufferUnlockBaseAddress(imageBuffer, kCVPixelBufferLock_ReadOnly);
ms_mutex_lock(&ctx->mutex); ms_filter_lock(ctx->f);
ms_queue_put(&ctx->queue, pixbuf); ms_queue_put(&ctx->queue, pixbuf);
ms_mutex_unlock(&ctx->mutex); ms_filter_unlock(ctx->f);
} }
static bool_t h264_dec_init_decoder(VTH264DecCtx *ctx) { static bool_t h264_dec_init_decoder(VTH264DecCtx *ctx) {
...@@ -730,7 +726,6 @@ static void h264_dec_uninit_decoder(VTH264DecCtx *ctx) { ...@@ -730,7 +726,6 @@ static void h264_dec_uninit_decoder(VTH264DecCtx *ctx) {
static void h264_dec_init(MSFilter *f) { static void h264_dec_init(MSFilter *f) {
VTH264DecCtx *ctx = ms_new0(VTH264DecCtx, 1); VTH264DecCtx *ctx = ms_new0(VTH264DecCtx, 1);
ms_queue_init(&ctx->queue); ms_queue_init(&ctx->queue);
ms_mutex_init(&ctx->mutex, NULL);
ctx->pixbuf_allocator = ms_yuv_buf_allocator_new(); ctx->pixbuf_allocator = ms_yuv_buf_allocator_new();
rfc3984_init(&ctx->unpacker); rfc3984_init(&ctx->unpacker);
ctx->vsize = MS_VIDEO_SIZE_UNKNOWN; ctx->vsize = MS_VIDEO_SIZE_UNKNOWN;
...@@ -911,11 +906,9 @@ static void h264_dec_process(MSFilter *f) { ...@@ -911,11 +906,9 @@ static void h264_dec_process(MSFilter *f) {
} }
// Transfer decoded frames in the output queue // Transfer decoded frames in the output queue
ms_mutex_lock(&ctx->mutex); ms_filter_lock(f);
while((pixbuf = ms_queue_get(&ctx->queue))) { while((pixbuf = ms_queue_get(&ctx->queue))) {
ms_mutex_unlock(&ctx->mutex);
ms_yuv_buf_init_from_mblk(&pixbuf_desc, pixbuf); ms_yuv_buf_init_from_mblk(&pixbuf_desc, pixbuf);
ms_filter_lock(f);
if(pixbuf_desc.w != ctx->vsize.width || pixbuf_desc.h != ctx->vsize.height) { if(pixbuf_desc.w != ctx->vsize.width || pixbuf_desc.h != ctx->vsize.height) {
ctx->vsize = (MSVideoSize){ pixbuf_desc.w , pixbuf_desc.h }; ctx->vsize = (MSVideoSize){ pixbuf_desc.w , pixbuf_desc.h };
} }
...@@ -924,11 +917,9 @@ static void h264_dec_process(MSFilter *f) { ...@@ -924,11 +917,9 @@ static void h264_dec_process(MSFilter *f) {
ms_filter_notify_no_arg(f, MS_VIDEO_DECODER_FIRST_IMAGE_DECODED); ms_filter_notify_no_arg(f, MS_VIDEO_DECODER_FIRST_IMAGE_DECODED);
ctx->first_image = FALSE; ctx->first_image = FALSE;
} }
ms_filter_unlock(f);
ms_queue_put(f->outputs[0], pixbuf); ms_queue_put(f->outputs[0], pixbuf);
ms_mutex_lock(&ctx->mutex);
} }
ms_mutex_unlock(&ctx->mutex); ms_filter_unlock(f);
ms_queue_flush(&q_nalus); ms_queue_flush(&q_nalus);
ms_queue_flush(&q_nalus2); ms_queue_flush(&q_nalus2);
...@@ -950,7 +941,6 @@ static void h264_dec_uninit(MSFilter *f) { ...@@ -950,7 +941,6 @@ static void h264_dec_uninit(MSFilter *f) {
if(ctx->format_desc != NULL) CFRelease(ctx->format_desc); if(ctx->format_desc != NULL) CFRelease(ctx->format_desc);
ms_queue_flush(&ctx->queue); ms_queue_flush(&ctx->queue);
ms_mutex_destroy(&ctx->mutex);
ms_yuv_buf_allocator_free(ctx->pixbuf_allocator); ms_yuv_buf_allocator_free(ctx->pixbuf_allocator);
if (ctx->sps != NULL) freemsg(ctx->sps); if (ctx->sps != NULL) freemsg(ctx->sps);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment