1 /**
2  * Copyright 2013 JogAmp Community. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are
5  * permitted provided that the following conditions are met:
6  *
7  *    1. Redistributions of source code must retain the above copyright notice, this list of
8  *       conditions and the following disclaimer.
9  *
10  *    2. Redistributions in binary form must reproduce the above copyright notice, this list
11  *       of conditions and the following disclaimer in the documentation and/or other materials
12  *       provided with the distribution.
13  *
14  * THIS SOFTWARE IS PROVIDED BY JogAmp Community ``AS IS'' AND ANY EXPRESS OR IMPLIED
15  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JogAmp Community OR
17  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
19  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
21  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
22  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  * The views and conclusions contained in the software and documentation are those of the
25  * authors and should not be interpreted as representing official policies, either expressed
26  * or implied, of JogAmp Community.
27  */
28 package jogamp.opengl.util.av;
29 
30 import java.nio.ByteBuffer;
31 
32 import com.jogamp.opengl.util.av.AudioSink;
33 
34 public class NullAudioSink implements AudioSink {
35 
36     private volatile float playSpeed = 1.0f;
37     private volatile boolean playRequested = false;
38     private volatile int playingPTS = AudioFrame.INVALID_PTS;
39     private float volume = 1.0f;
40 
41     private AudioFormat chosenFormat;
42     private boolean initialized;
43 
NullAudioSink()44     public NullAudioSink() {
45         initialized = true;
46         chosenFormat = null;
47     }
48 
49     @Override
isInitialized()50     public boolean isInitialized() {
51         return initialized;
52     }
53 
54     @Override
getPlaySpeed()55     public final float getPlaySpeed() { return playSpeed; }
56 
57     @Override
setPlaySpeed(float rate)58     public final boolean setPlaySpeed(float rate) {
59         if( Math.abs(1.0f - rate) < 0.01f ) {
60             rate = 1.0f;
61         }
62         playSpeed = rate;
63         return true;
64     }
65 
66     @Override
getVolume()67     public final float getVolume() {
68         // FIXME
69         return volume;
70     }
71 
72     @Override
setVolume(final float v)73     public final boolean setVolume(final float v) {
74         // FIXME
75         volume = v;
76         return true;
77     }
78 
79     @Override
getPreferredFormat()80     public AudioFormat getPreferredFormat() {
81         return DefaultFormat;
82     }
83 
84     @Override
getMaxSupportedChannels()85     public final int getMaxSupportedChannels() {
86         return 8;
87     }
88 
89     @Override
isSupported(final AudioFormat format)90     public final boolean isSupported(final AudioFormat format) {
91         /**
92          * If we like to emulate constraints ..
93          *
94         if( format.planar || !format.littleEndian ) {
95             return false;
96         }
97         if( format.sampleRate != DefaultFormat.sampleRate )  {
98             return false;
99         }
100         */
101         return true;
102     }
103 
104     @Override
init(final AudioFormat requestedFormat, final float frameDuration, final int initialQueueSize, final int queueGrowAmount, final int queueLimit)105     public boolean init(final AudioFormat requestedFormat, final float frameDuration, final int initialQueueSize, final int queueGrowAmount, final int queueLimit) {
106         chosenFormat = requestedFormat;
107         return true;
108     }
109 
110     @Override
getChosenFormat()111     public final AudioFormat getChosenFormat() {
112         return chosenFormat;
113     }
114 
115     @Override
isPlaying()116     public boolean isPlaying() {
117         return playRequested;
118     }
119 
120     @Override
play()121     public void play() {
122         playRequested = true;
123     }
124 
125     @Override
pause()126     public void pause() {
127         playRequested = false;
128     }
129 
130     @Override
flush()131     public void flush() {
132     }
133 
134     @Override
destroy()135     public void destroy() {
136         initialized = false;
137         chosenFormat = null;
138     }
139 
140     @Override
getEnqueuedFrameCount()141     public final int getEnqueuedFrameCount() {
142         return 0;
143     }
144 
145     @Override
getFrameCount()146     public int getFrameCount() {
147         return 0;
148     }
149 
150     @Override
getQueuedFrameCount()151     public int getQueuedFrameCount() {
152         return 0;
153     }
154 
155     @Override
getQueuedByteCount()156     public int getQueuedByteCount() {
157         return 0;
158     }
159 
160     @Override
getQueuedTime()161     public int getQueuedTime() {
162         return 0;
163     }
164 
165     @Override
getPTS()166     public final int getPTS() { return playingPTS; }
167 
168     @Override
getFreeFrameCount()169     public int getFreeFrameCount() {
170         return 1;
171     }
172 
173     @Override
enqueueData(final int pts, final ByteBuffer bytes, final int byteCount)174     public AudioFrame enqueueData(final int pts, final ByteBuffer bytes, final int byteCount) {
175         if( !initialized || null == chosenFormat ) {
176             return null;
177         }
178         playingPTS = pts;
179         return null;
180     }
181 }
182