зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1487797 - P1. Move sample index from FrameHeader to Frame. r=jya
Differential Revision: https://phabricator.services.mozilla.com/D9043 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
9b692b9cbd
Коммит
4deffa6a58
|
@ -36,9 +36,6 @@ public:
|
|||
|
||||
bool IsValid() const { return mValid; }
|
||||
|
||||
// Return the index (in samples) from the beginning of the track.
|
||||
int64_t Index() const { return mIndex; }
|
||||
|
||||
// Parse the current packet and check that it made a valid flac frame header.
|
||||
// From https://xiph.org/flac/format.html#frame_header
|
||||
// A valid header is one that can be decoded without error and that has a
|
||||
|
@ -87,11 +84,11 @@ public:
|
|||
}
|
||||
|
||||
// Sample or frame count.
|
||||
int64_t frame_or_sample_num = br.ReadUTF8();
|
||||
if (frame_or_sample_num < 0) {
|
||||
// Sample/frame number invalid.
|
||||
int64_t frameOrSampleNum = br.ReadUTF8();
|
||||
if (frameOrSampleNum < 0) {
|
||||
return false;
|
||||
}
|
||||
mFrameOrSampleNum = frameOrSampleNum;
|
||||
|
||||
// Blocksize
|
||||
if (bs_code == 0) {
|
||||
|
@ -105,13 +102,6 @@ public:
|
|||
mBlocksize = FlacBlocksizeTable[bs_code];
|
||||
}
|
||||
|
||||
// The sample index is either:
|
||||
// 1- coded sample number if blocksize is variable or
|
||||
// 2- coded frame number if blocksize is known.
|
||||
// A frame is made of Blocksize sample.
|
||||
mIndex = mVariableBlockSize ? frame_or_sample_num
|
||||
: frame_or_sample_num * mBlocksize;
|
||||
|
||||
// Sample rate.
|
||||
if (sr_code < 12) {
|
||||
mInfo.mRate = FlacSampleRateTable[sr_code];
|
||||
|
@ -152,8 +142,11 @@ private:
|
|||
FLAC_CHMODE_MID_SIDE,
|
||||
};
|
||||
AudioInfo mInfo;
|
||||
// Index in samples from start;
|
||||
int64_t mIndex = 0;
|
||||
// mFrameOrSampleNum is either:
|
||||
// 1- coded sample number if blocksize is variable or
|
||||
// 2- coded frame number if blocksize is fixed.
|
||||
// A frame is made of Blocksize sample.
|
||||
uint64_t mFrameOrSampleNum = 0;
|
||||
bool mVariableBlockSize = false;
|
||||
uint32_t mBlocksize = 0;;
|
||||
uint32_t mSize = 0;
|
||||
|
@ -290,6 +283,7 @@ public:
|
|||
|
||||
if (foundOffset >= 0) {
|
||||
SetOffset(aResource, foundOffset + offset);
|
||||
SetIndex();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -318,10 +312,13 @@ public:
|
|||
|
||||
void SetEndOffset(int64_t aOffset) { mSize = aOffset - mOffset; }
|
||||
|
||||
void SetEndTime(int64_t aIndex)
|
||||
// Return the index (in samples) from the beginning of the track.
|
||||
uint64_t Index() const { return mIndex; }
|
||||
|
||||
void SetEndTime(uint64_t aIndex)
|
||||
{
|
||||
if (aIndex > Header().mIndex) {
|
||||
mDuration = aIndex - Header().mIndex;
|
||||
if (aIndex > Index()) {
|
||||
mDuration = aIndex - Index();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -333,7 +330,7 @@ public:
|
|||
return TimeUnit::Invalid();
|
||||
}
|
||||
MOZ_ASSERT(Header().Info().mRate, "Invalid Frame. Need Header");
|
||||
return FramesToTimeUnit(Header().mIndex, Header().Info().mRate);
|
||||
return FramesToTimeUnit(Index(), Header().Info().mRate);
|
||||
}
|
||||
|
||||
TimeUnit Duration() const
|
||||
|
@ -368,6 +365,18 @@ private:
|
|||
aResource.Seek(SEEK_SET, mOffset);
|
||||
}
|
||||
|
||||
void SetIndex()
|
||||
{
|
||||
// Make sure the header has been parsed.
|
||||
MOZ_ASSERT(Header().mBlocksize);
|
||||
|
||||
mIndex = Header().mVariableBlockSize
|
||||
? Header().mFrameOrSampleNum
|
||||
: Header().mFrameOrSampleNum * Header().mBlocksize;
|
||||
}
|
||||
|
||||
// The index in samples from start.
|
||||
uint64_t mIndex = 0;
|
||||
// The offset to the start of the header.
|
||||
int64_t mOffset = 0;
|
||||
uint32_t mSize = 0;
|
||||
|
@ -413,7 +422,7 @@ public:
|
|||
mFrame.SetEndOffset(aResource.Tell());
|
||||
} else if (mNextFrame.IsValid()) {
|
||||
mFrame.SetEndOffset(mNextFrame.Offset());
|
||||
mFrame.SetEndTime(mNextFrame.Header().Index());
|
||||
mFrame.SetEndTime(mNextFrame.Index());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче