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

Side by Side Diff: webrtc/modules/audio_coding/codecs/g711/audio_encoder_pcm.cc

Issue 1230503003: Update a ton of audio code to use size_t more correctly and in general reduce (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Resync 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 19 matching lines...) Expand all
30 } // namespace 30 } // namespace
31 31
32 bool AudioEncoderPcm::Config::IsOk() const { 32 bool AudioEncoderPcm::Config::IsOk() const {
33 return (frame_size_ms % 10 == 0) && (num_channels >= 1); 33 return (frame_size_ms % 10 == 0) && (num_channels >= 1);
34 } 34 }
35 35
36 AudioEncoderPcm::AudioEncoderPcm(const Config& config, int sample_rate_hz) 36 AudioEncoderPcm::AudioEncoderPcm(const Config& config, int sample_rate_hz)
37 : sample_rate_hz_(sample_rate_hz), 37 : sample_rate_hz_(sample_rate_hz),
38 num_channels_(config.num_channels), 38 num_channels_(config.num_channels),
39 payload_type_(config.payload_type), 39 payload_type_(config.payload_type),
40 num_10ms_frames_per_packet_(config.frame_size_ms / 10), 40 num_10ms_frames_per_packet_(
41 static_cast<size_t>(config.frame_size_ms / 10)),
41 full_frame_samples_(NumSamplesPerFrame(config.num_channels, 42 full_frame_samples_(NumSamplesPerFrame(config.num_channels,
42 config.frame_size_ms, 43 config.frame_size_ms,
43 sample_rate_hz_)), 44 sample_rate_hz_)),
44 first_timestamp_in_buffer_(0) { 45 first_timestamp_in_buffer_(0) {
45 CHECK_GT(sample_rate_hz, 0) << "Sample rate must be larger than 0 Hz"; 46 CHECK_GT(sample_rate_hz, 0) << "Sample rate must be larger than 0 Hz";
46 CHECK_EQ(config.frame_size_ms % 10, 0) 47 CHECK_EQ(config.frame_size_ms % 10, 0)
47 << "Frame size must be an integer multiple of 10 ms."; 48 << "Frame size must be an integer multiple of 10 ms.";
48 speech_buffer_.reserve(full_frame_samples_); 49 speech_buffer_.reserve(full_frame_samples_);
49 } 50 }
50 51
51 AudioEncoderPcm::~AudioEncoderPcm() { 52 AudioEncoderPcm::~AudioEncoderPcm() {
52 } 53 }
53 54
54 int AudioEncoderPcm::SampleRateHz() const { 55 int AudioEncoderPcm::SampleRateHz() const {
55 return sample_rate_hz_; 56 return sample_rate_hz_;
56 } 57 }
57 58
58 int AudioEncoderPcm::NumChannels() const { 59 int AudioEncoderPcm::NumChannels() const {
59 return num_channels_; 60 return num_channels_;
60 } 61 }
61 62
62 size_t AudioEncoderPcm::MaxEncodedBytes() const { 63 size_t AudioEncoderPcm::MaxEncodedBytes() const {
63 return full_frame_samples_ * BytesPerSample(); 64 return full_frame_samples_ * BytesPerSample();
64 } 65 }
65 66
66 int AudioEncoderPcm::Num10MsFramesInNextPacket() const { 67 size_t AudioEncoderPcm::Num10MsFramesInNextPacket() const {
67 return num_10ms_frames_per_packet_; 68 return num_10ms_frames_per_packet_;
68 } 69 }
69 70
70 int AudioEncoderPcm::Max10MsFramesInAPacket() const { 71 size_t AudioEncoderPcm::Max10MsFramesInAPacket() const {
71 return num_10ms_frames_per_packet_; 72 return num_10ms_frames_per_packet_;
72 } 73 }
73 74
74 int AudioEncoderPcm::GetTargetBitrate() const { 75 int AudioEncoderPcm::GetTargetBitrate() const {
75 return 8 * BytesPerSample() * SampleRateHz() * NumChannels(); 76 return 8 * BytesPerSample() * SampleRateHz() * NumChannels();
76 } 77 }
77 78
78 AudioEncoder::EncodedInfo AudioEncoderPcm::EncodeInternal( 79 AudioEncoder::EncodedInfo AudioEncoderPcm::EncodeInternal(
79 uint32_t rtp_timestamp, 80 uint32_t rtp_timestamp,
80 const int16_t* audio, 81 const int16_t* audio,
81 size_t max_encoded_bytes, 82 size_t max_encoded_bytes,
82 uint8_t* encoded) { 83 uint8_t* encoded) {
83 const int num_samples = SampleRateHz() / 100 * NumChannels(); 84 const int num_samples = SampleRateHz() / 100 * NumChannels();
84 if (speech_buffer_.empty()) { 85 if (speech_buffer_.empty()) {
85 first_timestamp_in_buffer_ = rtp_timestamp; 86 first_timestamp_in_buffer_ = rtp_timestamp;
86 } 87 }
87 for (int i = 0; i < num_samples; ++i) { 88 for (int i = 0; i < num_samples; ++i) {
88 speech_buffer_.push_back(audio[i]); 89 speech_buffer_.push_back(audio[i]);
89 } 90 }
90 if (speech_buffer_.size() < full_frame_samples_) { 91 if (speech_buffer_.size() < full_frame_samples_) {
91 return EncodedInfo(); 92 return EncodedInfo();
92 } 93 }
93 CHECK_EQ(speech_buffer_.size(), full_frame_samples_); 94 CHECK_EQ(speech_buffer_.size(), full_frame_samples_);
94 CHECK_GE(max_encoded_bytes, full_frame_samples_); 95 CHECK_GE(max_encoded_bytes, full_frame_samples_);
95 EncodedInfo info; 96 EncodedInfo info;
96 info.encoded_timestamp = first_timestamp_in_buffer_; 97 info.encoded_timestamp = first_timestamp_in_buffer_;
97 info.payload_type = payload_type_; 98 info.payload_type = payload_type_;
98 int16_t ret = EncodeCall(&speech_buffer_[0], full_frame_samples_, encoded); 99 info.encoded_bytes =
99 CHECK_GE(ret, 0); 100 EncodeCall(&speech_buffer_[0], full_frame_samples_, encoded);
100 info.encoded_bytes = static_cast<size_t>(ret);
101 speech_buffer_.clear(); 101 speech_buffer_.clear();
102 return info; 102 return info;
103 } 103 }
104 104
105 int16_t AudioEncoderPcmA::EncodeCall(const int16_t* audio, 105 size_t AudioEncoderPcmA::EncodeCall(const int16_t* audio,
106 size_t input_len, 106 size_t input_len,
107 uint8_t* encoded) { 107 uint8_t* encoded) {
108 return WebRtcG711_EncodeA(audio, static_cast<int16_t>(input_len), encoded); 108 return WebRtcG711_EncodeA(audio, input_len, encoded);
109 } 109 }
110 110
111 int AudioEncoderPcmA::BytesPerSample() const { 111 int AudioEncoderPcmA::BytesPerSample() const {
112 return 1; 112 return 1;
113 } 113 }
114 114
115 int16_t AudioEncoderPcmU::EncodeCall(const int16_t* audio, 115 size_t AudioEncoderPcmU::EncodeCall(const int16_t* audio,
116 size_t input_len, 116 size_t input_len,
117 uint8_t* encoded) { 117 uint8_t* encoded) {
118 return WebRtcG711_EncodeU(audio, static_cast<int16_t>(input_len), encoded); 118 return WebRtcG711_EncodeU(audio, input_len, encoded);
119 } 119 }
120 120
121 int AudioEncoderPcmU::BytesPerSample() const { 121 int AudioEncoderPcmU::BytesPerSample() const {
122 return 1; 122 return 1;
123 } 123 }
124 124
125 namespace { 125 namespace {
126 template <typename T> 126 template <typename T>
127 typename T::Config CreateConfig(const CodecInst& codec_inst) { 127 typename T::Config CreateConfig(const CodecInst& codec_inst) {
128 typename T::Config config; 128 typename T::Config config;
129 config.frame_size_ms = codec_inst.pacsize / 8; 129 config.frame_size_ms = codec_inst.pacsize / 8;
130 config.num_channels = codec_inst.channels; 130 config.num_channels = codec_inst.channels;
131 config.payload_type = codec_inst.pltype; 131 config.payload_type = codec_inst.pltype;
132 return config; 132 return config;
133 } 133 }
134 } // namespace 134 } // namespace
135 135
136 AudioEncoderMutablePcmU::AudioEncoderMutablePcmU(const CodecInst& codec_inst) 136 AudioEncoderMutablePcmU::AudioEncoderMutablePcmU(const CodecInst& codec_inst)
137 : AudioEncoderMutableImpl<AudioEncoderPcmU>( 137 : AudioEncoderMutableImpl<AudioEncoderPcmU>(
138 CreateConfig<AudioEncoderPcmU>(codec_inst)) { 138 CreateConfig<AudioEncoderPcmU>(codec_inst)) {
139 } 139 }
140 140
141 AudioEncoderMutablePcmA::AudioEncoderMutablePcmA(const CodecInst& codec_inst) 141 AudioEncoderMutablePcmA::AudioEncoderMutablePcmA(const CodecInst& codec_inst)
142 : AudioEncoderMutableImpl<AudioEncoderPcmA>( 142 : AudioEncoderMutableImpl<AudioEncoderPcmA>(
143 CreateConfig<AudioEncoderPcmA>(codec_inst)) { 143 CreateConfig<AudioEncoderPcmA>(codec_inst)) {
144 } 144 }
145 145
146 } // namespace webrtc 146 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/codecs/cng/webrtc_cng.c ('k') | webrtc/modules/audio_coding/codecs/g711/g711_interface.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698