FileDocCategorySizeDatePackage
SampleListRenderer.javaAPI Docmp4parser 1.0-RC-175233Wed Dec 19 20:10:21 GMT 2012com.coremedia.iso.gui

SampleListRenderer

public class SampleListRenderer extends DefaultListCellRenderer
Knows how to display certain types of samples.

Fields Summary
private long
failedTrackId
private boolean
bruteforceAvc
Constructors Summary
Methods Summary
public java.awt.ComponentgetListCellRendererComponent(javax.swing.JList list, java.lang.Object value, int index, boolean isSelected, boolean cellHasFocus)


    
       
                                                   
                                                   
                                                   
                                                    
        SampleListModel.Entry sampleListEntry = (SampleListModel.Entry) value;

        value = "Sample " + (index + 1) + "@" + sampleListEntry.offset + " - " + sampleListEntry.sample.limit() + "bytes";
        final SampleEntry se = sampleListEntry.se;
        if (se != null && se instanceof VisualSampleEntry &&
                ("avc1".equals(se.getType()) || "mp4v".equals(se.getType()) || ("encv".equals(se.getType()) && ((VisualSampleEntry) se).getCompressorname().contains("AVC")))) {
            try {
                final int nalLengthSize = se.getBoxes(AvcConfigurationBox.class).get(0).getLengthSizeMinusOne() + 1;
                ArrayList<NalWrapper> nals = getNals(sampleListEntry, nalLengthSize);

                value = value + " " + nals;
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else if (sampleListEntry.avcD != null) {
            try {
                final int nalLengthSize = sampleListEntry.avcD.lengthSizeMinusOne + 1;
                ArrayList<NalWrapper> nals = getNals(sampleListEntry, nalLengthSize);

                value = value + " " + nals;
            } catch (IOException e) {
                e.printStackTrace();
            }
        } else if (bruteforceAvc && se == null && sampleListEntry.trackId != failedTrackId) {
            //try default nal length of 4
            try {
                System.out.println("No AVC SampleEntry found, trying to parse sample as AVC with default NAL length of 4bytes.");
                ArrayList<NalWrapper> nals = getNals(sampleListEntry, 4);

                value = value + " " + nals;
            } catch (Exception e) {
                failedTrackId = sampleListEntry.trackId;
                System.err.println("Didn't work. Won't try again with trackId " + failedTrackId);
                //e.printStackTrace();
            }
        }

        super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
        return this;
    
private java.util.ArrayListgetNals(SampleListModel.Entry sampleListEntry, int nalLengthSize)

        IsoSampleNALUnitReader isoSampleNALUnitReader = new IsoSampleNALUnitReader(sampleListEntry.sample, nalLengthSize);
        ArrayList<NalWrapper> nals = new ArrayList<NalWrapper>();

        do {
            ByteBuffer nal = isoSampleNALUnitReader.nextNALUnit();
            if (nal == null) {
                break;
            }
            nals.add(new NalWrapper(nal));
        } while (true);

        return nals;