1 /******************************************************************** 2 * * 3 * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. * 4 * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * 5 * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * 6 * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * 7 * * 8 * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 * 9 * by the Xiph.Org Foundation and contributors http://www.xiph.org/ * 10 * * 11 ******************************************************************** 12 13 function: 14 last mod: $Id: apiwrapper.c 16503 2009-08-22 18:14:02Z giles $ 15 16 ********************************************************************/ 17 18 #include <stdlib.h> 19 #include <string.h> 20 #include <limits.h> 21 #include "apiwrapper.h" 22 23 24 25 const char *theora_version_string(void){ 26 return th_version_string(); 27 } 28 29 ogg_uint32_t theora_version_number(void){ 30 return th_version_number(); 31 } 32 33 void theora_info_init(theora_info *_ci){ 34 memset(_ci,0,sizeof(*_ci)); 35 } 36 37 void theora_info_clear(theora_info *_ci){ 38 th_api_wrapper *api; 39 api=(th_api_wrapper *)_ci->codec_setup; 40 memset(_ci,0,sizeof(*_ci)); 41 if(api!=NULL){ 42 if(api->clear!=NULL)(*api->clear)(api); 43 _ogg_free(api); 44 } 45 } 46 47 void theora_clear(theora_state *_th){ 48 /*Provide compatibility with mixed encoder and decoder shared lib versions.*/ 49 if(_th->internal_decode!=NULL){ 50 (*((oc_state_dispatch_vtable *)_th->internal_decode)->clear)(_th); 51 } 52 if(_th->internal_encode!=NULL){ 53 (*((oc_state_dispatch_vtable *)_th->internal_encode)->clear)(_th); 54 } 55 if(_th->i!=NULL)theora_info_clear(_th->i); 56 memset(_th,0,sizeof(*_th)); 57 } 58 59 int theora_control(theora_state *_th,int _req,void *_buf,size_t _buf_sz){ 60 /*Provide compatibility with mixed encoder and decoder shared lib versions.*/ 61 if(_th->internal_decode!=NULL){ 62 return (*((oc_state_dispatch_vtable *)_th->internal_decode)->control)(_th, 63 _req,_buf,_buf_sz); 64 } 65 else if(_th->internal_encode!=NULL){ 66 return (*((oc_state_dispatch_vtable *)_th->internal_encode)->control)(_th, 67 _req,_buf,_buf_sz); 68 } 69 else return TH_EINVAL; 70 } 71 72 ogg_int64_t theora_granule_frame(theora_state *_th,ogg_int64_t _gp){ 73 /*Provide compatibility with mixed encoder and decoder shared lib versions.*/ 74 if(_th->internal_decode!=NULL){ 75 return (*((oc_state_dispatch_vtable *)_th->internal_decode)->granule_frame)( 76 _th,_gp); 77 } 78 else if(_th->internal_encode!=NULL){ 79 return (*((oc_state_dispatch_vtable *)_th->internal_encode)->granule_frame)( 80 _th,_gp); 81 } 82 else return -1; 83 } 84 85 double theora_granule_time(theora_state *_th, ogg_int64_t _gp){ 86 /*Provide compatibility with mixed encoder and decoder shared lib versions.*/ 87 if(_th->internal_decode!=NULL){ 88 return (*((oc_state_dispatch_vtable *)_th->internal_decode)->granule_time)( 89 _th,_gp); 90 } 91 else if(_th->internal_encode!=NULL){ 92 return (*((oc_state_dispatch_vtable *)_th->internal_encode)->granule_time)( 93 _th,_gp); 94 } 95 else return -1; 96 } 97 98 void oc_theora_info2th_info(th_info *_info,const theora_info *_ci){ 99 _info->version_major=_ci->version_major; 100 _info->version_minor=_ci->version_minor; 101 _info->version_subminor=_ci->version_subminor; 102 _info->frame_width=_ci->width; 103 _info->frame_height=_ci->height; 104 _info->pic_width=_ci->frame_width; 105 _info->pic_height=_ci->frame_height; 106 _info->pic_x=_ci->offset_x; 107 _info->pic_y=_ci->offset_y; 108 _info->fps_numerator=_ci->fps_numerator; 109 _info->fps_denominator=_ci->fps_denominator; 110 _info->aspect_numerator=_ci->aspect_numerator; 111 _info->aspect_denominator=_ci->aspect_denominator; 112 switch(_ci->colorspace){ 113 case OC_CS_ITU_REC_470M:_info->colorspace=TH_CS_ITU_REC_470M;break; 114 case OC_CS_ITU_REC_470BG:_info->colorspace=TH_CS_ITU_REC_470BG;break; 115 default:_info->colorspace=TH_CS_UNSPECIFIED;break; 116 } 117 switch(_ci->pixelformat){ 118 case OC_PF_420:_info->pixel_fmt=TH_PF_420;break; 119 case OC_PF_422:_info->pixel_fmt=TH_PF_422;break; 120 case OC_PF_444:_info->pixel_fmt=TH_PF_444;break; 121 default:_info->pixel_fmt=TH_PF_RSVD; 122 } 123 _info->target_bitrate=_ci->target_bitrate; 124 _info->quality=_ci->quality; 125 _info->keyframe_granule_shift=_ci->keyframe_frequency_force>0? 126 OC_MINI(31,oc_ilog(_ci->keyframe_frequency_force-1)):0; 127 } 128 129 int theora_packet_isheader(ogg_packet *_op){ 130 return th_packet_isheader(_op); 131 } 132 133 int theora_packet_iskeyframe(ogg_packet *_op){ 134 return th_packet_iskeyframe(_op); 135 } 136 137 int theora_granule_shift(theora_info *_ci){ 138 /*This breaks when keyframe_frequency_force is not positive or is larger than 139 2**31 (if your int is more than 32 bits), but that's what the original 140 function does.*/ 141 return oc_ilog(_ci->keyframe_frequency_force-1); 142 } 143 144 void theora_comment_init(theora_comment *_tc){ 145 th_comment_init((th_comment *)_tc); 146 } 147 148 char *theora_comment_query(theora_comment *_tc,char *_tag,int _count){ 149 return th_comment_query((th_comment *)_tc,_tag,_count); 150 } 151 152 int theora_comment_query_count(theora_comment *_tc,char *_tag){ 153 return th_comment_query_count((th_comment *)_tc,_tag); 154 } 155 156 void theora_comment_clear(theora_comment *_tc){ 157 th_comment_clear((th_comment *)_tc); 158 } 159 160 void theora_comment_add(theora_comment *_tc,char *_comment){ 161 th_comment_add((th_comment *)_tc,_comment); 162 } 163 164 void theora_comment_add_tag(theora_comment *_tc, char *_tag, char *_value){ 165 th_comment_add_tag((th_comment *)_tc,_tag,_value); 166 } 167