content/media/encoder/OpusTrackEncoder.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
michael@0 4 * You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 #ifndef OpusTrackEncoder_h_
michael@0 7 #define OpusTrackEncoder_h_
michael@0 8
michael@0 9 #include <stdint.h>
michael@0 10 #include <speex/speex_resampler.h>
michael@0 11 #include "TrackEncoder.h"
michael@0 12
michael@0 13 struct OpusEncoder;
michael@0 14
michael@0 15 namespace mozilla {
michael@0 16
michael@0 17 // Opus meta data structure
michael@0 18 class OpusMetadata : public TrackMetadataBase
michael@0 19 {
michael@0 20 public:
michael@0 21 // The ID Header of OggOpus. refer to http://wiki.xiph.org/OggOpus.
michael@0 22 nsTArray<uint8_t> mIdHeader;
michael@0 23 // The Comment Header of OggOpus.
michael@0 24 nsTArray<uint8_t> mCommentHeader;
michael@0 25
michael@0 26 MetadataKind GetKind() const MOZ_OVERRIDE { return METADATA_OPUS; }
michael@0 27 };
michael@0 28
michael@0 29 class OpusTrackEncoder : public AudioTrackEncoder
michael@0 30 {
michael@0 31 public:
michael@0 32 OpusTrackEncoder();
michael@0 33 virtual ~OpusTrackEncoder();
michael@0 34
michael@0 35 already_AddRefed<TrackMetadataBase> GetMetadata() MOZ_OVERRIDE;
michael@0 36
michael@0 37 nsresult GetEncodedTrack(EncodedFrameContainer& aData) MOZ_OVERRIDE;
michael@0 38
michael@0 39 protected:
michael@0 40 int GetPacketDuration();
michael@0 41
michael@0 42 nsresult Init(int aChannels, int aSamplingRate) MOZ_OVERRIDE;
michael@0 43
michael@0 44 /**
michael@0 45 * Get the samplerate of the data to be fed to the Opus encoder. This might be
michael@0 46 * different from the input samplerate if resampling occurs.
michael@0 47 */
michael@0 48 int GetOutputSampleRate();
michael@0 49
michael@0 50 private:
michael@0 51 /**
michael@0 52 * The Opus encoder from libopus.
michael@0 53 */
michael@0 54 OpusEncoder* mEncoder;
michael@0 55
michael@0 56 /**
michael@0 57 * A local segment queue which takes the raw data out from mRawSegment in the
michael@0 58 * call of GetEncodedTrack(). Opus encoder only accepts GetPacketDuration()
michael@0 59 * samples from mSourceSegment every encoding cycle, thus it needs to be
michael@0 60 * global in order to store the leftover segments taken from mRawSegment.
michael@0 61 */
michael@0 62 AudioSegment mSourceSegment;
michael@0 63
michael@0 64 /**
michael@0 65 * Total samples of delay added by codec, can be queried by the encoder. From
michael@0 66 * the perspective of decoding, real data begins this many samples late, so
michael@0 67 * the encoder needs to append this many null samples to the end of stream,
michael@0 68 * in order to align the time of input and output.
michael@0 69 */
michael@0 70 int mLookahead;
michael@0 71
michael@0 72 /**
michael@0 73 * If the input sample rate does not divide 48kHz evenly, the input data are
michael@0 74 * resampled.
michael@0 75 */
michael@0 76 SpeexResamplerState* mResampler;
michael@0 77
michael@0 78 /**
michael@0 79 * Store the resampled frames that don't fit into an Opus packet duration.
michael@0 80 * They will be prepended to the resampled frames next encoding cycle.
michael@0 81 */
michael@0 82 nsTArray<AudioDataValue> mResampledLeftover;
michael@0 83 };
michael@0 84
michael@0 85 }
michael@0 86 #endif

mercurial