Hopefullly this is once again something trivial I'm missing. I'm still
trying to figure out how to pull a part a stream. I get two out the three theora
headers I can see in the file (http://v2v.cc/~j/theora_testsuite/320x240.ogg) if
I use the buffer in the page struct and nothing usable if I try to use the
packet structs. Hopefully this is once again something something trivial
I've missed in the documentation.
Neil
>>>
#include <stdio.h>
#include "ogg/ogg.h"
#define BUF_SIZE 4096
int magic_check( unsigned char test, oggpack_buffer* buffer) {
        return (long) test == oggpack_read(buffer, 8);
}
void send_to_my_decoder(unsigned char *body, long body_len) {
        oggpack_buffer buffer;
        long bits_read;
        oggpack_readinit(&buffer, body, body_len);
        bits_read = oggpack_read(&buffer, 8);
        if ( bits_read == 0x80 || bits_read == 0x81 || bits_read == 0x82 ) {
                if ( magic_check( 't', &buffer) &&
                     magic_check( 'h', &buffer) &&
                     magic_check( 'e', &buffer) &&
                     magic_check( 'o', &buffer) &&
                     magic_check( 'r', &buffer) &&
                     magic_check( 'a', &buffer) ) {
                        printf("Magic!\n");
                }
                else {
                        printf("no Magic!\n");
                }
        }
        else {
                printf("not a header\n");
        }
}
int main( int argc, char** argv) {
        ogg_sync_state the_ogg_sync_state;
        ogg_stream_state the_ogg_stream_state;
        ogg_page the_ogg_page;
        ogg_packet the_ogg_packet;
        char* buffer;
        size_t bytes_actually_read;
        FILE* source;
        if (argc < 2) {
                printf("No file\n");
                return 0;
        }
        source = fopen(argv[1], "r");
        if (feof(source) != 0) {
                printf("Empty file\n");
                fclose(source);
                return 0;
        }
        ogg_sync_init(&the_ogg_sync_state);
        ogg_stream_init(&the_ogg_stream_state, 0);
        do {
                if (ogg_sync_pageout(&the_ogg_sync_state, &the_ogg_page)
== 1) {
                        printf("Decode Page\n");
                        send_to_my_decoder( the_ogg_page.body,
the_ogg_page.body_len );
                        ogg_stream_pagein(&the_ogg_stream_state,
&the_ogg_page);
                        ogg_stream_packetout(&the_ogg_stream_state,
&the_ogg_packet);
                        printf("Decode Packet\n");
                        send_to_my_decoder( the_ogg_packet.packet,
the_ogg_packet.bytes );
                }
                buffer = ogg_sync_buffer(&the_ogg_sync_state, BUF_SIZE);
                bytes_actually_read = fread(buffer, 1, BUF_SIZE, source);
                ogg_sync_wrote(&the_ogg_sync_state, bytes_actually_read);
        } while (feof(source) == 0 );
        ogg_stream_clear( &the_ogg_stream_state );
        ogg_sync_clear( &the_ogg_sync_state );
        fclose(source);
        return 1;
}>>>
$ ./a.out 320x240.ogg | head -20
Decode Page
Magic!
Decode Packet
not a header
Decode Page
Magic!
Decode Packet
not a header
Decode Page
not a header
Decode Packet
not a header
Decode Page
not a header
Decode Packet
not a header
Decode Page
not a header
Decode Packet
not a header