зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1656099 - AVIF (AV1 Image File Format): sniff MIME type from content. r=aosmond
Differential Revision: https://phabricator.services.mozilla.com/D85503
This commit is contained in:
Родитель
910e11aa99
Коммит
5f16fbcc7b
|
@ -51,6 +51,7 @@
|
|||
#include "nsIProgressEventSink.h"
|
||||
#include "nsIProtocolHandler.h"
|
||||
#include "nsImageModule.h"
|
||||
#include "nsMediaSniffer.h"
|
||||
#include "nsMimeTypes.h"
|
||||
#include "nsNetCID.h"
|
||||
#include "nsNetUtil.h"
|
||||
|
@ -2782,6 +2783,9 @@ nsresult imgLoader::GetMimeTypeFromContent(const char* aContents,
|
|||
!memcmp(aContents + 8, "WEBP", 4)) {
|
||||
aContentType.AssignLiteral(IMAGE_WEBP);
|
||||
|
||||
} else if (MatchesMP4(reinterpret_cast<const uint8_t*>(aContents), aLength,
|
||||
aContentType)) {
|
||||
MOZ_ASSERT(aContentType.Equals(IMAGE_AVIF));
|
||||
} else {
|
||||
/* none of the above? I give up */
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
|
|
|
@ -67,6 +67,26 @@ TEST_F(ImageLoader, DetectWebP) {
|
|||
CheckMimeType(buffer, sizeof(buffer), IMAGE_WEBP);
|
||||
}
|
||||
|
||||
TEST_F(ImageLoader, DetectAVIFMajorBrand) {
|
||||
const char buffer[] =
|
||||
"\x00\x00\x00\x20" // box length
|
||||
"ftyp" // box type
|
||||
"avif" // major brand
|
||||
"\x00\x00\x00\x00" // minor version
|
||||
"avifmif1miafMA1B"; // compatible brands
|
||||
CheckMimeType(buffer, sizeof(buffer), IMAGE_AVIF);
|
||||
}
|
||||
|
||||
TEST_F(ImageLoader, DetectAVIFCompatibleBrand) {
|
||||
const char buffer[] =
|
||||
"\x00\x00\x00\x20" // box length
|
||||
"ftyp" // box type
|
||||
"XXXX" // major brand
|
||||
"\x00\x00\x00\x00" // minor version
|
||||
"avifmif1miafMA1B"; // compatible brands
|
||||
CheckMimeType(buffer, sizeof(buffer), IMAGE_AVIF);
|
||||
}
|
||||
|
||||
TEST_F(ImageLoader, DetectNone) {
|
||||
const char buffer[] = "abcdefghijklmnop";
|
||||
CheckMimeType(buffer, sizeof(buffer), nullptr);
|
||||
|
|
|
@ -57,6 +57,7 @@ nsMediaSnifferEntry sFtypEntries[] = {
|
|||
PATTERN_ENTRY("\xFF\xFF\xFF\xFF", "qt ", VIDEO_QUICKTIME),
|
||||
PATTERN_ENTRY("\xFF\xFF\xFF", "iso", VIDEO_MP4), // Could be isom or iso2.
|
||||
PATTERN_ENTRY("\xFF\xFF\xFF\xFF", "mmp4", VIDEO_MP4),
|
||||
PATTERN_ENTRY("\xFF\xFF\xFF\xFF", "avif", IMAGE_AVIF),
|
||||
};
|
||||
|
||||
static bool MatchesBrands(const uint8_t aData[4], nsACString& aSniffedType) {
|
||||
|
@ -84,8 +85,8 @@ static bool MatchesBrands(const uint8_t aData[4], nsACString& aSniffedType) {
|
|||
// including MP4 (described at
|
||||
// http://mimesniff.spec.whatwg.org/#signature-for-mp4), M4A (Apple iTunes
|
||||
// audio), and 3GPP.
|
||||
static bool MatchesMP4(const uint8_t* aData, const uint32_t aLength,
|
||||
nsACString& aSniffedType) {
|
||||
bool MatchesMP4(const uint8_t* aData, const uint32_t aLength,
|
||||
nsACString& aSniffedType) {
|
||||
if (aLength <= MP4_MIN_BYTES_COUNT) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -33,6 +33,9 @@ struct nsMediaSnifferEntry {
|
|||
const char* mContentType;
|
||||
};
|
||||
|
||||
bool MatchesMP4(const uint8_t* aData, const uint32_t aLength,
|
||||
nsACString& aSniffedType);
|
||||
|
||||
class nsMediaSniffer final : public nsIContentSniffer {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
|
Загрузка…
Ссылка в новой задаче