Bug 1355933: P6. Hook up ADTS sniffer. r?kamidphish draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 13 Apr 2017 02:40:35 +0200
changeset 561794 2f6c1bd8510bb25271f2596b7965d04bd7fee0f3
parent 561793 e8f62b65d795e3870f11a43f957f7728840d1bad
child 624093 9265e7a03136e7d5d73065860a08813f20938fcd
push id53869
push userbmo:jyavenard@mozilla.com
push dateThu, 13 Apr 2017 07:09:28 +0000
reviewerskamidphish
bugs1355933
milestone55.0a1
Bug 1355933: P6. Hook up ADTS sniffer. r?kamidphish MozReview-Commit-ID: 3aYmCRRbRzg
netwerk/mime/nsMimeTypes.h
toolkit/components/mediasniffer/nsMediaSniffer.cpp
--- a/netwerk/mime/nsMimeTypes.h
+++ b/netwerk/mime/nsMimeTypes.h
@@ -83,16 +83,17 @@
 #define AUDIO_MP3                           "audio/mpeg"
 #define AUDIO_MP4                           "audio/mp4"
 #define AUDIO_AMR                           "audio/amr"
 #define AUDIO_FLAC                          "audio/flac"
 #define AUDIO_3GPP                          "audio/3gpp"
 #define AUDIO_3GPP2                         "audio/3gpp2"
 #define AUDIO_MIDI                          "audio/x-midi"
 #define AUDIO_MATROSKA                      "audio/x-matroska"
+#define AUDIO_AAC                           "audio/aac"
 
 #define BINARY_OCTET_STREAM                 "binary/octet-stream"
 
 #define IMAGE_GIF                           "image/gif"
 #define IMAGE_JPEG                          "image/jpeg"
 #define IMAGE_JPG                           "image/jpg"
 #define IMAGE_PJPEG                         "image/pjpeg"
 #define IMAGE_PNG                           "image/png"
--- a/toolkit/components/mediasniffer/nsMediaSniffer.cpp
+++ b/toolkit/components/mediasniffer/nsMediaSniffer.cpp
@@ -1,14 +1,15 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim:set ts=2 sw=2 sts=2 tw=80 et cindent: */
 /* 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 "ADTSDemuxer.h"
 #include "FlacDemuxer.h"
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/ModuleUtils.h"
 #include "mp3sniff.h"
 #include "nestegg/nestegg.h"
 #include "nsIClassInfoImpl.h"
 #include "nsIHttpChannel.h"
 #include "nsMediaSniffer.h"
@@ -125,16 +126,21 @@ static bool MatchesMP3(const uint8_t* aD
   return mp3_sniff(aData, (long)aLength);
 }
 
 static bool MatchesFLAC(const uint8_t* aData, const uint32_t aLength)
 {
   return mozilla::FlacDemuxer::FlacSniffer(aData, aLength);
 }
 
+static bool MatchesADTS(const uint8_t* aData, const uint32_t aLength)
+{
+  return mozilla::ADTSDemuxer::ADTSSniffer(aData, aLength);
+}
+
 NS_IMETHODIMP
 nsMediaSniffer::GetMIMETypeFromContent(nsIRequest* aRequest,
                                        const uint8_t* aData,
                                        const uint32_t aLength,
                                        nsACString& aSniffedType)
 {
   nsCOMPtr<nsIChannel> channel = do_QueryInterface(aRequest);
   if (channel) {
@@ -192,13 +198,18 @@ nsMediaSniffer::GetMIMETypeFromContent(n
   // Flac frames are generally big, often in excess of 24kB.
   // Using a size of MAX_BYTES_SNIFFED effectively means that we will only
   // recognize flac content if it starts with a frame.
   if (MatchesFLAC(aData, clampedLength)) {
     aSniffedType.AssignLiteral(AUDIO_FLAC);
     return NS_OK;
   }
 
+  if (MatchesADTS(aData, clampedLength)) {
+    aSniffedType.AssignLiteral(AUDIO_AAC);
+    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;
 }