Skip to content

Commit 6b10b67

Browse files
committed
New warning when reading a file illegally tagged with ID3v2 (e.g. MP4/M4A)
1 parent 257e336 commit 6b10b67

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

ATL/AudioData/AudioDataIOFactory.cs

+13-2
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,13 @@ public IAudioDataIO GetFromStream(Stream s)
417417
s.Seek(0, SeekOrigin.Begin);
418418
byte[] data = new byte[32];
419419
long offset = 0;
420+
bool hasID3v2 = false;
420421
if (s.Read(data, 0, 32) < 32) return getFromFormat(IN_MEMORY, new AudioFormat(Format.UNKNOWN_FORMAT));
421422
// Hardcoded case of ID3v2 as it is the sole standard metadata system to appear at the beginning of file
423+
// NB : useful to detect files tagged with ID3v2 even though their format isn't compatible (e.g. MP4/M4A)
422424
if (ID3v2.IsValidHeader(data))
423425
{
426+
hasID3v2 = true;
424427
byte[] data2 = new byte[4];
425428
Array.Copy(data, 6, data2, 0, 4); // bytes 6-9 only
426429
int id3v2Size = StreamUtils.DecodeSynchSafeInt32(data2) + 10; // 10 being the size of the header
@@ -433,13 +436,13 @@ public IAudioDataIO GetFromStream(Stream s)
433436
List<AudioFormat> expensiveFormats = new List<AudioFormat>();
434437
foreach (AudioFormat f in getFormats())
435438
{
436-
if (f.CheckHeader != null && f.CheckHeader(data)) return getFromFormat(IN_MEMORY, f);
439+
if (f.CheckHeader != null && f.CheckHeader(data)) return checkFromFormat(IN_MEMORY, f, hasID3v2);
437440
if (f.SearchHeader != null) expensiveFormats.Add(f);
438441
}
439442
foreach (AudioFormat f in expensiveFormats)
440443
{
441444
s.Seek(offset, SeekOrigin.Begin);
442-
if (f.SearchHeader(s)) return getFromFormat(IN_MEMORY, f);
445+
if (f.SearchHeader(s)) return checkFromFormat(IN_MEMORY, f, hasID3v2);
443446
}
444447
return getFromFormat(IN_MEMORY, new AudioFormat(Format.UNKNOWN_FORMAT));
445448
}
@@ -448,6 +451,14 @@ public IAudioDataIO GetFromStream(Stream s)
448451
s.Seek(0, SeekOrigin.Begin);
449452
}
450453
}
454+
private static IAudioDataIO checkFromFormat(string path, AudioFormat theFormat, bool hasID3v2)
455+
{
456+
var result = getFromFormat(path, theFormat);
457+
if (hasID3v2 && !result.GetSupportedMetas().Contains(MetaDataIOFactory.TagType.ID3V2))
458+
LogDelegator.GetLogDelegate()(Log.LV_WARNING, "ATL doesn't support " + result.AudioFormat.Name + " files illegally tagged with ID3v2");
459+
return result;
460+
}
461+
451462

452463
private static IAudioDataIO getFromFormat(string path, AudioFormat theFormat)
453464
{

0 commit comments

Comments
 (0)