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

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

Issue 2101303004: Pass delay and timestamp to AudioSourceCallback::OnMoreData. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Pass target playout time to AudioSourceCallback::OnMoreData. Created 4 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
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 #ifndef MEDIA_AUDIO_SIMPLE_SOURCES_H_ 5 #ifndef MEDIA_AUDIO_SIMPLE_SOURCES_H_
6 #define MEDIA_AUDIO_SIMPLE_SOURCES_H_ 6 #define MEDIA_AUDIO_SIMPLE_SOURCES_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <memory> 10 #include <memory>
11 11
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
14 #include "base/time/time.h"
14 #include "media/audio/audio_io.h" 15 #include "media/audio/audio_io.h"
15 #include "media/base/audio_converter.h" 16 #include "media/base/audio_converter.h"
16 #include "media/base/seekable_buffer.h" 17 #include "media/base/seekable_buffer.h"
17 18
18 namespace media { 19 namespace media {
19 20
20 class WavAudioHandler; 21 class WavAudioHandler;
21 22
22 // An audio source that produces a pure sinusoidal tone. 23 // An audio source that produces a pure sinusoidal tone.
23 class MEDIA_EXPORT SineWaveAudioSource 24 class MEDIA_EXPORT SineWaveAudioSource
24 : public AudioOutputStream::AudioSourceCallback { 25 : public AudioOutputStream::AudioSourceCallback {
25 public: 26 public:
26 // |channels| is the number of audio channels, |freq| is the frequency in 27 // |channels| is the number of audio channels, |freq| is the frequency in
27 // hertz and it has to be less than half of the sampling frequency 28 // hertz and it has to be less than half of the sampling frequency
28 // |sample_freq| or else you will get aliasing. 29 // |sample_freq| or else you will get aliasing.
29 SineWaveAudioSource(int channels, double freq, double sample_freq); 30 SineWaveAudioSource(int channels, double freq, double sample_freq);
30 ~SineWaveAudioSource() override; 31 ~SineWaveAudioSource() override;
31 32
32 // Return up to |cap| samples of data via OnMoreData(). Use Reset() to 33 // Return up to |cap| samples of data via OnMoreData(). Use Reset() to
33 // allow more data to be served. 34 // allow more data to be served.
34 void CapSamples(int cap); 35 void CapSamples(int cap);
35 void Reset(); 36 void Reset();
36 37
37 // Implementation of AudioSourceCallback. 38 // Implementation of AudioSourceCallback.
38 int OnMoreData(AudioBus* audio_bus, 39 int OnMoreData(base::TimeTicks target_playout_time,
39 uint32_t total_bytes_delay, 40 int prior_frames_skipped,
40 uint32_t frames_skipped) override; 41 AudioBus* dest) override;
41 void OnError(AudioOutputStream* stream) override; 42 void OnError(AudioOutputStream* stream) override;
42 43
43 // The number of OnMoreData() and OnError() calls respectively. 44 // The number of OnMoreData() and OnError() calls respectively.
44 int callbacks() { return callbacks_; } 45 int callbacks() { return callbacks_; }
45 int errors() { return errors_; } 46 int errors() { return errors_; }
46 47
47 protected: 48 protected:
48 int channels_; 49 int channels_;
49 double f_; 50 double f_;
50 int time_state_; 51 int time_state_;
51 int cap_; 52 int cap_;
52 int callbacks_; 53 int callbacks_;
53 int errors_; 54 int errors_;
54 base::Lock time_lock_; 55 base::Lock time_lock_;
55 }; 56 };
56 57
57 class MEDIA_EXPORT FileSource : public AudioOutputStream::AudioSourceCallback, 58 class MEDIA_EXPORT FileSource : public AudioOutputStream::AudioSourceCallback,
58 public AudioConverter::InputCallback { 59 public AudioConverter::InputCallback {
59 public: 60 public:
60 FileSource(const AudioParameters& params, 61 FileSource(const AudioParameters& params,
61 const base::FilePath& path_to_wav_file, 62 const base::FilePath& path_to_wav_file,
62 bool loop); 63 bool loop);
63 ~FileSource() override; 64 ~FileSource() override;
64 65
65 // Implementation of AudioSourceCallback. 66 // Implementation of AudioSourceCallback.
66 int OnMoreData(AudioBus* audio_bus, 67 int OnMoreData(base::TimeTicks target_playout_time,
67 uint32_t total_bytes_delay, 68 int prior_frames_skipped,
68 uint32_t frames_skipped) override; 69 AudioBus* dest) override;
69 void OnError(AudioOutputStream* stream) override; 70 void OnError(AudioOutputStream* stream) override;
70 71
71 private: 72 private:
72 AudioParameters params_; 73 AudioParameters params_;
73 base::FilePath path_to_wav_file_; 74 base::FilePath path_to_wav_file_;
74 75
75 // The WAV data at |path_to_wav_file_| is read into memory and kept here. 76 // The WAV data at |path_to_wav_file_| is read into memory and kept here.
76 // This memory needs to survive for the lifetime of |wav_audio_handler_|, 77 // This memory needs to survive for the lifetime of |wav_audio_handler_|,
77 // so declare it first. Do not access this member directly. 78 // so declare it first. Do not access this member directly.
78 std::unique_ptr<char[]> raw_wav_data_; 79 std::unique_ptr<char[]> raw_wav_data_;
79 80
80 std::unique_ptr<WavAudioHandler> wav_audio_handler_; 81 std::unique_ptr<WavAudioHandler> wav_audio_handler_;
81 std::unique_ptr<AudioConverter> file_audio_converter_; 82 std::unique_ptr<AudioConverter> file_audio_converter_;
82 int wav_file_read_pos_; 83 int wav_file_read_pos_;
83 bool load_failed_; 84 bool load_failed_;
84 bool looping_; 85 bool looping_;
85 86
86 // Provides audio data from wav_audio_handler_ into the file audio converter. 87 // Provides audio data from wav_audio_handler_ into the file audio converter.
87 double ProvideInput(AudioBus* audio_bus, uint32_t frames_delayed) override; 88 double ProvideInput(AudioBus* audio_bus, uint32_t frames_delayed) override;
88 89
89 // Loads the wav file on the first OnMoreData invocation. 90 // Loads the wav file on the first OnMoreData invocation.
90 void LoadWavFile(const base::FilePath& path_to_wav_file); 91 void LoadWavFile(const base::FilePath& path_to_wav_file);
91 92
92 // Rewinds the player to the start of the loaded wav file. 93 // Rewinds the player to the start of the loaded wav file.
93 void Rewind(); 94 void Rewind();
94 }; 95 };
95 96
96 class BeepingSource : public AudioOutputStream::AudioSourceCallback { 97 class BeepingSource : public AudioOutputStream::AudioSourceCallback {
97 public: 98 public:
98 BeepingSource(const AudioParameters& params); 99 explicit BeepingSource(const AudioParameters& params);
99 ~BeepingSource() override; 100 ~BeepingSource() override;
100 101
101 // Implementation of AudioSourceCallback. 102 // Implementation of AudioSourceCallback.
102 int OnMoreData(AudioBus* audio_bus, 103 int OnMoreData(base::TimeTicks target_playout_time,
103 uint32_t total_bytes_delay, 104 int prior_frames_skipped,
104 uint32_t frames_skipped) override; 105 AudioBus* dest) override;
105 void OnError(AudioOutputStream* stream) override; 106 void OnError(AudioOutputStream* stream) override;
106 107
107 static void BeepOnce(); 108 static void BeepOnce();
108 private: 109 private:
109 int buffer_size_; 110 int buffer_size_;
110 std::unique_ptr<uint8_t[]> buffer_; 111 std::unique_ptr<uint8_t[]> buffer_;
111 AudioParameters params_; 112 AudioParameters params_;
112 base::TimeTicks last_callback_time_; 113 base::TimeTicks last_callback_time_;
113 base::TimeDelta interval_from_last_beep_; 114 base::TimeDelta interval_from_last_beep_;
114 int beep_duration_in_buffers_; 115 int beep_duration_in_buffers_;
115 int beep_generated_in_buffers_; 116 int beep_generated_in_buffers_;
116 int beep_period_in_frames_; 117 int beep_period_in_frames_;
117 }; 118 };
118 119
119 } // namespace media 120 } // namespace media
120 121
121 #endif // MEDIA_AUDIO_SIMPLE_SOURCES_H_ 122 #endif // MEDIA_AUDIO_SIMPLE_SOURCES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698