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 | |
32 // ossu: I've seen this expressed in several different ways in checks inside | |
33 // ossu: EncodeInternal in implementations. Should this not suffice? | |
kwiberg-webrtc
2016/02/25 00:29:04
Well, maybe. But having an assert close to the cod
ossu
2016/02/25 15:58:46
Acknowledged.
| |
34 RTC_CHECK_EQ(audio.size(), | |
35 static_cast<size_t>(NumChannels() * SampleRateHz() / 100)); | |
36 | |
37 EncodedInfo info; | |
38 info = EncodeInternal(rtp_timestamp, audio, encoded); | |
39 return info; | |
kwiberg-webrtc
2016/02/25 00:29:04
You can eliminate the local variable and turn thes
ossu
2016/02/25 10:39:51
I believe I split this up while debugging and neve
kwiberg-webrtc
2016/02/25 12:24:25
The backwards-compatible EncodeInternal is only ca
ossu
2016/02/25 15:58:46
Ah, yes. Right you are!
| |
40 } | |
41 | |
42 AudioEncoder::EncodedInfo AudioEncoder::Encode( | |
43 uint32_t rtp_timestamp, | |
44 rtc::ArrayView<const int16_t> audio, | |
45 size_t max_encoded_bytes, | |
46 uint8_t* encoded) { | |
47 return DEPRECATED_Encode(rtp_timestamp, audio, max_encoded_bytes, encoded); | |
48 } | |
49 | |
50 AudioEncoder::EncodedInfo AudioEncoder::DEPRECATED_Encode( | |
51 uint32_t rtp_timestamp, | |
52 rtc::ArrayView<const int16_t> audio, | |
29 size_t max_encoded_bytes, | 53 size_t max_encoded_bytes, |
30 uint8_t* encoded) { | 54 uint8_t* encoded) { |
31 TRACE_EVENT0("webrtc", "AudioEncoder::Encode"); | 55 TRACE_EVENT0("webrtc", "AudioEncoder::Encode"); |
32 RTC_CHECK_EQ(audio.size(), | 56 RTC_CHECK_EQ(audio.size(), |
33 static_cast<size_t>(NumChannels() * SampleRateHz() / 100)); | 57 static_cast<size_t>(NumChannels() * SampleRateHz() / 100)); |
34 EncodedInfo info = | 58 EncodedInfo info = |
35 EncodeInternal(rtp_timestamp, audio, max_encoded_bytes, encoded); | 59 EncodeInternal(rtp_timestamp, audio, |
60 max_encoded_bytes, encoded); | |
36 RTC_CHECK_LE(info.encoded_bytes, max_encoded_bytes); | 61 RTC_CHECK_LE(info.encoded_bytes, max_encoded_bytes); |
37 return info; | 62 return info; |
38 } | 63 } |
39 | 64 |
65 AudioEncoder::EncodedInfo AudioEncoder::EncodeInternal( | |
66 uint32_t rtp_timestamp, | |
67 rtc::ArrayView<const int16_t> audio, | |
68 rtc::Buffer* encoded) | |
69 { | |
70 EncodedInfo info; | |
71 encoded->AppendData(MaxEncodedBytes(), [&] (rtc::ArrayView<uint8_t> encoded) { | |
72 info = EncodeInternal(rtp_timestamp, audio, | |
73 encoded.size(), encoded.data()); | |
74 return info.encoded_bytes; | |
75 }); | |
76 return info; | |
77 } | |
78 | |
79 AudioEncoder::EncodedInfo AudioEncoder::EncodeInternal( | |
80 uint32_t rtp_timestamp, | |
81 rtc::ArrayView<const int16_t> audio, | |
82 size_t max_encoded_bytes, | |
83 uint8_t* encoded) | |
84 { | |
85 rtc::Buffer temp_buffer; | |
86 EncodedInfo info = EncodeInternal(rtp_timestamp, audio, &temp_buffer); | |
87 RTC_DCHECK_LE(temp_buffer.size(), max_encoded_bytes); | |
88 std::memcpy(encoded, temp_buffer.data(), info.encoded_bytes); | |
89 return info; | |
90 } | |
91 | |
40 bool AudioEncoder::SetFec(bool enable) { | 92 bool AudioEncoder::SetFec(bool enable) { |
41 return !enable; | 93 return !enable; |
42 } | 94 } |
43 | 95 |
44 bool AudioEncoder::SetDtx(bool enable) { | 96 bool AudioEncoder::SetDtx(bool enable) { |
45 return !enable; | 97 return !enable; |
46 } | 98 } |
47 | 99 |
48 bool AudioEncoder::SetApplication(Application application) { | 100 bool AudioEncoder::SetApplication(Application application) { |
49 return false; | 101 return false; |
50 } | 102 } |
51 | 103 |
52 void AudioEncoder::SetMaxPlaybackRate(int frequency_hz) {} | 104 void AudioEncoder::SetMaxPlaybackRate(int frequency_hz) {} |
53 | 105 |
54 void AudioEncoder::SetProjectedPacketLossRate(double fraction) {} | 106 void AudioEncoder::SetProjectedPacketLossRate(double fraction) {} |
55 | 107 |
56 void AudioEncoder::SetTargetBitrate(int target_bps) {} | 108 void AudioEncoder::SetTargetBitrate(int target_bps) {} |
57 | 109 |
58 } // namespace webrtc | 110 } // namespace webrtc |
OLD | NEW |