зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1098126
- Remove duplication in MP4 demuxer seek; r=mattwoodrow
This commit is contained in:
Родитель
524fc6fe76
Коммит
162732a26d
|
@ -112,6 +112,7 @@ private:
|
|||
status_t parseSampleAuxiliaryInformationSizes(off64_t offset, off64_t size);
|
||||
status_t parseSampleAuxiliaryInformationOffsets(off64_t offset, off64_t size);
|
||||
void lookForMoof();
|
||||
status_t moveToNextFragment();
|
||||
|
||||
struct TrackFragmentHeaderInfo {
|
||||
enum Flags {
|
||||
|
@ -3575,6 +3576,34 @@ status_t MPEG4Source::read(
|
|||
}
|
||||
}
|
||||
|
||||
status_t MPEG4Source::moveToNextFragment() {
|
||||
off64_t nextMoof = mNextMoofOffset;
|
||||
mCurrentSamples.clear();
|
||||
mDeferredSaio.clear();
|
||||
mDeferredSaiz.clear();
|
||||
mCurrentSampleIndex = 0;
|
||||
uint32_t hdr[2];
|
||||
do {
|
||||
if (mDataSource->readAt(nextMoof, hdr, 8) < 8) {
|
||||
return ERROR_END_OF_STREAM;
|
||||
}
|
||||
uint64_t chunk_size = ntohl(hdr[0]);
|
||||
uint32_t chunk_type = ntohl(hdr[1]);
|
||||
|
||||
// Skip over anything that isn't a moof
|
||||
if (chunk_type != FOURCC('m', 'o', 'o', 'f')) {
|
||||
nextMoof += chunk_size;
|
||||
continue;
|
||||
}
|
||||
mCurrentMoofOffset = nextMoof;
|
||||
status_t ret = parseChunk(&nextMoof);
|
||||
if (ret != OK) {
|
||||
return ret;
|
||||
}
|
||||
} while (mCurrentSamples.size() == 0);
|
||||
return OK;
|
||||
}
|
||||
|
||||
status_t MPEG4Source::fragmentedRead(
|
||||
MediaBuffer **out, const ReadOptions *options) {
|
||||
|
||||
|
@ -3590,10 +3619,6 @@ status_t MPEG4Source::fragmentedRead(
|
|||
ReadOptions::SeekMode mode;
|
||||
if (options && options->getSeekTo(&seekTimeUs, &mode)) {
|
||||
|
||||
mCurrentSamples.clear();
|
||||
mDeferredSaio.clear();
|
||||
mDeferredSaiz.clear();
|
||||
mCurrentSampleIndex = 0;
|
||||
int numSidxEntries = mSegments.size();
|
||||
if (numSidxEntries != 0) {
|
||||
int64_t totalTime = 0;
|
||||
|
@ -3616,37 +3641,21 @@ status_t MPEG4Source::fragmentedRead(
|
|||
totalOffset += se->mSize;
|
||||
}
|
||||
mCurrentMoofOffset = totalOffset;
|
||||
mNextMoofOffset = totalOffset;
|
||||
mCurrentSamples.clear();
|
||||
mDeferredSaio.clear();
|
||||
mDeferredSaiz.clear();
|
||||
mCurrentSampleIndex = 0;
|
||||
mCurrentTime = totalTime * mTimescale / 1000000ll;
|
||||
mNextMoofOffset = totalOffset;
|
||||
}
|
||||
else {
|
||||
mNextMoofOffset = mFirstMoofOffset;
|
||||
uint32_t seekTime = (int32_t) ((seekTimeUs * mTimescale) / 1000000ll);
|
||||
while (true) {
|
||||
|
||||
uint32_t hdr[2];
|
||||
do {
|
||||
off64_t moofOffset = mNextMoofOffset; // lastSample.offset + lastSample.size;
|
||||
if (mDataSource->readAt(moofOffset, hdr, 8) < 8) {
|
||||
ALOGV("Seek ERROR_END_OF_STREAM\n");
|
||||
return ERROR_END_OF_STREAM;
|
||||
}
|
||||
uint64_t chunk_size = ntohl(hdr[0]);
|
||||
uint32_t chunk_type = ntohl(hdr[1]);
|
||||
char chunk[5];
|
||||
MakeFourCCString(chunk_type, chunk);
|
||||
|
||||
// If we're pointing to a segment type or sidx box then we skip them.
|
||||
if (chunk_type != FOURCC('m', 'o', 'o', 'f')) {
|
||||
mNextMoofOffset += chunk_size;
|
||||
continue;
|
||||
}
|
||||
mCurrentMoofOffset = moofOffset;
|
||||
status_t ret = parseChunk(&moofOffset);
|
||||
if (ret != OK) {
|
||||
return ret;
|
||||
}
|
||||
} while (mCurrentSamples.size() == 0);
|
||||
status_t ret = moveToNextFragment();
|
||||
if (ret != OK) {
|
||||
return ret;
|
||||
}
|
||||
uint32_t time = mCurrentTime;
|
||||
int i;
|
||||
for (i = 0; i < mCurrentSamples.size() && time <= seekTime; i++) {
|
||||
|
@ -3660,11 +3669,6 @@ status_t MPEG4Source::fragmentedRead(
|
|||
if (i != mCurrentSamples.size()) {
|
||||
break;
|
||||
}
|
||||
|
||||
mCurrentSamples.clear();
|
||||
mDeferredSaio.clear();
|
||||
mDeferredSaiz.clear();
|
||||
mCurrentSampleIndex = 0;
|
||||
}
|
||||
ALOGV("Seeking offset %d; %ldus\n", mCurrentTime - seekTime,
|
||||
(((int64_t) mCurrentTime - seekTime) * 1000000ll) / mTimescale);
|
||||
|
@ -3689,32 +3693,10 @@ status_t MPEG4Source::fragmentedRead(
|
|||
newBuffer = true;
|
||||
|
||||
if (mCurrentSampleIndex >= mCurrentSamples.size()) {
|
||||
// move to next fragment
|
||||
off64_t nextMoof = mNextMoofOffset; // lastSample.offset + lastSample.size;
|
||||
mCurrentSamples.clear();
|
||||
mDeferredSaio.clear();
|
||||
mDeferredSaiz.clear();
|
||||
mCurrentSampleIndex = 0;
|
||||
uint32_t hdr[2];
|
||||
do {
|
||||
if (mDataSource->readAt(nextMoof, hdr, 8) < 8) {
|
||||
return ERROR_END_OF_STREAM;
|
||||
}
|
||||
uint64_t chunk_size = ntohl(hdr[0]);
|
||||
uint32_t chunk_type = ntohl(hdr[1]);
|
||||
|
||||
// If we're pointing to a segment type or sidx box then we skip them.
|
||||
if (chunk_type == FOURCC('s', 't', 'y', 'p') ||
|
||||
chunk_type == FOURCC('s', 'i', 'd', 'x')) {
|
||||
nextMoof += chunk_size;
|
||||
continue;
|
||||
}
|
||||
mCurrentMoofOffset = nextMoof;
|
||||
status_t ret = parseChunk(&nextMoof);
|
||||
if (ret != OK) {
|
||||
return ret;
|
||||
}
|
||||
} while (mCurrentSamples.size() == 0);
|
||||
status_t ret = moveToNextFragment();
|
||||
if (ret != OK) {
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
const Sample *smpl = &mCurrentSamples[mCurrentSampleIndex];
|
||||
|
|
Загрузка…
Ссылка в новой задаче