public void initContainer(ReadableByteChannel readableByteChannel, long containerSize, BoxParser boxParser) throws IOException { long contentProcessed = 0; while (containerSize < 0 || contentProcessed < containerSize) { try { ParsableBox b = boxParser.parseBox(readableByteChannel, (this instanceof ParsableBox) ? ((ParsableBox) this).getType() : null); boxes.add(b); contentProcessed += b.getSize(); } catch (EOFException e) { if (containerSize < 0) { return; } else { throw e; } } } }
public ClassicMp4ContainerSource(InputStream is) throws IOException { readableByteChannel = Channels.newChannel(new TeeInputStream(is, baos)); BasicContainer container = new BasicContainer(); BoxParser boxParser = new PropertyBoxParserImpl(); Box current = null; while (current == null || !"moov".equals(current.getType())) { current = boxParser.parseBox(readableByteChannel, null); container.addBox(current); } // Either mdat was already read (yeahh sucks but what can you do if it's in the beginning) // or it's still coming for (TrackBox trackBox : Path.<TrackBox>getPaths(container, "moov[0]/trak")) { Mp4StreamingTrack mp4StreamingTrack = new Mp4StreamingTrack(trackBox); tracks.put(trackBox, mp4StreamingTrack); if (trackBox.getSampleTableBox().getCompositionTimeToSample() != null) { mp4StreamingTrack.addTrackExtension(new CompositionTimeTrackExtension()); } mp4StreamingTrack.addTrackExtension(new TrackIdTrackExtension(trackBox.getTrackHeaderBox().getTrackId())); currentChunks.put(trackBox, 1L); currentSamples.put(trackBox, 1L); } }
public void initContainer(ReadableByteChannel readableByteChannel, long containerSize, BoxParser boxParser) throws IOException { long contentProcessed = 0; while (containerSize < 0 || contentProcessed < containerSize) { try { ParsableBox b = boxParser.parseBox(readableByteChannel, (this instanceof ParsableBox) ? ((ParsableBox) this).getType() : null); boxes.add(b); contentProcessed += b.getSize(); } catch (EOFException e) { if (containerSize < 0) { return; } else { throw e; } } } }