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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 // The state can only transition to the next state, except for the FINISHED_
STATE which can | 47 // The state can only transition to the next state, except for the FINISHED_
STATE which can |
48 // never be changed. | 48 // never be changed. |
49 enum PlaybackState { | 49 enum PlaybackState { |
50 // These must be defined with the same names and values as in the .idl f
ile. | 50 // These must be defined with the same names and values as in the .idl f
ile. |
51 UNSCHEDULED_STATE = 0, | 51 UNSCHEDULED_STATE = 0, |
52 SCHEDULED_STATE = 1, | 52 SCHEDULED_STATE = 1, |
53 PLAYING_STATE = 2, | 53 PLAYING_STATE = 2, |
54 FINISHED_STATE = 3 | 54 FINISHED_STATE = 3 |
55 }; | 55 }; |
56 | 56 |
57 // This helper class handles the lifetime of an AudioScheduledSourceNode wit
h an onended event | |
58 // listener. This keeps the node alive until the event listener is processed
. | |
59 class NotifyEndedTask { | |
60 public: | |
61 NotifyEndedTask(PassRefPtr<AudioScheduledSourceNode> scheduledNode); | |
62 void notifyEnded(); | |
63 | |
64 private: | |
65 RefPtr<AudioScheduledSourceNode> m_scheduledNode; | |
66 }; | |
67 | |
68 AudioScheduledSourceNode(AudioContext*, float sampleRate); | 57 AudioScheduledSourceNode(AudioContext*, float sampleRate); |
69 | 58 |
70 // Scheduling. | 59 // Scheduling. |
71 void start(ExceptionState& exceptionState) { start(0.0, exceptionState); } | 60 void start(ExceptionState& exceptionState) { start(0.0, exceptionState); } |
72 void start(double when, ExceptionState&); | 61 void start(double when, ExceptionState&); |
73 void stop(ExceptionState& exceptionState) { stop(0.0, exceptionState); } | 62 void stop(ExceptionState& exceptionState) { stop(0.0, exceptionState); } |
74 void stop(double when, ExceptionState&); | 63 void stop(double when, ExceptionState&); |
75 | 64 |
76 unsigned short playbackState() const { return static_cast<unsigned short>(m_
playbackState); } | 65 unsigned short playbackState() const { return static_cast<unsigned short>(m_
playbackState); } |
77 bool isPlayingOrScheduled() const { return m_playbackState == PLAYING_STATE
|| m_playbackState == SCHEDULED_STATE; } | 66 bool isPlayingOrScheduled() const { return m_playbackState == PLAYING_STATE
|| m_playbackState == SCHEDULED_STATE; } |
(...skipping 11 matching lines...) Expand all Loading... |
89 // quantumFrameOffset : Offset frame in this time quantum to start render
ing. | 78 // quantumFrameOffset : Offset frame in this time quantum to start render
ing. |
90 // nonSilentFramesToProcess : Number of frames rendering non-silence (will b
e <= quantumFrameSize). | 79 // nonSilentFramesToProcess : Number of frames rendering non-silence (will b
e <= quantumFrameSize). |
91 void updateSchedulingInfo(size_t quantumFrameSize, | 80 void updateSchedulingInfo(size_t quantumFrameSize, |
92 AudioBus* outputBus, | 81 AudioBus* outputBus, |
93 size_t& quantumFrameOffset, | 82 size_t& quantumFrameOffset, |
94 size_t& nonSilentFramesToProcess); | 83 size_t& nonSilentFramesToProcess); |
95 | 84 |
96 // Called when we have no more sound to play or the noteOff() time has been
reached. | 85 // Called when we have no more sound to play or the noteOff() time has been
reached. |
97 virtual void finish(); | 86 virtual void finish(); |
98 | 87 |
99 static void notifyEndedDispatch(void*); | 88 void notifyEnded(); |
100 | 89 |
101 PlaybackState m_playbackState; | 90 PlaybackState m_playbackState; |
102 | 91 |
103 // 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"). | 92 // 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"). |
104 double m_startTime; // in seconds | 93 double m_startTime; // in seconds |
105 | 94 |
106 // 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"). | 95 // 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"). |
107 // If it hasn't been set explicitly, then the sound will not stop playing (i
f looping) or will stop when the end of the AudioBuffer | 96 // If it hasn't been set explicitly, then the sound will not stop playing (i
f looping) or will stop when the end of the AudioBuffer |
108 // has been reached. | 97 // has been reached. |
109 double m_endTime; // in seconds | 98 double m_endTime; // in seconds |
110 | 99 |
111 bool m_hasEndedListener; | 100 bool m_hasEndedListener; |
112 | 101 |
113 static const double UnknownTime; | 102 static const double UnknownTime; |
114 }; | 103 }; |
115 | 104 |
116 } // namespace WebCore | 105 } // namespace WebCore |
117 | 106 |
118 #endif // AudioScheduledSourceNode_h | 107 #endif // AudioScheduledSourceNode_h |
OLD | NEW |