[xiph-commits] r13843 - in trunk/theora/lib: . dec enc

tterribe at svn.xiph.org tterribe at svn.xiph.org
Sun Sep 16 15:05:48 PDT 2007


Author: tterribe
Date: 2007-09-16 15:05:48 -0700 (Sun, 16 Sep 2007)
New Revision: 13843

Modified:
   trunk/theora/lib/Makefile.am
   trunk/theora/lib/dec/apiwrapper.c
   trunk/theora/lib/enc/codec_internal.h
   trunk/theora/lib/internal.h
Log:
Port of r13842 from theora-exp.


Modified: trunk/theora/lib/Makefile.am
===================================================================
--- trunk/theora/lib/Makefile.am	2007-09-16 22:05:14 UTC (rev 13842)
+++ trunk/theora/lib/Makefile.am	2007-09-16 22:05:48 UTC (rev 13843)
@@ -71,6 +71,8 @@
 endif
 
 decoder_sources = \
+	dec/apiwrapper.c \
+	dec/decapiwrapper.c \
 	dec/decinfo.c \
 	dec/decode.c \
 	dec/dequant.c \
@@ -80,8 +82,7 @@
 	dec/info.c \
 	dec/internal.c \
 	dec/quant.c \
-	dec/state.c  \
-	dec/apiwrapper.c
+	dec/state.c
 
 if CPU_x86_64
 decoder_x86_sources = \

Modified: trunk/theora/lib/dec/apiwrapper.c
===================================================================
--- trunk/theora/lib/dec/apiwrapper.c	2007-09-16 22:05:14 UTC (rev 13842)
+++ trunk/theora/lib/dec/apiwrapper.c	2007-09-16 22:05:48 UTC (rev 13843)
@@ -18,27 +18,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <limits.h>
-#include <ogg/ogg.h>
-/*libtheora header.*/
-#include <theora/theora.h>
-/*theora-exp header.*/
-#include "theora/theoradec.h"
-/*For oc_ilog et al.*/
-#include "../internal.h"
+#include "apiwrapper.h"
 
-typedef struct th_api_wrapper th_api_wrapper;
 
-/*Generally only one of these pointers will be non-NULL in any given instance.
-  Technically we do not even really need this struct, since we should be able
-   to figure out which one from "context", but doing it this way makes sure we
-   don't flub it up.
-  It also means eventually adding encode support will work in the obvious
-   manner; theora_clear() does NOT provide enough context to distinguish
-   between an encoder and decoder without something like this.*/
-struct th_api_wrapper{
-  th_setup_info *setup;
-  th_dec_ctx    *decode;
-};
 
 const char *theora_version_string(void){
   return th_version_string();
@@ -49,33 +31,71 @@
 }
 
 void theora_info_init(theora_info *_ci){
-  th_api_wrapper *api;
-  api=(th_api_wrapper *)_ogg_calloc(1,sizeof(*api));
   memset(_ci,0,sizeof(*_ci));
-  _ci->codec_setup=api;
 }
 
 void theora_info_clear(theora_info *_ci){
   th_api_wrapper *api;
   api=(th_api_wrapper *)_ci->codec_setup;
-  if(api->setup)th_setup_free(api->setup);
-  if(api->decode)th_decode_free(api->decode);
-  free(api);
   memset(_ci,0,sizeof(*_ci));
+  if(api!=NULL){
+    if(api->clear!=NULL)(*api->clear)(api);
+    free(api);
+  }
 }
 
-void theora_clear(theora_state *_td){
-  if(_td->internal_encode!=NULL){
-    (*((oc_enc_dispatch_vtbl *)_td->internal_encode)->clear)(_td);
+void theora_clear(theora_state *_th){
+  /*Provide compatibility with mixed encoder and decoder shared lib versions.*/
+  if(_th->internal_decode!=NULL){
+    (*((oc_state_dispatch_vtbl *)_th->internal_decode)->clear)(_th);
   }
-  else if(_td->i!=NULL){
-    theora_info_clear(_td->i);
-    _ogg_free(_td->i);
-    _td->i=NULL;
+  if(_th->internal_encode!=NULL){
+    (*((oc_state_dispatch_vtbl *)_th->internal_encode)->clear)(_th);
   }
+  if(_th->i!=NULL)theora_info_clear(_th->i);
+  memset(_th,0,sizeof(*_th));
 }
 
-static void theora_info2th_info(th_info *_info,const theora_info *_ci){
+int theora_control(theora_state *_th,int _req,void *_buf,size_t _buf_sz){
+  /*Provide compatibility with mixed encoder and decoder shared lib versions.*/
+  if(_th->internal_decode!=NULL){
+    return (*((oc_state_dispatch_vtbl *)_th->internal_decode)->control)(_th,
+     _req,_buf,_buf_sz);
+  }
+  else if(_th->internal_encode!=NULL){
+    return (*((oc_state_dispatch_vtbl *)_th->internal_encode)->control)(_th,
+     _req,_buf,_buf_sz);
+  }
+  else return TH_EINVAL;
+}
+
+ogg_int64_t theora_granule_frame(theora_state *_th,ogg_int64_t _gp){
+  /*Provide compatibility with mixed encoder and decoder shared lib versions.*/
+  if(_th->internal_decode!=NULL){
+    return (*((oc_state_dispatch_vtbl *)_th->internal_decode)->granule_frame)(
+     _th,_gp);
+  }
+  else if(_th->internal_encode!=NULL){
+    return (*((oc_state_dispatch_vtbl *)_th->internal_encode)->granule_frame)(
+     _th,_gp);
+  }
+  else return -1;
+}
+
+double theora_granule_time(theora_state *_th, ogg_int64_t _gp){
+  /*Provide compatibility with mixed encoder and decoder shared lib versions.*/
+  if(_th->internal_decode!=NULL){
+    return (*((oc_state_dispatch_vtbl *)_th->internal_decode)->granule_time)(
+     _th,_gp);
+  }
+  else if(_th->internal_encode!=NULL){
+    return (*((oc_state_dispatch_vtbl *)_th->internal_encode)->granule_time)(
+     _th,_gp);
+  }
+  else return -1;
+}
+
+void oc_theora_info2th_info(th_info *_info,const theora_info *_ci){
   _info->version_major=_ci->version_major;
   _info->version_minor=_ci->version_minor;
   _info->version_subminor=_ci->version_subminor;
@@ -106,129 +126,6 @@
    OC_MINI(31,oc_ilog(_ci->keyframe_frequency_force-1)):0;
 }
 
-int theora_decode_init(theora_state *_td,theora_info *_ci){
-  th_api_wrapper *api;
-  th_api_wrapper *dapi;
-  th_info         info;
-  /*We don't need these two fields.*/
-  _td->internal_encode=NULL;
-  _td->internal_decode=NULL;
-  _td->granulepos=0;
-  api=(th_api_wrapper *)_ci->codec_setup;
-  /*Make our own copy of the info struct, since its lifetime should be
-     independent of the one we were passed in.*/
-  _td->i=(theora_info *)_ogg_malloc(sizeof(*_td->i));
-  *_td->i=*_ci;
-  /*Also make our own copy of the wrapper.*/
-  dapi=(th_api_wrapper *)_ogg_calloc(1,sizeof(*dapi));
-  _td->i->codec_setup=dapi;
-  /*Convert the info struct now instead of saving the the one we decoded with
-     theora_decode_header(), since the user might have modified values (i.e.,
-     color space, aspect ratio, etc. can be specified from a higher level).
-    The user also might be doing something "clever" with the header packets if
-     they are not using an Ogg encapsulation.*/
-  theora_info2th_info(&info,_ci);
-  /*Don't bother to copy the setup info; th_decode_alloc() makes its own copy
-     of the stuff it needs.*/
-  dapi->decode=th_decode_alloc(&info,api->setup);
-  return 0;
-}
-
-static void th_info2theora_info(theora_info *_ci,const th_info *_info){
-  _ci->version_major=_info->version_major;
-  _ci->version_minor=_info->version_minor;
-  _ci->version_subminor=_info->version_subminor;
-  _ci->width=_info->frame_width;
-  _ci->height=_info->frame_height;
-  _ci->frame_width=_info->pic_width;
-  _ci->frame_height=_info->pic_height;
-  _ci->offset_x=_info->pic_x;
-  _ci->offset_y=_info->pic_y;
-  _ci->fps_numerator=_info->fps_numerator;
-  _ci->fps_denominator=_info->fps_denominator;
-  _ci->aspect_numerator=_info->aspect_numerator;
-  _ci->aspect_denominator=_info->aspect_denominator;
-  switch(_info->colorspace){
-    case TH_CS_ITU_REC_470M:_ci->colorspace=OC_CS_ITU_REC_470M;break;
-    case TH_CS_ITU_REC_470BG:_ci->colorspace=OC_CS_ITU_REC_470BG;break;
-    default:_ci->colorspace=OC_CS_UNSPECIFIED;break;
-  }
-  switch(_info->pixel_fmt){
-    case TH_PF_420:_ci->pixelformat=OC_PF_420;break;
-    case TH_PF_422:_ci->pixelformat=OC_PF_422;break;
-    case TH_PF_444:_ci->pixelformat=OC_PF_444;break;
-    default:_ci->pixelformat=OC_PF_RSVD;
-  }
-  _ci->target_bitrate=_info->target_bitrate;
-  _ci->quality=_info->quality;
-  _ci->keyframe_frequency_force=1<<_info->keyframe_granule_shift;
-}
-
-int theora_decode_header(theora_info *_ci,theora_comment *_cc,ogg_packet *_op){
-  th_api_wrapper *api;
-  th_info         info;
-  int             ret;
-  api=(th_api_wrapper *)_ci->codec_setup;
-  /*Convert from the theora_info struct instead of saving our own th_info
-     struct between calls.
-    The user might be doing something "clever" with the header packets if they
-     are not using an Ogg encapsulation, and we don't want to break this.*/
-  theora_info2th_info(&info,_ci);
-  /*We rely on the fact that theora_comment and th_comment structures are
-     actually identical.
-    Take care not to change this fact unless you change the code here as
-     well!*/
-  ret=th_decode_headerin(&info,(th_comment *)_cc,&api->setup,_op);
-  /*We also rely on the fact that the error return code values are the same,
-    and that the implementations of these two functions return the same set of
-    them.
-   Note that theora_decode_header() really can return OC_NOTFORMAT, even
-    though it is not currently documented to do so.*/
-  if(ret<0)return ret;
-  th_info2theora_info(_ci,&info);
-  return 0;
-}
-
-int theora_decode_packetin(theora_state *_td,ogg_packet *_op){
-  th_api_wrapper *api;
-  ogg_int64_t     gp;
-  int             ret;
-  api=(th_api_wrapper *)_td->i->codec_setup;
-  ret=th_decode_packetin(api->decode,_op,&gp);
-  if(ret<0)return OC_BADPACKET;
-  _td->granulepos=gp;
-  return 0;
-}
-
-int theora_decode_YUVout(theora_state *_td,yuv_buffer *_yuv){
-  th_api_wrapper *api;
-  th_ycbcr_buffer buf;
-  int             ret;
-  api=(th_api_wrapper *)_td->i->codec_setup;
-  ret=th_decode_ycbcr_out(api->decode,buf);
-  if(ret>=0){
-    _yuv->y_width=buf[0].width;
-    _yuv->y_height=buf[0].height;
-    _yuv->y_stride=buf[0].ystride;
-    _yuv->uv_width=buf[1].width;
-    _yuv->uv_height=buf[1].height;
-    _yuv->uv_stride=buf[1].ystride;
-    _yuv->y=buf[0].data;
-    _yuv->u=buf[1].data;
-    _yuv->v=buf[2].data;
-  }
-  return ret;
-}
-
-int theora_control(theora_state *_td,int _req,void *_buf,size_t _buf_sz){
-  if(_td->internal_encode!=NULL){
-    return (*((oc_enc_dispatch_vtbl *)_td->internal_encode)->control)(_td,
-     _req,_buf,_buf_sz);
-  }
-  return th_decode_ctl(((th_api_wrapper *)_td->i->codec_setup)->decode,
-   _req,_buf,_buf_sz);
-}
-
 int theora_packet_isheader(ogg_packet *_op){
   return th_packet_isheader(_op);
 }
@@ -244,22 +141,6 @@
   return oc_ilog(_ci->keyframe_frequency_force-1);
 }
 
-ogg_int64_t theora_granule_frame(theora_state *_td,ogg_int64_t _gp){
-  if(_td->internal_encode!=NULL){
-    return
-     (*((oc_enc_dispatch_vtbl *)_td->internal_encode)->granule_frame)(_td,_gp);
-  }
-  return th_granule_frame(((th_api_wrapper *)_td->i->codec_setup)->decode,_gp);
-}
-
-double theora_granule_time(theora_state *_td, ogg_int64_t _gp){
-  if(_td->internal_encode!=NULL){
-    return
-     (*((oc_enc_dispatch_vtbl *)_td->internal_encode)->granule_time)(_td,_gp);
-  }
-  return th_granule_time(((th_api_wrapper *)_td->i->codec_setup)->decode,_gp);
-}
-
 void theora_comment_init(theora_comment *_tc){
   th_comment_init((th_comment *)_tc);
 }

Modified: trunk/theora/lib/enc/codec_internal.h
===================================================================
--- trunk/theora/lib/enc/codec_internal.h	2007-09-16 22:05:14 UTC (rev 13842)
+++ trunk/theora/lib/enc/codec_internal.h	2007-09-16 22:05:48 UTC (rev 13843)
@@ -531,7 +531,7 @@
   /*This structure must be first.
     It contains entry points accessed by the decoder library's API wrapper, and
      is the only assumption that library makes about our internal format.*/
-  oc_enc_dispatch_vtbl dispatch_vtbl;
+  oc_state_dispatch_vtbl dispatch_vtbl;
 
   /* Compressor Configuration */
   SCAN_CONFIG_DATA ScanConfig;

Modified: trunk/theora/lib/internal.h
===================================================================
--- trunk/theora/lib/internal.h	2007-09-16 22:05:14 UTC (rev 13842)
+++ trunk/theora/lib/internal.h	2007-09-16 22:05:48 UTC (rev 13843)
@@ -464,22 +464,24 @@
    dependency into the decoder, while still allowing the old alpha API which
    does not distinguish between encoder and decoder objects to be used.
   We do this by placing a function table at the start of the encoder object
-   which can dispatch into the encoder library.*/
-typedef void (*oc_enc_clear_func)(theora_state *_th);
-typedef int (*oc_enc_control_func)(theora_state *th,int req,
+   which can dispatch into the encoder library.
+  We do a similar thing for the decoder in case we ever decide to split off a
+   common base library.*/
+typedef void (*oc_state_clear_func)(theora_state *_th);
+typedef int (*oc_state_control_func)(theora_state *th,int req,
  void *buf,size_t buf_sz);
-typedef ogg_int64_t (*oc_enc_granule_frame_func)(theora_state *_th,
+typedef ogg_int64_t (*oc_state_granule_frame_func)(theora_state *_th,
  ogg_int64_t _granulepos);
-typedef double (*oc_enc_granule_time_func)(theora_state *_th,
+typedef double (*oc_state_granule_time_func)(theora_state *_th,
  ogg_int64_t _granulepos);
 
-typedef struct oc_enc_dispatch_vtbl oc_enc_dispatch_vtbl;
+typedef struct oc_state_dispatch_vtbl oc_state_dispatch_vtbl;
 
-struct oc_enc_dispatch_vtbl{
-  oc_enc_clear_func         clear;
-  oc_enc_control_func       control;
-  oc_enc_granule_frame_func granule_frame;
-  oc_enc_granule_time_func  granule_time;
+struct oc_state_dispatch_vtbl{
+  oc_state_clear_func         clear;
+  oc_state_control_func       control;
+  oc_state_granule_frame_func granule_frame;
+  oc_state_granule_time_func  granule_time;
 };
 
 #endif



More information about the commits mailing list