OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/speech/audio_encoder.h" | 5 #include "content/browser/speech/audio_encoder.h" |
6 | 6 |
7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 const char* const kContentTypeSpeex = "audio/x-speex-with-header-byte; rate="; | 105 const char* const kContentTypeSpeex = "audio/x-speex-with-header-byte; rate="; |
106 const int kSpeexEncodingQuality = 8; | 106 const int kSpeexEncodingQuality = 8; |
107 const int kMaxSpeexFrameLength = 110; // (44kbps rate sampled at 32kHz). | 107 const int kMaxSpeexFrameLength = 110; // (44kbps rate sampled at 32kHz). |
108 | 108 |
109 // Since the frame length gets written out as a byte in the encoded packet, | 109 // Since the frame length gets written out as a byte in the encoded packet, |
110 // make sure it is within the byte range. | 110 // make sure it is within the byte range. |
111 COMPILE_ASSERT(kMaxSpeexFrameLength <= 0xFF, invalidLength); | 111 COMPILE_ASSERT(kMaxSpeexFrameLength <= 0xFF, invalidLength); |
112 | 112 |
113 class SpeexEncoder : public AudioEncoder { | 113 class SpeexEncoder : public AudioEncoder { |
114 public: | 114 public: |
115 explicit SpeexEncoder(int sampling_rate, int bits_per_sample); | 115 SpeexEncoder(int sampling_rate, int bits_per_sample); |
116 virtual ~SpeexEncoder(); | 116 virtual ~SpeexEncoder(); |
117 virtual void Encode(const AudioChunk& raw_audio) OVERRIDE; | 117 virtual void Encode(const AudioChunk& raw_audio) OVERRIDE; |
118 virtual void Flush() OVERRIDE {} | 118 virtual void Flush() OVERRIDE {} |
119 | 119 |
120 private: | 120 private: |
121 void* encoder_state_; | 121 void* encoder_state_; |
122 SpeexBits bits_; | 122 SpeexBits bits_; |
123 int samples_per_frame_; | 123 int samples_per_frame_; |
124 char encoded_frame_data_[kMaxSpeexFrameLength + 1]; // +1 for the frame size. | 124 char encoded_frame_data_[kMaxSpeexFrameLength + 1]; // +1 for the frame size. |
125 DISALLOW_COPY_AND_ASSIGN(SpeexEncoder); | 125 DISALLOW_COPY_AND_ASSIGN(SpeexEncoder); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 } | 185 } |
186 | 186 |
187 AudioEncoder::~AudioEncoder() { | 187 AudioEncoder::~AudioEncoder() { |
188 } | 188 } |
189 | 189 |
190 scoped_refptr<AudioChunk> AudioEncoder::GetEncodedDataAndClear() { | 190 scoped_refptr<AudioChunk> AudioEncoder::GetEncodedDataAndClear() { |
191 return encoded_audio_buffer_.DequeueAll(); | 191 return encoded_audio_buffer_.DequeueAll(); |
192 } | 192 } |
193 | 193 |
194 } // namespace content | 194 } // namespace content |
OLD | NEW |