[xiph-commits] r3614 - in liboggz/trunk/src/tools: . oggz-chop
conrad at svn.annodex.net
conrad at svn.annodex.net
Sun Jun 29 02:24:17 PDT 2008
Author: conrad
Date: 2008-06-29 02:24:16 -0700 (Sun, 29 Jun 2008)
New Revision: 3614
Modified:
liboggz/trunk/src/tools/oggz-chop/Makefile.am
liboggz/trunk/src/tools/oggz-chop/cgi.c
liboggz/trunk/src/tools/oggz-chop/cmd.c
liboggz/trunk/src/tools/oggz-chop/oggz-chop.c
liboggz/trunk/src/tools/oggz-chop/oggz-chop.h
liboggz/trunk/src/tools/skeleton.c
liboggz/trunk/src/tools/skeleton.h
Log:
oggz-chop: add fishead and fisbone structures for all tracks, initialize
with existing skeleton track if available (else use codec info parsed by
oggz) and update with chop parameters and start_granules.
Modified: liboggz/trunk/src/tools/oggz-chop/Makefile.am
===================================================================
--- liboggz/trunk/src/tools/oggz-chop/Makefile.am 2008-06-29 08:26:28 UTC (rev 3613)
+++ liboggz/trunk/src/tools/oggz-chop/Makefile.am 2008-06-29 09:24:16 UTC (rev 3614)
@@ -1,7 +1,7 @@
## Process this file with automake to produce Makefile.in
INCLUDES = -I$(top_builddir) -I$(top_builddir)/include \
- -I$(top_srcdir)/include -I$(top_srcdir)/src/tests \
+ -I$(top_srcdir)/include -I$(top_srcdir)/src/tools \
@OGG_CFLAGS@
OGGZDIR = ../../liboggz
@@ -24,7 +24,8 @@
noinst_HEADERS = cgi.h cmd.h header.h httpdate.h oggz-chop.h timespec.h
-oggz_chop_SOURCES = oggz-chop.c ../oggz_tools.c cmd.c cgi.c header.c httpdate.c main.c timespec.c
+oggz_chop_SOURCES = oggz-chop.c ../oggz_tools.c ../skeleton.c \
+ cmd.c cgi.c header.c httpdate.c main.c timespec.c
oggz_chop_LDADD = $(OGGZ_LIBS) -lm
httpdate_test_SOURCES = httpdate.c httpdate_test.c
Modified: liboggz/trunk/src/tools/oggz-chop/cgi.c
===================================================================
--- liboggz/trunk/src/tools/oggz-chop/cgi.c 2008-06-29 08:26:28 UTC (rev 3613)
+++ liboggz/trunk/src/tools/oggz-chop/cgi.c 2008-06-29 09:24:16 UTC (rev 3614)
@@ -137,9 +137,8 @@
query_string = getenv ("QUERY_STRING");
if_modified_since = getenv ("HTTP_IF_MODIFIED_SINCE");
+ memset (state, 0, sizeof(*state));
state->infilename = path_translated;
- state->outfilename = NULL;
- state->start = 0.0;
state->end = -1.0;
/*photo_init (¶ms->in, path_translated);*/
Modified: liboggz/trunk/src/tools/oggz-chop/cmd.c
===================================================================
--- liboggz/trunk/src/tools/oggz-chop/cmd.c 2008-06-29 08:26:28 UTC (rev 3613)
+++ liboggz/trunk/src/tools/oggz-chop/cmd.c 2008-06-29 09:24:16 UTC (rev 3614)
@@ -44,10 +44,8 @@
return (1);
}
- state->start = 0.0;
+ memset (state, 0, sizeof(*state));
state->end = -1.0;
- state->infilename = NULL;
- state->outfilename = NULL;
while (1) {
char * optstring = "s:e:o:hv";
Modified: liboggz/trunk/src/tools/oggz-chop/oggz-chop.c
===================================================================
--- liboggz/trunk/src/tools/oggz-chop/oggz-chop.c 2008-06-29 08:26:28 UTC (rev 3613)
+++ liboggz/trunk/src/tools/oggz-chop/oggz-chop.c 2008-06-29 09:24:16 UTC (rev 3614)
@@ -40,6 +40,7 @@
#include <oggz/oggz.h>
#include "oggz-chop.h"
+#include "skeleton.h"
#ifdef OGG_H_CONST_CORRECT
#define OGG_PAGE_CONST(x) (x)
@@ -52,12 +53,15 @@
*/
typedef struct _OCTrackState {
+ /* Skeleton track info (fisbone) */
+ fisbone_packet fisbone;
+
+ /* Page accumulator for the GOP before the chop start */
OggzTable * page_accum;
int headers_remaining;
int rec_skeleton;
- long start_granule;
/* Greatest previously inferred keyframe value */
ogg_int64_t prev_keyframe;
@@ -81,6 +85,8 @@
{
if (ts == NULL) return;
+ fisbone_clear (&ts->fisbone);
+
/* XXX: delete accumulated pages */
oggz_table_delete (ts->page_accum);
@@ -96,6 +102,7 @@
OCTrackState * ts;
ts = track_state_new ();
+
if (oggz_table_insert (state, serialno, ts) == ts) {
return ts;
} else {
@@ -107,6 +114,11 @@
static void
state_init (OCState * state)
{
+ /* Initialize fishead presentation time */
+ state->fishead.ptime_n = state->start / (ogg_int64_t)1000;
+ state->fishead.ptime_d = 1000;
+
+ /* Initialize track table and page accumulator */
state->tracks = oggz_table_new ();
state->written_accum = 0;
}
@@ -261,7 +273,7 @@
/* Record this track's start_granule as the granulepos of the page prior
* to earliest_new */
if (i == (earliest_new-1)) {
- ts->start_granule = ogg_page_granulepos (pa->og);
+ ts->fisbone.start_granule = ogg_page_granulepos (pa->og);
}
page_accum_delete(pa);
oggz_table_remove (ts->page_accum, (long)i);
@@ -306,12 +318,13 @@
if (page_time < state->start) {
if ((gp = ogg_page_granulepos (og)) != -1)
- ts->start_granule = ogg_page_granulepos (og);
+ ts->fisbone.start_granule = ogg_page_granulepos (og);
} else if (page_time >= state->start &&
(state->end == -1 || page_time <= state->end)) {
if (!ts->rec_skeleton) {
#ifdef DEBUG
- printf ("read_plain: start granule for serialno %010ld: %ld\n", serialno, ts->start_granule);
+ printf ("read_plain: start granule for serialno %010ld: %ld\n",
+ serialno, ts->fisbone.start_granule);
#endif
ts->rec_skeleton = 1;
}
@@ -440,7 +453,8 @@
if (!ts->rec_skeleton) {
#ifdef DEBUG
- printf ("read_gs: start granule for serialno %010ld: %ld\n", serialno, ts->start_granule);
+ printf ("read_gs: start granule for serialno %010ld: %ld\n",
+ serialno, ts->fisbone.start_granule);
#endif
ts->rec_skeleton = 1;
}
@@ -488,18 +502,28 @@
{
OCState * state = (OCState *)user_data;
OCTrackState * ts;
+ int content_type;
+ fisbone_packet fisbone;
fwrite_ogg_page (state->outfile, og);
- ts = oggz_table_lookup (state->tracks, serialno);
- ts->headers_remaining -= ogg_page_packets (OGG_PAGE_CONST(og));
+ content_type = oggz_stream_get_content(oggz, serialno);
+ if(content_type == OGGZ_CONTENT_SKELETON) {
+ fisbone_from_ogg_page (og, &fisbone);
+ ts = oggz_table_lookup (state->tracks, fisbone.serial_no);
+ ts->fisbone.current_header_size = fisbone.current_header_size;
+ ts->fisbone.message_header_fields = fisbone.message_header_fields;
+ } else {
+ ts = oggz_table_lookup (state->tracks, serialno);
+ ts->headers_remaining -= ogg_page_packets (OGG_PAGE_CONST(og));
- if (ts->headers_remaining <= 0) {
- if (state->start == 0.0 || oggz_get_granuleshift (oggz, serialno) == 0) {
- oggz_set_read_page (oggz, serialno, read_plain, state);
- } else {
- ts->page_accum = oggz_table_new();
- oggz_set_read_page (oggz, serialno, read_gs, state);
+ if (ts->headers_remaining <= 0) {
+ if (state->start == 0.0 || oggz_get_granuleshift (oggz, serialno) == 0) {
+ oggz_set_read_page (oggz, serialno, read_plain, state);
+ } else {
+ ts->page_accum = oggz_table_new();
+ oggz_set_read_page (oggz, serialno, read_gs, state);
+ }
}
}
@@ -507,15 +531,66 @@
}
static int
+fisbone_init (OGGZ * oggz, OCState * state, OCTrackState * ts, long serialno)
+{
+ const char * content_type;
+ int len;
+
+ if (ts == NULL) return -1;
+
+ ts->fisbone.serial_no = serialno;
+ ts->fisbone.nr_header_packet = oggz_stream_get_numheaders (oggz, serialno);
+ oggz_get_granulerate (oggz, serialno, &ts->fisbone.granule_rate_n, &ts->fisbone.granule_rate_d);
+ ts->fisbone.start_granule = 0;
+ ts->fisbone.preroll = 0;
+ ts->fisbone.granule_shift = (unsigned char) oggz_get_granuleshift (oggz, serialno);
+ if (state->original_had_skeleton) {
+ /* Wait, and copy over message headers from original */
+ ts->fisbone.message_header_fields = NULL;
+ ts->fisbone.current_header_size = FISBONE_SIZE;
+ } else {
+ /* XXX: C99 */
+#define CONTENT_TYPE_FMT "Content-Type: %s\r\n"
+ content_type = oggz_stream_get_content_type (oggz, serialno);
+ len = snprintf (NULL, 0, CONTENT_TYPE_FMT, content_type);
+ ts->fisbone.message_header_fields = malloc(len+1);
+ snprintf (ts->fisbone.message_header_fields, len+1, CONTENT_TYPE_FMT, content_type);
+ ts->fisbone.current_header_size = len+1;
+ }
+
+ return 0;
+}
+
+static int
+fishead_update (OCState * state, const ogg_page * og)
+{
+ fishead_packet fishead;
+
+ fishead_from_ogg_page (og, &fishead);
+ state->fishead.btime_n = fishead.btime_n;
+ state->fishead.btime_d = fishead.btime_d;
+
+ return 0;
+}
+
+static int
read_bos (OGGZ * oggz, const ogg_page * og, long serialno, void * user_data)
{
OCState * state = (OCState *)user_data;
OCTrackState * ts;
double page_time;
+ int content_type;
if (ogg_page_bos (OGG_PAGE_CONST(og))) {
- ts = track_state_add (state->tracks, serialno);
- ts->headers_remaining = oggz_stream_get_numheaders (oggz, serialno);
+ content_type = oggz_stream_get_content(oggz, serialno);
+ if(content_type == OGGZ_CONTENT_SKELETON) {
+ state->original_had_skeleton = 1;
+ 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;
+ }
oggz_set_read_page (oggz, serialno, read_headers, state);
read_headers (oggz, og, serialno, user_data);
Modified: liboggz/trunk/src/tools/oggz-chop/oggz-chop.h
===================================================================
--- liboggz/trunk/src/tools/oggz-chop/oggz-chop.h 2008-06-29 08:26:28 UTC (rev 3613)
+++ liboggz/trunk/src/tools/oggz-chop/oggz-chop.h 2008-06-29 09:24:16 UTC (rev 3614)
@@ -34,6 +34,8 @@
#include <oggz/oggz.h>
+#include "skeleton.h"
+
/************************************************************
* OCState
*/
@@ -42,12 +44,14 @@
char * infilename;
char * outfilename;
+ fishead_packet fishead;
OggzTable * tracks;
FILE * outfile;
double start;
double end;
+ int original_had_skeleton;
int written_accum;
} OCState;
Modified: liboggz/trunk/src/tools/skeleton.c
===================================================================
--- liboggz/trunk/src/tools/skeleton.c 2008-06-29 08:26:28 UTC (rev 3613)
+++ liboggz/trunk/src/tools/skeleton.c 2008-06-29 09:24:16 UTC (rev 3614)
@@ -196,7 +196,7 @@
}
/* fills up a fishead_packet from a fishead ogg_page of a skeleton bistream */
-int fishead_from_ogg_page (ogg_page *og, fishead_packet *fp) {
+int fishead_from_ogg_page (const ogg_page *og, fishead_packet *fp) {
return fishead_from_data (og->body, og->body_len, fp);
}
@@ -229,7 +229,7 @@
}
/* fills up a fisbone_packet from a fisbone ogg_page of a skeleton bistream */
-int fisbone_from_ogg_page (ogg_page *og, fisbone_packet *fp) {
+int fisbone_from_ogg_page (const ogg_page *og, fisbone_packet *fp) {
return fisbone_from_data (og->body, og->body_len, fp);
}
Modified: liboggz/trunk/src/tools/skeleton.h
===================================================================
--- liboggz/trunk/src/tools/skeleton.h 2008-06-29 08:26:28 UTC (rev 3613)
+++ liboggz/trunk/src/tools/skeleton.h 2008-06-29 09:24:16 UTC (rev 3614)
@@ -57,8 +57,8 @@
extern int fisbone_clear(fisbone_packet *fp);
extern int fishead_from_ogg(ogg_packet *op,fishead_packet *fp);
extern int fisbone_from_ogg(ogg_packet *op,fisbone_packet *fp);
-extern int fishead_from_ogg_page(ogg_page *og,fishead_packet *fp);
-extern int fisbone_from_ogg_page(ogg_page *og,fisbone_packet *fp);
+extern int fishead_from_ogg_page(const ogg_page *og,fishead_packet *fp);
+extern int fisbone_from_ogg_page(const ogg_page *og,fisbone_packet *fp);
extern int add_fishead_to_stream(ogg_stream_state *os, fishead_packet *fp);
extern int add_fisbone_to_stream(ogg_stream_state *os, fisbone_packet *fp);
extern int add_eos_packet_to_stream(ogg_stream_state *os);
More information about the commits
mailing list