Breaks compatibility on purpose the hardest way.
---
libavcodec/Makefile | 2 +-
libavcodec/vda.c | 29 ++++++++++++
libavcodec/vda.h | 124 ++++++++++++++++++++++++++++++++++++++++++++++----
libavcodec/vda_h264.c | 106 ++----------------------------------------
4 files changed, 151 insertions(+), 110 deletions(-)
create mode 100644 libavcodec/vda.c
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 44d5ae6..fc52054 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -514,7 +514,7 @@ OBJS-$(CONFIG_H263_VAAPI_HWACCEL) += vaapi_mpeg4.o
OBJS-$(CONFIG_H263_VDPAU_HWACCEL) += vdpau_mpeg4.o
OBJS-$(CONFIG_H264_DXVA2_HWACCEL) += dxva2_h264.o
OBJS-$(CONFIG_H264_VAAPI_HWACCEL) += vaapi_h264.o
-OBJS-$(CONFIG_H264_VDA_HWACCEL) += vda_h264.o
+OBJS-$(CONFIG_H264_VDA_HWACCEL) += vda_h264.o vda.o
OBJS-$(CONFIG_H264_VDPAU_HWACCEL) += vdpau_h264.o
OBJS-$(CONFIG_MPEG1_VDPAU_HWACCEL) += vdpau_mpeg12.o
OBJS-$(CONFIG_MPEG2_DXVA2_HWACCEL) += dxva2_mpeg2.o
diff --git a/libavcodec/vda.c b/libavcodec/vda.c
new file mode 100644
index 0000000..b819b96
--- /dev/null
+++ b/libavcodec/vda.c
@@ -0,0 +1,29 @@
+/*
+ * VDA HW acceleration
+ *
+ * copyright (c) 2014 Sebastien Zwickert
+ *
+ * This file is part of Libav.
+ *
+ * Libav is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Libav is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with Libav; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/mem.h"
+#include "vda.h"
+
+AVVDAContext *av_vda_alloc_context(void)
+{
+ return av_mallocz(sizeof(AVVDAContext));
+}
diff --git a/libavcodec/vda.h b/libavcodec/vda.h
index 987b94f..ee7cfc4 100644
--- a/libavcodec/vda.h
+++ b/libavcodec/vda.h
@@ -53,8 +53,12 @@
* to the VDA Libav HWAccel implementation.
*
* The application must make it available as AVCodecContext.hwaccel_context.
+ *
+ * The size of this structure is not a part of the public ABI and must not
+ * be used outside of libavcodec.
+ * Use av_vda_alloc_context() to allocate an AVVDAContext.
*/
-struct vda_context {
+typedef struct AVVDAContext {
/**
* VDA decoder object.
*
@@ -125,15 +129,119 @@ struct vda_context {
* The reference size used for fast reallocation.
*/
int priv_allocated_size;
-};
+} AVVDAContext;
-/** Create the video decoder. */
-int ff_vda_create_decoder(struct vda_context *vda_ctx,
- uint8_t *extradata,
- int extradata_size);
+/**
+ * Allocate an AVVDAContext.
+ *
+ * @return Newly-allocated AVVDAContext or NULL on failure.
+ */
+AVVDAContext *av_vda_alloc_context(void);
+
+/**
+ * Example context setup and destroy functions
+ */
-/** Destroy the video decoder. */
-int ff_vda_destroy_decoder(struct vda_context *vda_ctx);
+#if 0
+
+int vda_create_decoder(AVVDAContext *vda_ctx,
+ uint8_t *extradata,
+ int extradata_size)
+{
+ OSStatus status = kVDADecoderNoErr;
+ CFNumberRef height;
+ CFNumberRef width;
+ CFNumberRef format;
+ CFDataRef avc_data;
+ CFMutableDictionaryRef config_info;
+ CFMutableDictionaryRef buffer_attributes;
+ CFMutableDictionaryRef io_surface_properties;
+ CFNumberRef cv_pix_fmt;
+
+ /* Each VCL NAL in the bistream sent to the decoder
+ * is preceded by a 4 bytes length header.
+ * Change the avcC atom header if needed, to signal headers of 4 bytes. */
+ if (extradata_size >= 4 && (extradata[4] & 0x03) != 0x03) {
+ uint8_t *rw_extradata;
+
+ if (!(rw_extradata = av_malloc(extradata_size)))
+ return AVERROR(ENOMEM);
+
+ memcpy(rw_extradata, extradata, extradata_size);
+
+ rw_extradata[4] |= 0x03;
+
+ avc_data = CFDataCreate(kCFAllocatorDefault, rw_extradata,
extradata_size);
+
+ av_freep(&rw_extradata);
+ } else {
+ avc_data = CFDataCreate(kCFAllocatorDefault, extradata,
extradata_size);
+ }
+
+ config_info = CFDictionaryCreateMutable(kCFAllocatorDefault,
+ 4,
+ &kCFTypeDictionaryKeyCallBacks,
+ &kCFTypeDictionaryValueCallBacks);
+
+ height = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type,
&vda_ctx->height);
+ width = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type,
&vda_ctx->width);
+ format = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type,
&vda_ctx->format);
+
+ CFDictionarySetValue(config_info, kVDADecoderConfiguration_Height, height);
+ CFDictionarySetValue(config_info, kVDADecoderConfiguration_Width, width);
+ CFDictionarySetValue(config_info, kVDADecoderConfiguration_SourceFormat,
format);
+ CFDictionarySetValue(config_info, kVDADecoderConfiguration_avcCData,
avc_data);
+
+ buffer_attributes = CFDictionaryCreateMutable(kCFAllocatorDefault,
+ 2,
+
&kCFTypeDictionaryKeyCallBacks,
+
&kCFTypeDictionaryValueCallBacks);
+ io_surface_properties = CFDictionaryCreateMutable(kCFAllocatorDefault,
+ 0,
+
&kCFTypeDictionaryKeyCallBacks,
+
&kCFTypeDictionaryValueCallBacks);
+ cv_pix_fmt = CFNumberCreate(kCFAllocatorDefault,
+ kCFNumberSInt32Type,
+ &vda_ctx->cv_pix_fmt_type);
+ CFDictionarySetValue(buffer_attributes,
+ kCVPixelBufferPixelFormatTypeKey,
+ cv_pix_fmt);
+ CFDictionarySetValue(buffer_attributes,
+ kCVPixelBufferIOSurfacePropertiesKey,
+ io_surface_properties);
+
+ status = VDADecoderCreate(config_info,
+ buffer_attributes,
+ vda_decoder_callback,
+ vda_ctx,
+ &vda_ctx->decoder);
+
+ CFRelease(height);
+ CFRelease(width);
+ CFRelease(format);
+ CFRelease(avc_data);
+ CFRelease(config_info);
+ CFRelease(io_surface_properties);
+ CFRelease(cv_pix_fmt);
+ CFRelease(buffer_attributes);
+
+ return status;
+}
+
+
+int vda_destroy_decoder(struct vda_context *vda_ctx)
+{
+ OSStatus status = kVDADecoderNoErr;
+
+ if (vda_ctx->decoder)
+ status = VDADecoderDestroy(vda_ctx->decoder);
+
+ av_freep(&vda_ctx->priv_bitstream);
+
+ return status;
+}
+
+#endif
/**
* @}
diff --git a/libavcodec/vda_h264.c b/libavcodec/vda_h264.c
index 6c1845a..e9c4af6 100644
--- a/libavcodec/vda_h264.c
+++ b/libavcodec/vda_h264.c
@@ -35,7 +35,7 @@ static void vda_decoder_callback(void *vda_hw_ctx,
uint32_t infoFlags,
CVImageBufferRef image_buffer)
{
- struct vda_context *vda_ctx = vda_hw_ctx;
+ AVVDAContext *vda_ctx = vda_hw_ctx;
if (!image_buffer)
return;
@@ -46,7 +46,7 @@ static void vda_decoder_callback(void *vda_hw_ctx,
vda_ctx->cv_buffer = CVPixelBufferRetain(image_buffer);
}
-static int vda_sync_decode(struct vda_context *vda_ctx)
+static int vda_sync_decode(AVVDAContext *vda_ctx)
{
OSStatus status;
CFDataRef coded_frame;
@@ -71,7 +71,7 @@ static int vda_h264_start_frame(AVCodecContext *avctx,
av_unused const uint8_t *buffer,
av_unused uint32_t size)
{
- struct vda_context *vda_ctx = avctx->hwaccel_context;
+ AVVDAContext *vda_ctx = avctx->hwaccel_context;
if (!vda_ctx->decoder)
return -1;
@@ -85,7 +85,7 @@ static int vda_h264_decode_slice(AVCodecContext *avctx,
const uint8_t *buffer,
uint32_t size)
{
- struct vda_context *vda_ctx = avctx->hwaccel_context;
+ AVVDAContext *vda_ctx = avctx->hwaccel_context;
void *tmp;
if (!vda_ctx->decoder)
@@ -110,7 +110,7 @@ static int vda_h264_decode_slice(AVCodecContext *avctx,
static int vda_h264_end_frame(AVCodecContext *avctx)
{
H264Context *h = avctx->priv_data;
- struct vda_context *vda_ctx = avctx->hwaccel_context;
+ AVVDAContext *vda_ctx = avctx->hwaccel_context;
AVFrame *frame = &h->cur_pic_ptr->f;
int status;
@@ -126,102 +126,6 @@ static int vda_h264_end_frame(AVCodecContext *avctx)
return status;
}
-int ff_vda_create_decoder(struct vda_context *vda_ctx,
- uint8_t *extradata,
- int extradata_size)
-{
- OSStatus status = kVDADecoderNoErr;
- CFNumberRef height;
- CFNumberRef width;
- CFNumberRef format;
- CFDataRef avc_data;
- CFMutableDictionaryRef config_info;
- CFMutableDictionaryRef buffer_attributes;
- CFMutableDictionaryRef io_surface_properties;
- CFNumberRef cv_pix_fmt;
-
- /* Each VCL NAL in the bistream sent to the decoder
- * is preceded by a 4 bytes length header.
- * Change the avcC atom header if needed, to signal headers of 4 bytes. */
- if (extradata_size >= 4 && (extradata[4] & 0x03) != 0x03) {
- uint8_t *rw_extradata;
-
- if (!(rw_extradata = av_malloc(extradata_size)))
- return AVERROR(ENOMEM);
-
- memcpy(rw_extradata, extradata, extradata_size);
-
- rw_extradata[4] |= 0x03;
-
- avc_data = CFDataCreate(kCFAllocatorDefault, rw_extradata,
extradata_size);
-
- av_freep(&rw_extradata);
- } else {
- avc_data = CFDataCreate(kCFAllocatorDefault, extradata,
extradata_size);
- }
-
- config_info = CFDictionaryCreateMutable(kCFAllocatorDefault,
- 4,
- &kCFTypeDictionaryKeyCallBacks,
- &kCFTypeDictionaryValueCallBacks);
-
- height = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type,
&vda_ctx->height);
- width = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type,
&vda_ctx->width);
- format = CFNumberCreate(kCFAllocatorDefault, kCFNumberSInt32Type,
&vda_ctx->format);
-
- CFDictionarySetValue(config_info, kVDADecoderConfiguration_Height, height);
- CFDictionarySetValue(config_info, kVDADecoderConfiguration_Width, width);
- CFDictionarySetValue(config_info, kVDADecoderConfiguration_SourceFormat,
format);
- CFDictionarySetValue(config_info, kVDADecoderConfiguration_avcCData,
avc_data);
-
- buffer_attributes = CFDictionaryCreateMutable(kCFAllocatorDefault,
- 2,
-
&kCFTypeDictionaryKeyCallBacks,
-
&kCFTypeDictionaryValueCallBacks);
- io_surface_properties = CFDictionaryCreateMutable(kCFAllocatorDefault,
- 0,
-
&kCFTypeDictionaryKeyCallBacks,
-
&kCFTypeDictionaryValueCallBacks);
- cv_pix_fmt = CFNumberCreate(kCFAllocatorDefault,
- kCFNumberSInt32Type,
- &vda_ctx->cv_pix_fmt_type);
- CFDictionarySetValue(buffer_attributes,
- kCVPixelBufferPixelFormatTypeKey,
- cv_pix_fmt);
- CFDictionarySetValue(buffer_attributes,
- kCVPixelBufferIOSurfacePropertiesKey,
- io_surface_properties);
-
- status = VDADecoderCreate(config_info,
- buffer_attributes,
- vda_decoder_callback,
- vda_ctx,
- &vda_ctx->decoder);
-
- CFRelease(height);
- CFRelease(width);
- CFRelease(format);
- CFRelease(avc_data);
- CFRelease(config_info);
- CFRelease(io_surface_properties);
- CFRelease(cv_pix_fmt);
- CFRelease(buffer_attributes);
-
- return status;
-}
-
-int ff_vda_destroy_decoder(struct vda_context *vda_ctx)
-{
- OSStatus status = kVDADecoderNoErr;
-
- if (vda_ctx->decoder)
- status = VDADecoderDestroy(vda_ctx->decoder);
-
- av_freep(&vda_ctx->priv_bitstream);
-
- return status;
-}
-
AVHWAccel ff_h264_vda_hwaccel = {
.name = "h264_vda",
.type = AVMEDIA_TYPE_VIDEO,
--
1.8.5.1
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel