Line data Source code
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 0 : const char *theora_version_string(void){
26 0 : return th_version_string();
27 : }
28 :
29 0 : ogg_uint32_t theora_version_number(void){
30 0 : return th_version_number();
31 : }
32 :
33 0 : void theora_info_init(theora_info *_ci){
34 0 : memset(_ci,0,sizeof(*_ci));
35 0 : }
36 :
37 0 : void theora_info_clear(theora_info *_ci){
38 : th_api_wrapper *api;
39 0 : api=(th_api_wrapper *)_ci->codec_setup;
40 0 : memset(_ci,0,sizeof(*_ci));
41 0 : if(api!=NULL){
42 0 : if(api->clear!=NULL)(*api->clear)(api);
43 0 : _ogg_free(api);
44 : }
45 0 : }
46 :
47 0 : void theora_clear(theora_state *_th){
48 : /*Provide compatibility with mixed encoder and decoder shared lib versions.*/
49 0 : if(_th->internal_decode!=NULL){
50 0 : (*((oc_state_dispatch_vtable *)_th->internal_decode)->clear)(_th);
51 : }
52 0 : if(_th->internal_encode!=NULL){
53 0 : (*((oc_state_dispatch_vtable *)_th->internal_encode)->clear)(_th);
54 : }
55 0 : if(_th->i!=NULL)theora_info_clear(_th->i);
56 0 : memset(_th,0,sizeof(*_th));
57 0 : }
58 :
59 0 : 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 0 : if(_th->internal_decode!=NULL){
62 0 : return (*((oc_state_dispatch_vtable *)_th->internal_decode)->control)(_th,
63 : _req,_buf,_buf_sz);
64 : }
65 0 : else if(_th->internal_encode!=NULL){
66 0 : return (*((oc_state_dispatch_vtable *)_th->internal_encode)->control)(_th,
67 : _req,_buf,_buf_sz);
68 : }
69 0 : else return TH_EINVAL;
70 : }
71 :
72 0 : 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 0 : if(_th->internal_decode!=NULL){
75 0 : return (*((oc_state_dispatch_vtable *)_th->internal_decode)->granule_frame)(
76 : _th,_gp);
77 : }
78 0 : else if(_th->internal_encode!=NULL){
79 0 : return (*((oc_state_dispatch_vtable *)_th->internal_encode)->granule_frame)(
80 : _th,_gp);
81 : }
82 0 : else return -1;
83 : }
84 :
85 0 : double theora_granule_time(theora_state *_th, ogg_int64_t _gp){
86 : /*Provide compatibility with mixed encoder and decoder shared lib versions.*/
87 0 : if(_th->internal_decode!=NULL){
88 0 : return (*((oc_state_dispatch_vtable *)_th->internal_decode)->granule_time)(
89 : _th,_gp);
90 : }
91 0 : else if(_th->internal_encode!=NULL){
92 0 : return (*((oc_state_dispatch_vtable *)_th->internal_encode)->granule_time)(
93 : _th,_gp);
94 : }
95 0 : else return -1;
96 : }
97 :
98 0 : void oc_theora_info2th_info(th_info *_info,const theora_info *_ci){
99 0 : _info->version_major=_ci->version_major;
100 0 : _info->version_minor=_ci->version_minor;
101 0 : _info->version_subminor=_ci->version_subminor;
102 0 : _info->frame_width=_ci->width;
103 0 : _info->frame_height=_ci->height;
104 0 : _info->pic_width=_ci->frame_width;
105 0 : _info->pic_height=_ci->frame_height;
106 0 : _info->pic_x=_ci->offset_x;
107 0 : _info->pic_y=_ci->offset_y;
108 0 : _info->fps_numerator=_ci->fps_numerator;
109 0 : _info->fps_denominator=_ci->fps_denominator;
110 0 : _info->aspect_numerator=_ci->aspect_numerator;
111 0 : _info->aspect_denominator=_ci->aspect_denominator;
112 0 : switch(_ci->colorspace){
113 0 : case OC_CS_ITU_REC_470M:_info->colorspace=TH_CS_ITU_REC_470M;break;
114 0 : case OC_CS_ITU_REC_470BG:_info->colorspace=TH_CS_ITU_REC_470BG;break;
115 0 : default:_info->colorspace=TH_CS_UNSPECIFIED;break;
116 : }
117 0 : switch(_ci->pixelformat){
118 0 : case OC_PF_420:_info->pixel_fmt=TH_PF_420;break;
119 0 : case OC_PF_422:_info->pixel_fmt=TH_PF_422;break;
120 0 : case OC_PF_444:_info->pixel_fmt=TH_PF_444;break;
121 0 : default:_info->pixel_fmt=TH_PF_RSVD;
122 : }
123 0 : _info->target_bitrate=_ci->target_bitrate;
124 0 : _info->quality=_ci->quality;
125 0 : _info->keyframe_granule_shift=_ci->keyframe_frequency_force>0?
126 0 : OC_MINI(31,oc_ilog(_ci->keyframe_frequency_force-1)):0;
127 0 : }
128 :
129 0 : int theora_packet_isheader(ogg_packet *_op){
130 0 : return th_packet_isheader(_op);
131 : }
132 :
133 0 : int theora_packet_iskeyframe(ogg_packet *_op){
134 0 : return th_packet_iskeyframe(_op);
135 : }
136 :
137 0 : 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 0 : return oc_ilog(_ci->keyframe_frequency_force-1);
142 : }
143 :
144 0 : void theora_comment_init(theora_comment *_tc){
145 0 : th_comment_init((th_comment *)_tc);
146 0 : }
147 :
148 0 : char *theora_comment_query(theora_comment *_tc,char *_tag,int _count){
149 0 : return th_comment_query((th_comment *)_tc,_tag,_count);
150 : }
151 :
152 0 : int theora_comment_query_count(theora_comment *_tc,char *_tag){
153 0 : return th_comment_query_count((th_comment *)_tc,_tag);
154 : }
155 :
156 0 : void theora_comment_clear(theora_comment *_tc){
157 0 : th_comment_clear((th_comment *)_tc);
158 0 : }
159 :
160 0 : void theora_comment_add(theora_comment *_tc,char *_comment){
161 0 : th_comment_add((th_comment *)_tc,_comment);
162 0 : }
163 :
164 0 : void theora_comment_add_tag(theora_comment *_tc, char *_tag, char *_value){
165 0 : th_comment_add_tag((th_comment *)_tc,_tag,_value);
166 0 : }
|