static void
_v_writestring (oggpack_buffer *o, char *s, int len)
{
- while (len--) {
+ while (len--)
oggpack_write (o, *s++, 8);
- }
}
static int
int result, bytes;
result = ogg_stream_packetout (&s->os, p);
-
- if (result > 0)
+ if (result == 1)
return 1;
if (s->eosin)
return 0;
- while (ogg_sync_pageout (&s->oy, page) <= 0) {
+ while (ogg_sync_pageout (&s->oy, page) != 1) {
buffer = ogg_sync_buffer (&s->oy, CHUNKSIZE);
bytes = fread (buffer, 1, CHUNKSIZE, s->in);
ogg_sync_wrote (&s->oy, bytes);
vcedit_open (vcedit_state *state)
{
vcedit_error ret;
- char *buffer;
- size_t bytes, total = 0;
- int i;
ogg_packet *header;
ogg_packet header_main, header_comments, header_codebooks;
ogg_page og;
+ char *buffer;
+ size_t bytes, total = 0;
+ int i = 0;
state->in = fopen (state->filename, "rb");
if (!state->in)
state->mainbuf = malloc (state->mainlen);
memcpy (state->mainbuf, header_main.packet, header_main.bytes);
- i = 0;
header = &header_comments;
while (i < 2) {
while (i < 2) {
- int result = ogg_sync_pageout (&state->oy, &og);
+ int result;
+ result = ogg_sync_pageout (&state->oy, &og);
if (!result)
break; /* Too little data so far */
- if (result == 1) {
- ogg_stream_pagein (&state->os, &og);
-
- while (i < 2) {
- result = ogg_stream_packetout (&state->os, header);
+ if (result != 1)
+ continue;
- if (!result)
- break;
+ ogg_stream_pagein (&state->os, &og);
- if (result == -1) {
- ret = VCEDIT_ERR_INVAL;
- goto err;
- }
+ while (i < 2) {
+ result = ogg_stream_packetout (&state->os, header);
+ if (!result)
+ break;
- vorbis_synthesis_headerin (&state->vi, &state->vc, header);
+ if (result != 1) {
+ ret = VCEDIT_ERR_INVAL;
+ goto err;
+ }
- if (i == 1) {
- state->booklen = header->bytes;
- state->bookbuf = malloc (state->booklen);
- memcpy (state->bookbuf, header->packet, header->bytes);
- }
+ vorbis_synthesis_headerin (&state->vi, &state->vc, header);
- i++;
- header = &header_codebooks;
+ if (i++ == 1) {
+ state->booklen = header->bytes;
+ state->bookbuf = malloc (state->booklen);
+ memcpy (state->bookbuf, header->packet, header->bytes);
}
+
+ header = &header_codebooks;
}
}
buffer = ogg_sync_buffer (&state->oy, CHUNKSIZE);
bytes = fread (buffer, 1, CHUNKSIZE, state->in);
- if (bytes == 0 && i < 2) {
+ if (!bytes && i < 2) {
ret = VCEDIT_ERR_INVAL;
goto err;
}
/* We copy the rest of the stream (other logical streams)
* through, a page at a time.
*/
- while (1) {
- result = ogg_sync_pageout (&state->oy, &ogout);
-
- if (!result)
- break;
+ while ((result = ogg_sync_pageout (&state->oy, &ogout))) {
+ if (result != 1)
+ continue;
- if (result >= 0) {
- /* Don't bother going through the rest, we can just
- * write the page out now
- */
- tmp = fwrite (ogout.header, 1, ogout.header_len, out);
- if (tmp != (size_t) ogout.header_len)
- goto cleanup;
+ /* Don't bother going through the rest, we can just
+ * write the page out now
+ */
+ tmp = fwrite (ogout.header, 1, ogout.header_len, out);
+ if (tmp != (size_t) ogout.header_len)
+ goto cleanup;
- tmp = fwrite (ogout.body, 1, ogout.body_len, out);
- if (tmp != (size_t) ogout.body_len)
- goto cleanup;
- }
+ tmp = fwrite (ogout.body, 1, ogout.body_len, out);
+ if (tmp != (size_t) ogout.body_len)
+ goto cleanup;
}
buffer = ogg_sync_buffer (&state->oy, CHUNKSIZE);
bytes = fread (buffer, 1, CHUNKSIZE, state->in);
ogg_sync_wrote (&state->oy, bytes);
- if (!bytes) {
+ if (!bytes)
state->eosin = 1;
- break;
- }
}
fclose (out);