Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Side by Side Diff: components/copresence/mediums/audio/audio_recorder.h

Issue 461803003: Stop playing/recording when not needed. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 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 #ifndef COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_RECORDER_ 5 #ifndef COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_RECORDER_H_
6 #define COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_RECORDER_ 6 #define COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_RECORDER_H_
7 7
8 #include <string> 8 #include <string>
9 9
10 #include "base/gtest_prod_util.h" 10 #include "base/gtest_prod_util.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "media/audio/audio_io.h" 13 #include "media/audio/audio_io.h"
14 #include "media/audio/audio_parameters.h" 14 #include "media/audio/audio_parameters.h"
15 #include "media/base/audio_converter.h" 15 #include "media/base/audio_converter.h"
16 16
17 namespace base { 17 namespace base {
18 class MessageLoop; 18 class MessageLoop;
19 } 19 }
20 20
21 namespace media { 21 namespace media {
22 class AudioBus; 22 class AudioBus;
23 } 23 }
24 24
25 namespace copresence { 25 namespace copresence {
26 26
27 // The AudioRecorder class will record audio until told to stop. 27 // The AudioRecorder class will record audio until told to stop.
28 class AudioRecorder : public media::AudioInputStream::AudioInputCallback, 28 class AudioRecorder : public media::AudioInputStream::AudioInputCallback,
29 public media::AudioConverter::InputCallback { 29 public media::AudioConverter::InputCallback {
30 public: 30 public:
31 typedef base::Callback<void(const std::string&)> DecodeSamplesCallback; 31 typedef base::Callback<void(const std::string&)> DecodeSamplesCallback;
32 32
33 explicit AudioRecorder(const DecodeSamplesCallback& decode_callback); 33 explicit AudioRecorder(const DecodeSamplesCallback& decode_callback);
34 34
35 // Initializes the object. Do not use this object before calling this method. 35 // Initializes the object. Do not use this object before calling this method.
36 void Initialize(); 36 virtual void Initialize();
37 37
38 void Record(); 38 virtual void Record();
39 void Stop(); 39 virtual void Stop();
40
41 virtual bool IsRecording();
xiyuan 2014/08/12 18:57:51 ditto
rkc 2014/08/13 00:29:00 Done.
40 42
41 // Cleans up and deletes this object. Do not use object after this call. 43 // Cleans up and deletes this object. Do not use object after this call.
42 void Finalize(); 44 virtual void Finalize();
43 45
44 // Takes ownership of the stream. 46 // Takes ownership of the stream.
45 void set_input_stream_for_testing( 47 void set_input_stream_for_testing(
46 media::AudioInputStream* input_stream_for_testing) { 48 media::AudioInputStream* input_stream_for_testing) {
47 input_stream_for_testing_.reset(input_stream_for_testing); 49 input_stream_for_testing_.reset(input_stream_for_testing);
48 } 50 }
49 51
50 // Takes ownership of the params. 52 // Takes ownership of the params.
51 void set_params_for_testing(media::AudioParameters* params_for_testing) { 53 void set_params_for_testing(media::AudioParameters* params_for_testing) {
52 params_for_testing_.reset(params_for_testing); 54 params_for_testing_.reset(params_for_testing);
53 } 55 }
54 56
57 protected:
58 virtual ~AudioRecorder();
59
60 bool is_recording_;
xiyuan 2014/08/12 18:57:51 ditto
rkc 2014/08/13 00:29:00 Done.
61
55 private: 62 private:
56 friend class AudioRecorderTest; 63 friend class AudioRecorderTest;
57 FRIEND_TEST_ALL_PREFIXES(AudioRecorderTest, BasicRecordAndStop); 64 FRIEND_TEST_ALL_PREFIXES(AudioRecorderTest, BasicRecordAndStop);
58 FRIEND_TEST_ALL_PREFIXES(AudioRecorderTest, OutOfOrderRecordAndStopMultiple); 65 FRIEND_TEST_ALL_PREFIXES(AudioRecorderTest, OutOfOrderRecordAndStopMultiple);
59 66
60 virtual ~AudioRecorder();
61
62 // Methods to do our various operations; all of these need to be run on the 67 // Methods to do our various operations; all of these need to be run on the
63 // audio thread. 68 // audio thread.
64 void InitializeOnAudioThread(); 69 void InitializeOnAudioThread();
65 void RecordOnAudioThread(); 70 void RecordOnAudioThread();
66 void StopOnAudioThread(); 71 void StopOnAudioThread();
67 void StopAndCloseOnAudioThread(); 72 void StopAndCloseOnAudioThread();
68 void FinalizeOnAudioThread(); 73 void FinalizeOnAudioThread();
69 74
70 // AudioInputStream::AudioInputCallback overrides: 75 // AudioInputStream::AudioInputCallback overrides:
71 // Called by the audio recorder when a full packet of audio data is 76 // 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 77 // available. This is called from a special audio thread and the
73 // implementation should return as soon as possible. 78 // implementation should return as soon as possible.
74 virtual void OnData(media::AudioInputStream* stream, 79 virtual void OnData(media::AudioInputStream* stream,
75 const media::AudioBus* source, 80 const media::AudioBus* source,
76 uint32 hardware_delay_bytes, 81 uint32 hardware_delay_bytes,
77 double volume) OVERRIDE; 82 double volume) OVERRIDE;
78 virtual void OnError(media::AudioInputStream* stream) OVERRIDE; 83 virtual void OnError(media::AudioInputStream* stream) OVERRIDE;
79 84
80 // AudioConverter::InputCallback overrides: 85 // AudioConverter::InputCallback overrides:
81 virtual double ProvideInput(media::AudioBus* dest, 86 virtual double ProvideInput(media::AudioBus* dest,
82 base::TimeDelta buffer_delay) OVERRIDE; 87 base::TimeDelta buffer_delay) OVERRIDE;
83 88
84 // Flushes the audio loop, making sure that any queued operations are 89 // Flushes the audio loop, making sure that any queued operations are
85 // performed. 90 // performed.
86 void FlushAudioLoopForTesting(); 91 void FlushAudioLoopForTesting();
87 92
88 media::AudioInputStream* stream_; 93 media::AudioInputStream* stream_;
89 bool is_recording_;
90 DecodeSamplesCallback decode_callback_; 94 DecodeSamplesCallback decode_callback_;
91 95
92 // ProvideInput will use this buffer as its source. 96 // ProvideInput will use this buffer as its source.
93 const media::AudioBus* temp_conversion_buffer_; 97 const media::AudioBus* temp_conversion_buffer_;
94 98
95 // Outside of the ctor/Initialize method, only access the next variables on 99 // Outside of the ctor/Initialize method, only access the next variables on
96 // the recording thread. 100 // the recording thread.
97 scoped_ptr<media::AudioBus> buffer_; 101 scoped_ptr<media::AudioBus> buffer_;
98 int total_buffer_frames_; 102 int total_buffer_frames_;
99 int buffer_frame_index_; 103 int buffer_frame_index_;
100 104
101 scoped_ptr<media::AudioConverter> converter_; 105 scoped_ptr<media::AudioConverter> converter_;
102 106
103 scoped_ptr<media::AudioInputStream> input_stream_for_testing_; 107 scoped_ptr<media::AudioInputStream> input_stream_for_testing_;
104 scoped_ptr<media::AudioParameters> params_for_testing_; 108 scoped_ptr<media::AudioParameters> params_for_testing_;
105 109
106 DISALLOW_COPY_AND_ASSIGN(AudioRecorder); 110 DISALLOW_COPY_AND_ASSIGN(AudioRecorder);
107 }; 111 };
108 112
109 } // namespace copresence 113 } // namespace copresence
110 114
111 #endif // COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_RECORDER_ 115 #endif // COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_RECORDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698