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

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: Implementation of 'AudioContext.getOutputTimestamp' method Created 4 years, 6 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 = {0, 0}) 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 ~FileSource() override; 63 ~FileSource() override;
63 64
64 // Implementation of AudioSourceCallback. 65 // Implementation of AudioSourceCallback.
65 int OnMoreData(AudioBus* audio_bus, 66 int OnMoreData(AudioBus* audio_bus,
66 uint32_t total_bytes_delay, 67 uint32_t total_bytes_delay,
67 uint32_t frames_skipped) override; 68 uint32_t frames_skipped,
69 const AudioTimestamp& timestamp = {0, 0}) override;
68 void OnError(AudioOutputStream* stream) override; 70 void OnError(AudioOutputStream* stream) override;
69 71
70 private: 72 private:
71 AudioParameters params_; 73 AudioParameters params_;
72 base::FilePath path_to_wav_file_; 74 base::FilePath path_to_wav_file_;
73 75
74 // 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.
75 // 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_|,
76 // so declare it first. Do not access this member directly. 78 // so declare it first. Do not access this member directly.
77 std::unique_ptr<char[]> raw_wav_data_; 79 std::unique_ptr<char[]> raw_wav_data_;
(...skipping 11 matching lines...) Expand all
89 }; 91 };
90 92
91 class BeepingSource : public AudioOutputStream::AudioSourceCallback { 93 class BeepingSource : public AudioOutputStream::AudioSourceCallback {
92 public: 94 public:
93 BeepingSource(const AudioParameters& params); 95 BeepingSource(const AudioParameters& params);
94 ~BeepingSource() override; 96 ~BeepingSource() override;
95 97
96 // Implementation of AudioSourceCallback. 98 // Implementation of AudioSourceCallback.
97 int OnMoreData(AudioBus* audio_bus, 99 int OnMoreData(AudioBus* audio_bus,
98 uint32_t total_bytes_delay, 100 uint32_t total_bytes_delay,
99 uint32_t frames_skipped) override; 101 uint32_t frames_skipped,
102 const AudioTimestamp& timestamp) override;
100 void OnError(AudioOutputStream* stream) override; 103 void OnError(AudioOutputStream* stream) override;
101 104
102 static void BeepOnce(); 105 static void BeepOnce();
103 private: 106 private:
104 int buffer_size_; 107 int buffer_size_;
105 std::unique_ptr<uint8_t[]> buffer_; 108 std::unique_ptr<uint8_t[]> buffer_;
106 AudioParameters params_; 109 AudioParameters params_;
107 base::TimeTicks last_callback_time_; 110 base::TimeTicks last_callback_time_;
108 base::TimeDelta interval_from_last_beep_; 111 base::TimeDelta interval_from_last_beep_;
109 int beep_duration_in_buffers_; 112 int beep_duration_in_buffers_;
110 int beep_generated_in_buffers_; 113 int beep_generated_in_buffers_;
111 int beep_period_in_frames_; 114 int beep_period_in_frames_;
112 }; 115 };
113 116
114 } // namespace media 117 } // namespace media
115 118
116 #endif // MEDIA_AUDIO_SIMPLE_SOURCES_H_ 119 #endif // MEDIA_AUDIO_SIMPLE_SOURCES_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698