From 5ada64a54913cc72da76010cf4a702eccdc1ecd2 Mon Sep 17 00:00:00 2001 From: Sebastien Zwickert Date: Sun, 8 Jan 2012 20:22:12 +0100 Subject: [PATCH 1/4] vda: convert 3 byte NAL sizes to 4 byte. --- libavcodec/vda.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libavcodec/vda.c b/libavcodec/vda.c index aaf5ba047a..20207eab70 100644 --- a/libavcodec/vda.c +++ b/libavcodec/vda.c @@ -179,6 +179,11 @@ int ff_vda_create_decoder(struct vda_context *vda_ctx, vda_lock_operation(&vda_ctx->queue_mutex, AV_LOCK_CREATE); + if (extradata[4]==0xFE) { + // convert 3 byte NAL sizes to 4 byte + extradata[4] = 0xFF; + } + config_info = CFDictionaryCreateMutable(kCFAllocatorDefault, 4, &kCFTypeDictionaryKeyCallBacks, From 75be547f77af196b14c0635bfad89445f04bdaed Mon Sep 17 00:00:00 2001 From: Sebastien Zwickert Date: Sun, 8 Jan 2012 20:22:12 +0100 Subject: [PATCH 2/4] vda: uses pthreads directly. --- libavcodec/vda.c | 43 +++++++++---------------------------------- libavcodec/vda.h | 3 ++- 2 files changed, 11 insertions(+), 35 deletions(-) diff --git a/libavcodec/vda.c b/libavcodec/vda.c index 20207eab70..eff5933e71 100644 --- a/libavcodec/vda.c +++ b/libavcodec/vda.c @@ -26,7 +26,7 @@ #include #include -#include "avcodec.h" +#include "libavutil/avutil.h" #include "vda_internal.h" /** @@ -35,27 +35,6 @@ * @{ */ -/* Mutex manager callback. */ -static int vda_lock_operation(void **mtx, enum AVLockOp op) -{ - switch (op) { - case AV_LOCK_CREATE: - *mtx = av_malloc(sizeof(pthread_mutex_t)); - if (!*mtx) - return 1; - return !!pthread_mutex_init(*mtx, NULL); - case AV_LOCK_OBTAIN: - return !!pthread_mutex_lock(*mtx); - case AV_LOCK_RELEASE: - return !!pthread_mutex_unlock(*mtx); - case AV_LOCK_DESTROY: - pthread_mutex_destroy(*mtx); - av_freep(mtx); - return 0; - } - return 1; -} - /* Helper to create a dictionary according to the given pts. */ static CFDictionaryRef vda_dictionary_with_pts(int64_t i_pts) { @@ -93,7 +72,7 @@ static void vda_clear_queue(struct vda_context *vda_ctx) { vda_frame *top_frame; - vda_lock_operation(&vda_ctx->queue_mutex, AV_LOCK_OBTAIN); + pthread_mutex_lock(&vda_ctx->queue_mutex); while (vda_ctx->queue) { top_frame = vda_ctx->queue; @@ -101,7 +80,7 @@ static void vda_clear_queue(struct vda_context *vda_ctx) ff_vda_release_vda_frame(top_frame); } - vda_lock_operation(&vda_ctx->queue_mutex, AV_LOCK_RELEASE); + pthread_mutex_unlock(&vda_ctx->queue_mutex); } @@ -130,7 +109,7 @@ static void vda_decoder_callback (void *vda_hw_ctx, new_frame->cv_buffer = CVPixelBufferRetain(image_buffer); new_frame->pts = vda_pts_from_dictionary(user_info); - vda_lock_operation(&vda_ctx->queue_mutex, AV_LOCK_OBTAIN); + pthread_mutex_lock(&vda_ctx->queue_mutex); queue_walker = vda_ctx->queue; @@ -154,7 +133,7 @@ static void vda_decoder_callback (void *vda_hw_ctx, } } - vda_lock_operation(&vda_ctx->queue_mutex, AV_LOCK_RELEASE); + pthread_mutex_unlock(&vda_ctx->queue_mutex); } int ff_vda_create_decoder(struct vda_context *vda_ctx, @@ -174,10 +153,7 @@ int ff_vda_create_decoder(struct vda_context *vda_ctx, vda_ctx->bitstream = NULL; vda_ctx->ref_size = 0; - if (av_lockmgr_register(vda_lock_operation)) - return -1; - - vda_lock_operation(&vda_ctx->queue_mutex, AV_LOCK_CREATE); + pthread_mutex_init(&vda_ctx->queue_mutex, NULL); if (extradata[4]==0xFE) { // convert 3 byte NAL sizes to 4 byte @@ -247,8 +223,7 @@ int ff_vda_destroy_decoder(struct vda_context *vda_ctx) vda_clear_queue(vda_ctx); - if (vda_ctx->queue_mutex) - vda_lock_operation(&vda_ctx->queue_mutex, AV_LOCK_DESTROY); + pthread_mutex_destroy(&vda_ctx->queue_mutex); if (vda_ctx->bitstream) av_freep(&vda_ctx->bitstream); @@ -266,10 +241,10 @@ vda_frame *ff_vda_queue_pop(struct vda_context *vda_ctx) if (!vda_ctx->queue) return NULL; - vda_lock_operation(&vda_ctx->queue_mutex, AV_LOCK_OBTAIN); + pthread_mutex_lock(&vda_ctx->queue_mutex); top_frame = vda_ctx->queue; vda_ctx->queue = top_frame->next_frame; - vda_lock_operation(&vda_ctx->queue_mutex, AV_LOCK_RELEASE); + pthread_mutex_unlock(&vda_ctx->queue_mutex); return top_frame; } diff --git a/libavcodec/vda.h b/libavcodec/vda.h index 5ff8070fd3..7d043c7e30 100644 --- a/libavcodec/vda.h +++ b/libavcodec/vda.h @@ -23,6 +23,7 @@ #ifndef AVCODEC_VDA_H #define AVCODEC_VDA_H +#include #include // emmintrin.h is unable to compile with -std=c99 -Werror=missing-prototypes @@ -92,7 +93,7 @@ struct vda_context { * - encoding: unused * - decoding: Set/Unset by libavcodec. */ - void *queue_mutex; + pthread_mutex_t queue_mutex; /** * The frame width. From e953b8b7be7358b6dea51ebbc7cbf75d6c5cf786 Mon Sep 17 00:00:00 2001 From: Sebastien Zwickert Date: Sun, 8 Jan 2012 20:22:12 +0100 Subject: [PATCH 3/4] vda: removes useless doxygen command. --- libavcodec/vda.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/libavcodec/vda.c b/libavcodec/vda.c index eff5933e71..a2814d7024 100644 --- a/libavcodec/vda.c +++ b/libavcodec/vda.c @@ -29,12 +29,6 @@ #include "libavutil/avutil.h" #include "vda_internal.h" -/** - * \addtogroup VDA_Decoding - * - * @{ - */ - /* Helper to create a dictionary according to the given pts. */ static CFDictionaryRef vda_dictionary_with_pts(int64_t i_pts) { @@ -279,5 +273,3 @@ int ff_vda_decoder_decode(struct vda_context *vda_ctx, return 0; } - -/* @} */ From 186980bf0f5e890295b6dc6b939084e3ebcf0dde Mon Sep 17 00:00:00 2001 From: Sebastien Zwickert Date: Sun, 8 Jan 2012 20:22:12 +0100 Subject: [PATCH 4/4] vda: cosmetic. --- libavcodec/vda.h | 9 ++++----- libavcodec/vda_internal.h | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/libavcodec/vda.h b/libavcodec/vda.h index 7d043c7e30..6e9de9cd0a 100644 --- a/libavcodec/vda.h +++ b/libavcodec/vda.h @@ -61,7 +61,6 @@ typedef struct { * - decoding: Set/Unset by libavcodec. */ struct vda_frame *next_frame; - } vda_frame; /** @@ -152,18 +151,18 @@ struct vda_context { int ref_size; }; -/** Creates the video decoder. */ +/** Create the video decoder. */ int ff_vda_create_decoder(struct vda_context *vda_ctx, uint8_t *extradata, int extradata_size); -/** Destroys the video decoder. */ +/** Destroy the video decoder. */ int ff_vda_destroy_decoder(struct vda_context *vda_ctx); -/** Returns the top frame of the queue. */ +/** Return the top frame of the queue. */ vda_frame *ff_vda_queue_pop(struct vda_context *vda_ctx); -/** Releases the given frame. */ +/** Release the given frame. */ void ff_vda_release_vda_frame(vda_frame *frame); #endif /* AVCODEC_VDA_H */ diff --git a/libavcodec/vda_internal.h b/libavcodec/vda_internal.h index 02c13df721..df7305bfe6 100644 --- a/libavcodec/vda_internal.h +++ b/libavcodec/vda_internal.h @@ -31,7 +31,7 @@ * @{ */ -/** Send a frame data to the hardware decoder. */ +/** Send frame data to the hardware decoder. */ int ff_vda_decoder_decode(struct vda_context *vda_ctx, uint8_t *bitstream, int bitstream_size,