[MPlayer-dev-eng] [PATCH] Latest CVS OGG Tremor and Theora Compile with MPlayer-CVS

Martin Drab drab at kepler.fjfi.cvut.cz
Fri Aug 15 16:40:34 CEST 2003


> Hi,
>
> here is a patch to let MPlayer (tested on MPlayer-20030814) compile with 
> latest CVS OGG Theora and Tremor. It just reacts on a slightly diffrent 
> API when using Tremor instead of Vorbis for decoding and reacts on 
> Theora API change. This patch has no influence on compiling MPlayer 
> without Tremor (i.e. it works with Vorbis too). 
>
> Martin Drab

Whoops! Forgot the attachment. ;-)

Martin Drab
-------------- next part --------------
diff -Naur old/libmpcodecs/ad_libvorbis.c new/libmpcodecs/ad_libvorbis.c
--- old/libmpcodecs/ad_libvorbis.c	2003-01-29 23:45:07.000000000 +0100
+++ new/libmpcodecs/ad_libvorbis.c	2003-07-30 14:41:35.000000000 +0200
@@ -83,21 +83,33 @@
   ov = (struct ov_struct_st*)malloc(sizeof(struct ov_struct_st));
   vorbis_info_init(&ov->vi);
   vorbis_comment_init(&vc);
+#ifdef TREMOR
+  op.bytes = ds_get_packet(sh->ds,&op.packet->buffer->data);
+#else
   op.bytes = ds_get_packet(sh->ds,&op.packet);
+#endif
   op.b_o_s  = 1;
   /// Header
   if(vorbis_synthesis_headerin(&ov->vi,&vc,&op) <0) {
     mp_msg(MSGT_DECAUDIO,MSGL_ERR,"OggVorbis: initial (identification) header broken!\n");
     ERROR();
   }
+#ifdef TREMOR
+  op.bytes = ds_get_packet(sh->ds,&op.packet->buffer->data);
+#else
   op.bytes = ds_get_packet(sh->ds,&op.packet);
+#endif
   op.b_o_s  = 0;
   /// Comments
   if(vorbis_synthesis_headerin(&ov->vi,&vc,&op) <0) {
     mp_msg(MSGT_DECAUDIO,MSGL_ERR,"OggVorbis: comment header broken!\n");
     ERROR();
   }
+#ifdef TREMOR
+  op.bytes = ds_get_packet(sh->ds,&op.packet->buffer->data);
+#else
   op.bytes = ds_get_packet(sh->ds,&op.packet);
+#endif
   //// Codebook
   if(vorbis_synthesis_headerin(&ov->vi,&vc,&op)<0) {
     mp_msg(MSGT_DECAUDIO,MSGL_WARN,"OggVorbis: codebook header broken!\n");
@@ -186,16 +198,28 @@
 {
         int len = 0;
         int samples;
+#ifdef TREMOR
+	ogg_int32_t **pcm;
+#else
         float **pcm;
+#endif
         float scale;
         struct ov_struct_st *ov = sh->context;
 	while(len < minlen) {
 	  while((samples=vorbis_synthesis_pcmout(&ov->vd,&pcm))<=0){
 	    ogg_packet op;
 	    memset(&op,0,sizeof(op)); //op.b_o_s = op.e_o_s = 0;
+#ifdef TREMOR
+	    op.bytes = ds_get_packet(sh->ds,&op.packet->buffer->data);
+#else
 	    op.bytes = ds_get_packet(sh->ds,&op.packet);
+#endif
 	    if(op.bytes<=0) break;
+#ifdef TREMOR
+	    if(vorbis_synthesis(&ov->vb,&op,0)==0) /* test for success! */
+#else
 	    if(vorbis_synthesis(&ov->vb,&op)==0) /* test for success! */
+#endif
 	      vorbis_synthesis_blockin(&ov->vd,&ov->vb);
 	  }
 	  if(samples<=0) break; // error/EOF
diff -Naur old/libmpcodecs/vd_theora.c new/libmpcodecs/vd_theora.c
--- old/libmpcodecs/vd_theora.c	2003-06-06 21:19:23.000000000 +0200
+++ new/libmpcodecs/vd_theora.c	2003-07-30 15:09:39.000000000 +0200
@@ -30,6 +30,7 @@
 
 typedef struct theora_struct_st {
     theora_state st;
+    theora_comment cc;
     theora_info inf;
 } theora_struct_t;
 
@@ -64,7 +65,9 @@
        /* read initial header */
        op.bytes = ds_get_packet (sh->ds,&op.packet);
        op.b_o_s  = 1;
-       if((errorCode = theora_decode_header (&context->inf, &op))) {
+       theora_comment_init(&context->cc);
+       theora_info_init(&context->inf);
+       if((errorCode = theora_decode_header (&context->inf, &context->cc, &op))) {
 	  mp_msg(MSGT_DECAUDIO,MSGL_ERR, 
 		 "Broken Theora header; erroroCode=%i!\n", errorCode);
 	  break;
@@ -84,11 +87,13 @@
        /* decode tables packet */
        op.bytes = ds_get_packet (sh->ds,&op.packet);
        op.b_o_s  = 1;
+#if 0
        if((errorCode = theora_decode_tables (&context->inf, &op))) {
 	  mp_msg(MSGT_DECVIDEO,MSGL_ERR, 
 		 "Broken Theora comment; erroroCode=%i!\n", errorCode);
 	  break;
        }
+#endif
 
        /* now init codec */
        errorCode = theora_decode_init (&context->st, &context->inf);
diff -Naur old/libmpdemux/demux_ogg.c new/libmpdemux/demux_ogg.c
--- old/libmpdemux/demux_ogg.c	2003-07-09 03:30:24.000000000 +0200
+++ new/libmpdemux/demux_ogg.c	2003-07-30 13:51:33.000000000 +0200
@@ -51,6 +51,7 @@
 typedef struct theora_struct_st {
     theora_state st;
     theora_info inf;
+    theora_comment cc;
 } theora_struct_t;
 #endif
 
@@ -211,7 +212,11 @@
   int lcv;
   int line_pos = 0;
   int ignoring = 0;
+#ifdef TREMOR
+  char *packet = pack->packet->buffer->data;
+#else
   char *packet = pack->packet;
+#endif
 
   mp_msg(MSGT_DEMUX,MSGL_DBG2,"\ndemux_ogg_add_sub %02X %02X %02X '%s'\n",
       (unsigned char)packet[0],
@@ -314,8 +319,13 @@
   *flags = 0;
 
   if(os->vorbis) {
+#ifdef TREMOR
+    data = pack->packet->buffer->data;
+    if(*pack->packet->buffer->data & PACKET_TYPE_HEADER)
+#else
     data = pack->packet;
     if(*pack->packet & PACKET_TYPE_HEADER)
+#endif
       os->hdr_packets++;
     else if (context )
     {
@@ -336,7 +346,11 @@
 # ifdef HAVE_OGGTHEORA
   } else if (os->theora) {
      /* we pass complete packets to theora, mustn't strip the header! */
+#ifdef TREMOR
+     data = pack->packet->buffer->data;
+#else
      data = pack->packet;
+#endif
      os->lastsize = 1;
      
      if (context != NULL)
@@ -360,6 +374,25 @@
 #endif /* HAVE_OGGTHEORA */
   } else {
     // Find data start
+#ifdef TREMOR
+    int16_t hdrlen = (*pack->packet->buffer->data & PACKET_LEN_BITS01)>>6;
+    hdrlen |= (*pack->packet->buffer->data & PACKET_LEN_BITS2) <<1;
+    data = pack->packet->buffer->data + 1 + hdrlen;
+    // Calculate the timestamp
+    if(pack->granulepos == -1)
+      pack->granulepos = os->lastpos + os->lastsize;
+    // If we alredy have a timestamp it can be a syncpoint
+    if(*pack->packet->buffer->data & PACKET_IS_SYNCPOINT)
+      *flags = 1;
+    *pts =  pack->granulepos/os->samplerate;
+    // Save the packet length and timestamp
+    os->lastsize = 0;
+    while(hdrlen) {
+      os->lastsize <<= 8;
+      os->lastsize |= pack->packet->buffer->data[hdrlen];
+      hdrlen--;
+    }
+#else
     int16_t hdrlen = (*pack->packet & PACKET_LEN_BITS01)>>6;
     hdrlen |= (*pack->packet & PACKET_LEN_BITS2) <<1;
     data = pack->packet + 1 + hdrlen;
@@ -377,6 +410,7 @@
       os->lastsize |= pack->packet[hdrlen];
       hdrlen--;
     }
+#endif
     os->lastpos = pack->granulepos;
   }
   return data;
@@ -398,7 +432,11 @@
   }
   // If packet is an header we jump it except for vorbis and theora
   // (PACKET_TYPE_HEADER bit doesn't even exist for theora ?!)
+#ifdef TREMOR
+  if((*pack->packet->buffer->data & PACKET_TYPE_HEADER) && 
+#else
   if((*pack->packet & PACKET_TYPE_HEADER) && 
+#endif
      (ds != d->audio || ( ((sh_audio_t*)ds->sh)->format != 0xFFFE || os->hdr_packets >= NUM_VORBIS_HDR_PACKETS ) ) &&
      (ds != d->video || (((sh_video_t*)ds->sh)->format != 0xFFFC)))
     return 0;
@@ -419,8 +457,13 @@
     clear_sub = -1;
   }
   /// Send the packet
+#ifdef TREMOR
+  dp = new_demux_packet(pack->bytes-(data-pack->packet->buffer->data));
+  memcpy(dp->buffer,data,pack->bytes-(data-pack->packet->buffer->data));
+#else
   dp = new_demux_packet(pack->bytes-(data-pack->packet));
   memcpy(dp->buffer,data,pack->bytes-(data-pack->packet));
+#endif
   dp->pts = pts;
   dp->flags = flags;
   ds_add_packet(ds,dp);
@@ -471,7 +514,11 @@
       continue;
     }
     if(np <= 0) { // We need more data
+#ifdef TREMOR
+      unsigned char* buf = ogg_sync_bufferin(sync,BLOCK_SIZE);
+#else
       char* buf = ogg_sync_buffer(sync,BLOCK_SIZE);
+#endif
       int len = stream_read(s,buf,BLOCK_SIZE);
       if(len == 0 && s->eof)
 	break;
@@ -524,7 +571,11 @@
   while(1) {
     np = ogg_sync_pageout(sync,page);
     if(np <= 0) { // We need more data
+#ifdef TREMOR
+      unsigned char* buf = ogg_sync_bufferin(sync,BLOCK_SIZE);
+#else
       char* buf = ogg_sync_buffer(sync,BLOCK_SIZE);
+#endif
       int len = stream_read(s,buf,BLOCK_SIZE);
       if(len == 0 && s->eof) {
 	mp_msg(MSGT_DEMUX,MSGL_ERR,"EOF while trying to get the first page !!!!\n");
@@ -582,7 +633,11 @@
     /// Need some more data
     if(np == 0) {
       int len;
+#ifdef TREMOR
+      unsigned char* buf = ogg_sync_bufferin(sync,BLOCK_SIZE);
+#else
       buf = ogg_sync_buffer(sync,BLOCK_SIZE);
+#endif
       len = stream_read(s,buf,BLOCK_SIZE);      
       if(len == 0 && s->eof) {
 	free(ogg_d);
@@ -621,7 +676,11 @@
     sh_v = NULL;
 
     // Check for Vorbis
+#ifdef TREMOR
+    if(pack.bytes >= 7 && ! strncmp(&pack.packet->buffer->data[1],"vorbis", 6) ) {
+#else
     if(pack.bytes >= 7 && ! strncmp(&pack.packet[1],"vorbis", 6) ) {
+#endif
       sh_a = new_sh_audio(demuxer,ogg_d->num_sub);
       sh_a->format = 0xFFFE;
       ogg_d->subs[ogg_d->num_sub].vorbis = 1;
@@ -630,10 +689,15 @@
 
       // check for Theora
 #   ifdef HAVE_OGGTHEORA
+#ifdef TREMOR
+    } else if (pack.bytes >= 7 && !strncmp (&pack.packet->buffer->data[1], "theora", 6)) {
+#else
     } else if (pack.bytes >= 7 && !strncmp (&pack.packet[1], "theora", 6)) {
+#endif
 	int errorCode = 0;
 	theora_info inf;
-	errorCode = theora_decode_header (&inf, &pack);
+	theora_comment cc;
+	errorCode = theora_decode_header (&inf, &cc, &pack);
 	if (errorCode)
 	    mp_msg(MSGT_DEMUX,MSGL_ERR,"Theora header parsing failed: %i \n",
 		   errorCode);
@@ -671,6 +735,59 @@
 	}
 #   endif /* HAVE_OGGTHEORA */
       /// Check for old header
+#ifdef TREMOR
+    } else if(pack.bytes >= 142 && ! strncmp(&pack.packet->buffer->data[1],"Direct Show Samples embedded in Ogg",35) ) {
+
+       // Old video header
+      if(get_uint32 (pack.packet->buffer->data+96) == 0x05589f80 && pack.bytes >= 184) {
+	sh_v = new_sh_video(demuxer,ogg_d->num_sub);
+	sh_v->bih = (BITMAPINFOHEADER*)calloc(1,sizeof(BITMAPINFOHEADER));
+	sh_v->bih->biSize=sizeof(BITMAPINFOHEADER);
+	sh_v->bih->biCompression=
+	sh_v->format = mmioFOURCC(pack.packet->buffer->data[68],pack.packet->buffer->data[69],
+				pack.packet->buffer->data[70],pack.packet->buffer->data[71]);
+	sh_v->frametime = get_uint64(pack.packet->buffer->data+164)*0.0000001;
+	sh_v->fps = 1/sh_v->frametime;
+	sh_v->disp_w = sh_v->bih->biWidth = get_uint32(pack.packet->buffer->data+176);
+	sh_v->disp_h = sh_v->bih->biHeight = get_uint32(pack.packet->buffer->data+180);
+	sh_v->bih->biBitCount = get_uint16(pack.packet->buffer->data+182);
+	if(!sh_v->bih->biBitCount) sh_v->bih->biBitCount=24; // hack, FIXME
+	sh_v->bih->biPlanes=1;
+	sh_v->bih->biSizeImage=(sh_v->bih->biBitCount>>3)*sh_v->bih->biWidth*sh_v->bih->biHeight;
+
+	ogg_d->subs[ogg_d->num_sub].samplerate = sh_v->fps;
+	n_video++;
+	mp_msg(MSGT_DEMUX,MSGL_V,"OGG stream %d is video (old hdr)\n",ogg_d->num_sub);
+	if(verbose>0) print_video_header(sh_v->bih);
+	// Old audio header
+      } else if(get_uint32(pack.packet->buffer->data+96) == 0x05589F81) {
+	unsigned int extra_size;
+	sh_a = new_sh_audio(demuxer,ogg_d->num_sub);
+	extra_size = get_uint16(pack.packet->buffer->data+140);
+	sh_a->wf = (WAVEFORMATEX*)calloc(1,sizeof(WAVEFORMATEX)+extra_size);
+	sh_a->format = sh_a->wf->wFormatTag = get_uint16(pack.packet->buffer->data+124);
+	sh_a->channels = sh_a->wf->nChannels = get_uint16(pack.packet->buffer->data+126);
+	sh_a->samplerate = sh_a->wf->nSamplesPerSec = get_uint32(pack.packet->buffer->data+128);
+	sh_a->wf->nAvgBytesPerSec = get_uint32(pack.packet->buffer->data+132);
+	sh_a->wf->nBlockAlign = get_uint16(pack.packet->buffer->data+136);
+	sh_a->wf->wBitsPerSample = get_uint16(pack.packet->buffer->data+138);
+	sh_a->samplesize = (sh_a->wf->wBitsPerSample+7)/8;
+	sh_a->wf->cbSize = extra_size;
+	if(extra_size > 0)
+	  memcpy(sh_a->wf+sizeof(WAVEFORMATEX),pack.packet->buffer->data+142,extra_size);
+
+	ogg_d->subs[ogg_d->num_sub].samplerate = sh_a->samplerate; // * sh_a->channels;
+	n_audio++;
+	mp_msg(MSGT_DEMUX,MSGL_V,"OGG stream %d is audio (old hdr)\n",ogg_d->num_sub);
+	if(verbose>0) print_wave_header(sh_a->wf);
+      } else
+	mp_msg(MSGT_DEMUX,MSGL_WARN,"OGG stream %d contains an old header but the header type is unknown\n",ogg_d->num_sub);
+
+        // Check new header
+    } else if ( (*pack.packet->buffer->data & PACKET_TYPE_BITS ) == PACKET_TYPE_HEADER && 
+	      pack.bytes >= (int)sizeof(stream_header)+1) {
+      stream_header *st = (stream_header*)(pack.packet->buffer->data+1);
+#else
     } else if(pack.bytes >= 142 && ! strncmp(&pack.packet[1],"Direct Show Samples embedded in Ogg",35) ) {
 
        // Old video header
@@ -722,6 +839,7 @@
     } else if ( (*pack.packet & PACKET_TYPE_BITS ) == PACKET_TYPE_HEADER && 
 	      pack.bytes >= (int)sizeof(stream_header)+1) {
       stream_header *st = (stream_header*)(pack.packet+1);
+#endif
       /// New video header
       if(strncmp(st->streamtype,"video",5) == 0) {
 	sh_v = new_sh_video(demuxer,ogg_d->num_sub);
@@ -875,7 +993,11 @@
       if(np == 0) {
 	while(1) {
 	  int pa,len;
+#ifdef TREMOR
+          unsigned char* buf;
+#else
 	  char *buf;
+#endif
 	  ogg_d->pos += ogg_d->last_size;
 	  /// Get the next page from the physical stream
 	  while( (pa = ogg_sync_pageseek(sync,page)) <= 0) {
@@ -886,7 +1008,11 @@
 	      continue;
 	    }
 	    /// We need more data
+#ifdef TREMOR
+            buf = ogg_sync_bufferin(sync,BLOCK_SIZE);
+#else
 	    buf = ogg_sync_buffer(sync,BLOCK_SIZE);	    
+#endif
 	    len = stream_read(s,buf,BLOCK_SIZE);
 	    if(len == 0 && s->eof) {
 	      mp_msg(MSGT_DEMUX,MSGL_DBG2,"OGG : Stream EOF !!!!\n");
@@ -976,7 +1102,11 @@
     }
     // Add some data
     plen = ds_get_packet(demuxer->audio,&p);    
+#ifdef TREMOR
+    buf = ogg_sync_bufferin(&ogg_d->sync,plen);
+#else
     buf = ogg_sync_buffer(&ogg_d->sync,plen);
+#endif
     memcpy(buf,p,plen);
     ogg_sync_wrote(&ogg_d->sync,plen);
   }
@@ -1103,7 +1233,11 @@
     if(np < 0)
       ogg_d->pos -= np;
     if(np <= 0) { // We need more data
+#ifdef TREMOR
+      unsigned char* buf = ogg_sync_bufferin(sync,BLOCK_SIZE);
+#else
       char* buf = ogg_sync_buffer(sync,BLOCK_SIZE);
+#endif
       int len = stream_read(demuxer->stream,buf,BLOCK_SIZE);
        if(len == 0 && demuxer->stream->eof) {
 	mp_msg(MSGT_DEMUX,MSGL_ERR,"EOF while trying to seek !!!!\n");
@@ -1137,7 +1271,11 @@
        is *variable*, with its excact value encoded in the theora header.
        This code just hopes that it is greater than 9 and that keyframes
        distance will never overflow 512. */
+#ifdef TREMOR
+      if( (((*op.packet->buffer->data & PACKET_IS_SYNCPOINT) && !os->theora) || 
+#else
       if( (((*op.packet & PACKET_IS_SYNCPOINT) && !os->theora) || 
+#endif
 	   os->vorbis || (os->theora && (op.granulepos&0x1FF) == 0)) &&
 	  (!ogg_d->syncpoints || op.granulepos >= gp) ) {
         ogg_sub.lines = 0;


More information about the MPlayer-dev-eng mailing list