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

Side by Side Diff: media/audio/fake_audio_input_stream.h

Issue 922663002: Moved the fake input stream's processing onto the audio worker thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 5 years, 10 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
« no previous file with comments | « media/audio/fake_audio_consumer_unittest.cc ('k') | media/audio/fake_audio_input_stream.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 // A fake implementation of AudioInputStream, useful for testing purpose. 5 // A fake implementation of AudioInputStream, useful for testing purpose.
6 6
7 #ifndef MEDIA_AUDIO_FAKE_AUDIO_INPUT_STREAM_H_ 7 #ifndef MEDIA_AUDIO_FAKE_AUDIO_INPUT_STREAM_H_
8 #define MEDIA_AUDIO_FAKE_AUDIO_INPUT_STREAM_H_ 8 #define MEDIA_AUDIO_FAKE_AUDIO_INPUT_STREAM_H_
9 9
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/files/file_path.h" 12 #include "base/callback_forward.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.h"
14 #include "base/synchronization/lock.h"
15 #include "base/threading/thread.h"
16 #include "base/time/time.h"
17 #include "media/audio/audio_io.h" 14 #include "media/audio/audio_io.h"
18 #include "media/audio/audio_parameters.h" 15 #include "media/audio/audio_parameters.h"
19 #include "media/audio/sounds/wav_audio_handler.h" 16 #include "media/audio/fake_audio_worker.h"
20 #include "media/base/audio_converter.h" 17
21 18
22 namespace media { 19 namespace media {
23 20
24 class AudioBus; 21 class AudioBus;
25 class AudioManagerBase; 22 class AudioManagerBase;
23 class SimpleSource;
26 24
27 // This class can either generate a beep sound or play audio from a file. 25 // This class acts as a fake audio input stream. The default is to generate a
26 // beeping sound unless --use-file-for-fake-audio-capture=<file> is specified,
27 // in which case the indicated .wav file will be read and played into the
28 // stream.
28 class MEDIA_EXPORT FakeAudioInputStream 29 class MEDIA_EXPORT FakeAudioInputStream
29 : public AudioInputStream, AudioConverter::InputCallback { 30 : public AudioInputStream {
30 public: 31 public:
31 static AudioInputStream* MakeFakeStream( 32 static AudioInputStream* MakeFakeStream(
32 AudioManagerBase* manager, const AudioParameters& params); 33 AudioManagerBase* manager, const AudioParameters& params);
33 34
34 bool Open() override; 35 bool Open() override;
35 void Start(AudioInputCallback* callback) override; 36 void Start(AudioInputCallback* callback) override;
36 void Stop() override; 37 void Stop() override;
37 void Close() override; 38 void Close() override;
38 double GetMaxVolume() override; 39 double GetMaxVolume() override;
39 void SetVolume(double volume) override; 40 void SetVolume(double volume) override;
40 double GetVolume() override; 41 double GetVolume() override;
41 bool IsMuted() override; 42 bool IsMuted() override;
42 bool SetAutomaticGainControl(bool enabled) override; 43 bool SetAutomaticGainControl(bool enabled) override;
43 bool GetAutomaticGainControl() override; 44 bool GetAutomaticGainControl() override;
44 45
45 // Generate one beep sound. This method is called by 46 // Generate one beep sound. This method is called by FakeVideoCaptureDevice to
46 // FakeVideoCaptureDevice to test audio/video synchronization. 47 // test audio/video synchronization. This is a static method because
47 // This is a static method because FakeVideoCaptureDevice is 48 // FakeVideoCaptureDevice is disconnected from an audio device. This means
48 // disconnected from an audio device. This means only one instance of 49 // only one instance of this class gets to respond, which is okay because we
49 // this class gets to respond, which is okay because we assume there's 50 // assume there's only one stream for this testing purpose. Furthermore this
50 // only one stream for this testing purpose. 51 // method will do nothing if --use-file-for-fake-audio-capture is specified
52 // since the input stream will be playing from a file instead of beeping.
51 // TODO(hclam): Make this non-static. To do this we'll need to fix 53 // TODO(hclam): Make this non-static. To do this we'll need to fix
52 // crbug.com/159053 such that video capture device is aware of audio 54 // crbug.com/159053 such that video capture device is aware of audio
53 // input stream. 55 // input stream.
54 static void BeepOnce(); 56 static void BeepOnce();
55 57
56 private: 58 private:
57 FakeAudioInputStream(AudioManagerBase* manager, 59 FakeAudioInputStream(AudioManagerBase* manager,
58 const AudioParameters& params); 60 const AudioParameters& params);
59 ~FakeAudioInputStream() override; 61 ~FakeAudioInputStream() override;
60 62
61 void DoCallback(); 63 scoped_ptr<AudioOutputStream::AudioSourceCallback> ChooseSource();
62 64 void ReadAudioFromSource();
63 // Opens this stream reading from a |wav_filename| rather than beeping.
64 void OpenInFileMode(const base::FilePath& wav_filename);
65
66 // Returns true if the device is playing from a file; false if we're beeping.
67 bool PlayingFromFile();
68
69 void PlayFile();
70 void PlayBeep();
71 65
72 AudioManagerBase* audio_manager_; 66 AudioManagerBase* audio_manager_;
73 AudioInputCallback* callback_; 67 AudioInputCallback* callback_;
74 scoped_ptr<uint8[]> buffer_; 68 FakeAudioWorker fake_audio_worker_;
75 int buffer_size_;
76 AudioParameters params_; 69 AudioParameters params_;
77 const scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 70
78 base::TimeTicks last_callback_time_; 71 scoped_ptr<AudioOutputStream::AudioSourceCallback> audio_source_;
79 base::TimeDelta callback_interval_;
80 base::TimeDelta interval_from_last_beep_;
81 int beep_duration_in_buffers_;
82 int beep_generated_in_buffers_;
83 int beep_period_in_frames_;
84 scoped_ptr<media::AudioBus> audio_bus_; 72 scoped_ptr<media::AudioBus> audio_bus_;
85 scoped_ptr<uint8[]> wav_file_data_;
86 scoped_ptr<media::WavAudioHandler> wav_audio_handler_;
87 scoped_ptr<media::AudioConverter> file_audio_converter_;
88 int wav_file_read_pos_;
89
90 // Allows us to run tasks on the FakeAudioInputStream instance which are
91 // bound by its lifetime.
92 base::WeakPtrFactory<FakeAudioInputStream> weak_factory_;
93
94 // If running in file mode, this provides audio data from wav_audio_handler_.
95 double ProvideInput(AudioBus* audio_bus,
96 base::TimeDelta buffer_delay) override;
97 73
98 DISALLOW_COPY_AND_ASSIGN(FakeAudioInputStream); 74 DISALLOW_COPY_AND_ASSIGN(FakeAudioInputStream);
99 }; 75 };
100 76
101 } // namespace media 77 } // namespace media
102 78
103 #endif // MEDIA_AUDIO_FAKE_AUDIO_INPUT_STREAM_H_ 79 #endif // MEDIA_AUDIO_FAKE_AUDIO_INPUT_STREAM_H_
OLDNEW
« no previous file with comments | « media/audio/fake_audio_consumer_unittest.cc ('k') | media/audio/fake_audio_input_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698