[refactor] More post-NSS WebCrypto cleanups (utility functions).
[chromium-blink-merge.git] / content / browser / speech / audio_encoder.h
blob7e59c08ea50b2650f5a9a1f9d16463860f93ff85
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_SPEECH_AUDIO_ENCODER_H_
6 #define CONTENT_BROWSER_SPEECH_AUDIO_ENCODER_H_
8 #include <string>
10 #include "base/macros.h"
11 #include "base/memory/ref_counted.h"
12 #include "content/browser/speech/audio_buffer.h"
13 #include "third_party/flac/include/FLAC/stream_encoder.h"
15 namespace content{
16 class AudioChunk;
18 // Provides a simple interface to encode raw audio using FLAC codec.
19 class AudioEncoder {
20 public:
21 AudioEncoder(int sampling_rate, int bits_per_sample);
22 ~AudioEncoder();
24 // Encodes |raw audio| to the internal buffer. Use
25 // |GetEncodedDataAndClear| to read the result after this call or when
26 // audio capture completes.
27 void Encode(const AudioChunk& raw_audio);
29 // Finish encoding and flush any pending encoded bits out.
30 void Flush();
32 // Merges, retrieves and clears all the accumulated encoded audio chunks.
33 scoped_refptr<AudioChunk> GetEncodedDataAndClear();
35 std::string GetMimeType();
36 int GetBitsPerSample();
38 private:
39 AudioBuffer encoded_audio_buffer_;
41 FLAC__StreamEncoder* encoder_;
42 bool is_encoder_initialized_;
44 DISALLOW_COPY_AND_ASSIGN(AudioEncoder);
47 } // namespace content
49 #endif // CONTENT_BROWSER_SPEECH_AUDIO_ENCODER_H_