1 /********************************************************************
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. *
8 * THE Theora SOURCE CODE IS COPYRIGHT (C) 2002-2009 *
9 * by the Xiph.Org Foundation and contributors http://www.xiph.org/ *
11 ********************************************************************
14 last mod: $Id: apiwrapper.c 16503 2009-08-22 18:14:02Z giles $
16 ********************************************************************/
21 #include "apiwrapper.h"
25 const char *theora_version_string(void){
26 return th_version_string();
29 ogg_uint32_t theora_version_number(void){
30 return th_version_number();
33 void theora_info_init(theora_info *_ci){
34 memset(_ci,0,sizeof(*_ci));
37 void theora_info_clear(theora_info *_ci){
39 api=(th_api_wrapper *)_ci->codec_setup;
40 memset(_ci,0,sizeof(*_ci));
42 if(api->clear!=NULL)(*api->clear)(api);
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);
52 if(_th->internal_encode!=NULL){
53 (*((oc_state_dispatch_vtable *)_th->internal_encode)->clear)(_th);
55 if(_th->i!=NULL)theora_info_clear(_th->i);
56 memset(_th,0,sizeof(*_th));
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,
65 else if(_th->internal_encode!=NULL){
66 return (*((oc_state_dispatch_vtable *)_th->internal_encode)->control)(_th,
69 else return TH_EINVAL;
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)(
78 else if(_th->internal_encode!=NULL){
79 return (*((oc_state_dispatch_vtable *)_th->internal_encode)->granule_frame)(
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)(
91 else if(_th->internal_encode!=NULL){
92 return (*((oc_state_dispatch_vtable *)_th->internal_encode)->granule_time)(
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;
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;
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;
129 int theora_packet_isheader(ogg_packet *_op){
130 return th_packet_isheader(_op);
133 int theora_packet_iskeyframe(ogg_packet *_op){
134 return th_packet_iskeyframe(_op);
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
141 return oc_ilog(_ci->keyframe_frequency_force-1);
144 void theora_comment_init(theora_comment *_tc){
145 th_comment_init((th_comment *)_tc);
148 char *theora_comment_query(theora_comment *_tc,char *_tag,int _count){
149 return th_comment_query((th_comment *)_tc,_tag,_count);
152 int theora_comment_query_count(theora_comment *_tc,char *_tag){
153 return th_comment_query_count((th_comment *)_tc,_tag);
156 void theora_comment_clear(theora_comment *_tc){
157 th_comment_clear((th_comment *)_tc);
160 void theora_comment_add(theora_comment *_tc,char *_comment){
161 th_comment_add((th_comment *)_tc,_comment);
164 void theora_comment_add_tag(theora_comment *_tc, char *_tag, char *_value){
165 th_comment_add_tag((th_comment *)_tc,_tag,_value);