[xiph-commits] r3742 - libannodex/trunk/src/importers
conrad at svn.annodex.net
conrad at svn.annodex.net
Mon Oct 27 01:45:04 PDT 2008
Author: conrad
Date: 2008-10-27 01:45:04 -0700 (Mon, 27 Oct 2008)
New Revision: 3742
Modified:
libannodex/trunk/src/importers/anx_import_ogg.c
Log:
anx_import_ogg: re-order functions into separate sections for setup, read, open
Modified: libannodex/trunk/src/importers/anx_import_ogg.c
===================================================================
--- libannodex/trunk/src/importers/anx_import_ogg.c 2008-10-27 08:44:58 UTC (rev 3741)
+++ libannodex/trunk/src/importers/anx_import_ogg.c 2008-10-27 08:45:04 UTC (rev 3742)
@@ -278,65 +278,10 @@
}
/***********************************************************
- *
+ * Setup
*/
-static double
-anxogg_seek_update (AnxSource * source)
-{
- AnxOggData * aod = (AnxOggData *)source->custom_data;
- double seek_offset;
- ogg_int64_t units, units_at;
- double offset;
- if (aod->use_granule_seek) {
- seek_offset = aod->min_granule_seek;
-#ifdef DEBUG
- fprintf(aod->df, "anxogg_seek_update: using min_granule_seek %f\n",
- seek_offset);
-#endif
- } else {
- seek_offset = source->start_time;
-#ifdef DEBUG
- fprintf(aod->df, "anxogg_seek_update: using start time %f\n", seek_offset);
-#endif
- }
- seek_offset -= 1.0;
- if (seek_offset < 0.0) seek_offset = 0.0;
-
- units = (ogg_int64_t)(SUBSECONDS * seek_offset);
- units_at = oggz_seek_units (aod->oggz, units, SEEK_SET);
-
- if (units_at == -1) {
-#ifdef DEBUG
- fprintf (aod->df, "anxogg_seek_update: oggz_seek_units FAIL\n");
-#endif
- return -1.0;
- }
-
- offset = ((double)units_at) / SUBSECONDS;
-
- aod->need_seek = NEED_SEEK_DONE;
-
-#ifdef DEBUG
- fprintf (aod->df,
- "anxogg: seek_update to %lld (wanted %lld (%f))\n", units_at,
- units, seek_offset);
-#endif
-
- if (source->end_time != -1.0 && offset >= source->end_time) {
-#ifdef DEBUG
- fprintf (aod->df,
- "anxoggg: seek update > end_time %f\n", source->end_time);
-#endif
- aod->got_end = 1;
- }
-
- return offset;
-}
-
-/***********************************************************
- * Parse Ogg BOS packet headers and fill in track info.
- */
+/* Parse Ogg BOS packet headers and fill in track info. */
static int
read_packet_headers (OGGZ * oggz, ogg_packet * op, long serialno,
void * user_data)
@@ -586,7 +531,349 @@
return OGGZ_CONTINUE;
}
+static int
+granuleinfo_update_state (AnxOggData * aod)
+{
+ AnxOggTrack * aot;
+ int i, n;
+
+#ifdef DEBUG
+ //fprintf (aod->df, "anxogg::granuleinfo_update_state cmml %010ld %s\n",
+ // aod->cmml_serialno,
+ // aod->cmml_need_keygranule ? "needs keygranule" : "no keygranule");
+#endif
+
+ if (aod->cmml_serialno != -1 && aod->cmml_need_keygranule) return 0;
+
+ n = oggz_table_size (aod->logicals);
+
+#ifdef DEBUG
+ fprintf (aod->df, "anxogg::granuleinfo_update_state %d logicals\n", n);
+#endif
+
+ for (i = 0; i < n; i++) {
+ aot = (AnxOggTrack *)oggz_table_nth (aod->logicals, i, NULL);
+ if (aot->need_keygranule) {
+#ifdef DEBUG
+ fprintf (aod->df, "anxogg::granuleinfo_update_state logical %d needs keygranule\n", i);
+#endif
+ return 0;
+ }
+ }
+
+ aod->state = STATE_FILTER;
+
+ return 0;
+}
+
+/*
+ * look for tracks, extract granule information. This is a preprocessor
+ * step that scans until info is found for all tracks. When all tracks
+ * are found, granuleinfo_update_state will set the state to FILTER and the
+ * loop will end.
+ *
+ * Note that in anxogg_setup() below, this packet reading callback is
+ * used after seeking to the specified startpos for the media.
+ */
+static int
+read_page_granuleinfo (OGGZ * oggz, const ogg_page * og, long serialno,
+ void * user_data)
+{
+ AnxOggData * aod = (AnxOggData *)user_data;
+ AnxOggTrack * aot = NULL;
+ AnxSourceTrack * track = NULL;
+ ogg_int64_t granulepos, iframe, pframe;
+ ogg_int64_t cmml_keygranule;
+ double offset, start_time;
+
+#ifdef DEBUG
+ static int page=0;
+ fprintf (aod->df, "read_page_granuleinfo: track %010ld page %d", serialno,
+ page++);
+#endif
+
+ granulepos = ogg_page_granulepos ((ogg_page *)og);
+ if (granulepos == -1) return OGGZ_STOP_OK;
+
+#ifdef DEBUG
+ fprintf(aod->df, " granulepos %llx cmml_serialno %d", granulepos,
+ aod->cmml_serialno);
+ fprintf(aod->df, " bytepos %d\n", oggz_tell(oggz));
+#endif
+
+ if (aod->cmml_serialno != -1 && serialno == aod->cmml_serialno) {
+ if (!aod->cmml_need_keygranule) return OGGZ_STOP_OK;
+
+#ifdef DEBUG
+ fprintf (aod->df, "read_page_granuleinfo: cmml_need_keygranule -> 0\n");
+#endif
+ aod->cmml_need_keygranule = 0;
+
+ /* If this content does use cmml_granuleshift, and this clip is right at
+ * the start time, there's no need to include the clip previous to this.
+ */
+ start_time = aod->anx_source->start_time;
+ offset = gp_to_time (aod->oggz, serialno, granulepos);
+ if (offset-TOLERANCE <= start_time) {
+ return OGGZ_STOP_OK;
+ }
+
+ iframe = granulepos >> aod->cmml_granuleshift;
+ cmml_keygranule = iframe << aod->cmml_granuleshift;
+#ifdef DEBUG
+ fprintf(aod->df, "cmml_keygranule is %llx\n", cmml_keygranule);
+#endif
+
+ offset = gp_to_time (aod->oggz, serialno, cmml_keygranule);
+ if (aod->min_granule_seek == 0.0 || offset < aod->min_granule_seek)
+ aod->min_granule_seek = offset;
+ } else {
+
+ aot = (AnxOggTrack *) oggz_table_lookup (aod->logicals, serialno);
+ if (aot == NULL) {
+ /* If this track is not in the table, ignore it. */
+ return OGGZ_STOP_OK;
+ }
+
+ track = &(aot->source_track);
+
+ /* Slurp in granuleinfo */
+ if (aot->need_keygranule) {
+ iframe = granulepos >> track->granuleshift;
+ pframe = granulepos - (iframe << track->granuleshift);
+
+ if (iframe > 0 && track->basegranule == 0.0)
+ track->basegranule = (iframe-1) << track->granuleshift;
+
+#if 1
+ /* XXX: vaguely similar reasoning to CMML above */
+ start_time = aod->anx_source->start_time;
+ offset = gp_to_time (aod->oggz, serialno, granulepos);
+#ifdef DEBUG
+ fprintf(aod->df, "offset %f start_time %f TOLERANCE %f\n", offset,
+ start_time, TOLERANCE);
+#endif
+ if (offset-TOLERANCE <= start_time) {
+ return OGGZ_STOP_OK;
+ }
+ /* End XXX: */
+#endif
+
+
+ granulepos = (iframe + pframe);
+ aot->keygranule = iframe << track->granuleshift;
+ aot->need_keygranule = 0;
+
+ offset = gp_to_time (aod->oggz, serialno, aot->keygranule);
+ aot->keygranule_time = offset;
+ if (aod->min_granule_seek == 0.0 || offset < aod->min_granule_seek) {
+ aod->min_granule_seek = offset;
+#ifdef DEBUG
+ fprintf (aod->df, "set min_granule_seek to %f\n",
+ aod->min_granule_seek);
+#endif
+ }
+#ifdef DEBUG
+ fprintf (aod->df,
+ "read_page_granuleinfo: ^^^ has keygranule "
+ "%lld (%lld|0) (%f seconds) (granuleshift %d)\n",
+ aot->keygranule, iframe, offset, track->granuleshift);
+#endif
+ }
+ }
+
+ /* Update state */
+ granuleinfo_update_state (aod);
+
+ return OGGZ_STOP_OK;
+}
+
+
+static int
+anxogg_setup (AnxOggData * aod)
+{
+ long n;
+ double start_time = 0.0, end_time = -1.0;
+ off_t start_offset = 0, end_offset = -1;
+ ogg_int64_t units, units_at;
+
+ /* Slurp headers */
+ oggz_set_read_callback (aod->oggz, -1, read_packet_headers, aod);
+ while (aod->state == STATE_HEADERS &&
+ (n = oggz_read (aod->oggz, 1024)) != 0);
+
+#ifdef DEBUG
+ fprintf (aod->df,
+ "anxogg: slurped headers:\n"
+ "\toggz_read returned %ld\n"
+ "\taod->got_non_bos == %d\n"
+ "\taod->got_skeleton_eos == %d\n"
+ "\taod->nr_headers_remaining = %d\n",
+ n, aod->got_non_bos, aod->got_skeleton_eos,
+ aod->nr_headers_remaining);
+#endif
+
+ /* Find bitrate info */
+ start_time = aod->anx_source->start_time;
+ end_time = aod->anx_source->end_time;
+
+ /* Check if the end_time is bigger than the end of the file */
+ units_at = oggz_seek_units (aod->oggz, 0, SEEK_END);
+ if (units_at == -1) {
+#ifdef DEBUG
+ fprintf (aod->df, "anxogg_setup: oggz_seek_units end FAIL\n");
+#endif
+ return -1;
+ } else {
+ int actual_end_time;
+
+ actual_end_time = ((double)units_at) / 1000.0;
+
+ if (end_time > actual_end_time) {
+ end_time = -1.0;
+ }
+ }
+
+ if (end_time == -1.0) {
+#ifdef DEBUG
+ fprintf(aod->df, "calling oggz_seek with whence of %d\n", SEEK_END);
+#endif
+ end_offset = oggz_seek (aod->oggz, 0, SEEK_END);
+#ifdef DEBUG
+ fprintf (aod->df, "anxogg_setup: end_offset is %d\n", end_offset);
+#endif
+
+ } else {
+ units = (ogg_int64_t)(SUBSECONDS * end_time);
+ units_at = oggz_seek_units (aod->oggz, units, SEEK_SET);
+ if (units_at == -1) {
+#ifdef DEBUG
+ fprintf (aod->df, "anxogg_setup: oggz_seek_units end FAIL\n");
+#endif
+ return -1;
+ }
+ end_offset = oggz_tell (aod->oggz);
+ }
+
+ units = (ogg_int64_t)(SUBSECONDS * start_time);
+ units_at = oggz_seek_units (aod->oggz, units, SEEK_SET);
+#ifdef DEBUG
+ fprintf(aod->df, "oggz_seek_units on %lld returned %lld\n", units, units_at);
+#endif
+ if (units_at == -1) {
+#ifdef DEBUG
+ fprintf (aod->df, "anxogg_setup: oggz_seek_units start FAIL\n");
+#endif
+ return -1;
+ }
+ start_offset = oggz_tell (aod->oggz);
+
+ aod->anx_source->byte_length = end_offset - start_offset;
+ if (end_time != -1) {
+ aod->anx_source->duration = end_time - start_time;
+ }
+
+#ifdef DEBUG
+ fprintf (aod->df,
+ "anxogg_setup: times (%f - %f) = %f\n", start_time, end_time,
+ end_time - start_time);
+ fprintf (aod->df, "anxogg_setup: got byte range [%ld - %ld] = %ld bytes\n",
+ start_offset, end_offset, end_offset - start_offset);
+#endif
+
+ /* Find granule_seek info */
+ if (aod->use_granule_seek && start_time > 0.0) {
+ oggz_set_read_callback (aod->oggz, -1, NULL, NULL);
+ oggz_set_read_page (aod->oggz, -1, read_page_granuleinfo, aod);
+ while (aod->state == STATE_GRANULEINFO &&
+ (n = oggz_read (aod->oggz, 1024)) != 0);
+ aod->state = STATE_FILTER;
+ oggz_set_read_page (aod->oggz, -1, NULL, NULL);
+ }
+
+ /* Reset to beginning */
+ oggz_seek (aod->oggz, 0, SEEK_SET);
+ aod->nr_headers_remaining = aod->headers_unread;
+
+ return 0;
+}
+
/***********************************************************
+ * Read: Pass data packets to the writer
+ */
+
+static double
+anxogg_seek_update (AnxSource * source)
+{
+ AnxOggData * aod = (AnxOggData *)source->custom_data;
+ double seek_offset;
+ ogg_int64_t units, units_at;
+ double offset;
+
+ if (aod->use_granule_seek) {
+ seek_offset = aod->min_granule_seek;
+#ifdef DEBUG
+ fprintf(aod->df, "anxogg_seek_update: using min_granule_seek %f\n",
+ seek_offset);
+#endif
+ } else {
+ seek_offset = source->start_time;
+#ifdef DEBUG
+ fprintf(aod->df, "anxogg_seek_update: using start time %f\n", seek_offset);
+#endif
+ }
+ seek_offset -= 1.0;
+ if (seek_offset < 0.0) seek_offset = 0.0;
+
+ units = (ogg_int64_t)(SUBSECONDS * seek_offset);
+ units_at = oggz_seek_units (aod->oggz, units, SEEK_SET);
+
+ if (units_at == -1) {
+#ifdef DEBUG
+ fprintf (aod->df, "anxogg_seek_update: oggz_seek_units FAIL\n");
+#endif
+ return -1.0;
+ }
+
+ offset = ((double)units_at) / SUBSECONDS;
+
+ aod->need_seek = NEED_SEEK_DONE;
+
+#ifdef DEBUG
+ fprintf (aod->df,
+ "anxogg: seek_update to %lld (wanted %lld (%f))\n", units_at,
+ units, seek_offset);
+#endif
+
+ if (source->end_time != -1.0 && offset >= source->end_time) {
+#ifdef DEBUG
+ fprintf (aod->df,
+ "anxoggg: seek update > end_time %f\n", source->end_time);
+#endif
+ aod->got_end = 1;
+ }
+
+ return offset;
+}
+
+static long
+anxogg_read_update (AnxSource * media)
+{
+ AnxOggData * aod = (AnxOggData *)media->custom_data;
+
+ do_read:
+
+ while ((aod->media_packets == NULL) && (oggz_read (aod->oggz, 1024)) != 0);
+
+ if (aod->need_seek == NEED_SEEK && aod->nr_headers_remaining == 0) {
+ anxogg_seek_update (media);
+ goto do_read;
+ }
+
+ return 0;
+}
+
+/***********************************************************
* A filter predicate, used between the min seek granule
* and the start time (ie. the bit between the prior keyframe
* and the chop time) to filter packets which should be
@@ -847,272 +1134,102 @@
return OGGZ_STOP_OK;
}
-static int
-granuleinfo_update_state (AnxOggData * aod)
+static AnxOggPacket *
+anxogg_packet_free (AnxOggPacket * aop)
{
- AnxOggTrack * aot;
- int i, n;
+ anx_free (aop->data);
+ anx_free (aop);
+ return NULL;
+}
-#ifdef DEBUG
- //fprintf (aod->df, "anxogg::granuleinfo_update_state cmml %010ld %s\n",
- // aod->cmml_serialno,
- // aod->cmml_need_keygranule ? "needs keygranule" : "no keygranule");
-#endif
+static long
+anxogg_read (AnxSource * media, char * buf, long n, long bound)
+{
+ AnxOggData * aod = (AnxOggData *)media->custom_data;
+ AnxOggPacket * aop;
+ AnxList * head;
+ long bytes_to_read;
- if (aod->cmml_serialno != -1 && aod->cmml_need_keygranule) return 0;
+ if (aod->ignore_media) return -1;
- n = oggz_table_size (aod->logicals);
+ anxogg_read_update (media);
-#ifdef DEBUG
- fprintf (aod->df, "anxogg::granuleinfo_update_state %d logicals\n", n);
-#endif
-
- for (i = 0; i < n; i++) {
- aot = (AnxOggTrack *)oggz_table_nth (aod->logicals, i, NULL);
- if (aot->need_keygranule) {
-#ifdef DEBUG
- fprintf (aod->df, "anxogg::granuleinfo_update_state logical %d needs keygranule\n", i);
-#endif
- return 0;
- }
+ head = aod->media_packets;
+ if (head == NULL) {
+ media->eos = 1;
+ return 0;
}
- aod->state = STATE_FILTER;
+ aop = (AnxOggPacket *)head->data;
+ bytes_to_read = MIN (n, aop->length - aod->current_offset);
- return 0;
-}
+ memcpy (buf, &aop->data[aod->current_offset], bytes_to_read);
-/*
- * look for tracks, extract granule information. This is a preprocessor
- * step that scans until info is found for all tracks. When all tracks
- * are found, granuleinfo_update_state will set the state to FILTER and the
- * loop will end.
- *
- * Note that in anxogg_setup() below, this packet reading callback is
- * used after seeking to the specified startpos for the media.
- */
-static int
-read_page_granuleinfo (OGGZ * oggz, const ogg_page * og, long serialno,
- void * user_data)
-{
- AnxOggData * aod = (AnxOggData *)user_data;
- AnxOggTrack * aot = NULL;
- AnxSourceTrack * track = NULL;
- ogg_int64_t granulepos, iframe, pframe;
- ogg_int64_t cmml_keygranule;
- double offset, start_time;
+ aod->current_offset += bytes_to_read;
-#ifdef DEBUG
- static int page=0;
- fprintf (aod->df, "read_page_granuleinfo: track %010ld page %d", serialno,
- page++);
-#endif
+ if (aod->headers_unread > 0) aod->headers_unread--;
+ if (aod->headers_unread == 0) media->written_secondaries = 1;
- granulepos = ogg_page_granulepos ((ogg_page *)og);
- if (granulepos == -1) return OGGZ_STOP_OK;
+ media->current_track = aop->source_track;
-#ifdef DEBUG
- fprintf(aod->df, " granulepos %llx cmml_serialno %d", granulepos,
- aod->cmml_serialno);
- fprintf(aod->df, " bytepos %d\n", oggz_tell(oggz));
+#ifdef DEBUG_VERBOSE
+ fprintf (aod->df, "anxogg: reading from stream %s\n",
+ media->current_track->content_type);
#endif
-
- if (aod->cmml_serialno != -1 && serialno == aod->cmml_serialno) {
- if (!aod->cmml_need_keygranule) return OGGZ_STOP_OK;
-#ifdef DEBUG
- fprintf (aod->df, "read_page_granuleinfo: cmml_need_keygranule -> 0\n");
-#endif
- aod->cmml_need_keygranule = 0;
+ media->current_track->current_granule = aop->granulepos;
+ media->current_track->eos = aop->eos;
- /* If this content does use cmml_granuleshift, and this clip is right at
- * the start time, there's no need to include the clip previous to this.
- */
- start_time = aod->anx_source->start_time;
- offset = gp_to_time (aod->oggz, serialno, granulepos);
- if (offset-TOLERANCE <= start_time) {
- return OGGZ_STOP_OK;
- }
+ /* If that's finished this media packet, advance to the next one */
+ if (aod->current_offset >= aop->length) {
+ aod->media_packets =
+ anx_list_remove (aod->media_packets, head);
- iframe = granulepos >> aod->cmml_granuleshift;
- cmml_keygranule = iframe << aod->cmml_granuleshift;
-#ifdef DEBUG
- fprintf(aod->df, "cmml_keygranule is %llx\n", cmml_keygranule);
-#endif
+ aop = anxogg_packet_free (aop);
+ anx_free (head);
- offset = gp_to_time (aod->oggz, serialno, cmml_keygranule);
- if (aod->min_granule_seek == 0.0 || offset < aod->min_granule_seek)
- aod->min_granule_seek = offset;
- } else {
+ aod->current_offset = 0;
- aot = (AnxOggTrack *) oggz_table_lookup (aod->logicals, serialno);
- if (aot == NULL) {
- /* If this track is not in the table, ignore it. */
- return OGGZ_STOP_OK;
- }
+ anxogg_read_update (media);
- track = &(aot->source_track);
-
- /* Slurp in granuleinfo */
- if (aot->need_keygranule) {
- iframe = granulepos >> track->granuleshift;
- pframe = granulepos - (iframe << track->granuleshift);
-
- if (iframe > 0 && track->basegranule == 0.0)
- track->basegranule = (iframe-1) << track->granuleshift;
-
-#if 1
- /* XXX: vaguely similar reasoning to CMML above */
- start_time = aod->anx_source->start_time;
- offset = gp_to_time (aod->oggz, serialno, granulepos);
-#ifdef DEBUG
- fprintf(aod->df, "offset %f start_time %f TOLERANCE %f\n", offset,
- start_time, TOLERANCE);
-#endif
- if (offset-TOLERANCE <= start_time) {
- return OGGZ_STOP_OK;
- }
- /* End XXX: */
-#endif
-
-
- granulepos = (iframe + pframe);
- aot->keygranule = iframe << track->granuleshift;
- aot->need_keygranule = 0;
-
- offset = gp_to_time (aod->oggz, serialno, aot->keygranule);
- aot->keygranule_time = offset;
- if (aod->min_granule_seek == 0.0 || offset < aod->min_granule_seek) {
- aod->min_granule_seek = offset;
-#ifdef DEBUG
- fprintf (aod->df, "set min_granule_seek to %f\n",
- aod->min_granule_seek);
-#endif
- }
-#ifdef DEBUG
- fprintf (aod->df,
- "read_page_granuleinfo: ^^^ has keygranule "
- "%lld (%lld|0) (%f seconds) (granuleshift %d)\n",
- aot->keygranule, iframe, offset, track->granuleshift);
-#endif
- }
+ if (aod->media_packets != NULL)
+ aop = (AnxOggPacket *)aod->media_packets->data;
}
- /* Update state */
- granuleinfo_update_state (aod);
+ /* Set current time to the current time of the next packet that would
+ * be served */
+ if (aop && aop->current_time != -1)
+ media->current_time = aop->current_time;
- return OGGZ_STOP_OK;
+ return bytes_to_read;
}
-static int
-anxogg_setup (AnxOggData * aod)
+static long
+anxogg_sizeof_next_read (AnxSource * media, long bound)
{
- long n;
- double start_time = 0.0, end_time = -1.0;
- off_t start_offset = 0, end_offset = -1;
- ogg_int64_t units, units_at;
+ AnxOggData * aod = (AnxOggData *)media->custom_data;
+ AnxOggPacket * aop;
+ long bytes_to_read;
- /* Slurp headers */
- oggz_set_read_callback (aod->oggz, -1, read_packet_headers, aod);
- while (aod->state == STATE_HEADERS &&
- (n = oggz_read (aod->oggz, 1024)) != 0);
+ if (aod->ignore_media) return -1;
-#ifdef DEBUG
- fprintf (aod->df,
- "anxogg: slurped headers:\n"
- "\toggz_read returned %ld\n"
- "\taod->got_non_bos == %d\n"
- "\taod->got_skeleton_eos == %d\n"
- "\taod->nr_headers_remaining = %d\n",
- n, aod->got_non_bos, aod->got_skeleton_eos,
- aod->nr_headers_remaining);
-#endif
+ while ((aod->media_packets == NULL) && (oggz_read (aod->oggz, 1024)) != 0);
- /* Find bitrate info */
- start_time = aod->anx_source->start_time;
- end_time = aod->anx_source->end_time;
-
- /* Check if the end_time is bigger than the end of the file */
- units_at = oggz_seek_units (aod->oggz, 0, SEEK_END);
- if (units_at == -1) {
-#ifdef DEBUG
- fprintf (aod->df, "anxogg_setup: oggz_seek_units end FAIL\n");
-#endif
- return -1;
- } else {
- int actual_end_time;
-
- actual_end_time = ((double)units_at) / 1000.0;
-
- if (end_time > actual_end_time) {
- end_time = -1.0;
- }
+ if (aod->media_packets == NULL) {
+ media->eos = 1;
+ return 0;
}
- if (end_time == -1.0) {
-#ifdef DEBUG
- fprintf(aod->df, "calling oggz_seek with whence of %d\n", SEEK_END);
-#endif
- end_offset = oggz_seek (aod->oggz, 0, SEEK_END);
-#ifdef DEBUG
- fprintf (aod->df, "anxogg_setup: end_offset is %d\n", end_offset);
-#endif
+ aop = (AnxOggPacket *)aod->media_packets->data;
+ bytes_to_read = aop->length - aod->current_offset;
- } else {
- units = (ogg_int64_t)(SUBSECONDS * end_time);
- units_at = oggz_seek_units (aod->oggz, units, SEEK_SET);
- if (units_at == -1) {
-#ifdef DEBUG
- fprintf (aod->df, "anxogg_setup: oggz_seek_units end FAIL\n");
-#endif
- return -1;
- }
- end_offset = oggz_tell (aod->oggz);
- }
+ return bytes_to_read;
+}
- units = (ogg_int64_t)(SUBSECONDS * start_time);
- units_at = oggz_seek_units (aod->oggz, units, SEEK_SET);
-#ifdef DEBUG
- fprintf(aod->df, "oggz_seek_units on %lld returned %lld\n", units, units_at);
-#endif
- if (units_at == -1) {
-#ifdef DEBUG
- fprintf (aod->df, "anxogg_setup: oggz_seek_units start FAIL\n");
-#endif
- return -1;
- }
- start_offset = oggz_tell (aod->oggz);
+/***********************************************************
+ * Open
+ */
- aod->anx_source->byte_length = end_offset - start_offset;
- if (end_time != -1) {
- aod->anx_source->duration = end_time - start_time;
- }
-
-#ifdef DEBUG
- fprintf (aod->df,
- "anxogg_setup: times (%f - %f) = %f\n", start_time, end_time,
- end_time - start_time);
- fprintf (aod->df, "anxogg_setup: got byte range [%ld - %ld] = %ld bytes\n",
- start_offset, end_offset, end_offset - start_offset);
-#endif
-
- /* Find granule_seek info */
- if (aod->use_granule_seek && start_time > 0.0) {
- oggz_set_read_callback (aod->oggz, -1, NULL, NULL);
- oggz_set_read_page (aod->oggz, -1, read_page_granuleinfo, aod);
- while (aod->state == STATE_GRANULEINFO &&
- (n = oggz_read (aod->oggz, 1024)) != 0);
- aod->state = STATE_FILTER;
- oggz_set_read_page (aod->oggz, -1, NULL, NULL);
- }
-
- /* Reset to beginning */
- oggz_seek (aod->oggz, 0, SEEK_SET);
- aod->nr_headers_remaining = aod->headers_unread;
-
- return 0;
-}
-
static AnxOggData *
aod_new (void)
{
@@ -1221,115 +1338,9 @@
return m;
}
-static long
-anxogg_read_update (AnxSource * media)
-{
- AnxOggData * aod = (AnxOggData *)media->custom_data;
-
- do_read:
-
- while ((aod->media_packets == NULL) && (oggz_read (aod->oggz, 1024)) != 0);
-
- if (aod->need_seek == NEED_SEEK && aod->nr_headers_remaining == 0) {
- anxogg_seek_update (media);
- goto do_read;
- }
-
- return 0;
-}
-
-static AnxOggPacket *
-anxogg_packet_free (AnxOggPacket * aop)
-{
- anx_free (aop->data);
- anx_free (aop);
- return NULL;
-}
-
-static long
-anxogg_read (AnxSource * media, char * buf, long n, long bound)
-{
- AnxOggData * aod = (AnxOggData *)media->custom_data;
- AnxOggPacket * aop;
- AnxList * head;
- long bytes_to_read;
-
- if (aod->ignore_media) return -1;
-
- anxogg_read_update (media);
-
- head = aod->media_packets;
- if (head == NULL) {
- media->eos = 1;
- return 0;
- }
-
- aop = (AnxOggPacket *)head->data;
- bytes_to_read = MIN (n, aop->length - aod->current_offset);
-
- memcpy (buf, &aop->data[aod->current_offset], bytes_to_read);
-
- aod->current_offset += bytes_to_read;
-
- if (aod->headers_unread > 0) aod->headers_unread--;
- if (aod->headers_unread == 0) media->written_secondaries = 1;
-
- media->current_track = aop->source_track;
-
-#ifdef DEBUG_VERBOSE
- fprintf (aod->df, "anxogg: reading from stream %s\n",
- media->current_track->content_type);
-#endif
-
- media->current_track->current_granule = aop->granulepos;
- media->current_track->eos = aop->eos;
-
- /* If that's finished this media packet, advance to the next one */
- if (aod->current_offset >= aop->length) {
- aod->media_packets =
- anx_list_remove (aod->media_packets, head);
-
- aop = anxogg_packet_free (aop);
- anx_free (head);
-
- aod->current_offset = 0;
-
- anxogg_read_update (media);
-
- if (aod->media_packets != NULL)
- aop = (AnxOggPacket *)aod->media_packets->data;
- }
-
- /* Set current time to the current time of the next packet that would
- * be served */
- if (aop && aop->current_time != -1)
- media->current_time = aop->current_time;
-
- return bytes_to_read;
-}
-
-static long
-anxogg_sizeof_next_read (AnxSource * media, long bound)
-{
- AnxOggData * aod = (AnxOggData *)media->custom_data;
- AnxOggPacket * aop;
- long bytes_to_read;
-
- if (aod->ignore_media) return -1;
-
- while ((aod->media_packets == NULL) && (oggz_read (aod->oggz, 1024)) != 0);
-
- if (aod->media_packets == NULL) {
- media->eos = 1;
- return 0;
- }
-
- aop = (AnxOggPacket *)aod->media_packets->data;
- bytes_to_read = aop->length - aod->current_offset;
-
- return bytes_to_read;
-}
-
+/***********************************************************
+ * Close
+ */
static int
anxogg_close (AnxSource * source)
{
@@ -1369,6 +1380,9 @@
return 0;
}
+/***********************************************************
+ * Importer instances
+ */
static struct _AnxImporter anx_ogg_importer = {
(AnxImporterOpenFunc)anxogg_open,
(AnxImporterOpenFDFunc)NULL,
More information about the commits
mailing list