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

avcodec: pass AVFrame.opaque to hwaccel release callback

With the reference counting stuff, the AVFrame structure is gone or
unreachable by the time the release function is called.
parent 9d189412
...@@ -471,9 +471,9 @@ static int Get(vlc_va_t *external, AVFrame *ff) ...@@ -471,9 +471,9 @@ static int Get(vlc_va_t *external, AVFrame *ff)
ff->opaque = surface; ff->opaque = surface;
return VLC_SUCCESS; return VLC_SUCCESS;
} }
static void Release(AVFrame *ff) static void Release(void *opaque)
{ {
vlc_va_surface_t *surface = ff->opaque; vlc_va_surface_t *surface = opaque;
surface->refcount--; surface->refcount--;
} }
......
...@@ -69,9 +69,9 @@ static int Lock(vlc_va_t *va, AVFrame *ff) ...@@ -69,9 +69,9 @@ static int Lock(vlc_va_t *va, AVFrame *ff)
return VLC_SUCCESS; return VLC_SUCCESS;
} }
static void Unlock(AVFrame *ff) static void Unlock(void *opaque)
{ {
assert((uintptr_t)ff->opaque == SURFACE_MAGIC); assert((uintptr_t)opaque == SURFACE_MAGIC);
} }
static VdpStatus Render(VdpDecoder decoder, VdpVideoSurface target, static VdpStatus Render(VdpDecoder decoder, VdpVideoSurface target,
......
...@@ -38,7 +38,7 @@ struct vlc_va_t { ...@@ -38,7 +38,7 @@ struct vlc_va_t {
int (*setup)(vlc_va_t *, void **hw, vlc_fourcc_t *output, int (*setup)(vlc_va_t *, void **hw, vlc_fourcc_t *output,
int width, int height); int width, int height);
int (*get)(vlc_va_t *, AVFrame *frame); int (*get)(vlc_va_t *, AVFrame *frame);
void (*release)(AVFrame *frame); void (*release)(void *opaque);
int (*extract)(vlc_va_t *, picture_t *dst, AVFrame *src); int (*extract)(vlc_va_t *, picture_t *dst, AVFrame *src);
}; };
...@@ -86,15 +86,17 @@ static inline int vlc_va_Get(vlc_va_t *va, AVFrame *frame) ...@@ -86,15 +86,17 @@ static inline int vlc_va_Get(vlc_va_t *va, AVFrame *frame)
* Releases a hardware surface from a libavcodec frame. * Releases a hardware surface from a libavcodec frame.
* The surface has been previously allocated with vlc_va_Get(). * The surface has been previously allocated with vlc_va_Get().
* *
* @param opaque opaque data pointer of the AVFrame passed to vlc_va_Get().
*
* @note This function needs not be reentrant. However it may be called * @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 * concurrently with vlc_va_Get() and/or vlc_va_Extract() from other threads
* and other frames. * and other frames.
* *
* @param frame libavcodec frame previously allocated by vlc_va_Get() * @param frame libavcodec frame previously allocated by vlc_va_Get()
*/ */
static inline void vlc_va_Release(vlc_va_t *va, AVFrame *frame) static inline void vlc_va_Release(vlc_va_t *va, void *opaque)
{ {
va->release(frame); va->release(opaque);
} }
/** /**
......
...@@ -518,9 +518,9 @@ static int Get( vlc_va_t *va, AVFrame *p_ff ) ...@@ -518,9 +518,9 @@ static int Get( vlc_va_t *va, AVFrame *p_ff )
return VLC_SUCCESS; return VLC_SUCCESS;
} }
static void Release( AVFrame *p_ff ) static void Release( void *opaque )
{ {
vlc_va_surface_t *p_surface = p_ff->opaque; vlc_va_surface_t *p_surface = opaque;
vlc_mutex_lock( p_surface->p_lock ); vlc_mutex_lock( p_surface->p_lock );
p_surface->i_refcount--; p_surface->i_refcount--;
......
...@@ -254,12 +254,15 @@ static int Extract( vlc_va_t *external, picture_t *p_picture, AVFrame *p_ff ) ...@@ -254,12 +254,15 @@ static int Extract( vlc_va_t *external, picture_t *p_picture, AVFrame *p_ff )
return VLC_SUCCESS; return VLC_SUCCESS;
} }
static void Release( AVFrame *p_ff ) static void Release( void *opaque )
{ {
assert( opaque == NULL );
#if 0
CVPixelBufferRef cv_buffer = ( CVPixelBufferRef )p_ff->data[3]; CVPixelBufferRef cv_buffer = ( CVPixelBufferRef )p_ff->data[3];
if ( cv_buffer ) if ( cv_buffer )
CVPixelBufferRelease( cv_buffer ); CVPixelBufferRelease( cv_buffer );
#endif
} }
static void Close( vlc_va_t *external ) static void Close( vlc_va_t *external )
......
...@@ -897,14 +897,14 @@ static void ffmpeg_CopyPicture( decoder_t *p_dec, ...@@ -897,14 +897,14 @@ static void ffmpeg_CopyPicture( decoder_t *p_dec,
typedef struct typedef struct
{ {
vlc_va_t *va; vlc_va_t *va;
AVFrame *frame; void *opaque;
} lavc_hw_ref_t; } lavc_hw_ref_t;
static void lavc_va_ReleaseFrame(void *opaque, uint8_t *data) static void lavc_va_ReleaseFrame(void *opaque, uint8_t *data)
{ {
lavc_hw_ref_t *ref = opaque; lavc_hw_ref_t *ref = opaque;
vlc_va_Release(ref->va, ref->frame); vlc_va_Release(ref->va, ref->opaque);
free(ref); free(ref);
(void) data; (void) data;
} }
...@@ -931,11 +931,11 @@ static int lavc_va_GetFrame(struct AVCodecContext *ctx, AVFrame *frame, ...@@ -931,11 +931,11 @@ static int lavc_va_GetFrame(struct AVCodecContext *ctx, AVFrame *frame,
lavc_hw_ref_t *ref = malloc(sizeof (*ref)); lavc_hw_ref_t *ref = malloc(sizeof (*ref));
if (unlikely(ref == NULL)) if (unlikely(ref == NULL))
{ {
vlc_va_Release(va, frame); vlc_va_Release(va, frame->opaque);
return -1; return -1;
} }
ref->va = va; ref->va = va;
ref->frame = frame; ref->opaque = frame->opaque;
frame->buf[0] = av_buffer_create(frame->data[0], 0, lavc_va_ReleaseFrame, frame->buf[0] = av_buffer_create(frame->data[0], 0, lavc_va_ReleaseFrame,
ref, 0); ref, 0);
...@@ -1262,7 +1262,7 @@ static void ffmpeg_ReleaseFrameBuf( struct AVCodecContext *p_context, ...@@ -1262,7 +1262,7 @@ static void ffmpeg_ReleaseFrameBuf( struct AVCodecContext *p_context,
decoder_sys_t *p_sys = p_dec->p_sys; decoder_sys_t *p_sys = p_dec->p_sys;
if( p_sys->p_va ) if( p_sys->p_va )
vlc_va_Release( p_sys->p_va, p_ff_pic ); vlc_va_Release( p_sys->p_va, p_ff_pic->opaque );
else if( p_ff_pic->opaque ) else if( p_ff_pic->opaque )
decoder_UnlinkPicture( p_dec, (picture_t*)p_ff_pic->opaque); decoder_UnlinkPicture( p_dec, (picture_t*)p_ff_pic->opaque);
else if( p_ff_pic->type == FF_BUFFER_TYPE_INTERNAL ) else if( p_ff_pic->type == FF_BUFFER_TYPE_INTERNAL )
......
...@@ -91,9 +91,9 @@ static int Lock(vlc_va_t *va, AVFrame *ff) ...@@ -91,9 +91,9 @@ static int Lock(vlc_va_t *va, AVFrame *ff)
return VLC_SUCCESS; return VLC_SUCCESS;
} }
static void Unlock(AVFrame *ff) static void Unlock(void *opaque)
{ {
vlc_vdp_video_field_t *field = ff->opaque; vlc_vdp_video_field_t *field = opaque;
assert(field != NULL); assert(field != NULL);
field->destroy(field); field->destroy(field);
......
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