Bug 835381 - Use the new libnestegg API to sniff for WebM. r=kinetik
authorPaul Adenot <paul@paul.cx>
Tue, 12 Feb 2013 22:15:55 +0100
changeset 122322 a1534b828aa7b66666b09a622af4ae4564fc41fd
parent 122321 5d873401eb7bb18b95a32006af79a6e4338762ad
child 122323 b143a7fb7f396327fadfaabb68ec2eb7d8522b0f
push id24336
push userryanvm@gmail.com
push dateWed, 20 Feb 2013 12:07:46 +0000
treeherdermozilla-central@1bcc3c56b011 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik
bugs835381
milestone21.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 835381 - Use the new libnestegg API to sniff for WebM. r=kinetik
toolkit/components/mediasniffer/nsMediaSniffer.cpp
--- a/toolkit/components/mediasniffer/nsMediaSniffer.cpp
+++ b/toolkit/components/mediasniffer/nsMediaSniffer.cpp
@@ -5,34 +5,33 @@
  * 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 "nestegg/nestegg.h"
 
 #include "nsIClassInfoImpl.h"
 #include <algorithm>
 
 // The minimum number of bytes that are needed to attempt to sniff an mp4 file.
 static const unsigned MP4_MIN_BYTES_COUNT = 12;
 // The maximum number of bytes to consider when attempting to sniff a file.
 static const uint32_t MAX_BYTES_SNIFFED = 512;
 
 NS_IMPL_ISUPPORTS1(nsMediaSniffer, nsIContentSniffer)
 
 nsMediaSniffer::nsMediaSnifferEntry nsMediaSniffer::sSnifferEntries[] = {
   // The string OggS, followed by the null byte.
   PATTERN_ENTRY("\xFF\xFF\xFF\xFF\xFF", "OggS", APPLICATION_OGG),
   // The string RIFF, followed by four bytes, followed by the string WAVE
   PATTERN_ENTRY("\xFF\xFF\xFF\xFF\x00\x00\x00\x00\xFF\xFF\xFF\xFF", "RIFF\x00\x00\x00\x00WAVE", AUDIO_WAV),
-  // WebM
-  PATTERN_ENTRY("\xFF\xFF\xFF\xFF", "\x1A\x45\xDF\xA3", VIDEO_WEBM),
   // mp3 with ID3 tags, the string "ID3".
   PATTERN_ENTRY("\xFF\xFF\xFF", "ID3", AUDIO_MP3)
 };
 
 // This function implements mp4 sniffing algorithm, described at
 // http://mimesniff.spec.whatwg.org/#signature-for-mp4
 static bool MatchesMP4(const uint8_t* aData, const uint32_t aLength)
 {
@@ -62,16 +61,21 @@ static bool MatchesMP4(const uint8_t* aD
         aData[4*i+1] == 0x70 &&
         aData[4*i+2] == 0x34) {
       return true;
     }
   }
   return false;
 }
 
+static bool MatchesWebM(const uint8_t* aData, const uint32_t aLength)
+{
+  return nestegg_sniff((uint8_t*)aData, aLength) ? true : false;
+}
+
 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.
@@ -107,13 +111,18 @@ nsMediaSniffer::GetMIMETypeFromContent(n
     }
   }
 
   if (MatchesMP4(aData, clampedLength)) {
     aSniffedType.AssignLiteral(VIDEO_MP4);
     return NS_OK;
   }
 
+  if (MatchesWebM(aData, clampedLength)) {
+    aSniffedType.AssignLiteral(VIDEO_WEBM);
+    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;
 }