New interface: AudioEncoderMutable
With implementations for all codecs. It has no users yet. This new interface is the same as AudioEncoder (in fact it is a subclass) but it allows changing some parameters after construction. COAUTHOR=henrik.lundin@webrtc.org BUG=4228 R=jmarusic@webrtc.org, minyue@webrtc.org Review URL: https://webrtc-codereview.appspot.com/51679004 Cr-Commit-Position: refs/heads/master@{#9149}
This commit is contained in:
@ -12,6 +12,7 @@
|
||||
|
||||
#include <limits>
|
||||
#include "webrtc/base/checks.h"
|
||||
#include "webrtc/common_types.h"
|
||||
#include "webrtc/modules/audio_coding/codecs/g722/include/g722_interface.h"
|
||||
|
||||
namespace webrtc {
|
||||
@ -22,6 +23,10 @@ const int kSampleRateHz = 16000;
|
||||
|
||||
} // namespace
|
||||
|
||||
bool AudioEncoderG722::Config::IsOk() const {
|
||||
return (frame_size_ms % 10 == 0) && (num_channels >= 1);
|
||||
}
|
||||
|
||||
AudioEncoderG722::EncoderState::EncoderState() {
|
||||
CHECK_EQ(0, WebRtcG722_CreateEncoder(&encoder));
|
||||
CHECK_EQ(0, WebRtcG722_EncoderInit(encoder));
|
||||
@ -39,8 +44,7 @@ AudioEncoderG722::AudioEncoderG722(const Config& config)
|
||||
first_timestamp_in_buffer_(0),
|
||||
encoders_(new EncoderState[num_channels_]),
|
||||
interleave_buffer_(2 * num_channels_) {
|
||||
CHECK_EQ(config.frame_size_ms % 10, 0)
|
||||
<< "Frame size must be an integer multiple of 10 ms.";
|
||||
CHECK(config.IsOk());
|
||||
const int samples_per_channel =
|
||||
kSampleRateHz / 100 * num_10ms_frames_per_packet_;
|
||||
for (int i = 0; i < num_channels_; ++i) {
|
||||
@ -134,4 +138,18 @@ int AudioEncoderG722::SamplesPerChannel() const {
|
||||
return kSampleRateHz / 100 * num_10ms_frames_per_packet_;
|
||||
}
|
||||
|
||||
namespace {
|
||||
AudioEncoderG722::Config CreateConfig(const CodecInst& codec_inst) {
|
||||
AudioEncoderG722::Config config;
|
||||
config.num_channels = codec_inst.channels;
|
||||
config.frame_size_ms = codec_inst.pacsize / 16;
|
||||
config.payload_type = codec_inst.pltype;
|
||||
return config;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
AudioEncoderMutableG722::AudioEncoderMutableG722(const CodecInst& codec_inst)
|
||||
: AudioEncoderMutableImpl<AudioEncoderG722>(CreateConfig(codec_inst)) {
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
#include "webrtc/base/buffer.h"
|
||||
#include "webrtc/base/scoped_ptr.h"
|
||||
#include "webrtc/modules/audio_coding/codecs/audio_encoder.h"
|
||||
#include "webrtc/modules/audio_coding/codecs/audio_encoder_mutable_impl.h"
|
||||
#include "webrtc/modules/audio_coding/codecs/g722/include/g722_interface.h"
|
||||
|
||||
namespace webrtc {
|
||||
@ -22,6 +23,7 @@ class AudioEncoderG722 : public AudioEncoder {
|
||||
public:
|
||||
struct Config {
|
||||
Config() : payload_type(9), frame_size_ms(20), num_channels(1) {}
|
||||
bool IsOk() const;
|
||||
|
||||
int payload_type;
|
||||
int frame_size_ms;
|
||||
@ -37,8 +39,6 @@ class AudioEncoderG722 : public AudioEncoder {
|
||||
int RtpTimestampRateHz() const override;
|
||||
int Num10MsFramesInNextPacket() const override;
|
||||
int Max10MsFramesInAPacket() const override;
|
||||
|
||||
protected:
|
||||
EncodedInfo EncodeInternal(uint32_t rtp_timestamp,
|
||||
const int16_t* audio,
|
||||
size_t max_encoded_bytes,
|
||||
@ -65,5 +65,13 @@ class AudioEncoderG722 : public AudioEncoder {
|
||||
rtc::Buffer interleave_buffer_;
|
||||
};
|
||||
|
||||
struct CodecInst;
|
||||
|
||||
class AudioEncoderMutableG722
|
||||
: public AudioEncoderMutableImpl<AudioEncoderG722> {
|
||||
public:
|
||||
explicit AudioEncoderMutableG722(const CodecInst& codec_inst);
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
#endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_G722_INCLUDE_AUDIO_ENCODER_G722_H_
|
||||
|
||||
Reference in New Issue
Block a user