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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 num_10ms_frames_per_packet_( | 46 num_10ms_frames_per_packet_( |
47 static_cast<size_t>(config.frame_size_ms / 10)), | 47 static_cast<size_t>(config.frame_size_ms / 10)), |
48 encoder_(nullptr) { | 48 encoder_(nullptr) { |
49 Reset(); | 49 Reset(); |
50 } | 50 } |
51 | 51 |
52 AudioEncoderIlbc::AudioEncoderIlbc(const CodecInst& codec_inst) | 52 AudioEncoderIlbc::AudioEncoderIlbc(const CodecInst& codec_inst) |
53 : AudioEncoderIlbc(CreateConfig(codec_inst)) {} | 53 : AudioEncoderIlbc(CreateConfig(codec_inst)) {} |
54 | 54 |
55 AudioEncoderIlbc::~AudioEncoderIlbc() { | 55 AudioEncoderIlbc::~AudioEncoderIlbc() { |
56 CHECK_EQ(0, WebRtcIlbcfix_EncoderFree(encoder_)); | 56 RTC_CHECK_EQ(0, WebRtcIlbcfix_EncoderFree(encoder_)); |
57 } | 57 } |
58 | 58 |
59 size_t AudioEncoderIlbc::MaxEncodedBytes() const { | 59 size_t AudioEncoderIlbc::MaxEncodedBytes() const { |
60 return RequiredOutputSizeBytes(); | 60 return RequiredOutputSizeBytes(); |
61 } | 61 } |
62 | 62 |
63 int AudioEncoderIlbc::SampleRateHz() const { | 63 int AudioEncoderIlbc::SampleRateHz() const { |
64 return kSampleRateHz; | 64 return kSampleRateHz; |
65 } | 65 } |
66 | 66 |
(...skipping 20 matching lines...) Expand all Loading... |
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 const int16_t* audio, | 94 const int16_t* audio, |
95 size_t max_encoded_bytes, | 95 size_t max_encoded_bytes, |
96 uint8_t* encoded) { | 96 uint8_t* encoded) { |
97 DCHECK_GE(max_encoded_bytes, RequiredOutputSizeBytes()); | 97 RTC_DCHECK_GE(max_encoded_bytes, RequiredOutputSizeBytes()); |
98 | 98 |
99 // Save timestamp if starting a new packet. | 99 // Save timestamp if starting a new packet. |
100 if (num_10ms_frames_buffered_ == 0) | 100 if (num_10ms_frames_buffered_ == 0) |
101 first_timestamp_in_buffer_ = rtp_timestamp; | 101 first_timestamp_in_buffer_ = rtp_timestamp; |
102 | 102 |
103 // Buffer input. | 103 // Buffer input. |
104 std::memcpy(input_buffer_ + kSampleRateHz / 100 * num_10ms_frames_buffered_, | 104 std::memcpy(input_buffer_ + kSampleRateHz / 100 * num_10ms_frames_buffered_, |
105 audio, | 105 audio, |
106 kSampleRateHz / 100 * sizeof(audio[0])); | 106 kSampleRateHz / 100 * sizeof(audio[0])); |
107 | 107 |
108 // If we don't yet have enough buffered input for a whole packet, we're done | 108 // If we don't yet have enough buffered input for a whole packet, we're done |
109 // for now. | 109 // for now. |
110 if (++num_10ms_frames_buffered_ < num_10ms_frames_per_packet_) { | 110 if (++num_10ms_frames_buffered_ < num_10ms_frames_per_packet_) { |
111 return EncodedInfo(); | 111 return EncodedInfo(); |
112 } | 112 } |
113 | 113 |
114 // Encode buffered input. | 114 // Encode buffered input. |
115 DCHECK_EQ(num_10ms_frames_buffered_, num_10ms_frames_per_packet_); | 115 RTC_DCHECK_EQ(num_10ms_frames_buffered_, num_10ms_frames_per_packet_); |
116 num_10ms_frames_buffered_ = 0; | 116 num_10ms_frames_buffered_ = 0; |
117 const int output_len = WebRtcIlbcfix_Encode( | 117 const int output_len = WebRtcIlbcfix_Encode( |
118 encoder_, | 118 encoder_, |
119 input_buffer_, | 119 input_buffer_, |
120 kSampleRateHz / 100 * num_10ms_frames_per_packet_, | 120 kSampleRateHz / 100 * num_10ms_frames_per_packet_, |
121 encoded); | 121 encoded); |
122 CHECK_GE(output_len, 0); | 122 RTC_CHECK_GE(output_len, 0); |
123 EncodedInfo info; | 123 EncodedInfo info; |
124 info.encoded_bytes = static_cast<size_t>(output_len); | 124 info.encoded_bytes = static_cast<size_t>(output_len); |
125 DCHECK_EQ(info.encoded_bytes, RequiredOutputSizeBytes()); | 125 RTC_DCHECK_EQ(info.encoded_bytes, RequiredOutputSizeBytes()); |
126 info.encoded_timestamp = first_timestamp_in_buffer_; | 126 info.encoded_timestamp = first_timestamp_in_buffer_; |
127 info.payload_type = config_.payload_type; | 127 info.payload_type = config_.payload_type; |
128 return info; | 128 return info; |
129 } | 129 } |
130 | 130 |
131 void AudioEncoderIlbc::Reset() { | 131 void AudioEncoderIlbc::Reset() { |
132 if (encoder_) | 132 if (encoder_) |
133 CHECK_EQ(0, WebRtcIlbcfix_EncoderFree(encoder_)); | 133 RTC_CHECK_EQ(0, WebRtcIlbcfix_EncoderFree(encoder_)); |
134 CHECK(config_.IsOk()); | 134 RTC_CHECK(config_.IsOk()); |
135 CHECK_EQ(0, WebRtcIlbcfix_EncoderCreate(&encoder_)); | 135 RTC_CHECK_EQ(0, WebRtcIlbcfix_EncoderCreate(&encoder_)); |
136 const int encoder_frame_size_ms = config_.frame_size_ms > 30 | 136 const int encoder_frame_size_ms = config_.frame_size_ms > 30 |
137 ? config_.frame_size_ms / 2 | 137 ? config_.frame_size_ms / 2 |
138 : config_.frame_size_ms; | 138 : config_.frame_size_ms; |
139 CHECK_EQ(0, WebRtcIlbcfix_EncoderInit(encoder_, encoder_frame_size_ms)); | 139 RTC_CHECK_EQ(0, WebRtcIlbcfix_EncoderInit(encoder_, encoder_frame_size_ms)); |
140 num_10ms_frames_buffered_ = 0; | 140 num_10ms_frames_buffered_ = 0; |
141 } | 141 } |
142 | 142 |
143 size_t AudioEncoderIlbc::RequiredOutputSizeBytes() const { | 143 size_t AudioEncoderIlbc::RequiredOutputSizeBytes() const { |
144 switch (num_10ms_frames_per_packet_) { | 144 switch (num_10ms_frames_per_packet_) { |
145 case 2: return 38; | 145 case 2: return 38; |
146 case 3: return 50; | 146 case 3: return 50; |
147 case 4: return 2 * 38; | 147 case 4: return 2 * 38; |
148 case 6: return 2 * 50; | 148 case 6: return 2 * 50; |
149 default: FATAL(); | 149 default: FATAL(); |
150 } | 150 } |
151 } | 151 } |
152 | 152 |
153 } // namespace webrtc | 153 } // namespace webrtc |
OLD | NEW |