media/libtheora/lib/apiwrapper.c

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial