Commit 47467b96 authored by Thomas Guillem's avatar Thomas Guillem

decoder: video: don't update format when creating a picture

Decoder modules are now responsible for calling decoder_UpdateVideoFormat()
before decoder_NewPicture().

In a lot of modules, decoder_UpdateVideoFormat() could be called in a better
place. Just after dec->fmt_out is updated for example.
parent a70366e6
......@@ -247,29 +247,9 @@ static inline int decoder_UpdateVideoFormat( decoder_t *dec )
* \return a picture buffer on success, NULL on error
*/
VLC_USED
static inline picture_t *decoder_GetPicture( decoder_t *dec )
{
return dec->pf_vout_buffer_new( dec );
}
/**
* Checks the format and allocates a picture buffer.
*
* This common helper function sets the output video output format and
* allocates a picture buffer in that format. The picture must be released with
* picture_Release() when it is no longer referenced by the decoder.
*
* \note
* Lile decoder_UpdateVideoFormat(), this function is not reentrant.
*
* \return a picture buffer on success, NULL on error
*/
VLC_USED
static inline picture_t *decoder_NewPicture( decoder_t *dec )
{
if( decoder_UpdateVideoFormat(dec) )
return NULL;
return decoder_GetPicture( dec );
return dec->pf_vout_buffer_new( dec );
}
/**
......
......@@ -142,6 +142,8 @@ static picture_t *Decode(decoder_t *dec, block_t **pp_block)
dec->fmt_out.video.i_sar_den = 1;
}
if (decoder_UpdateVideoFormat(dec))
return NULL;
picture_t *pic = decoder_NewPicture(dec);
if (!pic)
return NULL;
......
......@@ -913,7 +913,7 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
if (p_sys->p_va == NULL
&& lavc_UpdateVideoFormat(p_dec, p_context, p_context->pix_fmt,
p_context->pix_fmt) == 0)
p_pic = decoder_GetPicture(p_dec);
p_pic = decoder_NewPicture(p_dec);
if( !p_pic )
{
......@@ -1210,7 +1210,7 @@ static int lavc_GetFrame(struct AVCodecContext *ctx, AVFrame *frame, int flags)
}
post_mt(sys);
pic = decoder_GetPicture(dec);
pic = decoder_NewPicture(dec);
if (pic == NULL)
return -ENOMEM;
......@@ -1308,7 +1308,7 @@ static enum PixelFormat ffmpeg_GetFormat( AVCodecContext *p_context,
continue; /* Unsupported brand of hardware acceleration */
post_mt(p_sys);
picture_t *test_pic = decoder_GetPicture(p_dec);
picture_t *test_pic = decoder_NewPicture(p_dec);
assert(!test_pic || test_pic->format.i_chroma == p_dec->fmt_out.video.i_chroma);
vlc_va_t *va = vlc_va_New(VLC_OBJECT(p_dec), p_context, hwfmt,
&p_dec->fmt_in,
......
......@@ -134,6 +134,10 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
p_dec->fmt_out.video.i_sar_den = 1;
/* Get a new picture */
if( decoder_UpdateVideoFormat( p_dec ) )
{
goto error;
}
p_pic = decoder_NewPicture( p_dec );
if( !p_pic )
{
......
......@@ -173,6 +173,8 @@ static picture_t *Decode( decoder_t *p_dec, block_t **pp_block )
if( (p_sys->i_packet%3) == 1 && p_block->i_pts == p_block->i_dts )
{
/* Get a new picture */
if( decoder_UpdateVideoFormat( p_dec ) )
goto exit;
p_pic = decoder_NewPicture( p_dec );
if( !p_pic )
goto exit;
......
......@@ -400,7 +400,10 @@ static BC_STATUS ourCallback(void *shnd, uint32_t width, uint32_t height, uint32
/* Do not allocate for the second-field in the pair, in interlaced */
if( !(proc_in->PicInfo.flags & VDEC_FLAG_INTERLACED_SRC) ||
!(proc_in->PicInfo.flags & VDEC_FLAG_FIELDPAIR) )
p_dec->p_sys->p_pic = decoder_NewPicture( p_dec );
{
if( !decoder_UpdateVideoFormat( p_dec ) )
p_dec->p_sys->p_pic = decoder_NewPicture( p_dec );
}
/* */
picture_t *p_pic = p_dec->p_sys->p_pic;
......
......@@ -467,6 +467,8 @@ static picture_t *DecodePacket( decoder_t *p_dec, daala_packet *p_dpacket )
p_sys->b_decoded_first_keyframe = true;
/* Get a new picture */
if( decoder_UpdateVideoFormat( p_dec ) )
return NULL;
p_pic = decoder_NewPicture( p_dec );
if( !p_pic ) return NULL;
......
......@@ -957,6 +957,8 @@ static void *DecBlock( decoder_t *p_dec, block_t **pp_block )
if( p_dec->fmt_out.i_cat == VIDEO_ES )
{
/* Get a new picture */
if( decoder_UpdateVideoFormat( p_dec ) )
return NULL;
picture_t *p_pic = decoder_NewPicture( p_dec );
if( !p_pic ) return NULL;
......
......@@ -784,6 +784,8 @@ check_messages:
GstVideoFrame frame;
/* Get a new picture */
if( decoder_UpdateVideoFormat( p_dec ) )
goto done;
p_pic = decoder_NewPicture( p_dec );
if( !p_pic )
goto done;
......
......@@ -159,12 +159,13 @@ void gst_vlc_picture_plane_allocator_release(
bool gst_vlc_picture_plane_allocator_hold(
GstVlcPicturePlaneAllocator *p_allocator, GstBuffer *p_buffer )
{
picture_t* p_pic;
picture_t* p_pic = NULL;
decoder_t* p_dec = p_allocator->p_dec;
GstVlcPicturePlane *p_mem;
int i_plane;
p_pic = decoder_NewPicture( p_dec );
if( !decoder_UpdateVideoFormat( p_dec ) )
p_pic = decoder_NewPicture( p_dec );
if( !p_pic )
{
msg_Err( p_allocator->p_dec, "failed to acquire picture from vout" );
......@@ -253,7 +254,7 @@ static bool gst_vlc_video_info_from_vout( GstVideoInfo *p_info,
picture_t *p_pic_info )
{
const GstVideoFormatInfo *p_vinfo = p_info->finfo;
picture_t *p_pic;
picture_t *p_pic = NULL;
int i;
/* Ensure the queue is empty */
......@@ -269,7 +270,8 @@ static bool gst_vlc_video_info_from_vout( GstVideoInfo *p_info,
/* Acquire a picture and release it. This is to get the picture
* stride/offsets info for the Gstreamer decoder looking to use
* downstream bufferpool directly; Zero-Copy */
p_pic = decoder_NewPicture( p_dec );
if( !decoder_UpdateVideoFormat( p_dec ) )
p_pic = decoder_NewPicture( p_dec );
if( !p_pic )
{
msg_Err( p_dec, "failed to acquire picture from vout; for pic info" );
......
......@@ -455,6 +455,10 @@ static picture_t *DecodeBlock(decoder_t *p_dec, block_t **pp_block)
}
/* Get a new picture */
if (decoder_UpdateVideoFormat(p_dec))
{
goto error;
}
p_pic = decoder_NewPicture(p_dec);
if (!p_pic)
{
......
......@@ -658,6 +658,8 @@ static picture_t *GetNewPicture( decoder_t *p_dec )
VLC_CODEC_I420 : VLC_CODEC_I422;
/* Get a new picture */
if( decoder_UpdateVideoFormat( p_dec ) )
return NULL;
p_pic = decoder_NewPicture( p_dec );
if( p_pic == NULL )
......
......@@ -676,6 +676,8 @@ static int ProcessOutputStream(decoder_t *p_dec, DWORD stream_id, void **result)
if (p_dec->fmt_in.i_cat == VIDEO_ES)
{
if (decoder_UpdateVideoFormat(p_dec))
return VLC_SUCCESS;
picture = decoder_NewPicture(p_dec);
if (!picture)
return VLC_SUCCESS;
......
......@@ -1384,6 +1384,8 @@ static int DecodeVideoOutput( decoder_t *p_dec, OmxPort *p_port, picture_t **pp_
p_port->b_update_def = 0;
CHECK_ERROR(omx_error, "GetPortDefinition failed");
}
if( decoder_UpdateVideoFormat( p_dec ) )
goto error;
if( p_port->p_hwbuf )
{
......@@ -1621,7 +1623,9 @@ static picture_t *DecodeVideo( decoder_t *p_dec, block_t **pp_block )
playback is paused. */
if( p_sys->out.p_hwbuf && attempts == max_polling_attempts ) {
#ifdef USE_IOMX
picture_t *invalid_picture = decoder_NewPicture(p_dec);
picture_t *invalid_picture = NULL;
if( !decoder_UpdateVideoFormat(p_dec))
invalid_picture = decoder_NewPicture(p_dec);
if (invalid_picture) {
invalid_picture->date = VLC_TS_INVALID;
picture_sys_t *p_picsys = invalid_picture->p_sys;
......
......@@ -276,6 +276,8 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
}
/* Get a new picture */
if( decoder_UpdateVideoFormat( p_dec ) )
goto error;
p_pic = decoder_NewPicture( p_dec );
if( !p_pic ) goto error;
......
......@@ -227,7 +227,9 @@ static picture_t *DecodeFrame( decoder_t *p_dec, block_t **pp_block )
decoder_sys_t *p_sys = p_dec->p_sys;
/* Get a new picture */
picture_t *p_pic = decoder_NewPicture( p_dec );
picture_t *p_pic = NULL;
if( !decoder_UpdateVideoFormat( p_dec ) )
p_pic = decoder_NewPicture( p_dec );
if( p_pic == NULL )
{
block_Release( p_block );
......
......@@ -666,6 +666,8 @@ static SchroFrame *CreateSchroFrameFromPic( decoder_t *p_dec )
if( !p_schroframe )
return NULL;
if( decoder_UpdateVideoFormat( p_dec ) )
return NULL;
p_pic = decoder_NewPicture( p_dec );
if( !p_pic )
......
......@@ -177,6 +177,8 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
p_dec->fmt_out.video.i_sar_den = 1;
/* Get a new picture. */
if( decoder_UpdateVideoFormat( p_dec ) )
goto error;
p_pic = decoder_NewPicture( p_dec );
if ( p_pic == NULL ) goto error;
......
......@@ -193,6 +193,8 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
video_format_FixRgb(&p_dec->fmt_out.video);
/* Get a new picture */
if( decoder_UpdateVideoFormat( p_dec ) )
goto done;
p_pic = decoder_NewPicture( p_dec );
if( !p_pic )
goto done;
......
......@@ -521,6 +521,8 @@ static picture_t *DecodePacket( decoder_t *p_dec, ogg_packet *p_oggpacket )
return NULL;
/* Get a new picture */
if( decoder_UpdateVideoFormat( p_dec ) )
return NULL;
p_pic = decoder_NewPicture( p_dec );
if( !p_pic ) return NULL;
......
......@@ -169,6 +169,8 @@ static picture_t *Decode(decoder_t *dec, block_t **pp_block)
dec->fmt_out.video.i_sar_den = 1;
}
if (decoder_UpdateVideoFormat(dec))
return NULL;
picture_t *pic = decoder_NewPicture(dec);
if (!pic)
return NULL;
......
......@@ -134,6 +134,8 @@ static picture_t *Decode (decoder_t *dec, block_t **pp)
|| (block->i_buffer / pitch) < dec->fmt_out.video.i_height)
goto drop;
if (decoder_UpdateVideoFormat(dec))
goto drop;
pic = decoder_NewPicture(dec);
if (pic == NULL)
goto drop;
......
......@@ -426,7 +426,7 @@ static int send_output_buffer(decoder_t *dec)
decoder_sys_t *sys = dec->p_sys;
MMAL_BUFFER_HEADER_T *buffer;
picture_sys_t *p_sys;
picture_t *picture;
picture_t *picture = NULL;
MMAL_STATUS_T status;
unsigned buffer_size = 0;
int ret = 0;
......@@ -444,7 +444,8 @@ static int send_output_buffer(decoder_t *dec)
}
}
picture = decoder_NewPicture(dec);
if (!decoder_UpdateVideoFormat(dec))
picture = decoder_NewPicture(dec);
if (!picture) {
msg_Warn(dec, "Failed to get new picture");
ret = -1;
......
......@@ -48,7 +48,8 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
if( !pp_block || !*pp_block ) return NULL;
p_block = *pp_block;
p_pic = decoder_NewPicture( p_dec );
if( !decoder_UpdateVideoFormat( p_dec ) )
p_pic = decoder_NewPicture( p_dec );
if( !p_pic )
goto error;
......
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