Commit d49b43b6 authored by Thomas Guillem's avatar Thomas Guillem

dec: hide owner and callbacks from modules

parent 0df4762f
......@@ -41,10 +41,56 @@
* Decoder and encoder modules interface
*/
typedef struct decoder_owner_sys_t decoder_owner_sys_t;
typedef struct decoder_cc_desc_t decoder_cc_desc_t;
struct decoder_owner_callbacks
{
union
{
struct
{
int (*format_update)( decoder_t * );
/* cf. decoder_NewPicture */
picture_t* (*buffer_new)( decoder_t * );
/* cf.decoder_QueueVideo */
void (*queue)( decoder_t *, picture_t * );
/* cf.decoder_QueueCC */
void (*queue_cc)( decoder_t *, block_t *,
const decoder_cc_desc_t * );
/* Display date
* cf. decoder_GetDisplayDate */
mtime_t (*get_display_date)( decoder_t *, mtime_t );
/* Display rate
* cf. decoder_GetDisplayRate */
int (*get_display_rate)( decoder_t * );
} video;
struct
{
int (*format_update)( decoder_t * );
/* cf.decoder_QueueAudio */
void (*queue)( decoder_t *, block_t * );
} audio;
struct
{
/* cf. decoder_NewSubpicture */
subpicture_t* (*buffer_new)( decoder_t *,
const subpicture_updater_t * );
/* cf.decoder_QueueSub */
void (*queue)( decoder_t *, subpicture_t *);
} spu;
};
/* Input attachments
* cf. decoder_GetInputAttachments */
int (*get_attachments)( decoder_t *p_dec,
input_attachment_t ***ppp_attachment,
int *pi_attachment );
};
/*
* BIG FAT WARNING : the code relies in the first 4 members of filter_t
* and decoder_t to be the same, so if you have anything to add, do it
......@@ -67,6 +113,12 @@ struct decoder_t
/* Tell the decoder if it is allowed to drop frames */
bool b_frame_drop_allowed;
/**
* Number of extra (ie in addition to the DPB) picture buffers
* needed for decoding.
*/
int i_extra_picture_buffers;
# define VLCDEC_SUCCESS VLC_SUCCESS
# define VLCDEC_ECRITICAL VLC_EGENERIC
# define VLCDEC_RELOAD (-100)
......@@ -138,53 +190,8 @@ struct decoder_t
*/
vlc_meta_t *p_description;
/*
* Owner fields
* XXX You MUST not use them directly.
*/
/* Video output callbacks
* XXX use decoder_NewPicture */
int (*pf_vout_format_update)( decoder_t * );
picture_t *(*pf_vout_buffer_new)( decoder_t * );
/**
* Number of extra (ie in addition to the DPB) picture buffers
* needed for decoding.
*/
int i_extra_picture_buffers;
/* Audio output callbacks */
int (*pf_aout_format_update)( decoder_t * );
/* SPU output callbacks
* XXX use decoder_NewSubpicture */
subpicture_t *(*pf_spu_buffer_new)( decoder_t *, const subpicture_updater_t * );
/* Input attachments
* XXX use decoder_GetInputAttachments */
int (*pf_get_attachments)( decoder_t *p_dec, input_attachment_t ***ppp_attachment, int *pi_attachment );
/* Display date
* XXX use decoder_GetDisplayDate */
mtime_t (*pf_get_display_date)( decoder_t *, mtime_t );
/* Display rate
* XXX use decoder_GetDisplayRate */
int (*pf_get_display_rate)( decoder_t * );
/* XXX use decoder_QueueVideo or decoder_QueueVideoWithCc */
void (*pf_queue_video)( decoder_t *, picture_t * );
/* XXX use decoder_QueueAudio */
void (*pf_queue_audio)( decoder_t *, block_t * );
/* XXX use decoder_QueueCC */
void (*pf_queue_cc)( decoder_t *, block_t *, const decoder_cc_desc_t * );
/* XXX use decoder_QueueSub */
void (*pf_queue_sub)( decoder_t *, subpicture_t *);
void *p_queue_ctx;
/* Private structure for the owner of the decoder */
decoder_owner_sys_t *p_owner;
const struct decoder_owner_callbacks *cbs;
};
/* struct for packetizer get_cc polling/decoder queue_cc
......@@ -260,9 +267,9 @@ struct encoder_t
VLC_USED
static inline int decoder_UpdateVideoFormat( decoder_t *dec )
{
assert( dec->fmt_in.i_cat == VIDEO_ES );
if( dec->fmt_in.i_cat == VIDEO_ES && dec->pf_vout_format_update != NULL )
return dec->pf_vout_format_update( dec );
assert( dec->fmt_in.i_cat == VIDEO_ES && dec->cbs != NULL );
if( dec->fmt_in.i_cat == VIDEO_ES && dec->cbs->video.format_update != NULL )
return dec->cbs->video.format_update( dec );
else
return -1;
}
......@@ -287,7 +294,8 @@ static inline int decoder_UpdateVideoFormat( decoder_t *dec )
VLC_USED
static inline picture_t *decoder_NewPicture( decoder_t *dec )
{
return dec->pf_vout_buffer_new( dec );
assert( dec->fmt_in.i_cat == VIDEO_ES && dec->cbs != NULL );
return dec->cbs->video.buffer_new( dec );
}
/**
......@@ -309,9 +317,10 @@ VLC_API void decoder_AbortPictures( decoder_t *dec, bool b_abort );
*/
static inline void decoder_QueueVideo( decoder_t *dec, picture_t *p_pic )
{
assert( dec->fmt_in.i_cat == VIDEO_ES && dec->cbs != NULL );
assert( p_pic->p_next == NULL );
assert( dec->pf_queue_video != NULL );
dec->pf_queue_video( dec, p_pic );
assert( dec->cbs->video.queue != NULL );
dec->cbs->video.queue( dec, p_pic );
}
/**
......@@ -324,10 +333,11 @@ static inline void decoder_QueueVideo( decoder_t *dec, picture_t *p_pic )
static inline void decoder_QueueCc( decoder_t *dec, block_t *p_cc,
const decoder_cc_desc_t *p_desc )
{
if( dec->pf_queue_cc == NULL )
assert( dec->fmt_in.i_cat == VIDEO_ES && dec->cbs != NULL );
if( dec->cbs->video.queue_cc == NULL )
block_Release( p_cc );
else
dec->pf_queue_cc( dec, p_cc, p_desc );
dec->cbs->video.queue_cc( dec, p_cc, p_desc );
}
/**
......@@ -339,9 +349,10 @@ static inline void decoder_QueueCc( decoder_t *dec, block_t *p_cc,
*/
static inline void decoder_QueueAudio( decoder_t *dec, block_t *p_aout_buf )
{
assert( dec->fmt_in.i_cat == AUDIO_ES && dec->cbs != NULL );
assert( p_aout_buf->p_next == NULL );
assert( dec->pf_queue_audio != NULL );
dec->pf_queue_audio( dec, p_aout_buf );
assert( dec->cbs->audio.queue != NULL );
dec->cbs->audio.queue( dec, p_aout_buf );
}
/**
......@@ -353,9 +364,10 @@ static inline void decoder_QueueAudio( decoder_t *dec, block_t *p_aout_buf )
*/
static inline void decoder_QueueSub( decoder_t *dec, subpicture_t *p_spu )
{
assert( dec->fmt_in.i_cat == SPU_ES && dec->cbs != NULL );
assert( p_spu->p_next == NULL );
assert( dec->pf_queue_sub != NULL );
dec->pf_queue_sub( dec, p_spu );
assert( dec->cbs->spu.queue != NULL );
dec->cbs->spu.queue( dec, p_spu );
}
/**
......@@ -366,9 +378,9 @@ static inline void decoder_QueueSub( decoder_t *dec, subpicture_t *p_spu )
VLC_USED
static inline int decoder_UpdateAudioFormat( decoder_t *dec )
{
assert(dec->fmt_in.i_cat == AUDIO_ES);
if( dec->fmt_in.i_cat == AUDIO_ES && dec->pf_aout_format_update != NULL )
return dec->pf_aout_format_update( dec );
assert( dec->fmt_in.i_cat == AUDIO_ES && dec->cbs != NULL );
if( dec->fmt_in.i_cat == AUDIO_ES && dec->cbs->audio.format_update != NULL )
return dec->cbs->audio.format_update( dec );
else
return -1;
}
......@@ -389,7 +401,8 @@ VLC_USED
static inline subpicture_t *decoder_NewSubpicture( decoder_t *dec,
const subpicture_updater_t *p_dyn )
{
subpicture_t *p_subpicture = dec->pf_spu_buffer_new( dec, p_dyn );
assert( dec->fmt_in.i_cat == SPU_ES && dec->cbs != NULL );
subpicture_t *p_subpicture = dec->cbs->spu.buffer_new( dec, p_dyn );
if( !p_subpicture )
msg_Warn( dec, "can't get output subpicture" );
return p_subpicture;
......@@ -404,10 +417,11 @@ static inline int decoder_GetInputAttachments( decoder_t *dec,
input_attachment_t ***ppp_attachment,
int *pi_attachment )
{
if( !dec->pf_get_attachments )
assert( dec->cbs != NULL );
if( !dec->cbs->get_attachments )
return VLC_EGENERIC;
return dec->pf_get_attachments( dec, ppp_attachment, pi_attachment );
return dec->cbs->get_attachments( dec, ppp_attachment, pi_attachment );
}
/**
......@@ -418,10 +432,11 @@ static inline int decoder_GetInputAttachments( decoder_t *dec,
VLC_USED
static inline mtime_t decoder_GetDisplayDate( decoder_t *dec, mtime_t i_ts )
{
if( !dec->pf_get_display_date )
assert( dec->fmt_in.i_cat == VIDEO_ES && dec->cbs != NULL );
if( !dec->cbs->video.get_display_date )
return VLC_TS_INVALID;
return dec->pf_get_display_date( dec, i_ts );
return dec->cbs->video.get_display_date( dec, i_ts );
}
/**
......@@ -431,10 +446,11 @@ static inline mtime_t decoder_GetDisplayDate( decoder_t *dec, mtime_t i_ts )
VLC_USED
static inline int decoder_GetDisplayRate( decoder_t *dec )
{
if( !dec->pf_get_display_rate )
assert( dec->fmt_in.i_cat == VIDEO_ES && dec->cbs != NULL );
if( !dec->cbs->video.get_display_rate )
return 1000 /* XXX: INPUT_RATE_DEFAULT */;
return dec->pf_get_display_rate( dec );
return dec->cbs->video.get_display_rate( dec );
}
/** @} */
......
......@@ -62,12 +62,19 @@ typedef struct
filter_chain_t *p_vf2;
} sout_stream_sys_t;
struct decoder_owner_sys_t
struct decoder_owner
{
decoder_t dec;
/* Current format in use by the output */
video_format_t video;
sout_stream_t *p_stream;
};
static inline struct decoder_owner *dec_get_owner( decoder_t *p_dec )
{
return container_of( p_dec, struct decoder_owner, dec );
}
/*****************************************************************************
* Local prototypes
*****************************************************************************/
......@@ -77,12 +84,11 @@ static void *Add( sout_stream_t *, const es_format_t * );
static void Del( sout_stream_t *, void * );
static int Send( sout_stream_t *, void *, block_t * );
static int decoder_queue_video( decoder_t *p_dec, picture_t *p_pic );
static void decoder_queue_video( decoder_t *p_dec, picture_t *p_pic );
inline static int video_update_format_decoder( decoder_t *p_dec );
inline static picture_t *video_new_buffer_decoder( decoder_t * );
inline static picture_t *video_new_buffer_filter( filter_t * );
static int video_update_format( vlc_object_t *, decoder_owner_sys_t *,
es_format_t * );
static int video_update_format( vlc_object_t *, video_format_t *, es_format_t * );
static int HeightCallback( vlc_object_t *, char const *,
vlc_value_t, vlc_value_t, void * );
......@@ -282,9 +288,10 @@ static void *Add( sout_stream_t *p_stream, const es_format_t *p_fmt )
return NULL;
/* Create decoder object */
p_sys->p_decoder = vlc_object_create( p_stream, sizeof( decoder_t ) );
if( !p_sys->p_decoder )
struct decoder_owner *p_owner = vlc_object_create( p_stream, sizeof( *p_owner ) );
if( !p_owner )
return NULL;
p_sys->p_decoder = &p_owner->dec;
p_sys->p_decoder->p_module = NULL;
p_sys->p_decoder->fmt_in = *p_fmt;
p_sys->p_decoder->b_frame_drop_allowed = true;
......@@ -292,18 +299,19 @@ static void *Add( sout_stream_t *p_stream, const es_format_t *p_fmt )
p_sys->p_decoder->fmt_out.i_extra = 0;
p_sys->p_decoder->fmt_out.p_extra = 0;
p_sys->p_decoder->pf_decode = NULL;
p_sys->p_decoder->pf_queue_video = decoder_queue_video;
p_sys->p_decoder->p_queue_ctx = p_stream;
p_sys->p_decoder->pf_vout_format_update = video_update_format_decoder;
p_sys->p_decoder->pf_vout_buffer_new = video_new_buffer_decoder;
p_sys->p_decoder->p_owner = malloc( sizeof(decoder_owner_sys_t) );
if( !p_sys->p_decoder->p_owner )
{
vlc_object_release( p_sys->p_decoder );
return NULL;
}
p_sys->p_decoder->p_owner->video = p_fmt->video;
static const struct decoder_owner_callbacks dec_cbs =
{
.video = {
video_update_format_decoder,
video_new_buffer_decoder,
decoder_queue_video,
},
};
p_sys->p_decoder->cbs = &dec_cbs;
p_owner->video = p_fmt->video;
p_owner->p_stream = p_stream;
//p_sys->p_decoder->p_cfg = p_sys->p_video_cfg;
p_sys->p_decoder->p_module =
......@@ -312,7 +320,6 @@ static void *Add( sout_stream_t *p_stream, const es_format_t *p_fmt )
if( !p_sys->p_decoder->p_module )
{
msg_Err( p_stream, "cannot find decoder" );
free( p_sys->p_decoder->p_owner );
vlc_object_release( p_sys->p_decoder );
return NULL;
}
......@@ -381,7 +388,7 @@ static void *Add( sout_stream_t *p_stream, const es_format_t *p_fmt )
if( psz_chain )
{
filter_owner_t owner = {
.sys = p_sys->p_decoder->p_owner,
.sys = p_owner,
.video = {
.buffer_new = video_new_buffer_filter,
},
......@@ -422,16 +429,12 @@ static void Del( sout_stream_t *p_stream, void *id )
if( p_sys->p_decoder != NULL )
{
decoder_owner_sys_t *p_owner = p_sys->p_decoder->p_owner;
if( p_sys->p_decoder->p_module )
module_unneed( p_sys->p_decoder, p_sys->p_decoder->p_module );
if( p_sys->p_decoder->p_description )
vlc_meta_Delete( p_sys->p_decoder->p_description );
vlc_object_release( p_sys->p_decoder );
free( p_owner );
}
/* Destroy user specified video filters */
......@@ -480,9 +483,10 @@ static void Del( sout_stream_t *p_stream, void *id )
p_sys->b_inited = false;
}
static int decoder_queue_video( decoder_t *p_dec, picture_t *p_pic )
static void decoder_queue_video( decoder_t *p_dec, picture_t *p_pic )
{
sout_stream_t *p_stream = p_dec->p_queue_ctx;
struct decoder_owner *p_owner = dec_get_owner( p_dec );
sout_stream_t *p_stream = p_owner->p_stream;
sout_stream_sys_t *p_sys = p_stream->p_sys;
picture_t *p_new_pic;
const video_format_t *p_fmt_in = &p_sys->p_decoder->fmt_out.video;
......@@ -531,7 +535,7 @@ static int decoder_queue_video( decoder_t *p_dec, picture_t *p_pic )
{
msg_Err( p_stream, "image conversion failed" );
picture_Release( p_pic );
return -1;
return;
}
}
else
......@@ -546,7 +550,7 @@ static int decoder_queue_video( decoder_t *p_dec, picture_t *p_pic )
{
picture_Release( p_pic );
msg_Err( p_stream, "image allocation failed" );
return -1;
return;
}
picture_Copy( p_new_pic, p_pic );
......@@ -563,7 +567,6 @@ static int decoder_queue_video( decoder_t *p_dec, picture_t *p_pic )
p_new_pic->p_next = NULL;
p_es->pp_last = &p_new_pic->p_next;
vlc_global_unlock( VLC_MOSAIC_MUTEX );
return 0;
}
static int Send( sout_stream_t *p_stream, void *id, block_t *p_buffer )
......@@ -582,9 +585,9 @@ static int Send( sout_stream_t *p_stream, void *id, block_t *p_buffer )
inline static int video_update_format_decoder( decoder_t *p_dec )
{
struct decoder_owner *p_owner = dec_get_owner( p_dec );
return video_update_format( VLC_OBJECT( p_dec ),
(decoder_owner_sys_t *)p_dec->p_owner,
&p_dec->fmt_out );
&p_owner->video, &p_dec->fmt_out );
}
inline static picture_t *video_new_buffer_decoder( decoder_t *p_dec )
......@@ -594,9 +597,9 @@ inline static picture_t *video_new_buffer_decoder( decoder_t *p_dec )
inline static picture_t *video_new_buffer_filter( filter_t *p_filter )
{
struct decoder_owner *p_owner = p_filter->owner.sys;
if( video_update_format( VLC_OBJECT( p_filter ),
(decoder_owner_sys_t *)p_filter->owner.sys,
&p_filter->fmt_out ) ) {
&p_owner->video, &p_filter->fmt_out ) ) {
msg_Warn( p_filter, "can't get output picture" );
return NULL;
}
......@@ -604,15 +607,14 @@ inline static picture_t *video_new_buffer_filter( filter_t *p_filter )
}
static int video_update_format( vlc_object_t *p_this,
decoder_owner_sys_t *p_sys,
es_format_t *fmt_out )
video_format_t *video, es_format_t *fmt_out )
{
VLC_UNUSED(p_this);
if( fmt_out->video.i_width != p_sys->video.i_width ||
fmt_out->video.i_height != p_sys->video.i_height ||
fmt_out->video.i_chroma != p_sys->video.i_chroma ||
(int64_t)fmt_out->video.i_sar_num * p_sys->video.i_sar_den !=
(int64_t)fmt_out->video.i_sar_den * p_sys->video.i_sar_num )
if( fmt_out->video.i_width != video->i_width ||
fmt_out->video.i_height != video->i_height ||
fmt_out->video.i_chroma != video->i_chroma ||
(int64_t)fmt_out->video.i_sar_num * video->i_sar_den !=
(int64_t)fmt_out->video.i_sar_den * video->i_sar_num )
{
vlc_ureduce( &fmt_out->video.i_sar_num,
&fmt_out->video.i_sar_den,
......@@ -627,7 +629,7 @@ static int video_update_format( vlc_object_t *p_this,
}
fmt_out->video.i_chroma = fmt_out->i_codec;
p_sys->video = fmt_out->video;
*video = fmt_out->video;
}
/* */
......
......@@ -57,7 +57,8 @@ static const int pi_channels_maps[9] =
static int audio_update_format( decoder_t *p_dec )
{
sout_stream_id_sys_t *id = p_dec->p_queue_ctx;
struct decoder_owner *p_owner = dec_get_owner( p_dec );
sout_stream_id_sys_t *id = p_owner->id;
p_dec->fmt_out.audio.i_format = p_dec->fmt_out.i_codec;
aout_FormatPrepare( &p_dec->fmt_out.audio );
......@@ -158,7 +159,8 @@ static int transcode_audio_initialize_encoder( sout_stream_id_sys_t *id, sout_st
static void decoder_queue_audio( decoder_t *p_dec, block_t *p_audio )
{
sout_stream_id_sys_t *id = p_dec->p_queue_ctx;
struct decoder_owner *p_owner = dec_get_owner( p_dec );
sout_stream_id_sys_t *id = p_owner->id;
vlc_mutex_lock(&id->fifo.lock);
*id->fifo.audio.last = p_audio;
......@@ -185,12 +187,18 @@ static int transcode_audio_new( sout_stream_t *p_stream,
/*
* Open decoder
*/
dec_get_owner( id->p_decoder )->id = id;
static const struct decoder_owner_callbacks dec_cbs =
{
.audio = {
audio_update_format,
decoder_queue_audio,
},
};
id->p_decoder->cbs = &dec_cbs;
/* Initialization of decoder structures */
id->p_decoder->pf_decode = NULL;
id->p_decoder->pf_queue_audio = decoder_queue_audio;
id->p_decoder->p_queue_ctx = id;
id->p_decoder->pf_aout_format_update = audio_update_format;
/* id->p_decoder->p_cfg = p_sys->p_audio_cfg; */
id->p_decoder->p_module =
module_need_var( id->p_decoder, "audio decoder", "codec" );
......
......@@ -47,7 +47,8 @@ static subpicture_t *spu_new_buffer( decoder_t *p_dec,
static void decoder_queue_sub( decoder_t *p_dec, subpicture_t *p_spu )
{
sout_stream_id_sys_t *id = p_dec->p_queue_ctx;
struct decoder_owner *p_owner = dec_get_owner( p_dec );
sout_stream_id_sys_t *id = p_owner->id;
vlc_mutex_lock(&id->fifo.lock);
*id->fifo.spu.last = p_spu;
......@@ -73,12 +74,18 @@ static int transcode_spu_new( sout_stream_t *p_stream, sout_stream_id_sys_t *id
/*
* Open decoder
*/
dec_get_owner( id->p_decoder )->id = id;
static const struct decoder_owner_callbacks dec_cbs =
{
.spu = {
spu_new_buffer,
decoder_queue_sub,
},
};
id->p_decoder->cbs = &dec_cbs;
/* Initialization of decoder structures */
id->p_decoder->pf_decode = NULL;
id->p_decoder->pf_spu_buffer_new = spu_new_buffer;
id->p_decoder->pf_queue_sub = decoder_queue_sub;
id->p_decoder->p_queue_ctx = id;
/* id->p_decoder->p_cfg = p_sys->p_spu_cfg; */
id->p_decoder->p_module =
......
......@@ -499,9 +499,12 @@ static void *Add( sout_stream_t *p_stream, const es_format_t *p_fmt )
id->p_encoder = NULL;
/* Create decoder object */
id->p_decoder = vlc_object_create( p_stream, sizeof( decoder_t ) );
if( !id->p_decoder )
struct decoder_owner * p_owner = vlc_object_create( p_stream, sizeof( *p_owner ) );
if( !p_owner )
goto error;
p_owner->p_stream = p_stream;
id->p_decoder = &p_owner->dec;
id->p_decoder->p_module = NULL;
es_format_Init( &id->p_decoder->fmt_out, p_fmt->i_cat, 0 );
es_format_Copy( &id->p_decoder->fmt_in, p_fmt );
......
......@@ -132,6 +132,18 @@ struct sout_stream_id_sys_t
};
struct decoder_owner
{
decoder_t dec;
sout_stream_t *p_stream;
sout_stream_id_sys_t *id;
};
static inline struct decoder_owner *dec_get_owner( decoder_t *p_dec )
{
return container_of( p_dec, struct decoder_owner, dec );
}
/* SPU */
void transcode_spu_close ( sout_stream_t *, sout_stream_id_sys_t * );
......
......@@ -52,9 +52,10 @@ static const video_format_t* video_output_format( sout_stream_id_sys_t *id,
static int video_update_format_decoder( decoder_t *p_dec )
{
sout_stream_t *stream = (sout_stream_t*) p_dec->p_owner;
struct decoder_owner *p_owner = dec_get_owner( p_dec );
sout_stream_id_sys_t *id = p_owner->id;
sout_stream_t *stream = p_owner->p_stream;
sout_stream_sys_t *sys = stream->p_sys;
sout_stream_id_sys_t *id = p_dec->p_queue_ctx;
filter_chain_t *test_chain;
filter_owner_t filter_owner = {
......@@ -154,7 +155,8 @@ static void* EncoderThread( void *obj )
static void decoder_queue_video( decoder_t *p_dec, picture_t *p_pic )
{
sout_stream_id_sys_t *id = p_dec->p_queue_ctx;
struct decoder_owner *p_owner = dec_get_owner( p_dec );
sout_stream_id_sys_t *id = p_owner->id;
vlc_mutex_lock(&id->fifo.lock);
*id->fifo.pic.last = p_pic;
......@@ -178,15 +180,21 @@ static int transcode_video_new( sout_stream_t *p_stream, sout_stream_id_sys_t *i
sout_stream_sys_t *p_sys = p_stream->p_sys;
/* Open decoder
* Initialization of decoder structures
*/
dec_get_owner( id->p_decoder )->id = id;
static const struct decoder_owner_callbacks dec_cbs =
{
.video = {
video_update_format_decoder,
video_new_buffer_decoder,
decoder_queue_video,
},
};
id->p_decoder->cbs = &dec_cbs;
id->p_decoder->pf_decode = NULL;
id->p_decoder->pf_queue_video = decoder_queue_video;
id->p_decoder->p_queue_ctx = id;
id->p_decoder->pf_get_cc = NULL;
id->p_decoder->pf_vout_format_update = video_update_format_decoder;
id->p_decoder->pf_vout_buffer_new = video_new_buffer_decoder;
id->p_decoder->p_owner = (decoder_owner_sys_t*) p_stream;
id->p_decoder->p_module =
module_need_var( id->p_decoder, "video decoder", "codec" );
......
......@@ -63,8 +63,9 @@ enum reload
RELOAD_DECODER_AOUT /* Stop the aout and reload the decoder module */
};
struct decoder_owner_sys_t
struct decoder_owner
{
decoder_t dec;
input_thread_t *p_input;
input_resource_t*p_resource;
input_clock_t *p_clock;
......@@ -79,7 +80,7 @@ struct decoder_owner_sys_t
vlc_thread_t thread;
void (*pf_update_stat)( decoder_owner_sys_t *, unsigned decoded, unsigned lost );
void (*pf_update_stat)( struct decoder_owner *, unsigned decoded, unsigned lost );
/* Some decoders require already packetized data (ie. not truncated) */
decoder_t *p_packetizer;
......@@ -153,6 +154,11 @@ struct decoder_owner_sys_t
#define VLC_TS_OLDEST (VLC_TS_INVALID + 1)
static inline struct decoder_owner *dec_get_owner( decoder_t *p_dec )
{
return container_of( p_dec, struct decoder_owner, dec );
}
/**
* Load a decoder module
*/
......@@ -218,20 +224,20 @@ static int ReloadDecoder( decoder_t *p_dec, bool b_packetizer,
const es_format_t *restrict p_fmt, enum reload reload )
{
/* Copy p_fmt since it can be destroyed by UnloadDecoder */
struct decoder_owner *p_owner = dec_get_owner( p_dec );
es_format_t fmt_in;
if( es_format_Copy( &fmt_in, p_fmt ) != VLC_SUCCESS )
{
p_dec->p_owner->error = true;
p_owner->error = true;
return VLC_EGENERIC;
}
/* Restart the decoder module */
UnloadDecoder( p_dec );
p_dec->p_owner->error = false;
p_owner->error = false;
if( reload == RELOAD_DECODER_AOUT )
{
decoder_owner_sys_t *p_owner = p_dec->p_owner;
assert( p_owner->fmt.i_cat == AUDIO_ES );
audio_output_t *p_aout = p_owner->p_aout;
......@@ -247,7 +253,7 @@ static int ReloadDecoder( decoder_t *p_dec, bool b_packetizer,
if( LoadDecoder( p_dec, b_packetizer, &fmt_in ) )
{
p_dec->p_owner->error = true;
p_owner->error = true;
es_format_Clean( &fmt_in );
return VLC_EGENERIC;
}
......@@ -257,7 +263,7 @@ static int ReloadDecoder( decoder_t *p_dec, bool b_packetizer,
static void DecoderUpdateFormatLocked( decoder_t *p_dec )
{
decoder_owner_sys_t *p_owner = p_dec->p_owner;
struct decoder_owner *p_owner = dec_get_owner( p_dec );
vlc_assert_locked( &p_owner->lock );
......@@ -284,7 +290,7 @@ static vout_thread_t *aout_request_vout( void *p_private,
const video_format_t *p_fmt, bool b_recyle )
{
decoder_t *p_dec = p_private;
decoder_owner_sys_t *p_owner = p_dec->p_owner;
struct decoder_owner *p_owner = dec_get_owner( p_dec );
input_thread_t *p_input = p_owner->p_input;
p_vout = input_resource_RequestVout( p_owner->p_resource, p_vout, p_fmt, 1,
......@@ -311,7 +317,7 @@ static bool aout_replaygain_changed( const audio_replay_gain_t *a,
static int aout_update_format( decoder_t *p_dec )
{
decoder_owner_sys_t *p_owner = p_dec->p_owner;
struct decoder_owner *p_owner = dec_get_owner( p_dec );
if( p_owner->p_aout &&
( !AOUT_FMTS_IDENTICAL(&p_dec->fmt_out.audio, &p_owner->fmt.audio) ||
......@@ -407,7 +413,7 @@ static int aout_update_format( decoder_t *p_dec )
static int vout_update_format( decoder_t *p_dec )
{
decoder_owner_sys_t *p_owner = p_dec->p_owner;
struct decoder_owner *p_owner = dec_get_owner( p_dec );
if( p_owner->p_vout == NULL
|| p_dec->fmt_out.video.i_width != p_owner->fmt.video.i_width
......@@ -553,7 +559,7 @@ static int vout_update_format( decoder_t *p_dec )
static picture_t *vout_new_buffer( decoder_t *p_dec )
{
decoder_owner_sys_t *p_owner = p_dec->p_owner;
struct decoder_owner *p_owner = dec_get_owner( p_dec );
assert