Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(86)

Side by Side Diff: webrtc/modules/audio_coding/codecs/g722/audio_encoder_g722.cc

Issue 1335923002: Add RTC_ prefix to (D)CHECKs and related macros. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase. Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 27 matching lines...) Expand all
38 38
39 AudioEncoderG722::AudioEncoderG722(const Config& config) 39 AudioEncoderG722::AudioEncoderG722(const Config& config)
40 : num_channels_(config.num_channels), 40 : num_channels_(config.num_channels),
41 payload_type_(config.payload_type), 41 payload_type_(config.payload_type),
42 num_10ms_frames_per_packet_( 42 num_10ms_frames_per_packet_(
43 static_cast<size_t>(config.frame_size_ms / 10)), 43 static_cast<size_t>(config.frame_size_ms / 10)),
44 num_10ms_frames_buffered_(0), 44 num_10ms_frames_buffered_(0),
45 first_timestamp_in_buffer_(0), 45 first_timestamp_in_buffer_(0),
46 encoders_(new EncoderState[num_channels_]), 46 encoders_(new EncoderState[num_channels_]),
47 interleave_buffer_(2 * num_channels_) { 47 interleave_buffer_(2 * num_channels_) {
48 CHECK(config.IsOk()); 48 RTC_CHECK(config.IsOk());
49 const size_t samples_per_channel = 49 const size_t samples_per_channel =
50 kSampleRateHz / 100 * num_10ms_frames_per_packet_; 50 kSampleRateHz / 100 * num_10ms_frames_per_packet_;
51 for (int i = 0; i < num_channels_; ++i) { 51 for (int i = 0; i < num_channels_; ++i) {
52 encoders_[i].speech_buffer.reset(new int16_t[samples_per_channel]); 52 encoders_[i].speech_buffer.reset(new int16_t[samples_per_channel]);
53 encoders_[i].encoded_buffer.SetSize(samples_per_channel / 2); 53 encoders_[i].encoded_buffer.SetSize(samples_per_channel / 2);
54 } 54 }
55 Reset(); 55 Reset();
56 } 56 }
57 57
58 AudioEncoderG722::AudioEncoderG722(const CodecInst& codec_inst) 58 AudioEncoderG722::AudioEncoderG722(const CodecInst& codec_inst)
(...skipping 30 matching lines...) Expand all
89 int AudioEncoderG722::GetTargetBitrate() const { 89 int AudioEncoderG722::GetTargetBitrate() const {
90 // 4 bits/sample, 16000 samples/s/channel. 90 // 4 bits/sample, 16000 samples/s/channel.
91 return 64000 * NumChannels(); 91 return 64000 * NumChannels();
92 } 92 }
93 93
94 AudioEncoder::EncodedInfo AudioEncoderG722::EncodeInternal( 94 AudioEncoder::EncodedInfo AudioEncoderG722::EncodeInternal(
95 uint32_t rtp_timestamp, 95 uint32_t rtp_timestamp,
96 const int16_t* audio, 96 const int16_t* audio,
97 size_t max_encoded_bytes, 97 size_t max_encoded_bytes,
98 uint8_t* encoded) { 98 uint8_t* encoded) {
99 CHECK_GE(max_encoded_bytes, MaxEncodedBytes()); 99 RTC_CHECK_GE(max_encoded_bytes, MaxEncodedBytes());
100 100
101 if (num_10ms_frames_buffered_ == 0) 101 if (num_10ms_frames_buffered_ == 0)
102 first_timestamp_in_buffer_ = rtp_timestamp; 102 first_timestamp_in_buffer_ = rtp_timestamp;
103 103
104 // Deinterleave samples and save them in each channel's buffer. 104 // Deinterleave samples and save them in each channel's buffer.
105 const size_t start = kSampleRateHz / 100 * num_10ms_frames_buffered_; 105 const size_t start = kSampleRateHz / 100 * num_10ms_frames_buffered_;
106 for (size_t i = 0; i < kSampleRateHz / 100; ++i) 106 for (size_t i = 0; i < kSampleRateHz / 100; ++i)
107 for (int j = 0; j < num_channels_; ++j) 107 for (int j = 0; j < num_channels_; ++j)
108 encoders_[j].speech_buffer[start + i] = audio[i * num_channels_ + j]; 108 encoders_[j].speech_buffer[start + i] = audio[i * num_channels_ + j];
109 109
110 // If we don't yet have enough samples for a packet, we're done for now. 110 // If we don't yet have enough samples for a packet, we're done for now.
111 if (++num_10ms_frames_buffered_ < num_10ms_frames_per_packet_) { 111 if (++num_10ms_frames_buffered_ < num_10ms_frames_per_packet_) {
112 return EncodedInfo(); 112 return EncodedInfo();
113 } 113 }
114 114
115 // Encode each channel separately. 115 // Encode each channel separately.
116 CHECK_EQ(num_10ms_frames_buffered_, num_10ms_frames_per_packet_); 116 RTC_CHECK_EQ(num_10ms_frames_buffered_, num_10ms_frames_per_packet_);
117 num_10ms_frames_buffered_ = 0; 117 num_10ms_frames_buffered_ = 0;
118 const size_t samples_per_channel = SamplesPerChannel(); 118 const size_t samples_per_channel = SamplesPerChannel();
119 for (int i = 0; i < num_channels_; ++i) { 119 for (int i = 0; i < num_channels_; ++i) {
120 const size_t encoded = WebRtcG722_Encode( 120 const size_t encoded = WebRtcG722_Encode(
121 encoders_[i].encoder, encoders_[i].speech_buffer.get(), 121 encoders_[i].encoder, encoders_[i].speech_buffer.get(),
122 samples_per_channel, encoders_[i].encoded_buffer.data()); 122 samples_per_channel, encoders_[i].encoded_buffer.data());
123 CHECK_EQ(encoded, samples_per_channel / 2); 123 RTC_CHECK_EQ(encoded, samples_per_channel / 2);
124 } 124 }
125 125
126 // Interleave the encoded bytes of the different channels. Each separate 126 // Interleave the encoded bytes of the different channels. Each separate
127 // channel and the interleaved stream encodes two samples per byte, most 127 // channel and the interleaved stream encodes two samples per byte, most
128 // significant half first. 128 // significant half first.
129 for (size_t i = 0; i < samples_per_channel / 2; ++i) { 129 for (size_t i = 0; i < samples_per_channel / 2; ++i) {
130 for (int j = 0; j < num_channels_; ++j) { 130 for (int j = 0; j < num_channels_; ++j) {
131 uint8_t two_samples = encoders_[j].encoded_buffer.data()[i]; 131 uint8_t two_samples = encoders_[j].encoded_buffer.data()[i];
132 interleave_buffer_.data()[j] = two_samples >> 4; 132 interleave_buffer_.data()[j] = two_samples >> 4;
133 interleave_buffer_.data()[num_channels_ + j] = two_samples & 0xf; 133 interleave_buffer_.data()[num_channels_ + j] = two_samples & 0xf;
134 } 134 }
135 for (int j = 0; j < num_channels_; ++j) 135 for (int j = 0; j < num_channels_; ++j)
136 encoded[i * num_channels_ + j] = interleave_buffer_.data()[2 * j] << 4 | 136 encoded[i * num_channels_ + j] = interleave_buffer_.data()[2 * j] << 4 |
137 interleave_buffer_.data()[2 * j + 1]; 137 interleave_buffer_.data()[2 * j + 1];
138 } 138 }
139 EncodedInfo info; 139 EncodedInfo info;
140 info.encoded_bytes = samples_per_channel / 2 * num_channels_; 140 info.encoded_bytes = samples_per_channel / 2 * num_channels_;
141 info.encoded_timestamp = first_timestamp_in_buffer_; 141 info.encoded_timestamp = first_timestamp_in_buffer_;
142 info.payload_type = payload_type_; 142 info.payload_type = payload_type_;
143 return info; 143 return info;
144 } 144 }
145 145
146 void AudioEncoderG722::Reset() { 146 void AudioEncoderG722::Reset() {
147 num_10ms_frames_buffered_ = 0; 147 num_10ms_frames_buffered_ = 0;
148 for (int i = 0; i < num_channels_; ++i) 148 for (int i = 0; i < num_channels_; ++i)
149 CHECK_EQ(0, WebRtcG722_EncoderInit(encoders_[i].encoder)); 149 RTC_CHECK_EQ(0, WebRtcG722_EncoderInit(encoders_[i].encoder));
150 } 150 }
151 151
152 AudioEncoderG722::EncoderState::EncoderState() { 152 AudioEncoderG722::EncoderState::EncoderState() {
153 CHECK_EQ(0, WebRtcG722_CreateEncoder(&encoder)); 153 RTC_CHECK_EQ(0, WebRtcG722_CreateEncoder(&encoder));
154 } 154 }
155 155
156 AudioEncoderG722::EncoderState::~EncoderState() { 156 AudioEncoderG722::EncoderState::~EncoderState() {
157 CHECK_EQ(0, WebRtcG722_FreeEncoder(encoder)); 157 RTC_CHECK_EQ(0, WebRtcG722_FreeEncoder(encoder));
158 } 158 }
159 159
160 size_t AudioEncoderG722::SamplesPerChannel() const { 160 size_t AudioEncoderG722::SamplesPerChannel() const {
161 return kSampleRateHz / 100 * num_10ms_frames_per_packet_; 161 return kSampleRateHz / 100 * num_10ms_frames_per_packet_;
162 } 162 }
163 163
164 } // namespace webrtc 164 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698