Commit b2d47599 authored by conrad's avatar conrad

rolled back status stuff, merged check for all metrics back in


git-svn-id: http://svn.annodex.net/liboggz/trunk@391 8158c8cd-e7e1-0310-9fa4-c5954c97daef
parent c6bca30f
...@@ -100,8 +100,6 @@ oggz_new (int flags) ...@@ -100,8 +100,6 @@ oggz_new (int flags)
oggz_read_init (oggz); oggz_read_init (oggz);
} }
oggz->status = OGGZ_STATUS_INITIALIZED;
return oggz; return oggz;
} }
......
...@@ -166,8 +166,6 @@ struct _OggzIO { ...@@ -166,8 +166,6 @@ struct _OggzIO {
struct _OGGZ { struct _OGGZ {
int flags; int flags;
enum OggzStatus status;
FILE * file; FILE * file;
OggzIO * io; OggzIO * io;
......
...@@ -203,6 +203,7 @@ static int ...@@ -203,6 +203,7 @@ static int
oggz_read_sync (OGGZ * oggz) oggz_read_sync (OGGZ * oggz)
{ {
OggzReader * reader = &oggz->x.reader; OggzReader * reader = &oggz->x.reader;
long nread = 0;
oggz_stream_t * stream; oggz_stream_t * stream;
ogg_stream_state * os; ogg_stream_state * os;
...@@ -214,128 +215,113 @@ oggz_read_sync (OGGZ * oggz) ...@@ -214,128 +215,113 @@ oggz_read_sync (OGGZ * oggz)
int cb_ret = 0; int cb_ret = 0;
oggz->status = OGGZ_STATUS_READ_ACTIVE;
/*os = &reader->ogg_stream;*/ /*os = &reader->ogg_stream;*/
op = &packet; op = &packet;
/* handle one packet. Try to fetch it from current stream state */ /* handle one packet. Try to fetch it from current stream state */
/* extract packets from page */ /* extract packets from page */
while(cb_ret == OGGZ_CONTINUE) { while(cb_ret == 0){
if (reader->current_serialno != -1) { if (reader->current_serialno != -1) {
/* process a packet if we can. If the machine isn't loaded, /* process a packet if we can. If the machine isn't loaded,
neither is a page */ neither is a page */
while(cb_ret == OGGZ_CONTINUE) { while(cb_ret == 0) {
ogg_int64_t granulepos; ogg_int64_t granulepos;
int result; int result;
serialno = reader->current_serialno; serialno = reader->current_serialno;
stream = oggz_get_stream (oggz, serialno); stream = oggz_get_stream (oggz, serialno);
if (stream == NULL) { if (stream == NULL) {
/* new stream ... check bos etc. */ /* new stream ... check bos etc. */
if ((stream = oggz_add_stream (oggz, serialno)) == NULL) { if ((stream = oggz_add_stream (oggz, serialno)) == NULL) {
/* error -- could not add stream */ /* error -- could not add stream */
oggz->status = OGGZ_STATUS_INTERNAL_ERROR; return -7;
return -7;
}
} }
os = &stream->ogg_stream; }
os = &stream->ogg_stream;
result = ogg_stream_packetout(os, op); result = ogg_stream_packetout(os, op);
if(result == -1) { if(result == -1) {
/* hole in the data. */ /* hole in the data. */
oggz->status = OGGZ_STATUS_INTERNAL_ERROR; return -7;
return -7; }
}
if(result > 0){ if(result > 0){
/* got a packet. process it */ /* got a packet. process it */
granulepos = op->granulepos; granulepos = op->granulepos;
if (!stream->metric && (oggz->flags & OGGZ_AUTO)) { if (!stream->metric && (oggz->flags & OGGZ_AUTO)) {
oggz_auto (oggz, op, serialno, NULL); oggz_auto (oggz, op, serialno, NULL);
} }
if ((oggz->metric || stream->metric) && granulepos != -1) { if ((oggz->metric || stream->metric) && granulepos != -1) {
reader->current_unit = oggz_get_unit (oggz, serialno, granulepos); reader->current_unit = oggz_get_unit (oggz, serialno, granulepos);
} }
#ifndef DEBUG_BY_READING_PAGES #ifndef DEBUG_BY_READING_PAGES
if (stream->read_packet) { if (stream->read_packet) {
cb_ret = cb_ret =
stream->read_packet (oggz, op, serialno, stream->read_user_data); stream->read_packet (oggz, op, serialno, stream->read_user_data);
} else if (reader->read_packet) { } else if (reader->read_packet) {
cb_ret = cb_ret =
reader->read_packet (oggz, op, serialno, reader->read_user_data); reader->read_packet (oggz, op, serialno, reader->read_user_data);
}
#endif /* DEBUG_BY_READING_PAGES */
} }
else #endif /* DEBUG_BY_READING_PAGES */
break;
} }
else
break;
}
} }
if (cb_ret == OGGZ_CONTINUE) { /* If we've got a stop already, don't read more data in */
if(oggz_get_next_page_7 (oggz, &og) < 0) { if (cb_ret != 0) return cb_ret;
if (reader->current_unit != 0)
oggz->status = OGGZ_STATUS_READ_EOF;
return -404; /* eof. leave unitialized */
}
serialno = ogg_page_serialno (&og); if(oggz_get_next_page_7 (oggz, &og) < 0)
reader->current_serialno = serialno; /* XXX: maybe not necessary */ return -404; /* eof. leave unitialized */
stream = oggz_get_stream (oggz, serialno); serialno = ogg_page_serialno (&og);
reader->current_serialno = serialno; /* XXX: maybe not necessary */
stream = oggz_get_stream (oggz, serialno);
if (stream == NULL) { if (stream == NULL) {
/* new stream ... check bos etc. */ /* new stream ... check bos etc. */
if ((stream = oggz_add_stream (oggz, serialno)) == NULL) { if ((stream = oggz_add_stream (oggz, serialno)) == NULL) {
/* error -- could not add stream */ /* error -- could not add stream */
oggz->status = OGGZ_STATUS_INTERNAL_ERROR; return -7;
return -7;
}
} }
os = &stream->ogg_stream; }
os = &stream->ogg_stream;
#ifdef DEBUG_BY_READING_PAGES #ifdef DEBUG_BY_READING_PAGES
{ {
ogg_packet op_debug; ogg_packet op_debug;
op_debug.packet = og.body; op_debug.packet = og.body;
op_debug.bytes = og.body_len; op_debug.bytes = og.body_len;
op_debug.b_o_s = ogg_page_bos (&og); op_debug.b_o_s = ogg_page_bos (&og);
op_debug.e_o_s = ogg_page_eos (&og); op_debug.e_o_s = ogg_page_eos (&og);
op_debug.granulepos = ogg_page_granulepos (&og); op_debug.granulepos = ogg_page_granulepos (&og);
op_debug.packetno = ogg_page_packets (&og); op_debug.packetno = ogg_page_packets (&og);
if (stream->read_packet) { if (stream->read_packet) {
cb_ret = stream->read_packet (oggz, &op_debug, serialno, cb_ret = stream->read_packet (oggz, &op_debug, serialno,
stream->read_user_data); stream->read_user_data);
} else if (reader->read_packet) { } else if (reader->read_packet) {
cb_ret = reader->read_packet (oggz, &op_debug, serialno, cb_ret = reader->read_packet (oggz, &op_debug, serialno,
reader->read_user_data); reader->read_user_data);
}
} }
}
#endif #endif
#if 0 #if 0
/* bitrate tracking; add the header's bytes here, the body bytes /* bitrate tracking; add the header's bytes here, the body bytes
are done by packet above */ are done by packet above */
vf->bittrack+=og.header_len*8; vf->bittrack+=og.header_len*8;
#endif #endif
ogg_stream_pagein(os, &og); ogg_stream_pagein(os, &og);
}
if (cb_ret == OGGZ_CONTINUE) {
oggz->status = OGGZ_STATUS_READ_ACTIVE;
} else if (cb_ret == OGGZ_STOP_ERR) {
oggz->status = OGGZ_STATUS_READ_STOP_ERR;
} else {
oggz->status = OGGZ_STATUS_READ_STOP_OK;
}
} }
return cb_ret; return cb_ret;
...@@ -359,15 +345,17 @@ oggz_read (OGGZ * oggz, long n) ...@@ -359,15 +345,17 @@ oggz_read (OGGZ * oggz, long n)
cb_ret = oggz_read_sync (oggz); cb_ret = oggz_read_sync (oggz);
while (oggz->status == OGGZ_STATUS_READ_ACTIVE && /* If there's nothing to read yet, don't flag an error */
bytes_read > 0 && remaining > 0) { if (reader->current_unit == 0 && cb_ret == -404) cb_ret = 0;
while (cb_ret != -1 && cb_ret != 1 && bytes_read > 0 && remaining > 0) {
bytes = MIN (remaining, 4096); bytes = MIN (remaining, 4096);
buffer = ogg_sync_buffer (&reader->ogg_sync, bytes); buffer = ogg_sync_buffer (&reader->ogg_sync, bytes);
if ((bytes_read = (long) oggz_io_read (oggz, buffer, bytes)) == 0) { if ((bytes_read = (long) oggz_io_read (oggz, buffer, bytes)) == 0) {
/* schyeah! */
} if (ferror (oggz->file)) {
if (bytes_read == OGGZ_ERR_SYSTEM) { return OGGZ_ERR_SYSTEM;
return OGGZ_ERR_SYSTEM; }
} }
ogg_sync_wrote (&reader->ogg_sync, bytes_read); ogg_sync_wrote (&reader->ogg_sync, bytes_read);
...@@ -378,8 +366,7 @@ oggz_read (OGGZ * oggz, long n) ...@@ -378,8 +366,7 @@ oggz_read (OGGZ * oggz, long n)
cb_ret = oggz_read_sync (oggz); cb_ret = oggz_read_sync (oggz);
} }
if (oggz->status == OGGZ_STATUS_READ_STOP_ERR) if (cb_ret == -1) oggz_purge (oggz);
oggz_purge (oggz);
return nread; return nread;
} }
...@@ -391,6 +378,7 @@ oggz_read_input (OGGZ * oggz, unsigned char * buf, long n) ...@@ -391,6 +378,7 @@ oggz_read_input (OGGZ * oggz, unsigned char * buf, long n)
OggzReader * reader; OggzReader * reader;
char * buffer; char * buffer;
long bytes, remaining = n, nread = 0; long bytes, remaining = n, nread = 0;
int cb_ret = 0;
if (oggz == NULL) return OGGZ_ERR_BAD_OGGZ; if (oggz == NULL) return OGGZ_ERR_BAD_OGGZ;
...@@ -400,10 +388,12 @@ oggz_read_input (OGGZ * oggz, unsigned char * buf, long n) ...@@ -400,10 +388,12 @@ oggz_read_input (OGGZ * oggz, unsigned char * buf, long n)
reader = &oggz->x.reader; reader = &oggz->x.reader;
oggz_read_sync (oggz); cb_ret = oggz_read_sync (oggz);
/* If there's nothing to read yet, don't flag an error */
if (reader->current_unit == 0 && cb_ret == -404) cb_ret = 0;
while (oggz->status == OGGZ_STATUS_READ_ACTIVE && /* !oggz->eos && */ while (cb_ret != -1 && cb_ret != 1 && /* !oggz->eos && */ remaining > 0) {
remaining > 0) {
bytes = MIN (remaining, 4096); bytes = MIN (remaining, 4096);
buffer = ogg_sync_buffer (&reader->ogg_sync, bytes); buffer = ogg_sync_buffer (&reader->ogg_sync, bytes);
memcpy (buffer, buf, bytes); memcpy (buffer, buf, bytes);
...@@ -413,11 +403,10 @@ oggz_read_input (OGGZ * oggz, unsigned char * buf, long n) ...@@ -413,11 +403,10 @@ oggz_read_input (OGGZ * oggz, unsigned char * buf, long n)
remaining -= bytes; remaining -= bytes;
nread += bytes; nread += bytes;
oggz_read_sync (oggz); cb_ret = oggz_read_sync (oggz);
} }
if (oggz->status == OGGZ_STATUS_READ_STOP_ERR) if (cb_ret == -1) oggz_purge (oggz);
oggz_purge (oggz);
return nread; return nread;
} }
...@@ -522,6 +511,8 @@ oggz_reset (OGGZ * oggz, oggz_off_t offset, ogg_int64_t unit, int whence) ...@@ -522,6 +511,8 @@ oggz_reset (OGGZ * oggz, oggz_off_t offset, ogg_int64_t unit, int whence)
int int
oggz_purge (OGGZ * oggz) oggz_purge (OGGZ * oggz)
{ {
long reset_ret;
if (oggz == NULL) return OGGZ_ERR_BAD_OGGZ; if (oggz == NULL) return OGGZ_ERR_BAD_OGGZ;
if (oggz->flags & OGGZ_WRITE) { if (oggz->flags & OGGZ_WRITE) {
......
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