From 537e15d0d5ee4cd9b726f6b156af90e2ffd5cf35 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Wed, 15 Jan 2020 21:52:07 +1100 Subject: [PATCH 01/10] Set MP3 long name --- Source/com/drew/imaging/FileType.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/com/drew/imaging/FileType.java b/Source/com/drew/imaging/FileType.java index fd2b283d2..3758e3585 100644 --- a/Source/com/drew/imaging/FileType.java +++ b/Source/com/drew/imaging/FileType.java @@ -48,7 +48,7 @@ public enum FileType Mp4("MP4", "MPEG-4 Part 14", "video/mp4", "mp4", "m4a", "m4p", "m4b", "m4r", "m4v"), Heif("HEIF", "High Efficiency Image File Format", "image/heif", "heif", "heic"), Eps("EPS", "Encapsulated PostScript", "application/postscript", "eps", "epsf", "epsi"), - Mp3("MP3", "MP3", "audio/mpeg", "mp3"), + Mp3("MP3", "MPEG Audio Layer III", "audio/mpeg", "mp3"), /** Sony camera raw. */ Arw("ARW", "Sony Camera Raw", null, "arw"), From 2b15bcf540a6a8fdbe6251a216f2711bc25dddfe Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Wed, 15 Jan 2020 21:53:24 +1100 Subject: [PATCH 02/10] Model ID as an int --- Source/com/drew/metadata/mp3/Mp3Reader.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Source/com/drew/metadata/mp3/Mp3Reader.java b/Source/com/drew/metadata/mp3/Mp3Reader.java index 0c7bad0d2..9077c8cd0 100644 --- a/Source/com/drew/metadata/mp3/Mp3Reader.java +++ b/Source/com/drew/metadata/mp3/Mp3Reader.java @@ -50,11 +50,9 @@ public void extract(@NotNull final InputStream inputStream, @NotNull final Metad int header = reader.getInt32(); // ID: MPEG-2.5, MPEG-2, or MPEG-1 - double id = 0; + int id = 0; switch ((header & 0x000180000) >> 19) { case (0): - directory.setString(Mp3Directory.TAG_ID, "MPEG-2.5"); - id = 2.5; throw new ImageProcessingException("MPEG-2.5 not supported."); case (2): directory.setString(Mp3Directory.TAG_ID, "MPEG-2"); @@ -162,7 +160,7 @@ public void extract(@NotNull final InputStream inputStream, @NotNull final Metad } } - public int setBitrate(int bitrate, int layer, double id) + public int setBitrate(int bitrate, int layer, int id) { int[][] bitrateMapping = new int[14][6]; bitrateMapping[0] = new int[]{32, 32, 32, 32, 32, 8}; From 2e10a6ed77f9dc8382eeb4a6351f7363df567204 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Wed, 15 Jan 2020 21:53:38 +1100 Subject: [PATCH 03/10] Comment out unused method --- Source/com/drew/metadata/mp3/Mp3Reader.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Source/com/drew/metadata/mp3/Mp3Reader.java b/Source/com/drew/metadata/mp3/Mp3Reader.java index 9077c8cd0..f2412d478 100644 --- a/Source/com/drew/metadata/mp3/Mp3Reader.java +++ b/Source/com/drew/metadata/mp3/Mp3Reader.java @@ -214,10 +214,9 @@ public int setBitrate(int bitrate, int layer, int id) return bitrateMapping[yPos][xPos]; } - /** - * https://phoxis.org/2010/05/08/synch-safe/ - */ - public static int getSyncSafeSize(int decode) +/* + // https://phoxis.org/2010/05/08/synch-safe/ + private static int getSyncSafeSize(int decode) { int a = decode & 0xFF; int b = (decode >> 8) & 0xFF; @@ -231,4 +230,5 @@ public static int getSyncSafeSize(int decode) decoded = decoded | (d << 21); return decoded; } +*/ } From 70fed8c37239b76372c6b713bde186aa32317a8e Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Wed, 15 Jan 2020 21:53:53 +1100 Subject: [PATCH 04/10] Reference static member via its type --- Source/com/drew/metadata/mp3/Mp3Reader.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/com/drew/metadata/mp3/Mp3Reader.java b/Source/com/drew/metadata/mp3/Mp3Reader.java index f2412d478..57302c00c 100644 --- a/Source/com/drew/metadata/mp3/Mp3Reader.java +++ b/Source/com/drew/metadata/mp3/Mp3Reader.java @@ -97,10 +97,10 @@ public void extract(@NotNull final InputStream inputStream, @NotNull final Metad frequencyMapping[0] = new int[]{44100, 48000, 32000}; frequencyMapping[1] = new int[]{22050, 24000, 16000}; if (id == 2) { - directory.setInt(directory.TAG_FREQUENCY, frequencyMapping[1][frequency]); + directory.setInt(Mp3Directory.TAG_FREQUENCY, frequencyMapping[1][frequency]); frequency = frequencyMapping[1][frequency]; } else if (id == 1) { - directory.setInt(directory.TAG_FREQUENCY, frequencyMapping[0][frequency]); + directory.setInt(Mp3Directory.TAG_FREQUENCY, frequencyMapping[0][frequency]); frequency = frequencyMapping[0][frequency]; } From ad45333d3d0291f7ae7d9d80e60d0851c9085d41 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Wed, 15 Jan 2020 21:54:29 +1100 Subject: [PATCH 05/10] Remove empty default case blocks --- Source/com/drew/metadata/mp3/Mp3Reader.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/Source/com/drew/metadata/mp3/Mp3Reader.java b/Source/com/drew/metadata/mp3/Mp3Reader.java index 57302c00c..89032caaa 100644 --- a/Source/com/drew/metadata/mp3/Mp3Reader.java +++ b/Source/com/drew/metadata/mp3/Mp3Reader.java @@ -62,7 +62,6 @@ public void extract(@NotNull final InputStream inputStream, @NotNull final Metad directory.setString(Mp3Directory.TAG_ID, "MPEG-1"); id = 1; break; - default: } // Layer Type: 1, 2, 3, or not defined @@ -80,7 +79,6 @@ public void extract(@NotNull final InputStream inputStream, @NotNull final Metad case(3): directory.setString(Mp3Directory.TAG_LAYER, "Layer I"); break; - default: } @@ -122,7 +120,6 @@ public void extract(@NotNull final InputStream inputStream, @NotNull final Metad case(3): directory.setString(Mp3Directory.TAG_MODE, "Mono"); break; - default: } // Copyright boolean @@ -134,7 +131,6 @@ public void extract(@NotNull final InputStream inputStream, @NotNull final Metad case(1): directory.setString(Mp3Directory.TAG_COPYRIGHT, "True"); break; - default: } int emphasis = (header & 0x00000003); @@ -148,7 +144,6 @@ public void extract(@NotNull final InputStream inputStream, @NotNull final Metad case (3): directory.setString(Mp3Directory.TAG_EMPHASIS, "CCITT j.17"); break; - default: } int frameSize = ((setBitrate(bitrate, layer, id) * 1000) * 144) / frequency; @@ -193,7 +188,6 @@ public int setBitrate(int bitrate, int layer, int id) case (3): xPos = 3; break; - default: } } else if (id == 1) { // MPEG-1 @@ -207,7 +201,6 @@ public int setBitrate(int bitrate, int layer, int id) case(3): xPos = 0; break; - default: } } From 07a033c0aac9bafa1d147eae4d5eaf84504bfea8 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Wed, 15 Jan 2020 21:54:51 +1100 Subject: [PATCH 06/10] Don't reset stream --- Source/com/drew/metadata/mp3/Mp3Reader.java | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/com/drew/metadata/mp3/Mp3Reader.java b/Source/com/drew/metadata/mp3/Mp3Reader.java index 89032caaa..fed192514 100644 --- a/Source/com/drew/metadata/mp3/Mp3Reader.java +++ b/Source/com/drew/metadata/mp3/Mp3Reader.java @@ -44,7 +44,6 @@ public void extract(@NotNull final InputStream inputStream, @NotNull final Metad metadata.addDirectory(directory); try { - inputStream.reset(); SequentialReader reader = new StreamReader(inputStream); int header = reader.getInt32(); From f1f692b17d534ef86bd5bd9c3b257ef841ebd751 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Wed, 15 Jan 2020 21:55:06 +1100 Subject: [PATCH 07/10] Protect against invalid bitrate values --- Source/com/drew/metadata/mp3/Mp3Reader.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Source/com/drew/metadata/mp3/Mp3Reader.java b/Source/com/drew/metadata/mp3/Mp3Reader.java index fed192514..79b1696fa 100644 --- a/Source/com/drew/metadata/mp3/Mp3Reader.java +++ b/Source/com/drew/metadata/mp3/Mp3Reader.java @@ -145,8 +145,10 @@ public void extract(@NotNull final InputStream inputStream, @NotNull final Metad break; } - int frameSize = ((setBitrate(bitrate, layer, id) * 1000) * 144) / frequency; - directory.setString(Mp3Directory.TAG_FRAME_SIZE, frameSize + " bytes"); + if (bitrate != 0 && bitrate != 15) { + int frameSize = ((setBitrate(bitrate, layer, id) * 1000) * 144) / frequency; + directory.setString(Mp3Directory.TAG_FRAME_SIZE, frameSize + " bytes"); + } } catch (IOException e) { e.printStackTrace(); } catch (ImageProcessingException e) { From a43d998d130dc65899f00807ad0ea6c373546a0d Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Wed, 15 Jan 2020 21:55:18 +1100 Subject: [PATCH 08/10] Make method private and static --- Source/com/drew/metadata/mp3/Mp3Reader.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Source/com/drew/metadata/mp3/Mp3Reader.java b/Source/com/drew/metadata/mp3/Mp3Reader.java index 79b1696fa..c63073a9f 100644 --- a/Source/com/drew/metadata/mp3/Mp3Reader.java +++ b/Source/com/drew/metadata/mp3/Mp3Reader.java @@ -156,7 +156,7 @@ public void extract(@NotNull final InputStream inputStream, @NotNull final Metad } } - public int setBitrate(int bitrate, int layer, int id) + private static int setBitrate(int bitrate, int layer, int id) { int[][] bitrateMapping = new int[14][6]; bitrateMapping[0] = new int[]{32, 32, 32, 32, 32, 8}; From 837a3f0e6979f151f2fcc8db7c74e775ce8558ec Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Wed, 15 Jan 2020 21:55:30 +1100 Subject: [PATCH 09/10] Formatting --- .../com/drew/metadata/mp3/Mp3Directory.java | 1 - Source/com/drew/metadata/mp3/Mp3Reader.java | 45 +++++++++---------- 2 files changed, 22 insertions(+), 24 deletions(-) diff --git a/Source/com/drew/metadata/mp3/Mp3Directory.java b/Source/com/drew/metadata/mp3/Mp3Directory.java index 56d9ab316..0abd6cdd7 100644 --- a/Source/com/drew/metadata/mp3/Mp3Directory.java +++ b/Source/com/drew/metadata/mp3/Mp3Directory.java @@ -30,7 +30,6 @@ */ public class Mp3Directory extends Directory { - public static final int TAG_ID = 1; public static final int TAG_LAYER = 2; public static final int TAG_BITRATE = 3; diff --git a/Source/com/drew/metadata/mp3/Mp3Reader.java b/Source/com/drew/metadata/mp3/Mp3Reader.java index c63073a9f..ce320b36e 100644 --- a/Source/com/drew/metadata/mp3/Mp3Reader.java +++ b/Source/com/drew/metadata/mp3/Mp3Reader.java @@ -37,7 +37,6 @@ */ public class Mp3Reader { - public void extract(@NotNull final InputStream inputStream, @NotNull final Metadata metadata) { Mp3Directory directory = new Mp3Directory(); @@ -51,13 +50,13 @@ public void extract(@NotNull final InputStream inputStream, @NotNull final Metad // ID: MPEG-2.5, MPEG-2, or MPEG-1 int id = 0; switch ((header & 0x000180000) >> 19) { - case (0): + case 0: throw new ImageProcessingException("MPEG-2.5 not supported."); - case (2): + case 2: directory.setString(Mp3Directory.TAG_ID, "MPEG-2"); id = 2; break; - case (3): + case 3: directory.setString(Mp3Directory.TAG_ID, "MPEG-1"); id = 1; break; @@ -66,16 +65,16 @@ public void extract(@NotNull final InputStream inputStream, @NotNull final Metad // Layer Type: 1, 2, 3, or not defined int layer = ((header & 0x00060000) >> 17); switch (layer) { - case(0): + case 0: directory.setString(Mp3Directory.TAG_LAYER, "Not defined"); break; - case(1): + case 1: directory.setString(Mp3Directory.TAG_LAYER, "Layer III"); break; - case(2): + case 2: directory.setString(Mp3Directory.TAG_LAYER, "Layer II"); break; - case(3): + case 3: directory.setString(Mp3Directory.TAG_LAYER, "Layer I"); break; } @@ -107,16 +106,16 @@ public void extract(@NotNull final InputStream inputStream, @NotNull final Metad // Encoding type: Stereo, Joint Stereo, Dual Channel, or Mono int mode = ((header & 0x000000C0) >> 6); switch (mode){ - case(0): + case 0: directory.setString(Mp3Directory.TAG_MODE, "Stereo"); break; - case(1): + case 1: directory.setString(Mp3Directory.TAG_MODE, "Joint stereo"); break; - case(2): + case 2: directory.setString(Mp3Directory.TAG_MODE, "Dual channel"); break; - case(3): + case 3: directory.setString(Mp3Directory.TAG_MODE, "Mono"); break; } @@ -124,23 +123,23 @@ public void extract(@NotNull final InputStream inputStream, @NotNull final Metad // Copyright boolean int copyright = ((header & 0x00000008) >> 3); switch (copyright) { - case(0): + case 0: directory.setString(Mp3Directory.TAG_COPYRIGHT, "False"); break; - case(1): + case 1: directory.setString(Mp3Directory.TAG_COPYRIGHT, "True"); break; } int emphasis = (header & 0x00000003); switch (emphasis) { - case (0): + case 0: directory.setString(Mp3Directory.TAG_EMPHASIS, "none"); break; - case (1): + case 1: directory.setString(Mp3Directory.TAG_EMPHASIS, "50/15ms"); break; - case (3): + case 3: directory.setString(Mp3Directory.TAG_EMPHASIS, "CCITT j.17"); break; } @@ -180,26 +179,26 @@ private static int setBitrate(int bitrate, int layer, int id) if (id == 2) { // MPEG-2 switch (layer) { - case (1): + case 1: xPos = 5; break; - case (2): + case 2: xPos = 4; break; - case (3): + case 3: xPos = 3; break; } } else if (id == 1) { // MPEG-1 switch (layer) { - case(1): + case 1: xPos = 2; break; - case(2): + case 2: xPos = 1; break; - case(3): + case 3: xPos = 0; break; } From 5fdd5c94b5cdf34462261faa78edf50f191a0a6e Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Wed, 15 Jan 2020 22:05:39 +1100 Subject: [PATCH 10/10] Update UUID box tag names --- Source/com/drew/metadata/mp4/media/Mp4UuidBoxDirectory.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/com/drew/metadata/mp4/media/Mp4UuidBoxDirectory.java b/Source/com/drew/metadata/mp4/media/Mp4UuidBoxDirectory.java index 7974323b7..91b0d43ce 100644 --- a/Source/com/drew/metadata/mp4/media/Mp4UuidBoxDirectory.java +++ b/Source/com/drew/metadata/mp4/media/Mp4UuidBoxDirectory.java @@ -35,8 +35,8 @@ public class Mp4UuidBoxDirectory extends Mp4MediaDirectory static { Mp4UuidBoxDirectory.addMp4MediaTags(_tagNameMap); - _tagNameMap.put(TAG_UUID, "uuid"); - _tagNameMap.put(TAG_USER_DATA, "data"); + _tagNameMap.put(TAG_UUID, "UUID"); + _tagNameMap.put(TAG_USER_DATA, "Data"); } public Mp4UuidBoxDirectory()