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 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 // vector. | 45 // vector. |
46 struct EncodedInfo : public EncodedInfoLeaf { | 46 struct EncodedInfo : public EncodedInfoLeaf { |
47 EncodedInfo(); | 47 EncodedInfo(); |
48 ~EncodedInfo(); | 48 ~EncodedInfo(); |
49 | 49 |
50 std::vector<EncodedInfoLeaf> redundant; | 50 std::vector<EncodedInfoLeaf> redundant; |
51 }; | 51 }; |
52 | 52 |
53 virtual ~AudioEncoder() = default; | 53 virtual ~AudioEncoder() = default; |
54 | 54 |
| 55 // Returns the maximum number of bytes that can be produced by the encoder |
| 56 // at each Encode() call. The caller can use the return value to determine |
| 57 // the size of the buffer that needs to be allocated. This value is allowed |
| 58 // to depend on encoder parameters like bitrate, frame size etc., so if |
| 59 // any of these change, the caller of Encode() is responsible for checking |
| 60 // that the buffer is large enough by calling MaxEncodedBytes() again. |
| 61 virtual size_t MaxEncodedBytes() const = 0; |
| 62 |
55 // Returns the input sample rate in Hz and the number of input channels. | 63 // Returns the input sample rate in Hz and the number of input channels. |
56 // These are constants set at instantiation time. | 64 // These are constants set at instantiation time. |
57 virtual int SampleRateHz() const = 0; | 65 virtual int SampleRateHz() const = 0; |
58 virtual size_t NumChannels() const = 0; | 66 virtual size_t NumChannels() const = 0; |
59 | 67 |
60 // Returns the rate at which the RTP timestamps are updated. The default | 68 // Returns the rate at which the RTP timestamps are updated. The default |
61 // implementation returns SampleRateHz(). | 69 // implementation returns SampleRateHz(). |
62 virtual int RtpTimestampRateHz() const; | 70 virtual int RtpTimestampRateHz() const; |
63 | 71 |
64 // Returns the number of 10 ms frames the encoder will put in the next | 72 // Returns the number of 10 ms frames the encoder will put in the next |
(...skipping 15 matching lines...) Expand all Loading... |
80 // 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 * |
81 // NumChannels() samples). Multi-channel audio must be sample-interleaved. | 89 // NumChannels() samples). Multi-channel audio must be sample-interleaved. |
82 // The encoder appends zero or more bytes of output to |encoded| and returns | 90 // The encoder appends zero or more bytes of output to |encoded| and returns |
83 // additional encoding information. Encode() checks some preconditions, calls | 91 // additional encoding information. Encode() checks some preconditions, calls |
84 // EncodeImpl() which does the actual work, and then checks some | 92 // EncodeImpl() which does the actual work, and then checks some |
85 // postconditions. | 93 // postconditions. |
86 EncodedInfo Encode(uint32_t rtp_timestamp, | 94 EncodedInfo Encode(uint32_t rtp_timestamp, |
87 rtc::ArrayView<const int16_t> audio, | 95 rtc::ArrayView<const int16_t> audio, |
88 rtc::Buffer* encoded); | 96 rtc::Buffer* encoded); |
89 | 97 |
| 98 // Deprecated interface to Encode (remove eventually, bug 5591). May incur a |
| 99 // copy. The encoder produces zero or more bytes of output in |encoded| and |
| 100 // returns additional encoding information. The caller is responsible for |
| 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 EncodeInternal (see 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 // EncodeImpl() that accepts an rtc::Buffer instead of a raw pointer. |
| 117 // That version is protected, so see below. At least one of EncodeInternal |
| 118 // or EncodeImpl _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); |
| 124 |
90 // 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 |
91 // 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. |
92 virtual void Reset() = 0; | 127 virtual void Reset() = 0; |
93 | 128 |
94 // Enables or disables codec-internal FEC (forward error correction). Returns | 129 // Enables or disables codec-internal FEC (forward error correction). Returns |
95 // 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 |
96 // 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 |
97 // that FEC isn't supported). | 132 // that FEC isn't supported). |
98 virtual bool SetFec(bool enable); | 133 virtual bool SetFec(bool enable); |
99 | 134 |
(...skipping 20 matching lines...) Expand all Loading... |
120 // does nothing. | 155 // does nothing. |
121 virtual void SetProjectedPacketLossRate(double fraction); | 156 virtual void SetProjectedPacketLossRate(double fraction); |
122 | 157 |
123 // 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 |
124 // 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 |
125 // implementation does the latter). | 160 // implementation does the latter). |
126 virtual void SetTargetBitrate(int target_bps); | 161 virtual void SetTargetBitrate(int target_bps); |
127 | 162 |
128 protected: | 163 protected: |
129 // Subclasses implement this to perform the actual encoding. Called by | 164 // Subclasses implement this to perform the actual encoding. Called by |
130 // Encode(). | 165 // Encode(). For compatibility reasons, this is implemented by default as a |
| 166 // call to the older interface EncodeInternal(). At least one of |
| 167 // EncodeInternal or EncodeImpl _must_ be implemented by a |
| 168 // subclass. Preferably this one. |
131 virtual EncodedInfo EncodeImpl(uint32_t rtp_timestamp, | 169 virtual EncodedInfo EncodeImpl(uint32_t rtp_timestamp, |
132 rtc::ArrayView<const int16_t> audio, | 170 rtc::ArrayView<const int16_t> audio, |
133 rtc::Buffer* encoded) = 0; | 171 rtc::Buffer* encoded); |
134 | |
135 private: | |
136 // This function is deprecated. It was used to return the maximum number of | |
137 // bytes that can be produced by the encoder at each Encode() call. Since the | |
138 // Encode interface was changed to use rtc::Buffer, this is no longer | |
139 // applicable. It is only kept in to avoid breaking subclasses that still have | |
140 // it implemented (with the override attribute). It will be removed as soon | |
141 // as these subclasses have been given a chance to change. | |
142 virtual size_t MaxEncodedBytes() const; | |
143 }; | 172 }; |
144 } // namespace webrtc | 173 } // namespace webrtc |
145 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_AUDIO_ENCODER_H_ | 174 #endif // WEBRTC_MODULES_AUDIO_CODING_CODECS_AUDIO_ENCODER_H_ |
OLD | NEW |