Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: rillian/firefox
...
head fork: rillian/firefox
  • 3 commits
  • 6 files changed
  • 0 commit comments
  • 1 contributor
Commits on Apr 03, 2012
Ralph Giles Fix a reordering warning.
GCC 4.6 warns about mOpusEnabled being initialized
after mOpusState, which makes reference to it.
Declaring them in the other order prevents the
possible race.
2c12df7
Ralph Giles Bug 674225 - Cleanup from review comments.
Fix formatting, add comments, remove debug output,
plus some code cleanup. Thanks to Chris Pearce
for the review.
65bb143
Ralph Giles Bug 674225 - Declare IsOpusEnabled unconditionally.
Make nsHTMLMediaElement::IsOpusEnabled conditional
just on MOZ_OGG, not MOZ_OPUS, so that it's always
available to nsOggReader, whose constructor calls
it to support the media.opus.enabled pref.

Instead, we just return false inside the method
body if MOZ_OPUS isn't defined.

Thanks to Chris Pearce for the suggestion.
e7c1b98
2  content/html/content/public/nsHTMLMediaElement.h
View
@@ -282,11 +282,9 @@ class nsHTMLMediaElement : public nsGenericHTMLElement,
static bool IsOggType(const nsACString& aType);
static const char gOggTypes[3][16];
static char const *const gOggCodecs[3];
-#ifdef MOZ_OPUS
static bool IsOpusEnabled();
static char const *const gOggCodecsWithOpus[4];
#endif
-#endif
#ifdef MOZ_WAVE
static bool IsWaveEnabled();
6 content/html/content/src/nsHTMLMediaElement.cpp
View
@@ -1745,7 +1745,6 @@ char const *const nsHTMLMediaElement::gOggCodecs[3] = {
nsnull
};
-#ifdef MOZ_OPUS
char const *const nsHTMLMediaElement::gOggCodecsWithOpus[4] = {
"vorbis",
"opus",
@@ -1756,9 +1755,12 @@ char const *const nsHTMLMediaElement::gOggCodecsWithOpus[4] = {
bool
nsHTMLMediaElement::IsOpusEnabled()
{
+#ifdef MOZ_OPUS
return Preferences::GetBool("media.opus.enabled");
-}
+#else
+ return false;
#endif
+}
bool
nsHTMLMediaElement::IsOggEnabled()
58 content/media/ogg/nsOggCodecState.cpp
View
@@ -781,23 +781,26 @@ nsresult nsVorbisState::ReconstructVorbisGranulepos()
nsOpusState::nsOpusState(ogg_page* aBosPage) :
- nsOggCodecState(aBosPage, true),
- mRate(0),
- mNominalRate(0),
- mChannels(0),
- mDecoder(NULL)
+ nsOggCodecState(aBosPage, true),
+ mRate(0),
+ mNominalRate(0),
+ mChannels(0),
+ mPreSkip(0),
+ mGain(0.0),
+ mChannelMapping(0),
+ mDecoder(NULL)
{
- MOZ_COUNT_CTOR(nsOpusState);
+ MOZ_COUNT_CTOR(nsOpusState);
}
nsOpusState::~nsOpusState() {
- MOZ_COUNT_DTOR(nsOpusState);
- Reset();
+ MOZ_COUNT_DTOR(nsOpusState);
+ Reset();
- if (mDecoder) {
- opus_decoder_destroy(mDecoder);
- mDecoder = NULL;
- }
+ if (mDecoder) {
+ opus_decoder_destroy(mDecoder);
+ mDecoder = NULL;
+ }
}
nsresult nsOpusState::Reset()
@@ -842,15 +845,13 @@ bool nsOpusState::DecodeHeader(ogg_packet* aPacket)
// try parsing as the metadata header
if (!memcmp(aPacket->packet, "OpusTags", 8)) {
- mDoneReadingHeaders = true; // last opus header
- mActive = true;
- return true;
+ mDoneReadingHeaders = true; // last opus header
+ mActive = true;
+ return true;
}
// otherwise, parse as the id header
- if (memcmp(aPacket->packet, "OpusHead\0", 9))
- return NS_ERROR_FAILURE;
- if (aPacket->bytes < 19)
+ if (aPacket->bytes < 19 || memcmp(aPacket->packet, "OpusHead\0", 9))
return NS_ERROR_FAILURE;
mRate = 48000; // decoder runs at 48 kHz regardless
@@ -877,8 +878,6 @@ PRInt64 nsOpusState::Time(PRInt64 granulepos)
return -1;
/* Ogg Opus always runs at a granule rate of 48 kHz */
- //CheckedInt64 t = CheckedInt64(granulepos - mPreSkip) * USECS_PER_S;
- // HACK: don't subtract preskip to avoid generating negative timestamps.
CheckedInt64 t = CheckedInt64(granulepos) * USECS_PER_S;
if (!t.valid())
return -1;
@@ -901,7 +900,7 @@ nsresult nsOpusState::PageIn(ogg_page* aPage)
if (!mActive)
return NS_OK;
NS_ASSERTION(static_cast<PRUint32>(ogg_page_serialno(aPage)) == mSerial,
- "Page is not for this stream");
+ "Page must be for this stream!");
if (ogg_stream_pagein(&mState, aPage) == -1)
return NS_ERROR_FAILURE;
@@ -928,8 +927,6 @@ void nsOpusState::ReconstructGranulepos(void)
ogg_packet* last = mUnstamped[mUnstamped.Length()-1];
NS_ASSERTION(last->e_o_s || last->granulepos > 0,
"Must know last granulepos!");
- if (mUnstamped.Length() == 1)
- return; // nothing to do
// loop through the packets backwards, subtracting the next
// packet's duration from its granulepos to get the value
@@ -937,19 +934,20 @@ void nsOpusState::ReconstructGranulepos(void)
for (PRUint32 i = mUnstamped.Length() - 1; i > 0; i--) {
ogg_packet* next = mUnstamped[i];
int offset = opus_decoder_get_nb_samples(mDecoder,
- next->packet, next->bytes);
- // check for error (negative) and overflow
+ next->packet,
+ next->bytes);
+ // check for error (negative offset) and overflow
if (offset > 0 && offset < next->granulepos)
mUnstamped[i - 1]->granulepos = next->granulepos - offset;
}
}
-nsSkeletonState::nsSkeletonState(ogg_page* aBosPage)
- : nsOggCodecState(aBosPage, true),
- mVersion(0),
- mPresentationTime(0),
- mLength(0)
+nsSkeletonState::nsSkeletonState(ogg_page* aBosPage) :
+ nsOggCodecState(aBosPage, true),
+ mVersion(0),
+ mPresentationTime(0),
+ mLength(0)
{
MOZ_COUNT_CTOR(nsSkeletonState);
}
13 content/media/ogg/nsOggCodecState.h
View
@@ -336,12 +336,13 @@ class nsOpusState : public nsOggCodecState {
bool IsHeader(ogg_packet* aPacket);
nsresult PageIn(ogg_page* aPage);
- int mRate;
- int mNominalRate;
- int mChannels;
- int mPreSkip;
- float mGain;
- int mChannelMapping;
+ // Various fields from the Ogg Opus header
+ int mRate; // Sample rate the decoder uses (always 48 kHz)
+ int mNominalRate; // Original sample rate of the data (informational)
+ int mChannels; // Number of channels decoder will produce
+ int mPreSkip; // Number of samples to strip after decoder reset
+ float mGain; // Gain (dB) to apply to decoder output
+ int mChannelMapping; // Channel mapping family
OpusDecoder *mDecoder;
45 content/media/ogg/nsOggReader.cpp
View
@@ -230,7 +230,8 @@ nsresult nsOggReader::ReadMetadata(nsVideoInfo* aInfo)
if (mOpusEnabled)
mOpusState = static_cast<nsOpusState*>(codecState);
else
- printf("media.opus.enabled is not set\n");
+ NS_WARNING("Opus decoding disabled."
+ " See media.opus.enabled in about:config");
}
if (codecState &&
codecState->GetType() == nsOggCodecState::TYPE_SKELETON &&
@@ -413,7 +414,8 @@ nsresult nsOggReader::DecodeOpus(ogg_packet* aPacket) {
NS_ASSERTION(aPacket->granulepos != -1, "Must know opus granulepos!");
PRInt32 frames = opus_decoder_get_nb_samples(mOpusState->mDecoder,
- aPacket->packet, aPacket->bytes);
+ aPacket->packet,
+ aPacket->bytes);
if (frames <= 0)
return NS_ERROR_FAILURE;
PRUint32 channels = mOpusState->mChannels;
@@ -423,7 +425,9 @@ nsresult nsOggReader::DecodeOpus(ogg_packet* aPacket) {
NS_ASSERTION(MOZ_SAMPLE_TYPE_FLOAT32, "need to hook up fixed-point decode");
int ret = opus_decode_float(mOpusState->mDecoder,
- aPacket->packet, aPacket->bytes, buffer, frames, false);
+ aPacket->packet,
+ aPacket->bytes,
+ buffer, frames, false);
if (ret < 0)
return NS_ERROR_FAILURE;
NS_ASSERTION(ret == frames, "Opus decoded too few audio samples");
@@ -444,26 +448,23 @@ nsresult nsOggReader::DecodeOpus(ogg_packet* aPacket) {
bool nsOggReader::DecodeAudioData()
{
NS_ASSERTION(mDecoder->OnDecodeThread(), "Should be on decode thread.");
- NS_ASSERTION(mVorbisState!=0 || mOpusState!=0,
+ NS_ASSERTION(mVorbisState != nsnull || mOpusState != nsnull,
"Need audio codec state to decode audio");
// Read the next data packet. Skip any non-data packets we encounter.
ogg_packet* packet = 0;
- if (mVorbisState) {
- do {
- if (packet) {
- nsOggCodecState::ReleasePacket(packet);
- }
- packet = NextOggPacket(mVorbisState);
- } while (packet && mVorbisState->IsHeader(packet));
- } else if (mOpusState) {
- do {
- if (packet) {
- nsOggCodecState::ReleasePacket(packet);
- }
- packet = NextOggPacket(mOpusState);
- } while (packet && mOpusState->IsHeader(packet));
- }
+ nsOggCodecState* codecState;
+ if (mVorbisState)
+ codecState = static_cast<nsOggCodecState*>(mVorbisState);
+ else
+ codecState = static_cast<nsOggCodecState*>(mOpusState);
+ do {
+ if (packet) {
+ nsOggCodecState::ReleasePacket(packet);
+ }
+ packet = NextOggPacket(codecState);
+ } while (packet && codecState->IsHeader(packet));
+
if (!packet) {
mAudioQueue.Finish();
return false;
@@ -472,10 +473,12 @@ bool nsOggReader::DecodeAudioData()
NS_ASSERTION(packet && packet->granulepos != -1,
"Must have packet with known granulepos");
nsAutoReleasePacket autoRelease(packet);
- if (mVorbisState)
+ if (mVorbisState) {
DecodeVorbis(packet);
- else
+ } else if (mOpusState) {
DecodeOpus(packet);
+ }
+
if (packet->e_o_s) {
// We've encountered an end of bitstream packet, or we've hit the end of
// file while trying to decode, so inform the audio queue that there'll
6 content/media/ogg/nsOggReader.h
View
@@ -258,14 +258,14 @@ class nsOggReader : public nsBuiltinDecoderReader
// Decode state of the Vorbis bitstream we're decoding, if we have audio.
nsVorbisState* mVorbisState;
+ // Decode state of the Opus bitstream we're decoding, if we have one.
+ nsOpusState *mOpusState;
+
// Represents the user pref media.opus.enabled at the time our
// contructor was called. We can't check it dynamically because
// we're not on the main thread;
bool mOpusEnabled;
- // Decode state of the Opus bitstream we're decoding, if we have one.
- nsOpusState *mOpusState;
-
// Decode state of the Skeleton bitstream.
nsSkeletonState* mSkeletonState;

No commit comments for this range

Something went wrong with that request. Please try again.