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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 // 50 bytes per frame of 30 ms => (approx) 13333 bits/s. | 85 // 50 bytes per frame of 30 ms => (approx) 13333 bits/s. |
86 return 13333; | 86 return 13333; |
87 default: | 87 default: |
88 FATAL(); | 88 FATAL(); |
89 } | 89 } |
90 } | 90 } |
91 | 91 |
92 AudioEncoder::EncodedInfo AudioEncoderIlbc::EncodeInternal( | 92 AudioEncoder::EncodedInfo AudioEncoderIlbc::EncodeInternal( |
93 uint32_t rtp_timestamp, | 93 uint32_t rtp_timestamp, |
94 rtc::ArrayView<const int16_t> audio, | 94 rtc::ArrayView<const int16_t> audio, |
95 size_t max_encoded_bytes, | 95 rtc::Buffer* encoded) { |
96 uint8_t* encoded) { | |
97 RTC_DCHECK_GE(max_encoded_bytes, RequiredOutputSizeBytes()); | |
98 | 96 |
99 // Save timestamp if starting a new packet. | 97 // Save timestamp if starting a new packet. |
100 if (num_10ms_frames_buffered_ == 0) | 98 if (num_10ms_frames_buffered_ == 0) |
101 first_timestamp_in_buffer_ = rtp_timestamp; | 99 first_timestamp_in_buffer_ = rtp_timestamp; |
102 | 100 |
103 // Buffer input. | 101 // Buffer input. |
104 RTC_DCHECK_EQ(static_cast<size_t>(kSampleRateHz / 100), audio.size()); | |
105 std::copy(audio.cbegin(), audio.cend(), | 102 std::copy(audio.cbegin(), audio.cend(), |
106 input_buffer_ + kSampleRateHz / 100 * num_10ms_frames_buffered_); | 103 input_buffer_ + kSampleRateHz / 100 * num_10ms_frames_buffered_); |
107 | 104 |
108 // If we don't yet have enough buffered input for a whole packet, we're done | 105 // If we don't yet have enough buffered input for a whole packet, we're done |
109 // for now. | 106 // for now. |
110 if (++num_10ms_frames_buffered_ < num_10ms_frames_per_packet_) { | 107 if (++num_10ms_frames_buffered_ < num_10ms_frames_per_packet_) { |
111 return EncodedInfo(); | 108 return EncodedInfo(); |
112 } | 109 } |
113 | 110 |
114 // Encode buffered input. | 111 // Encode buffered input. |
115 RTC_DCHECK_EQ(num_10ms_frames_buffered_, num_10ms_frames_per_packet_); | 112 RTC_DCHECK_EQ(num_10ms_frames_buffered_, num_10ms_frames_per_packet_); |
116 num_10ms_frames_buffered_ = 0; | 113 num_10ms_frames_buffered_ = 0; |
117 const int output_len = WebRtcIlbcfix_Encode( | 114 size_t encoded_bytes = |
118 encoder_, | 115 encoded->AppendData( |
119 input_buffer_, | 116 RequiredOutputSizeBytes(), |
120 kSampleRateHz / 100 * num_10ms_frames_per_packet_, | 117 [&] (rtc::ArrayView<uint8_t> encoded) { |
121 encoded); | 118 const int r = WebRtcIlbcfix_Encode( |
122 RTC_CHECK_GE(output_len, 0); | 119 encoder_, |
120 input_buffer_, | |
121 kSampleRateHz / 100 * num_10ms_frames_per_packet_, | |
122 encoded.data()); | |
123 RTC_CHECK_GE(r, 0); | |
124 | |
125 return (r >= 0) ? static_cast<size_t>(r) : 0; | |
hlundin-webrtc
2016/02/29 12:46:47
You just CHECKed that r >= 0; no need to take care
ossu
2016/02/29 13:23:01
Acknowledged.
| |
126 }); | |
127 | |
128 RTC_DCHECK_EQ(encoded_bytes, RequiredOutputSizeBytes()); | |
129 | |
123 EncodedInfo info; | 130 EncodedInfo info; |
124 info.encoded_bytes = static_cast<size_t>(output_len); | 131 info.encoded_bytes = encoded_bytes; |
125 RTC_DCHECK_EQ(info.encoded_bytes, RequiredOutputSizeBytes()); | |
126 info.encoded_timestamp = first_timestamp_in_buffer_; | 132 info.encoded_timestamp = first_timestamp_in_buffer_; |
127 info.payload_type = config_.payload_type; | 133 info.payload_type = config_.payload_type; |
128 return info; | 134 return info; |
129 } | 135 } |
130 | 136 |
131 void AudioEncoderIlbc::Reset() { | 137 void AudioEncoderIlbc::Reset() { |
132 if (encoder_) | 138 if (encoder_) |
133 RTC_CHECK_EQ(0, WebRtcIlbcfix_EncoderFree(encoder_)); | 139 RTC_CHECK_EQ(0, WebRtcIlbcfix_EncoderFree(encoder_)); |
134 RTC_CHECK(config_.IsOk()); | 140 RTC_CHECK(config_.IsOk()); |
135 RTC_CHECK_EQ(0, WebRtcIlbcfix_EncoderCreate(&encoder_)); | 141 RTC_CHECK_EQ(0, WebRtcIlbcfix_EncoderCreate(&encoder_)); |
136 const int encoder_frame_size_ms = config_.frame_size_ms > 30 | 142 const int encoder_frame_size_ms = config_.frame_size_ms > 30 |
137 ? config_.frame_size_ms / 2 | 143 ? config_.frame_size_ms / 2 |
138 : config_.frame_size_ms; | 144 : config_.frame_size_ms; |
139 RTC_CHECK_EQ(0, WebRtcIlbcfix_EncoderInit(encoder_, encoder_frame_size_ms)); | 145 RTC_CHECK_EQ(0, WebRtcIlbcfix_EncoderInit(encoder_, encoder_frame_size_ms)); |
140 num_10ms_frames_buffered_ = 0; | 146 num_10ms_frames_buffered_ = 0; |
141 } | 147 } |
142 | 148 |
143 size_t AudioEncoderIlbc::RequiredOutputSizeBytes() const { | 149 size_t AudioEncoderIlbc::RequiredOutputSizeBytes() const { |
144 switch (num_10ms_frames_per_packet_) { | 150 switch (num_10ms_frames_per_packet_) { |
145 case 2: return 38; | 151 case 2: return 38; |
146 case 3: return 50; | 152 case 3: return 50; |
147 case 4: return 2 * 38; | 153 case 4: return 2 * 38; |
148 case 6: return 2 * 50; | 154 case 6: return 2 * 50; |
149 default: FATAL(); | 155 default: FATAL(); |
150 } | 156 } |
151 } | 157 } |
152 | 158 |
153 } // namespace webrtc | 159 } // namespace webrtc |
OLD | NEW |