am a063cd64: Merge "Instead of asserting, publish no tracks if an MP3Extractor is used on non-mp3 content." into gingerbread

Merge commit 'a063cd6478254bba3290576ae5556abf469d6535' into gingerbread-plus-aosp

* commit 'a063cd6478254bba3290576ae5556abf469d6535':
  Instead of asserting, publish no tracks if an MP3Extractor is used on non-mp3 content.
This commit is contained in:
Andreas Huber
2010-09-09 10:01:05 -07:00
committed by Android Git Automerger
2 changed files with 39 additions and 38 deletions

View File

@@ -459,7 +459,8 @@ private:
MP3Extractor::MP3Extractor( MP3Extractor::MP3Extractor(
const sp<DataSource> &source, const sp<AMessage> &meta) const sp<DataSource> &source, const sp<AMessage> &meta)
: mDataSource(source), : mInitCheck(NO_INIT),
mDataSource(source),
mFirstFramePos(-1), mFirstFramePos(-1),
mFixedHeader(0), mFixedHeader(0),
mByteNumber(0) { mByteNumber(0) {
@@ -480,53 +481,54 @@ MP3Extractor::MP3Extractor(
success = true; success = true;
} else { } else {
success = Resync(mDataSource, 0, &pos, &header); success = Resync(mDataSource, 0, &pos, &header);
CHECK(success);
} }
if (success) { if (!success) {
mFirstFramePos = pos; // mInitCheck will remain NO_INIT
mFixedHeader = header; return;
}
size_t frame_size; mFirstFramePos = pos;
int sample_rate; mFixedHeader = header;
int num_channels;
int bitrate;
get_mp3_frame_size(
header, &frame_size, &sample_rate, &num_channels, &bitrate);
mMeta = new MetaData; size_t frame_size;
int sample_rate;
int num_channels;
int bitrate;
get_mp3_frame_size(
header, &frame_size, &sample_rate, &num_channels, &bitrate);
mMeta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_MPEG); mMeta = new MetaData;
mMeta->setInt32(kKeySampleRate, sample_rate);
mMeta->setInt32(kKeyBitRate, bitrate * 1000);
mMeta->setInt32(kKeyChannelCount, num_channels);
int64_t duration; mMeta->setCString(kKeyMIMEType, MEDIA_MIMETYPE_AUDIO_MPEG);
parse_xing_header( mMeta->setInt32(kKeySampleRate, sample_rate);
mDataSource, mFirstFramePos, NULL, &mByteNumber, mMeta->setInt32(kKeyBitRate, bitrate * 1000);
mTableOfContents, NULL, &duration); mMeta->setInt32(kKeyChannelCount, num_channels);
if (duration > 0) {
mMeta->setInt64(kKeyDuration, duration); int64_t duration;
} else { parse_xing_header(
off_t fileSize; mDataSource, mFirstFramePos, NULL, &mByteNumber,
if (mDataSource->getSize(&fileSize) == OK) { mTableOfContents, NULL, &duration);
mMeta->setInt64( if (duration > 0) {
kKeyDuration, mMeta->setInt64(kKeyDuration, duration);
8000LL * (fileSize - mFirstFramePos) / bitrate); } else {
} off_t fileSize;
if (mDataSource->getSize(&fileSize) == OK) {
mMeta->setInt64(
kKeyDuration,
8000LL * (fileSize - mFirstFramePos) / bitrate);
} }
} }
}
MP3Extractor::~MP3Extractor() { mInitCheck = OK;
} }
size_t MP3Extractor::countTracks() { size_t MP3Extractor::countTracks() {
return (mFirstFramePos < 0) ? 0 : 1; return mInitCheck != OK ? 0 : 1;
} }
sp<MediaSource> MP3Extractor::getTrack(size_t index) { sp<MediaSource> MP3Extractor::getTrack(size_t index) {
if (mFirstFramePos < 0 || index != 0) { if (mInitCheck != OK || index != 0) {
return NULL; return NULL;
} }
@@ -536,7 +538,7 @@ sp<MediaSource> MP3Extractor::getTrack(size_t index) {
} }
sp<MetaData> MP3Extractor::getTrackMetaData(size_t index, uint32_t flags) { sp<MetaData> MP3Extractor::getTrackMetaData(size_t index, uint32_t flags) {
if (mFirstFramePos < 0 || index != 0) { if (mInitCheck != OK || index != 0) {
return NULL; return NULL;
} }
@@ -713,7 +715,7 @@ status_t MP3Source::read(
sp<MetaData> MP3Extractor::getMetaData() { sp<MetaData> MP3Extractor::getMetaData() {
sp<MetaData> meta = new MetaData; sp<MetaData> meta = new MetaData;
if (mFirstFramePos < 0) { if (mInitCheck != OK) {
return meta; return meta;
} }

View File

@@ -37,10 +37,9 @@ public:
virtual sp<MetaData> getMetaData(); virtual sp<MetaData> getMetaData();
protected:
virtual ~MP3Extractor();
private: private:
status_t mInitCheck;
sp<DataSource> mDataSource; sp<DataSource> mDataSource;
off_t mFirstFramePos; off_t mFirstFramePos;
sp<MetaData> mMeta; sp<MetaData> mMeta;