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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
48 return speech_encoder_->Max10MsFramesInAPacket(); | 48 return speech_encoder_->Max10MsFramesInAPacket(); |
49 } | 49 } |
50 | 50 |
51 int AudioEncoderCopyRed::GetTargetBitrate() const { | 51 int AudioEncoderCopyRed::GetTargetBitrate() const { |
52 return speech_encoder_->GetTargetBitrate(); | 52 return speech_encoder_->GetTargetBitrate(); |
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 rtc::ArrayView<const int16_t> audio, | 57 rtc::ArrayView<const int16_t> audio, |
58 size_t max_encoded_bytes, | 58 rtc::Buffer* encoded) { |
59 uint8_t* encoded) { | 59 |
60 size_t primary_offset = encoded->size(); | |
kwiberg-webrtc
2016/02/25 00:29:04
const
ossu
2016/02/25 10:39:51
Acknowledged.
| |
60 EncodedInfo info = | 61 EncodedInfo info = |
61 speech_encoder_->Encode(rtp_timestamp, audio, max_encoded_bytes, encoded); | 62 speech_encoder_->Encode(rtp_timestamp, audio, encoded); |
62 RTC_CHECK_GE(max_encoded_bytes, | 63 |
63 info.encoded_bytes + secondary_info_.encoded_bytes); | |
64 RTC_CHECK(info.redundant.empty()) << "Cannot use nested redundant encoders."; | 64 RTC_CHECK(info.redundant.empty()) << "Cannot use nested redundant encoders."; |
65 RTC_DCHECK_EQ(encoded->size() - primary_offset, info.encoded_bytes); | |
65 | 66 |
66 if (info.encoded_bytes > 0) { | 67 if (info.encoded_bytes > 0) { |
67 // |info| will be implicitly cast to an EncodedInfoLeaf struct, effectively | 68 // |info| will be implicitly cast to an EncodedInfoLeaf struct, effectively |
68 // discarding the (empty) vector of redundant information. This is | 69 // discarding the (empty) vector of redundant information. This is |
69 // intentional. | 70 // intentional. |
70 info.redundant.push_back(info); | 71 info.redundant.push_back(info); |
71 RTC_DCHECK_EQ(info.redundant.size(), 1u); | 72 RTC_DCHECK_EQ(info.redundant.size(), 1u); |
72 if (secondary_info_.encoded_bytes > 0) { | 73 if (secondary_info_.encoded_bytes > 0) { |
73 memcpy(&encoded[info.encoded_bytes], secondary_encoded_.data(), | 74 encoded->AppendData(secondary_encoded_); |
74 secondary_info_.encoded_bytes); | |
75 info.redundant.push_back(secondary_info_); | 75 info.redundant.push_back(secondary_info_); |
76 RTC_DCHECK_EQ(info.redundant.size(), 2u); | 76 RTC_DCHECK_EQ(info.redundant.size(), 2u); |
77 } | 77 } |
78 // Save primary to secondary. | 78 // Save primary to secondary. |
79 secondary_encoded_.SetData(encoded, info.encoded_bytes); | 79 secondary_encoded_.SetData(encoded->data() + primary_offset, |
80 info.encoded_bytes); | |
80 secondary_info_ = info; | 81 secondary_info_ = info; |
81 RTC_DCHECK_EQ(info.speech, info.redundant[0].speech); | 82 RTC_DCHECK_EQ(info.speech, info.redundant[0].speech); |
82 } | 83 } |
83 // Update main EncodedInfo. | 84 // Update main EncodedInfo. |
84 info.payload_type = red_payload_type_; | 85 info.payload_type = red_payload_type_; |
85 info.encoded_bytes = 0; | 86 info.encoded_bytes = 0; |
86 for (std::vector<EncodedInfoLeaf>::const_iterator it = info.redundant.begin(); | 87 for (std::vector<EncodedInfoLeaf>::const_iterator it = info.redundant.begin(); |
87 it != info.redundant.end(); ++it) { | 88 it != info.redundant.end(); ++it) { |
88 info.encoded_bytes += it->encoded_bytes; | 89 info.encoded_bytes += it->encoded_bytes; |
89 } | 90 } |
(...skipping 24 matching lines...) Expand all Loading... | |
114 | 115 |
115 void AudioEncoderCopyRed::SetProjectedPacketLossRate(double fraction) { | 116 void AudioEncoderCopyRed::SetProjectedPacketLossRate(double fraction) { |
116 speech_encoder_->SetProjectedPacketLossRate(fraction); | 117 speech_encoder_->SetProjectedPacketLossRate(fraction); |
117 } | 118 } |
118 | 119 |
119 void AudioEncoderCopyRed::SetTargetBitrate(int bits_per_second) { | 120 void AudioEncoderCopyRed::SetTargetBitrate(int bits_per_second) { |
120 speech_encoder_->SetTargetBitrate(bits_per_second); | 121 speech_encoder_->SetTargetBitrate(bits_per_second); |
121 } | 122 } |
122 | 123 |
123 } // namespace webrtc | 124 } // namespace webrtc |
OLD | NEW |