OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2014 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. | |
4 | |
5 #ifndef COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_RECORDER_ | |
6 #define COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_RECORDER_ | |
7 | |
8 #include "base/gtest_prod_util.h" | |
9 #include "base/macros.h" | |
10 #include "base/memory/scoped_ptr.h" | |
11 #include "media/audio/audio_io.h" | |
12 #include "media/audio/audio_parameters.h" | |
13 #include "media/base/audio_converter.h" | |
14 | |
15 namespace base { | |
16 class MessageLoop; | |
17 } | |
18 | |
19 namespace media { | |
20 class AudioBus; | |
21 } | |
22 | |
23 namespace copresence { | |
24 | |
25 // The AudioRecorder class will record audio until told to stop. | |
26 class AudioRecorder : public media::AudioInputStream::AudioInputCallback, | |
27 public media::AudioConverter::InputCallback { | |
28 public: | |
29 typedef base::Callback<void(const std::string&)> DecodeSamplesCallback; | |
30 | |
31 explicit AudioRecorder(const DecodeSamplesCallback& decode_callback); | |
32 | |
33 // This constructor is only for testing. | |
34 AudioRecorder(const DecodeSamplesCallback& decode_callback, | |
Daniel Erat
2014/07/28 21:18:19
could this also be removed in favor of e.g. set_in
rkc
2014/07/29 00:33:36
Done.
| |
35 media::AudioInputStream* input_stream_for_testing, | |
36 scoped_ptr<media::AudioParameters> params_for_testing); | |
37 | |
38 void Record(); | |
39 void Stop(); | |
40 | |
41 // Cleans up and deletes this object. Do not use object after this call. | |
42 void Finalize(); | |
43 | |
44 private: | |
45 friend class AudioRecorderTest; | |
46 FRIEND_TEST_ALL_PREFIXES(AudioRecorderTest, BasicRecordAndStop); | |
47 FRIEND_TEST_ALL_PREFIXES(AudioRecorderTest, OutOfOrderRecordAndStopMultiple); | |
48 | |
49 virtual ~AudioRecorder(); | |
50 | |
51 // Methods to do our various operations; all of these need to be run on the | |
52 // audio thread. | |
53 void InitializeOnAudioThread(); | |
54 void RecordOnAudioThread(); | |
55 void StopOnAudioThread(); | |
56 void StopAndCloseOnAudioThread(); | |
57 void FinalizeOnAudioThread(); | |
58 | |
59 // AudioInputStream::AudioInputCallback overrides: | |
60 // Called by the audio recorder when a full packet of audio data is | |
61 // available. This is called from a special audio thread and the | |
62 // implementation should return as soon as possible. | |
63 virtual void OnData(media::AudioInputStream* stream, | |
64 const media::AudioBus* source, | |
65 uint32 hardware_delay_bytes, | |
66 double volume) OVERRIDE; | |
67 virtual void OnError(media::AudioInputStream* stream) OVERRIDE; | |
68 | |
69 // AudioConverter::InputCallback overrides: | |
70 virtual double ProvideInput(media::AudioBus* dest, | |
71 base::TimeDelta buffer_delay) OVERRIDE; | |
72 | |
73 // This is used by unit tests, do NOT use in production code. | |
74 bool IsRecording(); | |
Daniel Erat
2014/07/28 21:18:18
IsRecordingForTesting() or IsRecordingForTest() (c
rkc
2014/07/29 00:33:36
This is all gone; replaced this with FlushAudioLoo
| |
75 | |
76 media::AudioInputStream* stream_; | |
77 bool is_recording_; | |
78 DecodeSamplesCallback decode_callback_; | |
79 | |
80 // ProvideInput will use this buffer as its source. | |
81 const media::AudioBus* temp_conversion_buffer_; | |
82 | |
83 // Past the initialization, only access the next variables on | |
Daniel Erat
2014/07/28 21:18:18
nit: s/Past the initialization/Outside of the cons
rkc
2014/07/29 00:33:36
Done.
| |
84 // the recording thread. | |
85 scoped_ptr<media::AudioBus> buffer_; | |
86 int total_buffer_frames_; | |
87 int buffer_frame_index_; | |
88 | |
89 scoped_ptr<media::AudioConverter> converter_; | |
90 | |
91 media::AudioInputStream* input_stream_for_testing_; | |
92 scoped_ptr<media::AudioParameters> params_for_testing_; | |
93 | |
94 DISALLOW_COPY_AND_ASSIGN(AudioRecorder); | |
95 }; | |
96 | |
97 } // namespace copresence | |
98 | |
99 #endif // COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_RECORDER_ | |
OLD | NEW |