Skip to content

Commit d263fe1

Browse files
committed
MediaIO : remove MediaCoder (not available in FFM)
1 parent 3dc5596 commit d263fe1

18 files changed

Lines changed: 138 additions & 139 deletions

File tree

projects/jfaudio/src/Decoder.java

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -51,36 +51,30 @@ public void stop() {
5151
}
5252
}
5353

54-
public int read(MediaCoder coder, byte[] bytes) {
55-
if (coder == decoder) {
56-
try {
57-
return fin.read(bytes, 0, bytes.length);
58-
} catch (Exception e) {
59-
JFLog.log(e);
60-
return 0;
61-
}
54+
public int read(byte[] bytes) {
55+
try {
56+
return fin.read(bytes, 0, bytes.length);
57+
} catch (Exception e) {
58+
JFLog.log(e);
59+
return 0;
6260
}
63-
return 0;
6461
}
6562

66-
public int write(MediaCoder coder, byte[] bytes) {
63+
public int write(byte[] bytes) {
6764
return 0;
6865
}
6966

70-
public long seek(MediaCoder coder, long pos, int how) {
71-
if (coder == decoder) {
72-
try {
73-
switch (how) {
74-
case MediaCoder.SEEK_SET: break;
75-
case MediaCoder.SEEK_CUR: pos += fin.getFilePointer(); break;
76-
case MediaCoder.SEEK_END: pos += fin.length(); break;
77-
}
78-
fin.seek(pos);
79-
return pos;
80-
} catch (Exception e) {
81-
JFLog.log(e);
67+
public long seek(long pos, int how) {
68+
try {
69+
switch (how) {
70+
case MediaCoder.SEEK_SET: break;
71+
case MediaCoder.SEEK_CUR: pos += fin.getFilePointer(); break;
72+
case MediaCoder.SEEK_END: pos += fin.length(); break;
8273
}
83-
return 0;
74+
fin.seek(pos);
75+
return pos;
76+
} catch (Exception e) {
77+
JFLog.log(e);
8478
}
8579
return 0;
8680
}

projects/jfaudio/src/Transcoder.java

Lines changed: 64 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import javaforce.voip.*;
1212
import javaforce.media.*;
1313

14-
public class Transcoder implements MediaIO {
14+
public class Transcoder {
1515
MediaOutput encoder = new MediaOutput();
1616
MediaAudioEncoder audio_encoder;
1717
MediaInput decoder = new MediaInput();
@@ -23,12 +23,73 @@ public boolean transcode(String in, String out, String outCodec, int bit_rate) {
2323
fin = new RandomAccessFile(in, "r");
2424
fout = new RandomAccessFile(out, "rw");
2525
fout.setLength(0);
26-
if (!decoder.open(this)) throw new Exception("Decoder Failed to start");
26+
if (!decoder.open(
27+
new MediaIO() {
28+
public int read(byte[] bytes) {
29+
try {
30+
return fin.read(bytes, 0, bytes.length);
31+
} catch (Exception e) {
32+
JFLog.log(e);
33+
return 0;
34+
}
35+
}
36+
37+
public int write(byte[] bytes) {
38+
return 0;
39+
}
40+
41+
public long seek(long pos, int how) {
42+
try {
43+
switch (how) {
44+
case MediaCoder.SEEK_SET: break;
45+
case MediaCoder.SEEK_CUR: pos += fin.getFilePointer(); break;
46+
case MediaCoder.SEEK_END: pos += fin.length(); break;
47+
}
48+
fin.seek(pos);
49+
return pos;
50+
} catch (Exception e) {
51+
JFLog.log(e);
52+
}
53+
return 0;
54+
}
55+
}
56+
)) throw new Exception("Decoder Failed to start");
2757
audio_decoder = decoder.createAudioDecoder();
2858
chs = audio_decoder.getChannels();
2959
freq = audio_decoder.getSampleRate();
3060
JFLog.log("decoder:chs=" + chs + ",freq=" + freq);
31-
if (!encoder.create(this, outCodec)) throw new Exception("Encoder Failed to start");
61+
if (!encoder.create(
62+
new MediaIO() {
63+
public int read(byte[] bytes) {
64+
return 0;
65+
}
66+
67+
public int write(byte[] bytes) {
68+
try {
69+
fout.write(bytes);
70+
return bytes.length;
71+
} catch (Exception e) {
72+
JFLog.log(e);
73+
return 0;
74+
}
75+
}
76+
77+
public long seek(long pos, int how) {
78+
try {
79+
switch (how) {
80+
case MediaCoder.SEEK_SET: break;
81+
case MediaCoder.SEEK_CUR: pos += fout.getFilePointer(); break;
82+
case MediaCoder.SEEK_END: pos += fout.length(); break;
83+
}
84+
fout.seek(pos);
85+
return pos;
86+
} catch (Exception e) {
87+
JFLog.log(e);
88+
}
89+
return 0;
90+
}
91+
}
92+
, outCodec)) throw new Exception("Encoder Failed to start");
3293
CodecInfo info = new CodecInfo();
3394
info.audio_bit_rate = bit_rate;
3495
info.audio_codec = MediaCoder.AV_CODEC_ID_DEFAULT; //BUG ??? Need value from outCodec
@@ -57,60 +118,4 @@ public boolean transcode(String in, String out, String outCodec, int bit_rate) {
57118
}
58119
return true;
59120
}
60-
61-
public int read(MediaCoder coder, byte[] bytes) {
62-
if (coder == decoder) {
63-
try {
64-
return fin.read(bytes, 0, bytes.length);
65-
} catch (Exception e) {
66-
JFLog.log(e);
67-
return 0;
68-
}
69-
}
70-
return 0;
71-
}
72-
73-
public int write(MediaCoder coder, byte[] bytes) {
74-
if (coder == encoder) {
75-
try {
76-
fout.write(bytes);
77-
return bytes.length;
78-
} catch (Exception e) {
79-
JFLog.log(e);
80-
return 0;
81-
}
82-
}
83-
return 0;
84-
}
85-
86-
public long seek(MediaCoder coder, long pos, int how) {
87-
if (coder == decoder) {
88-
try {
89-
switch (how) {
90-
case MediaCoder.SEEK_SET: break;
91-
case MediaCoder.SEEK_CUR: pos += fin.getFilePointer(); break;
92-
case MediaCoder.SEEK_END: pos += fin.length(); break;
93-
}
94-
fin.seek(pos);
95-
return pos;
96-
} catch (Exception e) {
97-
JFLog.log(e);
98-
}
99-
return 0;
100-
} else if (coder == encoder) {
101-
try {
102-
switch (how) {
103-
case MediaCoder.SEEK_SET: break;
104-
case MediaCoder.SEEK_CUR: pos += fout.getFilePointer(); break;
105-
case MediaCoder.SEEK_END: pos += fout.length(); break;
106-
}
107-
fout.seek(pos);
108-
return pos;
109-
} catch (Exception e) {
110-
JFLog.log(e);
111-
}
112-
return 0;
113-
}
114-
return 0;
115-
}
116121
}

projects/jfdvr/src/service/MediaTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ public MediaTest() {
1919
try { raf = new RandomAccessFile("test.mp4", "rw"); } catch (Exception e) {}
2020
}
2121

22-
public int read(MediaCoder coder, byte[] buffer) {
22+
public int read(byte[] buffer) {
2323
JFLog.log("read:" + buffer.length);
2424
return -1;
2525
}
2626

27-
public int write(MediaCoder coder, byte[] buffer) {
27+
public int write(byte[] buffer) {
2828
long pos = 0;
2929
try { pos=raf.getFilePointer(); raf.write(buffer); } catch (Exception e) {}
3030
JFLog.log("write:" + buffer.length + "@" + pos);
3131
return buffer.length;
3232
}
3333

34-
public long seek(MediaCoder coder, long pos, int how) {
34+
public long seek(long pos, int how) {
3535
JFLog.log("seek:" + pos + ":" + how);
3636
long newpos = 0;
3737
try {

projects/jfdvr/src/viewer/MediaDownload.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ private void closeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:e
8989
private RandomAccessFile raf;
9090
private Viewer viewer;
9191
private boolean complete;
92-
public int read(MediaCoder coder, byte data[]) {
92+
public int read(byte data[]) {
9393
try {
9494
return raf.read(data);
9595
} catch (Exception e) {
9696
JFLog.log(e);
9797
return 0;
9898
}
9999
}
100-
public int write(MediaCoder coder, byte data[]) {
100+
public int write(byte data[]) {
101101
try {
102102
raf.write(data);
103103
return data.length;
@@ -106,7 +106,7 @@ public int write(MediaCoder coder, byte data[]) {
106106
return 0;
107107
}
108108
}
109-
public long seek(MediaCoder coder, long pos, int how) {
109+
public long seek(long pos, int how) {
110110
try {
111111
switch (how) {
112112
case MediaCoder.SEEK_SET: raf.seek(pos); break;

projects/jfmedia/src/MainPanel.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ public void run() {
970970
decoder = null;
971971
JFLog.log("read thread exit");
972972
}
973-
public int read(MediaCoder coder, byte data[]) {
973+
public int read(byte data[]) {
974974
int read = 0;
975975
try {
976976
read = raf.read(data, 0, data.length);
@@ -981,11 +981,11 @@ public int read(MediaCoder coder, byte data[]) {
981981
if (read == -1) read = 0;
982982
return read;
983983
}
984-
public int write(MediaCoder coder, byte data[]) {
984+
public int write(byte data[]) {
985985
// jfmedia does not create media files
986986
return 0;
987987
}
988-
public long seek(MediaCoder coder, long pos, int how) {
988+
public long seek(long pos, int how) {
989989
long opos = pos;
990990
try {
991991
switch (how) {
@@ -1328,7 +1328,7 @@ private void close(boolean teardown) {
13281328
}
13291329

13301330
//interface MediaIO
1331-
public int read(MediaCoder coder, byte data[]) {
1331+
public int read(byte data[]) {
13321332
int read = 0;
13331333
try {
13341334
//TODO : read network data
@@ -1339,11 +1339,11 @@ public int read(MediaCoder coder, byte data[]) {
13391339
if (read == -1) read = 0;
13401340
return read;
13411341
}
1342-
public int write(MediaCoder coder, byte data[]) {
1342+
public int write(byte data[]) {
13431343
//jfmedia does not create media files
13441344
return 0;
13451345
}
1346-
public long seek(MediaCoder coder, long pos, int how) {
1346+
public long seek(long pos, int how) {
13471347
return -1;
13481348
}
13491349

projects/jfphone/src/LocalCamera.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,11 +279,11 @@ public void run() {
279279
private MediaOutput encoder;
280280
private MediaVideoEncoder video;
281281

282-
public int read(MediaCoder coder, byte[] bytes) {
282+
public int read(byte[] bytes) {
283283
return 0;
284284
}
285285

286-
public int write(MediaCoder coder, byte[] bytes) {
286+
public int write(byte[] bytes) {
287287
int len = bytes.length;
288288
if (codec.name.equals("H263")) {
289289
// printArray("encoded_h263", bytes, 0, bytes.length);
@@ -324,7 +324,7 @@ public int write(MediaCoder coder, byte[] bytes) {
324324
return len;
325325
}
326326

327-
public long seek(MediaCoder coder, long l, int i) {
327+
public long seek(long pos, int how) {
328328
return 0;
329329
}
330330

projects/jfprojector/src/client/MainPanel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,11 +445,11 @@ public void run() {
445445
}
446446
}
447447

448-
public int read(MediaCoder coder, byte[] bytes) {
448+
public int read(byte[] bytes) {
449449
return 0;
450450
}
451451

452-
public int write(MediaCoder coder, byte[] bytes) {
452+
public int write(byte[] bytes) {
453453
try {
454454
os.write(bytes);
455455
return bytes.length;
@@ -460,7 +460,7 @@ public int write(MediaCoder coder, byte[] bytes) {
460460
}
461461
}
462462

463-
public long seek(MediaCoder coder, long pos, int how) {
463+
public long seek(long pos, int how) {
464464
/*
465465
try {
466466
switch (how) {

projects/jfprojector/src/server/Session.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ else if (packet.stream == info.video_stream) {
166166
decoder = null;
167167
inuse = false;
168168
}
169-
public int read(MediaCoder coder, byte data[]) {
169+
public int read(byte data[]) {
170170
int read = 0;
171171
try {
172172
read = is.read(data, 0, data.length);
@@ -181,10 +181,10 @@ public int read(MediaCoder coder, byte data[]) {
181181
}
182182
return read;
183183
}
184-
public int write(MediaCoder coder, byte data[]) {
184+
public int write(byte data[]) {
185185
return 0;
186186
}
187-
public long seek(MediaCoder coder, long pos, int how) {
187+
public long seek(long pos, int how) {
188188
switch (how) {
189189
case MediaCoder.SEEK_SET: return pos;
190190
case MediaCoder.SEEK_CUR: return pos;

projects/jfrecordcamera/src/MainPanel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -994,11 +994,11 @@ public String toString() {
994994
}
995995

996996
//MediaIO interface
997-
public int read(MediaCoder coder, byte[] bytes) {
997+
public int read(byte[] bytes) {
998998
return 0;
999999
}
10001000

1001-
public int write(MediaCoder coder, byte[] bytes) {
1001+
public int write(byte[] bytes) {
10021002
try {
10031003
raf.write(bytes);
10041004
return bytes.length;
@@ -1008,7 +1008,7 @@ public int write(MediaCoder coder, byte[] bytes) {
10081008
}
10091009
}
10101010

1011-
public long seek(MediaCoder coder, long pos, int how) {
1011+
public long seek(long pos, int how) {
10121012
try {
10131013
switch (how) {
10141014
case MediaCoder.SEEK_SET: break;

0 commit comments

Comments
 (0)