Skip to content

Commit

Permalink
Fix probing mpeg video in program streams
Browse files Browse the repository at this point in the history
... and probably some other formats as well.  Libav's probe routine
doesn't necessarily return names that match the codec names 
that can be looked up by avcodec_find_decoder_by_name().  So we
have to manually map the names if the lookup fails.  Lookup for
mpeg video started failing with the last Libav bump because
they removed an obsolete "mpegvideo" decoder that we were matching
on.  The correct decoder is "mpeg2video", but probe doesn't return
that string.

Also fix our implementation of the ff_lockmgr callback.  Current
git Libav fails if we don't fix it. So might as well fix it now.


git-svn-id: svn://localhost/HandBrake/trunk@4341 b64f7644-9d1e-0410-96f1-a4d463321fa5
  • Loading branch information
jstebbins committed Nov 6, 2011
1 parent 736d5c1 commit 29089a5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 7 deletions.
7 changes: 2 additions & 5 deletions libhb/hb.c
Expand Up @@ -64,20 +64,17 @@ int hb_process_initialized = 0;
static void thread_func( void * );
hb_title_t * hb_get_title_by_index( hb_handle_t *, int );

hb_lock_t *hb_avcodec_lock;
static int ff_lockmgr_cb(void **mutex, enum AVLockOp op)
{
switch ( op )
{
case AV_LOCK_CREATE:
{
hb_avcodec_lock = hb_lock_init();
*mutex = hb_avcodec_lock;
*mutex = hb_lock_init();
} break;
case AV_LOCK_DESTROY:
{
hb_lock_close( &hb_avcodec_lock );
*mutex = NULL;
hb_lock_close( (hb_lock_t**)mutex );
} break;
case AV_LOCK_OBTAIN:
{
Expand Down
39 changes: 37 additions & 2 deletions libhb/stream.c
Expand Up @@ -3907,7 +3907,42 @@ static int do_probe( hb_pes_stream_t *pes, hb_buffer_t *buf )
if ( fmt && score > AVPROBE_SCORE_MAX / 2 )
{
AVCodec *codec = avcodec_find_decoder_by_name( fmt->name );
if ( codec )
if( !codec )
{
int i;
static const struct {
const char *name; enum CodecID id;
} fmt_id_type[] = {
{ "g722" , CODEC_ID_ADPCM_G722 },
{ "mlp" , CODEC_ID_MLP },
{ "truehd" , CODEC_ID_TRUEHD },
{ "shn" , CODEC_ID_SHORTEN },
{ "aac" , CODEC_ID_AAC },
{ "ac3" , CODEC_ID_AC3 },
{ "dts" , CODEC_ID_DTS },
{ "eac3" , CODEC_ID_EAC3 },
{ "h264" , CODEC_ID_H264 },
{ "m4v" , CODEC_ID_MPEG4 },
{ "mp3" , CODEC_ID_MP3 },
{ "mpegvideo", CODEC_ID_MPEG2VIDEO },
{ "cavsvideo", CODEC_ID_CAVS },
{ "dnxhd" , CODEC_ID_DNXHD },
{ "h261" , CODEC_ID_H261 },
{ "h263" , CODEC_ID_H263 },
{ "mjpeg" , CODEC_ID_MJPEG },
{ "vc1" , CODEC_ID_VC1 },
{ 0 }
};
for( i = 0; fmt_id_type[i].name; i++ )
{
if( !strcmp(fmt->name, fmt_id_type[i].name ) )
{
codec = avcodec_find_decoder( fmt_id_type[i].id );
break;
}
}
}
if( codec )
{
pes->codec_param = codec->id;
if ( codec->type == AVMEDIA_TYPE_VIDEO )
Expand Down Expand Up @@ -3955,7 +3990,7 @@ static int do_probe( hb_pes_stream_t *pes, hb_buffer_t *buf )
{
pes->stream_kind = N;
}
strncpy(pes->codec_name, fmt->name, 79);
strncpy(pes->codec_name, codec->name, 79);
pes->codec_name[79] = 0;
}
else
Expand Down

0 comments on commit 29089a5

Please sign in to comment.