summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/mpeg2ts/MPEG2TSExtractor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'media/libstagefright/mpeg2ts/MPEG2TSExtractor.cpp')
-rw-r--r--media/libstagefright/mpeg2ts/MPEG2TSExtractor.cpp55
1 files changed, 30 insertions, 25 deletions
diff --git a/media/libstagefright/mpeg2ts/MPEG2TSExtractor.cpp b/media/libstagefright/mpeg2ts/MPEG2TSExtractor.cpp
index 56ca375..2417305 100644
--- a/media/libstagefright/mpeg2ts/MPEG2TSExtractor.cpp
+++ b/media/libstagefright/mpeg2ts/MPEG2TSExtractor.cpp
@@ -32,6 +32,8 @@
namespace android {
+static const size_t kTSPacketSize = 188;
+
struct MPEG2TSSource : public MediaSource {
MPEG2TSSource(
const sp<MPEG2TSExtractor> &extractor,
@@ -126,27 +128,37 @@ sp<MetaData> MPEG2TSExtractor::getMetaData() {
void MPEG2TSExtractor::init() {
bool haveAudio = false;
bool haveVideo = false;
+ int numPacketsParsed = 0;
while (feedMore() == OK) {
ATSParser::SourceType type;
if (haveAudio && haveVideo) {
break;
}
- if (haveVideo) {
- type = ATSParser::MPEG2ADTS_AUDIO;
- } else {
- type = ATSParser::AVC_VIDEO;
+ if (!haveVideo) {
+ sp<AnotherPacketSource> impl =
+ (AnotherPacketSource *)mParser->getSource(
+ ATSParser::AVC_VIDEO).get();
+
+ if (impl != NULL) {
+ haveVideo = true;
+ mSourceImpls.push(impl);
+ }
}
- sp<AnotherPacketSource> impl =
- (AnotherPacketSource *)mParser->getSource(type).get();
- if (impl != NULL) {
- if (type == ATSParser::MPEG2ADTS_AUDIO) {
+ if (!haveAudio) {
+ sp<AnotherPacketSource> impl =
+ (AnotherPacketSource *)mParser->getSource(
+ ATSParser::MPEG2ADTS_AUDIO).get();
+
+ if (impl != NULL) {
haveAudio = true;
- } else {
- haveVideo = true;
+ mSourceImpls.push(impl);
}
- mSourceImpls.push(impl);
+ }
+
+ if (++numPacketsParsed > 1500) {
+ break;
}
}
@@ -156,8 +168,6 @@ void MPEG2TSExtractor::init() {
status_t MPEG2TSExtractor::feedMore() {
Mutex::Autolock autoLock(mLock);
- static const size_t kTSPacketSize = 188;
-
uint8_t packet[kTSPacketSize];
ssize_t n = mDataSource->readAt(mOffset, packet, kTSPacketSize);
@@ -176,23 +186,18 @@ status_t MPEG2TSExtractor::feedMore() {
bool SniffMPEG2TS(
const sp<DataSource> &source, String8 *mimeType, float *confidence,
sp<AMessage> *) {
-#if 0
- char header;
- if (source->readAt(0, &header, 1) != 1 || header != 0x47) {
- return false;
+ for (int i = 0; i < 5; ++i) {
+ char header;
+ if (source->readAt(kTSPacketSize * i, &header, 1) != 1
+ || header != 0x47) {
+ return false;
+ }
}
- *confidence = 0.05f;
+ *confidence = 0.1f;
mimeType->setTo(MEDIA_MIMETYPE_CONTAINER_MPEG2TS);
return true;
-#else
- // For now we're going to never identify this type of stream, since we'd
- // just base our decision on a single byte...
- // Instead you can instantiate an MPEG2TSExtractor by explicitly stating
- // its proper mime type in the call to MediaExtractor::Create(...).
- return false;
-#endif
}
} // namespace android