Chromium Code Reviews| 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 |
| 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 size_t kSampleRateHz = 8000; |
|
kwiberg-webrtc
2015/08/11 09:33:21
It seems wrong to use size_t for sample rates. It'
Peter Kasting
2015/08/14 00:56:09
I agree, I'm not sure why I changed this. Fixed.
| |
| 24 | 24 |
| 25 } // namespace | 25 } // namespace |
| 26 | 26 |
| 27 // static | |
| 28 const size_t AudioEncoderIlbc::kMaxSamplesPerPacket; | |
|
Peter Kasting
2015/07/23 19:17:04
Changing the type of this from int to size_t means
kwiberg-webrtc
2015/08/11 09:33:21
Acknowledged.
| |
| 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 (kSampleRateHz / 100 * (frame_size_ms / 10)) <= kMaxSamplesPerPacket; |
| 31 } | 34 } |
| 32 | 35 |
| 33 AudioEncoderIlbc::AudioEncoderIlbc(const Config& config) | 36 AudioEncoderIlbc::AudioEncoderIlbc(const Config& config) |
| 34 : payload_type_(config.payload_type), | 37 : payload_type_(config.payload_type), |
| 35 num_10ms_frames_per_packet_(config.frame_size_ms / 10), | 38 num_10ms_frames_per_packet_( |
| 39 static_cast<size_t>(config.frame_size_ms / 10)), | |
| 36 num_10ms_frames_buffered_(0) { | 40 num_10ms_frames_buffered_(0) { |
| 37 CHECK(config.IsOk()); | 41 CHECK(config.IsOk()); |
| 38 CHECK_EQ(0, WebRtcIlbcfix_EncoderCreate(&encoder_)); | 42 CHECK_EQ(0, WebRtcIlbcfix_EncoderCreate(&encoder_)); |
| 39 const int encoder_frame_size_ms = config.frame_size_ms > 30 | 43 const int encoder_frame_size_ms = config.frame_size_ms > 30 |
| 40 ? config.frame_size_ms / 2 | 44 ? config.frame_size_ms / 2 |
| 41 : config.frame_size_ms; | 45 : config.frame_size_ms; |
| 42 CHECK_EQ(0, WebRtcIlbcfix_EncoderInit(encoder_, encoder_frame_size_ms)); | 46 CHECK_EQ(0, WebRtcIlbcfix_EncoderInit(encoder_, encoder_frame_size_ms)); |
| 43 } | 47 } |
| 44 | 48 |
| 45 AudioEncoderIlbc::~AudioEncoderIlbc() { | 49 AudioEncoderIlbc::~AudioEncoderIlbc() { |
| 46 CHECK_EQ(0, WebRtcIlbcfix_EncoderFree(encoder_)); | 50 CHECK_EQ(0, WebRtcIlbcfix_EncoderFree(encoder_)); |
| 47 } | 51 } |
| 48 | 52 |
| 49 int AudioEncoderIlbc::SampleRateHz() const { | 53 int AudioEncoderIlbc::SampleRateHz() const { |
| 50 return kSampleRateHz; | 54 return kSampleRateHz; |
| 51 } | 55 } |
| 52 | 56 |
| 53 int AudioEncoderIlbc::NumChannels() const { | 57 int AudioEncoderIlbc::NumChannels() const { |
| 54 return 1; | 58 return 1; |
| 55 } | 59 } |
| 56 | 60 |
| 57 size_t AudioEncoderIlbc::MaxEncodedBytes() const { | 61 size_t AudioEncoderIlbc::MaxEncodedBytes() const { |
| 58 return RequiredOutputSizeBytes(); | 62 return RequiredOutputSizeBytes(); |
| 59 } | 63 } |
| 60 | 64 |
| 61 int AudioEncoderIlbc::Num10MsFramesInNextPacket() const { | 65 size_t AudioEncoderIlbc::Num10MsFramesInNextPacket() const { |
| 62 return num_10ms_frames_per_packet_; | 66 return num_10ms_frames_per_packet_; |
| 63 } | 67 } |
| 64 | 68 |
| 65 int AudioEncoderIlbc::Max10MsFramesInAPacket() const { | 69 size_t AudioEncoderIlbc::Max10MsFramesInAPacket() const { |
| 66 return num_10ms_frames_per_packet_; | 70 return num_10ms_frames_per_packet_; |
| 67 } | 71 } |
| 68 | 72 |
| 69 int AudioEncoderIlbc::GetTargetBitrate() const { | 73 int AudioEncoderIlbc::GetTargetBitrate() const { |
| 70 switch (num_10ms_frames_per_packet_) { | 74 switch (num_10ms_frames_per_packet_) { |
| 71 case 2: case 4: | 75 case 2: case 4: |
| 72 // 38 bytes per frame of 20 ms => 15200 bits/s. | 76 // 38 bytes per frame of 20 ms => 15200 bits/s. |
| 73 return 15200; | 77 return 15200; |
| 74 case 3: case 6: | 78 case 3: case 6: |
| 75 // 50 bytes per frame of 30 ms => (approx) 13333 bits/s. | 79 // 50 bytes per frame of 30 ms => (approx) 13333 bits/s. |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 104 // Encode buffered input. | 108 // Encode buffered input. |
| 105 DCHECK_EQ(num_10ms_frames_buffered_, num_10ms_frames_per_packet_); | 109 DCHECK_EQ(num_10ms_frames_buffered_, num_10ms_frames_per_packet_); |
| 106 num_10ms_frames_buffered_ = 0; | 110 num_10ms_frames_buffered_ = 0; |
| 107 const int output_len = WebRtcIlbcfix_Encode( | 111 const int output_len = WebRtcIlbcfix_Encode( |
| 108 encoder_, | 112 encoder_, |
| 109 input_buffer_, | 113 input_buffer_, |
| 110 kSampleRateHz / 100 * num_10ms_frames_per_packet_, | 114 kSampleRateHz / 100 * num_10ms_frames_per_packet_, |
| 111 encoded); | 115 encoded); |
| 112 CHECK_GE(output_len, 0); | 116 CHECK_GE(output_len, 0); |
| 113 EncodedInfo info; | 117 EncodedInfo info; |
| 114 info.encoded_bytes = output_len; | 118 info.encoded_bytes = static_cast<size_t>(output_len); |
| 115 DCHECK_EQ(info.encoded_bytes, RequiredOutputSizeBytes()); | 119 DCHECK_EQ(info.encoded_bytes, RequiredOutputSizeBytes()); |
| 116 info.encoded_timestamp = first_timestamp_in_buffer_; | 120 info.encoded_timestamp = first_timestamp_in_buffer_; |
| 117 info.payload_type = payload_type_; | 121 info.payload_type = payload_type_; |
| 118 return info; | 122 return info; |
| 119 } | 123 } |
| 120 | 124 |
| 121 size_t AudioEncoderIlbc::RequiredOutputSizeBytes() const { | 125 size_t AudioEncoderIlbc::RequiredOutputSizeBytes() const { |
| 122 switch (num_10ms_frames_per_packet_) { | 126 switch (num_10ms_frames_per_packet_) { |
| 123 case 2: return 38; | 127 case 2: return 38; |
| 124 case 3: return 50; | 128 case 3: return 50; |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 135 config.payload_type = codec_inst.pltype; | 139 config.payload_type = codec_inst.pltype; |
| 136 return config; | 140 return config; |
| 137 } | 141 } |
| 138 } // namespace | 142 } // namespace |
| 139 | 143 |
| 140 AudioEncoderMutableIlbc::AudioEncoderMutableIlbc(const CodecInst& codec_inst) | 144 AudioEncoderMutableIlbc::AudioEncoderMutableIlbc(const CodecInst& codec_inst) |
| 141 : AudioEncoderMutableImpl<AudioEncoderIlbc>(CreateConfig(codec_inst)) { | 145 : AudioEncoderMutableImpl<AudioEncoderIlbc>(CreateConfig(codec_inst)) { |
| 142 } | 146 } |
| 143 | 147 |
| 144 } // namespace webrtc | 148 } // namespace webrtc |
| OLD | NEW |