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

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

Issue 637223011: Redesign the copresence audio handlers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git/+/master
Patch Set: Created 6 years, 1 month 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
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_H_ 5 #ifndef COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_RECORDER_H_
6 #define COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_RECORDER_H_ 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 {
29 public media::AudioConverter::InputCallback {
30 public: 29 public:
31 typedef base::Callback<void(const std::string&)> DecodeSamplesCallback; 30 typedef base::Callback<void(const std::string&)> RecordedSamplesCallback;
32
33 explicit AudioRecorder(const DecodeSamplesCallback& decode_callback);
34 31
35 // Initializes the object. Do not use this object before calling this method. 32 // Initializes the object. Do not use this object before calling this method.
36 virtual void Initialize(); 33 virtual void Initialize(const RecordedSamplesCallback& decode_callback) = 0;
37 34
38 virtual void Record(); 35 virtual void Record() = 0;
39 virtual void Stop(); 36 virtual void Stop() = 0;
40 37
41 // Cleans up and deletes this object. Do not use object after this call. 38 // Cleans up and deletes this object. Do not use object after this call.
42 virtual void Finalize(); 39 virtual void Finalize() = 0;
43 40
44 bool IsRecording(); 41 virtual bool IsRecording() = 0;
42
43 protected:
44 virtual ~AudioRecorder(){};
Daniel Erat 2014/10/21 19:43:22 nit: virtual ~AudioRecorder() {}
rkc 2014/10/22 00:06:20 Done.
45 };
46
47 // The AudioRecorder class will record audio until told to stop.
48 class AudioRecorderImpl : public AudioRecorder,
49 public media::AudioInputStream::AudioInputCallback,
50 public media::AudioConverter::InputCallback {
51 public:
52 typedef base::Callback<void(const std::string&)> RecordedSamplesCallback;
53
54 AudioRecorderImpl();
55
56 // AudioRecorder overrides:
57 virtual void Initialize(
58 const RecordedSamplesCallback& decode_callback) override;
59 virtual void Record() override;
60 virtual void Stop() override;
61 virtual void Finalize() override;
62 virtual bool IsRecording() override;
45 63
46 // Takes ownership of the stream. 64 // Takes ownership of the stream.
47 void set_input_stream_for_testing( 65 void set_input_stream_for_testing(
48 media::AudioInputStream* input_stream_for_testing) { 66 media::AudioInputStream* input_stream_for_testing) {
49 input_stream_for_testing_.reset(input_stream_for_testing); 67 input_stream_for_testing_.reset(input_stream_for_testing);
50 } 68 }
51 69
52 // Takes ownership of the params. 70 // Takes ownership of the params.
53 void set_params_for_testing(media::AudioParameters* params_for_testing) { 71 void set_params_for_testing(media::AudioParameters* params_for_testing) {
54 params_for_testing_.reset(params_for_testing); 72 params_for_testing_.reset(params_for_testing);
55 } 73 }
56 74
57 protected: 75 protected:
58 virtual ~AudioRecorder(); 76 virtual ~AudioRecorderImpl();
59 void set_is_recording(bool is_recording) { is_recording_ = is_recording; } 77 void set_is_recording(bool is_recording) { is_recording_ = is_recording; }
60 78
61 private: 79 private:
62 friend class AudioRecorderTest; 80 friend class AudioRecorderTest;
63 FRIEND_TEST_ALL_PREFIXES(AudioRecorderTest, BasicRecordAndStop); 81 FRIEND_TEST_ALL_PREFIXES(AudioRecorderTest, BasicRecordAndStop);
64 FRIEND_TEST_ALL_PREFIXES(AudioRecorderTest, OutOfOrderRecordAndStopMultiple); 82 FRIEND_TEST_ALL_PREFIXES(AudioRecorderTest, OutOfOrderRecordAndStopMultiple);
65 83
66 // Methods to do our various operations; all of these need to be run on the 84 // Methods to do our various operations; all of these need to be run on the
67 // audio thread. 85 // audio thread.
68 void InitializeOnAudioThread(); 86 void InitializeOnAudioThread();
(...skipping 16 matching lines...) Expand all
85 virtual double ProvideInput(media::AudioBus* dest, 103 virtual double ProvideInput(media::AudioBus* dest,
86 base::TimeDelta buffer_delay) override; 104 base::TimeDelta buffer_delay) override;
87 105
88 // Flushes the audio loop, making sure that any queued operations are 106 // Flushes the audio loop, making sure that any queued operations are
89 // performed. 107 // performed.
90 void FlushAudioLoopForTesting(); 108 void FlushAudioLoopForTesting();
91 109
92 bool is_recording_; 110 bool is_recording_;
93 111
94 media::AudioInputStream* stream_; 112 media::AudioInputStream* stream_;
95 DecodeSamplesCallback decode_callback_; 113
114 RecordedSamplesCallback decode_callback_;
96 115
97 // ProvideInput will use this buffer as its source. 116 // ProvideInput will use this buffer as its source.
98 const media::AudioBus* temp_conversion_buffer_; 117 const media::AudioBus* temp_conversion_buffer_;
99 118
100 // Outside of the ctor/Initialize method, only access the next variables on 119 // Outside of the ctor/Initialize method, only access the next variables on
101 // the recording thread. 120 // the recording thread.
102 scoped_ptr<media::AudioBus> buffer_; 121 scoped_ptr<media::AudioBus> buffer_;
103 int total_buffer_frames_; 122 int total_buffer_frames_;
104 int buffer_frame_index_; 123 int buffer_frame_index_;
105 124
106 scoped_ptr<media::AudioConverter> converter_; 125 scoped_ptr<media::AudioConverter> converter_;
107 126
108 scoped_ptr<media::AudioInputStream> input_stream_for_testing_; 127 scoped_ptr<media::AudioInputStream> input_stream_for_testing_;
109 scoped_ptr<media::AudioParameters> params_for_testing_; 128 scoped_ptr<media::AudioParameters> params_for_testing_;
110 129
111 DISALLOW_COPY_AND_ASSIGN(AudioRecorder); 130 DISALLOW_COPY_AND_ASSIGN(AudioRecorderImpl);
112 }; 131 };
113 132
114 } // namespace copresence 133 } // namespace copresence
115 134
116 #endif // COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_RECORDER_H_ 135 #endif // COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_RECORDER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698