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

Side by Side Diff: webrtc/modules/audio_coding/codecs/ilbc/audio_encoder_ilbc.cc

Issue 1230693002: Update audio code to use size_t more correctly, (Closed) Base URL: https://chromium.googlesource.com/external/webrtc@master
Patch Set: Review comments Created 5 years, 4 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
11 #include "webrtc/modules/audio_coding/codecs/ilbc/interface/audio_encoder_ilbc.h " 11 #include "webrtc/modules/audio_coding/codecs/ilbc/interface/audio_encoder_ilbc.h "
12 12
13 #include <cstring> 13 #include <cstring>
14 #include <limits> 14 #include <limits>
15 #include "webrtc/base/checks.h" 15 #include "webrtc/base/checks.h"
16 #include "webrtc/common_types.h" 16 #include "webrtc/common_types.h"
17 #include "webrtc/modules/audio_coding/codecs/ilbc/interface/ilbc.h" 17 #include "webrtc/modules/audio_coding/codecs/ilbc/interface/ilbc.h"
18 18
19 namespace webrtc { 19 namespace webrtc {
20 20
21 namespace { 21 namespace {
22 22
23 const int kSampleRateHz = 8000; 23 const int kSampleRateHz = 8000;
24 24
25 } // namespace 25 } // namespace
26 26
27 // static
28 const size_t AudioEncoderIlbc::kMaxSamplesPerPacket;
29
27 bool AudioEncoderIlbc::Config::IsOk() const { 30 bool AudioEncoderIlbc::Config::IsOk() const {
28 return (frame_size_ms == 20 || frame_size_ms == 30 || frame_size_ms == 40 || 31 return (frame_size_ms == 20 || frame_size_ms == 30 || frame_size_ms == 40 ||
29 frame_size_ms == 60) && 32 frame_size_ms == 60) &&
30 (kSampleRateHz / 100 * (frame_size_ms / 10)) <= kMaxSamplesPerPacket; 33 static_cast<size_t>(kSampleRateHz / 100 * (frame_size_ms / 10)) <=
34 kMaxSamplesPerPacket;
31 } 35 }
32 36
33 AudioEncoderIlbc::AudioEncoderIlbc(const Config& config) 37 AudioEncoderIlbc::AudioEncoderIlbc(const Config& config)
34 : payload_type_(config.payload_type), 38 : payload_type_(config.payload_type),
35 num_10ms_frames_per_packet_(config.frame_size_ms / 10), 39 num_10ms_frames_per_packet_(
40 static_cast<size_t>(config.frame_size_ms / 10)),
36 num_10ms_frames_buffered_(0) { 41 num_10ms_frames_buffered_(0) {
37 CHECK(config.IsOk()); 42 CHECK(config.IsOk());
38 CHECK_EQ(0, WebRtcIlbcfix_EncoderCreate(&encoder_)); 43 CHECK_EQ(0, WebRtcIlbcfix_EncoderCreate(&encoder_));
39 const int encoder_frame_size_ms = config.frame_size_ms > 30 44 const int encoder_frame_size_ms = config.frame_size_ms > 30
40 ? config.frame_size_ms / 2 45 ? config.frame_size_ms / 2
41 : config.frame_size_ms; 46 : config.frame_size_ms;
42 CHECK_EQ(0, WebRtcIlbcfix_EncoderInit(encoder_, encoder_frame_size_ms)); 47 CHECK_EQ(0, WebRtcIlbcfix_EncoderInit(encoder_, encoder_frame_size_ms));
43 } 48 }
44 49
45 AudioEncoderIlbc::~AudioEncoderIlbc() { 50 AudioEncoderIlbc::~AudioEncoderIlbc() {
46 CHECK_EQ(0, WebRtcIlbcfix_EncoderFree(encoder_)); 51 CHECK_EQ(0, WebRtcIlbcfix_EncoderFree(encoder_));
47 } 52 }
48 53
49 int AudioEncoderIlbc::SampleRateHz() const { 54 int AudioEncoderIlbc::SampleRateHz() const {
50 return kSampleRateHz; 55 return kSampleRateHz;
51 } 56 }
52 57
53 int AudioEncoderIlbc::NumChannels() const { 58 int AudioEncoderIlbc::NumChannels() const {
54 return 1; 59 return 1;
55 } 60 }
56 61
57 size_t AudioEncoderIlbc::MaxEncodedBytes() const { 62 size_t AudioEncoderIlbc::MaxEncodedBytes() const {
58 return RequiredOutputSizeBytes(); 63 return RequiredOutputSizeBytes();
59 } 64 }
60 65
61 int AudioEncoderIlbc::Num10MsFramesInNextPacket() const { 66 size_t AudioEncoderIlbc::Num10MsFramesInNextPacket() const {
62 return num_10ms_frames_per_packet_; 67 return num_10ms_frames_per_packet_;
63 } 68 }
64 69
65 int AudioEncoderIlbc::Max10MsFramesInAPacket() const { 70 size_t AudioEncoderIlbc::Max10MsFramesInAPacket() const {
66 return num_10ms_frames_per_packet_; 71 return num_10ms_frames_per_packet_;
67 } 72 }
68 73
69 int AudioEncoderIlbc::GetTargetBitrate() const { 74 int AudioEncoderIlbc::GetTargetBitrate() const {
70 switch (num_10ms_frames_per_packet_) { 75 switch (num_10ms_frames_per_packet_) {
71 case 2: case 4: 76 case 2: case 4:
72 // 38 bytes per frame of 20 ms => 15200 bits/s. 77 // 38 bytes per frame of 20 ms => 15200 bits/s.
73 return 15200; 78 return 15200;
74 case 3: case 6: 79 case 3: case 6:
75 // 50 bytes per frame of 30 ms => (approx) 13333 bits/s. 80 // 50 bytes per frame of 30 ms => (approx) 13333 bits/s.
(...skipping 28 matching lines...) Expand all
104 // Encode buffered input. 109 // Encode buffered input.
105 DCHECK_EQ(num_10ms_frames_buffered_, num_10ms_frames_per_packet_); 110 DCHECK_EQ(num_10ms_frames_buffered_, num_10ms_frames_per_packet_);
106 num_10ms_frames_buffered_ = 0; 111 num_10ms_frames_buffered_ = 0;
107 const int output_len = WebRtcIlbcfix_Encode( 112 const int output_len = WebRtcIlbcfix_Encode(
108 encoder_, 113 encoder_,
109 input_buffer_, 114 input_buffer_,
110 kSampleRateHz / 100 * num_10ms_frames_per_packet_, 115 kSampleRateHz / 100 * num_10ms_frames_per_packet_,
111 encoded); 116 encoded);
112 CHECK_GE(output_len, 0); 117 CHECK_GE(output_len, 0);
113 EncodedInfo info; 118 EncodedInfo info;
114 info.encoded_bytes = output_len; 119 info.encoded_bytes = static_cast<size_t>(output_len);
115 DCHECK_EQ(info.encoded_bytes, RequiredOutputSizeBytes()); 120 DCHECK_EQ(info.encoded_bytes, RequiredOutputSizeBytes());
116 info.encoded_timestamp = first_timestamp_in_buffer_; 121 info.encoded_timestamp = first_timestamp_in_buffer_;
117 info.payload_type = payload_type_; 122 info.payload_type = payload_type_;
118 return info; 123 return info;
119 } 124 }
120 125
121 size_t AudioEncoderIlbc::RequiredOutputSizeBytes() const { 126 size_t AudioEncoderIlbc::RequiredOutputSizeBytes() const {
122 switch (num_10ms_frames_per_packet_) { 127 switch (num_10ms_frames_per_packet_) {
123 case 2: return 38; 128 case 2: return 38;
124 case 3: return 50; 129 case 3: return 50;
(...skipping 10 matching lines...) Expand all
135 config.payload_type = codec_inst.pltype; 140 config.payload_type = codec_inst.pltype;
136 return config; 141 return config;
137 } 142 }
138 } // namespace 143 } // namespace
139 144
140 AudioEncoderMutableIlbc::AudioEncoderMutableIlbc(const CodecInst& codec_inst) 145 AudioEncoderMutableIlbc::AudioEncoderMutableIlbc(const CodecInst& codec_inst)
141 : AudioEncoderMutableImpl<AudioEncoderIlbc>(CreateConfig(codec_inst)) { 146 : AudioEncoderMutableImpl<AudioEncoderIlbc>(CreateConfig(codec_inst)) {
142 } 147 }
143 148
144 } // namespace webrtc 149 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_coding/codecs/ilbc/abs_quant_loop.c ('k') | webrtc/modules/audio_coding/codecs/ilbc/augmented_cb_corr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698