Bug 1313632: P2. Cleaner Ogg related headers. r?kaku
MozReview-Commit-ID: DpnezpZw27H
--- a/dom/media/flac/FlacFrameParser.cpp
+++ b/dom/media/flac/FlacFrameParser.cpp
@@ -3,16 +3,17 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "FlacFrameParser.h"
#include "mp4_demuxer/ByteReader.h"
#include "nsTArray.h"
#include "OggCodecState.h"
+#include "OpusParser.h"
#include "VideoUtils.h"
using mp4_demuxer::ByteReader;
namespace mozilla
{
#define OGG_FLAC_METADATA_TYPE_STREAMINFO 0x7F
@@ -38,16 +39,20 @@ FlacFrameParser::FlacFrameParser()
, mMinFrameSize(0)
, mMaxFrameSize(0)
, mNumFrames(0)
, mFullMetadata(false)
, mPacketCount(0)
{
}
+FlacFrameParser::~FlacFrameParser()
+{
+}
+
uint32_t
FlacFrameParser::HeaderBlockLength(const uint8_t* aPacket) const
{
uint32_t extra = 4;
if (aPacket[0] == 'f') {
// This must be the first block read, which contains the fLaC signature.
aPacket += 4;
extra += 4;
--- a/dom/media/flac/FlacFrameParser.h
+++ b/dom/media/flac/FlacFrameParser.h
@@ -21,16 +21,17 @@ class OpusParser;
// Decode a Flac Metadata block contained in either a ogg packet
// (https://xiph.org/flac/ogg_mapping.html) or in flac container
// (https://xiph.org/flac/format.html#frame_header)
class FlacFrameParser
{
public:
FlacFrameParser();
+ ~FlacFrameParser();
bool IsHeaderBlock(const uint8_t* aPacket, size_t aLength) const;
// Return the length of the block header (METADATA_BLOCK_HEADER+
// METADATA_BLOCK_DATA), aPacket must point to at least 4
// bytes and to a valid block header start (as determined by IsHeaderBlock).
uint32_t HeaderBlockLength(const uint8_t* aPacket) const;
bool DecodeHeaderBlock(const uint8_t* aPacket, size_t aLength);
bool HasFullMetadata() const { return mFullMetadata; }
@@ -51,14 +52,13 @@ private:
uint32_t mMinFrameSize;
uint32_t mMaxFrameSize;
uint64_t mNumFrames;
bool mFullMetadata;
uint32_t mPacketCount;
// Used to decode the vorbis comment metadata.
nsAutoPtr<OpusParser> mParser;
-
};
}
#endif // FLAC_FRAME_PARSER_H_
--- a/dom/media/ogg/OggCodecState.cpp
+++ b/dom/media/ogg/OggCodecState.cpp
@@ -1,28 +1,28 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <string.h>
-#include "mozilla/DebugOnly.h"
#include "mozilla/EndianUtils.h"
#include <stdint.h>
#include "nsDebug.h"
-#include "MediaDecoderReader.h"
#include "OggCodecState.h"
-#include "OggDecoder.h"
-#include "nsISupportsImpl.h"
+#include "OpusParser.h"
#include "VideoUtils.h"
#include <algorithm>
+#include <opus/opus.h>
+#include "opus/opus_multistream.h"
+
// On Android JellyBean, the hardware.h header redefines version_major and
// version_minor, which breaks our build. See:
// https://bugzilla.mozilla.org/show_bug.cgi?id=912702#c6
#ifdef MOZ_WIDGET_GONK
#ifdef version_major
#undef version_major
#endif
#ifdef version_minor
--- a/dom/media/ogg/OggCodecState.h
+++ b/dom/media/ogg/OggCodecState.h
@@ -2,49 +2,45 @@
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#if !defined(OggCodecState_h_)
#define OggCodecState_h_
#include <ogg/ogg.h>
-#include <theora/theoradec.h>
-#ifdef MOZ_TREMOR
-#include <tremor/ivorbiscodec.h>
-#else
-#include <vorbis/codec.h>
-#endif
-#include <opus/opus.h>
-#include "opus/opus_multistream.h"
// For MOZ_SAMPLE_TYPE_*
-#include "mozilla/dom/HTMLMediaElement.h"
-#include "MediaDecoderStateMachine.h"
-#include "MediaDecoderReader.h"
#include <nsAutoPtr.h>
#include <nsAutoRef.h>
#include <nsDeque.h>
#include <nsTArray.h>
#include <nsClassHashtable.h>
#include "VideoUtils.h"
#include "FlacFrameParser.h"
-#include <stdint.h>
+#include <theora/theoradec.h>
+#ifdef MOZ_TREMOR
+#include <tremor/ivorbiscodec.h>
+#else
+#include <vorbis/codec.h>
+#endif
// Uncomment the following to validate that we're predicting the number
// of Vorbis samples in each packet correctly.
#define VALIDATE_VORBIS_SAMPLE_CALCULATION
#ifdef VALIDATE_VORBIS_SAMPLE_CALCULATION
#include <map>
#endif
-#include "OpusParser.h"
+struct OpusMSDecoder;
namespace mozilla {
+class OpusParser;
+
// Deallocates a packet, used in OggPacketQueue below.
class OggPacketDeallocator : public nsDequeFunctor
{
virtual void* operator() (void* aPacket)
{
ogg_packet* p = static_cast<ogg_packet*>(aPacket);
delete [] p->packet;
delete p;
@@ -89,21 +85,21 @@ public:
TYPE_THEORA,
TYPE_OPUS,
TYPE_SKELETON,
TYPE_FLAC,
TYPE_UNKNOWN
};
virtual ~OggCodecState();
-
+
// Factory for creating nsCodecStates. Use instead of constructor.
// aPage should be a beginning-of-stream page.
static OggCodecState* Create(ogg_page* aPage);
-
+
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)
@@ -204,32 +200,32 @@ public:
// Extracts all packets from the page, and inserts them into the packet
// queue. They can be extracted by calling PacketOut(). Packets from an
// inactive stream are not buffered, i.e. this call has no effect for
// inactive streams. Multiple pages may need to be inserted before
// PacketOut() starts to return packets, as granulepos may need to be
// captured.
virtual nsresult PageIn(ogg_page* aPage);
- // Number of packets read.
+ // Number of packets read.
uint64_t mPacketCount;
// Serial number of the bitstream.
uint32_t mSerial;
// Ogg specific state.
ogg_stream_state mState;
// Queue of as yet undecoded packets. Packets are guaranteed to have
// a valid granulepos.
OggPacketQueue mPackets;
// Is the bitstream active; whether we're decoding and playing this bitstream.
bool mActive;
-
+
// True when all headers packets have been read.
bool mDoneReadingHeaders;
// Validation utility for vorbis-style tag names.
static bool IsValidVorbisTagName(nsCString& aName);
// Utility method to parse and add a vorbis-style comment
// to a metadata hash table. Most Ogg-encapsulated codecs
@@ -355,17 +351,17 @@ public:
bool IsKeyframe(ogg_packet* aPacket) override;
nsresult PageIn(ogg_page* aPage) override;
// Returns the maximum number of microseconds which a keyframe can be offset
// from any given interframe.
int64_t MaxKeyframeOffset();
// Returns the end time that a granulepos represents.
- static int64_t Time(th_info* aInfo, int64_t aGranulePos);
+ static int64_t Time(th_info* aInfo, int64_t aGranulePos);
th_info mInfo;
th_comment mComment;
th_setup_info* mSetup;
th_dec_ctx* mCtx;
float mPixelAspectRatio;
@@ -561,17 +557,17 @@ private:
int64_t mLength;
// Stores the keyframe index and duration information for a particular
// stream.
class nsKeyFrameIndex
{
public:
- nsKeyFrameIndex(int64_t aStartTime, int64_t aEndTime)
+ nsKeyFrameIndex(int64_t aStartTime, int64_t aEndTime)
: mStartTime(aStartTime)
, mEndTime(aEndTime)
{
MOZ_COUNT_CTOR(nsKeyFrameIndex);
}
~nsKeyFrameIndex()
{
--- a/dom/media/ogg/OpusParser.cpp
+++ b/dom/media/ogg/OpusParser.cpp
@@ -1,26 +1,19 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-#include <string.h>
-
-#include "mozilla/DebugOnly.h"
+#include <algorithm>
#include "mozilla/EndianUtils.h"
-#include <stdint.h>
#include "OpusParser.h"
-
-#include "nsDebug.h"
-#include "MediaDecoderReader.h"
#include "VideoUtils.h"
-#include <algorithm>
#include "opus/opus.h"
extern "C" {
#include "opus/opus_multistream.h"
}
namespace mozilla {
--- a/dom/media/ogg/OpusParser.h
+++ b/dom/media/ogg/OpusParser.h
@@ -1,21 +1,16 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#if !defined(OpusParser_h_)
#define OpusParser_h_
-#include <stdint.h>
-
-#include <opus/opus.h>
-#include "opus/opus_multistream.h"
-
#include "nsTArray.h"
#include "nsString.h"
namespace mozilla {
class OpusParser
{
public:
@@ -41,14 +36,13 @@ public:
// Granule position (end sample) of the last decoded Opus packet. This is
// used to calculate the amount we should trim from the last packet.
int64_t mPrevPacketGranulepos;
nsTArray<nsCString> mTags; // Unparsed comment strings from the header.
nsCString mVendorString; // Encoder vendor string from the header.
-
};
} // namespace mozilla
#endif
--- a/dom/media/platforms/agnostic/OpusDecoder.cpp
+++ b/dom/media/platforms/agnostic/OpusDecoder.cpp
@@ -1,25 +1,30 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "OpusDecoder.h"
+#include "OpusParser.h"
#include "TimeUnits.h"
#include "VorbisUtils.h"
#include "VorbisDecoder.h" // For VorbisLayout
#include "mozilla/EndianUtils.h"
#include "mozilla/PodOperations.h"
#include "mozilla/SyncRunnable.h"
-#include <stdint.h>
#include <inttypes.h> // For PRId64
+#include "opus/opus.h"
+extern "C" {
+#include "opus/opus_multistream.h"
+}
+
#define OPUS_DEBUG(arg, ...) MOZ_LOG(sPDMLog, mozilla::LogLevel::Debug, \
("OpusDataDecoder(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
namespace mozilla {
OpusDataDecoder::OpusDataDecoder(const CreateDecoderParams& aParams)
: mInfo(aParams.AudioConfig())
, mTaskQueue(aParams.mTaskQueue)
--- a/dom/media/platforms/agnostic/OpusDecoder.h
+++ b/dom/media/platforms/agnostic/OpusDecoder.h
@@ -1,24 +1,27 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim:set ts=2 sw=2 sts=2 et cindent: */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#if !defined(OpusDecoder_h_)
#define OpusDecoder_h_
-#include "OpusParser.h"
#include "PlatformDecoderModule.h"
#include "mozilla/Maybe.h"
#include "nsAutoPtr.h"
+struct OpusMSDecoder;
+
namespace mozilla {
+class OpusParser;
+
class OpusDataDecoder : public MediaDataDecoder
{
public:
explicit OpusDataDecoder(const CreateDecoderParams& aParams);
~OpusDataDecoder();
RefPtr<InitPromise> Init() override;
void Input(MediaRawData* aSample) override;