OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2012 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 28 matching lines...) Expand all Loading... |
39 | 39 |
40 class AudioScheduledSourceHandler : public AudioHandler { | 40 class AudioScheduledSourceHandler : public AudioHandler { |
41 public: | 41 public: |
42 // These are the possible states an AudioScheduledSourceNode can be in: | 42 // These are the possible states an AudioScheduledSourceNode can be in: |
43 // | 43 // |
44 // UNSCHEDULED_STATE - Initial playback state. Created, but not yet scheduled. | 44 // UNSCHEDULED_STATE - Initial playback state. Created, but not yet scheduled. |
45 // SCHEDULED_STATE - Scheduled to play (via start()), but not yet playing. | 45 // SCHEDULED_STATE - Scheduled to play (via start()), but not yet playing. |
46 // PLAYING_STATE - Generating sound. | 46 // PLAYING_STATE - Generating sound. |
47 // FINISHED_STATE - Finished generating sound. | 47 // FINISHED_STATE - Finished generating sound. |
48 // | 48 // |
49 // The state can only transition to the next state, except for the FINISHED_ST
ATE which can | 49 // The state can only transition to the next state, except for the |
50 // never be changed. | 50 // FINISHED_STATE which can never be changed. |
51 enum PlaybackState { | 51 enum PlaybackState { |
52 // These must be defined with the same names and values as in the .idl file. | 52 // These must be defined with the same names and values as in the .idl file. |
53 UNSCHEDULED_STATE = 0, | 53 UNSCHEDULED_STATE = 0, |
54 SCHEDULED_STATE = 1, | 54 SCHEDULED_STATE = 1, |
55 PLAYING_STATE = 2, | 55 PLAYING_STATE = 2, |
56 FINISHED_STATE = 3 | 56 FINISHED_STATE = 3 |
57 }; | 57 }; |
58 | 58 |
59 AudioScheduledSourceHandler(NodeType, AudioNode&, float sampleRate); | 59 AudioScheduledSourceHandler(NodeType, AudioNode&, float sampleRate); |
60 | 60 |
(...skipping 12 matching lines...) Expand all Loading... |
73 bool isPlayingOrScheduled() const { | 73 bool isPlayingOrScheduled() const { |
74 PlaybackState state = playbackState(); | 74 PlaybackState state = playbackState(); |
75 return state == PLAYING_STATE || state == SCHEDULED_STATE; | 75 return state == PLAYING_STATE || state == SCHEDULED_STATE; |
76 } | 76 } |
77 | 77 |
78 bool hasFinished() const { return playbackState() == FINISHED_STATE; } | 78 bool hasFinished() const { return playbackState() == FINISHED_STATE; } |
79 | 79 |
80 protected: | 80 protected: |
81 // Get frame information for the current time quantum. | 81 // Get frame information for the current time quantum. |
82 // We handle the transition into PLAYING_STATE and FINISHED_STATE here, | 82 // We handle the transition into PLAYING_STATE and FINISHED_STATE here, |
83 // zeroing out portions of the outputBus which are outside the range of startF
rame and endFrame. | 83 // zeroing out portions of the outputBus which are outside the range of |
| 84 // startFrame and endFrame. |
84 // | 85 // |
85 // Each frame time is relative to the context's currentSampleFrame(). | 86 // Each frame time is relative to the context's currentSampleFrame(). |
86 // quantumFrameOffset : Offset frame in this time quantum to start renderin
g. | 87 // quantumFrameOffset : Offset frame in this time quantum to start |
87 // nonSilentFramesToProcess : Number of frames rendering non-silence (will be
<= quantumFrameSize). | 88 // rendering. |
| 89 // nonSilentFramesToProcess : Number of frames rendering non-silence (will be |
| 90 // <= quantumFrameSize). |
88 void updateSchedulingInfo(size_t quantumFrameSize, | 91 void updateSchedulingInfo(size_t quantumFrameSize, |
89 AudioBus* outputBus, | 92 AudioBus* outputBus, |
90 size_t& quantumFrameOffset, | 93 size_t& quantumFrameOffset, |
91 size_t& nonSilentFramesToProcess); | 94 size_t& nonSilentFramesToProcess); |
92 | 95 |
93 // Called when we have no more sound to play or the stop() time has been reach
ed. No onEnded | 96 // Called when we have no more sound to play or the stop() time has been |
94 // event is called. | 97 // reached. No onEnded event is called. |
95 virtual void finishWithoutOnEnded(); | 98 virtual void finishWithoutOnEnded(); |
96 | 99 |
97 // Like finishWithoutOnEnded(), but an onEnded (if specified) is called. | 100 // Like finishWithoutOnEnded(), but an onEnded (if specified) is called. |
98 virtual void finish(); | 101 virtual void finish(); |
99 | 102 |
100 void notifyEnded(); | 103 void notifyEnded(); |
101 | 104 |
102 // This synchronizes with process() and any other method that needs to be sync
hronized like | 105 // This synchronizes with process() and any other method that needs to be |
103 // setBuffer for AudioBufferSource. | 106 // synchronized like setBuffer for AudioBufferSource. |
104 mutable Mutex m_processLock; | 107 mutable Mutex m_processLock; |
105 | 108 |
106 // m_startTime is the time to start playing based on the context's timeline (0
or a time less than the context's current time means "now"). | 109 // m_startTime is the time to start playing based on the context's timeline (0 |
| 110 // or a time less than the context's current time means "now"). |
107 double m_startTime; // in seconds | 111 double m_startTime; // in seconds |
108 | 112 |
109 // m_endTime is the time to stop playing based on the context's timeline (0 or
a time less than the context's current time means "now"). | 113 // m_endTime is the time to stop playing based on the context's timeline (0 or |
110 // If it hasn't been set explicitly, then the sound will not stop playing (if
looping) or will stop when the end of the AudioBuffer | 114 // a time less than the context's current time means "now"). If it hasn't |
111 // has been reached. | 115 // been set explicitly, then the sound will not stop playing (if looping) or |
| 116 // will stop when the end of the AudioBuffer has been reached. |
112 double m_endTime; // in seconds | 117 double m_endTime; // in seconds |
113 | 118 |
114 static const double UnknownTime; | 119 static const double UnknownTime; |
115 | 120 |
116 private: | 121 private: |
117 // This is accessed by both the main thread and audio thread. Use the setter
and getter to | 122 // This is accessed by both the main thread and audio thread. Use the setter |
118 // protect the access to this! | 123 // and getter to protect the access to this. |
119 int m_playbackState; | 124 int m_playbackState; |
120 }; | 125 }; |
121 | 126 |
122 class AudioScheduledSourceNode : public AudioSourceNode, | 127 class AudioScheduledSourceNode : public AudioSourceNode, |
123 public ActiveScriptWrappable { | 128 public ActiveScriptWrappable { |
124 USING_GARBAGE_COLLECTED_MIXIN(AudioScheduledSourceNode); | 129 USING_GARBAGE_COLLECTED_MIXIN(AudioScheduledSourceNode); |
125 | 130 |
126 public: | 131 public: |
127 void start(ExceptionState&); | 132 void start(ExceptionState&); |
128 void start(double when, ExceptionState&); | 133 void start(double when, ExceptionState&); |
129 void stop(ExceptionState&); | 134 void stop(ExceptionState&); |
130 void stop(double when, ExceptionState&); | 135 void stop(double when, ExceptionState&); |
131 | 136 |
132 EventListener* onended(); | 137 EventListener* onended(); |
133 void setOnended(EventListener*); | 138 void setOnended(EventListener*); |
134 | 139 |
135 // ScriptWrappable: | 140 // ScriptWrappable: |
136 bool hasPendingActivity() const final; | 141 bool hasPendingActivity() const final; |
137 | 142 |
138 DEFINE_INLINE_VIRTUAL_TRACE() { AudioSourceNode::trace(visitor); } | 143 DEFINE_INLINE_VIRTUAL_TRACE() { AudioSourceNode::trace(visitor); } |
139 | 144 |
140 protected: | 145 protected: |
141 explicit AudioScheduledSourceNode(BaseAudioContext&); | 146 explicit AudioScheduledSourceNode(BaseAudioContext&); |
142 AudioScheduledSourceHandler& audioScheduledSourceHandler() const; | 147 AudioScheduledSourceHandler& audioScheduledSourceHandler() const; |
143 }; | 148 }; |
144 | 149 |
145 } // namespace blink | 150 } // namespace blink |
146 | 151 |
147 #endif // AudioScheduledSourceNode_h | 152 #endif // AudioScheduledSourceNode_h |
OLD | NEW |