r44270 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r44269‎ | r44270 | r44271 >
Date:15:54, 6 December 2008
Author:maikmerten
Status:deferred (Comments)
Tags:
Comment:
add HTML5 media API subset to Cortado. Reformatting of Cortado.java (indentation was all off). Try to determine the duration of the given media file if no duration was given. More info print if range requests failed during duration-scanning.
Modified paths:
  • /trunk/cortado/src/com/fluendo/player/Cortado.java (modified) (history)
  • /trunk/cortado/src/com/fluendo/player/DurationScanner.java (modified) (history)

Diff [purge]

Index: trunk/cortado/src/com/fluendo/player/DurationScanner.java
@@ -43,6 +43,7 @@
4444 final static int VORBIS = 1;
4545 final static int THEORA = 2;
4646 private long contentLength = -1;
 47+ private long responseOffset;
4748 private Hashtable streaminfo = new Hashtable();
4849 private SyncState oy = new SyncState();
4950 private Page og = new Page();
@@ -86,7 +87,6 @@
8788 dis = uc.getInputStream();
8889
8990 String responseRange = uc.getHeaderField("Content-Range");
90 - long responseOffset;
9191 if (responseRange == null) {
9292 Debug.info("Response contained no Content-Range field, assuming offset=0");
9393 responseOffset = 0;
@@ -199,8 +199,8 @@
200200
201201 public float getDurationForURL(URL url, String user, String password) {
202202 try {
203 - int headbytes = 16 * 1024;
204 - int tailbytes = 80 * 1024;
 203+ int headbytes = 24 * 1024;
 204+ int tailbytes = 128 * 1024;
205205
206206 float time = 0;
207207
@@ -217,8 +217,12 @@
218218 time = t > time ? t : time;
219219 read = is.read(buffer);
220220 }
221 -
 221+ is.close();
222222 is = openWithConnection(url, user, password, contentLength - tailbytes);
 223+ if(responseOffset == 0) {
 224+ Debug.warning("DurationScanner: Couldn't complete duration scan due to failing range requests!");
 225+ return -1;
 226+ }
223227
224228 read = is.read(buffer);
225229 // read tail until eos, also abort if way too many bytes have been read
@@ -231,6 +235,7 @@
232236
233237 return time;
234238 } catch (IOException e) {
 239+ Debug.error(e.toString());
235240 return -1;
236241 }
237242 }
Index: trunk/cortado/src/com/fluendo/player/Cortado.java
@@ -15,7 +15,6 @@
1616 * along with this program; if not, write to the Free Software
1717 * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
1818 */
19 -
2019 package com.fluendo.player;
2120
2221 import java.applet.*;
@@ -28,11 +27,10 @@
2928
3029 public class Cortado extends Applet implements Runnable, MouseMotionListener,
3130 MouseListener, ComponentListener, BusHandler, StatusListener, ActionListener {
 31+
3232 private static final long serialVersionUID = 1L;
33 -
3433 private Cortado cortado;
3534 private CortadoPipeline pipeline;
36 -
3735 private String urlString;
3836 private boolean audio;
3937 private boolean video;
@@ -45,8 +43,7 @@
4644 private int bufferLow;
4745 private int bufferHigh;
4846 private int debug;
49 - private double duration;
50 -
 47+ private double durationParam;
5148 private boolean statusRunning;
5249 private Thread statusThread;
5350 public Status status;
@@ -55,19 +52,16 @@
5653 private boolean isBuffering;
5754 private int desiredState;
5855 private boolean started = false;
59 -
6056 private boolean isEOS;
6157 private boolean isError;
62 -
63 - private static final String[] autoBoolVals = { "auto", "true", "false" };
 58+ private static final String[] autoBoolVals = {"auto", "true", "false"};
6459 private static final int BOOL_AUTO = 0;
6560 private static final int BOOL_TRUE = 1;
6661 private static final int BOOL_FALSE = 2;
6762 private int seekable;
6863 private int live;
69 -
7064 private int showStatus;
71 - private static final String[] showStatusVals = { "auto", "show", "hide" };
 65+ private static final String[] showStatusVals = {"auto", "show", "hide"};
7266 public static final int STATUS_AUTO = 0;
7367 public static final int STATUS_SHOW = 1;
7468 public static final int STATUS_HIDE = 2;
@@ -75,49 +69,53 @@
7670 private int hideCounter;
7771 private boolean mayHide;
7872
 73+ // HTML-5 media element attributes
 74+ public double currentTime = 0;
 75+ public double duration = -1;
 76+ public boolean paused;
 77+ public String src;
 78+
7979 private PopupMenu menu;
80 -
8180 private Hashtable params = new Hashtable();
82 -
8381 private Configure configure;
84 -
8582 private Dimension appletDimension;
8683
8784 public String getAppletInfo() {
8885 return "Title: Fluendo media player \nAuthor: Wim Taymans \nA Java based network multimedia player.";
8986 }
 87+
9088 public String getRevision() {
9189 return "$Revision: 4170 $";
9290 }
9391
9492 public String[][] getParameterInfo() {
9593 String[][] info = {
96 - { "url", "URL", "The media file to play" },
97 - { "seekable", "enum",
98 - "Can you seek in this file (auto|true|false) (default auto)" },
99 - { "live", "enum",
100 - "Is this a live stream (disabled PAUSE) (auto|true|false) (default auto)" },
101 - { "duration", "float",
102 - "Total duration of the file in seconds (default unknown)" },
103 - { "audio", "boolean", "Enable audio playback (default true)" },
104 - { "video", "boolean", "Enable video playback (default true)" },
105 - { "statusHeight", "int", "The height of the status area (default 12)" },
106 - { "autoPlay", "boolean", "Automatically start playback (default true)" },
107 - { "showStatus", "enum", "Show status area (auto|show|hide) (default auto)" },
108 - { "hideTimeout", "int", "Timeout in seconds to hide the status area when " +
109 - "showStatus is auto (default 0)" },
110 - { "showSpeaker", "boolean", "Show a speaker icon when audio is available (default true)" },
111 - { "keepAspect", "boolean",
112 - "Use aspect ratio of video (default true)" },
113 - { "bufferSize", "int",
114 - "The size of the prebuffer in Kbytes (default 100)" },
115 - { "bufferLow", "int", "Percent of empty buffer (default 10)" },
116 - { "bufferHigh", "int", "Percent of full buffer (default 70)" },
117 - { "userId", "string",
118 - "userId for basic authentication (default null)" },
119 - { "password", "string",
120 - "password for basic authentication (default null)" },
121 - { "debug", "int", "Debug level 0 - 4 (default = 3)" }, };
 94+ {"url", "URL", "The media file to play"},
 95+ {"seekable", "enum",
 96+ "Can you seek in this file (auto|true|false) (default auto)"},
 97+ {"live", "enum",
 98+ "Is this a live stream (disabled PAUSE) (auto|true|false) (default auto)"},
 99+ {"duration", "float",
 100+ "Total duration of the file in seconds (default unknown)"},
 101+ {"audio", "boolean", "Enable audio playback (default true)"},
 102+ {"video", "boolean", "Enable video playback (default true)"},
 103+ {"statusHeight", "int", "The height of the status area (default 12)"},
 104+ {"autoPlay", "boolean", "Automatically start playback (default true)"},
 105+ {"showStatus", "enum", "Show status area (auto|show|hide) (default auto)"},
 106+ {"hideTimeout", "int", "Timeout in seconds to hide the status area when " +
 107+ "showStatus is auto (default 0)"},
 108+ {"showSpeaker", "boolean", "Show a speaker icon when audio is available (default true)"},
 109+ {"keepAspect", "boolean",
 110+ "Use aspect ratio of video (default true)"},
 111+ {"bufferSize", "int",
 112+ "The size of the prebuffer in Kbytes (default 100)"},
 113+ {"bufferLow", "int", "Percent of empty buffer (default 10)"},
 114+ {"bufferHigh", "int", "Percent of full buffer (default 70)"},
 115+ {"userId", "string",
 116+ "userId for basic authentication (default null)"},
 117+ {"password", "string",
 118+ "password for basic authentication (default null)"},
 119+ {"debug", "int", "Debug level 0 - 4 (default = 3)"},};
122120 return info;
123121 }
124122
@@ -149,50 +147,55 @@
150148 }
151149
152150 public int getEnumParam(String name, String[] vals, String def) {
153 - int res = -1;
 151+ int res = -1;
154152
155 - String val = getParam (name, def);
156 - for (int i=0; i<vals.length;i++) {
157 - if (vals[i].equals (val)) {
158 - res = i;
159 - break;
160 - }
161 - }
162 - if (res != -1)
163 - Debug.info("param \""+name+"\" has enum value \""+res+"\" ("+vals[res]+")");
164 - else
165 - Debug.info("param \""+name+"\" has invalid enum value");
166 - return res;
 153+ String val = getParam(name, def);
 154+ for (int i = 0; i < vals.length; i++) {
 155+ if (vals[i].equals(val)) {
 156+ res = i;
 157+ break;
 158+ }
 159+ }
 160+ if (res != -1) {
 161+ Debug.info("param \"" + name + "\" has enum value \"" + res + "\" (" + vals[res] + ")");
 162+ } else {
 163+ Debug.info("param \"" + name + "\" has invalid enum value");
 164+ }
 165+ return res;
167166 }
 167+
168168 public String getStringParam(String name, String def) {
169 - String res = getParam(name, def);
170 - Debug.info("param \""+name+"\" has string value \""+res+"\"");
171 - return res;
 169+ String res = getParam(name, def);
 170+ Debug.info("param \"" + name + "\" has string value \"" + res + "\"");
 171+ return res;
172172 }
 173+
173174 public boolean getBoolParam(String name, boolean def) {
174 - boolean res;
175 - String defStr = def ? "true" : "false";
176 - String paramVal;
 175+ boolean res;
 176+ String defStr = def ? "true" : "false";
 177+ String paramVal;
177178
178 - paramVal = String.valueOf(getParam(name, defStr));
 179+ paramVal = String.valueOf(getParam(name, defStr));
179180
180 - res = paramVal.equals("true");
181 - res |= paramVal.equals("1");
 181+ res = paramVal.equals("true");
 182+ res |= paramVal.equals("1");
182183
183 - Debug.info("param \""+name+"\" has boolean value \""+res+"\"");
184 - return res;
 184+ Debug.info("param \"" + name + "\" has boolean value \"" + res + "\"");
 185+ return res;
185186 }
 187+
186188 public double getDoubleParam(String name, double def) {
187 - double res;
188 - res = Double.valueOf(getParam(name, ""+def)).doubleValue();
189 - Debug.info("param \""+name+"\" has double value \""+res+"\"");
190 - return res;
 189+ double res;
 190+ res = Double.valueOf(getParam(name, "" + def)).doubleValue();
 191+ Debug.info("param \"" + name + "\" has double value \"" + res + "\"");
 192+ return res;
191193 }
 194+
192195 public int getIntParam(String name, int def) {
193 - int res;
194 - res = Integer.valueOf(getParam(name, ""+def)).intValue();
195 - Debug.info("param \""+name+"\" has int value \""+res+"\"");
196 - return res;
 196+ int res;
 197+ res = Integer.valueOf(getParam(name, "" + def)).intValue();
 198+ Debug.info("param \"" + name + "\" has int value \"" + res + "\"");
 199+ return res;
197200 }
198201
199202 public void shutDown(Throwable error) {
@@ -204,18 +207,19 @@
205208 public synchronized void init() {
206209 cortado = this;
207210
208 - Debug.info("init()");
 211+ Debug.info("init()");
209212
210 - if (pipeline != null)
211 - stop();
 213+ if (pipeline != null) {
 214+ stop();
 215+ }
212216
213217 pipeline = new CortadoPipeline(this);
214218 configure = new Configure();
215219
216 - urlString = getStringParam("url", null);
 220+ src = urlString = getStringParam("url", null);
217221 seekable = getEnumParam("seekable", autoBoolVals, "auto");
218222 live = getEnumParam("live", autoBoolVals, "auto");
219 - duration = getDoubleParam("duration", -1.0);
 223+ durationParam = getDoubleParam("duration", -1.0);
220224 audio = getBoolParam("audio", true);
221225 video = getBoolParam("video", true);
222226 statusHeight = getIntParam("statusHeight", 12);
@@ -230,20 +234,22 @@
231235 debug = getIntParam("debug", 3);
232236 userId = getStringParam("userId", null);
233237 password = getStringParam("password", null);
234 -
 238+
235239 // if audio-only don't hide the status bar
236 - if(!video) hideTimeout = Integer.MAX_VALUE;
 240+ if (!video) {
 241+ hideTimeout = Integer.MAX_VALUE;
 242+ }
237243
238244 Debug.level = debug;
239245 Debug.log(Debug.INFO, "build info: " + configure.buildInfo);
240246 Debug.log(Debug.INFO, "revision: " + getRevision());
241247
242 - /* FIXME, HTTP Range returns 206, which HTTPConnection on MS JVM thinks
243 - * is a fatal error. Disable seeking for now. */
244 - if (System.getProperty("java.vendor").toUpperCase().startsWith ("MICROSOFT", 0)){
245 - Debug.log (Debug.WARNING, "Found MS JVM, disable seeking.");
246 - seekable = BOOL_FALSE;
247 - }
 248+ /* FIXME, HTTP Range returns 206, which HTTPConnection on MS JVM thinks
 249+ * is a fatal error. Disable seeking for now. */
 250+ if (System.getProperty("java.vendor").toUpperCase().startsWith("MICROSOFT", 0)) {
 251+ Debug.log(Debug.WARNING, "Found MS JVM, disable seeking.");
 252+ seekable = BOOL_FALSE;
 253+ }
248254
249255 pipeline.setUrl(urlString);
250256 pipeline.setUserId(userId);
@@ -254,14 +260,13 @@
255261 pipeline.setBufferLow(bufferLow);
256262 pipeline.setBufferHigh(bufferHigh);
257263
258 - URL documentBase;
259 - try {
260 - documentBase = getDocumentBase();
261 - Debug.log(Debug.INFO, "Document base: " + documentBase);
262 - }
263 - catch (Throwable t) {
264 - documentBase = null;
265 - }
 264+ URL documentBase;
 265+ try {
 266+ documentBase = getDocumentBase();
 267+ Debug.log(Debug.INFO, "Document base: " + documentBase);
 268+ } catch (Throwable t) {
 269+ documentBase = null;
 270+ }
266271 pipeline.setDocumentBase(documentBase);
267272 pipeline.setComponent(this);
268273 pipeline.getBus().addHandler(this);
@@ -273,28 +278,42 @@
274279 status.setShowSpeaker(showSpeaker);
275280 status.setHaveAudio(audio);
276281 status.setHavePercent(true);
277 - /* assume live stream unless specified */
278 - if (live == BOOL_FALSE)
279 - status.setLive(false);
280 - else
281 - status.setLive(true);
 282+ /* assume live stream unless specified */
 283+ if (live == BOOL_FALSE) {
 284+ status.setLive(false);
 285+ } else {
 286+ status.setLive(true);
 287+ }
282288
283 - /* assume non seekable stream unless specified */
284 - if (seekable == BOOL_TRUE)
285 - status.setSeekable(true);
286 - else
287 - status.setSeekable(false);
 289+ /* assume non seekable stream unless specified */
 290+ if (seekable == BOOL_TRUE) {
 291+ status.setSeekable(true);
 292+ } else {
 293+ status.setSeekable(false);
 294+ }
288295
289 - status.setDuration(duration);
 296+ if (durationParam < 0) {
 297+ try {
 298+ String base = documentBase != null ? documentBase.toString().substring(0, documentBase.toString().lastIndexOf("/")) : "";
 299+ String docurlstring = urlString.contains("://") ? urlString : base + "/" + urlString;
 300+ Debug.log(Debug.INFO, "trying to determine duration for " + docurlstring);
 301+ URL url = new URL(docurlstring);
 302+ duration = durationParam = new DurationScanner().getDurationForURL(url, userId, password);
 303+ Debug.log(Debug.INFO, "Determined stream duration to be approx. " + durationParam);
 304+ } catch (Exception ex) {
 305+ Debug.log(Debug.WARNING, "Couldn't determine duration for stream.");
 306+ }
 307+ }
 308+
 309+ status.setDuration(durationParam);
290310 inStatus = false;
291311 mayHide = (hideTimeout == 0);
292 - hideCounter = 0;
293 - if (showStatus != STATUS_HIDE) {
294 - status.setVisible(true);
295 - }
296 - else {
297 - status.setVisible(false);
298 - }
 312+ hideCounter = 0;
 313+ if (showStatus != STATUS_HIDE) {
 314+ status.setVisible(true);
 315+ } else {
 316+ status.setVisible(false);
 317+ }
299318
300319 menu = new PopupMenu();
301320 menu.add("About...");
@@ -303,7 +322,7 @@
304323 }
305324
306325 public void actionPerformed(ActionEvent e) {
307 - String command = e.getActionCommand();
 326+ String command = e.getActionCommand();
308327
309328 if (command.equals("About...")) {
310329 AboutFrame about = new AboutFrame(pipeline);
@@ -312,7 +331,7 @@
313332 }
314333
315334 public Graphics getGraphics() {
316 - Dimension dim = getSize();
 335+ Dimension dim = getSize();
317336 Graphics g = super.getGraphics();
318337
319338 if (status != null && status.isVisible()) {
@@ -325,27 +344,31 @@
326345
327346 public void componentHidden(ComponentEvent e) {
328347 }
 348+
329349 public void componentMoved(ComponentEvent e) {
330350 }
 351+
331352 public void componentResized(ComponentEvent e) {
332 - /* reset cached dimension */
333 - appletDimension = super.getSize();
334 - if (pipeline != null) {
335 - pipeline.resize(appletDimension);
336 - }
 353+ /* reset cached dimension */
 354+ appletDimension = super.getSize();
 355+ if (pipeline != null) {
 356+ pipeline.resize(appletDimension);
 357+ }
337358 }
 359+
338360 public void componentShown(ComponentEvent e) {
339 - // reset cached dimension
340 - appletDimension = super.getSize();
341 - Debug.debug("Component shown, size = " + appletDimension);
342 - if (pipeline != null) {
343 - pipeline.resize(appletDimension);
344 - }
 361+ // reset cached dimension
 362+ appletDimension = super.getSize();
 363+ Debug.debug("Component shown, size = " + appletDimension);
 364+ if (pipeline != null) {
 365+ pipeline.resize(appletDimension);
 366+ }
345367 }
346368
347369 public Dimension getSize() {
348 - if (appletDimension == null)
 370+ if (appletDimension == null) {
349371 appletDimension = super.getSize();
 372+ }
350373
351374 return appletDimension;
352375 }
@@ -366,45 +389,44 @@
367390 Debug.log(Debug.INFO, "entering status thread");
368391 while (statusRunning) {
369392 try {
370 - long now;
371 -
372 - now = pipeline.getPosition() / Clock.SECOND;
 393+ long now;
 394+
 395+ currentTime = now = pipeline.getPosition() / Clock.SECOND;
373396 status.setTime(now);
374397
375398 Thread.sleep(1000);
376399
377 - if (hideCounter > 0) {
378 - hideCounter--;
379 - if (hideCounter == 0) {
380 - mayHide = true;
381 - setStatusVisible(false, false);
382 - }
383 - }
 400+ if (hideCounter > 0) {
 401+ hideCounter--;
 402+ if (hideCounter == 0) {
 403+ mayHide = true;
 404+ setStatusVisible(false, false);
 405+ }
 406+ }
384407 } catch (Exception e) {
385408 if (statusRunning) {
386409 Debug.log(Debug.ERROR, "Exception in status thread:");
387410 e.printStackTrace();
388 - }
 411+ }
389412 }
390413 }
391414 Debug.log(Debug.INFO, "exit status thread");
392415 }
393416
394417 public void paint(Graphics g) {
395 - Dimension dim = getSize();
 418+ Dimension dim = getSize();
396419
397420 int dwidth = dim.width;
398421 int dheight = dim.height;
399422
400423 /* sometimes dimension is wrong */
401424 if (dwidth <= 0 || dheight < statusHeight) {
402 - appletDimension = null;
403 - Debug.log (Debug.WARNING,
404 - "paint aborted: appletDimension wrong; dwidth " + dwidth
405 - + ", dheight " + dheight + ", statusHeight " + statusHeight);
406 - return;
407 - }
408 -
 425+ appletDimension = null;
 426+ Debug.log(Debug.WARNING,
 427+ "paint aborted: appletDimension wrong; dwidth " + dwidth + ", dheight " + dheight + ", statusHeight " + statusHeight);
 428+ return;
 429+ }
 430+
409431 if (status != null && status.isVisible()) {
410432 status.setBounds(0, dheight - statusHeight, dwidth, statusHeight);
411433 status.paint(g);
@@ -415,43 +437,46 @@
416438 /* no change, do nothing */
417439 if (status.isVisible() == b) {
418440 return;
419 - }
 441+ }
420442
421 - /* refuse to hide when hideTimeout did not expire */
422 - if (!b && !mayHide) {
 443+ /* refuse to hide when hideTimeout did not expire */
 444+ if (!b && !mayHide) {
423445 return;
424 - }
 446+ }
425447
426 - if (!force) {
427 - if (showStatus == STATUS_SHOW && !b) {
428 - return;
429 - }
430 - if (showStatus == STATUS_HIDE && b) {
431 - return;
432 - }
433 - }
434 - /* never hide when we are in error */
435 - if (isError && !b) {
 448+ if (!force) {
 449+ if (showStatus == STATUS_SHOW && !b) {
 450+ return;
 451+ }
 452+ if (showStatus == STATUS_HIDE && b) {
 453+ return;
 454+ }
 455+ }
 456+ /* never hide when we are in error */
 457+ if (isError && !b) {
436458 return;
437 - }
438 -
 459+ }
 460+
439461 /* don't make invisible when the mouse pointer is inside status area */
440462 if (inStatus && !b) {
441463 b = true;
442 - }
 464+ }
443465
444 - if(b != status.isVisible())
445 - Debug.log (Debug.INFO, "Status: "+ (b ? "Show" : "Hide"));
446 -
447 - if(b) hideCounter = hideTimeout;
 466+ if (b != status.isVisible()) {
 467+ Debug.log(Debug.INFO, "Status: " + (b ? "Show" : "Hide"));
 468+ }
 469+
 470+ if (b) {
 471+ hideCounter = hideTimeout;
 472+ }
448473 status.setVisible(b);
449474 repaint();
450475 }
451476
452477 private boolean intersectStatus(MouseEvent e) {
453 - int y = e.getY();
454 - int max = getSize().height;
455 - int top = max - statusHeight;
 478+ int y = e.getY();
 479+ int max = getSize().height;
 480+ int top = max - statusHeight;
456481
457482 inStatus = y > top && y < max;
458483 return inStatus;
@@ -484,10 +509,9 @@
485510 int y = getSize().height - statusHeight;
486511 e.translatePoint(0, -y);
487512 ((MouseListener) status).mouseReleased(e);
 513+ } else {
 514+ status.cancelMouseOperation();
488515 }
489 - else {
490 - status.cancelMouseOperation();
491 - }
492516 }
493517
494518 public void mouseDragged(MouseEvent e) {
@@ -497,8 +521,8 @@
498522 e.translatePoint(0, -y);
499523 ((MouseMotionListener) status).mouseDragged(e);
500524 } /*else {
501 - setStatusVisible(false, false);
502 - }*/
 525+ setStatusVisible(false, false);
 526+ }*/
503527 }
504528
505529 public void mouseMoved(MouseEvent e) {
@@ -508,338 +532,372 @@
509533 e.translatePoint(0, -y);
510534 ((MouseMotionListener) status).mouseMoved(e);
511535 } /*else {
512 - setStatusVisible(false, false);
 536+ setStatusVisible(false, false);
513537 }*/
514538 setStatusVisible(true, false);
515539 }
516540
517541 public void handleMessage(Message msg) {
518542 switch (msg.getType()) {
519 - case Message.WARNING:
520 - Debug.info(msg.toString());
521 - break;
522 - case Message.ERROR:
523 - Debug.info(msg.toString());
524 - if (!isError) {
525 - status.setMessage(msg.parseErrorString());
526 - status.setState(Status.STATE_STOPPED);
527 - pipeline.setState(Element.STOP);
528 - setStatusVisible(true, true);
529 - isError = true;
530 - }
531 - break;
532 - case Message.EOS:
533 - Debug.log(Debug.INFO, "EOS: playback ended");
534 - if (!isError) {
535 - status.setState(Status.STATE_STOPPED);
536 - status.setMessage("Playback ended");
537 - isEOS = true;
538 - pipeline.setState(Element.STOP);
539 - setStatusVisible(true, false);
540 - }
541 - break;
542 - case Message.STREAM_STATUS:
543 - Debug.info(msg.toString());
544 - break;
545 - case Message.RESOURCE:
546 - if (!isError) {
547 - status.setMessage(msg.parseResourceString());
548 - setStatusVisible(true, false);
549 - }
550 - break;
551 - case Message.DURATION:
552 - long duration;
 543+ case Message.WARNING:
 544+ Debug.info(msg.toString());
 545+ break;
 546+ case Message.ERROR:
 547+ Debug.info(msg.toString());
 548+ if (!isError) {
 549+ status.setMessage(msg.parseErrorString());
 550+ status.setState(Status.STATE_STOPPED);
 551+ pipeline.setState(Element.STOP);
 552+ setStatusVisible(true, true);
 553+ isError = true;
 554+ }
 555+ break;
 556+ case Message.EOS:
 557+ Debug.log(Debug.INFO, "EOS: playback ended");
 558+ if (!isError) {
 559+ status.setState(Status.STATE_STOPPED);
 560+ status.setMessage("Playback ended");
 561+ isEOS = true;
 562+ pipeline.setState(Element.STOP);
 563+ setStatusVisible(true, false);
 564+ }
 565+ break;
 566+ case Message.STREAM_STATUS:
 567+ Debug.info(msg.toString());
 568+ break;
 569+ case Message.RESOURCE:
 570+ if (!isError) {
 571+ status.setMessage(msg.parseResourceString());
 572+ setStatusVisible(true, false);
 573+ }
 574+ break;
 575+ case Message.DURATION:
 576+ long duration;
553577
554 - duration = msg.parseDurationValue();
555 -
556 - status.setByteDuration(duration);
 578+ duration = msg.parseDurationValue();
557579
558 - Debug.log(Debug.DEBUG, "got duration: "+duration);
559 - if (duration != -1) {
560 - /* we got duration, we can enable automatic setting */
561 - if (seekable == BOOL_AUTO)
562 - status.setSeekable(true);
563 - if (live == BOOL_AUTO)
564 - status.setLive(false);
565 - }
566 - break;
567 - case Message.BUFFERING:
568 - boolean busy;
569 - int percent;
 580+ status.setByteDuration(duration);
570581
571 - if (isError)
572 - break;
 582+ Debug.log(Debug.DEBUG, "got duration: " + duration);
 583+ if (duration != -1) {
 584+ /* we got duration, we can enable automatic setting */
 585+ if (seekable == BOOL_AUTO) {
 586+ status.setSeekable(true);
 587+ }
 588+ if (live == BOOL_AUTO) {
 589+ status.setLive(false);
 590+ }
 591+ }
 592+ break;
 593+ case Message.BUFFERING:
 594+ boolean busy;
 595+ int percent;
573596
574 - busy = msg.parseBufferingBusy();
575 - percent = msg.parseBufferingPercent();
 597+ if (isError) {
 598+ break;
 599+ }
576600
577 - if (busy) {
578 - if (!isBuffering) {
579 - Debug.log(Debug.INFO, "PAUSE: we are buffering");
580 - if (desiredState == Element.PLAY)
581 - pipeline.setState(Element.PAUSE);
582 - isBuffering = true;
583 - setStatusVisible(true, false);
584 - }
585 - status.setBufferPercent(busy, percent);
586 - }
587 - else {
588 - if (isBuffering) {
589 - Debug.log(Debug.INFO, "PLAY: we finished buffering");
590 - if (desiredState == Element.PLAY)
591 - pipeline.setState(Element.PLAY);
592 - isBuffering = false;
593 - setStatusVisible(false, false);
594 - }
595 - status.setBufferPercent(busy, percent);
596 - }
597 - break;
598 - case Message.STATE_CHANGED:
599 - if (msg.getSrc() == pipeline) {
600 - int old, next;
 601+ busy = msg.parseBufferingBusy();
 602+ percent = msg.parseBufferingPercent();
601603
602 - old = msg.parseStateChangedOld();
603 - next = msg.parseStateChangedNext();
 604+ if (busy) {
 605+ if (!isBuffering) {
 606+ Debug.log(Debug.INFO, "PAUSE: we are buffering");
 607+ if (desiredState == Element.PLAY) {
 608+ pipeline.setState(Element.PAUSE);
 609+ }
 610+ isBuffering = true;
 611+ setStatusVisible(true, false);
 612+ }
 613+ status.setBufferPercent(busy, percent);
 614+ } else {
 615+ if (isBuffering) {
 616+ Debug.log(Debug.INFO, "PLAY: we finished buffering");
 617+ if (desiredState == Element.PLAY) {
 618+ pipeline.setState(Element.PLAY);
 619+ }
 620+ isBuffering = false;
 621+ setStatusVisible(false, false);
 622+ }
 623+ status.setBufferPercent(busy, percent);
 624+ }
 625+ break;
 626+ case Message.STATE_CHANGED:
 627+ if (msg.getSrc() == pipeline) {
 628+ int old, next;
604629
605 - switch (next) {
606 - case Element.PAUSE:
607 - if (!isError && !isEOS) {
608 - status.setMessage("Paused");
609 - }
610 - status.setState(Status.STATE_PAUSED);
611 - break;
612 - case Element.PLAY:
613 - if (!isError && !isEOS) {
614 - status.setMessage("Playing");
615 - setStatusVisible(false, false);
616 - if (!mayHide)
617 - hideCounter = hideTimeout;
618 - }
619 - status.setState(Status.STATE_PLAYING);
620 - break;
621 - case Element.STOP:
622 - if (!isError && !isEOS) {
623 - status.setMessage("Stopped");
624 - setStatusVisible(true, false);
625 - }
626 - status.setState(Status.STATE_STOPPED);
627 - break;
 630+ old = msg.parseStateChangedOld();
 631+ next = msg.parseStateChangedNext();
 632+
 633+ switch (next) {
 634+ case Element.PAUSE:
 635+ if (!isError && !isEOS) {
 636+ status.setMessage("Paused");
 637+ }
 638+ status.setState(Status.STATE_PAUSED);
 639+ break;
 640+ case Element.PLAY:
 641+ if (!isError && !isEOS) {
 642+ status.setMessage("Playing");
 643+ setStatusVisible(false, false);
 644+ if (!mayHide) {
 645+ hideCounter = hideTimeout;
 646+ }
 647+ }
 648+ status.setState(Status.STATE_PLAYING);
 649+ break;
 650+ case Element.STOP:
 651+ if (!isError && !isEOS) {
 652+ status.setMessage("Stopped");
 653+ setStatusVisible(true, false);
 654+ }
 655+ status.setState(Status.STATE_STOPPED);
 656+ break;
 657+ }
628658 }
629 - }
630 - break;
631 - case Message.BYTEPOSITION:
632 - status.setBytePosition(msg.parseBytePosition());
633 - break;
634 - default:
635 - break;
 659+ break;
 660+ case Message.BYTEPOSITION:
 661+ status.setBytePosition(msg.parseBytePosition());
 662+ break;
 663+ default:
 664+ break;
636665 }
637666 }
638667
639668 public void doPause() {
640 - isError = false;
641 - isEOS = false;
642 - status.setMessage("Pause");
643 - desiredState = Element.PAUSE;
644 - pipeline.setState(desiredState);
 669+ isError = false;
 670+ isEOS = false;
 671+ paused = true;
 672+ status.setMessage("Pause");
 673+ desiredState = Element.PAUSE;
 674+ pipeline.setState(desiredState);
645675 }
 676+
646677 public void doPlay() {
647 - isError = false;
648 - isEOS = false;
649 - status.setMessage("Play");
650 - desiredState = Element.PLAY;
651 - pipeline.setState(desiredState);
 678+ isError = false;
 679+ isEOS = false;
 680+ paused = false;
 681+ status.setMessage("Play");
 682+ desiredState = Element.PLAY;
 683+ pipeline.setState(desiredState);
652684 }
 685+
653686 public void doStop() {
654 - status.setMessage("Stop");
655 - desiredState = Element.STOP;
656 - pipeline.setState(desiredState);
 687+ status.setMessage("Stop");
 688+ desiredState = Element.STOP;
 689+ pipeline.setState(desiredState);
657690 }
658691
659692 public void doSeek(double aPos) {
660 - boolean res;
661 - com.fluendo.jst.Event event;
 693+ boolean res;
 694+ com.fluendo.jst.Event event;
662695
663 - /* get value, convert to PERCENT and construct seek event */
664 - event = com.fluendo.jst.Event.newSeek(Format.PERCENT,
665 - (int) (aPos * 100.0 * Format.PERCENT_SCALE));
 696+ /* get value, convert to PERCENT and construct seek event */
 697+ event = com.fluendo.jst.Event.newSeek(Format.PERCENT,
 698+ (int) (aPos * 100.0 * Format.PERCENT_SCALE));
666699
667 - /* send event to pipeline */
668 - res = pipeline.sendEvent(event);
669 - if (!res) {
670 - Debug.log(Debug.WARNING, "seek failed");
671 - }
 700+ /* send event to pipeline */
 701+ res = pipeline.sendEvent(event);
 702+ if (!res) {
 703+ Debug.log(Debug.WARNING, "seek failed");
 704+ }
672705 }
673706
674707 public double getPlayPosition() {
675 - return (double) pipeline.getPosition() / Clock.SECOND;
 708+ return (double) pipeline.getPosition() / Clock.SECOND;
676709 }
677710
678711 public void newState(int aState) {
679712 int ret;
680713 switch (aState) {
681 - case Status.STATE_PAUSED:
682 - doPause();
683 - break;
684 - case Status.STATE_PLAYING:
685 - doPlay();
686 - break;
687 - case Status.STATE_STOPPED:
688 - doStop();
689 - break;
690 - default:
691 - break;
 714+ case Status.STATE_PAUSED:
 715+ doPause();
 716+ break;
 717+ case Status.STATE_PLAYING:
 718+ doPlay();
 719+ break;
 720+ case Status.STATE_STOPPED:
 721+ doStop();
 722+ break;
 723+ default:
 724+ break;
692725 }
693726 }
 727+
694728 public void newSeek(double aPos) {
695 - doSeek (aPos);
 729+ doSeek(aPos);
696730 }
697731
698732 public synchronized void start() {
699733 int res;
700734
701 - Debug.info("Application starting");
 735+ Debug.info("Application starting");
702736
703737 addComponentListener(this);
704738 addMouseListener(this);
705739 addMouseMotionListener(this);
706740 status.addStatusListener(this);
707741
708 - if (autoPlay)
709 - desiredState = Element.PLAY;
710 - else
711 - desiredState = Element.PAUSE;
 742+ if (autoPlay) {
 743+ desiredState = Element.PLAY;
 744+ } else {
 745+ desiredState = Element.PAUSE;
 746+ }
712747
713748 res = pipeline.setState(desiredState);
714749
715 - if (statusThread != null)
716 - throw new RuntimeException ("invalid state");
 750+ if (statusThread != null) {
 751+ throw new RuntimeException("invalid state");
 752+ }
717753
718 - statusThread = new Thread(this, "cortado-StatusThread-"+Debug.genId());
719 - statusRunning = true;
 754+ statusThread = new Thread(this, "cortado-StatusThread-" + Debug.genId());
 755+ statusRunning = true;
720756 statusThread.start();
721757 }
722758
723759 public synchronized void stop() {
724 - Debug.info("Application stopping...");
 760+ Debug.info("Application stopping...");
725761
726762 status.removeStatusListener(this);
727763 removeMouseMotionListener(this);
728764 removeMouseListener(this);
729765 removeComponentListener(this);
730766
731 - statusRunning = false;
 767+ statusRunning = false;
732768 desiredState = Element.STOP;
733 - if (pipeline != null) {
734 - try {
735 - pipeline.setState(desiredState);
736 - }
737 - catch (Throwable e) {
738 - }
739 - try {
740 - pipeline.shutDown();
741 - }
742 - catch (Throwable e) {
743 - }
744 - pipeline = null;
745 - }
 769+ if (pipeline != null) {
 770+ try {
 771+ pipeline.setState(desiredState);
 772+ } catch (Throwable e) {
 773+ }
 774+ try {
 775+ pipeline.shutDown();
 776+ } catch (Throwable e) {
 777+ }
 778+ pipeline = null;
 779+ }
746780 if (statusThread != null) {
747 - try {
748 - statusThread.interrupt();
749 - } catch (Throwable e) {
750 - }
751 - try {
752 - statusThread.join();
753 - } catch (Throwable e) {
754 - }
755 - statusThread = null;
756 - }
757 - Debug.info("Application stopped");
 781+ try {
 782+ statusThread.interrupt();
 783+ } catch (Throwable e) {
 784+ }
 785+ try {
 786+ statusThread.join();
 787+ } catch (Throwable e) {
 788+ }
 789+ statusThread = null;
 790+ }
 791+ Debug.info("Application stopped");
758792 }
759793
760794 public int getStatusHeight() {
761 - return statusHeight;
 795+ return statusHeight;
762796 }
763797
764798 public int getShowStatus() {
765 - return showStatus;
 799+ return showStatus;
766800 }
 801+
 802+ /* HTML-5 media element methods */
 803+ public synchronized void play() {
 804+ doPlay();
 805+ }
 806+
 807+ public synchronized void pause() {
 808+ doPause();
 809+ }
767810 }
768811
769812 /* dialog box */
 813+class AppFrame extends Frame
 814+ implements WindowListener {
770815
771 -class AppFrame extends Frame
772 - implements WindowListener {
773 - public AppFrame(String title) {
774 - super(title);
775 - addWindowListener(this);
776 - }
777 - public void windowClosing(WindowEvent e) {
778 - setVisible(false);
779 - dispose();
780 - System.exit(0);
781 - }
782 - public void windowClosed(WindowEvent e) {}
783 - public void windowDeactivated(WindowEvent e) {}
784 - public void windowActivated(WindowEvent e) {}
785 - public void windowDeiconified(WindowEvent e) {}
786 - public void windowIconified(WindowEvent e) {}
787 - public void windowOpened(WindowEvent e) {}
788 -}
 816+ public AppFrame(String title) {
 817+ super(title);
 818+ addWindowListener(this);
 819+ }
789820
790 -class AboutFrame extends AppFrame {
791 - Dialog d;
 821+ public void windowClosing(WindowEvent e) {
 822+ setVisible(false);
 823+ dispose();
 824+ System.exit(0);
 825+ }
792826
 827+ public void windowClosed(WindowEvent e) {
 828+ }
 829+
 830+ public void windowDeactivated(WindowEvent e) {
 831+ }
 832+
 833+ public void windowActivated(WindowEvent e) {
 834+ }
 835+
 836+ public void windowDeiconified(WindowEvent e) {
 837+ }
 838+
 839+ public void windowIconified(WindowEvent e) {
 840+ }
 841+
 842+ public void windowOpened(WindowEvent e) {
 843+ }
 844+}
 845+
 846+class AboutFrame extends AppFrame {
 847+
 848+ Dialog d;
 849+
793850 public String getRevision() {
794851 return "$Revision: 4170 $";
795852 }
796 -
797 - public AboutFrame(CortadoPipeline pipeline) {
798 - super("AboutFrame");
799853
800 - Configure configure = new Configure();
801 - SourceInfo info = new SourceInfo();
 854+ public AboutFrame(CortadoPipeline pipeline) {
 855+ super("AboutFrame");
802856
803 - setSize(200, 100);
804 - Button dbtn;
805 - d = new Dialog(this, "About Cortado", false);
806 - d.setVisible(true);
 857+ Configure configure = new Configure();
 858+ SourceInfo info = new SourceInfo();
807859
808 - TextArea ta = new TextArea("", 8, 40, TextArea.SCROLLBARS_NONE);
809 - d.add(ta);
810 - ta.appendText("This is Cortado " + configure.buildVersion + ".\n");
811 - ta.appendText("Brought to you by Wim Taymans.\n");
812 - ta.appendText("(C) Copyright 2004,2005,2006 Fluendo\n\n");
813 - ta.appendText("Built on " + configure.buildDate + "\n");
814 - ta.appendText("Built in " + configure.buildType + " mode.\n");
815 - ta.appendText("Built from SVN branch " + info.branch + ", revision " +
816 - info.revision + "\n");
817 - ta.appendText("Running on Java VM " + System.getProperty("java.version")
818 - + " from " + System.getProperty("java.vendor") + "\n");
 860+ setSize(200, 100);
 861+ Button dbtn;
 862+ d = new Dialog(this, "About Cortado", false);
 863+ d.setVisible(true);
819864
820 - if (pipeline.isAudioEnabled()) {
821 - if (pipeline.usingJavaX) {
822 - ta.appendText("Using the javax.sound backend.");
823 - } else {
824 - ta.appendText("Using the sun.audio backend.\n\n");
825 - ta.appendText("NOTE: you should install the Java(TM) from Sun for better audio quality.");
826 - }
827 - }
 865+ TextArea ta = new TextArea("", 8, 40, TextArea.SCROLLBARS_NONE);
 866+ d.add(ta);
 867+ ta.appendText("This is Cortado " + configure.buildVersion + ".\n");
 868+ ta.appendText("Brought to you by Wim Taymans.\n");
 869+ ta.appendText("(C) Copyright 2004,2005,2006 Fluendo\n\n");
 870+ ta.appendText("Built on " + configure.buildDate + "\n");
 871+ ta.appendText("Built in " + configure.buildType + " mode.\n");
 872+ ta.appendText("Built from SVN branch " + info.branch + ", revision " +
 873+ info.revision + "\n");
 874+ ta.appendText("Running on Java VM " + System.getProperty("java.version") + " from " + System.getProperty("java.vendor") + "\n");
828875
829 - d.add(dbtn = new Button("OK"),
830 - BorderLayout.SOUTH);
 876+ if (pipeline.isAudioEnabled()) {
 877+ if (pipeline.usingJavaX) {
 878+ ta.appendText("Using the javax.sound backend.");
 879+ } else {
 880+ ta.appendText("Using the sun.audio backend.\n\n");
 881+ ta.appendText("NOTE: you should install the Java(TM) from Sun for better audio quality.");
 882+ }
 883+ }
831884
832 - Dimension dim = d.getPreferredSize();
833 - dim.height += 30;
834 - d.setSize(dim);
835 - dbtn.addActionListener(new ActionListener() {
836 - public void actionPerformed(ActionEvent e) {
837 - d.setVisible(false);
838 - }
839 - });
840 - d.addWindowListener(new WindowAdapter() {
841 - public void windowClosing(WindowEvent e) {
842 - d.setVisible(false);
843 - }
844 - });
845 - }
 885+ d.add(dbtn = new Button("OK"),
 886+ BorderLayout.SOUTH);
 887+
 888+ Dimension dim = d.getPreferredSize();
 889+ dim.height += 30;
 890+ d.setSize(dim);
 891+ dbtn.addActionListener(new ActionListener() {
 892+
 893+ public void actionPerformed(ActionEvent e) {
 894+ d.setVisible(false);
 895+ }
 896+ });
 897+ d.addWindowListener(new WindowAdapter() {
 898+
 899+ public void windowClosing(WindowEvent e) {
 900+ d.setVisible(false);
 901+ }
 902+ });
 903+ }
846904 }

Comments

#Comment by Brion VIBBER (talk | contribs)   23:16, 10 December 2008

Awesome!

Status & tagging log