[xiph-commits] r3616 - liboggz/trunk/src/tools/oggz-chop
conrad at svn.annodex.net
conrad at svn.annodex.net
Sun Jun 29 05:16:34 PDT 2008
Author: conrad
Date: 2008-06-29 05:16:34 -0700 (Sun, 29 Jun 2008)
New Revision: 3616
Modified:
liboggz/trunk/src/tools/oggz-chop/oggz-chop.c
liboggz/trunk/src/tools/oggz-chop/oggz-chop.h
Log:
oggz-chop: add skeleton writer, fishead generator, and internal flag
for adding skeleton. Currently disabled; output file contains no
skeleton pages.
Modified: liboggz/trunk/src/tools/oggz-chop/oggz-chop.c
===================================================================
--- liboggz/trunk/src/tools/oggz-chop/oggz-chop.c 2008-06-29 10:22:43 UTC (rev 3615)
+++ liboggz/trunk/src/tools/oggz-chop/oggz-chop.c 2008-06-29 12:16:34 UTC (rev 3616)
@@ -48,6 +48,10 @@
#define OGG_PAGE_CONST(x) ((ogg_page *)x)
#endif
+#ifdef WIN32
+#define snprintf _snprintf
+#endif
+
/************************************************************
* OCTrackState
*/
@@ -120,7 +124,7 @@
/* Initialize track table and page accumulator */
state->tracks = oggz_table_new ();
- state->written_accum = 0;
+ state->status = OC_INIT;
}
static void
@@ -352,7 +356,7 @@
ogg_page * og, * min_og;
double min_time;
- if (state->written_accum) return -1;
+ if (state->status >= OC_WRITTEN_ACCUM) return -1;
/*
* We create a table of candidate tracks, which are all those which
@@ -421,7 +425,7 @@
oggz_table_delete (candidates);
- state->written_accum = 1;
+ state->status = OC_WRITTEN_ACCUM;
return 0;
}
@@ -505,8 +509,6 @@
int content_type;
fisbone_packet fisbone;
- fwrite_ogg_page (state->outfile, og);
-
content_type = oggz_stream_get_content(oggz, serialno);
if(content_type == OGGZ_CONTENT_SKELETON) {
if (fisbone_from_ogg_page (og, &fisbone) != -1) {
@@ -516,6 +518,8 @@
}
}
} else {
+ fwrite_ogg_page (state->outfile, og);
+
ts = oggz_table_lookup (state->tracks, serialno);
ts->headers_remaining -= ogg_page_packets (OGG_PAGE_CONST(og));
@@ -575,6 +579,30 @@
return 0;
}
+static long
+skeleton_write_packet (OCState * state, ogg_packet * op)
+{
+ oggz_write_feed (state->skeleton_writer, op, state->skeleton_serialno,
+ OGGZ_FLUSH_BEFORE|OGGZ_FLUSH_AFTER, NULL);
+ return oggz_run (state->skeleton_writer);
+}
+
+static long
+fishead_write (OCState * state)
+{
+ ogg_packet op;
+ int ret = -1001;
+
+ if (state->do_skeleton) {
+ ogg_from_fishead (&state->fishead, &op);
+ ret = skeleton_write_packet (state, &op);
+ _ogg_free (op.packet);
+ }
+
+ return ret;
+}
+
+
static int
read_bos (OGGZ * oggz, const ogg_page * og, long serialno, void * user_data)
{
@@ -586,14 +614,23 @@
if (ogg_page_bos (OGG_PAGE_CONST(og))) {
content_type = oggz_stream_get_content(oggz, serialno);
if(content_type == OGGZ_CONTENT_SKELETON) {
- state->original_had_skeleton = 1;
- fishead_update (state, og);
+ if (state->do_skeleton) {
+ state->original_had_skeleton = 1;
+ state->skeleton_serialno = serialno;
+ fishead_update (state, og);
+ }
} else {
ts = track_state_add (state->tracks, serialno);
fisbone_init (oggz, state, ts, serialno);
ts->headers_remaining = ts->fisbone.nr_header_packet;
}
+ /* Write the Skeleton BOS page out */
+ if (state->status == OC_INIT) {
+ fishead_write (state);
+ state->status = OC_HEADERS;
+ }
+
oggz_set_read_page (oggz, serialno, read_headers, state);
read_headers (oggz, og, serialno, user_data);
} else {
@@ -628,7 +665,14 @@
}
}
- /* set up a demux filter */
+ /* Only need the writer if creating skeleton */
+ if (state->do_skeleton) {
+ state->skeleton_writer = oggz_open_stdio (state->outfile, OGGZ_WRITE);
+ /* Choose a serialno that does not appear in the input stream. */
+ state->skeleton_serialno = oggz_serialno_new (oggz);
+ }
+
+ /* set up a demux filter on the reader */
oggz_set_read_page (oggz, -1, read_bos, state);
oggz_run_set_blocksize (oggz, 1024*1024);
Modified: liboggz/trunk/src/tools/oggz-chop/oggz-chop.h
===================================================================
--- liboggz/trunk/src/tools/oggz-chop/oggz-chop.h 2008-06-29 10:22:43 UTC (rev 3615)
+++ liboggz/trunk/src/tools/oggz-chop/oggz-chop.h 2008-06-29 12:16:34 UTC (rev 3616)
@@ -40,19 +40,32 @@
* OCState
*/
+typedef enum {
+ OC_INIT = 0, /* Done nothing yet */
+ OC_HEADERS, /* Done Skeleton BOS, copying media headers */
+ OC_SKIP, /* Skipping pages before start */
+ OC_WRITTEN_ACCUM, /* Written accum pages */
+ OC_BLAT /* Copying pages after start */
+} OCStatus;
+
typedef struct _OCState {
+ OCStatus status;
+
char * infilename;
char * outfilename;
fishead_packet fishead;
OggzTable * tracks;
+
FILE * outfile;
+ int do_skeleton; /* Boolean: should output contain skeleton? */
+ OGGZ * skeleton_writer;
+ long skeleton_serialno;
double start;
double end;
int original_had_skeleton;
- int written_accum;
} OCState;
More information about the commits
mailing list