[xiph-commits] r3348 - libfishsound/branches/1.0-stable/src/examples

conrad at svn.annodex.net conrad at svn.annodex.net
Sat Jan 12 02:10:10 PST 2008


Author: conrad
Date: 2008-01-12 02:10:08 -0800 (Sat, 12 Jan 2008)
New Revision: 3348

Modified:
   libfishsound/branches/1.0-stable/src/examples/fishsound-decode.c
Log:
update fishsound-decode example to handle multiple logical bitstreams. It
now extracts the first audio track and ignores anything else.
Tested on some music videos off archive.org, re-encoded to Theora+FLAC.


Modified: libfishsound/branches/1.0-stable/src/examples/fishsound-decode.c
===================================================================
--- libfishsound/branches/1.0-stable/src/examples/fishsound-decode.c	2008-01-12 07:09:26 UTC (rev 3347)
+++ libfishsound/branches/1.0-stable/src/examples/fishsound-decode.c	2008-01-12 10:10:08 UTC (rev 3348)
@@ -45,6 +45,13 @@
 static FishSoundInfo fsinfo;
 static SNDFILE * sndfile;
 
+/* In general, an Ogg file may contain multiple audio tracks in parallel.
+ * To keep this example simple, we only decode the first track that we find.
+ * Tracks ("logical bitstreams" in the Ogg documentations) are identified by
+ * a serialno.
+ */
+static long decode_serialno = -1;
+
 static int
 open_output (int samplerate, int channels)
 {
@@ -79,9 +86,25 @@
 {
   FishSound * fsound = (FishSound *)user_data;
 
-  fish_sound_prepare_truncation (fsound, op->granulepos, op->e_o_s);
-  fish_sound_decode (fsound, op->packet, op->bytes);
+  /* If we have not yet selected an audio track to decode, then try
+   * to identify this one. If it is a known audio codec, then remember its
+   * serialno.
+   * NB. We only try this if we are processing a BOS (beginning of stream)
+   * packet, and it contains at least 8 bytes of data. If it contained less
+   * than 8 bytes of data, fish_sound_identify would simply return
+   * FISH_SOUND_ERR_SHORT_IDENTIFY.
+   */
+  if (decode_serialno == -1 && op->b_o_s && op->bytes >= 8) {
+    if (fish_sound_identify (op->packet, op->bytes) != FISH_SOUND_UNKNOWN)
+      decode_serialno = serialno;
+  }
 
+  /* If this is the track we are decoding, go ahead and decode it */
+  if (serialno == decode_serialno) {
+    fish_sound_prepare_truncation (fsound, op->granulepos, op->e_o_s);
+    fish_sound_decode (fsound, op->packet, op->bytes);
+  }
+
   return 0;
 }
 



More information about the commits mailing list