r42991 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r42990‎ | r42991 | r42992 >
Date:11:20, 1 November 2008
Author:maikmerten
Status:old
Tags:
Comment:
Estimate playback position according to how many bytes have been read from source if no duration is given.
Modified paths:
  • /trunk/cortado/src/com/fluendo/jst/Message.java (modified) (history)
  • /trunk/cortado/src/com/fluendo/player/Cortado.java (modified) (history)
  • /trunk/cortado/src/com/fluendo/player/Status.java (modified) (history)
  • /trunk/cortado/src/com/fluendo/plugin/HTTPSrc.java (modified) (history)

Diff [purge]

Index: trunk/cortado/src/com/fluendo/jst/Message.java
@@ -41,6 +41,7 @@
4242 public static final int SEGMENT_DONE = (1 << 17);
4343 public static final int DURATION = (1 << 18);
4444 public static final int RESOURCE = (1 << 19);
 45+ public static final int BYTEPOSITION = (1 << 20);
4546
4647 private com.fluendo.jst.Object src;
4748 private int type;
@@ -182,4 +183,13 @@
183184 public long parseDurationValue() {
184185 return longVal;
185186 }
 187+ public static Message newBytePosition(com.fluendo.jst.Object src, long aPos) {
 188+ Message msg = new Message(src, BYTEPOSITION);
 189+ msg.longVal = aPos;
 190+ return msg;
 191+ }
 192+ public long parseBytePosition() {
 193+ return longVal;
 194+ }
 195+
186196 }
Index: trunk/cortado/src/com/fluendo/player/Status.java
@@ -70,6 +70,8 @@
7171 private double position = 0;
7272 private long time;
7373 private double duration;
 74+ private long byteDuration;
 75+ private long bytePosition;
7476
7577 private String speaker = "\0\0\0\0\0\357\0\0\357U\27"
7678 + "\36\0\0\0\0\357\357\0\0" + "\0\357U\30\0\0\0\357\0\357"
@@ -217,8 +219,8 @@
218220 }
219221
220222 private void paintSeekBar(Graphics g) {
221 - Rectangle sr = getSeekBarRect();
222 - Rectangle tr = getThumbRect();
 223+ Rectangle sr = getSeekBarRect();
 224+ Rectangle tr = getThumbRect();
223225
224226 // Bounding rectangle
225227 g.setColor(Color.darkGray);
@@ -227,7 +229,7 @@
228230 // Progress bar
229231 g.setColor(Color.gray);
230232 g.fillRect(sr.x + 2, sr.y + 3, tr.x - (sr.x + 2), sr.height - 6);
231 -
 233+
232234 // Thumb
233235 g.setColor(Color.white);
234236 g.drawLine(tr.x + 1, tr.y, tr.x + tr.width - 1, tr.y); // Top
@@ -331,16 +333,22 @@
332334 if (clicked == NONE) {
333335 double newPosition;
334336
335 - if (seconds < duration)
 337+ if (seconds < duration || seekable)
336338 time = (long) seconds;
337339 else
338340 time = (long) duration;
339341
340 - newPosition = ((double) time) / duration;
341 - if (newPosition != position) {
342 - position = newPosition;
343 - component.repaint();
344 - }
 342+ if(duration > -1) {
 343+ newPosition = ((double) time) / duration;
 344+ if (newPosition != position) {
 345+ position = newPosition;
 346+ component.repaint();
 347+ }
 348+ } else {
 349+ newPosition = ((double)bytePosition) / (double)byteDuration;
 350+ position = newPosition;
 351+ component.repaint();
 352+ }
345353 }
346354 }
347355
@@ -348,6 +356,22 @@
349357 duration = seconds;
350358 component.repaint();
351359 }
 360+
 361+ public void setByteDuration(long bytes) {
 362+ this.byteDuration = bytes;
 363+ if(duration == -1) {
 364+ position = ((double)bytePosition) / (double)byteDuration;
 365+ component.repaint();
 366+ }
 367+ }
 368+
 369+ public void setBytePosition(long bytes) {
 370+ this.bytePosition = bytes;
 371+ if(duration == -1) {
 372+ position = ((double)bytePosition) / (double)byteDuration;
 373+ component.repaint();
 374+ }
 375+ }
352376
353377 public void setMessage(String m) {
354378 message = m;
Index: trunk/cortado/src/com/fluendo/player/Cortado.java
@@ -544,6 +544,8 @@
545545 long duration;
546546
547547 duration = msg.parseDurationValue();
 548+
 549+ status.setByteDuration(duration);
548550
549551 Debug.log(Debug.DEBUG, "got duration: "+duration);
550552 if (duration != -1) {
@@ -618,6 +620,9 @@
619621 }
620622 }
621623 break;
 624+ case Message.BYTEPOSITION:
 625+ status.setBytePosition(msg.parseBytePosition());
 626+ break;
622627 default:
623628 break;
624629 }
Index: trunk/cortado/src/com/fluendo/plugin/HTTPSrc.java
@@ -34,6 +34,7 @@
3535 private InputStream input;
3636 private long contentLength;
3737 private long offset;
 38+ private long offsetLastMessage = 0;
3839 private long skipBytes = 0;
3940 private String mime;
4041 private Caps outCaps;
@@ -164,6 +165,10 @@
165166 }
166167 if (data.length <= 0) {
167168 /* EOS */
 169+
 170+ postMessage (Message.newBytePosition(this, offset));
 171+ offsetLastMessage = offset;
 172+
168173 try {
169174 input.close();
170175 }
@@ -179,6 +184,13 @@
180185 }
181186
182187 offset += data.length;
 188+ if(offsetLastMessage > offset) {
 189+ offsetLastMessage = 0;
 190+ }
 191+ if(offset - offsetLastMessage > contentLength / 100) {
 192+ postMessage (Message.newBytePosition(this, offset));
 193+ offsetLastMessage = offset;
 194+ }
183195
184196 // Negotiate capabilities
185197 if (srcpad.getCaps() == null) {

Status & tagging log