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

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

Issue 1322973004: Fold AudioEncoderMutable into AudioEncoder (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: review fixes & stuff 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
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 AudioEncoderIlbc::Config CreateConfig(const CodecInst& codec_inst) {
26 AudioEncoderIlbc::Config config;
27 config.frame_size_ms = codec_inst.pacsize / 8;
28 config.payload_type = codec_inst.pltype;
29 return config;
30 }
31
25 } // namespace 32 } // namespace
26 33
27 // static 34 // static
28 const size_t AudioEncoderIlbc::kMaxSamplesPerPacket; 35 const size_t AudioEncoderIlbc::kMaxSamplesPerPacket;
29 36
30 bool AudioEncoderIlbc::Config::IsOk() const { 37 bool AudioEncoderIlbc::Config::IsOk() const {
31 return (frame_size_ms == 20 || frame_size_ms == 30 || frame_size_ms == 40 || 38 return (frame_size_ms == 20 || frame_size_ms == 30 || frame_size_ms == 40 ||
32 frame_size_ms == 60) && 39 frame_size_ms == 60) &&
33 static_cast<size_t>(kSampleRateHz / 100 * (frame_size_ms / 10)) <= 40 static_cast<size_t>(kSampleRateHz / 100 * (frame_size_ms / 10)) <=
34 kMaxSamplesPerPacket; 41 kMaxSamplesPerPacket;
35 } 42 }
36 43
37 AudioEncoderIlbc::AudioEncoderIlbc(const Config& config) 44 AudioEncoderIlbc::AudioEncoderIlbc(const Config& config)
38 : payload_type_(config.payload_type), 45 : num_10ms_frames_per_packet_(config.frame_size_ms / 10),
hlundin-webrtc 2015/09/07 20:00:01 Why is cast gone?
kwiberg-webrtc 2015/09/08 10:47:45 It got lost in the rebase. Fixed now.
39 num_10ms_frames_per_packet_( 46 config_(config),
40 static_cast<size_t>(config.frame_size_ms / 10)), 47 encoder_(nullptr) {
41 num_10ms_frames_buffered_(0) { 48 Reset();
42 CHECK(config.IsOk());
43 CHECK_EQ(0, WebRtcIlbcfix_EncoderCreate(&encoder_));
44 const int encoder_frame_size_ms = config.frame_size_ms > 30
45 ? config.frame_size_ms / 2
46 : config.frame_size_ms;
47 CHECK_EQ(0, WebRtcIlbcfix_EncoderInit(encoder_, encoder_frame_size_ms));
48 } 49 }
49 50
51 AudioEncoderIlbc::AudioEncoderIlbc(const CodecInst& codec_inst)
52 : AudioEncoderIlbc(CreateConfig(codec_inst)) {}
53
50 AudioEncoderIlbc::~AudioEncoderIlbc() { 54 AudioEncoderIlbc::~AudioEncoderIlbc() {
51 CHECK_EQ(0, WebRtcIlbcfix_EncoderFree(encoder_)); 55 CHECK_EQ(0, WebRtcIlbcfix_EncoderFree(encoder_));
52 } 56 }
53 57
58 size_t AudioEncoderIlbc::MaxEncodedBytes() const {
59 return RequiredOutputSizeBytes();
60 }
61
54 int AudioEncoderIlbc::SampleRateHz() const { 62 int AudioEncoderIlbc::SampleRateHz() const {
55 return kSampleRateHz; 63 return kSampleRateHz;
56 } 64 }
57 65
58 int AudioEncoderIlbc::NumChannels() const { 66 int AudioEncoderIlbc::NumChannels() const {
59 return 1; 67 return 1;
60 } 68 }
61 69
62 size_t AudioEncoderIlbc::MaxEncodedBytes() const {
63 return RequiredOutputSizeBytes();
64 }
65
66 size_t AudioEncoderIlbc::Num10MsFramesInNextPacket() const { 70 size_t AudioEncoderIlbc::Num10MsFramesInNextPacket() const {
67 return num_10ms_frames_per_packet_; 71 return num_10ms_frames_per_packet_;
68 } 72 }
69 73
70 size_t AudioEncoderIlbc::Max10MsFramesInAPacket() const { 74 size_t AudioEncoderIlbc::Max10MsFramesInAPacket() const {
71 return num_10ms_frames_per_packet_; 75 return num_10ms_frames_per_packet_;
72 } 76 }
73 77
74 int AudioEncoderIlbc::GetTargetBitrate() const { 78 int AudioEncoderIlbc::GetTargetBitrate() const {
75 switch (num_10ms_frames_per_packet_) { 79 switch (num_10ms_frames_per_packet_) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 const int output_len = WebRtcIlbcfix_Encode( 116 const int output_len = WebRtcIlbcfix_Encode(
113 encoder_, 117 encoder_,
114 input_buffer_, 118 input_buffer_,
115 kSampleRateHz / 100 * num_10ms_frames_per_packet_, 119 kSampleRateHz / 100 * num_10ms_frames_per_packet_,
116 encoded); 120 encoded);
117 CHECK_GE(output_len, 0); 121 CHECK_GE(output_len, 0);
118 EncodedInfo info; 122 EncodedInfo info;
119 info.encoded_bytes = static_cast<size_t>(output_len); 123 info.encoded_bytes = static_cast<size_t>(output_len);
120 DCHECK_EQ(info.encoded_bytes, RequiredOutputSizeBytes()); 124 DCHECK_EQ(info.encoded_bytes, RequiredOutputSizeBytes());
121 info.encoded_timestamp = first_timestamp_in_buffer_; 125 info.encoded_timestamp = first_timestamp_in_buffer_;
122 info.payload_type = payload_type_; 126 info.payload_type = config_.payload_type;
123 return info; 127 return info;
124 } 128 }
125 129
130 void AudioEncoderIlbc::Reset() {
131 if (encoder_)
132 CHECK_EQ(0, WebRtcIlbcfix_EncoderFree(encoder_));
133 CHECK(config_.IsOk());
134 CHECK_EQ(0, WebRtcIlbcfix_EncoderCreate(&encoder_));
135 const int encoder_frame_size_ms = config_.frame_size_ms > 30
136 ? config_.frame_size_ms / 2
137 : config_.frame_size_ms;
138 CHECK_EQ(0, WebRtcIlbcfix_EncoderInit(encoder_, encoder_frame_size_ms));
139 num_10ms_frames_buffered_ = 0;
140 }
141
126 size_t AudioEncoderIlbc::RequiredOutputSizeBytes() const { 142 size_t AudioEncoderIlbc::RequiredOutputSizeBytes() const {
127 switch (num_10ms_frames_per_packet_) { 143 switch (num_10ms_frames_per_packet_) {
128 case 2: return 38; 144 case 2: return 38;
129 case 3: return 50; 145 case 3: return 50;
130 case 4: return 2 * 38; 146 case 4: return 2 * 38;
131 case 6: return 2 * 50; 147 case 6: return 2 * 50;
132 default: FATAL(); 148 default: FATAL();
133 } 149 }
134 } 150 }
135 151
136 namespace {
137 AudioEncoderIlbc::Config CreateConfig(const CodecInst& codec_inst) {
138 AudioEncoderIlbc::Config config;
139 config.frame_size_ms = codec_inst.pacsize / 8;
140 config.payload_type = codec_inst.pltype;
141 return config;
142 }
143 } // namespace
144
145 AudioEncoderMutableIlbc::AudioEncoderMutableIlbc(const CodecInst& codec_inst)
146 : AudioEncoderMutableImpl<AudioEncoderIlbc>(CreateConfig(codec_inst)) {
147 }
148
149 } // namespace webrtc 152 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698