media/libtheora/lib/apiwrapper.c

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libtheora/lib/apiwrapper.c	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,166 @@
     1.4 +/********************************************************************
     1.5 + *                                                                  *
     1.6 + * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE.   *
     1.7 + * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS     *
     1.8 + * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE *
     1.9 + * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING.       *
    1.10 + *                                                                  *
    1.11 + * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009                *
    1.12 + * by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
    1.13 + *                                                                  *
    1.14 + ********************************************************************
    1.15 +
    1.16 +  function:
    1.17 +    last mod: $Id: apiwrapper.c 16503 2009-08-22 18:14:02Z giles $
    1.18 +
    1.19 + ********************************************************************/
    1.20 +
    1.21 +#include <stdlib.h>
    1.22 +#include <string.h>
    1.23 +#include <limits.h>
    1.24 +#include "apiwrapper.h"
    1.25 +
    1.26 +
    1.27 +
    1.28 +const char *theora_version_string(void){
    1.29 +  return th_version_string();
    1.30 +}
    1.31 +
    1.32 +ogg_uint32_t theora_version_number(void){
    1.33 +  return th_version_number();
    1.34 +}
    1.35 +
    1.36 +void theora_info_init(theora_info *_ci){
    1.37 +  memset(_ci,0,sizeof(*_ci));
    1.38 +}
    1.39 +
    1.40 +void theora_info_clear(theora_info *_ci){
    1.41 +  th_api_wrapper *api;
    1.42 +  api=(th_api_wrapper *)_ci->codec_setup;
    1.43 +  memset(_ci,0,sizeof(*_ci));
    1.44 +  if(api!=NULL){
    1.45 +    if(api->clear!=NULL)(*api->clear)(api);
    1.46 +    _ogg_free(api);
    1.47 +  }
    1.48 +}
    1.49 +
    1.50 +void theora_clear(theora_state *_th){
    1.51 +  /*Provide compatibility with mixed encoder and decoder shared lib versions.*/
    1.52 +  if(_th->internal_decode!=NULL){
    1.53 +    (*((oc_state_dispatch_vtable *)_th->internal_decode)->clear)(_th);
    1.54 +  }
    1.55 +  if(_th->internal_encode!=NULL){
    1.56 +    (*((oc_state_dispatch_vtable *)_th->internal_encode)->clear)(_th);
    1.57 +  }
    1.58 +  if(_th->i!=NULL)theora_info_clear(_th->i);
    1.59 +  memset(_th,0,sizeof(*_th));
    1.60 +}
    1.61 +
    1.62 +int theora_control(theora_state *_th,int _req,void *_buf,size_t _buf_sz){
    1.63 +  /*Provide compatibility with mixed encoder and decoder shared lib versions.*/
    1.64 +  if(_th->internal_decode!=NULL){
    1.65 +    return (*((oc_state_dispatch_vtable *)_th->internal_decode)->control)(_th,
    1.66 +     _req,_buf,_buf_sz);
    1.67 +  }
    1.68 +  else if(_th->internal_encode!=NULL){
    1.69 +    return (*((oc_state_dispatch_vtable *)_th->internal_encode)->control)(_th,
    1.70 +     _req,_buf,_buf_sz);
    1.71 +  }
    1.72 +  else return TH_EINVAL;
    1.73 +}
    1.74 +
    1.75 +ogg_int64_t theora_granule_frame(theora_state *_th,ogg_int64_t _gp){
    1.76 +  /*Provide compatibility with mixed encoder and decoder shared lib versions.*/
    1.77 +  if(_th->internal_decode!=NULL){
    1.78 +    return (*((oc_state_dispatch_vtable *)_th->internal_decode)->granule_frame)(
    1.79 +     _th,_gp);
    1.80 +  }
    1.81 +  else if(_th->internal_encode!=NULL){
    1.82 +    return (*((oc_state_dispatch_vtable *)_th->internal_encode)->granule_frame)(
    1.83 +     _th,_gp);
    1.84 +  }
    1.85 +  else return -1;
    1.86 +}
    1.87 +
    1.88 +double theora_granule_time(theora_state *_th, ogg_int64_t _gp){
    1.89 +  /*Provide compatibility with mixed encoder and decoder shared lib versions.*/
    1.90 +  if(_th->internal_decode!=NULL){
    1.91 +    return (*((oc_state_dispatch_vtable *)_th->internal_decode)->granule_time)(
    1.92 +     _th,_gp);
    1.93 +  }
    1.94 +  else if(_th->internal_encode!=NULL){
    1.95 +    return (*((oc_state_dispatch_vtable *)_th->internal_encode)->granule_time)(
    1.96 +     _th,_gp);
    1.97 +  }
    1.98 +  else return -1;
    1.99 +}
   1.100 +
   1.101 +void oc_theora_info2th_info(th_info *_info,const theora_info *_ci){
   1.102 +  _info->version_major=_ci->version_major;
   1.103 +  _info->version_minor=_ci->version_minor;
   1.104 +  _info->version_subminor=_ci->version_subminor;
   1.105 +  _info->frame_width=_ci->width;
   1.106 +  _info->frame_height=_ci->height;
   1.107 +  _info->pic_width=_ci->frame_width;
   1.108 +  _info->pic_height=_ci->frame_height;
   1.109 +  _info->pic_x=_ci->offset_x;
   1.110 +  _info->pic_y=_ci->offset_y;
   1.111 +  _info->fps_numerator=_ci->fps_numerator;
   1.112 +  _info->fps_denominator=_ci->fps_denominator;
   1.113 +  _info->aspect_numerator=_ci->aspect_numerator;
   1.114 +  _info->aspect_denominator=_ci->aspect_denominator;
   1.115 +  switch(_ci->colorspace){
   1.116 +    case OC_CS_ITU_REC_470M:_info->colorspace=TH_CS_ITU_REC_470M;break;
   1.117 +    case OC_CS_ITU_REC_470BG:_info->colorspace=TH_CS_ITU_REC_470BG;break;
   1.118 +    default:_info->colorspace=TH_CS_UNSPECIFIED;break;
   1.119 +  }
   1.120 +  switch(_ci->pixelformat){
   1.121 +    case OC_PF_420:_info->pixel_fmt=TH_PF_420;break;
   1.122 +    case OC_PF_422:_info->pixel_fmt=TH_PF_422;break;
   1.123 +    case OC_PF_444:_info->pixel_fmt=TH_PF_444;break;
   1.124 +    default:_info->pixel_fmt=TH_PF_RSVD;
   1.125 +  }
   1.126 +  _info->target_bitrate=_ci->target_bitrate;
   1.127 +  _info->quality=_ci->quality;
   1.128 +  _info->keyframe_granule_shift=_ci->keyframe_frequency_force>0?
   1.129 +   OC_MINI(31,oc_ilog(_ci->keyframe_frequency_force-1)):0;
   1.130 +}
   1.131 +
   1.132 +int theora_packet_isheader(ogg_packet *_op){
   1.133 +  return th_packet_isheader(_op);
   1.134 +}
   1.135 +
   1.136 +int theora_packet_iskeyframe(ogg_packet *_op){
   1.137 +  return th_packet_iskeyframe(_op);
   1.138 +}
   1.139 +
   1.140 +int theora_granule_shift(theora_info *_ci){
   1.141 +  /*This breaks when keyframe_frequency_force is not positive or is larger than
   1.142 +     2**31 (if your int is more than 32 bits), but that's what the original
   1.143 +     function does.*/
   1.144 +  return oc_ilog(_ci->keyframe_frequency_force-1);
   1.145 +}
   1.146 +
   1.147 +void theora_comment_init(theora_comment *_tc){
   1.148 +  th_comment_init((th_comment *)_tc);
   1.149 +}
   1.150 +
   1.151 +char *theora_comment_query(theora_comment *_tc,char *_tag,int _count){
   1.152 +  return th_comment_query((th_comment *)_tc,_tag,_count);
   1.153 +}
   1.154 +
   1.155 +int theora_comment_query_count(theora_comment *_tc,char *_tag){
   1.156 +  return th_comment_query_count((th_comment *)_tc,_tag);
   1.157 +}
   1.158 +
   1.159 +void theora_comment_clear(theora_comment *_tc){
   1.160 +  th_comment_clear((th_comment *)_tc);
   1.161 +}
   1.162 +
   1.163 +void theora_comment_add(theora_comment *_tc,char *_comment){
   1.164 +  th_comment_add((th_comment *)_tc,_comment);
   1.165 +}
   1.166 +
   1.167 +void theora_comment_add_tag(theora_comment *_tc, char *_tag, char *_value){
   1.168 +  th_comment_add_tag((th_comment *)_tc,_tag,_value);
   1.169 +}

mercurial