diff options
author | Andreas Huber <andih@google.com> | 2010-09-27 12:04:43 -0700 |
---|---|---|
committer | Andreas Huber <andih@google.com> | 2010-09-27 12:04:43 -0700 |
commit | 0da4dab0a45a2bc1d95cbc6ef6a4850ed2569584 (patch) | |
tree | 4150ff394b0a10838310b9b228a8e378d64b1a88 /media/libstagefright/mpeg2ts/MPEG2TSExtractor.cpp | |
parent | 676570f3c6b41e8b854cb31e8ceaa370980eb6fc (diff) | |
download | frameworks_av-0da4dab0a45a2bc1d95cbc6ef6a4850ed2569584.zip frameworks_av-0da4dab0a45a2bc1d95cbc6ef6a4850ed2569584.tar.gz frameworks_av-0da4dab0a45a2bc1d95cbc6ef6a4850ed2569584.tar.bz2 |
Squashed commit of the following:
commit 29a4d3effb05a2e074cb0693316ab1977baeb0b6
Author: Andreas Huber <andih@google.com>
Date: Mon Sep 27 12:01:32 2010 -0700
Fully working implementation of MPEG2TSWriter (for AAC and AVC sources).
Change-Id: I8a32a47565b647bf6c078c520e39565e08ea0d84
commit f4dec4c3899f3be393508e180d6c07e249d3335e
Author: Andreas Huber <andih@google.com>
Date: Mon Sep 27 10:36:31 2010 -0700
More reliable identification of MPEG2 transport streams. Don't keep scanning forever in case the stream does not have both audio and video tracks.
Change-Id: Icc5b4e8be145b2805e8776559546a6818342aea7
commit 4fe3cc942f9b3d3cf54138b828c41214aa916dd2
Author: Andreas Huber <andih@google.com>
Date: Mon Sep 27 08:23:39 2010 -0700
test code
Change-Id: I16560a17661407d06497f99ff88230724bb898af
commit 64d988b24f49f179a90fa677be11c823959e734b
Author: Andreas Huber <andih@google.com>
Date: Thu Sep 23 14:42:52 2010 -0700
First shot at supporting writing to an MPEG2 transport stream.
Change-Id: Ie537939a99fa3ddc0c7661c47c18277584817c74
Change-Id: If78fd034af8f6e8ceac8dbeff96d5ecb3f6b96dc
Diffstat (limited to 'media/libstagefright/mpeg2ts/MPEG2TSExtractor.cpp')
-rw-r--r-- | media/libstagefright/mpeg2ts/MPEG2TSExtractor.cpp | 55 |
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 |