Bug 539620 - Deprecate X-Content-Duration for Content-Duration. r=chris.double
authorRalph Giles <giles@xiph.org>
Wed, 27 Jan 2010 13:29:26 +0100
changeset 37543 3cdf3bd2608ca5bc4c8e50d8b9f43d2e1917a11d
parent 37542 51caa47ea5bd9d657af20e7eb5cd32df375b588a
child 37544 4363b7bb201c4778893369d279c424abe45b19b3
child 46621 15030b53f5f8e7e958fe751257bfc61353d5c65e
push id11367
push userdgottwald@mozilla.com
push dateWed, 27 Jan 2010 12:29:58 +0000
treeherdermozilla-central@3cdf3bd2608c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschris.double
bugs539620
milestone1.9.3a1pre
Bug 539620 - Deprecate X-Content-Duration for Content-Duration. r=chris.double
content/media/nsMediaStream.cpp
content/media/test/Makefile.in
content/media/test/contentDuration1.sjs
content/media/test/contentDuration4.sjs
content/media/test/contentDuration5.sjs
content/media/test/contentDuration6.sjs
content/media/test/contentDuration7.sjs
content/media/test/manifest.js
content/media/test/test_contentDuration7.html
--- a/content/media/nsMediaStream.cpp
+++ b/content/media/nsMediaStream.cpp
@@ -190,28 +190,33 @@ nsMediaChannelStream::OnStartRequest(nsI
     }
 
     nsCAutoString ranges;
     hc->GetResponseHeader(NS_LITERAL_CSTRING("Accept-Ranges"),
                           ranges);
     PRBool acceptsRanges = ranges.EqualsLiteral("bytes");
 
     if (mOffset == 0) {
-      // Look for duration headers from known Ogg content systems. In the case
-      // of multiple options for obtaining the duration the order of precedence is;
+      // Look for duration headers from known Ogg content systems.
+      // In the case of multiple options for obtaining the duration
+      // the order of precedence is:
       // 1) The Media resource metadata if possible (done by the decoder itself).
-      // 2) X-Content-Duration.
-      // 3) x-amz-meta-content-duration.
-      // 4) Perform a seek in the decoder to find the value.
+      // 2) Content-Duration message header.
+      // 3) X-AMZ-Meta-Content-Duration.
+      // 4) X-Content-Duration.
+      // 5) Perform a seek in the decoder to find the value.
       nsCAutoString durationText;
       PRInt32 ec = 0;
-      rv = hc->GetResponseHeader(NS_LITERAL_CSTRING("X-Content-Duration"), durationText);
+      rv = hc->GetResponseHeader(NS_LITERAL_CSTRING("Content-Duration"), durationText);
       if (NS_FAILED(rv)) {
         rv = hc->GetResponseHeader(NS_LITERAL_CSTRING("X-AMZ-Meta-Content-Duration"), durationText);
       }
+      if (NS_FAILED(rv)) {
+        rv = hc->GetResponseHeader(NS_LITERAL_CSTRING("X-Content-Duration"), durationText);
+      }
 
       if (NS_SUCCEEDED(rv)) {
         float duration = durationText.ToFloat(&ec);
         if (ec == NS_OK && duration >= 0) {
           mDecoder->SetDuration(PRInt64(NS_round(duration*1000)));
         }
       }
     }
--- a/content/media/test/Makefile.in
+++ b/content/media/test/Makefile.in
@@ -188,16 +188,17 @@ ifdef MOZ_OGG
 		test_bug495319.html \
 		test_closing_connections.html \
 		test_contentDuration1.html \
 		test_contentDuration2.html \
 		test_contentDuration3.html \
 		test_contentDuration4.html \
 		test_contentDuration5.html \
 		test_contentDuration6.html \
+		test_contentDuration7.html \
 		test_delay_load.html \
 		test_duration1.html \
 		test_ended1.html \
 		test_ended2.html \
 		test_error_on_404.html \
 		test_info_leak.html \
 		test_onloadedmetadata.html \
 		test_load_candidates.html \
@@ -212,16 +213,17 @@ ifdef MOZ_OGG
 		test_timeupdate2.html \
 		redirect.sjs \
 		contentDuration1.sjs \
 		contentDuration2.sjs \
 		contentDuration3.sjs \
 		contentDuration4.sjs \
 		contentDuration5.sjs \
 		contentDuration6.sjs \
+		contentDuration7.sjs \
 		$(NULL)
 # These tests disabled until we figure out random failures.
 # Bug 492821:
 # test_videoDocumentTitle.html
 # Bug 493692:
 # test_autobuffer2.html
 ifneq ($(OS_ARCH),WINNT)
 # These tests are disabled on windows until we
--- a/content/media/test/contentDuration1.sjs
+++ b/content/media/test/contentDuration1.sjs
@@ -10,14 +10,14 @@ function handleRequest(request, response
   var paths = "tests/content/media/test/320x240.ogv";
   var split = paths.split("/");
   for(var i = 0; i < split.length; ++i) {
     file.append(split[i]);
   }
   fis.init(file, -1, -1, false);
   bis.setInputStream(fis);
   var bytes = bis.readBytes(bis.available());
-  response.setHeader("X-Content-Duration", "0.233", false);
+  response.setHeader("Content-Duration", "0.233", false);
   response.setHeader("Content-Length", ""+bytes.length, false);
   response.setHeader("Content-Type", "video/ogg", false);
   response.write(bytes, bytes.length);
   bis.close();
 }
--- a/content/media/test/contentDuration4.sjs
+++ b/content/media/test/contentDuration4.sjs
@@ -11,14 +11,14 @@ function handleRequest(request, response
   var split = paths.split("/");
   for(var i = 0; i < split.length; ++i) {
     file.append(split[i]);
   }
   fis.init(file, -1, -1, false);
   bis.setInputStream(fis);
   var bytes = bis.readBytes(bis.available());
   response.setStatusLine(request.httpVersion, 200, "Content Follows");
-  response.setHeader("X-Content-Duration", "-5", false);
+  response.setHeader("Content-Duration", "-5", false);
   response.setHeader("Content-Length", ""+bytes.length, false);
   response.setHeader("Content-Type", "video/ogg", false);
   response.write(bytes, bytes.length);
   bis.close();
 }
--- a/content/media/test/contentDuration5.sjs
+++ b/content/media/test/contentDuration5.sjs
@@ -11,13 +11,13 @@ function handleRequest(request, response
   var split = paths.split("/");
   for(var i = 0; i < split.length; ++i) {
     file.append(split[i]);
   }
   fis.init(file, -1, -1, false);
   bis.setInputStream(fis);
   var bytes = bis.readBytes(bis.available());
   response.setStatusLine(request.httpVersion, 200, "Content Follows");
-  response.setHeader("X-Content-Duration", "-6", false);
+  response.setHeader("Content-Duration", "-6", false);
   response.setHeader("Content-Length", ""+bytes.length, false);
   response.setHeader("Content-Type", "video/ogg", false);
   response.write(bytes, bytes.length);
 }
--- a/content/media/test/contentDuration6.sjs
+++ b/content/media/test/contentDuration6.sjs
@@ -11,14 +11,14 @@ function handleRequest(request, response
   var split = paths.split("/");
   for(var i = 0; i < split.length; ++i) {
     file.append(split[i]);
   }
   fis.init(file, -1, -1, false);
   bis.setInputStream(fis);
   var bytes = bis.readBytes(bis.available());
   response.setStatusLine(request.httpVersion, 200, "Content Follows");
-  response.setHeader("X-Content-Duration", "Invalid Float Value", false);
+  response.setHeader("Content-Duration", "Invalid Float Value", false);
   response.setHeader("Content-Length", ""+bytes.length, false);
   response.setHeader("Content-Type", "video/ogg", false);
   response.write(bytes, bytes.length);
   bis.close();
 }
new file mode 100644
--- /dev/null
+++ b/content/media/test/contentDuration7.sjs
@@ -0,0 +1,23 @@
+function handleRequest(request, response)
+{
+  var file = Components.classes["@mozilla.org/file/directory_service;1"].
+                        getService(Components.interfaces.nsIProperties).
+                        get("CurWorkD", Components.interfaces.nsILocalFile);
+  var fis  = Components.classes['@mozilla.org/network/file-input-stream;1'].
+                        createInstance(Components.interfaces.nsIFileInputStream);
+  var bis  = Components.classes["@mozilla.org/binaryinputstream;1"].
+                        createInstance(Components.interfaces.nsIBinaryInputStream);
+  var paths = "tests/content/media/test/320x240.ogv";
+  var split = paths.split("/");
+  for(var i = 0; i < split.length; ++i) {
+    file.append(split[i]);
+  }
+  fis.init(file, -1, -1, false);
+  bis.setInputStream(fis);
+  var bytes = bis.readBytes(bis.available());
+  response.setHeader("X-Content-Duration", "0.233", false);
+  response.setHeader("Content-Length", ""+bytes.length, false);
+  response.setHeader("Content-Type", "video/ogg", false);
+  response.write(bytes, bytes.length);
+  bis.close();
+}
--- a/content/media/test/manifest.js
+++ b/content/media/test/manifest.js
@@ -8,17 +8,17 @@ var gSmallTests = [
   { name:"r11025_s16_c1.wav", type:"audio/x-wav", duration:1.0 },
   { name:"320x240.ogv", type:"video/ogg", width:320, height:240 },
   { name:"bogus.duh", type:"bogus/duh" }
 ];
 
 // Used by test_mozLoadFrom.  Need one test file per decoder backend, plus
 // anything for testing clone-specific bugs.
 var gCloneTests = gSmallTests.concat([
-  // Actual duration is ~200ms, we have X-Content-Duration lie about it.
+  // Actual duration is ~200ms, we have Content-Duration lie about it.
   { name:"bug520908.ogv", type:"video/ogg", duration:9000 },
 ]);
 
 // These are files that we want to make sure we can play through.  We can
 // also check metadata.  Put files of the same type together in this list so if
 // something crashes we have some idea of which backend is responsible.
 // Used by test_playback, which expects no error event and one ended event.
 var gPlayTests = [
new file mode 100644
--- /dev/null
+++ b/content/media/test/test_contentDuration7.html
@@ -0,0 +1,27 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+  <title>Media test: X-Content-Duration</title>
+  <script type="text/javascript" src="/MochiKit/packed.js"></script>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+function on_metadataloaded() {
+  var v = document.getElementById('v');
+  var d = Math.round(v.duration*1000);
+  ok(d == 233, "Checking duration: " + d);
+  SimpleTest.finish();
+}
+
+SimpleTest.waitForExplicitFinish();
+</script>
+</pre>
+<video id='v'
+       src='contentDuration7.sjs'
+       onloadedmetadata='on_metadataloaded();'></video>
+</body>
+</html>