Introduced SpeechRecognitionDispatcher(Host) classes, handling dispatch of IPC messag...
[chromium-blink-merge.git] / content / browser / speech / audio_encoder.h
blob943628e5aa748da2569e460fe49e90c09bb06f45
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_
7 #pragma once
9 #include <list>
10 #include <string>
12 #include "base/basictypes.h"
13 #include "base/memory/ref_counted.h"
14 #include "content/browser/speech/audio_buffer.h"
16 namespace speech {
17 class AudioChunk;
18 // Provides a simple interface to encode raw audio using the various speech
19 // codecs.
20 class AudioEncoder {
21 public:
22 enum Codec {
23 CODEC_FLAC,
24 CODEC_SPEEX,
27 static AudioEncoder* Create(Codec codec,
28 int sampling_rate,
29 int bits_per_sample);
31 virtual ~AudioEncoder();
33 // Encodes |raw audio| to the internal buffer. Use
34 // |GetEncodedDataAndClear| to read the result after this call or when
35 // audio capture completes.
36 virtual void Encode(const AudioChunk& raw_audio) = 0;
38 // Finish encoding and flush any pending encoded bits out.
39 virtual void Flush() = 0;
41 // Merges, retrieves and clears all the accumulated encoded audio chunks.
42 scoped_refptr<AudioChunk> GetEncodedDataAndClear();
44 const std::string& mime_type() { return mime_type_; }
45 int bits_per_sample() { return bits_per_sample_; }
47 protected:
48 AudioEncoder(const std::string& mime_type, int bits_per_sample);
49 AudioBuffer encoded_audio_buffer_;
51 private:
52 std::string mime_type_;
53 int bits_per_sample_;
55 DISALLOW_COPY_AND_ASSIGN(AudioEncoder);
58 } // namespace speech
60 #endif // CONTENT_BROWSER_SPEECH_AUDIO_ENCODER_H_