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

avcodec: revector, no functional changes

parent bdf4249d
......@@ -210,28 +210,35 @@ void EndAudioDec( decoder_t *p_dec )
*****************************************************************************
* The avcodec codec will be opened, some memory allocated.
*****************************************************************************/
int InitAudioDec( decoder_t *p_dec, AVCodecContext *p_context,
const AVCodec *p_codec )
int InitAudioDec( decoder_t *p_dec )
{
decoder_sys_t *p_sys;
const AVCodec *codec;
AVCodecContext *avctx = ffmpeg_AllocContext( p_dec, &codec );
if( avctx == NULL )
return VLC_EGENERIC;
avctx->refcounted_frames = true;
/* Allocate the memory needed to store the decoder's structure */
if( ( p_dec->p_sys = p_sys = malloc(sizeof(*p_sys)) ) == NULL )
decoder_sys_t *p_sys = malloc(sizeof(*p_sys));
if( unlikely(p_sys == NULL) )
{
avcodec_free_context( &avctx );
return VLC_ENOMEM;
}
p_context->refcounted_frames = true;
p_sys->p_context = p_context;
p_sys->p_codec = p_codec;
p_dec->p_sys = p_sys;
p_sys->p_context = avctx;
p_sys->p_codec = codec;
// Initialize decoder extradata
InitDecoderConfig( p_dec, p_context);
InitDecoderConfig( p_dec, avctx );
/* ***** Open the codec ***** */
if( OpenAudioCodec( p_dec ) < 0 )
{
free( p_sys );
avcodec_free_context( &avctx );
return VLC_EGENERIC;
}
......@@ -253,6 +260,13 @@ int InitAudioDec( decoder_t *p_dec, AVCodecContext *p_context,
p_dec->pf_decode = DecodeAudio;
p_dec->pf_flush = Flush;
/* XXX: Writing input format makes little sense. */
if( avctx->profile != FF_PROFILE_UNKNOWN )
p_dec->fmt_in.i_profile = avctx->profile;
if( avctx->level != FF_LEVEL_UNKNOWN )
p_dec->fmt_in.i_level = avctx->level;
return VLC_SUCCESS;
}
......
......@@ -236,7 +236,6 @@ vlc_module_begin ()
#endif
vlc_module_end ()
static
AVCodecContext *ffmpeg_AllocContext( decoder_t *p_dec,
const AVCodec **restrict codecp )
{
......@@ -295,41 +294,24 @@ AVCodecContext *ffmpeg_AllocContext( decoder_t *p_dec,
static int OpenDecoder( vlc_object_t *p_this )
{
decoder_t *p_dec = (decoder_t *)p_this;
const AVCodec *p_codec;
AVCodecContext *avctx = ffmpeg_AllocContext( p_dec, &p_codec );
if( unlikely(avctx == NULL) )
return VLC_EGENERIC;
int ret;
switch( p_dec->fmt_in.i_cat )
{
case VIDEO_ES:
ret = InitVideoDec( p_dec, avctx, p_codec );
ret = InitVideoDec( p_dec );
break;
case AUDIO_ES:
ret = InitAudioDec( p_dec, avctx, p_codec );
ret = InitAudioDec( p_dec );
break;
case SPU_ES:
ret = InitSubtitleDec( p_dec, avctx, p_codec );
ret = InitSubtitleDec( p_dec );
break;
default:
vlc_assert_unreachable();
}
if( ret != VLC_SUCCESS )
{
avcodec_free_context( &avctx );
return ret;
}
if( avctx->profile != FF_PROFILE_UNKNOWN)
p_dec->fmt_in.i_profile = avctx->profile;
if( avctx->level != FF_LEVEL_UNKNOWN)
p_dec->fmt_in.i_level = avctx->level;
return VLC_SUCCESS;
return ret;
}
/*****************************************************************************
......
......@@ -35,18 +35,19 @@ int OpenEncoder ( vlc_object_t * );
void CloseEncoder( vlc_object_t * );
/* Video Decoder */
int InitVideoDec( decoder_t *, AVCodecContext *, const AVCodec * );
int InitVideoDec( decoder_t * );
void EndVideoDec( decoder_t *p_dec );
/* Audio Decoder */
int InitAudioDec( decoder_t *, AVCodecContext *, const AVCodec * );
int InitAudioDec( decoder_t * );
void EndAudioDec( decoder_t *p_dec );
/* Subtitle Decoder */
int InitSubtitleDec( decoder_t *, AVCodecContext *, const AVCodec * );
int InitSubtitleDec( decoder_t * );
void EndSubtitleDec( decoder_t * );
/* Initialize decoder */
AVCodecContext *ffmpeg_AllocContext( decoder_t *, const AVCodec ** );
int ffmpeg_OpenCodec( decoder_t *p_dec, AVCodecContext *, const AVCodec * );
/*****************************************************************************
......
......@@ -52,9 +52,13 @@ static void Flush(decoder_t *);
/**
* Initialize subtitle decoder
*/
int InitSubtitleDec(decoder_t *dec, AVCodecContext *context,
const AVCodec *codec)
int InitSubtitleDec(decoder_t *dec)
{
const AVCodec *codec;
AVCodecContext *context = ffmpeg_AllocContext(dec, &codec);
if (context == NULL)
return VLC_EGENERIC;
decoder_sys_t *sys;
/* */
......@@ -65,13 +69,17 @@ int InitSubtitleDec(decoder_t *dec, AVCodecContext *context,
break;
default:
msg_Warn(dec, "refusing to decode non validated subtitle codec");
avcodec_free_context(&context);
return VLC_EGENERIC;
}
/* */
dec->p_sys = sys = malloc(sizeof(*sys));
if (!sys)
if (unlikely(sys == NULL))
{
avcodec_free_context(&context);
return VLC_ENOMEM;
}
sys->p_context = context;
sys->p_codec = codec;
......@@ -107,6 +115,7 @@ int InitSubtitleDec(decoder_t *dec, AVCodecContext *context,
if (ret < 0) {
msg_Err(dec, "cannot open codec (%s)", codec->name);
free(sys);
avcodec_free_context(&context);
return VLC_EGENERIC;
}
......
......@@ -434,16 +434,24 @@ static int OpenVideoCodec( decoder_t *p_dec )
* the ffmpeg codec will be opened, some memory allocated. The vout is not yet
* opened (done after the first decoded frame).
*****************************************************************************/
int InitVideoDec( decoder_t *p_dec, AVCodecContext *p_context,
const AVCodec *p_codec )
int InitVideoDec( decoder_t *p_dec )
{
decoder_sys_t *p_sys;
const AVCodec *p_codec;
AVCodecContext *p_context = ffmpeg_AllocContext( p_dec, &p_codec );
if( p_context == NULL )
return VLC_EGENERIC;
int i_val;
/* Allocate the memory needed to store the decoder's structure */
if( ( p_dec->p_sys = p_sys = calloc( 1, sizeof(decoder_sys_t) ) ) == NULL )
decoder_sys_t *p_sys = calloc( 1, sizeof(*p_sys) );
if( unlikely(p_sys == NULL) )
{
avcodec_free_context( &p_context );
return VLC_ENOMEM;
}
p_dec->p_sys = p_sys;
p_sys->p_context = p_context;
p_sys->p_codec = p_codec;
p_sys->p_va = NULL;
......@@ -590,12 +598,18 @@ int InitVideoDec( decoder_t *p_dec, AVCodecContext *p_context,
{
vlc_sem_destroy( &p_sys->sem_mt );
free( p_sys );
avcodec_free_context( &p_context );
return VLC_EGENERIC;
}
p_dec->pf_decode = DecodeVideo;
p_dec->pf_flush = Flush;
/* XXX: Writing input format makes little sense. */
if( p_context->profile != FF_PROFILE_UNKNOWN )
p_dec->fmt_in.i_profile = p_context->profile;
if( p_context->level != FF_LEVEL_UNKNOWN )
p_dec->fmt_in.i_level = p_context->level;
return VLC_SUCCESS;
}
......
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