summaryrefslogtreecommitdiffstats
path: root/media/libstagefright/mpeg2ts/ATSParser.cpp
diff options
context:
space:
mode:
authorAndreas Huber <andih@google.com>2010-09-27 12:04:43 -0700
committerAndreas Huber <andih@google.com>2010-09-27 12:04:43 -0700
commit0da4dab0a45a2bc1d95cbc6ef6a4850ed2569584 (patch)
tree4150ff394b0a10838310b9b228a8e378d64b1a88 /media/libstagefright/mpeg2ts/ATSParser.cpp
parent676570f3c6b41e8b854cb31e8ceaa370980eb6fc (diff)
downloadframeworks_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/ATSParser.cpp')
-rw-r--r--media/libstagefright/mpeg2ts/ATSParser.cpp48
1 files changed, 31 insertions, 17 deletions
diff --git a/media/libstagefright/mpeg2ts/ATSParser.cpp b/media/libstagefright/mpeg2ts/ATSParser.cpp
index 9952783..47cca80 100644
--- a/media/libstagefright/mpeg2ts/ATSParser.cpp
+++ b/media/libstagefright/mpeg2ts/ATSParser.cpp
@@ -389,20 +389,23 @@ void ATSParser::Stream::parsePES(ABitReader *br) {
// ES data follows.
- onPayloadData(
- PTS_DTS_flags, PTS, DTS,
- br->data(), br->numBitsLeft() / 8);
-
if (PES_packet_length != 0) {
CHECK_GE(PES_packet_length, PES_header_data_length + 3);
unsigned dataLength =
PES_packet_length - 3 - PES_header_data_length;
- CHECK_EQ(br->numBitsLeft(), dataLength * 8);
+ CHECK_GE(br->numBitsLeft(), dataLength * 8);
+
+ onPayloadData(
+ PTS_DTS_flags, PTS, DTS, br->data(), dataLength);
br->skipBits(dataLength * 8);
} else {
+ onPayloadData(
+ PTS_DTS_flags, PTS, DTS,
+ br->data(), br->numBitsLeft() / 8);
+
size_t payloadSizeBits = br->numBitsLeft();
CHECK((payloadSizeBits % 8) == 0);
@@ -491,7 +494,7 @@ static sp<ABuffer> MakeAVCCodecSpecificData(
CHECK(picParamSet != NULL);
buffer->setRange(stopOffset, size - stopOffset);
- LOGI("buffer has %d bytes left.", buffer->size());
+ LOGV("buffer has %d bytes left.", buffer->size());
size_t csdSize =
1 + 3 + 1 + 1
@@ -527,6 +530,8 @@ static bool getNextNALUnit(
const uint8_t *data = *_data;
size_t size = *_size;
+ // hexdump(data, size);
+
*nalStart = NULL;
*nalSize = 0;
@@ -572,18 +577,23 @@ static bool getNextNALUnit(
++offset;
}
- CHECK_LT(offset + 2, size);
-
*nalStart = &data[startOffset];
*nalSize = endOffset - startOffset;
- *_data = &data[offset];
- *_size = size - offset;
+ if (offset + 2 < size) {
+ *_data = &data[offset];
+ *_size = size - offset;
+ } else {
+ *_data = NULL;
+ *_size = 0;
+ }
return true;
}
sp<ABuffer> MakeCleanAVCData(const uint8_t *data, size_t size) {
+ // hexdump(data, size);
+
const uint8_t *tmpData = data;
size_t tmpSize = size;
@@ -591,6 +601,7 @@ sp<ABuffer> MakeCleanAVCData(const uint8_t *data, size_t size) {
const uint8_t *nalStart;
size_t nalSize;
while (getNextNALUnit(&tmpData, &tmpSize, &nalStart, &nalSize)) {
+ // hexdump(nalStart, nalSize);
totalSize += 4 + nalSize;
}
@@ -615,15 +626,15 @@ static sp<ABuffer> FindMPEG2ADTSConfig(
CHECK_EQ(br.getBits(2), 0u);
br.getBits(1); // protection_absent
unsigned profile = br.getBits(2);
- LOGI("profile = %u", profile);
+ LOGV("profile = %u", profile);
CHECK_NE(profile, 3u);
unsigned sampling_freq_index = br.getBits(4);
br.getBits(1); // private_bit
unsigned channel_configuration = br.getBits(3);
CHECK_NE(channel_configuration, 0u);
- LOGI("sampling_freq_index = %u", sampling_freq_index);
- LOGI("channel_configuration = %u", channel_configuration);
+ LOGV("sampling_freq_index = %u", sampling_freq_index);
+ LOGV("channel_configuration = %u", channel_configuration);
CHECK_LE(sampling_freq_index, 11u);
static const int32_t kSamplingFreq[] = {
@@ -707,8 +718,8 @@ void ATSParser::Stream::onPayloadData(
sp<ABuffer> csd =
FindMPEG2ADTSConfig(buffer, &sampleRate, &channelCount);
- LOGI("sampleRate = %d", sampleRate);
- LOGI("channelCount = %d", channelCount);
+ LOGV("sampleRate = %d", sampleRate);
+ LOGV("channelCount = %d", channelCount);
meta->setInt32(kKeySampleRate, sampleRate);
meta->setInt32(kKeyChannelCount, channelCount);
@@ -716,7 +727,7 @@ void ATSParser::Stream::onPayloadData(
meta->setData(kKeyESDS, 0, csd->data(), csd->size());
}
- LOGI("created source!");
+ LOGV("created source!");
mSource = new AnotherPacketSource(meta);
// fall through
@@ -915,7 +926,10 @@ void ATSParser::parseTS(ABitReader *br) {
unsigned adaptation_field_control = br->getBits(2);
LOGV("adaptation_field_control = %u", adaptation_field_control);
- MY_LOGV("continuity_counter = %u", br->getBits(4));
+ unsigned continuity_counter = br->getBits(4);
+ LOGV("continuity_counter = %u", continuity_counter);
+
+ // LOGI("PID = 0x%04x, continuity_counter = %u", PID, continuity_counter);
if (adaptation_field_control == 2 || adaptation_field_control == 3) {
parseAdaptationField(br);