[FFmpeg-devel] [PATCH 1/2] vda: export vda_sync_decode

Xidorn Quan quanxunzhen at gmail.com
Tue Aug 21 03:48:46 CEST 2012


---
 libavcodec/vda.h      |  7 +++++--
 libavcodec/vda_h264.c | 33 +++++++++++++++++----------------
 2 files changed, 22 insertions(+), 18 deletions(-)

diff --git a/libavcodec/vda.h b/libavcodec/vda.h
index ccbf375..8950fbf 100644
--- a/libavcodec/vda.h
+++ b/libavcodec/vda.h
@@ -176,7 +176,7 @@ struct vda_context {
      * - encoding: unused
      * - decoding: Set/Unset by libavcodec.
      */
-    uint8_t             *priv_bitstream;
+    uint8_t             *bitstream;
 
     /**
      * The current size of the bitstream.
@@ -184,7 +184,7 @@ struct vda_context {
      * - encoding: unused
      * - decoding: Set/Unset by libavcodec.
      */
-    int                 priv_bitstream_size;
+    int                 bitstream_size;
 
     /**
      * The reference size used for fast reallocation.
@@ -203,6 +203,9 @@ int ff_vda_create_decoder(struct vda_context *vda_ctx,
 /** Destroy the video decoder. */
 int ff_vda_destroy_decoder(struct vda_context *vda_ctx);
 
+/** Synchronous decode video. */
+int ff_vda_sync_decode(struct vda_context *vda_ctx);
+
 #if FF_API_VDA_ASYNC
 /**
  * Return the top frame of the queue.
diff --git a/libavcodec/vda_h264.c b/libavcodec/vda_h264.c
index ec5a371..ec41418 100644
--- a/libavcodec/vda_h264.c
+++ b/libavcodec/vda_h264.c
@@ -179,15 +179,15 @@ static void vda_decoder_callback (void *vda_hw_ctx,
     }
 }
 
-static int vda_sync_decode(struct vda_context *vda_ctx)
+int ff_vda_sync_decode(struct vda_context *vda_ctx)
 {
     OSStatus status;
     CFDataRef coded_frame;
     uint32_t flush_flags = 1 << 0; ///< kVDADecoderFlush_emitFrames
 
     coded_frame = CFDataCreate(kCFAllocatorDefault,
-                               vda_ctx->priv_bitstream,
-                               vda_ctx->priv_bitstream_size);
+                               vda_ctx->bitstream,
+                               vda_ctx->bitstream_size);
 
     status = VDADecoderDecode(vda_ctx->decoder, 0, coded_frame, NULL);
 
@@ -208,7 +208,7 @@ static int start_frame(AVCodecContext *avctx,
     if (!vda_ctx->decoder)
         return -1;
 
-    vda_ctx->priv_bitstream_size = 0;
+    vda_ctx->bitstream_size = 0;
 
     return 0;
 }
@@ -223,18 +223,18 @@ static int decode_slice(AVCodecContext *avctx,
     if (!vda_ctx->decoder)
         return -1;
 
-    tmp = av_fast_realloc(vda_ctx->priv_bitstream,
+    tmp = av_fast_realloc(vda_ctx->bitstream,
                           &vda_ctx->priv_allocated_size,
-                          vda_ctx->priv_bitstream_size + size + 4);
+                          vda_ctx->bitstream_size + size + 4);
     if (!tmp)
         return AVERROR(ENOMEM);
 
-    vda_ctx->priv_bitstream = tmp;
+    vda_ctx->bitstream = tmp;
 
-    AV_WB32(vda_ctx->priv_bitstream + vda_ctx->priv_bitstream_size, size);
-    memcpy(vda_ctx->priv_bitstream + vda_ctx->priv_bitstream_size + 4, buffer, size);
+    AV_WB32(vda_ctx->bitstream + vda_ctx->bitstream_size, size);
+    memcpy(vda_ctx->bitstream + vda_ctx->bitstream_size + 4, buffer, size);
 
-    vda_ctx->priv_bitstream_size += size + 4;
+    vda_ctx->bitstream_size += size + 4;
 
     return 0;
 }
@@ -246,15 +246,15 @@ static int end_frame(AVCodecContext *avctx)
     AVFrame *frame                      = &h->s.current_picture_ptr->f;
     int status;
 
-    if (!vda_ctx->decoder || !vda_ctx->priv_bitstream)
+    if (!vda_ctx->decoder || !vda_ctx->bitstream)
         return -1;
 
     if (vda_ctx->use_sync_decoding) {
-        status = vda_sync_decode(vda_ctx);
+        status = ff_vda_sync_decode(vda_ctx);
         frame->data[3] = (void*)vda_ctx->cv_buffer;
     } else {
-        status = vda_decoder_decode(vda_ctx, vda_ctx->priv_bitstream,
-                                    vda_ctx->priv_bitstream_size,
+        status = vda_decoder_decode(vda_ctx, vda_ctx->bitstream,
+                                    vda_ctx->bitstream_size,
                                     frame->reordered_opaque);
     }
 
@@ -278,7 +278,7 @@ int ff_vda_create_decoder(struct vda_context *vda_ctx,
     CFMutableDictionaryRef io_surface_properties;
     CFNumberRef cv_pix_fmt;
 
-    vda_ctx->priv_bitstream = NULL;
+    vda_ctx->bitstream = NULL;
     vda_ctx->priv_allocated_size = 0;
 
 #if FF_API_VDA_ASYNC
@@ -366,7 +366,8 @@ int ff_vda_destroy_decoder(struct vda_context *vda_ctx)
     vda_clear_queue(vda_ctx);
     pthread_mutex_destroy(&vda_ctx->queue_mutex);
 #endif
-    av_freep(&vda_ctx->priv_bitstream);
+    if (vda_ctx->priv_allocated_size)
+        av_freep(&vda_ctx->bitstream);
 
     return status;
 }
-- 
1.7.11.4



More information about the ffmpeg-devel mailing list