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-10-24 19:59:52 -07:00
|
|
|
nsRefPtr<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:
|
|
|
|
int GetPacketDuration() MOZ_OVERRIDE;
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A local segment queue which stores the raw segments. Opus encoder only
|
|
|
|
* takes GetPacketDuration() samples from mSourceSegment in every encoding
|
|
|
|
* cycle, thus it needs to store the raw track data.
|
|
|
|
*/
|
|
|
|
nsAutoPtr<AudioSegment> mSourceSegment;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|