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 #include "webrtc/modules/audio_coding/codecs/audio_encoder.h" | 11 #include "webrtc/modules/audio_coding/codecs/audio_encoder.h" |
12 | 12 |
13 #include "webrtc/base/checks.h" | 13 #include "webrtc/base/checks.h" |
14 #include "webrtc/base/trace_event.h" | 14 #include "webrtc/base/trace_event.h" |
15 | 15 |
16 namespace webrtc { | 16 namespace webrtc { |
17 | 17 |
18 AudioEncoder::EncodedInfo::EncodedInfo() = default; | 18 AudioEncoder::EncodedInfo::EncodedInfo() = default; |
19 | 19 |
20 AudioEncoder::EncodedInfo::~EncodedInfo() = default; | 20 AudioEncoder::EncodedInfo::~EncodedInfo() = default; |
21 | 21 |
22 int AudioEncoder::RtpTimestampRateHz() const { | 22 int AudioEncoder::RtpTimestampRateHz() const { |
23 return SampleRateHz(); | 23 return SampleRateHz(); |
24 } | 24 } |
25 | 25 |
26 AudioEncoder::EncodedInfo AudioEncoder::Encode( | 26 AudioEncoder::EncodedInfo AudioEncoder::Encode( |
27 uint32_t rtp_timestamp, | 27 uint32_t rtp_timestamp, |
28 rtc::ArrayView<const int16_t> audio, | 28 rtc::ArrayView<const int16_t> audio, |
| 29 rtc::Buffer* encoded) { |
| 30 TRACE_EVENT0("webrtc", "AudioEncoder::Encode"); |
| 31 RTC_CHECK_EQ(audio.size(), |
| 32 static_cast<size_t>(NumChannels() * SampleRateHz() / 100)); |
| 33 |
| 34 const size_t old_size = encoded->size(); |
| 35 EncodedInfo info = EncodeInternal(rtp_timestamp, audio, encoded); |
| 36 RTC_CHECK_EQ(encoded->size() - old_size, info.encoded_bytes); |
| 37 return info; |
| 38 } |
| 39 |
| 40 AudioEncoder::EncodedInfo AudioEncoder::Encode( |
| 41 uint32_t rtp_timestamp, |
| 42 rtc::ArrayView<const int16_t> audio, |
| 43 size_t max_encoded_bytes, |
| 44 uint8_t* encoded) { |
| 45 return DEPRECATED_Encode(rtp_timestamp, audio, max_encoded_bytes, encoded); |
| 46 } |
| 47 |
| 48 AudioEncoder::EncodedInfo AudioEncoder::DEPRECATED_Encode( |
| 49 uint32_t rtp_timestamp, |
| 50 rtc::ArrayView<const int16_t> audio, |
29 size_t max_encoded_bytes, | 51 size_t max_encoded_bytes, |
30 uint8_t* encoded) { | 52 uint8_t* encoded) { |
31 TRACE_EVENT0("webrtc", "AudioEncoder::Encode"); | 53 TRACE_EVENT0("webrtc", "AudioEncoder::Encode"); |
32 RTC_CHECK_EQ(audio.size(), | 54 RTC_CHECK_EQ(audio.size(), |
33 static_cast<size_t>(NumChannels() * SampleRateHz() / 100)); | 55 static_cast<size_t>(NumChannels() * SampleRateHz() / 100)); |
34 EncodedInfo info = | 56 EncodedInfo info = |
35 EncodeInternal(rtp_timestamp, audio, max_encoded_bytes, encoded); | 57 EncodeInternal(rtp_timestamp, audio, |
| 58 max_encoded_bytes, encoded); |
36 RTC_CHECK_LE(info.encoded_bytes, max_encoded_bytes); | 59 RTC_CHECK_LE(info.encoded_bytes, max_encoded_bytes); |
37 return info; | 60 return info; |
38 } | 61 } |
39 | 62 |
| 63 AudioEncoder::EncodedInfo AudioEncoder::EncodeInternal( |
| 64 uint32_t rtp_timestamp, |
| 65 rtc::ArrayView<const int16_t> audio, |
| 66 rtc::Buffer* encoded) |
| 67 { |
| 68 EncodedInfo info; |
| 69 encoded->AppendData(MaxEncodedBytes(), [&] (rtc::ArrayView<uint8_t> encoded) { |
| 70 info = EncodeInternal(rtp_timestamp, audio, |
| 71 encoded.size(), encoded.data()); |
| 72 return info.encoded_bytes; |
| 73 }); |
| 74 return info; |
| 75 } |
| 76 |
| 77 AudioEncoder::EncodedInfo AudioEncoder::EncodeInternal( |
| 78 uint32_t rtp_timestamp, |
| 79 rtc::ArrayView<const int16_t> audio, |
| 80 size_t max_encoded_bytes, |
| 81 uint8_t* encoded) |
| 82 { |
| 83 rtc::Buffer temp_buffer; |
| 84 EncodedInfo info = EncodeInternal(rtp_timestamp, audio, &temp_buffer); |
| 85 RTC_DCHECK_LE(temp_buffer.size(), max_encoded_bytes); |
| 86 std::memcpy(encoded, temp_buffer.data(), info.encoded_bytes); |
| 87 return info; |
| 88 } |
| 89 |
40 bool AudioEncoder::SetFec(bool enable) { | 90 bool AudioEncoder::SetFec(bool enable) { |
41 return !enable; | 91 return !enable; |
42 } | 92 } |
43 | 93 |
44 bool AudioEncoder::SetDtx(bool enable) { | 94 bool AudioEncoder::SetDtx(bool enable) { |
45 return !enable; | 95 return !enable; |
46 } | 96 } |
47 | 97 |
48 bool AudioEncoder::SetApplication(Application application) { | 98 bool AudioEncoder::SetApplication(Application application) { |
49 return false; | 99 return false; |
50 } | 100 } |
51 | 101 |
52 void AudioEncoder::SetMaxPlaybackRate(int frequency_hz) {} | 102 void AudioEncoder::SetMaxPlaybackRate(int frequency_hz) {} |
53 | 103 |
54 void AudioEncoder::SetProjectedPacketLossRate(double fraction) {} | 104 void AudioEncoder::SetProjectedPacketLossRate(double fraction) {} |
55 | 105 |
56 void AudioEncoder::SetTargetBitrate(int target_bps) {} | 106 void AudioEncoder::SetTargetBitrate(int target_bps) {} |
57 | 107 |
58 } // namespace webrtc | 108 } // namespace webrtc |
OLD | NEW |