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

Side by Side Diff: third_party/WebKit/Source/platform/audio/AudioDestination.h

Issue 2777903005: Add WebThread in AudioDestination to support AudioWorkletThread (Closed)
Patch Set: Refactoring WIP (please ignore) Created 3 years, 8 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 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 25 matching lines...) Expand all
36 #include "platform/wtf/Noncopyable.h" 36 #include "platform/wtf/Noncopyable.h"
37 #include "platform/wtf/text/WTFString.h" 37 #include "platform/wtf/text/WTFString.h"
38 #include "public/platform/WebAudioDevice.h" 38 #include "public/platform/WebAudioDevice.h"
39 #include "public/platform/WebVector.h" 39 #include "public/platform/WebVector.h"
40 40
41 namespace blink { 41 namespace blink {
42 42
43 class PushPullFIFO; 43 class PushPullFIFO;
44 class SecurityOrigin; 44 class SecurityOrigin;
45 class WebAudioLatencyHint; 45 class WebAudioLatencyHint;
46 class WebThread;
46 47
47 // The AudioDestination class is an audio sink interface between the media 48 // The AudioDestination class is an audio sink interface between the media
48 // renderer and the Blink's WebAudio module. It has a FIFO to adapt the 49 // renderer and the Blink's WebAudio module. It has a FIFO to adapt the
49 // different processing block sizes of WebAudio renderer and actual hardware 50 // different processing block sizes of WebAudio renderer and actual hardware
50 // audio callback. 51 // audio callback.
51 class PLATFORM_EXPORT AudioDestination : public WebAudioDevice::RenderCallback { 52 class PLATFORM_EXPORT AudioDestination : public WebAudioDevice::RenderCallback {
52 USING_FAST_MALLOC(AudioDestination); 53 USING_FAST_MALLOC(AudioDestination);
53 WTF_MAKE_NONCOPYABLE(AudioDestination); 54 WTF_MAKE_NONCOPYABLE(AudioDestination);
54 55
55 public: 56 public:
(...skipping 13 matching lines...) Expand all
69 // invoked by the media renderer. 70 // invoked by the media renderer.
70 void Render(const WebVector<float*>& destination_data, 71 void Render(const WebVector<float*>& destination_data,
71 size_t number_of_frames, 72 size_t number_of_frames,
72 double delay, 73 double delay,
73 double delay_timestamp, 74 double delay_timestamp,
74 size_t prior_frames_skipped) override; 75 size_t prior_frames_skipped) override;
75 76
76 virtual void Start(); 77 virtual void Start();
77 virtual void Stop(); 78 virtual void Stop();
78 79
80 void RequestRenderOnWebThread(size_t numberOfFrames,
81 double delay,
82 double delayTimestamp,
83 size_t priorFramesSkipped);
o1ka 2017/04/13 08:36:53 Should these params also be renamed with a new sty
hongchan 2017/04/14 16:31:48 Done.
84
79 size_t CallbackBufferSize() const { return callback_buffer_size_; } 85 size_t CallbackBufferSize() const { return callback_buffer_size_; }
86
80 bool IsPlaying() { return is_playing_; } 87 bool IsPlaying() { return is_playing_; }
81 88
82 double SampleRate() const { return web_audio_device_->SampleRate(); } 89 double SampleRate() const { return web_audio_device_->SampleRate(); }
83 90
84 // Returns the audio buffer size in frames used by the underlying audio 91 // Returns the audio buffer size in frames used by the underlying audio
85 // hardware. 92 // hardware.
86 int FramesPerBuffer() const { return web_audio_device_->FramesPerBuffer(); } 93 int FramesPerBuffer() const { return web_audio_device_->FramesPerBuffer(); }
87 94
88 // The information from the actual audio hardware. (via Platform::current) 95 // The information from the actual audio hardware. (via Platform::Current())
89 static float HardwareSampleRate(); 96 static float HardwareSampleRate();
90 static unsigned long MaxChannelCount(); 97 static unsigned long MaxChannelCount();
91 98
92 private: 99 private:
93 std::unique_ptr<WebAudioDevice> web_audio_device_; 100 std::unique_ptr<WebAudioDevice> web_audio_device_;
94 unsigned number_of_output_channels_; 101 unsigned number_of_output_channels_;
95 size_t callback_buffer_size_; 102 size_t callback_buffer_size_;
96 bool is_playing_; 103 bool is_playing_;
97 104
98 // The render callback function of WebAudio engine. (i.e. DestinationNode) 105 // WebThread for WebAudio rendering.
99 AudioIOCallback& callback_; 106 std::unique_ptr<WebThread> rendering_thread_;
100 107
101 // To pass the data from FIFO to the audio device callback. 108 // To pass the data from FIFO to the audio device callback.
102 RefPtr<AudioBus> output_bus_; 109 RefPtr<AudioBus> output_bus_;
103 110
104 // To push the rendered result from WebAudio graph into the FIFO.
105 RefPtr<AudioBus> render_bus_;
106
107 // Resolves the buffer size mismatch between the WebAudio engine and 111 // Resolves the buffer size mismatch between the WebAudio engine and
108 // the callback function from the actual audio device. 112 // the callback function from the actual audio device.
109 std::unique_ptr<PushPullFIFO> fifo_; 113 std::unique_ptr<PushPullFIFO> fifo_;
110 114
111 size_t frames_elapsed_;
112 AudioIOPosition output_position_;
113 base::TimeTicks output_position_received_timestamp_;
114
115 // Check if the buffer size chosen by the WebAudioDevice is too large. 115 // Check if the buffer size chosen by the WebAudioDevice is too large.
116 bool CheckBufferSize(); 116 bool CheckBufferSize();
117 117
118 size_t HardwareBufferSize(); 118 size_t HardwareBufferSize();
119
120 bool IsRenderingThread();
121
122 size_t frames_elapsed_;
119 }; 123 };
120 124
121 } // namespace blink 125 } // namespace blink
122 126
123 #endif // AudioDestination_h 127 #endif // AudioDestination_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698