Skip to content

Commit 96a52e3

Browse files
JavaDoc for Outlet methods
1 parent c437025 commit 96a52e3

File tree

2 files changed

+74
-28
lines changed

2 files changed

+74
-28
lines changed

src/main/java/com/goxr3plus/streamplayer/stream/Outlet.java

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
import javax.sound.sampled.*;
44
import java.util.logging.Logger;
55

6+
/**
7+
* Owner of the SourceDataLine which is the output line of the player.
8+
* Also owns controls for the SourceDataLine.
9+
* Future goal is to move all handling of the SourceDataLine to here,
10+
* so that the StreamPlayer doesn't have to call {@link #getSourceDataLine()}.
11+
* Another goal is to remove some of the setter and getter methods of this class,
12+
* by moving all code that needs them to this class.
13+
*/
614
public class Outlet {
715

816
private final Logger logger;
@@ -12,47 +20,82 @@ public class Outlet {
1220
private FloatControl panControl;
1321
private SourceDataLine sourceDataLine;
1422

23+
/**
24+
* @param logger used to log messages
25+
*/
1526
public Outlet(Logger logger) {
1627
this.logger = logger;
1728
}
1829

1930

31+
/**
32+
* @return the balance control of the {@link #sourceDataLine}
33+
*/
2034
public FloatControl getBalanceControl() {
2135
return balanceControl;
2236
}
2337

38+
/**
39+
* @return the gain control of the {@link #sourceDataLine}
40+
*/
2441
public FloatControl getGainControl() {
2542
return gainControl;
2643
}
2744

45+
/**
46+
* @return the mute control of the {@link #sourceDataLine}
47+
*/
2848
public BooleanControl getMuteControl() {
2949
return muteControl;
3050
}
3151

52+
/**
53+
* @return the pan control of the {@link #sourceDataLine}
54+
*/
3255
public FloatControl getPanControl() {
3356
return panControl;
3457
}
3558

59+
/**
60+
* @return the {@link #sourceDataLine}, which is the output audio signal of the player
61+
*/
3662
public SourceDataLine getSourceDataLine() {
3763
return sourceDataLine;
3864
}
3965

66+
67+
/**
68+
* @param balanceControl to be set on the {@link #sourceDataLine}
69+
*/
4070
public void setBalanceControl(FloatControl balanceControl) {
4171
this.balanceControl = balanceControl;
4272
}
4373

74+
/**
75+
* @param gainControl to be set on the {@link #sourceDataLine}
76+
*/
4477
public void setGainControl(FloatControl gainControl) {
4578
this.gainControl = gainControl;
4679
}
4780

81+
/**
82+
* @param muteControl to be set on the {@link #sourceDataLine}
83+
*/
4884
public void setMuteControl(BooleanControl muteControl) {
4985
this.muteControl = muteControl;
5086
}
5187

88+
/**
89+
* @param panControl to be set on the {@link #sourceDataLine}
90+
*/
5291
public void setPanControl(FloatControl panControl) {
5392
this.panControl = panControl;
5493
}
5594

95+
/**
96+
* @param sourceDataLine representing the audio output of the player.
97+
* Usually taken from {@link AudioSystem#getLine(Line.Info)}.
98+
*/
5699
public void setSourceDataLine(SourceDataLine sourceDataLine) {
57100
this.sourceDataLine = sourceDataLine;
58101
}
@@ -84,6 +127,10 @@ public float getGainValue() {
84127
}
85128
}
86129

130+
/**
131+
* Stop the {@link #sourceDataLine} in a nice way.
132+
* Also nullify it. (Is that necessary?)
133+
*/
87134
void drainStopAndFreeDataLine() {
88135
// Free audio resources.
89136
if (sourceDataLine != null) {
@@ -94,34 +141,56 @@ void drainStopAndFreeDataLine() {
94141
}
95142
}
96143

97-
void stopAndFreeDataLine() {
144+
/**
145+
* Flush and close the {@link #sourceDataLine} in a nice way.
146+
* Also nullify it. (Is that necessary?)
147+
*/
148+
void flushAndFreeDataLine() {
98149
if (sourceDataLine != null) {
99150
sourceDataLine.flush();
100151
sourceDataLine.close();
101152
this.sourceDataLine = null; // TODO: Is this necessary? Will it not be garbage collected?
102153
}
103154
}
104155

156+
/**
157+
* Flush and stop the {@link #sourceDataLine}, if it's running.
158+
*/
105159
void flushAndStop() {
106160
// Flush and stop the source data line
107-
if (sourceDataLine != null && sourceDataLine.isRunning()) {
161+
if (sourceDataLine != null && sourceDataLine.isRunning()) { // TODO: Risk for NullPointerException?
108162
sourceDataLine.flush();
109163
sourceDataLine.stop();
110164
}
111165
}
112166

167+
/**
168+
* @return true if the {@link #sourceDataLine} is startable.
169+
*/
113170
boolean isStartable() {
114171
return sourceDataLine != null && !sourceDataLine.isRunning();
115172
}
173+
174+
175+
/**
176+
* Start the {@link #sourceDataLine}
177+
*/
116178
void start() {
117179
sourceDataLine.start();
118180
}
119181

120-
void open(AudioFormat audioFormat, int currentLineBufferSize) throws LineUnavailableException {
182+
/**
183+
* Open the {@link #sourceDataLine}.
184+
* Also create controls for it.
185+
* @param format The wanted audio format.
186+
* @param bufferSize the desired buffer size for the {@link #sourceDataLine}
187+
* @throws LineUnavailableException
188+
*/
189+
void open(AudioFormat format, int bufferSize) throws LineUnavailableException {
121190
logger.info("Entered OpenLine()!:\n");
122191

123192
if (sourceDataLine != null) {
124-
sourceDataLine.open(audioFormat, currentLineBufferSize);
193+
sourceDataLine.open(format, bufferSize);
125194

126195
// opened?
127196
if (sourceDataLine.isOpen()) {

src/main/java/com/goxr3plus/streamplayer/stream/StreamPlayer.java

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public void reset() {
186186
closeStream();
187187
}
188188

189-
outlet.stopAndFreeDataLine();
189+
outlet.flushAndFreeDataLine();
190190

191191
// AudioFile
192192
audioInputStream = null;
@@ -759,17 +759,6 @@ public long seekTo(int seconds) throws StreamPlayerException {
759759
return seekBytes(bytes);
760760
}
761761

762-
// /**
763-
// * Go to X time of the Audio
764-
// * See {@link #seek(long)}
765-
// *
766-
// * @param pattern A string in the format (HH:MM:SS) WHERE h = HOURS , M = minutes , S = seconds
767-
// */
768-
// public void seekTo(String pattern) throws StreamPlayerException {
769-
// long bytes = 0;
770-
//
771-
// seek(bytes);
772-
// }
773762

774763
private void validateSeconds(int seconds, int durationInSeconds) {
775764
if (seconds < 0) {
@@ -852,8 +841,6 @@ public Void call() {
852841
// Compute position in bytes in encoded stream.
853842
final int nEncodedBytes = getEncodedStreamPosition();
854843

855-
// System.err.println(trimBuffer[0] + " , Data Length :" + trimBuffer.length)
856-
857844
// Notify all registered Listeners
858845
listeners.forEach(listener -> {
859846
if (audioInputStream instanceof PropertiesContainer) {
@@ -1103,16 +1090,6 @@ public long getTotalBytes() {
11031090
return encodedAudioLength;
11041091
}
11051092

1106-
/**
1107-
* @return
1108-
*/
1109-
// public int getByteLength() {
1110-
// return audioProperties == null ||
1111-
// !audioProperties.containsKey("audio.length.bytes") ?
1112-
// AudioSystem.NOT_SPECIFIED
1113-
// : ((Integer) audioProperties.get("audio.length.bytes")).intValue();
1114-
// }
1115-
11161093
/**
11171094
* @return BytePosition
11181095
*/

0 commit comments

Comments
 (0)