Commit aeda948e authored by conrad's avatar conrad

ensure ogg_stream flushing during oggz_flush() and oggz_close() when writing


git-svn-id: http://svn.annodex.net/liboggz/trunk@540 8158c8cd-e7e1-0310-9fa4-c5954c97daef
parent 36ccab44
......@@ -148,6 +148,10 @@ oggz_flush (OGGZ * oggz)
{
if (oggz == NULL) return OGGZ_ERR_BAD_OGGZ;
if (OGGZ_CONFIG_WRITE && (oggz->flags & OGGZ_WRITE)) {
oggz_write_flush (oggz);
}
return oggz_io_flush (oggz);
}
......@@ -172,15 +176,15 @@ oggz_close (OGGZ * oggz)
{
if (oggz == NULL) return OGGZ_ERR_BAD_OGGZ;
oggz_vector_foreach (oggz->streams, oggz_stream_clear);
oggz_vector_delete (oggz->streams);
if (OGGZ_CONFIG_WRITE && (oggz->flags & OGGZ_WRITE)) {
oggz_write_close (oggz);
} else if (OGGZ_CONFIG_READ) {
oggz_read_close (oggz);
}
oggz_vector_foreach (oggz->streams, oggz_stream_clear);
oggz_vector_delete (oggz->streams);
if (oggz->file != NULL) {
if (fclose (oggz->file) == EOF) {
return OGGZ_ERR_SYSTEM;
......@@ -188,6 +192,7 @@ oggz_close (OGGZ * oggz)
}
if (oggz->io != NULL) {
oggz_io_flush (oggz);
oggz_free (oggz->io);
}
......
......@@ -196,6 +196,7 @@ OGGZ * oggz_read_init (OGGZ * oggz);
OGGZ * oggz_read_close (OGGZ * oggz);
OGGZ * oggz_write_init (OGGZ * oggz);
int oggz_write_flush (OGGZ * oggz);
OGGZ * oggz_write_close (OGGZ * oggz);
oggz_stream_t * oggz_get_stream (OGGZ * oggz, long serialno);
......
......@@ -56,7 +56,8 @@
/* #define DEBUG */
/* #define ALWAYS_FLUSH */
/* Define to 0 or 1 */
#define ALWAYS_FLUSH 0
/* #define ZPACKET_CMP */
......@@ -136,11 +137,30 @@ oggz_writer_packet_free (oggz_writer_packet_t * zpacket)
return 0;
}
int
oggz_write_flush (OGGZ * oggz)
{
OggzWriter * writer = &oggz->x.writer;
ogg_stream_state * os;
ogg_page * og;
int ret = 0;
os = writer->current_stream;
og = &oggz->current_page;
if (os != NULL)
ret = ogg_stream_flush (os, og);
return ret;
}
OGGZ *
oggz_write_close (OGGZ * oggz)
{
OggzWriter * writer = &oggz->x.writer;
oggz_write_flush (oggz);
oggz_vector_foreach (writer->packet_queue,
(OggzFunc)oggz_writer_packet_free);
oggz_vector_delete (writer->packet_queue);
......@@ -183,6 +203,10 @@ oggz_write_feed (OGGZ * oggz, ogg_packet * op, long serialno, int flush,
int b_o_s, e_o_s, bos_auto;
int strict;
#ifdef DEBUG
printf ("oggz_write_feed: IN\n");
#endif
if (oggz == NULL) return OGGZ_ERR_BAD_OGGZ;
if (!(oggz->flags & OGGZ_WRITE)) {
......@@ -288,6 +312,11 @@ oggz_write_feed (OGGZ * oggz, ogg_packet * op, long serialno, int flush,
return -1;
}
#ifdef DEBUG
printf ("oggz_write_feed: enqueued packet, queue size %d\n",
oggz_vector_size (writer->packet_queue));
#endif
return 0;
}
......@@ -328,21 +357,17 @@ oggz_page_init (OGGZ * oggz)
os = writer->current_stream;
og = &oggz->current_page;
#ifdef ALWAYS_FLUSH
ret = ogg_stream_flush (os, og);
#else
if (writer->flushing) {
if (ALWAYS_FLUSH || writer->flushing) {
#ifdef DEBUG
printf ("*** ATTEMPT FLUSH: ");
printf ("oggz_page_init: ATTEMPT FLUSH: ");
#endif
ret = ogg_stream_flush (os, og);
ret = oggz_write_flush (oggz);
} else {
#ifdef DEBUG
printf ("*** ATTEMPT pageout: ");
printf ("oggz_page_init: ATTEMPT pageout: ");
#endif
ret = ogg_stream_pageout (os, og);
}
#endif
if (ret) {
writer->page_offset = 0;
......@@ -528,7 +553,7 @@ oggz_writer_make_packet (OGGZ * oggz)
int cb_ret = 0, ret = 0;
#ifdef DEBUG
printf ("make packet ...\n");
printf ("oggz_writer_make_packet: IN\n");
#endif
/* finished with current packet; unguard */
......@@ -547,6 +572,9 @@ oggz_writer_make_packet (OGGZ * oggz)
if (cb_ret == 0) {
/* dequeue and init the next packet */
if ((next_zpacket = oggz_dequeue_packet (oggz)) == NULL) {
#ifdef DEBUG
printf ("oggz_writer_make_packet: packet queue empty\n");
#endif
/*writer->eos = 1;*/
ret = 0;
} else {
......@@ -722,6 +750,12 @@ oggz_write_init (OGGZ * oggz)
return NULL;
}
int
oggz_write_flush (OGGZ * oggz)
{
return OGGZ_ERR_DISABLED;
}
OGGZ *
oggz_write_close (OGGZ * oggz)
{
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment