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

Unified Diff: components/copresence/mediums/audio/audio_recorder.h

Issue 419073002: Add the copresence DirectiveHandler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: components/copresence/mediums/audio/audio_recorder.h
diff --git a/components/copresence/mediums/audio/audio_recorder.h b/components/copresence/mediums/audio/audio_recorder.h
new file mode 100644
index 0000000000000000000000000000000000000000..69a135d5534d57dcdad75bb9b88a035825b630fe
--- /dev/null
+++ b/components/copresence/mediums/audio/audio_recorder.h
@@ -0,0 +1,99 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_RECORDER_
+#define COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_RECORDER_
+
+#include "base/gtest_prod_util.h"
+#include "base/macros.h"
+#include "base/memory/scoped_ptr.h"
+#include "media/audio/audio_io.h"
+#include "media/audio/audio_parameters.h"
+#include "media/base/audio_converter.h"
+
+namespace base {
+class MessageLoop;
+}
+
+namespace media {
+class AudioBus;
+}
+
+namespace copresence {
+
+// The AudioRecorder class will record audio until told to stop.
+class AudioRecorder : public media::AudioInputStream::AudioInputCallback,
+ public media::AudioConverter::InputCallback {
+ public:
+ typedef base::Callback<void(const std::string&)> DecodeSamplesCallback;
+
+ explicit AudioRecorder(const DecodeSamplesCallback& decode_callback);
+
+ // This constructor is only for testing.
+ 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.
+ media::AudioInputStream* input_stream_for_testing,
+ scoped_ptr<media::AudioParameters> params_for_testing);
+
+ void Record();
+ void Stop();
+
+ // Cleans up and deletes this object. Do not use object after this call.
+ void Finalize();
+
+ private:
+ friend class AudioRecorderTest;
+ FRIEND_TEST_ALL_PREFIXES(AudioRecorderTest, BasicRecordAndStop);
+ FRIEND_TEST_ALL_PREFIXES(AudioRecorderTest, OutOfOrderRecordAndStopMultiple);
+
+ virtual ~AudioRecorder();
+
+ // Methods to do our various operations; all of these need to be run on the
+ // audio thread.
+ void InitializeOnAudioThread();
+ void RecordOnAudioThread();
+ void StopOnAudioThread();
+ void StopAndCloseOnAudioThread();
+ void FinalizeOnAudioThread();
+
+ // AudioInputStream::AudioInputCallback overrides:
+ // Called by the audio recorder when a full packet of audio data is
+ // available. This is called from a special audio thread and the
+ // implementation should return as soon as possible.
+ virtual void OnData(media::AudioInputStream* stream,
+ const media::AudioBus* source,
+ uint32 hardware_delay_bytes,
+ double volume) OVERRIDE;
+ virtual void OnError(media::AudioInputStream* stream) OVERRIDE;
+
+ // AudioConverter::InputCallback overrides:
+ virtual double ProvideInput(media::AudioBus* dest,
+ base::TimeDelta buffer_delay) OVERRIDE;
+
+ // This is used by unit tests, do NOT use in production code.
+ 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
+
+ media::AudioInputStream* stream_;
+ bool is_recording_;
+ DecodeSamplesCallback decode_callback_;
+
+ // ProvideInput will use this buffer as its source.
+ const media::AudioBus* temp_conversion_buffer_;
+
+ // 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.
+ // the recording thread.
+ scoped_ptr<media::AudioBus> buffer_;
+ int total_buffer_frames_;
+ int buffer_frame_index_;
+
+ scoped_ptr<media::AudioConverter> converter_;
+
+ media::AudioInputStream* input_stream_for_testing_;
+ scoped_ptr<media::AudioParameters> params_for_testing_;
+
+ DISALLOW_COPY_AND_ASSIGN(AudioRecorder);
+};
+
+} // namespace copresence
+
+#endif // COMPONENTS_COPRESENCE_MEDIUMS_AUDIO_AUDIO_RECORDER_

Powered by Google App Engine
This is Rietveld 408576698