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/red/audio_encoder_copy_red.h" | 11 #include "webrtc/modules/audio_coding/codecs/red/audio_encoder_copy_red.h" |
12 | 12 |
13 #include <string.h> | 13 #include <string.h> |
14 | 14 |
15 #include "webrtc/base/checks.h" | 15 #include "webrtc/base/checks.h" |
16 | 16 |
17 namespace webrtc { | 17 namespace webrtc { |
18 | 18 |
19 AudioEncoderCopyRed::AudioEncoderCopyRed(const Config& config) | 19 AudioEncoderCopyRed::AudioEncoderCopyRed(const Config& config) |
20 : speech_encoder_(config.speech_encoder), | 20 : speech_encoder_(config.speech_encoder), |
21 red_payload_type_(config.payload_type) { | 21 red_payload_type_(config.payload_type) { |
22 CHECK(speech_encoder_) << "Speech encoder not provided."; | 22 RTC_CHECK(speech_encoder_) << "Speech encoder not provided."; |
23 } | 23 } |
24 | 24 |
25 AudioEncoderCopyRed::~AudioEncoderCopyRed() = default; | 25 AudioEncoderCopyRed::~AudioEncoderCopyRed() = default; |
26 | 26 |
27 size_t AudioEncoderCopyRed::MaxEncodedBytes() const { | 27 size_t AudioEncoderCopyRed::MaxEncodedBytes() const { |
28 return 2 * speech_encoder_->MaxEncodedBytes(); | 28 return 2 * speech_encoder_->MaxEncodedBytes(); |
29 } | 29 } |
30 | 30 |
31 int AudioEncoderCopyRed::SampleRateHz() const { | 31 int AudioEncoderCopyRed::SampleRateHz() const { |
32 return speech_encoder_->SampleRateHz(); | 32 return speech_encoder_->SampleRateHz(); |
(...skipping 20 matching lines...) Expand all Loading... |
53 } | 53 } |
54 | 54 |
55 AudioEncoder::EncodedInfo AudioEncoderCopyRed::EncodeInternal( | 55 AudioEncoder::EncodedInfo AudioEncoderCopyRed::EncodeInternal( |
56 uint32_t rtp_timestamp, | 56 uint32_t rtp_timestamp, |
57 const int16_t* audio, | 57 const int16_t* audio, |
58 size_t max_encoded_bytes, | 58 size_t max_encoded_bytes, |
59 uint8_t* encoded) { | 59 uint8_t* encoded) { |
60 EncodedInfo info = speech_encoder_->Encode( | 60 EncodedInfo info = speech_encoder_->Encode( |
61 rtp_timestamp, audio, static_cast<size_t>(SampleRateHz() / 100), | 61 rtp_timestamp, audio, static_cast<size_t>(SampleRateHz() / 100), |
62 max_encoded_bytes, encoded); | 62 max_encoded_bytes, encoded); |
63 CHECK_GE(max_encoded_bytes, | 63 RTC_CHECK_GE(max_encoded_bytes, |
64 info.encoded_bytes + secondary_info_.encoded_bytes); | 64 info.encoded_bytes + secondary_info_.encoded_bytes); |
65 CHECK(info.redundant.empty()) << "Cannot use nested redundant encoders."; | 65 RTC_CHECK(info.redundant.empty()) << "Cannot use nested redundant encoders."; |
66 | 66 |
67 if (info.encoded_bytes > 0) { | 67 if (info.encoded_bytes > 0) { |
68 // |info| will be implicitly cast to an EncodedInfoLeaf struct, effectively | 68 // |info| will be implicitly cast to an EncodedInfoLeaf struct, effectively |
69 // discarding the (empty) vector of redundant information. This is | 69 // discarding the (empty) vector of redundant information. This is |
70 // intentional. | 70 // intentional. |
71 info.redundant.push_back(info); | 71 info.redundant.push_back(info); |
72 DCHECK_EQ(info.redundant.size(), 1u); | 72 RTC_DCHECK_EQ(info.redundant.size(), 1u); |
73 if (secondary_info_.encoded_bytes > 0) { | 73 if (secondary_info_.encoded_bytes > 0) { |
74 memcpy(&encoded[info.encoded_bytes], secondary_encoded_.data(), | 74 memcpy(&encoded[info.encoded_bytes], secondary_encoded_.data(), |
75 secondary_info_.encoded_bytes); | 75 secondary_info_.encoded_bytes); |
76 info.redundant.push_back(secondary_info_); | 76 info.redundant.push_back(secondary_info_); |
77 DCHECK_EQ(info.redundant.size(), 2u); | 77 RTC_DCHECK_EQ(info.redundant.size(), 2u); |
78 } | 78 } |
79 // Save primary to secondary. | 79 // Save primary to secondary. |
80 secondary_encoded_.SetData(encoded, info.encoded_bytes); | 80 secondary_encoded_.SetData(encoded, info.encoded_bytes); |
81 secondary_info_ = info; | 81 secondary_info_ = info; |
82 DCHECK_EQ(info.speech, info.redundant[0].speech); | 82 RTC_DCHECK_EQ(info.speech, info.redundant[0].speech); |
83 } | 83 } |
84 // Update main EncodedInfo. | 84 // Update main EncodedInfo. |
85 info.payload_type = red_payload_type_; | 85 info.payload_type = red_payload_type_; |
86 info.encoded_bytes = 0; | 86 info.encoded_bytes = 0; |
87 for (std::vector<EncodedInfoLeaf>::const_iterator it = info.redundant.begin(); | 87 for (std::vector<EncodedInfoLeaf>::const_iterator it = info.redundant.begin(); |
88 it != info.redundant.end(); ++it) { | 88 it != info.redundant.end(); ++it) { |
89 info.encoded_bytes += it->encoded_bytes; | 89 info.encoded_bytes += it->encoded_bytes; |
90 } | 90 } |
91 return info; | 91 return info; |
92 } | 92 } |
(...skipping 22 matching lines...) Expand all Loading... |
115 | 115 |
116 void AudioEncoderCopyRed::SetProjectedPacketLossRate(double fraction) { | 116 void AudioEncoderCopyRed::SetProjectedPacketLossRate(double fraction) { |
117 speech_encoder_->SetProjectedPacketLossRate(fraction); | 117 speech_encoder_->SetProjectedPacketLossRate(fraction); |
118 } | 118 } |
119 | 119 |
120 void AudioEncoderCopyRed::SetTargetBitrate(int bits_per_second) { | 120 void AudioEncoderCopyRed::SetTargetBitrate(int bits_per_second) { |
121 speech_encoder_->SetTargetBitrate(bits_per_second); | 121 speech_encoder_->SetTargetBitrate(bits_per_second); |
122 } | 122 } |
123 | 123 |
124 } // namespace webrtc | 124 } // namespace webrtc |
OLD | NEW |