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;
}
buffer->meta_data()->setInt32(kKeyTimeUnits, mPhase);
buffer->meta_data()->setInt32(kKeyTimeScale, mSampleRate);
buffer->meta_data()->setInt64(
kKeyTime, ((int64_t)mPhase * 1000000) / mSampleRate);
mPhase += numFramesPerBuffer;

View File

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

View File

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

View File

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

View File

@ -209,15 +209,9 @@ void AudioPlayer::fillBuffer(void *data, size_t size) {
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);
mPositionTimeMediaUs = (int64_t)units * 1000000 / scale;
CHECK(mInputBuffer->meta_data()->findInt64(
kKeyTime, &mPositionTimeMediaUs));
mPositionTimeRealUs =
((mNumFramesPlayed + size_done / mFrameSize) * 1000000)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -58,6 +58,10 @@ bool MetaData::setInt32(uint32_t key, int32_t 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) {
return setData(key, TYPE_FLOAT, &value, sizeof(value));
}
@ -94,6 +98,21 @@ bool MetaData::findInt32(uint32_t key, int32_t *value) {
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) {
uint32_t type;
const void *data;

View File

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