From e4db7cbebdecb8b083a1f0cbb0f1f55274ceb3cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Mangano?= Date: Tue, 1 Jan 2013 13:17:32 +0100 Subject: [PATCH] read packets --- opustags.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/opustags.c b/opustags.c index 23cad4c..2d6b75b 100644 --- a/opustags.c +++ b/opustags.c @@ -11,11 +11,14 @@ int main(int argc, char **argv){ return EXIT_FAILURE; } ogg_sync_state oy; + ogg_stream_state os; ogg_page og; + ogg_packet op; ogg_sync_init(&oy); char *buf; size_t len; char *error = NULL; + int packet_count = -1; while(error == NULL && !feof(in)){ // Read until we complete a page. if(ogg_sync_pageout(&oy, &og) != 1){ @@ -34,7 +37,26 @@ int main(int argc, char **argv){ } // We got a page. puts("got a page"); + if(packet_count == -1){ // First page + if(ogg_stream_init(&os, ogg_page_serialno(&og)) == -1){ + error = "ogg_stream_init: unsuccessful"; + break; + } + packet_count = 0; + } + if(ogg_stream_pagein(&os, &og) == -1){ + error = "ogg_stream_pagein: invalid page"; + break; + } + if(ogg_stream_packetout(&os, &op) == 1){ + packet_count++; + puts("got a packet"); + } + if(ogg_stream_check(&os) != 0) + error = "ogg_stream_check: internal error"; } + if(packet_count >= 0) + ogg_stream_clear(&os); ogg_sync_clear(&oy); fclose(in); if(error){