Skip to content

Commit

Permalink
#JAUDIOTAGGER-387:Not writing new tag correctly when file has no tag …
Browse files Browse the repository at this point in the history
…but does has free top header

git-svn-id: https://svn.java.net/svn/jaudiotagger~svn/trunk@998 922cec90-98bc-ecba-b0a9-867c771b4a74
  • Loading branch information
paultaylor committed Sep 22, 2011
1 parent 916ed09 commit cd21637
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 8 deletions.
4 changes: 2 additions & 2 deletions src/org/jaudiotagger/audio/mp4/Mp4InfoReader.java
Expand Up @@ -282,7 +282,7 @@ public GenericAudioHeader read(RandomAccessFile raf) throws CannotReadException,
}
}
}
//Set default channels if couldnt calculate it
//Set default channels if couldn't calculate it
if (info.getChannelNumber() == -1)
{
info.setChannelNumber(2);
Expand All @@ -294,7 +294,7 @@ public GenericAudioHeader read(RandomAccessFile raf) throws CannotReadException,
info.setBitrate(128);
}

//This is the most likley option if cant find a match
//This is the most likely option if cant find a match
if (info.getEncodingType().equals(""))
{
info.setEncodingType(EncoderType.AAC.getDescription());
Expand Down
7 changes: 4 additions & 3 deletions src/org/jaudiotagger/audio/mp4/Mp4TagWriter.java
Expand Up @@ -480,7 +480,7 @@ else if (oldIlstSize > newIlstSize)
//There is not enough padding in the metadata free atom anyway
//Size meta needs to be increased by (if not writing a free atom)
//Special Case this could actually be negative (upto -8)if is actually enough space but would
//not be able to write free atom properly, it doesnt matter the parent atoms would still
//not be able to write free atom properly, it doesn't matter the parent atoms would still
//need their sizes adjusted.
else
{
Expand Down Expand Up @@ -510,10 +510,11 @@ else if (oldIlstSize > newIlstSize)
|| ((topLevelFreeSize - Mp4BoxHeader.HEADER_LENGTH < additionalMetaSizeThatWontFitWithinMetaAtom)
&& (topLevelFreeSize != additionalMetaSizeThatWontFitWithinMetaAtom)))
{
//We dont bother using the top level free atom coz not big enough anyway, we need to adjust offsets
//We don't bother using the top level free atom coz not big enough anyway, we need to adjust offsets
//by the amount mdat is going to be shifted
if (mdatHeader.getFilePos() > moovHeader.getFilePos())
{
logger.config("Adjusting Offsets");
stco.adjustOffsets(additionalMetaSizeThatWontFitWithinMetaAtom);
}
}
Expand Down Expand Up @@ -596,7 +597,7 @@ else if (oldIlstSize > newIlstSize)

//If we have top level free atom that comes before mdat we might be able to use it but only if
//the free atom actually come after the the metadata
if (topLevelFreeAtomComesBeforeMdatAtomAndAfterMetadata&&(topLevelFreePosition>startIlstWithinFile))
if (topLevelFreeAtomComesBeforeMdatAtomAndAfterMetadata&&(topLevelFreePosition>=startIlstWithinFile))
{
//If the shift is less than the space available in this second free atom data size we should
//minimize the free atom accordingly (then we don't have to update stco atom)
Expand Down
4 changes: 2 additions & 2 deletions src/org/jaudiotagger/tag/mp4/Mp4TagCreator.java
Expand Up @@ -98,9 +98,9 @@ public ByteBuffer convert(Tag tag, int padding) throws UnsupportedEncodingExcept
{
processedArtwork = true;

//Because each artwork image is held within the tag as a seperate field, but when
//Because each artwork image is held within the tag as a separate field, but when
//they are written they are all held under a single covr box we need to do some checks
//and special processing here if we have any artwork image (this code only neccessary
//and special processing here if we have any artwork image (this code only necessary
//if we have more than 1 but do it anyway even if only have 1 image)
ByteArrayOutputStream covrDataBaos = new ByteArrayOutputStream();

Expand Down
45 changes: 45 additions & 0 deletions srctest/org/jaudiotagger/issues/Issue387Test.java
@@ -0,0 +1,45 @@
package org.jaudiotagger.issues;

import org.jaudiotagger.AbstractTestCase;
import org.jaudiotagger.audio.AudioFile;
import org.jaudiotagger.audio.AudioFileIO;
import org.jaudiotagger.audio.mp4.Mp4AtomTree;

import java.io.File;
import java.io.RandomAccessFile;

/**
* Test writing mp4
*/
public class Issue387Test extends AbstractTestCase
{
public void testIssue() throws Exception
{
Exception caught = null;
try
{
File orig = new File("testdata", "test100.mp4");
if (!orig.isFile())
{
System.err.println("Unable to test file - not available");
return;
}

File testFile = AbstractTestCase.copyAudioToTmp("test100.mp4");
AudioFile af = AudioFileIO.read(testFile);
System.out.println(af.getAudioHeader());
af.getTagOrCreateAndSetDefault();
af.commit();

Mp4AtomTree atomTree = new Mp4AtomTree(new RandomAccessFile(testFile, "r"));
atomTree.printAtomTree();

}
catch(Exception e)
{
caught=e;
e.printStackTrace();
}
assertNull(caught);
}
}
4 changes: 3 additions & 1 deletion testdata/testfiles.txt
Expand Up @@ -47,4 +47,6 @@ test94.mp3,no,369,mp3 without id3
test95.m4a,no,368,MPE reading discno,disctotal
test96.m4a,no,370,valid mp4 with corrupted free header preventing finding mdat atom
test97.mp3,no,028,Audio Version 2 Layer III
test98.m4a,no,380,Mp4 with problem with tracktotal
test98.m4a,no,380,Mp4 with problem with tracktotal
test99.mp3,no,386,Mp3 that lib sees as 128 kbps when in fact it is 192 kbps
test100.mp4,no,387,Error creating tag in mp4 file

0 comments on commit cd21637

Please sign in to comment.