#include "nsAString.h" #include "nsMimeTypes.h" #include "mozilla/ModuleUtils.h" #include "nsIClassInfoImpl.h" // 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 without ID3 tags. PATTERN_ENTRY("\xFF\xFB", "\xFF\xFA", AUDIO_MP3), // 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) { if (aLength <= MP4_MIN_BYTES_COUNT) {
#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. 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), // 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) { if (aLength <= MP4_MIN_BYTES_COUNT) { return false; } // Conversion from big endian to host byte order. uint32_t boxSize = (uint32_t)(aData[3] | aData[2] << 8 | aData[1] << 16 | aData[0] << 24);