FileDocCategorySizeDatePackage
SampleListTest.javaAPI Docmp4parser 1.0-RC-175398Wed Dec 19 20:10:22 GMT 2012com.coremedia.iso.boxes.mdat

SampleListTest

public class SampleListTest extends Object

Fields Summary
Constructors Summary
Methods Summary
java.nio.ByteBuffergetMdatContent(java.nio.channels.FileChannel fc)


        while (fc.size() - fc.position() > 8) {
            long start = fc.position();
            ByteBuffer bb = ByteBuffer.allocate(8);
            fc.read(bb);
            bb.rewind();
            long size = IsoTypeReader.readUInt32(bb);
            String type = IsoTypeReader.read4cc(bb);
            long end = start + size;
            if (type.equals("mdat")) {
                ByteBuffer mdatContent = ByteBuffer.allocate(l2i(size));
                fc.read(mdatContent);
                mdatContent.rewind();
                return mdatContent;
            }


            fc.position(end);

        }
        Assert.fail("No mdat found!?!");
        return null;
    
public voidtestFragmented()

        File fragFile = File.createTempFile("SampleListTest", "testFragmented");
        FileOutputStream fos = new FileOutputStream(fragFile);

        Movie m = MovieCreator.build(Channels.newChannel(getClass().getResourceAsStream("/Beethoven - Bagatelle op.119 no.11 i.m4a")));
        IsoFile orig = new IsoFile(Channels.newChannel(getClass().getResourceAsStream("/Beethoven - Bagatelle op.119 no.11 i.m4a")));
        SampleList slOrig = new SampleList(orig.getMovieBox().getBoxes(TrackBox.class).get(0));

        FragmentedMp4Builder fragmentedMp4Builder = new FragmentedMp4Builder();
        fragmentedMp4Builder.setIntersectionFinder(new TwoSecondIntersectionFinder());
        IsoFile isoFile = fragmentedMp4Builder.build(m);
        isoFile.getBox(fos.getChannel());
        fos.close();

        IsoFile fragmented = new IsoFile(new FileInputStream(fragFile).getChannel());
        SampleList slFrag = new SampleList(fragmented.getMovieBox().getBoxes(TrackBox.class).get(0));

        Assert.assertEquals(slOrig.size(), slFrag.size());

        Iterator<ByteBuffer> origBBIt = slOrig.iterator();
        Iterator<ByteBuffer> fragBBIt = slFrag.iterator();
        while (origBBIt.hasNext() && fragBBIt.hasNext()) {
            ByteBuffer origSample = origBBIt.next();
            ByteBuffer fragSample = fragBBIt.next();
            origSample.reset();
            fragSample.reset();
            while (origSample.remaining() > 0 && fragSample.remaining() > 0) {
                Assert.assertEquals((byte) origSample.get(), (byte) fragSample.get());
            }
            Assert.assertTrue(origSample.remaining() == 0);
            Assert.assertTrue(fragSample.remaining() == 0);
        }

    
public voidtestGotAll()

        String input = SampleListTest.class.getProtectionDomain().getCodeSource().getLocation().getFile() + "/Beethoven - Bagatelle op.119 no.11 i.m4a";

        IsoFile isoFile = new IsoFile(input);

        TrackBox tb = isoFile.getBoxes(MovieBox.class).get(0).getBoxes(TrackBox.class).get(0);
        SampleList sl = new SampleList(tb);
        FileChannel fc = new RandomAccessFile(input, "r").getChannel();
        ByteBuffer mdatContent = getMdatContent(fc);
        fc.close();

        for (ByteBuffer sample : sl) {

            while (sample.remaining() > 0) {
                byte ist = sample.get();
                byte soll = mdatContent.get();
                Assert.assertEquals("Offset " + mdatContent.position() + " soll: " + soll + " ist: " + ist, soll, ist);
            }

        }
        isoFile.close();