Commit b13bd5a2 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

avcodec: pass data pointer to hwaccel release callbacks and simplify

parent 458ba518
......@@ -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);
......
......@@ -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,
......
......@@ -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);
}
/**
......
......@@ -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 )
......
......@@ -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 )
......
......@@ -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 )
......
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment