Skip to content

Commit

Permalink
mythtranscode: always check if audio stream still exists
Browse files Browse the repository at this point in the history
This doesn’t cater for when there’s a change in audio format or new audio stream, but it prevents the crash when that occurs.

Fixes #12207
  • Loading branch information
jyavenard committed Jul 19, 2014
1 parent b04e14b commit 43eed00
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 12 additions & 4 deletions mythtv/programs/mythtranscode/mpeg2fix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,18 +583,21 @@ void MPEG2fixup::InitReplex()
int mp2_count = 0, ac3_count = 0;
for (FrameMap::Iterator it = aFrame.begin(); it != aFrame.end(); it++)
{
int i = aud_map[it.key()];
int index = it.key();
if (index > inputFC->nb_streams)
continue; // will never happen in practice
int i = aud_map[index];
AVDictionaryEntry *metatag =
av_dict_get(inputFC->streams[it.key()]->metadata,
av_dict_get(inputFC->streams[index]->metadata,
"language", NULL, 0);
char *lang = metatag ? metatag->value : (char *)"";
ring_init(&rx.extrbuf[i], memsize / 5);
ring_init(&rx.index_extrbuf[i], INDEX_BUF);
rx.extframe[i].set = 1;
rx.extframe[i].bit_rate = getCodecContext(it.key())->bit_rate;
rx.extframe[i].bit_rate = getCodecContext(index)->bit_rate;
rx.extframe[i].framesize = (*it)->first()->pkt.size;
strncpy(rx.extframe[i].language, lang, 4);
switch(GetStreamType(it.key()))
switch(GetStreamType(index))
{
case AV_CODEC_ID_MP2:
case AV_CODEC_ID_MP3:
Expand Down Expand Up @@ -2420,6 +2423,11 @@ int MPEG2fixup::Start()

while (af->count())
{
if (!CC || !CPC)
{
framePool.enqueue(af->takeFirst());
continue;
}
// What to do if the CC is corrupt?
// Just wait and hope it repairs itself
if (CC->sample_rate == 0 || !CPC || CPC->duration == 0)
Expand Down
4 changes: 4 additions & 0 deletions mythtv/programs/mythtranscode/mpeg2fix.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,14 @@ class MPEG2fixup
}
AVCodecContext *getCodecContext(int id)
{
if (id >= inputFC->nb_streams)
return NULL;
return inputFC->streams[id]->codec;
}
AVCodecParserContext *getCodecParserContext(int id)
{
if (id >= inputFC->nb_streams)
return NULL;
return inputFC->streams[id]->parser;
}

Expand Down

0 comments on commit 43eed00

Please sign in to comment.