Merge commit '31a46750c7eafe6bce6a3e4f09853cd0a585292b'
authorMichael Niedermayer <michaelni@gmx.at>
Sun, 11 May 2014 23:04:27 +0000 (01:04 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Sun, 11 May 2014 23:04:27 +0000 (01:04 +0200)
* commit '31a46750c7eafe6bce6a3e4f09853cd0a585292b':
  vda: use hwaccel private data for internal bitstream buffer

Conflicts:
libavcodec/vda.h
libavcodec/vda_h264.c

Merged-by: Michael Niedermayer <michaelni@gmx.at>
1  2 
libavcodec/vda.h
libavcodec/vda_h264.c

@@@ -134,23 -122,9 +128,20 @@@ struct vda_context 
      int                 priv_bitstream_size;
  
      /**
-      * The reference size used for fast reallocation.
-      *
-      * - encoding: unused
-      * - decoding: Set/Unset by libavcodec.
+      * unused
       */
      int                 priv_allocated_size;
 +
 +    /**
 +     * Use av_buffer to manage buffer.
 +     * When the flag is set, the CVPixelBuffers returned by the decoder will
 +     * be released automatically, so you have to retain them if necessary.
 +     * Not setting this flag may cause memory leak.
 +     *
 +     * encoding: unused
 +     * decoding: Set by user.
 +     */
 +    int                 use_ref_buffer;
  };
  
  /** Create the video decoder. */
   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
   */
  
 +#include <CoreFoundation/CFDictionary.h>
  #include <CoreFoundation/CFNumber.h>
  #include <CoreFoundation/CFData.h>
 -#include <CoreFoundation/CFString.h>
  
 +#include "vda.h"
  #include "libavutil/avutil.h"
  #include "h264.h"
 -#include "vda.h"
 +
 +struct vda_buffer {
 +    CVPixelBufferRef cv_buffer;
 +};
  
 -/* Decoder callback that adds the VDA frame to the queue in display order. */
+ typedef struct VDAContext {
+     // The current bitstream buffer.
+     uint8_t             *bitstream;
+     // The current size of the bitstream.
+     int                  bitstream_size;
+     // The reference size used for fast reallocation.
+     int                  allocated_size;
+ } VDAContext;
 +/* Decoder callback that adds the vda frame to the queue in display order. */
  static void vda_decoder_callback(void *vda_hw_ctx,
                                   CFDictionaryRef user_info,
                                   OSStatus status,
@@@ -78,7 -82,8 +89,8 @@@ static int vda_h264_start_frame(AVCodec
                                  av_unused const uint8_t *buffer,
                                  av_unused uint32_t size)
  {
 -    struct vda_context *vda_ctx         = avctx->hwaccel_context;
+     VDAContext *vda = avctx->internal->hwaccel_priv_data;
 +    struct vda_context *vda_ctx = avctx->hwaccel_context;
  
      if (!vda_ctx->decoder)
          return -1;
@@@ -92,7 -97,8 +104,8 @@@ static int vda_h264_decode_slice(AVCode
                                   const uint8_t *buffer,
                                   uint32_t size)
  {
 -    VDAContext *vda                     = avctx->internal->hwaccel_priv_data;
 -    struct vda_context *vda_ctx         = avctx->hwaccel_context;
++    VDAContext *vda             = avctx->internal->hwaccel_priv_data;
 +    struct vda_context *vda_ctx = avctx->hwaccel_context;
      void *tmp;
  
      if (!vda_ctx->decoder)
@@@ -124,16 -123,15 +137,17 @@@ static void vda_h264_release_buffer(voi
  static int vda_h264_end_frame(AVCodecContext *avctx)
  {
      H264Context *h                      = avctx->priv_data;
+     VDAContext *vda                     = avctx->internal->hwaccel_priv_data;
      struct vda_context *vda_ctx         = avctx->hwaccel_context;
      AVFrame *frame                      = &h->cur_pic_ptr->f;
 +    struct vda_buffer *context;
 +    AVBufferRef *buffer;
      int status;
  
-     if (!vda_ctx->decoder || !vda_ctx->priv_bitstream)
+     if (!vda_ctx->decoder || !vda->bitstream)
          return -1;
  
-     status = vda_sync_decode(vda_ctx);
+     status = vda_sync_decode(vda, vda_ctx);
      frame->data[3] = (void*)vda_ctx->cv_buffer;
  
      if (status)