[xiph-cvs] cvs commit: theora/win32/experimental/splayer splayer.c

Mauricio Piacentini mauricio at xiph.org
Sun May 25 09:37:06 PDT 2003



mauricio    03/05/25 12:37:06

  Modified:    win32/experimental/encoderwin encoderwin.c
               win32/experimental/splayer splayer.c
  Log:
  incorporated new 3 header structure (comments and tables)

Revision  Changes    Path
1.2       +33 -4     theora/win32/experimental/encoderwin/encoderwin.c

Index: encoderwin.c
===================================================================
RCS file: /usr/local/cvsroot/theora/win32/experimental/encoderwin/encoderwin.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- encoderwin.c	23 May 2003 14:14:40 -0000	1.1
+++ encoderwin.c	25 May 2003 16:37:06 -0000	1.2
@@ -12,7 +12,7 @@
 
   function: example encoder application; makes an Ogg Theora/Vorbis 
             file from YUV4MPEG2 and WAV input
-  last mod: $Id: encoderwin.c,v 1.1 2003/05/23 14:14:40 mauricio Exp $
+  last mod: $Id: encoderwin.c,v 1.2 2003/05/25 16:37:06 mauricio Exp $
 
  ********************************************************************/
 
@@ -419,6 +419,7 @@
 
   theora_state     td;
   theora_info      ti;
+  theora_comment   tc;
   
   vorbis_info      vi; /* struct that stores all the static vorbis bitstream
                           settings */
@@ -571,6 +572,13 @@
   }
   fwrite(og.header,1,og.header_len,stdout);
   fwrite(og.body,1,og.body_len,stdout);
+  
+  /* create the remaining theora headers */
+  theora_comment_init(&tc);
+  theora_encode_comment(&tc,&op);
+  ogg_stream_packetin(&to,&op);
+  theora_encode_tables(&td,&op);
+  ogg_stream_packetin(&to,&op); 
 
   if(audio){
     ogg_packet header;
@@ -580,12 +588,33 @@
     vorbis_analysis_headerout(&vd,&vc,&header,&header_comm,&header_code);
     ogg_stream_packetin(&vo,&header); /* automatically placed in its own
                                          page */
+    if(ogg_stream_pageout(&vo,&og)!=1){
+      fprintf(stderr,"Internal Ogg library error.\n");
+      exit(1);
+    }
+    fwrite(og.header,1,og.header_len,stdout);
+    fwrite(og.body,1,og.body_len,stdout);
+    
+    /* remaining vorbis header packets */
     ogg_stream_packetin(&vo,&header_comm);
     ogg_stream_packetin(&vo,&header_code);
+    }
     
-    /* This ensures the actual
-     * audio data will start on a new page, as per spec
-     */
+    /* Flush the rest of our headers. This ensures
+     the actual data in each stream will start 
+     on a new page, as per spec. */
+  while(1){
+    int result = ogg_stream_flush(&to,&og);
+      if(result<0){
+        /* can't get here */
+        fprintf(stderr,"Internal Ogg library error.\n");
+        exit(1);
+      }
+    if(result==0)break;
+    fwrite(og.header,1,og.header_len,stdout);
+    fwrite(og.body,1,og.body_len,stdout);
+  }
+  if(audio){
     while(1){
       int result=ogg_stream_flush(&vo,&og);
       if(result<0){

<p><p>1.2       +67 -11    theora/win32/experimental/splayer/splayer.c

Index: splayer.c
===================================================================
RCS file: /usr/local/cvsroot/theora/win32/experimental/splayer/splayer.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- splayer.c	23 May 2003 14:10:17 -0000	1.1
+++ splayer.c	25 May 2003 16:37:06 -0000	1.2
@@ -46,6 +46,7 @@
 ogg_stream_state vo;
 ogg_stream_state to;
 theora_info      ti;
+theora_comment   tc;
 theora_state     td;
 vorbis_info      vi;
 vorbis_dsp_state vd;
@@ -248,6 +249,38 @@
   
 }
 
+/* dump the theora (or vorbis) comment header */
+static int dump_comments(theora_comment *tc){
+  int i, len;
+  char *value;
+  
+  printf("Encoded by %s\n",tc->vendor);
+  if(tc->comments){
+    printf("theora comment header:\n");
+    for(i=0;i<tc->comments;i++){
+      if(tc->user_comments[i]){
+        len=tc->comment_lengths[i];
+      	value=malloc(len+1);
+      	memcpy(value,tc->user_comments[i],len);
+      	value[len]='\0';
+      	printf("\t%s\n", value);
+      	free(value);
+      }
+    }
+  }
+  return(0);
+}
+
+/* helper: push a page into the appropriate steam */
+/* this can be done blindly; a stream won't accept a page
+                that doesn't belong to it */
+static int queue_page(ogg_page *page){
+  if(theora_p)ogg_stream_pagein(&to,&og);
+  if(vorbis_p)ogg_stream_pagein(&vo,&og);
+  return 0;
+}                                   
+
+
 void parseHeaders(){
         /*extracted from player_sample.c test file for theora alpha*/
         ogg_packet op;
@@ -262,10 +295,7 @@
       /* is this a mandated initial header? If not, stop parsing */
       if(!ogg_page_bos(&og)){
         /* don't leak the page; get it into the appropriate stream */
-	/* this can be done blindly; a stream won't accept a page
-             that doesn't bewlong to it */
-	if(theora_p)ogg_stream_pagein(&to,&og);
-	if(vorbis_p)ogg_stream_pagein(&vo,&og);
+	queue_page(&og);
         stateflag=1;
         break;
       }
@@ -291,30 +321,56 @@
     }
   }
   
-  /* we're expecting more vorbis header packets. */
-  while(vorbis_p && vorbis_p<3){
+  /* we're expecting more header packets. */
+  while((theora_p && theora_p<3) || (vorbis_p && vorbis_p<3)){
     int ret;
-    while((ret=ogg_stream_packetout(&vo,&op))){
+    
+    /* look for further theora headers */
+    while(theora_p && (theora_p<3) && (ret=ogg_stream_packetout(&to,&op))){
+      if(ret<0){
+      	printf("Error parsing Theora stream headers; corrupt stream?\n");
+      	exit(1);
+      }
+      if(theora_p==1){
+        if(theora_decode_comment(&tc,&op)){
+          printf("Error parsing Theora stream headers; corrupt stream?\n");
+          exit(1);
+        }else{
+          dump_comments(&tc);
+          theora_p++;
+          continue;
+        }
+      }
+      if(theora_p==2){
+        if(theora_decode_tables(&ti,&op)){
+          printf("Error parsing Theora stream headers; corrupt stream?\n");
+          exit(1);
+        }
+        theora_p++;
+        /* fall through */
+      }
+      if(theora_p==3)break;
+    }
+
+    /* look for more vorbis header packets */  
+    while(vorbis_p && (vorbis_p<3) && (ret=ogg_stream_packetout(&vo,&op))){
       if(ret<0){
         printf("Error parsing Vorbis stream headers; corrupt stream?\n");
         exit(1);
       }
-      
       if(vorbis_synthesis_headerin(&vi,&vc,&op)){
         printf("Error parsing Vorbis stream headers; corrupt stream?\n");
         exit(1);
       }
       vorbis_p++;
       if(vorbis_p==3)break;
-      
     }
     
     /* The header pages/packets will arrive before anything else we
        care about, or the stream is not obeying spec */
     
     if(ogg_sync_pageout(&oy,&og)>0){
-      ogg_stream_pagein(&vo,&og); /* the vorbis stream will accept
-                                     only its own */
+      queue_page(&og); /* demux into the appropriate stream */
     }else{
       int ret=buffer_data(&oy);
       if(ret==0){

<p><p>--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'cvs-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the commits mailing list