Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Unified Diff: media/base/container_names.cc

Issue 2807463003: Simplify checking for MP3 format (Closed)
Patch Set: Simplify Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | media/base/container_names_unittest.cc » ('j') | media/base/container_names_unittest.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/container_names.cc
diff --git a/media/base/container_names.cc b/media/base/container_names.cc
index 24d8ea953ffe58789c7493f1f73b2e69d0595402..53c454d33569deace5b859391f8f18c3fa63fbd0 100644
--- a/media/base/container_names.cc
+++ b/media/base/container_names.cc
@@ -1084,32 +1084,20 @@ static bool ValidMpegAudioFrameHeader(const uint8_t* header,
return (bitrate > 0 && sampling_rate > 0);
}
-// Extract a size encoded the MP3 way.
-static int GetMp3HeaderSize(const uint8_t* buffer, int buffer_size) {
- DCHECK_GE(buffer_size, 9);
- int size = ((buffer[6] & 0x7f) << 21) + ((buffer[7] & 0x7f) << 14) +
- ((buffer[8] & 0x7f) << 7) + (buffer[9] & 0x7f) + 10;
- if (buffer[5] & 0x10) // Footer added?
- size += 10;
- return size;
-}
-
// Additional checks for a MP3 container.
-static bool CheckMp3(const uint8_t* buffer, int buffer_size, bool seenHeader) {
- RCHECK(buffer_size >= 10); // Must be enough to read the initial header.
-
- int framesize;
+static bool CheckMp3(const uint8_t* buffer, int buffer_size) {
+ // This function assumes that the ID3 header is not present in the file and
+ // simply checks for several valid MPEG audio buffers after skipping any
+ // optional padding characters.
int numSeen = 0;
int offset = 0;
- if (seenHeader) {
- offset = GetMp3HeaderSize(buffer, buffer_size);
- } else {
- // Skip over leading 0's.
- while (offset < buffer_size && buffer[offset] == 0)
- ++offset;
- }
+
+ // Skip over any padding (0's).
+ while (offset < buffer_size && buffer[offset] == 0)
+ ++offset;
while (offset + 3 < buffer_size) {
+ int framesize;
RCHECK(ValidMpegAudioFrameHeader(
buffer + offset, buffer_size - offset, &framesize));
@@ -1594,9 +1582,7 @@ static MediaContainerName LookupContainerByFirst4(const uint8_t* buffer,
return CONTAINER_SWF;
case TAG('I','D','3',0):
DaleCurtis 2017/04/13 23:25:42 Ah, I think this accidentally completely dropped n
- if (CheckMp3(buffer, buffer_size, true))
- return CONTAINER_MP3;
- break;
+ return CONTAINER_MP3;
}
// Maybe the first 2 characters are something we can use.
@@ -1618,8 +1604,8 @@ static MediaContainerName LookupContainerByFirst4(const uint8_t* buffer,
break;
}
- // Check if the file is in MP3 format without the header.
- if (CheckMp3(buffer, buffer_size, false))
+ // Check if the file is in MP3 format without the ID3 header.
+ if (CheckMp3(buffer, buffer_size))
return CONTAINER_MP3;
return CONTAINER_UNKNOWN;
« no previous file with comments | « no previous file | media/base/container_names_unittest.cc » ('j') | media/base/container_names_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698