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