Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,9 @@ protected static boolean isTheoraSpecial(OggPacket packet) {
* instance based on the type.
*/
public static TheoraPacket create(OggPacket packet) {
byte type = packet.getData()[0];

// Special header types detection
if(isTheoraSpecial(packet)) {
byte type = packet.getData()[0];
switch(type) {
case (byte)TYPE_IDENTIFICATION:
return new TheoraInfo(packet);
Expand Down
72 changes: 72 additions & 0 deletions core/src/test/java/org/gagravarr/theora/TestTheoraFileRead.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.gagravarr.ogg.OggStreamIdentifier;
import org.gagravarr.ogg.OggStreamVideoData;
import org.gagravarr.opus.OpusAudioData;
import org.gagravarr.skeleton.SkeletonFisbone;
import org.gagravarr.skeleton.SkeletonStream;
import org.gagravarr.speex.SpeexAudioData;
import org.gagravarr.vorbis.VorbisAudioData;
Expand All @@ -52,6 +53,10 @@ private InputStream getTheoraVorbisOpusSpeexFile() throws IOException {
}
// TODO Finish the other test files and use them

private InputStream getTheoraEmptyPacketsFile() throws IOException {
return this.getClass().getResourceAsStream("/TIKA-1856-1.ogx");
}

private TheoraFile tf;
@Override
protected void tearDown() throws IOException {
Expand Down Expand Up @@ -471,4 +476,71 @@ public void testGetAudioVisualDataBySid() throws Exception {
assertEquals(3, speexPackets);
assertEquals(9, vorbisPackets);
}

/**
* TIKA-1856 / Issue #51
* If the video data packet is empty, don't break!
*/
public void testEmptyPackets() throws Exception {
OggFile ogg = new OggFile(getTheoraEmptyPacketsFile());
tf = new TheoraFile(ogg);

// Check the Info
assertEquals("3.2.1", tf.getInfo().getVersion());
assertEquals(3, tf.getInfo().getMajorVersion());
assertEquals(2, tf.getInfo().getMinorVersion());
assertEquals(1, tf.getInfo().getRevisionVersion());

assertEquals(40, tf.getInfo().getFrameWidthMB());
assertEquals(27, tf.getInfo().getFrameHeightMB());
assertEquals(640, tf.getInfo().getFrameWidth());
assertEquals(432, tf.getInfo().getFrameHeight());
assertEquals(640, tf.getInfo().getPictureRegionWidth());
assertEquals(425, tf.getInfo().getPictureRegionHeight());
assertEquals(0, tf.getInfo().getPictureRegionXOffset());
assertEquals(5, tf.getInfo().getPictureRegionYOffset());

// Check the Comments
assertEquals(
"Xiph.Org libtheora 1.1 20090822 (Thusnelda)",
tf.getComments().getVendor()
);
assertEquals(2, tf.getComments().getAllComments().size());

// Check the setup
assertNotNull(tf.getSetup());

// Has a basic skeleton
assertNotNull(tf.getSkeleton());
assertNotNull(tf.getSkeleton().getFishead());
assertNotNull(tf.getSkeleton().getFisbones());
assertEquals(1, tf.getSkeleton().getFisbones().size());
SkeletonFisbone fisbone = tf.getSkeleton().getFisbones().get(0);
assertEquals("video/theora", fisbone.getMessageHeaders().get("Content-Type"));

// No soundtracks, video only
assertNotNull(tf.getSoundtracks());
assertNotNull(tf.getSoundtrackStreams());
assertEquals(0, tf.getSoundtracks().size());
assertEquals(0, tf.getSoundtrackStreams().size());

// Read all the video packets - shouldn't crash even on empty ones!
OggStreamAudioVisualData avd = null;
int numTheora = 0;
int emptyVideo = 0;
while ((avd = tf.getNextAudioVisualPacket()) != null) {
if (avd instanceof TheoraVideoData) {
numTheora++;
if (avd.getData() != null && avd.getData().length == 0) {
emptyVideo++;
}
} else {
fail("Unexpected packet " + avd.getClass());
}
}

// Verify we found some of each
assertTrue("Not enough video frames, found " + numTheora, numTheora > 0);
assertTrue("Not enough empty video frames, found " + emptyVideo, emptyVideo > 0);
}
}
Binary file added core/src/test/resources/TIKA-1856-1.ogx
Binary file not shown.