2013-05-17 04:18:08 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-*/
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef OpusTrackEncoder_h_
|
|
|
|
#define OpusTrackEncoder_h_
|
|
|
|
|
2013-10-17 06:45:32 -07:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <speex/speex_resampler.h>
|
2013-05-17 04:18:08 -07:00
|
|
|
#include "TrackEncoder.h"
|
|
|
|
|
|
|
|
struct OpusEncoder;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2013-10-24 19:59:52 -07:00
|
|
|
// Opus meta data structure
|
|
|
|
class OpusMetadata : public TrackMetadataBase
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// The ID Header of OggOpus. refer to http://wiki.xiph.org/OggOpus.
|
|
|
|
nsTArray<uint8_t> mIdHeader;
|
|
|
|
// The Comment Header of OggOpus.
|
|
|
|
nsTArray<uint8_t> mCommentHeader;
|
|
|
|
|
|
|
|
MetadataKind GetKind() const MOZ_OVERRIDE { return METADATA_OPUS; }
|
|
|
|
};
|
|
|
|
|
2013-05-17 04:18:08 -07:00
|
|
|
class OpusTrackEncoder : public AudioTrackEncoder
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
OpusTrackEncoder();
|
|
|
|
virtual ~OpusTrackEncoder();
|
|
|
|
|
2013-11-09 14:30:01 -08:00
|
|
|
already_AddRefed<TrackMetadataBase> GetMetadata() MOZ_OVERRIDE;
|
2013-05-17 04:18:08 -07:00
|
|
|
|
2013-10-24 19:59:52 -07:00
|
|
|
nsresult GetEncodedTrack(EncodedFrameContainer& aData) MOZ_OVERRIDE;
|
2013-05-17 04:18:08 -07:00
|
|
|
|
|
|
|
protected:
|
2013-11-11 18:29:09 -08:00
|
|
|
int GetPacketDuration();
|
2013-05-17 04:18:08 -07:00
|
|
|
|
|
|
|
nsresult Init(int aChannels, int aSamplingRate) MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
private:
|
2013-10-17 06:45:32 -07:00
|
|
|
/**
|
|
|
|
* Get the samplerate of the data to be fed to the Opus encoder. This might be
|
|
|
|
* different from the intput samplerate if resampling occurs.
|
|
|
|
*/
|
|
|
|
int GetOutputSampleRate();
|
|
|
|
|
2013-05-17 04:18:08 -07:00
|
|
|
/**
|
|
|
|
* The Opus encoder from libopus.
|
|
|
|
*/
|
|
|
|
OpusEncoder* mEncoder;
|
|
|
|
|
|
|
|
/**
|
2013-11-11 18:29:09 -08:00
|
|
|
* A local segment queue which takes the raw data out from mRawSegment in the
|
|
|
|
* call of GetEncodedTrack(). Opus encoder only accepts GetPacketDuration()
|
|
|
|
* samples from mSourceSegment every encoding cycle, thus it needs to be
|
|
|
|
* global in order to store the leftover segments taken from mRawSegment.
|
2013-05-17 04:18:08 -07:00
|
|
|
*/
|
2013-11-11 18:29:09 -08:00
|
|
|
AudioSegment mSourceSegment;
|
2013-05-17 04:18:08 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Total samples of delay added by codec, can be queried by the encoder. From
|
|
|
|
* the perspective of decoding, real data begins this many samples late, so
|
|
|
|
* the encoder needs to append this many null samples to the end of stream,
|
|
|
|
* in order to align the time of input and output.
|
|
|
|
*/
|
|
|
|
int mLookahead;
|
2013-10-17 06:45:32 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* If the input sample rate does not divide 48kHz evenly, the input data are
|
|
|
|
* resampled.
|
|
|
|
*/
|
|
|
|
SpeexResamplerState* mResampler;
|
2013-05-17 04:18:08 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|