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

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

Issue 2060833002: Implementation of 'AudioContext.getOutputTimestamp' method (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added implementation for ALSA. Created 4 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 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>
(...skipping 19 matching lines...) Expand all
30 ~SineWaveAudioSource() override; 30 ~SineWaveAudioSource() override;
31 31
32 // Return up to |cap| samples of data via OnMoreData(). Use Reset() to 32 // Return up to |cap| samples of data via OnMoreData(). Use Reset() to
33 // allow more data to be served. 33 // allow more data to be served.
34 void CapSamples(int cap); 34 void CapSamples(int cap);
35 void Reset(); 35 void Reset();
36 36
37 // Implementation of AudioSourceCallback. 37 // Implementation of AudioSourceCallback.
38 int OnMoreData(AudioBus* audio_bus, 38 int OnMoreData(AudioBus* audio_bus,
39 uint32_t total_bytes_delay, 39 uint32_t total_bytes_delay,
40 uint32_t frames_skipped) override; 40 uint32_t frames_skipped,
41 const AudioTimestamp& timestamp = AudioTimestamp()) 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(AudioBus* audio_bus,
67 uint32_t total_bytes_delay, 68 uint32_t total_bytes_delay,
68 uint32_t frames_skipped) override; 69 uint32_t frames_skipped,
70 const AudioTimestamp& timestamp = AudioTimestamp()) override;
69 void OnError(AudioOutputStream* stream) override; 71 void OnError(AudioOutputStream* stream) override;
70 72
71 private: 73 private:
72 AudioParameters params_; 74 AudioParameters params_;
73 base::FilePath path_to_wav_file_; 75 base::FilePath path_to_wav_file_;
74 76
75 // The WAV data at |path_to_wav_file_| is read into memory and kept here. 77 // 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_|, 78 // This memory needs to survive for the lifetime of |wav_audio_handler_|,
77 // so declare it first. Do not access this member directly. 79 // so declare it first. Do not access this member directly.
78 std::unique_ptr<char[]> raw_wav_data_; 80 std::unique_ptr<char[]> raw_wav_data_;
(...skipping 15 matching lines...) Expand all
94 }; 96 };
95 97
96 class BeepingSource : public AudioOutputStream::AudioSourceCallback { 98 class BeepingSource : public AudioOutputStream::AudioSourceCallback {
97 public: 99 public:
98 BeepingSource(const AudioParameters& params); 100 BeepingSource(const AudioParameters& params);
99 ~BeepingSource() override; 101 ~BeepingSource() override;
100 102
101 // Implementation of AudioSourceCallback. 103 // Implementation of AudioSourceCallback.
102 int OnMoreData(AudioBus* audio_bus, 104 int OnMoreData(AudioBus* audio_bus,
103 uint32_t total_bytes_delay, 105 uint32_t total_bytes_delay,
104 uint32_t frames_skipped) override; 106 uint32_t frames_skipped,
107 const AudioTimestamp& timestamp) override;
105 void OnError(AudioOutputStream* stream) override; 108 void OnError(AudioOutputStream* stream) override;
106 109
107 static void BeepOnce(); 110 static void BeepOnce();
108 private: 111 private:
109 int buffer_size_; 112 int buffer_size_;
110 std::unique_ptr<uint8_t[]> buffer_; 113 std::unique_ptr<uint8_t[]> buffer_;
111 AudioParameters params_; 114 AudioParameters params_;
112 base::TimeTicks last_callback_time_; 115 base::TimeTicks last_callback_time_;
113 base::TimeDelta interval_from_last_beep_; 116 base::TimeDelta interval_from_last_beep_;
114 int beep_duration_in_buffers_; 117 int beep_duration_in_buffers_;
115 int beep_generated_in_buffers_; 118 int beep_generated_in_buffers_;
116 int beep_period_in_frames_; 119 int beep_period_in_frames_;
117 }; 120 };
118 121
119 } // namespace media 122 } // namespace media
120 123
121 #endif // MEDIA_AUDIO_SIMPLE_SOURCES_H_ 124 #endif // MEDIA_AUDIO_SIMPLE_SOURCES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698