Merge change I98276091 into eclair-mr2

* changes:
  Change to a int64_t usecs representation for timestamps and duration throughout stagefright.
This commit is contained in:
Android (Google) Code Review
2009-10-12 19:01:28 -04:00
12 changed files with 69 additions and 82 deletions

View File

@ -86,8 +86,8 @@ status_t SineSource::read(
x += k; x += k;
} }
buffer->meta_data()->setInt32(kKeyTimeUnits, mPhase); buffer->meta_data()->setInt64(
buffer->meta_data()->setInt32(kKeyTimeScale, mSampleRate); kKeyTime, ((int64_t)mPhase * 1000000) / mSampleRate);
mPhase += numFramesPerBuffer; mPhase += numFramesPerBuffer;

View File

@ -76,14 +76,12 @@ static void playSource(OMXClient *client, const sp<MediaSource> &source) {
shouldSeek = true; shouldSeek = true;
} else { } else {
int32_t units, scale; int64_t timestampUs;
CHECK(buffer->meta_data()->findInt32(kKeyTimeUnits, &units)); CHECK(buffer->meta_data()->findInt64(kKeyTime, &timestampUs));
CHECK(buffer->meta_data()->findInt32(kKeyTimeScale, &scale));
int64_t timestamp = ((OMX_TICKS)units * 1000000) / scale;
bool failed = false; bool failed = false;
if (seekTimeUs >= 0) { if (seekTimeUs >= 0) {
int64_t diff = timestamp - seekTimeUs; int64_t diff = timestampUs - seekTimeUs;
if (diff > 500000) { if (diff > 500000) {
printf("ERROR: "); printf("ERROR: ");
@ -92,7 +90,7 @@ static void playSource(OMXClient *client, const sp<MediaSource> &source) {
} }
printf("buffer has timestamp %lld us (%.2f secs)\n", printf("buffer has timestamp %lld us (%.2f secs)\n",
timestamp, timestamp / 1E6); timestampUs, timestampUs / 1E6);
buffer->release(); buffer->release();
buffer = NULL; buffer = NULL;

View File

@ -27,23 +27,23 @@
namespace android { namespace android {
// The following keys map to int32_t data unless indicated otherwise.
enum { enum {
kKeyMIMEType = 'mime', kKeyMIMEType = 'mime', // cstring
kKeyWidth = 'widt', kKeyWidth = 'widt',
kKeyHeight = 'heig', kKeyHeight = 'heig',
kKeyChannelCount = '#chn', kKeyChannelCount = '#chn',
kKeySampleRate = 'srte', kKeySampleRate = 'srte',
kKeyBitRate = 'brte', kKeyBitRate = 'brte',
kKeyESDS = 'esds', kKeyESDS = 'esds', // raw data
kKeyAVCC = 'avcc', kKeyAVCC = 'avcc', // raw data
kKeyTimeUnits = '#tim',
kKeyTimeScale = 'scal',
kKeyWantsNALFragments = 'NALf', kKeyWantsNALFragments = 'NALf',
kKeyIsSyncFrame = 'sync', kKeyIsSyncFrame = 'sync',
kKeyDuration = 'dura', kKeyTime = 'time', // int64_t (usecs)
kKeyDuration = 'dura', // int64_t (usecs)
kKeyColorFormat = 'colf', kKeyColorFormat = 'colf',
kKeyPlatformPrivate = 'priv', kKeyPlatformPrivate = 'priv', // pointer
kKeyDecoderComponent = 'decC', kKeyDecoderComponent = 'decC', // cstring
kKeyBufferID = 'bfID', kKeyBufferID = 'bfID',
kKeyMaxInputSize = 'inpS', kKeyMaxInputSize = 'inpS',
}; };
@ -62,6 +62,7 @@ public:
TYPE_NONE = 'none', TYPE_NONE = 'none',
TYPE_C_STRING = 'cstr', TYPE_C_STRING = 'cstr',
TYPE_INT32 = 'in32', TYPE_INT32 = 'in32',
TYPE_INT64 = 'in64',
TYPE_FLOAT = 'floa', TYPE_FLOAT = 'floa',
TYPE_POINTER = 'ptr ', TYPE_POINTER = 'ptr ',
}; };
@ -71,11 +72,13 @@ public:
bool setCString(uint32_t key, const char *value); bool setCString(uint32_t key, const char *value);
bool setInt32(uint32_t key, int32_t value); bool setInt32(uint32_t key, int32_t value);
bool setInt64(uint32_t key, int64_t value);
bool setFloat(uint32_t key, float value); bool setFloat(uint32_t key, float value);
bool setPointer(uint32_t key, void *value); bool setPointer(uint32_t key, void *value);
bool findCString(uint32_t key, const char **value); bool findCString(uint32_t key, const char **value);
bool findInt32(uint32_t key, int32_t *value); bool findInt32(uint32_t key, int32_t *value);
bool findInt64(uint32_t key, int64_t *value);
bool findFloat(uint32_t key, float *value); bool findFloat(uint32_t key, float *value);
bool findPointer(uint32_t key, void **value); bool findPointer(uint32_t key, void **value);

View File

@ -201,10 +201,7 @@ status_t AMRSource::read(
} }
buffer->set_range(0, frameSize); buffer->set_range(0, frameSize);
buffer->meta_data()->setInt32( buffer->meta_data()->setInt64(kKeyTime, mCurrentTimeUs);
kKeyTimeUnits, (mCurrentTimeUs + 500) / 1000);
buffer->meta_data()->setInt32(
kKeyTimeScale, 1000);
mOffset += frameSize; mOffset += frameSize;
mCurrentTimeUs += 20000; // Each frame is 20ms mCurrentTimeUs += 20000; // Each frame is 20ms

View File

@ -209,15 +209,9 @@ void AudioPlayer::fillBuffer(void *data, size_t size) {
break; break;
} }
int32_t units, scale;
bool success =
mInputBuffer->meta_data()->findInt32(kKeyTimeUnits, &units);
success = success &&
mInputBuffer->meta_data()->findInt32(kKeyTimeScale, &scale);
CHECK(success);
Mutex::Autolock autoLock(mLock); Mutex::Autolock autoLock(mLock);
mPositionTimeMediaUs = (int64_t)units * 1000000 / scale; CHECK(mInputBuffer->meta_data()->findInt64(
kKeyTime, &mPositionTimeMediaUs));
mPositionTimeRealUs = mPositionTimeRealUs =
((mNumFramesPlayed + size_done / mFrameSize) * 1000000) ((mNumFramesPlayed + size_done / mFrameSize) * 1000000)

View File

@ -191,8 +191,7 @@ status_t CameraSource::read(
*buffer = new CameraBuffer(frame); *buffer = new CameraBuffer(frame);
(*buffer)->meta_data()->clear(); (*buffer)->meta_data()->clear();
(*buffer)->meta_data()->setInt32(kKeyTimeScale, 15); (*buffer)->meta_data()->setInt64(kKeyTime, (count * 1000000) / 15);
(*buffer)->meta_data()->setInt32(kKeyTimeUnits, count);
(*buffer)->add_ref(); (*buffer)->add_ref();
(*buffer)->setObserver(this); (*buffer)->setObserver(this);

View File

@ -338,10 +338,9 @@ MP3Extractor::MP3Extractor(const sp<DataSource> &source)
off_t fileSize; off_t fileSize;
if (mDataSource->getSize(&fileSize) == OK) { if (mDataSource->getSize(&fileSize) == OK) {
mMeta->setInt32( mMeta->setInt64(
kKeyDuration, kKeyDuration,
8 * (fileSize - mFirstFramePos) / bitrate); 8000 * (fileSize - mFirstFramePos) / bitrate);
mMeta->setInt32(kKeyTimeScale, 1000);
} }
} }
} }
@ -492,8 +491,7 @@ status_t MP3Source::read(
buffer->set_range(0, frame_size); buffer->set_range(0, frame_size);
buffer->meta_data()->setInt32(kKeyTimeUnits, mCurrentTimeUs / 1000); buffer->meta_data()->setInt64(kKeyTime, mCurrentTimeUs);
buffer->meta_data()->setInt32(kKeyTimeScale, 1000);
mCurrentPos += frame_size; mCurrentPos += frame_size;
mCurrentTimeUs += 1152 * 1000000 / 44100; mCurrentTimeUs += 1152 * 1000000 / 44100;

View File

@ -43,6 +43,7 @@ public:
// Caller retains ownership of both "dataSource" and "sampleTable". // Caller retains ownership of both "dataSource" and "sampleTable".
MPEG4Source(const sp<MetaData> &format, MPEG4Source(const sp<MetaData> &format,
const sp<DataSource> &dataSource, const sp<DataSource> &dataSource,
int32_t timeScale,
const sp<SampleTable> &sampleTable); const sp<SampleTable> &sampleTable);
virtual status_t start(MetaData *params = NULL); virtual status_t start(MetaData *params = NULL);
@ -390,7 +391,6 @@ status_t MPEG4Extractor::parseChunk(off_t *offset, int depth) {
} }
mLastTrack->timescale = ntohl(timescale); mLastTrack->timescale = ntohl(timescale);
mLastTrack->meta->setInt32(kKeyTimeScale, mLastTrack->timescale);
int64_t duration; int64_t duration;
if (version == 1) { if (version == 1) {
@ -409,7 +409,8 @@ status_t MPEG4Extractor::parseChunk(off_t *offset, int depth) {
} }
duration = ntohl(duration32); duration = ntohl(duration32);
} }
mLastTrack->meta->setInt32(kKeyDuration, duration); mLastTrack->meta->setInt64(
kKeyDuration, (duration * 1000000) / mLastTrack->timescale);
*offset += chunk_size; *offset += chunk_size;
break; break;
@ -722,7 +723,7 @@ sp<MediaSource> MPEG4Extractor::getTrack(size_t index) {
} }
return new MPEG4Source( return new MPEG4Source(
track->meta, mDataSource, track->sampleTable); track->meta, mDataSource, track->timescale, track->sampleTable);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -730,10 +731,11 @@ sp<MediaSource> MPEG4Extractor::getTrack(size_t index) {
MPEG4Source::MPEG4Source( MPEG4Source::MPEG4Source(
const sp<MetaData> &format, const sp<MetaData> &format,
const sp<DataSource> &dataSource, const sp<DataSource> &dataSource,
int32_t timeScale,
const sp<SampleTable> &sampleTable) const sp<SampleTable> &sampleTable)
: mFormat(format), : mFormat(format),
mDataSource(dataSource), mDataSource(dataSource),
mTimescale(0), mTimescale(timeScale),
mSampleTable(sampleTable), mSampleTable(sampleTable),
mCurrentSampleIndex(0), mCurrentSampleIndex(0),
mIsAVC(false), mIsAVC(false),
@ -746,9 +748,6 @@ MPEG4Source::MPEG4Source(
bool success = mFormat->findCString(kKeyMIMEType, &mime); bool success = mFormat->findCString(kKeyMIMEType, &mime);
CHECK(success); CHECK(success);
success = mFormat->findInt32(kKeyTimeScale, &mTimescale);
CHECK(success);
mIsAVC = !strcasecmp(mime, MEDIA_MIMETYPE_VIDEO_AVC); mIsAVC = !strcasecmp(mime, MEDIA_MIMETYPE_VIDEO_AVC);
} }
@ -879,8 +878,8 @@ status_t MPEG4Source::read(
mBuffer->set_range(0, size); mBuffer->set_range(0, size);
mBuffer->meta_data()->clear(); mBuffer->meta_data()->clear();
mBuffer->meta_data()->setInt32(kKeyTimeUnits, dts); mBuffer->meta_data()->setInt64(
mBuffer->meta_data()->setInt32(kKeyTimeScale, mTimescale); kKeyTime, ((int64_t)dts * 1000000) / mTimescale);
++mCurrentSampleIndex; ++mCurrentSampleIndex;
} }
@ -959,8 +958,8 @@ status_t MPEG4Source::read(
mBuffer->set_range(0, dstOffset); mBuffer->set_range(0, dstOffset);
mBuffer->meta_data()->clear(); mBuffer->meta_data()->clear();
mBuffer->meta_data()->setInt32(kKeyTimeUnits, dts); mBuffer->meta_data()->setInt64(
mBuffer->meta_data()->setInt32(kKeyTimeScale, mTimescale); kKeyTime, ((int64_t)dts * 1000000) / mTimescale);
++mCurrentSampleIndex; ++mCurrentSampleIndex;
*out = mBuffer; *out = mBuffer;

View File

@ -399,15 +399,11 @@ void MPEG4Writer::Track::threadEntry() {
info.size = buffer->range_length(); info.size = buffer->range_length();
info.offset = offset; info.offset = offset;
int32_t units, scale; int64_t timestampUs;
bool success = CHECK(buffer->meta_data()->findInt64(kKeyTime, &timestampUs));
buffer->meta_data()->findInt32(kKeyTimeUnits, &units);
CHECK(success);
success =
buffer->meta_data()->findInt32(kKeyTimeScale, &scale);
CHECK(success);
info.timestamp = (int64_t)units * 1000 / scale; // Our timestamp is in ms.
info.timestamp = (timestampUs + 500) / 1000;
mSampleInfos.push_back(info); mSampleInfos.push_back(info);

View File

@ -261,15 +261,9 @@ void MediaPlayerImpl::videoEntry() {
continue; continue;
} }
int32_t units, scale; int64_t pts_us;
bool success = CHECK(buffer->meta_data()->findInt64(kKeyTime, &pts_us));
buffer->meta_data()->findInt32(kKeyTimeUnits, &units);
CHECK(success);
success =
buffer->meta_data()->findInt32(kKeyTimeScale, &scale);
CHECK(success);
int64_t pts_us = (int64_t)units * 1000000 / scale;
{ {
Mutex::Autolock autoLock(mLock); Mutex::Autolock autoLock(mLock);
mVideoPosition = pts_us; mVideoPosition = pts_us;
@ -379,12 +373,10 @@ void MediaPlayerImpl::init() {
sp<MediaSource> source = mExtractor->getTrack(i); sp<MediaSource> source = mExtractor->getTrack(i);
int32_t units, scale; int64_t durationUs;
if (meta->findInt32(kKeyDuration, &units) if (meta->findInt64(kKeyDuration, &durationUs)) {
&& meta->findInt32(kKeyTimeScale, &scale)) { if (durationUs > mDuration) {
int64_t duration_us = (int64_t)units * 1000000 / scale; mDuration = durationUs;
if (duration_us > mDuration) {
mDuration = duration_us;
} }
} }

View File

@ -58,6 +58,10 @@ bool MetaData::setInt32(uint32_t key, int32_t value) {
return setData(key, TYPE_INT32, &value, sizeof(value)); return setData(key, TYPE_INT32, &value, sizeof(value));
} }
bool MetaData::setInt64(uint32_t key, int64_t value) {
return setData(key, TYPE_INT64, &value, sizeof(value));
}
bool MetaData::setFloat(uint32_t key, float value) { bool MetaData::setFloat(uint32_t key, float value) {
return setData(key, TYPE_FLOAT, &value, sizeof(value)); return setData(key, TYPE_FLOAT, &value, sizeof(value));
} }
@ -94,6 +98,21 @@ bool MetaData::findInt32(uint32_t key, int32_t *value) {
return true; return true;
} }
bool MetaData::findInt64(uint32_t key, int64_t *value) {
uint32_t type;
const void *data;
size_t size;
if (!findData(key, &type, &data, &size) || type != TYPE_INT64) {
return false;
}
CHECK_EQ(size, sizeof(*value));
*value = *(int64_t *)data;
return true;
}
bool MetaData::findFloat(uint32_t key, float *value) { bool MetaData::findFloat(uint32_t key, float *value) {
uint32_t type; uint32_t type;
const void *data; const void *data;

View File

@ -986,12 +986,8 @@ void OMXCodec::on_message(const omx_message &msg) {
buffer->meta_data()->clear(); buffer->meta_data()->clear();
buffer->meta_data()->setInt32( buffer->meta_data()->setInt64(
kKeyTimeUnits, kKeyTime, msg.u.extended_buffer_data.timestamp);
(msg.u.extended_buffer_data.timestamp + 500) / 1000);
buffer->meta_data()->setInt32(
kKeyTimeScale, 1000);
if (msg.u.extended_buffer_data.flags & OMX_BUFFERFLAG_SYNCFRAME) { if (msg.u.extended_buffer_data.flags & OMX_BUFFERFLAG_SYNCFRAME) {
buffer->meta_data()->setInt32(kKeyIsSyncFrame, true); buffer->meta_data()->setInt32(kKeyIsSyncFrame, true);
@ -1439,7 +1435,7 @@ void OMXCodec::drainInputBuffer(BufferInfo *info) {
} }
OMX_U32 flags = OMX_BUFFERFLAG_ENDOFFRAME; OMX_U32 flags = OMX_BUFFERFLAG_ENDOFFRAME;
OMX_TICKS timestamp = 0; OMX_TICKS timestampUs = 0;
size_t srcLength = 0; size_t srcLength = 0;
if (err != OK) { if (err != OK) {
@ -1459,15 +1455,11 @@ void OMXCodec::drainInputBuffer(BufferInfo *info) {
(const uint8_t *)srcBuffer->data() + srcBuffer->range_offset(), (const uint8_t *)srcBuffer->data() + srcBuffer->range_offset(),
srcLength); srcLength);
int32_t units, scale; if (srcBuffer->meta_data()->findInt64(kKeyTime, &timestampUs)) {
if (srcBuffer->meta_data()->findInt32(kKeyTimeUnits, &units)
&& srcBuffer->meta_data()->findInt32(kKeyTimeScale, &scale)) {
timestamp = ((OMX_TICKS)units * 1000000) / scale;
CODEC_LOGV("Calling empty_buffer on buffer %p (length %d)", CODEC_LOGV("Calling empty_buffer on buffer %p (length %d)",
info->mBuffer, srcLength); info->mBuffer, srcLength);
CODEC_LOGV("Calling empty_buffer with timestamp %lld us (%.2f secs)", CODEC_LOGV("Calling empty_buffer with timestamp %lld us (%.2f secs)",
timestamp, timestamp / 1E6); timestampUs, timestampUs / 1E6);
} }
} }
@ -1478,7 +1470,7 @@ void OMXCodec::drainInputBuffer(BufferInfo *info) {
err = mOMX->empty_buffer( err = mOMX->empty_buffer(
mNode, info->mBuffer, 0, srcLength, mNode, info->mBuffer, 0, srcLength,
flags, timestamp); flags, timestampUs);
if (err != OK) { if (err != OK) {
setState(ERROR); setState(ERROR);