michael@0: /******************************************************************** michael@0: * * michael@0: * THIS FILE IS PART OF THE OggTheora SOFTWARE CODEC SOURCE CODE. * michael@0: * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * michael@0: * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * michael@0: * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * michael@0: * * michael@0: * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 * michael@0: * by the Xiph.Org Foundation and contributors http://www.xiph.org/ * michael@0: * * michael@0: ******************************************************************** michael@0: michael@0: function: michael@0: last mod: $Id: apiwrapper.c 16503 2009-08-22 18:14:02Z giles $ michael@0: michael@0: ********************************************************************/ michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include "apiwrapper.h" michael@0: michael@0: michael@0: michael@0: const char *theora_version_string(void){ michael@0: return th_version_string(); michael@0: } michael@0: michael@0: ogg_uint32_t theora_version_number(void){ michael@0: return th_version_number(); michael@0: } michael@0: michael@0: void theora_info_init(theora_info *_ci){ michael@0: memset(_ci,0,sizeof(*_ci)); michael@0: } michael@0: michael@0: void theora_info_clear(theora_info *_ci){ michael@0: th_api_wrapper *api; michael@0: api=(th_api_wrapper *)_ci->codec_setup; michael@0: memset(_ci,0,sizeof(*_ci)); michael@0: if(api!=NULL){ michael@0: if(api->clear!=NULL)(*api->clear)(api); michael@0: _ogg_free(api); michael@0: } michael@0: } michael@0: michael@0: void theora_clear(theora_state *_th){ michael@0: /*Provide compatibility with mixed encoder and decoder shared lib versions.*/ michael@0: if(_th->internal_decode!=NULL){ michael@0: (*((oc_state_dispatch_vtable *)_th->internal_decode)->clear)(_th); michael@0: } michael@0: if(_th->internal_encode!=NULL){ michael@0: (*((oc_state_dispatch_vtable *)_th->internal_encode)->clear)(_th); michael@0: } michael@0: if(_th->i!=NULL)theora_info_clear(_th->i); michael@0: memset(_th,0,sizeof(*_th)); michael@0: } michael@0: michael@0: int theora_control(theora_state *_th,int _req,void *_buf,size_t _buf_sz){ michael@0: /*Provide compatibility with mixed encoder and decoder shared lib versions.*/ michael@0: if(_th->internal_decode!=NULL){ michael@0: return (*((oc_state_dispatch_vtable *)_th->internal_decode)->control)(_th, michael@0: _req,_buf,_buf_sz); michael@0: } michael@0: else if(_th->internal_encode!=NULL){ michael@0: return (*((oc_state_dispatch_vtable *)_th->internal_encode)->control)(_th, michael@0: _req,_buf,_buf_sz); michael@0: } michael@0: else return TH_EINVAL; michael@0: } michael@0: michael@0: ogg_int64_t theora_granule_frame(theora_state *_th,ogg_int64_t _gp){ michael@0: /*Provide compatibility with mixed encoder and decoder shared lib versions.*/ michael@0: if(_th->internal_decode!=NULL){ michael@0: return (*((oc_state_dispatch_vtable *)_th->internal_decode)->granule_frame)( michael@0: _th,_gp); michael@0: } michael@0: else if(_th->internal_encode!=NULL){ michael@0: return (*((oc_state_dispatch_vtable *)_th->internal_encode)->granule_frame)( michael@0: _th,_gp); michael@0: } michael@0: else return -1; michael@0: } michael@0: michael@0: double theora_granule_time(theora_state *_th, ogg_int64_t _gp){ michael@0: /*Provide compatibility with mixed encoder and decoder shared lib versions.*/ michael@0: if(_th->internal_decode!=NULL){ michael@0: return (*((oc_state_dispatch_vtable *)_th->internal_decode)->granule_time)( michael@0: _th,_gp); michael@0: } michael@0: else if(_th->internal_encode!=NULL){ michael@0: return (*((oc_state_dispatch_vtable *)_th->internal_encode)->granule_time)( michael@0: _th,_gp); michael@0: } michael@0: else return -1; michael@0: } michael@0: michael@0: void oc_theora_info2th_info(th_info *_info,const theora_info *_ci){ michael@0: _info->version_major=_ci->version_major; michael@0: _info->version_minor=_ci->version_minor; michael@0: _info->version_subminor=_ci->version_subminor; michael@0: _info->frame_width=_ci->width; michael@0: _info->frame_height=_ci->height; michael@0: _info->pic_width=_ci->frame_width; michael@0: _info->pic_height=_ci->frame_height; michael@0: _info->pic_x=_ci->offset_x; michael@0: _info->pic_y=_ci->offset_y; michael@0: _info->fps_numerator=_ci->fps_numerator; michael@0: _info->fps_denominator=_ci->fps_denominator; michael@0: _info->aspect_numerator=_ci->aspect_numerator; michael@0: _info->aspect_denominator=_ci->aspect_denominator; michael@0: switch(_ci->colorspace){ michael@0: case OC_CS_ITU_REC_470M:_info->colorspace=TH_CS_ITU_REC_470M;break; michael@0: case OC_CS_ITU_REC_470BG:_info->colorspace=TH_CS_ITU_REC_470BG;break; michael@0: default:_info->colorspace=TH_CS_UNSPECIFIED;break; michael@0: } michael@0: switch(_ci->pixelformat){ michael@0: case OC_PF_420:_info->pixel_fmt=TH_PF_420;break; michael@0: case OC_PF_422:_info->pixel_fmt=TH_PF_422;break; michael@0: case OC_PF_444:_info->pixel_fmt=TH_PF_444;break; michael@0: default:_info->pixel_fmt=TH_PF_RSVD; michael@0: } michael@0: _info->target_bitrate=_ci->target_bitrate; michael@0: _info->quality=_ci->quality; michael@0: _info->keyframe_granule_shift=_ci->keyframe_frequency_force>0? michael@0: OC_MINI(31,oc_ilog(_ci->keyframe_frequency_force-1)):0; michael@0: } michael@0: michael@0: int theora_packet_isheader(ogg_packet *_op){ michael@0: return th_packet_isheader(_op); michael@0: } michael@0: michael@0: int theora_packet_iskeyframe(ogg_packet *_op){ michael@0: return th_packet_iskeyframe(_op); michael@0: } michael@0: michael@0: int theora_granule_shift(theora_info *_ci){ michael@0: /*This breaks when keyframe_frequency_force is not positive or is larger than michael@0: 2**31 (if your int is more than 32 bits), but that's what the original michael@0: function does.*/ michael@0: return oc_ilog(_ci->keyframe_frequency_force-1); michael@0: } michael@0: michael@0: void theora_comment_init(theora_comment *_tc){ michael@0: th_comment_init((th_comment *)_tc); michael@0: } michael@0: michael@0: char *theora_comment_query(theora_comment *_tc,char *_tag,int _count){ michael@0: return th_comment_query((th_comment *)_tc,_tag,_count); michael@0: } michael@0: michael@0: int theora_comment_query_count(theora_comment *_tc,char *_tag){ michael@0: return th_comment_query_count((th_comment *)_tc,_tag); michael@0: } michael@0: michael@0: void theora_comment_clear(theora_comment *_tc){ michael@0: th_comment_clear((th_comment *)_tc); michael@0: } michael@0: michael@0: void theora_comment_add(theora_comment *_tc,char *_comment){ michael@0: th_comment_add((th_comment *)_tc,_comment); michael@0: } michael@0: michael@0: void theora_comment_add_tag(theora_comment *_tc, char *_tag, char *_value){ michael@0: th_comment_add_tag((th_comment *)_tc,_tag,_value); michael@0: }