if (trun.isSampleDurationPresent()) { if (decodingTimeEntries.size() == 0 || decodingTimeEntries.get(decodingTimeEntries.size() - 1).getDelta() != entry.getSampleDuration()) { decodingTimeEntries.add(new TimeToSampleBox.Entry(1, entry.getSampleDuration())); } else { TimeToSampleBox.Entry e = decodingTimeEntries.get(decodingTimeEntries.size() - 1); e.setCount(e.getCount() + 1); decodingTimeEntries.add(new TimeToSampleBox.Entry(1, tfhd.getDefaultSampleDuration())); } else { decodingTimeEntries.add(new TimeToSampleBox.Entry(1, trex.getDefaultSampleDuration()));
if (trun.isSampleDurationPresent()) { if (decodingTimeEntries.size() == 0 || decodingTimeEntries.get(decodingTimeEntries.size() - 1).getDelta() != entry.getSampleDuration()) { decodingTimeEntries.add(new TimeToSampleBox.Entry(1, entry.getSampleDuration())); } else { TimeToSampleBox.Entry e = decodingTimeEntries.get(decodingTimeEntries.size() - 1); e.setCount(e.getCount() + 1); decodingTimeEntries.add(new TimeToSampleBox.Entry(1, tfhd.getDefaultSampleDuration())); } else { decodingTimeEntries.add(new TimeToSampleBox.Entry(1, trex.getDefaultSampleDuration()));
/** * Decompresses the list of entries and returns the list of decoding times. * * @param entries compressed entries * @return decoding time per sample */ public static synchronized long[] blowupTimeToSamples(List<TimeToSampleBox.Entry> entries) { SoftReference<long[]> cacheEntry; if ((cacheEntry = cache.get(entries)) != null) { long[] cacheVal; if ((cacheVal = cacheEntry.get()) != null) { return cacheVal; } } long numOfSamples = 0; for (TimeToSampleBox.Entry entry : entries) { numOfSamples += entry.getCount(); } assert numOfSamples <= Integer.MAX_VALUE; long[] decodingTime = new long[(int) numOfSamples]; int current = 0; for (TimeToSampleBox.Entry entry : entries) { for (int i = 0; i < entry.getCount(); i++) { decodingTime[current++] = entry.getDelta(); } } cache.put(entries, new SoftReference<long[]>(decodingTime)); return decodingTime; }
static List<TimeToSampleBox.Entry> getDecodingTimeEntries(List<TimeToSampleBox.Entry> origSamples, long fromSample, long toSample) { if (origSamples != null && !origSamples.isEmpty()) { long current = 0; ListIterator<TimeToSampleBox.Entry> e = origSamples.listIterator(); LinkedList<TimeToSampleBox.Entry> nuList = new LinkedList<TimeToSampleBox.Entry>(); // Skip while not yet reached: TimeToSampleBox.Entry currentEntry; while ((currentEntry = e.next()).getCount() + current <= fromSample) { current += currentEntry.getCount(); } // Take just a bit from the next if (currentEntry.getCount() + current >= toSample) { nuList.add(new TimeToSampleBox.Entry(toSample - fromSample, currentEntry.getDelta())); return nuList; // done in one step } else { nuList.add(new TimeToSampleBox.Entry(currentEntry.getCount() + current - fromSample, currentEntry.getDelta())); } current += currentEntry.getCount(); while (e.hasNext() && (currentEntry = e.next()).getCount() + current < toSample) { nuList.add(currentEntry); current += currentEntry.getCount(); } nuList.add(new TimeToSampleBox.Entry(toSample - current, currentEntry.getDelta())); return nuList; } else { return null; } }
protected void createStts(Track track, SampleTableBox stbl) { TimeToSampleBox.Entry lastEntry = null; List<TimeToSampleBox.Entry> entries = new ArrayList<TimeToSampleBox.Entry>(); for (long delta : track.getSampleDurations()) { if (lastEntry != null && lastEntry.getDelta() == delta) { lastEntry.setCount(lastEntry.getCount() + 1); } else { lastEntry = new TimeToSampleBox.Entry(1, delta); entries.add(lastEntry); } } TimeToSampleBox stts = new TimeToSampleBox(); stts.setEntries(entries); stbl.addBox(stts); }
@Override public void _parseDetails(ByteBuffer content) { parseVersionAndFlags(content); int entryCount = CastUtils.l2i(IsoTypeReader.readUInt32(content)); entries = new ArrayList<Entry>(entryCount); for (int i = 0; i < entryCount; i++) { entries.add(new Entry(IsoTypeReader.readUInt32(content), IsoTypeReader.readUInt32(content))); } }
if (stts.getEntries().isEmpty()) { ArrayList<TimeToSampleBox.Entry> entries = new ArrayList<TimeToSampleBox.Entry>(stts.getEntries()); entries.add(new TimeToSampleBox.Entry(1, sample.getDuration())); stts.setEntries(entries); } else { TimeToSampleBox.Entry sttsEntry = stts.getEntries().get(stts.getEntries().size() - 1); if (sttsEntry.getDelta() == sample.getDuration()) { sttsEntry.setCount(sttsEntry.getCount() + 1); } else { stts.getEntries().add(new TimeToSampleBox.Entry(1, sample.getDuration()));
/** * Decompresses the list of entries and returns the list of decoding times. * * @param entries compressed entries * @return decoding time per sample */ public static synchronized long[] blowupTimeToSamples(List<TimeToSampleBox.Entry> entries) { SoftReference<long[]> cacheEntry; if ((cacheEntry = cache.get(entries)) != null) { long[] cacheVal; if ((cacheVal = cacheEntry.get()) != null) { return cacheVal; } } long numOfSamples = 0; for (TimeToSampleBox.Entry entry : entries) { numOfSamples += entry.getCount(); } assert numOfSamples <= Integer.MAX_VALUE; long[] decodingTime = new long[(int) numOfSamples]; int current = 0; for (TimeToSampleBox.Entry entry : entries) { for (int i = 0; i < entry.getCount(); i++) { decodingTime[current++] = entry.getDelta(); } } cache.put(entries, new SoftReference<long[]>(decodingTime)); return decodingTime; }
static List<TimeToSampleBox.Entry> getDecodingTimeEntries(List<TimeToSampleBox.Entry> origSamples, long fromSample, long toSample) { if (origSamples != null && !origSamples.isEmpty()) { long current = 0; ListIterator<TimeToSampleBox.Entry> e = origSamples.listIterator(); LinkedList<TimeToSampleBox.Entry> nuList = new LinkedList<TimeToSampleBox.Entry>(); // Skip while not yet reached: TimeToSampleBox.Entry currentEntry; while ((currentEntry = e.next()).getCount() + current <= fromSample) { current += currentEntry.getCount(); } // Take just a bit from the next if (currentEntry.getCount() + current >= toSample) { nuList.add(new TimeToSampleBox.Entry(toSample - fromSample, currentEntry.getDelta())); return nuList; // done in one step } else { nuList.add(new TimeToSampleBox.Entry(currentEntry.getCount() + current - fromSample, currentEntry.getDelta())); } current += currentEntry.getCount(); while (e.hasNext() && (currentEntry = e.next()).getCount() + current < toSample) { nuList.add(currentEntry); current += currentEntry.getCount(); } nuList.add(new TimeToSampleBox.Entry(toSample - current, currentEntry.getDelta())); return nuList; } else { return null; } }