| OLD | NEW |
| 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_IMPL_H_ |
| 6 #define COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_RECORDER_H_ | 6 #define COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_RECORDER_IMPL_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 "components/copresence/mediums/audio/audio_recorder.h" |
| 13 #include "media/audio/audio_io.h" | 14 #include "media/audio/audio_io.h" |
| 14 #include "media/audio/audio_parameters.h" | 15 #include "media/audio/audio_parameters.h" |
| 15 #include "media/base/audio_converter.h" | 16 #include "media/base/audio_converter.h" |
| 16 | 17 |
| 17 namespace base { | 18 namespace base { |
| 18 class MessageLoop; | 19 class MessageLoop; |
| 19 } | 20 } |
| 20 | 21 |
| 21 namespace media { | 22 namespace media { |
| 22 class AudioBus; | 23 class AudioBus; |
| 23 } | 24 } |
| 24 | 25 |
| 25 namespace copresence { | 26 namespace copresence { |
| 26 | 27 |
| 27 // The AudioRecorder class will record audio until told to stop. | 28 // The AudioRecorder class will record audio until told to stop. |
| 28 class AudioRecorder : public media::AudioInputStream::AudioInputCallback, | 29 class AudioRecorderImpl final |
| 29 public media::AudioConverter::InputCallback { | 30 : public AudioRecorder, |
| 31 public media::AudioInputStream::AudioInputCallback, |
| 32 public media::AudioConverter::InputCallback { |
| 30 public: | 33 public: |
| 31 typedef base::Callback<void(const std::string&)> DecodeSamplesCallback; | 34 typedef base::Callback<void(const std::string&)> RecordedSamplesCallback; |
| 32 | 35 |
| 33 explicit AudioRecorder(const DecodeSamplesCallback& decode_callback); | 36 AudioRecorderImpl(); |
| 34 | 37 |
| 35 // Initializes the object. Do not use this object before calling this method. | 38 // AudioRecorder overrides: |
| 36 virtual void Initialize(); | 39 virtual void Initialize( |
| 37 | 40 const RecordedSamplesCallback& decode_callback) override; |
| 38 virtual void Record(); | 41 virtual void Record() override; |
| 39 virtual void Stop(); | 42 virtual void Stop() override; |
| 40 | 43 virtual void Finalize() override; |
| 41 // Cleans up and deletes this object. Do not use object after this call. | 44 virtual bool IsRecording() override; |
| 42 virtual void Finalize(); | |
| 43 | |
| 44 bool IsRecording(); | |
| 45 | 45 |
| 46 // Takes ownership of the stream. | 46 // Takes ownership of the stream. |
| 47 void set_input_stream_for_testing( | 47 void set_input_stream_for_testing( |
| 48 media::AudioInputStream* input_stream_for_testing) { | 48 media::AudioInputStream* input_stream_for_testing) { |
| 49 input_stream_for_testing_.reset(input_stream_for_testing); | 49 input_stream_for_testing_.reset(input_stream_for_testing); |
| 50 } | 50 } |
| 51 | 51 |
| 52 // Takes ownership of the params. | 52 // Takes ownership of the params. |
| 53 void set_params_for_testing(media::AudioParameters* params_for_testing) { | 53 void set_params_for_testing(media::AudioParameters* params_for_testing) { |
| 54 params_for_testing_.reset(params_for_testing); | 54 params_for_testing_.reset(params_for_testing); |
| 55 } | 55 } |
| 56 | 56 |
| 57 protected: | 57 protected: |
| 58 virtual ~AudioRecorder(); | 58 virtual ~AudioRecorderImpl(); |
| 59 void set_is_recording(bool is_recording) { is_recording_ = is_recording; } | 59 void set_is_recording(bool is_recording) { is_recording_ = is_recording; } |
| 60 | 60 |
| 61 private: | 61 private: |
| 62 friend class AudioRecorderTest; | 62 friend class AudioRecorderTest; |
| 63 FRIEND_TEST_ALL_PREFIXES(AudioRecorderTest, BasicRecordAndStop); | 63 FRIEND_TEST_ALL_PREFIXES(AudioRecorderTest, BasicRecordAndStop); |
| 64 FRIEND_TEST_ALL_PREFIXES(AudioRecorderTest, OutOfOrderRecordAndStopMultiple); | 64 FRIEND_TEST_ALL_PREFIXES(AudioRecorderTest, OutOfOrderRecordAndStopMultiple); |
| 65 | 65 |
| 66 // Methods to do our various operations; all of these need to be run on the | 66 // Methods to do our various operations; all of these need to be run on the |
| 67 // audio thread. | 67 // audio thread. |
| 68 void InitializeOnAudioThread(); | 68 void InitializeOnAudioThread(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 85 virtual double ProvideInput(media::AudioBus* dest, | 85 virtual double ProvideInput(media::AudioBus* dest, |
| 86 base::TimeDelta buffer_delay) override; | 86 base::TimeDelta buffer_delay) override; |
| 87 | 87 |
| 88 // Flushes the audio loop, making sure that any queued operations are | 88 // Flushes the audio loop, making sure that any queued operations are |
| 89 // performed. | 89 // performed. |
| 90 void FlushAudioLoopForTesting(); | 90 void FlushAudioLoopForTesting(); |
| 91 | 91 |
| 92 bool is_recording_; | 92 bool is_recording_; |
| 93 | 93 |
| 94 media::AudioInputStream* stream_; | 94 media::AudioInputStream* stream_; |
| 95 DecodeSamplesCallback decode_callback_; | 95 |
| 96 RecordedSamplesCallback decode_callback_; |
| 96 | 97 |
| 97 // ProvideInput will use this buffer as its source. | 98 // ProvideInput will use this buffer as its source. |
| 98 const media::AudioBus* temp_conversion_buffer_; | 99 const media::AudioBus* temp_conversion_buffer_; |
| 99 | 100 |
| 100 // Outside of the ctor/Initialize method, only access the next variables on | 101 // Outside of the ctor/Initialize method, only access the next variables on |
| 101 // the recording thread. | 102 // the recording thread. |
| 102 scoped_ptr<media::AudioBus> buffer_; | 103 scoped_ptr<media::AudioBus> buffer_; |
| 103 int total_buffer_frames_; | 104 int total_buffer_frames_; |
| 104 int buffer_frame_index_; | 105 int buffer_frame_index_; |
| 105 | 106 |
| 106 scoped_ptr<media::AudioConverter> converter_; | 107 scoped_ptr<media::AudioConverter> converter_; |
| 107 | 108 |
| 108 scoped_ptr<media::AudioInputStream> input_stream_for_testing_; | 109 scoped_ptr<media::AudioInputStream> input_stream_for_testing_; |
| 109 scoped_ptr<media::AudioParameters> params_for_testing_; | 110 scoped_ptr<media::AudioParameters> params_for_testing_; |
| 110 | 111 |
| 111 DISALLOW_COPY_AND_ASSIGN(AudioRecorder); | 112 DISALLOW_COPY_AND_ASSIGN(AudioRecorderImpl); |
| 112 }; | 113 }; |
| 113 | 114 |
| 114 } // namespace copresence | 115 } // namespace copresence |
| 115 | 116 |
| 116 #endif // COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_RECORDER_H_ | 117 #endif // COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_RECORDER_IMPL_H_ |
| OLD | NEW |