Update {virtual,override} to follow C++11 style in pdf.
[chromium-blink-merge.git] / components / audio_modem / audio_recorder_impl.h
blobd5f567f0eff086dfecb00017bdf7fae32043458b
1 // Copyright 2015 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 COMPONENTS_AUDIO_MODEM_AUDIO_RECORDER_IMPL_H_
6 #define COMPONENTS_AUDIO_MODEM_AUDIO_RECORDER_IMPL_H_
8 #include <string>
10 #include "base/gtest_prod_util.h"
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "components/audio_modem/audio_recorder.h"
14 #include "media/audio/audio_io.h"
15 #include "media/audio/audio_parameters.h"
17 namespace base {
18 class MessageLoop;
21 namespace media {
22 class AudioBus;
25 namespace audio_modem {
27 // The AudioRecorder class will record audio until told to stop.
28 class AudioRecorderImpl final
29 : public AudioRecorder,
30 public media::AudioInputStream::AudioInputCallback {
31 public:
32 using RecordedSamplesCallback = base::Callback<void(const std::string&)>;
34 AudioRecorderImpl();
36 // AudioRecorder overrides:
37 void Initialize(const RecordedSamplesCallback& decode_callback) override;
38 void Record() override;
39 void Stop() override;
40 void Finalize() override;
42 // Takes ownership of the stream.
43 void set_input_stream_for_testing(
44 media::AudioInputStream* input_stream_for_testing) {
45 input_stream_for_testing_.reset(input_stream_for_testing);
48 // Takes ownership of the params.
49 void set_params_for_testing(media::AudioParameters* params_for_testing) {
50 params_for_testing_.reset(params_for_testing);
53 protected:
54 ~AudioRecorderImpl() override;
55 void set_is_recording(bool is_recording) { is_recording_ = is_recording; }
57 private:
58 friend class AudioRecorderTest;
59 FRIEND_TEST_ALL_PREFIXES(AudioRecorderTest, BasicRecordAndStop);
60 FRIEND_TEST_ALL_PREFIXES(AudioRecorderTest, OutOfOrderRecordAndStopMultiple);
62 // Methods to do our various operations; all of these need to be run on the
63 // audio thread.
64 void InitializeOnAudioThread();
65 void RecordOnAudioThread();
66 void StopOnAudioThread();
67 void StopAndCloseOnAudioThread();
68 void FinalizeOnAudioThread();
70 // AudioInputStream::AudioInputCallback overrides:
71 // Called by the audio recorder when a full packet of audio data is
72 // available. This is called from a special audio thread and the
73 // implementation should return as soon as possible.
74 void OnData(media::AudioInputStream* stream,
75 const media::AudioBus* source,
76 uint32 hardware_delay_bytes,
77 double volume) override;
78 void OnError(media::AudioInputStream* stream) override;
80 // Flushes the audio loop, making sure that any queued operations are
81 // performed.
82 void FlushAudioLoopForTesting();
84 bool is_recording_;
86 media::AudioInputStream* stream_;
88 RecordedSamplesCallback decode_callback_;
90 // Outside of the ctor/Initialize method, only access the next variables on
91 // the recording thread.
92 scoped_ptr<media::AudioBus> buffer_;
93 int total_buffer_frames_;
94 int buffer_frame_index_;
96 scoped_ptr<media::AudioInputStream> input_stream_for_testing_;
97 scoped_ptr<media::AudioParameters> params_for_testing_;
99 DISALLOW_COPY_AND_ASSIGN(AudioRecorderImpl);
102 } // namespace audio_modem
104 #endif // COMPONENTS_AUDIO_MODEM_AUDIO_RECORDER_IMPL_H_