| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_AUDIO_ENCODER_H_ | 11 #ifndef WEBRTC_MODULES_AUDIO_CODING_CODECS_AUDIO_ENCODER_H_ |
| 12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_AUDIO_ENCODER_H_ | 12 #define WEBRTC_MODULES_AUDIO_CODING_CODECS_AUDIO_ENCODER_H_ |
| 13 | 13 |
| 14 #include <algorithm> | 14 #include <algorithm> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "webrtc/base/array_view.h" | 17 #include "webrtc/base/array_view.h" |
| 18 #include "webrtc/base/buffer.h" |
| 19 #include "webrtc/base/deprecation.h" |
| 18 #include "webrtc/typedefs.h" | 20 #include "webrtc/typedefs.h" |
| 19 | 21 |
| 20 namespace webrtc { | 22 namespace webrtc { |
| 21 | 23 |
| 22 // This is the interface class for encoders in AudioCoding module. Each codec | 24 // This is the interface class for encoders in AudioCoding module. Each codec |
| 23 // type must have an implementation of this class. | 25 // type must have an implementation of this class. |
| 24 class AudioEncoder { | 26 class AudioEncoder { |
| 25 public: | 27 public: |
| 26 struct EncodedInfoLeaf { | 28 struct EncodedInfoLeaf { |
| 27 size_t encoded_bytes = 0; | 29 size_t encoded_bytes = 0; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 // Num10MsFramesInNextPacket(). | 80 // Num10MsFramesInNextPacket(). |
| 79 virtual size_t Max10MsFramesInAPacket() const = 0; | 81 virtual size_t Max10MsFramesInAPacket() const = 0; |
| 80 | 82 |
| 81 // Returns the current target bitrate in bits/s. The value -1 means that the | 83 // Returns the current target bitrate in bits/s. The value -1 means that the |
| 82 // codec adapts the target automatically, and a current target cannot be | 84 // codec adapts the target automatically, and a current target cannot be |
| 83 // provided. | 85 // provided. |
| 84 virtual int GetTargetBitrate() const = 0; | 86 virtual int GetTargetBitrate() const = 0; |
| 85 | 87 |
| 86 // Accepts one 10 ms block of input audio (i.e., SampleRateHz() / 100 * | 88 // Accepts one 10 ms block of input audio (i.e., SampleRateHz() / 100 * |
| 87 // NumChannels() samples). Multi-channel audio must be sample-interleaved. | 89 // NumChannels() samples). Multi-channel audio must be sample-interleaved. |
| 88 // The encoder produces zero or more bytes of output in |encoded| and | 90 // The encoder appends zero or more bytes of output to |encoded| and returns |
| 89 // returns additional encoding information. | 91 // additional encoding information. Encode() checks some preconditions, calls |
| 90 // The caller is responsible for making sure that |max_encoded_bytes| is | 92 // EncodeInternal() which does the actual work, and then checks some |
| 91 // not smaller than the number of bytes actually produced by the encoder. | 93 // postconditions. |
| 92 // Encode() checks some preconditions, calls EncodeInternal() which does the | |
| 93 // actual work, and then checks some postconditions. | |
| 94 EncodedInfo Encode(uint32_t rtp_timestamp, | 94 EncodedInfo Encode(uint32_t rtp_timestamp, |
| 95 rtc::ArrayView<const int16_t> audio, | 95 rtc::ArrayView<const int16_t> audio, |
| 96 size_t max_encoded_bytes, | 96 rtc::Buffer* encoded); |
| 97 uint8_t* encoded); | |
| 98 | 97 |
| 99 virtual EncodedInfo EncodeInternal(uint32_t rtp_timestamp, | 98 // Deprecated interface to Encode (remove eventually, bug 5591). May incur a |
| 100 rtc::ArrayView<const int16_t> audio, | 99 // copy. The encoder produces zero or more bytes of output in |encoded| and |
| 101 size_t max_encoded_bytes, | 100 // returns additional encoding information. The caller is responsible for |
| 102 uint8_t* encoded) = 0; | 101 // making sure that |max_encoded_bytes| is not smaller than the number of |
| 102 // bytes actually produced by the encoder. |
| 103 RTC_DEPRECATED EncodedInfo Encode(uint32_t rtp_timestamp, |
| 104 rtc::ArrayView<const int16_t> audio, |
| 105 size_t max_encoded_bytes, |
| 106 uint8_t* encoded); |
| 107 |
| 108 EncodedInfo DEPRECATED_Encode(uint32_t rtp_timestamp, |
| 109 rtc::ArrayView<const int16_t> audio, |
| 110 size_t max_encoded_bytes, |
| 111 uint8_t* encoded); |
| 112 |
| 113 // Deprecated interface of EncodeInternal (also bug 5591). May incur a copy. |
| 114 // Subclasses implement this to perform the actual encoding. Called by |
| 115 // Encode(). By default, this is implemented as a call to the newer |
| 116 // EncodeInternal() that accepts an rtc::Buffer instead of a raw pointer. |
| 117 // That version is protected, so see below. At least one of the two |
| 118 // interfaces of EncodeInternal _must_ be implemented by a subclass. |
| 119 virtual EncodedInfo EncodeInternal( |
| 120 uint32_t rtp_timestamp, |
| 121 rtc::ArrayView<const int16_t> audio, |
| 122 size_t max_encoded_bytes, |
| 123 uint8_t* encoded); |
| 103 | 124 |
| 104 // Resets the encoder to its starting state, discarding any input that has | 125 // Resets the encoder to its starting state, discarding any input that has |
| 105 // been fed to the encoder but not yet emitted in a packet. | 126 // been fed to the encoder but not yet emitted in a packet. |
| 106 virtual void Reset() = 0; | 127 virtual void Reset() = 0; |
| 107 | 128 |
| 108 // Enables or disables codec-internal FEC (forward error correction). Returns | 129 // Enables or disables codec-internal FEC (forward error correction). Returns |
| 109 // true if the codec was able to comply. The default implementation returns | 130 // true if the codec was able to comply. The default implementation returns |
| 110 // true when asked to disable FEC and false when asked to enable it (meaning | 131 // true when asked to disable FEC and false when asked to enable it (meaning |
| 111 // that FEC isn't supported). | 132 // that FEC isn't supported). |
| 112 virtual bool SetFec(bool enable); | 133 virtual bool SetFec(bool enable); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 131 // Tells the encoder what the projected packet loss rate is. The rate is in | 152 // Tells the encoder what the projected packet loss rate is. The rate is in |
| 132 // the range [0.0, 1.0]. The encoder would typically use this information to | 153 // the range [0.0, 1.0]. The encoder would typically use this information to |
| 133 // adjust channel coding efforts, such as FEC. The default implementation | 154 // adjust channel coding efforts, such as FEC. The default implementation |
| 134 // does nothing. | 155 // does nothing. |
| 135 virtual void SetProjectedPacketLossRate(double fraction); | 156 virtual void SetProjectedPacketLossRate(double fraction); |
| 136 | 157 |
| 137 // Tells the encoder what average bitrate we'd like it to produce. The | 158 // Tells the encoder what average bitrate we'd like it to produce. The |
| 138 // encoder is free to adjust or disregard the given bitrate (the default | 159 // encoder is free to adjust or disregard the given bitrate (the default |
| 139 // implementation does the latter). | 160 // implementation does the latter). |
| 140 virtual void SetTargetBitrate(int target_bps); | 161 virtual void SetTargetBitrate(int target_bps); |
| 162 |
| 163 protected: |
| 164 // Subclasses implement this to perform the actual encoding. Called by |
| 165 // Encode(). For compatibility reasons, this is implemented by default as a |
| 166 // call to the older version of EncodeInternal(). At least one of the two |
| 167 // interfaces of EncodeInternal _must_ be implemented by a subclass. |
| 168 // Preferably this one. |
| 169 virtual EncodedInfo EncodeInternal(uint32_t rtp_timestamp, |
| 170 rtc::ArrayView<const int16_t> audio, |
| 171 rtc::Buffer* encoded); |
| 141 }; | 172 }; |
| 142 } // namespace webrtc | 173 } // namespace webrtc |
| 143 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_AUDIO_ENCODER_H_ | 174 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_AUDIO_ENCODER_H_ |
| OLD | NEW |