vlc | branch: master | Rémi Denis-Courmont <[email protected]> | Thu Jul 25 18:45:24 2013 +0300| [b13bd5a2896150fecc6260635dddc211f61532b5] | committer: Rémi Denis-Courmont
avcodec: pass data pointer to hwaccel release callbacks and simplify > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=b13bd5a2896150fecc6260635dddc211f61532b5 --- modules/codec/avcodec/dxva2.c | 5 ++++- modules/codec/avcodec/hwdummy.c | 22 ++++++++++++---------- modules/codec/avcodec/va.h | 9 +++++---- modules/codec/avcodec/vaapi.c | 3 ++- modules/codec/avcodec/vda.c | 3 ++- modules/codec/avcodec/video.c | 32 ++++---------------------------- modules/hw/vdpau/avcodec.c | 3 ++- 7 files changed, 31 insertions(+), 46 deletions(-) diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c index d33b571..5d8cd19 100644 --- a/modules/codec/avcodec/dxva2.c +++ b/modules/codec/avcodec/dxva2.c @@ -471,12 +471,15 @@ static int Get(vlc_va_t *external, AVFrame *ff) ff->opaque = surface; return VLC_SUCCESS; } -static void Release(void *opaque) + +static void Release(void *opaque, uint8_t *data) { vlc_va_surface_t *surface = opaque; surface->refcount--; + (void) data; } + static void Close(vlc_va_t *external) { vlc_va_dxva2_t *va = vlc_va_dxva2_Get(external); diff --git a/modules/codec/avcodec/hwdummy.c b/modules/codec/avcodec/hwdummy.c index ead7ccd..83b56e0 100644 --- a/modules/codec/avcodec/hwdummy.c +++ b/modules/codec/avcodec/hwdummy.c @@ -47,8 +47,9 @@ vlc_module_begin() add_shortcut("dummy") vlc_module_end() -#define DECODER_MAGIC 0x12345678 -#define SURFACE_MAGIC 0x87654321 +#define DECODER_MAGIC 0xdec0dea0 +#define DATA_MAGIC 0xda1a0000 +#define OPAQUE_MAGIC 0x0da00e00 struct vlc_va_sys_t { @@ -63,15 +64,16 @@ static int Lock(vlc_va_t *va, AVFrame *ff) ff->linesize[i] = 0; } - ff->data[0] = (void *)(uintptr_t)SURFACE_MAGIC; /* must be non-NULL */ - ff->data[3] = (void *)(uintptr_t)SURFACE_MAGIC; - ff->opaque = (void *)(uintptr_t)SURFACE_MAGIC; + ff->data[0] = (void *)(uintptr_t)DATA_MAGIC; /* must be non-NULL */ + ff->data[3] = (void *)(uintptr_t)DATA_MAGIC; + ff->opaque = (void *)(uintptr_t)OPAQUE_MAGIC; return VLC_SUCCESS; } -static void Unlock(void *opaque) +static void Unlock(void *opaque, uint8_t *data) { - assert((uintptr_t)opaque == SURFACE_MAGIC); + assert((uintptr_t)opaque == OPAQUE_MAGIC); + assert((uintptr_t)data == DATA_MAGIC); } static VdpStatus Render(VdpDecoder decoder, VdpVideoSurface target, @@ -82,7 +84,7 @@ static VdpStatus Render(VdpDecoder decoder, VdpVideoSurface target, (void) decoder; (void) target; (void) picture_info; (void) bitstream_buffer_count; (void) bitstream_buffers; assert(decoder == DECODER_MAGIC); - assert(target == SURFACE_MAGIC); + assert(target == DATA_MAGIC); return VDP_STATUS_OK; } @@ -90,8 +92,8 @@ static int Copy(vlc_va_t *va, picture_t *pic, AVFrame *ff) { (void) va; (void) ff; - assert((uintptr_t)ff->data[3] == SURFACE_MAGIC); - assert((uintptr_t)ff->opaque == SURFACE_MAGIC); + assert((uintptr_t)ff->data[3] == DATA_MAGIC); + assert((uintptr_t)ff->opaque == OPAQUE_MAGIC); /* Put some dummy picture content */ memset(pic->p[0].p_pixels, 0xF0, diff --git a/modules/codec/avcodec/va.h b/modules/codec/avcodec/va.h index 128942c..ddbf9ce 100644 --- a/modules/codec/avcodec/va.h +++ b/modules/codec/avcodec/va.h @@ -38,7 +38,7 @@ struct vlc_va_t { int (*setup)(vlc_va_t *, void **hw, vlc_fourcc_t *output, int width, int height); int (*get)(vlc_va_t *, AVFrame *frame); - void (*release)(void *opaque); + void (*release)(void *opaque, uint8_t *surface); int (*extract)(vlc_va_t *, picture_t *dst, AVFrame *src); }; @@ -86,7 +86,8 @@ static inline int vlc_va_Get(vlc_va_t *va, AVFrame *frame) * Releases a hardware surface from a libavcodec frame. * The surface has been previously allocated with vlc_va_Get(). * - * @param opaque opaque data pointer of the AVFrame passed to vlc_va_Get(). + * @param opaque opaque data pointer of the AVFrame set by vlc_va_Get() + * @param data data[0] pointer of the AVFrame set by vlc_va_Get() * * @note This function needs not be reentrant. However it may be called * concurrently with vlc_va_Get() and/or vlc_va_Extract() from other threads @@ -94,9 +95,9 @@ static inline int vlc_va_Get(vlc_va_t *va, AVFrame *frame) * * @param frame libavcodec frame previously allocated by vlc_va_Get() */ -static inline void vlc_va_Release(vlc_va_t *va, void *opaque) +static inline void vlc_va_Release(vlc_va_t *va, void *opaque, uint8_t *data) { - va->release(opaque); + va->release(opaque, data); } /** diff --git a/modules/codec/avcodec/vaapi.c b/modules/codec/avcodec/vaapi.c index df3fc4a..7b40c3e 100644 --- a/modules/codec/avcodec/vaapi.c +++ b/modules/codec/avcodec/vaapi.c @@ -518,13 +518,14 @@ static int Get( vlc_va_t *va, AVFrame *p_ff ) return VLC_SUCCESS; } -static void Release( void *opaque ) +static void Release( void *opaque, uint8_t *data ) { vlc_va_surface_t *p_surface = opaque; vlc_mutex_lock( p_surface->p_lock ); p_surface->i_refcount--; vlc_mutex_unlock( p_surface->p_lock ); + (void) data; } static void Close( vlc_va_sys_t *sys ) diff --git a/modules/codec/avcodec/vda.c b/modules/codec/avcodec/vda.c index faddbe7..695d08c 100644 --- a/modules/codec/avcodec/vda.c +++ b/modules/codec/avcodec/vda.c @@ -255,7 +255,7 @@ static int Extract( vlc_va_t *external, picture_t *p_picture, AVFrame *p_ff ) return VLC_SUCCESS; } -static void Release( void *opaque ) +static void Release( void *opaque, uint8_t *data ) { assert( opaque == NULL ); #if 0 @@ -264,6 +264,7 @@ static void Release( void *opaque ) if ( cv_buffer ) CVPixelBufferRelease( cv_buffer ); #endif + (void) data; } static void Close( vlc_va_t *external ) diff --git a/modules/codec/avcodec/video.c b/modules/codec/avcodec/video.c index d6a966f..b25a8d4 100644 --- a/modules/codec/avcodec/video.c +++ b/modules/codec/avcodec/video.c @@ -894,21 +894,6 @@ static void ffmpeg_CopyPicture( decoder_t *p_dec, } #if LIBAVCODEC_VERSION_MAJOR >= 55 -typedef struct -{ - vlc_va_t *va; - void *opaque; -} lavc_hw_ref_t; - -static void lavc_va_ReleaseFrame(void *opaque, uint8_t *data) -{ - lavc_hw_ref_t *ref = opaque; - - vlc_va_Release(ref->va, ref->opaque); - free(ref); - (void) data; -} - static int lavc_va_GetFrame(struct AVCodecContext *ctx, AVFrame *frame, int flags) { @@ -928,20 +913,11 @@ static int lavc_va_GetFrame(struct AVCodecContext *ctx, AVFrame *frame, return -1; } - lavc_hw_ref_t *ref = malloc(sizeof (*ref)); - if (unlikely(ref == NULL)) - { - vlc_va_Release(va, frame->opaque); - return -1; - } - ref->va = va; - ref->opaque = frame->opaque; - - frame->buf[0] = av_buffer_create(frame->data[0], 0, lavc_va_ReleaseFrame, - ref, 0); + frame->buf[0] = av_buffer_create(frame->data[0], 0, va->release, + frame->opaque, 0); if (unlikely(frame->buf[0] == NULL)) { - lavc_va_ReleaseFrame(ref, frame->data[0]); + vlc_va_Release(va, frame->opaque, frame->data[0]); return -1; } assert(frame->data[0] != NULL); @@ -1262,7 +1238,7 @@ static void ffmpeg_ReleaseFrameBuf( struct AVCodecContext *p_context, decoder_sys_t *p_sys = p_dec->p_sys; if( p_sys->p_va ) - vlc_va_Release( p_sys->p_va, p_ff_pic->opaque ); + vlc_va_Release( p_sys->p_va, p_ff_pic->opaque, p_ff_pic->data[0] ); else if( p_ff_pic->opaque ) decoder_UnlinkPicture( p_dec, (picture_t*)p_ff_pic->opaque); else if( p_ff_pic->type == FF_BUFFER_TYPE_INTERNAL ) diff --git a/modules/hw/vdpau/avcodec.c b/modules/hw/vdpau/avcodec.c index 8c027d3..07028b6 100644 --- a/modules/hw/vdpau/avcodec.c +++ b/modules/hw/vdpau/avcodec.c @@ -91,12 +91,13 @@ static int Lock(vlc_va_t *va, AVFrame *ff) return VLC_SUCCESS; } -static void Unlock(void *opaque) +static void Unlock(void *opaque, uint8_t *data) { vlc_vdp_video_field_t *field = opaque; assert(field != NULL); field->destroy(field); + (void) data; } static int Copy(vlc_va_t *va, picture_t *pic, AVFrame *ff) _______________________________________________ vlc-commits mailing list [email protected] http://mailman.videolan.org/listinfo/vlc-commits
