[mythtv] [PATCH] AvFmtDec scanAudioStreams
Daniel Thor Kristjansson
danielk at mrl.nyu.edu
Tue Oct 26 16:09:27 UTC 2004
On Tue, 26 Oct 2004, Kenneth Aafløy wrote:
]Could be, I've been reading some of the commits to avfd, nvp and tv_play, but
]I've not found anything yet. I'm wondering though, could it be that it will
]select the wrong stream id for whatever reason, and then output no audio
]because of the pkt->stream_index != wantedAudioStream in avfd? I think there
]should be some sort of protection there, ie perform autoselect if no audio
]packets of the current stream is found within say 2 seconds.
Here's another patch for the audio. At one point I thought we might be
selecting a stream we couldn't decode. This turned out not to be the
case, but this patch would address that problem if it happened.
I eliminated scanAudioStreams, and put that functionality in the general
ScanStreams method. Now it only adds an audio stream to the list if it
finds the codec for it in avlib. I've also changed ScanStreams so if it
finds an unidentified stream it keeps scanning the rest of the streams.
Finally, I added a check in GetFrame that calls SelectAudioTrack() if
the currently selected audio track is outside the bounds of our audio
stream list.
-- Daniel
-------------- next part --------------
Index: libs/libmythtv/avformatdecoder.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/avformatdecoder.cpp,v
retrieving revision 1.111
diff -u -r1.111 avformatdecoder.cpp
--- libs/libmythtv/avformatdecoder.cpp 25 Oct 2004 22:39:53 -0000 1.111
+++ libs/libmythtv/avformatdecoder.cpp 26 Oct 2004 15:59:11 -0000
@@ -343,9 +343,7 @@
if (-1 == ret)
return ret;
- // Scan for audio tracks and pick one to use.
- if (scanAudioTracks())
- autoSelectAudioTrack();
+ autoSelectAudioTrack();
ringBuffer->CalcReadAheadThresh(bitrate);
@@ -391,9 +389,12 @@
int AvFormatDecoder::ScanStreams(bool novideo)
{
+ int scanerror = 0;
bitrate = 0;
fps = 0;
+ audioStreams.clear();
+
for (int i = 0; i < ic->nb_streams; i++)
{
AVCodecContext *enc = &ic->streams[i]->codec;
@@ -491,17 +492,20 @@
case CODEC_TYPE_DATA:
{
bitrate += enc->bit_rate;
- // otherwise, ignore it
- continue;
+ VERBOSE(VB_PLAYBACK, QString("AvFormatDecoder: data codec, ignoring (%1).")
+ .arg(enc->codec_type));
break;
}
default:
{
+ bitrate += enc->bit_rate;
VERBOSE(VB_PLAYBACK, QString("AvFormatDecoder: Unknown codec type (%1).")
.arg(enc->codec_type));
break;
}
}
+ if (enc->codec_type!=CODEC_TYPE_AUDIO && enc->codec_type!=CODEC_TYPE_VIDEO)
+ continue;
VERBOSE(VB_PLAYBACK, QString("AVFD: Looking for decoder for %1").arg(enc->codec_id));
AVCodec *codec = avcodec_find_decoder(enc->codec_id);
@@ -511,7 +515,8 @@
.arg(enc->codec_id));
av_close_input_file(ic);
ic = NULL;
- return -1;
+ scanerror = -1;
+ continue;
}
if (enc->codec) {
@@ -525,13 +530,21 @@
VERBOSE(VB_IMPORTANT, QString("AvFormatDecoder: Could not open codec aborting. reason %1").arg(open_val));
av_close_input_file(ic);
ic = NULL;
- return -1;
+ scanerror = -1;
+ continue;
+ }
+
+ if (enc->codec_type == CODEC_TYPE_AUDIO)
+ {
+ audioStreams.push_back( i );
+ VERBOSE(VB_AUDIO, QString("Stream #%1 (audio track #%2) is an audio stream with %3 channels.")
+ .arg(i).arg(audioStreams.size()).arg(enc->channels));
}
}
// Select a new track at the next opportunity.
currentAudioTrack = -1;
- return 0;
+ return scanerror;
}
bool AvFormatDecoder::CheckVideoParams(int width, int height)
@@ -965,28 +978,6 @@
return retval;
}
-bool AvFormatDecoder::scanAudioTracks()
-{
- audioStreams.clear();
-
- int trackNo = 0;
- for (int i = 0; i < ic->nb_streams; i++)
- {
- AVCodecContext *enc = &ic->streams[i]->codec;
- if (enc->codec_type == CODEC_TYPE_AUDIO)
- {
- ++trackNo;
- audioStreams.push_back( i );
-
- VERBOSE(VB_AUDIO, QString("Stream #%1 (audio track #%2) is an audio stream with %3 channels.")
- .arg(i).arg(trackNo).arg(enc->channels));
-
- }
- }
-
- return (audioStreams.size() > 0);
-}
-
void AvFormatDecoder::incCurrentAudioTrack()
{
if (audioStreams.size())
@@ -1132,14 +1123,8 @@
bool allowedquit = false;
bool storevideoframes = false;
- if (currentAudioTrack == -1 )
- {
- // Scan for audio tracks and pick one to use.
- if (scanAudioTracks())
- {
- autoSelectAudioTrack();
- }
- }
+ if (currentAudioTrack==-1 || currentAudioTrack>=(int)audioStreams.size())
+ autoSelectAudioTrack();
while (!allowedquit)
{
Index: libs/libmythtv/avformatdecoder.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmythtv/avformatdecoder.h,v
retrieving revision 1.47
diff -u -r1.47 avformatdecoder.h
--- libs/libmythtv/avformatdecoder.h 25 Oct 2004 23:45:25 -0000 1.47
+++ libs/libmythtv/avformatdecoder.h 26 Oct 2004 15:59:12 -0000
@@ -75,9 +75,6 @@
int ScanStreams(bool novideo);
protected:
- /// Loop through the streams in the file to identify audio streams.
- bool scanAudioTracks();
-
/// Attempt to find the optimal audio stream to use based on the number of channels,
/// and if we're doing AC3 passthrough. This will select the highest stream number
/// that matches our criteria.
More information about the mythtv-dev
mailing list