Skip to content

Commit 8b9bc01

Browse files
kokorinkokorin
authored andcommitted
Frame static factory methods, remove some todos
1 parent e2a1ddf commit 8b9bc01

File tree

13 files changed

+37
-50
lines changed

13 files changed

+37
-50
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ FrameProducer producer = new FrameProducer() {
265265
graphics.setPaint(new Color(frameCounter * 1.0f / 30, 0, 0));
266266
graphics.fillRect(0, 0, 320, 240);
267267
long pts = frameCounter * 1000 / 10; // Frame PTS in Stream Timebase
268-
Frame videoFrame = new Frame(0, pts, image);
268+
Frame videoFrame = Frame.createVideoFrame(0, pts, image);
269269
frameCounter++;
270270

271271
return videoFrame;

src/main/java/com/github/kokorin/jaffree/ffmpeg/CaptureInput.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ public CaptureInput<T> setCaptureVideoSize(String size) {
106106
*/
107107
public abstract CaptureInput<T> setCaptureCursor(boolean captureCursor);
108108

109-
// TODO check static method references
110109
public static CaptureInput<?> captureDesktop() {
111110
CaptureInput<?> result = null;
112111
if (OS.IS_LINUX) {

src/main/java/com/github/kokorin/jaffree/ffmpeg/FFmpeg.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -411,8 +411,6 @@ protected StdReader<FFmpegResult> createStdErrReader(OutputListener outputListen
411411
* @return this
412412
*/
413413
protected StdReader<FFmpegResult> createStdOutReader() {
414-
// TODO ffmpeg normally doesn't write to Std OUT, stdOutReader should throw an error
415-
// if it reads any byte
416414
return new LoggingStdReader<>();
417415
}
418416

src/main/java/com/github/kokorin/jaffree/ffmpeg/FFmpegResultFuture.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,10 @@ public FFmpegResult get(long timeout, TimeUnit unit) throws InterruptedException
111111
return resultFuture.get(timeout, unit);
112112
}
113113

114-
// TODO check if required or replace with more suitable method
115114
public boolean isCancelled() {
116115
return resultFuture.isCancelled();
117116
}
118117

119-
// TODO check if required or replace with more suitable method
120118
public boolean isDone() {
121119
return resultFuture.isDone();
122120
}

src/main/java/com/github/kokorin/jaffree/ffmpeg/Frame.java

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,32 +32,6 @@ public class Frame {
3232
private final BufferedImage image;
3333
private final int[] samples;
3434

35-
/**
36-
* Creates video {@link Frame}, samples are set to null.
37-
*
38-
* @param streamId stream id (starting with 0)
39-
* @param pts pts in {@link Stream} timebase
40-
* @param image video frame image
41-
* @see Stream#getTimebase()
42-
*/
43-
// TODO make static method
44-
public Frame(final int streamId, final long pts, final BufferedImage image) {
45-
this(streamId, pts, image, null);
46-
}
47-
48-
/**
49-
* Creates audio {@link Frame}, image is set to null.
50-
*
51-
* @param streamId streamId
52-
* @param pts pts in {@link Stream} timebase
53-
* @param samples audio samples in PCM S32BE format
54-
* @see Stream#getTimebase()
55-
*/
56-
// TODO make static method
57-
public Frame(final int streamId, final long pts, final int[] samples) {
58-
this(streamId, pts, null, samples);
59-
}
60-
6135
/**
6236
* Creates {@link Frame}.
6337
*
@@ -67,7 +41,7 @@ public Frame(final int streamId, final long pts, final int[] samples) {
6741
* @param samples audio samples in PCM S32BE format
6842
* @see Stream#getTimebase()
6943
*/
70-
public Frame(final int streamId, final long pts, final BufferedImage image,
44+
protected Frame(final int streamId, final long pts, final BufferedImage image,
7145
final int[] samples) {
7246
if (image != null && samples != null) {
7347
throw new IllegalArgumentException(
@@ -133,4 +107,29 @@ public String toString() {
133107
+ ", samples?=" + (samples != null)
134108
+ '}';
135109
}
110+
111+
/**
112+
* Creates video {@link Frame}, samples are set to null.
113+
*
114+
* @param streamId stream id (starting with 0)
115+
* @param pts pts in {@link Stream} timebase
116+
* @param image video frame image
117+
* @see Stream#getTimebase()
118+
*/
119+
public static Frame createVideoFrame(final int streamId, final long pts, final BufferedImage image) {
120+
return new Frame(streamId, pts, image, null);
121+
}
122+
123+
/**
124+
* Creates audio {@link Frame}, image is set to null.
125+
*
126+
* @param streamId streamId
127+
* @param pts pts in {@link Stream} timebase
128+
* @param samples audio samples in PCM S32BE format
129+
* @see Stream#getTimebase()
130+
*/
131+
public static Frame createAudioFrame(final int streamId, final long pts, final int[] samples) {
132+
return new Frame(streamId, pts, null, samples);
133+
}
134+
136135
}

src/main/java/com/github/kokorin/jaffree/ffmpeg/NutFrameWriter.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ private void write(final NutWriter writer) throws IOException {
198198

199199
case AUDIO:
200200
data = new byte[frame.getSamples().length * 4];
201-
// TODO check number of samples provided
202201
ByteBuffer.wrap(data).asIntBuffer().put(frame.getSamples());
203202
break;
204203

src/main/java/com/github/kokorin/jaffree/nut/DataItem.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
public class DataItem {
6161
public final String name;
6262
public final Object value;
63-
// TODO: introduce type enum?
6463
public final String type;
6564

6665
/**

src/main/java/com/github/kokorin/jaffree/process/LoggingStdReader.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,10 @@ public class LoggingStdReader<T> implements StdReader<T> {
4040
*/
4141
@Override
4242
public T read(final InputStream stdOut) {
43-
// TODO use line iterator?
4443
BufferedReader reader = new BufferedReader(new InputStreamReader(stdOut));
4544

4645
try {
4746
String line;
48-
// TODO log message with the same logging level
49-
// for example if message starts with [DEBUG] output it to debug.
5047
while ((line = reader.readLine()) != null) {
5148
LOGGER.info(line);
5249
}

src/main/java/com/github/kokorin/jaffree/util/LineIterator.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
/**
2828
* Adapts {@link BufferedReader} to line {@link Iterator}.
2929
*/
30-
// TODO: move to util package
3130
public class LineIterator implements Iterator<String> {
3231
private final BufferedReader reader;
3332
private String nextLine = null;

src/test/java/com/github/kokorin/jaffree/ffmpeg/FrameIOTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,10 +270,10 @@ public Frame produce() {
270270
}
271271

272272
if (videoPts <= audioPts) {
273-
return new Frame(0, videoPts++, flag);
273+
return Frame.createVideoFrame(0, videoPts++, flag);
274274
}
275275

276-
return new Frame(1, audioPts++, samples);
276+
return Frame.createAudioFrame(1, audioPts++, samples);
277277
}
278278
};
279279

@@ -406,10 +406,10 @@ public Frame produce() {
406406
}
407407

408408
if (videoPts <= audioPts) {
409-
return new Frame(0, videoPts++, redCross);
409+
return Frame.createVideoFrame(0, videoPts++, redCross);
410410
}
411411

412-
return new Frame(1, audioPts++, samples);
412+
return Frame.createAudioFrame(1, audioPts++, samples);
413413
}
414414
};
415415

@@ -504,7 +504,6 @@ private void testNutGenerationAndConsumption(final int duration, final int fps,
504504

505505
final AtomicReference<FFmpegProgress> progressRef = new AtomicReference<>();
506506

507-
// TODO: convert outputPath to MP4 with ffmpeg and check how long will it take
508507
FFmpeg.atPath(BIN)
509508
.addInput(FrameInput.withProducer(
510509
new FrameProducer() {
@@ -546,7 +545,7 @@ public Frame produce() {
546545
lastSecond = currentSecond;
547546
}
548547

549-
Frame result = new Frame(0, frame * timebase / fps, image);
548+
Frame result = Frame.createVideoFrame(0, frame * timebase / fps, image);
550549
frame++;
551550

552551
return result;

src/test/java/examples/BouncingBallExample.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public Frame produce() {
125125
graphics.setPaint(ballColor);
126126
graphics.fillOval(ballCenterX - BALL_RADIUS, ballCenterY - BALL_RADIUS, BALL_RADIUS * 2, BALL_RADIUS * 2);
127127

128-
Frame videoFrame = new Frame(0, nextVideoTimecode, image);
128+
Frame videoFrame = Frame.createVideoFrame(0, nextVideoTimecode, image);
129129

130130
if (collisionVideoTimecode <= nextVideoTimecode) {
131131
Random random = new Random();
@@ -152,7 +152,7 @@ public Frame produce() {
152152
}
153153

154154

155-
Frame audioFrame = new Frame(1, nextAudioTimecode, samples);
155+
Frame audioFrame = Frame.createAudioFrame(1, nextAudioTimecode, samples);
156156

157157
nextAudioTimecode += 1000 / FPS;
158158
return audioFrame;

src/test/java/examples/MosaicExample.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, in
235235
return null;
236236
}
237237

238-
Frame result = new Frame(0, nextVideoFrameTimecode, mosaic);
238+
Frame result = Frame.createVideoFrame(0, nextVideoFrameTimecode, mosaic);
239239

240240
nextVideoFrameTimecode += videoFrameDuration;
241241

@@ -273,7 +273,7 @@ private Frame produceAudioFrame() {
273273
if (aFrame == null) {
274274
return null;
275275
}
276-
aFrame = new Frame(1 + minI, aFrame.getPts(), aFrame.getSamples());
276+
aFrame = Frame.createAudioFrame(1 + minI, aFrame.getPts(), aFrame.getSamples());
277277

278278
if (nextPts != Long.MAX_VALUE) {
279279
nextAudioFrameTimecode = 1000L * nextPts / sampleRate;

src/test/java/examples/ProduceVideoExample.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public Frame produce() {
5454
graphics.setPaint(new Color(frameCounter * 1.0f / 30, 0, 0));
5555
graphics.fillRect(0, 0, 320, 240);
5656
long pts = frameCounter * 1000 / 10; // Frame PTS in Stream Timebase
57-
Frame videoFrame = new Frame(0, pts, image);
57+
Frame videoFrame = Frame.createVideoFrame(0, pts, image);
5858
frameCounter++;
5959

6060
return videoFrame;

0 commit comments

Comments
 (0)