Backed out changesets bde36c2eacc0 and 8dc40bbe844e (bug 862088) for causing bug 875769.
authorRyan VanderMeulen <ryanvm@gmail.com>
Sat, 25 May 2013 09:21:29 -0400
changeset 144379 218785bab4bdee32764eeb142656476d7ffa33df
parent 144378 512f5aab943e2da8623153995e7e5e2b99056d74
child 144380 51ed5a22e3c2639059ccf404230d6718bfcfbe07
child 144472 1df6805a09ec71d3c5e9f770432f7e7da532babf
child 144485 00a26ef87463b46b68ac8cddea07434abc52fd8b
child 144491 82f30e56c1d9eddce699e465d36ff1ac754baed9
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs862088, 875769
milestone24.0a1
backs outbde36c2eacc048fe0cbe17828a20e1e788192650
8dc40bbe844e2b9a8742abffbe0476e32ce86095
first release with
nightly linux32
218785bab4bd / 24.0a1 / 20130525062525 / files
nightly linux64
218785bab4bd / 24.0a1 / 20130525062525 / files
nightly mac
218785bab4bd / 24.0a1 / 20130525062525 / files
nightly win32
218785bab4bd / 24.0a1 / 20130525062525 / files
nightly win64
218785bab4bd / 24.0a1 / 20130525062525 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changesets bde36c2eacc0 and 8dc40bbe844e (bug 862088) for causing bug 875769.
toolkit/components/mediasniffer/Makefile.in
toolkit/components/mediasniffer/mp3sniff.c
toolkit/components/mediasniffer/mp3sniff.h
toolkit/components/mediasniffer/nsMediaSniffer.cpp
toolkit/components/mediasniffer/test/unit/data/id3tags.mp3
toolkit/components/mediasniffer/test/unit/data/notags-bad.mp3
toolkit/components/mediasniffer/test/unit/data/notags.mp3
toolkit/components/mediasniffer/test/unit/test_mediasniffer_ext.js
toolkit/components/mediasniffer/test/unit/test_mediasniffer_webm.js
toolkit/components/mediasniffer/test/unit/xpcshell.ini
--- a/toolkit/components/mediasniffer/Makefile.in
+++ b/toolkit/components/mediasniffer/Makefile.in
@@ -16,14 +16,10 @@ MODULE_NAME = nsMediaSnifferModule
 IS_COMPONENT = 1
 
 
 CPPSRCS = \
     nsMediaSniffer.cpp \
     nsMediaSnifferModule.cpp \
     $(NULL)
 
-CSRCS = \
-    mp3sniff.c
-    $(NULL)
-
 include $(topsrcdir)/config/config.mk
 include $(topsrcdir)/config/rules.mk
deleted file mode 100644
--- a/toolkit/components/mediasniffer/mp3sniff.c
+++ /dev/null
@@ -1,166 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-/* MPEG format parsing */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdint.h>
-
-#include "mp3sniff.h"
-
-/* Maximum packet size is 320 kbits/s * 144 / 32 kHz + 1 padding byte */
-#define MP3_MAX_SIZE 1441
-
-typedef struct {
-  int version;
-  int layer;
-  int errp;
-  int bitrate;
-  int freq;
-  int pad;
-  int priv;
-  int mode;
-  int modex;
-  int copyright;
-  int original;
-  int emphasis;
-} mp3_header;
-
-/* Parse the 4-byte header in p and fill in the header struct. */
-static void mp3_parse(const uint8_t *p, mp3_header *header)
-{
-  const int bitrates[16] =
-	{0,  32000,  40000,  48000,  56000,  64000,  80000,  96000,
-         112000, 128000, 160000, 192000, 224000, 256000, 320000, 0};
-  const int samplerates[4] = {44100, 48000, 32000, 0};
-
-  header->version = (p[1] & 0x08) >> 3;
-  header->layer = 4 - ((p[1] & 0x06) >> 1);
-  header->errp = (p[1] & 0x01);
-
-  header->bitrate = bitrates[(p[2] & 0xf0) >> 4];
-  header->freq = samplerates[(p[2] & 0x0c) >> 2];
-  header->pad = (p[2] & 0x02) >> 1;
-  header->priv = (p[2] & 0x01);
-
-  header->mode = (p[3] & 0xc0) >> 6;
-  header->modex = (p[3] & 0x30) >> 4;
-  header->copyright = (p[3] & 0x08) >> 3;
-  header->original = (p[3] & 0x04) >> 2;
-  header->emphasis = (p[3] & 0x03);
-}
-
-/* calculate the size of an mp3 frame from its header */
-static int mp3_framesize(mp3_header *header)
-{
-  int size;
-  int scale;
-
-  if (header->layer == 1) scale = 48;
-  else scale = 144;
-
-  size = header->bitrate * scale / header->freq;
-  /* divide by an extra factor of 2 for MPEG-2? */
-
-  if (header->pad) size += 1;
-
-  return size;
-}
-
-static int is_mp3(const uint8_t *p, long length) {
-  /* Do we have enough room to see a 4 byte header? */
-  if (length < 4) return 0;
-  /* Do we have a sync pattern? */
-  if (p[0] == 0xff && (p[1]&0xe0) == 0xe0) {
-    /* Do we have any illegal field values? */
-    if (((p[1] & 0x06) >> 1) == 0) return 0;  /* No layer 4 */
-    if (((p[2] & 0xf0) >> 4) == 15) return 0; /* Bitrate can't be 1111 */
-    if (((p[2] & 0x0c) >> 2) == 3) return 0;  /* Samplerate can't be 11 */
-    /* Looks like a header. */
-    return 1;
-  }
-  return 0;
-}
-
-/* Identify an ID3 tag based on its header. */
-/* http://id3.org/id3v2.4.0-structure */
-static int is_id3(const uint8_t *p, long length) {
-  /* Do we have enough room to see the header? */
-  if (length < 10) return 0;
-  /* Do we have a sync pattern? */
-  if (p[0] == 'I' && p[1] == 'D' && p[2] == '3') {
-    if (p[3] == 0xff || p[4] == 0xff) return 0; /* Illegal version. */
-    if (p[6] & 0x80 || p[7] & 0x80 ||
-        p[8] & 0x80) return 0; /* Bad length encoding. */
-    /* Looks like an id3 header. */
-    return 1;
-  }
-  return 0;
-}
-
-/* Calculate the size of an id3 tag structure from its header. */
-static int id3_framesize(const uint8_t *p, long length)
-{
-  int size;
-
-  /* Header is 10 bytes. */
-  if (length < 10) {
-    return 0;
-  }
-  /* Frame is header plus declared size. */
-  size = 10 + (p[9] | (p[8] << 7) | (p[7] << 14) | (p[6] << 21));
-
-  return size;
-}
-
-int mp3_sniff(const uint8_t *buf, long length)
-{
-  mp3_header header;
-  const uint8_t *p, *q;
-  long skip;
-  long avail;
-
-  p = buf;
-  q = p;
-  avail = length;
-  while (avail > 0) {
-    if (is_id3(p, avail)) {
-      /* Skip over any id3 tags */
-      skip = id3_framesize(p, avail);
-      p += skip;
-      avail -= skip;
-      /* Is there enough data to continue? */
-      if (skip + 4 > avail) {
-        return 0;
-      }
-    } else if (is_mp3(p, avail)) {
-      mp3_parse(p, &header);
-      skip = mp3_framesize(&header);
-      if (skip + 4 > avail) {
-        return 0;
-      }
-      p += skip;
-      avail -= skip;
-      /* Check for a second header at the expected offset. */
-      if (is_mp3(p, avail)) {
-         /* Looks like mp3. */
-        return 1;
-      } else {
-        /* Give up. */
-        return 0;
-      }
-    } else {
-      /* Advance one byte and look for sync again. */
-      p++;
-      avail--;
-      /* Don't scan for more than the maximum frame size. */
-      if (length - avail > MP3_MAX_SIZE) {
-        return 0;
-      }
-    }
-  }
-
-  return 0;
-}
deleted file mode 100644
--- a/toolkit/components/mediasniffer/mp3sniff.h
+++ /dev/null
@@ -1,15 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this file,
- * You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdint.h>
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-int mp3_sniff(const uint8_t *buf, long length);
-
-#ifdef __cplusplus
-}
-#endif
--- a/toolkit/components/mediasniffer/nsMediaSniffer.cpp
+++ b/toolkit/components/mediasniffer/nsMediaSniffer.cpp
@@ -5,17 +5,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "nsMediaSniffer.h"
 #include "nsMemory.h"
 #include "nsIHttpChannel.h"
 #include "nsString.h"
 #include "nsMimeTypes.h"
 #include "mozilla/ModuleUtils.h"
-#include "mp3sniff.h"
 #ifdef MOZ_WEBM
 #include "nestegg/nestegg.h"
 #endif
 
 #include "nsIClassInfoImpl.h"
 #include <algorithm>
 
 // The minimum number of bytes that are needed to attempt to sniff an mp4 file.
@@ -80,23 +79,16 @@ static bool MatchesWebM(const uint8_t* a
 {
 #ifdef MOZ_WEBM
   return nestegg_sniff((uint8_t*)aData, aLength) ? true : false;
 #else
   return false;
 #endif
 }
 
-// This function implements mp3 sniffing based on parsing
-// packet headers and looking for expected boundaries.
-static bool MatchesMP3(const uint8_t* aData, const uint32_t aLength)
-{
-  return mp3_sniff(aData, (long)aLength);
-}
-
 NS_IMETHODIMP
 nsMediaSniffer::GetMIMETypeFromContent(nsIRequest* aRequest,
                                        const uint8_t* aData,
                                        const uint32_t aLength,
                                        nsACString& aSniffedType)
 {
   // For media, we want to sniff only if the Content-Type is unknown, or if it
   // is application/octet-stream.
@@ -137,18 +129,13 @@ nsMediaSniffer::GetMIMETypeFromContent(n
     return NS_OK;
   }
 
   if (MatchesWebM(aData, clampedLength)) {
     aSniffedType.AssignLiteral(VIDEO_WEBM);
     return NS_OK;
   }
 
-  if (MatchesMP3(aData, clampedLength)) {
-    aSniffedType.AssignLiteral(AUDIO_MP3);
-    return NS_OK;
-  }
-
   // Could not sniff the media type, we are required to set it to
   // application/octet-stream.
   aSniffedType.AssignLiteral(APPLICATION_OCTET_STREAM);
   return NS_ERROR_NOT_AVAILABLE;
 }
deleted file mode 100644
index 23091e666729c3e881428b75fc5d1f27d1275938..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index 5ad89786fa59971971107ff398e0022bfc643374..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
index c7db9436179fbd3f1e8aa05c011c34379b6f9d72..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391
GIT binary patch
literal 0
Hc$@<O00001
deleted file mode 100644
--- a/toolkit/components/mediasniffer/test/unit/test_mediasniffer_ext.js
+++ /dev/null
@@ -1,108 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-const Ci = Components.interfaces;
-const Cu = Components.utils;
-const Cc = Components.classes;
-const CC = Components.Constructor;
-
-var BinaryOutputStream = CC("@mozilla.org/binaryoutputstream;1",
-                            "nsIBinaryOutputStream",
-                            "setOutputStream");
-
-Cu.import("resource://testing-common/httpd.js");
-
-var httpserver = new HttpServer();
-
-var testRan = 0;
-
-// The tests files we want to test, and the type we should have after sniffing.
-const tests = [
-  // Real webm and mkv files truncated to 512 bytes.
-  { path: "data/file.webm", expected: "video/webm" },
-  { path: "data/file.mkv", expected: "application/octet-stream" },
-  // MP3 files with and without id3 headers truncated to 512 bytes.
-  // NB these have 208/209 byte frames, but mp3 can require up to
-  // 1445 bytes to detect with our method.
-  { path: "data/id3tags.mp3", expected: "audio/mpeg" },
-  { path: "data/notags.mp3", expected: "audio/mpeg" },
-  // Padding bit flipped in the first header: sniffing should fail.
-  { path: "data/notags-bad.mp3", expected: "application/octet-stream" },
-];
-
-// A basic listener that reads checks the if we sniffed properly.
-var listener = {
-  onStartRequest: function(request, context) {
-    do_print("Sniffing " + tests[testRan].path);
-    do_check_eq(request.QueryInterface(Ci.nsIChannel).contentType, tests[testRan].expected);
-  },
-
-  onDataAvailable: function(request, context, stream, offset, count) {
-    try {
-      var bis = Components.classes["@mozilla.org/binaryinputstream;1"]
-                          .createInstance(Components.interfaces.nsIBinaryInputStream);
-      bis.setInputStream(stream);
-      var array = bis.readByteArray(bis.available());
-    } catch (ex) {
-      do_throw("Error in onDataAvailable: " + ex);
-    }
-  },
-
-  onStopRequest: function(request, context, status) {
-    testRan++;
-    runNext();
-  }
-};
-
-function setupChannel(url) {
-  var ios = Components.classes["@mozilla.org/network/io-service;1"].
-                       getService(Ci.nsIIOService);
-  var chan = ios.newChannel("http://localhost:4444" + url, "", null);
-  var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel);
-  return httpChan;
-}
-
-function runNext() {
-  if (testRan == tests.length) {
-    do_test_finished();
-    return;
-  }
-  var channel = setupChannel("/");
-  channel.asyncOpen(listener, channel, null);
-}
-
-function getFileContents(aFile) {
-  const PR_RDONLY = 0x01;
-  var fileStream = Cc["@mozilla.org/network/file-input-stream;1"]
-                      .createInstance(Ci.nsIFileInputStream);
-  fileStream.init(aFile, 1, -1, null);
-  var bis = Components.classes["@mozilla.org/binaryinputstream;1"]
-                      .createInstance(Components.interfaces.nsIBinaryInputStream);
-  bis.setInputStream(fileStream);
-
-  var data = bis.readByteArray(bis.available());
-
-  return data;
-}
-
-function handler(metadata, response) {
-  response.setStatusLine(metadata.httpVersion, 200, "OK");
-  // Send an empty Content-Type, so we are guaranteed to sniff.
-  response.setHeader("Content-Type", "", false);
-  var body = getFileContents(do_get_file(tests[testRan].path));
-  var bos = new BinaryOutputStream(response.bodyOutputStream);
-  bos.writeByteArray(body, body.length);
-}
-
-function run_test() {
-  // We use a custom handler so we can change the header to force sniffing.
-  httpserver.registerPathHandler("/", handler);
-  httpserver.start(4444);
-  do_test_pending();
-  try {
-    runNext();
-  } catch (e) {
-    print("ERROR - " + e + "\n");
-  }
-}
new file mode 100644
--- /dev/null
+++ b/toolkit/components/mediasniffer/test/unit/test_mediasniffer_webm.js
@@ -0,0 +1,100 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+const Ci = Components.interfaces;
+const Cu = Components.utils;
+const Cc = Components.classes;
+const CC = Components.Constructor;
+
+var BinaryOutputStream = CC("@mozilla.org/binaryoutputstream;1",
+                            "nsIBinaryOutputStream",
+                            "setOutputStream");
+
+Cu.import("resource://testing-common/httpd.js");
+
+var httpserver = new HttpServer();
+
+var testRan = 0;
+
+// The tests files we want to test, and the type we should have after sniffing.
+// Those file are real webm and mkv files truncated to 512 bytes.
+const tests = [
+  { path: "data/file.webm", expected: "video/webm" },
+  { path: "data/file.mkv", expected: "application/octet-stream" },
+];
+
+// A basic listener that reads checks the if we sniffed properly.
+var listener = {
+  onStartRequest: function(request, context) {
+    do_check_eq(request.QueryInterface(Ci.nsIChannel).contentType, tests[testRan].expected);
+  },
+
+  onDataAvailable: function(request, context, stream, offset, count) {
+    try {
+      var bis = Components.classes["@mozilla.org/binaryinputstream;1"]
+                          .createInstance(Components.interfaces.nsIBinaryInputStream);
+      bis.setInputStream(stream);
+      var array = bis.readByteArray(bis.available());
+    } catch (ex) {
+      do_throw("Error in onDataAvailable: " + ex);
+    }
+  },
+
+  onStopRequest: function(request, context, status) {
+    testRan++;
+    runNext();
+  }
+};
+
+function setupChannel(url) {
+  var ios = Components.classes["@mozilla.org/network/io-service;1"].
+                       getService(Ci.nsIIOService);
+  var chan = ios.newChannel("http://localhost:4444" + url, "", null);
+  var httpChan = chan.QueryInterface(Components.interfaces.nsIHttpChannel);
+  return httpChan;
+}
+
+function runNext() {
+  if (testRan == tests.length) {
+    do_test_finished();
+    return;
+  }
+  var channel = setupChannel("/");
+  channel.asyncOpen(listener, channel, null);
+}
+
+function getFileContents(aFile) {
+  const PR_RDONLY = 0x01;
+  var fileStream = Cc["@mozilla.org/network/file-input-stream;1"]
+                      .createInstance(Ci.nsIFileInputStream);
+  fileStream.init(aFile, 1, -1, null);
+  var bis = Components.classes["@mozilla.org/binaryinputstream;1"]
+                      .createInstance(Components.interfaces.nsIBinaryInputStream);
+  bis.setInputStream(fileStream);
+
+  var data = bis.readByteArray(bis.available());
+
+  return data;
+}
+
+function handler(metadata, response) {
+  response.setStatusLine(metadata.httpVersion, 200, "OK");
+  // Send an empty Content-Type, so we are guaranteed to sniff.
+  response.setHeader("Content-Type", "", false);
+  var body = getFileContents(do_get_file(tests[testRan].path));
+  var bos = new BinaryOutputStream(response.bodyOutputStream);
+  bos.writeByteArray(body, body.length);
+}
+
+function run_test() {
+  // We use a custom handler so we can change the header to force sniffing.
+  httpserver.registerPathHandler("/", handler);
+  httpserver.start(4444);
+  do_test_pending();
+  try {
+    runNext();
+  } catch (e) {
+    print("ERROR - " + e + "\n");
+  }
+}
--- a/toolkit/components/mediasniffer/test/unit/xpcshell.ini
+++ b/toolkit/components/mediasniffer/test/unit/xpcshell.ini
@@ -1,6 +1,6 @@
 [DEFAULT]
 head =
 tail =
 
 [test_mediasniffer.js]
-[test_mediasniffer_ext.js]
+[test_mediasniffer_webm.js]