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

avcodec: simplify hwaccel picture release

parent 30cb3147
...@@ -488,6 +488,7 @@ static void Release(void *opaque, uint8_t *data) ...@@ -488,6 +488,7 @@ static void Release(void *opaque, uint8_t *data)
surface->refcount--; surface->refcount--;
pic->context = NULL; pic->context = NULL;
picture_Release(pic);
(void) data; (void) data;
} }
......
...@@ -391,6 +391,7 @@ static void Release( void *opaque, uint8_t *data ) ...@@ -391,6 +391,7 @@ static void Release( void *opaque, uint8_t *data )
vlc_mutex_unlock( p_surface->p_lock ); vlc_mutex_unlock( p_surface->p_lock );
pic->context = NULL; pic->context = NULL;
picture_Release(pic);
(void) data; (void) data;
} }
......
...@@ -307,7 +307,8 @@ static void Release( void *opaque, uint8_t *data ) ...@@ -307,7 +307,8 @@ static void Release( void *opaque, uint8_t *data )
if ( cv_buffer ) if ( cv_buffer )
CVPixelBufferRelease( cv_buffer ); CVPixelBufferRelease( cv_buffer );
#endif #endif
(void) opaque; (void) data; picture_Release(opaque);
(void) data;
} }
#else #else
...@@ -385,7 +386,8 @@ static int Extract( vlc_va_t *va, picture_t *p_picture, uint8_t *data ) ...@@ -385,7 +386,8 @@ static int Extract( vlc_va_t *va, picture_t *p_picture, uint8_t *data )
static void Release( void *opaque, uint8_t *data ) static void Release( void *opaque, uint8_t *data )
{ {
(void) opaque; (void) data; picture_Release(opaque);
(void) data;
} }
#endif #endif
...@@ -84,12 +84,6 @@ struct decoder_sys_t ...@@ -84,12 +84,6 @@ struct decoder_sys_t
vlc_sem_t sem_mt; vlc_sem_t sem_mt;
}; };
typedef struct
{
vlc_va_t *va;
picture_t *pic;
} lavc_va_picture_t;
#ifdef HAVE_AVCODEC_MT #ifdef HAVE_AVCODEC_MT
# define wait_mt(s) vlc_sem_wait( &s->sem_mt ) # define wait_mt(s) vlc_sem_wait( &s->sem_mt )
# define post_mt(s) vlc_sem_post( &s->sem_mt ) # define post_mt(s) vlc_sem_post( &s->sem_mt )
...@@ -654,7 +648,6 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block ) ...@@ -654,7 +648,6 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
while( !p_block || p_block->i_buffer > 0 || p_sys->b_flush ) while( !p_block || p_block->i_buffer > 0 || p_sys->b_flush )
{ {
int i_used, b_gotpicture; int i_used, b_gotpicture;
picture_t *p_pic;
AVPacket pkt; AVPacket pkt;
post_mt( p_sys ); post_mt( p_sys );
...@@ -791,7 +784,8 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block ) ...@@ -791,7 +784,8 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
if( !b_drawpicture || ( !p_sys->p_va && !p_sys->p_ff_pic->linesize[0] ) ) if( !b_drawpicture || ( !p_sys->p_va && !p_sys->p_ff_pic->linesize[0] ) )
continue; continue;
if( p_sys->p_ff_pic->opaque == NULL ) picture_t *p_pic = p_sys->p_ff_pic->opaque;
if( p_pic == NULL )
{ {
/* Get a new picture */ /* Get a new picture */
if( p_sys->p_va == NULL ) if( p_sys->p_va == NULL )
...@@ -807,19 +801,11 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block ) ...@@ -807,19 +801,11 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
lavc_CopyPicture(p_dec, p_pic, p_sys->p_ff_pic); lavc_CopyPicture(p_dec, p_pic, p_sys->p_ff_pic);
} }
else else
if( p_sys->p_va != NULL )
{ {
lavc_va_picture_t *vapic = p_sys->p_ff_pic->opaque; if( p_sys->p_va != NULL )
p_pic = vapic->pic;
vlc_va_Extract( p_sys->p_va, p_pic, p_sys->p_ff_pic->data[3] ); vlc_va_Extract( p_sys->p_va, p_pic, p_sys->p_ff_pic->data[3] );
picture_Hold( p_pic ); picture_Hold( p_pic );
} }
else
{
p_pic = (picture_t *)p_sys->p_ff_pic->opaque;
picture_Hold( p_pic );
}
if( !p_dec->fmt_in.video.i_sar_num || !p_dec->fmt_in.video.i_sar_den ) if( !p_dec->fmt_in.video.i_sar_num || !p_dec->fmt_in.video.i_sar_den )
{ {
...@@ -959,15 +945,6 @@ static void ffmpeg_InitCodec( decoder_t *p_dec ) ...@@ -959,15 +945,6 @@ static void ffmpeg_InitCodec( decoder_t *p_dec )
} }
} }
static void lavc_va_ReleaseFrame(void *opaque, uint8_t *data)
{
lavc_va_picture_t *vapic = opaque;
vlc_va_Release(vapic->va, vapic->pic, data);
picture_Release(vapic->pic);
free(vapic);
}
static int lavc_va_GetFrame(struct AVCodecContext *ctx, AVFrame *frame, static int lavc_va_GetFrame(struct AVCodecContext *ctx, AVFrame *frame,
int flags) int flags)
{ {
...@@ -984,10 +961,6 @@ static int lavc_va_GetFrame(struct AVCodecContext *ctx, AVFrame *frame, ...@@ -984,10 +961,6 @@ static int lavc_va_GetFrame(struct AVCodecContext *ctx, AVFrame *frame,
if (pic == NULL) if (pic == NULL)
return -1; return -1;
lavc_va_picture_t *vapic = xmalloc(sizeof (*vapic));
vapic->va = va;
vapic->pic = pic;
if (vlc_va_Get(va, pic, &frame->data[0])) if (vlc_va_Get(va, pic, &frame->data[0]))
{ {
msg_Err(dec, "hardware acceleration picture allocation failed"); msg_Err(dec, "hardware acceleration picture allocation failed");
...@@ -998,15 +971,14 @@ static int lavc_va_GetFrame(struct AVCodecContext *ctx, AVFrame *frame, ...@@ -998,15 +971,14 @@ static int lavc_va_GetFrame(struct AVCodecContext *ctx, AVFrame *frame,
* data[3] actually contains the format-specific surface handle. */ * data[3] actually contains the format-specific surface handle. */
frame->data[3] = frame->data[0]; frame->data[3] = frame->data[0];
frame->buf[0] = av_buffer_create(frame->data[0], 0, lavc_va_ReleaseFrame, frame->buf[0] = av_buffer_create(frame->data[0], 0, va->release, pic, 0);
vapic, 0);
if (unlikely(frame->buf[0] == NULL)) if (unlikely(frame->buf[0] == NULL))
{ {
lavc_va_ReleaseFrame(vapic, frame->data[0]); vlc_va_Release(va, pic, frame->data[0]);
return -1; return -1;
} }
frame->opaque = vapic; frame->opaque = pic;
assert(frame->data[0] != NULL); assert(frame->data[0] != NULL);
(void) flags; (void) flags;
return 0; return 0;
......
...@@ -148,7 +148,8 @@ static int Lock(vlc_va_t *va, picture_t *pic, uint8_t **data) ...@@ -148,7 +148,8 @@ static int Lock(vlc_va_t *va, picture_t *pic, uint8_t **data)
static void Unlock(void *opaque, uint8_t *data) static void Unlock(void *opaque, uint8_t *data)
{ {
(void) opaque; (void) data; picture_Release(opaque);
(void) data;
} }
static int Copy(vlc_va_t *va, picture_t *pic, uint8_t *data) static int Copy(vlc_va_t *va, picture_t *pic, uint8_t *data)
......
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