--- a/dom/media/ogg/OggCodecState.cpp
+++ b/dom/media/ogg/OggCodecState.cpp
@@ -50,75 +50,83 @@ OggCodecState::Create(ogg_page* aPage)
} else if (aPage->body_len > 8 && memcmp(aPage->body, "fishead\0", 8) == 0) {
codecState = new SkeletonState(aPage);
} else {
codecState = new OggCodecState(aPage, false);
}
return codecState->OggCodecState::Init() ? codecState.forget() : nullptr;
}
-OggCodecState::OggCodecState(ogg_page* aBosPage, bool aActive) :
- mPacketCount(0),
- mSerial(ogg_page_serialno(aBosPage)),
- mActive(aActive),
- mDoneReadingHeaders(!aActive)
+OggCodecState::OggCodecState(ogg_page* aBosPage, bool aActive)
+ : mPacketCount(0)
+ , mSerial(ogg_page_serialno(aBosPage))
+ , mActive(aActive)
+ , mDoneReadingHeaders(!aActive)
{
MOZ_COUNT_CTOR(OggCodecState);
memset(&mState, 0, sizeof(ogg_stream_state));
}
-OggCodecState::~OggCodecState() {
+OggCodecState::~OggCodecState()
+{
MOZ_COUNT_DTOR(OggCodecState);
Reset();
#ifdef DEBUG
int ret =
#endif
ogg_stream_clear(&mState);
NS_ASSERTION(ret == 0, "ogg_stream_clear failed");
}
-nsresult OggCodecState::Reset() {
+nsresult
+OggCodecState::Reset()
+{
if (ogg_stream_reset(&mState) != 0) {
return NS_ERROR_FAILURE;
}
mPackets.Erase();
ClearUnstamped();
return NS_OK;
}
-void OggCodecState::ClearUnstamped()
+void
+OggCodecState::ClearUnstamped()
{
for (uint32_t i = 0; i < mUnstamped.Length(); ++i) {
OggCodecState::ReleasePacket(mUnstamped[i]);
}
mUnstamped.Clear();
}
-bool OggCodecState::Init() {
+bool
+OggCodecState::Init()
+{
int ret = ogg_stream_init(&mState, mSerial);
return ret == 0;
}
-bool OggCodecState::IsValidVorbisTagName(nsCString& aName)
+bool
+OggCodecState::IsValidVorbisTagName(nsCString& aName)
{
// Tag names must consist of ASCII 0x20 through 0x7D,
// excluding 0x3D '=' which is the separator.
uint32_t length = aName.Length();
const char* data = aName.Data();
for (uint32_t i = 0; i < length; i++) {
if (data[i] < 0x20 || data[i] > 0x7D || data[i] == '=') {
return false;
}
}
return true;
}
-bool OggCodecState::AddVorbisComment(MetadataTags* aTags,
- const char* aComment,
- uint32_t aLength)
+bool
+OggCodecState::AddVorbisComment(MetadataTags* aTags,
+ const char* aComment,
+ uint32_t aLength)
{
const char* div = (const char*)memchr(aComment, '=', aLength);
if (!div) {
LOG(LogLevel::Debug, ("Skipping comment: no separator"));
return false;
}
nsCString key = nsCString(aComment, div-aComment);
if (!IsValidVorbisTagName(key)) {
@@ -130,87 +138,101 @@ bool OggCodecState::AddVorbisComment(Met
if (!IsUTF8(value)) {
LOG(LogLevel::Debug, ("Skipping comment: invalid UTF-8 in value"));
return false;
}
aTags->Put(key, value);
return true;
}
-void VorbisState::RecordVorbisPacketSamples(ogg_packet* aPacket,
- long aSamples)
+void
+VorbisState::RecordVorbisPacketSamples(ogg_packet* aPacket, long aSamples)
{
#ifdef VALIDATE_VORBIS_SAMPLE_CALCULATION
mVorbisPacketSamples[aPacket] = aSamples;
#endif
}
-void VorbisState::ValidateVorbisPacketSamples(ogg_packet* aPacket,
- long aSamples)
+void
+VorbisState::ValidateVorbisPacketSamples(ogg_packet* aPacket, long aSamples)
{
#ifdef VALIDATE_VORBIS_SAMPLE_CALCULATION
NS_ASSERTION(mVorbisPacketSamples[aPacket] == aSamples,
"Decoded samples for Vorbis packet don't match expected!");
mVorbisPacketSamples.erase(aPacket);
#endif
}
-void VorbisState::AssertHasRecordedPacketSamples(ogg_packet* aPacket)
+void
+VorbisState::AssertHasRecordedPacketSamples(ogg_packet* aPacket)
{
#ifdef VALIDATE_VORBIS_SAMPLE_CALCULATION
NS_ASSERTION(mVorbisPacketSamples.count(aPacket) == 1,
"Must have recorded packet samples");
#endif
}
-static ogg_packet* Clone(ogg_packet* aPacket) {
+static ogg_packet*
+Clone(ogg_packet* aPacket)
+{
ogg_packet* p = new ogg_packet();
memcpy(p, aPacket, sizeof(ogg_packet));
p->packet = new unsigned char[p->bytes];
memcpy(p->packet, aPacket->packet, p->bytes);
return p;
}
-void OggCodecState::ReleasePacket(ogg_packet* aPacket) {
+void
+OggCodecState::ReleasePacket(ogg_packet* aPacket)
+{
if (aPacket)
delete [] aPacket->packet;
delete aPacket;
}
-void OggPacketQueue::Append(ogg_packet* aPacket) {
+void
+OggPacketQueue::Append(ogg_packet* aPacket)
+{
nsDeque::Push(aPacket);
}
-bool OggCodecState::IsPacketReady()
+bool
+OggCodecState::IsPacketReady()
{
return !mPackets.IsEmpty();
}
-ogg_packet* OggCodecState::PacketOut() {
+ogg_packet*
+OggCodecState::PacketOut()
+{
if (mPackets.IsEmpty()) {
return nullptr;
}
return mPackets.PopFront();
}
-ogg_packet* OggCodecState::PacketPeek() {
+ogg_packet*
+OggCodecState::PacketPeek()
+{
if (mPackets.IsEmpty()) {
return nullptr;
}
return mPackets.PeekFront();
}
-void OggCodecState::PushFront(OggPacketQueue &&aOther)
+void
+OggCodecState::PushFront(OggPacketQueue &&aOther)
{
while (!aOther.IsEmpty()) {
mPackets.PushFront(aOther.Pop());
}
}
-RefPtr<MediaRawData> OggCodecState::PacketOutAsMediaRawData()
+RefPtr<MediaRawData>
+OggCodecState::PacketOutAsMediaRawData()
{
ogg_packet* packet = PacketOut();
if (!packet) {
return nullptr;
}
NS_ASSERTION(!IsHeader(packet), "PacketOutAsMediaRawData can only be called on non-header packets");
RefPtr<MediaRawData> sample = new MediaRawData(packet->packet, packet->bytes);
@@ -226,39 +248,45 @@ RefPtr<MediaRawData> OggCodecState::Pack
sample->mDuration = duration;
sample->mKeyframe = IsKeyframe(packet);
ReleasePacket(packet);
return sample;
}
-nsresult OggCodecState::PageIn(ogg_page* aPage) {
- if (!mActive)
+nsresult
+OggCodecState::PageIn(ogg_page* aPage)
+{
+ if (!mActive) {
return NS_OK;
+ }
NS_ASSERTION(static_cast<uint32_t>(ogg_page_serialno(aPage)) == mSerial,
"Page must be for this stream!");
- if (ogg_stream_pagein(&mState, aPage) == -1)
+ if (ogg_stream_pagein(&mState, aPage) == -1) {
return NS_ERROR_FAILURE;
+ }
int r;
do {
ogg_packet packet;
r = ogg_stream_packetout(&mState, &packet);
if (r == 1) {
mPackets.Append(Clone(&packet));
}
} while (r != 0);
if (ogg_stream_check(&mState)) {
NS_WARNING("Unrecoverable error in ogg_stream_packetout");
return NS_ERROR_FAILURE;
}
return NS_OK;
}
-nsresult OggCodecState::PacketOutUntilGranulepos(bool& aFoundGranulepos) {
+nsresult
+OggCodecState::PacketOutUntilGranulepos(bool& aFoundGranulepos)
+{
int r;
aFoundGranulepos = false;
// Extract packets from the sync state until either no more packets
// come out, or we get a data packet with non -1 granulepos.
do {
ogg_packet packet;
r = ogg_stream_packetout(&mState, &packet);
if (r == 1) {
@@ -277,55 +305,59 @@ nsresult OggCodecState::PacketOutUntilGr
} while (r != 0 && !aFoundGranulepos);
if (ogg_stream_check(&mState)) {
NS_WARNING("Unrecoverable error in ogg_stream_packetout");
return NS_ERROR_FAILURE;
}
return NS_OK;
}
-TheoraState::TheoraState(ogg_page* aBosPage) :
- OggCodecState(aBosPage, true),
- mSetup(0),
- mCtx(0),
- mPixelAspectRatio(0)
+TheoraState::TheoraState(ogg_page* aBosPage)
+ : OggCodecState(aBosPage, true)
+ , mSetup(0)
+ , mCtx(0)
+ , mPixelAspectRatio(0)
{
MOZ_COUNT_CTOR(TheoraState);
th_info_init(&mInfo);
th_comment_init(&mComment);
}
-TheoraState::~TheoraState() {
+TheoraState::~TheoraState()
+{
MOZ_COUNT_DTOR(TheoraState);
th_setup_free(mSetup);
th_decode_free(mCtx);
th_comment_clear(&mComment);
th_info_clear(&mInfo);
}
-bool TheoraState::Init() {
- if (!mActive)
+bool
+TheoraState::Init()
+{
+ if (!mActive) {
return false;
+ }
int64_t n = mInfo.aspect_numerator;
int64_t d = mInfo.aspect_denominator;
- mPixelAspectRatio = (n == 0 || d == 0) ?
- 1.0f : static_cast<float>(n) / static_cast<float>(d);
+ mPixelAspectRatio = (n == 0 || d == 0)
+ ? 1.0f : static_cast<float>(n) / static_cast<float>(d);
// Ensure the frame and picture regions aren't larger than our prescribed
// maximum, or zero sized.
nsIntSize frame(mInfo.frame_width, mInfo.frame_height);
nsIntRect picture(mInfo.pic_x, mInfo.pic_y, mInfo.pic_width, mInfo.pic_height);
if (!IsValidVideoRegion(frame, picture, frame)) {
return mActive = false;
}
mCtx = th_decode_alloc(&mInfo, mSetup);
- if (mCtx == nullptr) {
+ if (!mCtx) {
return mActive = false;
}
return true;
}
bool
TheoraState::DecodeHeader(ogg_packet* aPacket)
@@ -360,62 +392,73 @@ TheoraState::DecodeHeader(ogg_packet* aP
} else if (ret > 0 && isSetupHeader && mPacketCount == 3) {
// Successfully read the three header packets.
mDoneReadingHeaders = true;
}
return true;
}
int64_t
-TheoraState::Time(int64_t granulepos) {
+TheoraState::Time(int64_t granulepos)
+{
if (!mActive) {
return -1;
}
return TheoraState::Time(&mInfo, granulepos);
}
bool
-TheoraState::IsHeader(ogg_packet* aPacket) {
+TheoraState::IsHeader(ogg_packet* aPacket)
+{
return th_packet_isheader(aPacket);
}
# define TH_VERSION_CHECK(_info,_maj,_min,_sub) \
(((_info)->version_major>(_maj)||(_info)->version_major==(_maj))&& \
(((_info)->version_minor>(_min)||(_info)->version_minor==(_min))&& \
(_info)->version_subminor>=(_sub)))
-int64_t TheoraState::Time(th_info* aInfo, int64_t aGranulepos)
+int64_t
+TheoraState::Time(th_info* aInfo, int64_t aGranulepos)
{
if (aGranulepos < 0 || aInfo->fps_numerator == 0) {
return -1;
}
// Implementation of th_granule_frame inlined here to operate
// on the th_info structure instead of the theora_state.
int shift = aInfo->keyframe_granule_shift;
ogg_int64_t iframe = aGranulepos >> shift;
ogg_int64_t pframe = aGranulepos - (iframe << shift);
int64_t frameno = iframe + pframe - TH_VERSION_CHECK(aInfo, 3, 2, 1);
- CheckedInt64 t = ((CheckedInt64(frameno) + 1) * USECS_PER_S) * aInfo->fps_denominator;
- if (!t.isValid())
+ CheckedInt64 t =
+ ((CheckedInt64(frameno) + 1) * USECS_PER_S) * aInfo->fps_denominator;
+ if (!t.isValid()) {
return -1;
+ }
t /= aInfo->fps_numerator;
return t.isValid() ? t.value() : -1;
}
-int64_t TheoraState::StartTime(int64_t granulepos) {
+int64_t TheoraState::StartTime(int64_t granulepos)
+{
if (granulepos < 0 || !mActive || mInfo.fps_numerator == 0) {
return -1;
}
- CheckedInt64 t = (CheckedInt64(th_granule_frame(mCtx, granulepos)) * USECS_PER_S) * mInfo.fps_denominator;
- if (!t.isValid())
+ CheckedInt64 t =
+ (CheckedInt64(th_granule_frame(mCtx, granulepos)) * USECS_PER_S)
+ * mInfo.fps_denominator;
+ if (!t.isValid()) {
return -1;
+ }
return t.value() / mInfo.fps_numerator;
}
-int64_t TheoraState::PacketDuration(ogg_packet* aPacket) {
+int64_t
+TheoraState::PacketDuration(ogg_packet* aPacket)
+{
if (!mActive || mInfo.fps_numerator == 0) {
return -1;
}
CheckedInt64 t = CheckedInt64(mInfo.fps_denominator) * USECS_PER_S;
if (!t.isValid()) {
return -1;
}
return t.value() / mInfo.fps_numerator;
@@ -489,17 +532,18 @@ TheoraVersion(th_info* info,
{
ogg_uint32_t ver = (maj << 16) + (min << 8) + sub;
ogg_uint32_t th_ver = (info->version_major << 16) +
(info->version_minor << 8) +
info->version_subminor;
return (th_ver >= ver) ? 1 : 0;
}
-void TheoraState::ReconstructTheoraGranulepos()
+void
+TheoraState::ReconstructTheoraGranulepos()
{
if (mUnstamped.Length() == 0) {
return;
}
ogg_int64_t lastGranulepos = mUnstamped[mUnstamped.Length() - 1]->granulepos;
NS_ASSERTION(lastGranulepos != -1, "Must know last granulepos");
// Reconstruct the granulepos (and thus timestamps) of the decoded
@@ -568,54 +612,58 @@ void TheoraState::ReconstructTheoraGranu
// the last frame's (the known granule number). If not our granulepos
// recovery missed a beat.
NS_ASSERTION(mUnstamped.Length() < 2 ||
th_granule_frame(mCtx, mUnstamped[mUnstamped.Length()-2]->granulepos) + 1 ==
th_granule_frame(mCtx, lastGranulepos),
"Granulepos recovery should catch up with packet->granulepos!");
}
-nsresult VorbisState::Reset()
+nsresult
+VorbisState::Reset()
{
nsresult res = NS_OK;
if (mActive && vorbis_synthesis_restart(&mDsp) != 0) {
res = NS_ERROR_FAILURE;
}
if (NS_FAILED(OggCodecState::Reset())) {
return NS_ERROR_FAILURE;
}
mGranulepos = 0;
mPrevVorbisBlockSize = 0;
return res;
}
-VorbisState::VorbisState(ogg_page* aBosPage) :
- OggCodecState(aBosPage, true),
- mPrevVorbisBlockSize(0),
- mGranulepos(0)
+VorbisState::VorbisState(ogg_page* aBosPage)
+ : OggCodecState(aBosPage, true)
+ , mPrevVorbisBlockSize(0)
+ , mGranulepos(0)
{
MOZ_COUNT_CTOR(VorbisState);
vorbis_info_init(&mInfo);
vorbis_comment_init(&mComment);
memset(&mDsp, 0, sizeof(vorbis_dsp_state));
memset(&mBlock, 0, sizeof(vorbis_block));
}
-VorbisState::~VorbisState() {
+VorbisState::~VorbisState()
+{
MOZ_COUNT_DTOR(VorbisState);
Reset();
vorbis_block_clear(&mBlock);
vorbis_dsp_clear(&mDsp);
vorbis_info_clear(&mInfo);
vorbis_comment_clear(&mComment);
}
-bool VorbisState::DecodeHeader(ogg_packet* aPacket) {
+bool
+VorbisState::DecodeHeader(ogg_packet* aPacket)
+{
nsAutoRef<ogg_packet> autoRelease(aPacket);
mPacketCount++;
int ret = vorbis_synthesis_headerin(&mInfo,
&mComment,
aPacket);
// We must determine when we've read the last header packet.
// vorbis_synthesis_headerin() does not tell us when it's read the last
// header, so we must keep track of the headers externally.
@@ -642,20 +690,22 @@ bool VorbisState::DecodeHeader(ogg_packe
} else if (ret == 0 && isSetupHeader && mPacketCount == 3) {
// Successfully read the three header packets.
// The bitstream remains active.
mDoneReadingHeaders = true;
}
return true;
}
-bool VorbisState::Init()
+bool
+VorbisState::Init()
{
- if (!mActive)
+ if (!mActive) {
return false;
+ }
int ret = vorbis_synthesis_init(&mDsp, &mInfo);
if (ret != 0) {
NS_WARNING("vorbis_synthesis_init() failed initializing vorbis bitstream");
return mActive = false;
}
ret = vorbis_block_init(&mDsp, &mBlock);
if (ret != 0) {
@@ -663,37 +713,41 @@ bool VorbisState::Init()
if (mActive) {
vorbis_dsp_clear(&mDsp);
}
return mActive = false;
}
return true;
}
-int64_t VorbisState::Time(int64_t granulepos)
+int64_t
+VorbisState::Time(int64_t granulepos)
{
if (!mActive) {
return -1;
}
return VorbisState::Time(&mInfo, granulepos);
}
-int64_t VorbisState::Time(vorbis_info* aInfo, int64_t aGranulepos)
+int64_t
+VorbisState::Time(vorbis_info* aInfo, int64_t aGranulepos)
{
if (aGranulepos == -1 || aInfo->rate == 0) {
return -1;
}
CheckedInt64 t = CheckedInt64(aGranulepos) * USECS_PER_S;
- if (!t.isValid())
+ if (!t.isValid()) {
t = 0;
+ }
return t.value() / aInfo->rate;
}
-int64_t VorbisState::PacketDuration(ogg_packet* aPacket)
+int64_t
+VorbisState::PacketDuration(ogg_packet* aPacket)
{
if (!mActive) {
return -1;
}
if (aPacket->granulepos == -1) {
return -1;
}
// @FIXME store these in a more stable place
@@ -729,43 +783,46 @@ VorbisState::GetTags()
mComment.comment_lengths[i]);
}
return tags;
}
nsresult
VorbisState::PageIn(ogg_page* aPage)
{
- if (!mActive)
+ if (!mActive) {
return NS_OK;
+ }
NS_ASSERTION(static_cast<uint32_t>(ogg_page_serialno(aPage)) == mSerial,
"Page must be for this stream!");
if (ogg_stream_pagein(&mState, aPage) == -1)
return NS_ERROR_FAILURE;
bool foundGp;
nsresult res = PacketOutUntilGranulepos(foundGp);
- if (NS_FAILED(res))
+ if (NS_FAILED(res)) {
return res;
+ }
if (foundGp && mDoneReadingHeaders) {
// We've found a packet with a granulepos, and we've loaded our metadata
// and initialized our decoder. Determine granulepos of buffered packets.
ReconstructVorbisGranulepos();
for (uint32_t i = 0; i < mUnstamped.Length(); ++i) {
ogg_packet* packet = mUnstamped[i];
AssertHasRecordedPacketSamples(packet);
NS_ASSERTION(!IsHeader(packet), "Don't try to recover header packet gp");
NS_ASSERTION(packet->granulepos != -1, "Packet must have gp by now");
mPackets.Append(packet);
}
mUnstamped.Clear();
}
return NS_OK;
}
-nsresult VorbisState::ReconstructVorbisGranulepos()
+nsresult
+VorbisState::ReconstructVorbisGranulepos()
{
// The number of samples in a Vorbis packet is:
// window_blocksize(previous_packet)/4+window_blocksize(current_packet)/4
// See: http://xiph.org/vorbis/doc/Vorbis_I_spec.html#x1-230001.3.2
// So we maintain mPrevVorbisBlockSize, the block size of the last packet
// encountered. We also maintain mGranulepos, which is the granulepos of
// the last encountered packet. This enables us to give granulepos to
// packets when the last packet in mUnstamped doesn't have a granulepos
@@ -866,43 +923,46 @@ nsresult VorbisState::ReconstructVorbisG
mPrevVorbisBlockSize = vorbis_packet_blocksize(&mInfo, last);
mPrevVorbisBlockSize = std::max(static_cast<long>(0), mPrevVorbisBlockSize);
mGranulepos = last->granulepos;
return NS_OK;
}
-OpusState::OpusState(ogg_page* aBosPage) :
- OggCodecState(aBosPage, true),
- mParser(nullptr),
- mDecoder(nullptr),
- mSkip(0),
- mPrevPacketGranulepos(0),
- mPrevPageGranulepos(0)
+OpusState::OpusState(ogg_page* aBosPage)
+ : OggCodecState(aBosPage, true)
+ , mParser(nullptr)
+ , mDecoder(nullptr)
+ , mSkip(0)
+ , mPrevPacketGranulepos(0)
+ , mPrevPageGranulepos(0)
{
MOZ_COUNT_CTOR(OpusState);
}
-OpusState::~OpusState() {
+OpusState::~OpusState()
+{
MOZ_COUNT_DTOR(OpusState);
Reset();
if (mDecoder) {
opus_multistream_decoder_destroy(mDecoder);
mDecoder = nullptr;
}
}
-nsresult OpusState::Reset()
+nsresult
+OpusState::Reset()
{
return Reset(false);
}
-nsresult OpusState::Reset(bool aStart)
+nsresult
+OpusState::Reset(bool aStart)
{
nsresult res = NS_OK;
if (mActive && mDecoder) {
// Reset the decoder.
opus_multistream_decoder_ctl(mDecoder, OPUS_RESET_STATE);
// Let the seek logic handle pre-roll if we're not seeking to the start.
mSkip = aStart ? mParser->mPreSkip : 0;
@@ -917,20 +977,22 @@ nsresult OpusState::Reset(bool aStart)
return NS_ERROR_FAILURE;
}
LOG(LogLevel::Debug, ("Opus decoder reset, to skip %d", mSkip));
return res;
}
-bool OpusState::Init(void)
+bool
+OpusState::Init(void)
{
- if (!mActive)
+ if (!mActive) {
return false;
+ }
int error;
NS_ASSERTION(mDecoder == nullptr, "leaking OpusDecoder");
mDecoder = opus_multistream_decoder_create(mParser->mRate,
mParser->mChannels,
mParser->mStreams,
@@ -940,144 +1002,155 @@ bool OpusState::Init(void)
mSkip = mParser->mPreSkip;
LOG(LogLevel::Debug, ("Opus decoder init, to skip %d", mSkip));
return error == OPUS_OK;
}
-bool OpusState::DecodeHeader(ogg_packet* aPacket)
+bool
+OpusState::DecodeHeader(ogg_packet* aPacket)
{
nsAutoRef<ogg_packet> autoRelease(aPacket);
switch(mPacketCount++) {
// Parse the id header.
- case 0: {
- mParser = new OpusParser;
- if(!mParser->DecodeHeader(aPacket->packet, aPacket->bytes)) {
- return false;
- }
- mRate = mParser->mRate;
- mChannels = mParser->mChannels;
- mPreSkip = mParser->mPreSkip;
+ case 0:
+ mParser = new OpusParser;
+ if (!mParser->DecodeHeader(aPacket->packet, aPacket->bytes)) {
+ return false;
+ }
+ mRate = mParser->mRate;
+ mChannels = mParser->mChannels;
+ mPreSkip = mParser->mPreSkip;
#ifdef MOZ_SAMPLE_TYPE_FLOAT32
- mGain = mParser->mGain;
+ mGain = mParser->mGain;
#else
- mGain_Q16 = mParser->mGain_Q16;
+ mGain_Q16 = mParser->mGain_Q16;
#endif
- }
- break;
+ break;
// Parse the metadata header.
- case 1: {
- if(!mParser->DecodeTags(aPacket->packet, aPacket->bytes)) {
- return false;
- }
- }
- break;
+ case 1:
+ if (!mParser->DecodeTags(aPacket->packet, aPacket->bytes)) {
+ return false;
+ }
+ break;
// We made it to the first data packet (which includes reconstructing
// timestamps for it in PageIn). Success!
- default: {
+ default:
mDoneReadingHeaders = true;
// Put it back on the queue so we can decode it.
mPackets.PushFront(autoRelease.disown());
- }
- break;
+ break;
}
return true;
}
/* Construct and return a tags hashmap from our internal array */
-MetadataTags* OpusState::GetTags()
+MetadataTags*
+OpusState::GetTags()
{
MetadataTags* tags;
tags = new MetadataTags;
for (uint32_t i = 0; i < mParser->mTags.Length(); i++) {
AddVorbisComment(tags, mParser->mTags[i].Data(), mParser->mTags[i].Length());
}
return tags;
}
/* Return the timestamp (in microseconds) equivalent to a granulepos. */
-int64_t OpusState::Time(int64_t aGranulepos)
+int64_t
+OpusState::Time(int64_t aGranulepos)
{
- if (!mActive)
+ if (!mActive) {
return -1;
+ }
return Time(mParser->mPreSkip, aGranulepos);
}
-int64_t OpusState::Time(int aPreSkip, int64_t aGranulepos)
+int64_t
+OpusState::Time(int aPreSkip, int64_t aGranulepos)
{
- if (aGranulepos < 0)
+ if (aGranulepos < 0) {
return -1;
+ }
// Ogg Opus always runs at a granule rate of 48 kHz.
CheckedInt64 t = (CheckedInt64(aGranulepos) - aPreSkip) * USECS_PER_S;
return t.isValid() ? t.value() / 48000 : -1;
}
-bool OpusState::IsHeader(ogg_packet* aPacket)
+bool
+OpusState::IsHeader(ogg_packet* aPacket)
{
return aPacket->bytes >= 16 &&
(!memcmp(aPacket->packet, "OpusHead", 8) ||
!memcmp(aPacket->packet, "OpusTags", 8));
}
-nsresult OpusState::PageIn(ogg_page* aPage)
+nsresult
+OpusState::PageIn(ogg_page* aPage)
{
- if (!mActive)
+ if (!mActive) {
return NS_OK;
+ }
NS_ASSERTION(static_cast<uint32_t>(ogg_page_serialno(aPage)) == mSerial,
"Page must be for this stream!");
if (ogg_stream_pagein(&mState, aPage) == -1)
return NS_ERROR_FAILURE;
bool haveGranulepos;
nsresult rv = PacketOutUntilGranulepos(haveGranulepos);
- if (NS_FAILED(rv) || !haveGranulepos || mPacketCount < 2)
+ if (NS_FAILED(rv) || !haveGranulepos || mPacketCount < 2) {
return rv;
- if(!ReconstructOpusGranulepos())
+ }
+ if (!ReconstructOpusGranulepos()) {
return NS_ERROR_FAILURE;
+ }
for (uint32_t i = 0; i < mUnstamped.Length(); i++) {
ogg_packet* packet = mUnstamped[i];
NS_ASSERTION(!IsHeader(packet), "Don't try to play a header packet");
NS_ASSERTION(packet->granulepos != -1, "Packet should have a granulepos");
mPackets.Append(packet);
}
mUnstamped.Clear();
return NS_OK;
}
// Helper method to return the change in granule position due to an Opus packet
// (as distinct from the number of samples in the packet, which depends on the
// decoder rate). It should work with a multistream Opus file, and continue to
// work should we ever allow the decoder to decode at a rate other than 48 kHz.
// It even works before we've created the actual Opus decoder.
-static int GetOpusDeltaGP(ogg_packet* packet)
+static int
+GetOpusDeltaGP(ogg_packet* packet)
{
int nframes;
nframes = opus_packet_get_nb_frames(packet->packet, packet->bytes);
if (nframes > 0) {
return nframes*opus_packet_get_samples_per_frame(packet->packet, 48000);
}
NS_WARNING("Invalid Opus packet.");
return nframes;
}
-int64_t OpusState::PacketDuration(ogg_packet* aPacket)
+int64_t
+OpusState::PacketDuration(ogg_packet* aPacket)
{
CheckedInt64 t = CheckedInt64(GetOpusDeltaGP(aPacket)) * USECS_PER_S;
return t.isValid() ? t.value() / 48000 : -1;
}
-bool OpusState::ReconstructOpusGranulepos(void)
+bool
+OpusState::ReconstructOpusGranulepos(void)
{
NS_ASSERTION(mUnstamped.Length() > 0, "Must have unstamped packets");
ogg_packet* last = mUnstamped[mUnstamped.Length()-1];
NS_ASSERTION(last->e_o_s || last->granulepos > 0,
"Must know last granulepos!");
int64_t gp;
// If this is the last page, and we've seen at least one previous page (or
// this is the first page)...
@@ -1149,27 +1222,28 @@ bool OpusState::ReconstructOpusGranulepo
}
mUnstamped[i - 1]->granulepos = gp;
}
// Check to make sure the first granule position is at least as large as the
// total number of samples decodable from the first page with completed
// packets. This requires looking at the duration of the first packet, too.
// We MUST reject such streams.
- if (!mDoneReadingHeaders && GetOpusDeltaGP(mUnstamped[0]) > gp)
+ if (!mDoneReadingHeaders && GetOpusDeltaGP(mUnstamped[0]) > gp) {
return false;
+ }
mPrevPageGranulepos = last->granulepos;
return true;
}
-SkeletonState::SkeletonState(ogg_page* aBosPage) :
- OggCodecState(aBosPage, true),
- mVersion(0),
- mPresentationTime(0),
- mLength(0)
+SkeletonState::SkeletonState(ogg_page* aBosPage)
+ : OggCodecState(aBosPage, true)
+ , mVersion(0)
+ , mPresentationTime(0)
+ , mLength(0)
{
MOZ_COUNT_CTOR(SkeletonState);
}
SkeletonState::~SkeletonState()
{
MOZ_COUNT_DTOR(SkeletonState);
}
@@ -1209,62 +1283,67 @@ static const size_t INDEX_TIME_DENOM_OFF
static const size_t INDEX_FIRST_NUMER_OFFSET = 26;
static const size_t INDEX_LAST_NUMER_OFFSET = 34;
static const size_t INDEX_KEYPOINT_OFFSET = 42;
// Byte-offsets of the fields in the Skeleton Fisbone packet.
static const size_t FISBONE_MSG_FIELDS_OFFSET = 8;
static const size_t FISBONE_SERIALNO_OFFSET = 12;
-static bool IsSkeletonBOS(ogg_packet* aPacket)
+static bool
+IsSkeletonBOS(ogg_packet* aPacket)
{
static_assert(SKELETON_MIN_HEADER_LEN >= 8,
"Minimum length of skeleton BOS header incorrect");
return aPacket->bytes >= SKELETON_MIN_HEADER_LEN &&
memcmp(reinterpret_cast<char*>(aPacket->packet), "fishead", 8) == 0;
}
-static bool IsSkeletonIndex(ogg_packet* aPacket)
+static bool
+IsSkeletonIndex(ogg_packet* aPacket)
{
static_assert(SKELETON_4_0_MIN_INDEX_LEN >= 5,
"Minimum length of skeleton index header incorrect");
return aPacket->bytes >= SKELETON_4_0_MIN_INDEX_LEN &&
memcmp(reinterpret_cast<char*>(aPacket->packet), "index", 5) == 0;
}
-static bool IsSkeletonFisbone(ogg_packet* aPacket)
+static bool
+IsSkeletonFisbone(ogg_packet* aPacket)
{
static_assert(SKELETON_MIN_FISBONE_LEN >= 8,
"Minimum length of skeleton fisbone header incorrect");
return aPacket->bytes >= SKELETON_MIN_FISBONE_LEN &&
memcmp(reinterpret_cast<char*>(aPacket->packet), "fisbone", 8) == 0;
}
// Reads a variable length encoded integer at p. Will not read
// past aLimit. Returns pointer to character after end of integer.
-static const unsigned char* ReadVariableLengthInt(const unsigned char* p,
- const unsigned char* aLimit,
- int64_t& n)
+static const unsigned char*
+ReadVariableLengthInt(const unsigned char* p,
+ const unsigned char* aLimit,
+ int64_t& n)
{
int shift = 0;
int64_t byte = 0;
n = 0;
while (p < aLimit &&
(byte & 0x80) != 0x80 &&
shift < 57)
{
byte = static_cast<int64_t>(*p);
n |= ((byte & 0x7f) << shift);
shift += 7;
p++;
}
return p;
}
-bool SkeletonState::DecodeIndex(ogg_packet* aPacket)
+bool
+SkeletonState::DecodeIndex(ogg_packet* aPacket)
{
NS_ASSERTION(aPacket->bytes >= SKELETON_4_0_MIN_INDEX_LEN,
"Index must be at least minimum size");
if (!mActive) {
return false;
}
uint32_t serialno = LittleEndian::readUint32(aPacket->packet + INDEX_SERIALNO_OFFSET);
@@ -1295,28 +1374,28 @@ bool SkeletonState::DecodeIndex(ogg_pack
if (!t.isValid()) {
return (mActive = false);
} else {
endTime = t.value() / timeDenom;
}
// Check the numKeyPoints value read, ensure we're not going to run out of
// memory while trying to decode the index packet.
- CheckedInt64 minPacketSize = (CheckedInt64(numKeyPoints) * MIN_KEY_POINT_SIZE) + INDEX_KEYPOINT_OFFSET;
+ CheckedInt64 minPacketSize =
+ (CheckedInt64(numKeyPoints) * MIN_KEY_POINT_SIZE) + INDEX_KEYPOINT_OFFSET;
if (!minPacketSize.isValid())
{
return (mActive = false);
}
int64_t sizeofIndex = aPacket->bytes - INDEX_KEYPOINT_OFFSET;
int64_t maxNumKeyPoints = sizeofIndex / MIN_KEY_POINT_SIZE;
if (aPacket->bytes < minPacketSize.value() ||
numKeyPoints > maxNumKeyPoints ||
- numKeyPoints < 0)
- {
+ numKeyPoints < 0) {
// Packet size is less than the theoretical minimum size, or the packet is
// claiming to store more keypoints than it's capable of storing. This means
// that the numKeyPoints field is too large or small for the packet to
// possibly contain as many packets as it claims to, so the numKeyPoints
// field is possibly malicious. Don't try decoding this index, we may run
// out of memory.
LOG(LogLevel::Debug, ("Possibly malicious number of key points reported "
"(%lld) in index packet for stream %u.",
@@ -1327,67 +1406,62 @@ bool SkeletonState::DecodeIndex(ogg_pack
nsAutoPtr<nsKeyFrameIndex> keyPoints(new nsKeyFrameIndex(startTime, endTime));
p = aPacket->packet + INDEX_KEYPOINT_OFFSET;
const unsigned char* limit = aPacket->packet + aPacket->bytes;
int64_t numKeyPointsRead = 0;
CheckedInt64 offset = 0;
CheckedInt64 time = 0;
- while (p < limit &&
- numKeyPointsRead < numKeyPoints)
- {
+ while (p < limit && numKeyPointsRead < numKeyPoints) {
int64_t delta = 0;
p = ReadVariableLengthInt(p, limit, delta);
offset += delta;
if (p == limit ||
!offset.isValid() ||
offset.value() > mLength ||
- offset.value() < 0)
- {
+ offset.value() < 0) {
return (mActive = false);
}
p = ReadVariableLengthInt(p, limit, delta);
time += delta;
if (!time.isValid() ||
time.value() > endTime ||
- time.value() < startTime)
- {
+ time.value() < startTime) {
return (mActive = false);
}
CheckedInt64 timeUsecs = time * USECS_PER_S;
- if (!timeUsecs.isValid())
+ if (!timeUsecs.isValid()) {
return mActive = false;
+ }
timeUsecs /= timeDenom;
keyPoints->Add(offset.value(), timeUsecs.value());
numKeyPointsRead++;
}
int32_t keyPointsRead = keyPoints->Length();
if (keyPointsRead > 0) {
mIndex.Put(serialno, keyPoints.forget());
}
LOG(LogLevel::Debug, ("Loaded %d keypoints for Skeleton on stream %u",
keyPointsRead, serialno));
return true;
}
-nsresult SkeletonState::IndexedSeekTargetForTrack(uint32_t aSerialno,
- int64_t aTarget,
- nsKeyPoint& aResult)
+nsresult
+SkeletonState::IndexedSeekTargetForTrack(uint32_t aSerialno,
+ int64_t aTarget,
+ nsKeyPoint& aResult)
{
nsKeyFrameIndex* index = nullptr;
mIndex.Get(aSerialno, &index);
- if (!index ||
- index->Length() == 0 ||
- aTarget < index->mStartTime ||
- aTarget > index->mEndTime)
- {
+ if (!index || index->Length() == 0 ||
+ aTarget < index->mStartTime || aTarget > index->mEndTime) {
return NS_ERROR_FAILURE;
}
// Binary search to find the last key point with time less than target.
int start = 0;
int end = index->Length() - 1;
while (end > start) {
int mid = start + ((end - start + 1) >> 1);
@@ -1401,54 +1475,54 @@ nsresult SkeletonState::IndexedSeekTarge
}
}
aResult = index->Get(start);
NS_ASSERTION(aResult.mTime <= aTarget, "Result should have time <= target");
return NS_OK;
}
-nsresult SkeletonState::IndexedSeekTarget(int64_t aTarget,
- nsTArray<uint32_t>& aTracks,
- nsSeekTarget& aResult)
+nsresult
+SkeletonState::IndexedSeekTarget(int64_t aTarget,
+ nsTArray<uint32_t>& aTracks,
+ nsSeekTarget& aResult)
{
if (!mActive || mVersion < SKELETON_VERSION(4,0)) {
return NS_ERROR_FAILURE;
}
// Loop over all requested tracks' indexes, and get the keypoint for that
// seek target. Record the keypoint with the lowest offset, this will be
// our seek result. User must seek to the one with lowest offset to ensure we
// pass "keyframes" on all tracks when we decode forwards to the seek target.
nsSeekTarget r;
for (uint32_t i=0; i<aTracks.Length(); i++) {
nsKeyPoint k;
if (NS_SUCCEEDED(IndexedSeekTargetForTrack(aTracks[i], aTarget, k)) &&
- k.mOffset < r.mKeyPoint.mOffset)
- {
+ k.mOffset < r.mKeyPoint.mOffset) {
r.mKeyPoint = k;
r.mSerial = aTracks[i];
}
}
if (r.IsNull()) {
return NS_ERROR_FAILURE;
}
LOG(LogLevel::Debug, ("Indexed seek target for time %lld is offset %lld",
aTarget, r.mKeyPoint.mOffset));
aResult = r;
return NS_OK;
}
-nsresult SkeletonState::GetDuration(const nsTArray<uint32_t>& aTracks,
- int64_t& aDuration)
+nsresult
+SkeletonState::GetDuration(const nsTArray<uint32_t>& aTracks,
+ int64_t& aDuration)
{
if (!mActive ||
mVersion < SKELETON_VERSION(4,0) ||
!HasIndex() ||
- aTracks.Length() == 0)
- {
+ aTracks.Length() == 0) {
return NS_ERROR_FAILURE;
}
int64_t endTime = INT64_MIN;
int64_t startTime = INT64_MAX;
for (uint32_t i=0; i<aTracks.Length(); i++) {
nsKeyFrameIndex* index = nullptr;
mIndex.Get(aTracks[i], &index);
if (!index) {
@@ -1463,29 +1537,33 @@ nsresult SkeletonState::GetDuration(cons
}
}
NS_ASSERTION(endTime > startTime, "Duration must be positive");
CheckedInt64 duration = CheckedInt64(endTime) - startTime;
aDuration = duration.isValid() ? duration.value() : 0;
return duration.isValid() ? NS_OK : NS_ERROR_FAILURE;
}
-bool SkeletonState::DecodeFisbone(ogg_packet* aPacket)
+bool
+SkeletonState::DecodeFisbone(ogg_packet* aPacket)
{
if (aPacket->bytes < static_cast<long>(FISBONE_MSG_FIELDS_OFFSET + 4)) {
return false;
}
- uint32_t offsetMsgField = LittleEndian::readUint32(aPacket->packet + FISBONE_MSG_FIELDS_OFFSET);
+ uint32_t offsetMsgField =
+ LittleEndian::readUint32(aPacket->packet + FISBONE_MSG_FIELDS_OFFSET);
if (aPacket->bytes < static_cast<long>(FISBONE_SERIALNO_OFFSET + 4)) {
return false;
}
- uint32_t serialno = LittleEndian::readUint32(aPacket->packet + FISBONE_SERIALNO_OFFSET);
+ uint32_t serialno =
+ LittleEndian::readUint32(aPacket->packet + FISBONE_SERIALNO_OFFSET);
- CheckedUint32 checked_fields_pos = CheckedUint32(FISBONE_MSG_FIELDS_OFFSET) + offsetMsgField;
+ CheckedUint32 checked_fields_pos =
+ CheckedUint32(FISBONE_MSG_FIELDS_OFFSET) + offsetMsgField;
if (!checked_fields_pos.isValid() ||
aPacket->bytes < static_cast<int64_t>(checked_fields_pos.value())) {
return false;
}
int64_t msgLength = aPacket->bytes - checked_fields_pos.value();
char* msgProbe = (char*)aPacket->packet + checked_fields_pos.value();
char* msgHead = msgProbe;
nsAutoPtr<MessageField> field(new MessageField());
@@ -1542,38 +1620,46 @@ bool SkeletonState::DecodeFisbone(ogg_pa
mMsgFieldStore.Put(serialno, field.forget());
} else {
return false;
}
return true;
}
-bool SkeletonState::DecodeHeader(ogg_packet* aPacket)
+bool
+SkeletonState::DecodeHeader(ogg_packet* aPacket)
{
nsAutoRef<ogg_packet> autoRelease(aPacket);
if (IsSkeletonBOS(aPacket)) {
- uint16_t verMajor = LittleEndian::readUint16(aPacket->packet + SKELETON_VERSION_MAJOR_OFFSET);
- uint16_t verMinor = LittleEndian::readUint16(aPacket->packet + SKELETON_VERSION_MINOR_OFFSET);
+ uint16_t verMajor =
+ LittleEndian::readUint16(aPacket->packet + SKELETON_VERSION_MAJOR_OFFSET);
+ uint16_t verMinor =
+ LittleEndian::readUint16(aPacket->packet + SKELETON_VERSION_MINOR_OFFSET);
// Read the presentation time. We read this before the version check as the
// presentation time exists in all versions.
- int64_t n = LittleEndian::readInt64(aPacket->packet + SKELETON_PRESENTATION_TIME_NUMERATOR_OFFSET);
- int64_t d = LittleEndian::readInt64(aPacket->packet + SKELETON_PRESENTATION_TIME_DENOMINATOR_OFFSET);
- mPresentationTime = d == 0 ? 0 : (static_cast<float>(n) / static_cast<float>(d)) * USECS_PER_S;
+ int64_t n =
+ LittleEndian::readInt64(aPacket->packet + SKELETON_PRESENTATION_TIME_NUMERATOR_OFFSET);
+ int64_t d =
+ LittleEndian::readInt64(aPacket->packet + SKELETON_PRESENTATION_TIME_DENOMINATOR_OFFSET);
+ mPresentationTime =
+ d == 0 ? 0 : (static_cast<float>(n) / static_cast<float>(d)) * USECS_PER_S;
mVersion = SKELETON_VERSION(verMajor, verMinor);
// We can only care to parse Skeleton version 4.0+.
if (mVersion < SKELETON_VERSION(4,0) ||
mVersion >= SKELETON_VERSION(5,0) ||
- aPacket->bytes < SKELETON_4_0_MIN_HEADER_LEN)
+ aPacket->bytes < SKELETON_4_0_MIN_HEADER_LEN) {
return false;
+ }
// Extract the segment length.
- mLength = LittleEndian::readInt64(aPacket->packet + SKELETON_FILE_LENGTH_OFFSET);
+ mLength =
+ LittleEndian::readInt64(aPacket->packet + SKELETON_FILE_LENGTH_OFFSET);
LOG(LogLevel::Debug, ("Skeleton segment length: %lld", mLength));
// Initialize the serialno-to-index map.
return true;
} else if (IsSkeletonIndex(aPacket) && mVersion >= SKELETON_VERSION(4,0)) {
return DecodeIndex(aPacket);
} else if (IsSkeletonFisbone(aPacket)) {
--- a/dom/media/ogg/OggCodecState.h
+++ b/dom/media/ogg/OggCodecState.h
@@ -35,18 +35,20 @@
#include <map>
#endif
#include "OpusParser.h"
namespace mozilla {
// Deallocates a packet, used in OggPacketQueue below.
-class OggPacketDeallocator : public nsDequeFunctor {
- virtual void* operator() (void* aPacket) {
+class OggPacketDeallocator : public nsDequeFunctor
+{
+ virtual void* operator() (void* aPacket)
+ {
ogg_packet* p = static_cast<ogg_packet*>(aPacket);
delete [] p->packet;
delete p;
return nullptr;
}
};
// A queue of ogg_packets. When we read a page, we extract the page's packets
@@ -54,36 +56,39 @@ class OggPacketDeallocator : public nsDe
// if we're skipping up to the next keyframe in very large frame sized videos,
// there may be several megabytes of data between keyframes, and the
// ogg_stream_state would end up resizing its buffer every time we added a
// new 4KB page to the bitstream, which kills performance on Windows. This
// also gives us the option to timestamp packets rather than decoded
// frames/samples, reducing the amount of frames/samples we must decode to
// determine start-time at a particular offset, and gives us finer control
// over memory usage.
-class OggPacketQueue : private nsDeque {
+class OggPacketQueue : private nsDeque
+{
public:
OggPacketQueue() : nsDeque(new OggPacketDeallocator()) {}
~OggPacketQueue() { Erase(); }
bool IsEmpty() { return nsDeque::GetSize() == 0; }
void Append(ogg_packet* aPacket);
ogg_packet* PopFront() { return static_cast<ogg_packet*>(nsDeque::PopFront()); }
ogg_packet* PeekFront() { return static_cast<ogg_packet*>(nsDeque::PeekFront()); }
ogg_packet* Pop() { return static_cast<ogg_packet*>(nsDeque::Pop()); }
void PushFront(ogg_packet* aPacket) { nsDeque::PushFront(aPacket); }
void Erase() { nsDeque::Erase(); }
};
// Encapsulates the data required for decoding an ogg bitstream and for
// converting granulepos to timestamps.
-class OggCodecState {
+class OggCodecState
+{
public:
typedef mozilla::MetadataTags MetadataTags;
// Ogg types we know about
- enum CodecType {
+ enum CodecType
+ {
TYPE_VORBIS=0,
TYPE_THEORA=1,
TYPE_OPUS=2,
TYPE_SKELETON=3,
TYPE_UNKNOWN=4
};
virtual ~OggCodecState();
@@ -94,36 +99,39 @@ public:
virtual CodecType GetType() { return TYPE_UNKNOWN; }
// Reads a header packet. Returns false if an error was encountered
// while reading header packets. Callers should check DoneReadingHeaders()
// to determine if the last header has been read.
// This function takes ownership of the packet and is responsible for
// releasing it or queuing it for later processing.
- virtual bool DecodeHeader(ogg_packet* aPacket) {
+ virtual bool DecodeHeader(ogg_packet* aPacket)
+ {
return (mDoneReadingHeaders = true);
}
// Build a hash table with tag metadata parsed from the stream.
- virtual MetadataTags* GetTags() {
+ virtual MetadataTags* GetTags()
+ {
return nullptr;
}
// Returns the end time that a granulepos represents.
virtual int64_t Time(int64_t granulepos) { return -1; }
// Returns the start time that a granulepos represents.
virtual int64_t StartTime(int64_t granulepos) { return -1; }
// Returns the duration of the given packet, if it can be determined.
virtual int64_t PacketDuration(ogg_packet* aPacket) { return -1; }
// Returns the start time of the given packet, if it can be determined.
- virtual int64_t PacketStartTime(ogg_packet* aPacket) {
+ virtual int64_t PacketStartTime(ogg_packet* aPacket)
+ {
if (aPacket->granulepos < 0) {
return -1;
}
int64_t endTime = Time(aPacket->granulepos);
int64_t duration = PacketDuration(aPacket);
if (duration > endTime) {
// Audio preskip may eat a whole packet or more.
return 0;
@@ -136,17 +144,18 @@ public:
virtual bool Init();
// Returns true when this bitstream has finished reading all its
// header packets.
bool DoneReadingHeaders() { return mDoneReadingHeaders; }
// Deactivates the bitstream. Only the primary video and audio bitstreams
// should be active.
- void Deactivate() {
+ void Deactivate()
+ {
mActive = false;
mDoneReadingHeaders = true;
Reset();
}
// Resets decoding state.
virtual nsresult Reset();
@@ -245,17 +254,18 @@ protected:
// Utility method to parse and add a vorbis-style comment
// to a metadata hash table. Most Ogg-encapsulated codecs
// use the vorbis comment format for metadata.
static bool AddVorbisComment(MetadataTags* aTags,
const char* aComment,
uint32_t aLength);
};
-class VorbisState : public OggCodecState {
+class VorbisState : public OggCodecState
+{
public:
explicit VorbisState(ogg_page* aBosPage);
virtual ~VorbisState();
CodecType GetType() override { return TYPE_VORBIS; }
bool DecodeHeader(ogg_packet* aPacket) override;
int64_t Time(int64_t granulepos) override;
int64_t PacketDuration(ogg_packet* aPacket) override;
@@ -319,17 +329,18 @@ public:
// Returns 1 if the Theora info struct is decoding a media of Theora
// version (maj,min,sub) or later, otherwise returns 0.
int TheoraVersion(th_info* info,
unsigned char maj,
unsigned char min,
unsigned char sub);
-class TheoraState : public OggCodecState {
+class TheoraState : public OggCodecState
+{
public:
explicit TheoraState(ogg_page* aBosPage);
virtual ~TheoraState();
CodecType GetType() override { return TYPE_THEORA; }
bool DecodeHeader(ogg_packet* aPacket) override;
int64_t Time(int64_t granulepos) override;
int64_t StartTime(int64_t granulepos) override;
@@ -359,17 +370,18 @@ private:
// mUnstamped array. mUnstamped must be filled with consecutive packets from
// the stream, with the last packet having a known granulepos. Using this
// known granulepos, and the known frame numbers, we recover the granulepos
// of all frames in the array. This enables us to determine their timestamps.
void ReconstructTheoraGranulepos();
};
-class OpusState : public OggCodecState {
+class OpusState : public OggCodecState
+{
public:
explicit OpusState(ogg_page* aBosPage);
virtual ~OpusState();
CodecType GetType() override { return TYPE_OPUS; }
bool DecodeHeader(ogg_packet* aPacket) override;
int64_t Time(int64_t aGranulepos) override;
int64_t PacketDuration(ogg_packet* aPacket) override;
@@ -430,27 +442,30 @@ enum EMsgHeaderType {
eLanguage,
eTitle,
eDisplayHint,
eAltitude,
eTrackOrder,
eTrackDependencies
};
-typedef struct {
+typedef struct
+{
const char* mPatternToRecognize;
EMsgHeaderType mMsgHeaderType;
} FieldPatternType;
// Stores the message information for different logical bitstream.
-typedef struct {
+typedef struct
+{
nsClassHashtable<nsUint32HashKey, nsCString> mValuesStore;
} MessageField;
-class SkeletonState : public OggCodecState {
+class SkeletonState : public OggCodecState
+{
public:
explicit SkeletonState(ogg_page* aBosPage);
~SkeletonState();
nsClassHashtable<nsUint32HashKey, MessageField> mMsgFieldStore;
CodecType GetType() override { return TYPE_SKELETON; }
bool DecodeHeader(ogg_packet* aPacket) override;
@@ -459,59 +474,62 @@ public:
bool IsHeader(ogg_packet* aPacket) override { return true; }
// Return true if the given time (in milliseconds) is within
// the presentation time defined in the skeleton track.
bool IsPresentable(int64_t aTime) { return aTime >= mPresentationTime; }
// Stores the offset of the page on which a keyframe starts,
// and its presentation time.
- class nsKeyPoint {
+ class nsKeyPoint
+ {
public:
nsKeyPoint()
- : mOffset(INT64_MAX),
- mTime(INT64_MAX) {}
+ : mOffset(INT64_MAX)
+ , mTime(INT64_MAX) {}
nsKeyPoint(int64_t aOffset, int64_t aTime)
- : mOffset(aOffset),
- mTime(aTime) {}
+ : mOffset(aOffset)
+ ,mTime(aTime) {}
// Offset from start of segment/link-in-the-chain in bytes.
int64_t mOffset;
// Presentation time in usecs.
int64_t mTime;
- bool IsNull() {
- return mOffset == INT64_MAX &&
- mTime == INT64_MAX;
+ bool IsNull()
+ {
+ return mOffset == INT64_MAX && mTime == INT64_MAX;
}
};
// Stores a keyframe's byte-offset, presentation time and the serialno
// of the stream it belongs to.
- class nsSeekTarget {
+ class nsSeekTarget
+ {
public:
nsSeekTarget() : mSerial(0) {}
nsKeyPoint mKeyPoint;
uint32_t mSerial;
- bool IsNull() {
- return mKeyPoint.IsNull() &&
- mSerial == 0;
+ bool IsNull()
+ {
+ return mKeyPoint.IsNull() && mSerial == 0;
}
};
// Determines from the seek index the keyframe which you must seek back to
// in order to get all keyframes required to render all streams with
// serialnos in aTracks, at time aTarget.
nsresult IndexedSeekTarget(int64_t aTarget,
nsTArray<uint32_t>& aTracks,
nsSeekTarget& aResult);
- bool HasIndex() const {
+ bool HasIndex() const
+ {
return mIndex.Count() > 0;
}
// Returns the duration of the active tracks in the media, if we have
// an index. aTracks must be filled with the serialnos of the active tracks.
// The duration is calculated as the greatest end time of all active tracks,
// minus the smalled start time of all the active tracks.
nsresult GetDuration(const nsTArray<uint32_t>& aTracks, int64_t& aDuration);
@@ -535,39 +553,44 @@ private:
// Presentation time of the resource in milliseconds
int64_t mPresentationTime;
// Length of the resource in bytes.
int64_t mLength;
// Stores the keyframe index and duration information for a particular
// stream.
- class nsKeyFrameIndex {
+ class nsKeyFrameIndex
+ {
public:
nsKeyFrameIndex(int64_t aStartTime, int64_t aEndTime)
- : mStartTime(aStartTime),
- mEndTime(aEndTime)
+ : mStartTime(aStartTime)
+ , mEndTime(aEndTime)
{
MOZ_COUNT_CTOR(nsKeyFrameIndex);
}
- ~nsKeyFrameIndex() {
+ ~nsKeyFrameIndex()
+ {
MOZ_COUNT_DTOR(nsKeyFrameIndex);
}
- void Add(int64_t aOffset, int64_t aTimeMs) {
+ void Add(int64_t aOffset, int64_t aTimeMs)
+ {
mKeyPoints.AppendElement(nsKeyPoint(aOffset, aTimeMs));
}
- const nsKeyPoint& Get(uint32_t aIndex) const {
+ const nsKeyPoint& Get(uint32_t aIndex) const
+ {
return mKeyPoints[aIndex];
}
- uint32_t Length() const {
+ uint32_t Length() const
+ {
return mKeyPoints.Length();
}
// Presentation time of the first sample in this stream in usecs.
const int64_t mStartTime;
// End time of the last sample in this stream in usecs.
const int64_t mEndTime;
@@ -583,15 +606,16 @@ private:
} // namespace mozilla
// This allows the use of nsAutoRefs for an ogg_packet that properly free the
// contents of the packet.
template <>
class nsAutoRefTraits<ogg_packet> : public nsPointerRefTraits<ogg_packet>
{
public:
- static void Release(ogg_packet* aPacket) {
+ static void Release(ogg_packet* aPacket)
+ {
mozilla::OggCodecState::ReleasePacket(aPacket);
}
};
#endif