void stop();
bool reachedEOS();
- int64_t getDuration() const;
+ int64_t getDurationUs() const;
void writeTrackHeader(int32_t trackID);
private:
sp<MetaData> mMeta;
sp<MediaSource> mSource;
volatile bool mDone;
+ int64_t mMaxTimeStampUs;
pthread_t mThread;
it != mTracks.end(); ++it) {
(*it)->stop();
- int64_t duration = (*it)->getDuration();
+ int64_t duration = (*it)->getDurationUs();
if (duration > max_duration) {
max_duration = duration;
}
writeInt32(now); // creation time
writeInt32(now); // modification time
writeInt32(1000); // timescale
- writeInt32(max_duration);
+ writeInt32(max_duration / 1000);
writeInt32(0x10000); // rate
writeInt16(0x100); // volume
writeInt16(0); // reserved
mMeta(source->getFormat()),
mSource(source),
mDone(false),
+ mMaxTimeStampUs(0),
mCodecSpecificData(NULL),
mCodecSpecificDataSize(0),
mReachedEOS(false) {
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
mDone = false;
+ mMaxTimeStampUs = 0;
mReachedEOS = false;
pthread_create(&mThread, &attr, ThreadWrapper, this);
int64_t timestampUs;
CHECK(buffer->meta_data()->findInt64(kKeyTime, ×tampUs));
+ if (timestampUs > mMaxTimeStampUs) {
+ mMaxTimeStampUs = timestampUs;
+ }
+
// Our timestamp is in ms.
info.timestamp = (timestampUs + 500) / 1000;
mReachedEOS = true;
}
-int64_t MPEG4Writer::Track::getDuration() const {
- return 10000; // XXX
+int64_t MPEG4Writer::Track::getDurationUs() const {
+ return mMaxTimeStampUs;
}
void MPEG4Writer::Track::writeTrackHeader(int32_t trackID) {
mOwner->writeInt32(now); // modification time
mOwner->writeInt32(trackID);
mOwner->writeInt32(0); // reserved
- mOwner->writeInt32(getDuration());
+ mOwner->writeInt32(getDurationUs() / 1000);
mOwner->writeInt32(0); // reserved
mOwner->writeInt32(0); // reserved
mOwner->writeInt16(0); // layer
mOwner->writeInt32(now); // creation time
mOwner->writeInt32(now); // modification time
mOwner->writeInt32(1000); // timescale
- mOwner->writeInt32(getDuration());
+ mOwner->writeInt32(getDurationUs() / 1000);
mOwner->writeInt16(0); // language code XXX
mOwner->writeInt16(0); // predefined
mOwner->endBox();