Line data Source code
1 : /*
2 : * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 : *
4 : * Use of this source code is governed by a BSD-style license
5 : * that can be found in the LICENSE file in the root of the source
6 : * tree. An additional intellectual property rights grant can be found
7 : * in the file PATENTS. All contributing project authors may
8 : * be found in the AUTHORS file in the root of the source tree.
9 : */
10 :
11 : #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_H_
12 : #define WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_H_
13 :
14 : #include <vector>
15 :
16 : #include "webrtc/base/constructormagic.h"
17 : #include "webrtc/base/scoped_ref_ptr.h"
18 : #include "webrtc/modules/audio_coding/codecs/audio_encoder.h"
19 : #include "webrtc/modules/audio_coding/codecs/isac/locked_bandwidth_info.h"
20 :
21 : namespace webrtc {
22 :
23 : struct CodecInst;
24 :
25 : template <typename T>
26 : class AudioEncoderIsacT final : public AudioEncoder {
27 : public:
28 : // Allowed combinations of sample rate, frame size, and bit rate are
29 : // - 16000 Hz, 30 ms, 10000-32000 bps
30 : // - 16000 Hz, 60 ms, 10000-32000 bps
31 : // - 32000 Hz, 30 ms, 10000-56000 bps (if T has super-wideband support)
32 0 : struct Config {
33 : bool IsOk() const;
34 :
35 : rtc::scoped_refptr<LockedIsacBandwidthInfo> bwinfo;
36 :
37 : int payload_type = 103;
38 : int sample_rate_hz = 16000;
39 : int frame_size_ms = 30;
40 : int bit_rate = kDefaultBitRate; // Limit on the short-term average bit
41 : // rate, in bits/s.
42 : int max_payload_size_bytes = -1;
43 : int max_bit_rate = -1;
44 :
45 : // If true, the encoder will dynamically adjust frame size and bit rate;
46 : // the configured values are then merely the starting point.
47 : bool adaptive_mode = false;
48 :
49 : // In adaptive mode, prevent adaptive changes to the frame size. (Not used
50 : // in nonadaptive mode.)
51 : bool enforce_frame_size = false;
52 : };
53 :
54 : explicit AudioEncoderIsacT(const Config& config);
55 : explicit AudioEncoderIsacT(
56 : const CodecInst& codec_inst,
57 : const rtc::scoped_refptr<LockedIsacBandwidthInfo>& bwinfo);
58 : ~AudioEncoderIsacT() override;
59 :
60 : int SampleRateHz() const override;
61 : size_t NumChannels() const override;
62 : size_t Num10MsFramesInNextPacket() const override;
63 : size_t Max10MsFramesInAPacket() const override;
64 : int GetTargetBitrate() const override;
65 : EncodedInfo EncodeImpl(uint32_t rtp_timestamp,
66 : rtc::ArrayView<const int16_t> audio,
67 : rtc::Buffer* encoded) override;
68 : void Reset() override;
69 :
70 : private:
71 : // This value is taken from STREAM_SIZE_MAX_60 for iSAC float (60 ms) and
72 : // STREAM_MAXW16_60MS for iSAC fix (60 ms).
73 : static const size_t kSufficientEncodeBufferSizeBytes = 400;
74 :
75 : static const int kDefaultBitRate = 32000;
76 :
77 : // Recreate the iSAC encoder instance with the given settings, and save them.
78 : void RecreateEncoderInstance(const Config& config);
79 :
80 : Config config_;
81 : typename T::instance_type* isac_state_ = nullptr;
82 : rtc::scoped_refptr<LockedIsacBandwidthInfo> bwinfo_;
83 :
84 : // Have we accepted input but not yet emitted it in a packet?
85 : bool packet_in_progress_ = false;
86 :
87 : // Timestamp of the first input of the currently in-progress packet.
88 : uint32_t packet_timestamp_;
89 :
90 : // Timestamp of the previously encoded packet.
91 : uint32_t last_encoded_timestamp_;
92 :
93 : RTC_DISALLOW_COPY_AND_ASSIGN(AudioEncoderIsacT);
94 : };
95 :
96 : } // namespace webrtc
97 :
98 : #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_ISAC_AUDIO_ENCODER_ISAC_T_H_
|