Advertisement
Guest User

oggpagesizes.c

a guest
Mar 1st, 2020
318
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.48 KB | None | 0 0
  1. // compile with gcc -o oggpagesizes -logg oggpagesizes.c
  2.  
  3. #include <stdio.h>
  4. #include <ogg/ogg.h>
  5.  
  6. ogg_sync_state oss;
  7. ogg_stream_state os;
  8. int serialno = -1;
  9.  
  10. int main(int argc, char *argv[]){
  11.   if(argc < 2){
  12.     printf("no file\n");
  13.     return -1;
  14.   }
  15.   FILE *f = fopen(argv[1], "r");
  16.   if(!f){
  17.     printf("fopen fail\n");
  18.     return -1;
  19.   }
  20.   ogg_sync_init(&oss);
  21.   ogg_stream_init(&os, -1);
  22.   int maxbody = 0;
  23.   int maxpacket = 0;
  24.   while(!feof(f)){
  25.     char *buf = ogg_sync_buffer(&oss, 8192);
  26.     int read = fread(buf, 1, 8192, f);
  27.     ogg_sync_wrote(&oss, read);
  28.  
  29.     while(1){
  30.       ogg_page op;
  31.       int res = ogg_sync_pageout(&oss, &op);
  32.       if(res == 1){
  33.     printf("header %d body %d\n", op.header_len, op.body_len);
  34.     maxbody = op.body_len > maxbody ? op.body_len : maxbody;
  35.     if(serialno != ogg_page_serialno(&op)){
  36.       printf("now reading serialno %d\n", serialno);
  37.       serialno = ogg_page_serialno(&op);
  38.       ogg_stream_reset_serialno(&os, serialno);
  39.     }
  40.     int res = ogg_stream_pagein(&os, &op);
  41.     printf("ogg_stream_pagein %d\n", res);
  42.     while(1){
  43.       ogg_packet opkt;
  44.       int res = ogg_stream_packetout(&os, &opkt);
  45.       if(res == 1){
  46.         printf("    packet %d\n", opkt.bytes);
  47.         maxpacket = opkt.bytes > maxpacket ? opkt.bytes : maxpacket;
  48.       }else{
  49.         printf("ogg_stream_packetout %d\n", res);
  50.         break;
  51.       }
  52.     }
  53.       }else{
  54.     break;
  55.       }
  56.     }
  57.   }
  58.   printf("max body %d\n", maxbody);
  59.   printf("max packet %d\n", maxpacket);
  60.   return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement