apiwrapper.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. function:
  13. last mod: $Id$
  14. ********************************************************************/
  15. #include <stdlib.h>
  16. #include <string.h>
  17. #include <limits.h>
  18. #include "apiwrapper.h"
  19. const char *theora_version_string(void){
  20. return th_version_string();
  21. }
  22. ogg_uint32_t theora_version_number(void){
  23. return th_version_number();
  24. }
  25. void theora_info_init(theora_info *_ci){
  26. memset(_ci,0,sizeof(*_ci));
  27. }
  28. void theora_info_clear(theora_info *_ci){
  29. th_api_wrapper *api;
  30. api=(th_api_wrapper *)_ci->codec_setup;
  31. memset(_ci,0,sizeof(*_ci));
  32. if(api!=NULL){
  33. if(api->clear!=NULL)(*api->clear)(api);
  34. _ogg_free(api);
  35. }
  36. }
  37. void theora_clear(theora_state *_th){
  38. /*Provide compatibility with mixed encoder and decoder shared lib versions.*/
  39. if(_th->internal_decode!=NULL){
  40. (*((oc_state_dispatch_vtable *)_th->internal_decode)->clear)(_th);
  41. }
  42. if(_th->internal_encode!=NULL){
  43. (*((oc_state_dispatch_vtable *)_th->internal_encode)->clear)(_th);
  44. }
  45. if(_th->i!=NULL)theora_info_clear(_th->i);
  46. memset(_th,0,sizeof(*_th));
  47. }
  48. int theora_control(theora_state *_th,int _req,void *_buf,size_t _buf_sz){
  49. /*Provide compatibility with mixed encoder and decoder shared lib versions.*/
  50. if(_th->internal_decode!=NULL){
  51. return (*((oc_state_dispatch_vtable *)_th->internal_decode)->control)(_th,
  52. _req,_buf,_buf_sz);
  53. }
  54. else if(_th->internal_encode!=NULL){
  55. return (*((oc_state_dispatch_vtable *)_th->internal_encode)->control)(_th,
  56. _req,_buf,_buf_sz);
  57. }
  58. else return TH_EINVAL;
  59. }
  60. ogg_int64_t theora_granule_frame(theora_state *_th,ogg_int64_t _gp){
  61. /*Provide compatibility with mixed encoder and decoder shared lib versions.*/
  62. if(_th->internal_decode!=NULL){
  63. return (*((oc_state_dispatch_vtable *)_th->internal_decode)->granule_frame)(
  64. _th,_gp);
  65. }
  66. else if(_th->internal_encode!=NULL){
  67. return (*((oc_state_dispatch_vtable *)_th->internal_encode)->granule_frame)(
  68. _th,_gp);
  69. }
  70. else return -1;
  71. }
  72. double theora_granule_time(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_time)(
  76. _th,_gp);
  77. }
  78. else if(_th->internal_encode!=NULL){
  79. return (*((oc_state_dispatch_vtable *)_th->internal_encode)->granule_time)(
  80. _th,_gp);
  81. }
  82. else return -1;
  83. }
  84. void oc_theora_info2th_info(th_info *_info,const theora_info *_ci){
  85. _info->version_major=_ci->version_major;
  86. _info->version_minor=_ci->version_minor;
  87. _info->version_subminor=_ci->version_subminor;
  88. _info->frame_width=_ci->width;
  89. _info->frame_height=_ci->height;
  90. _info->pic_width=_ci->frame_width;
  91. _info->pic_height=_ci->frame_height;
  92. _info->pic_x=_ci->offset_x;
  93. _info->pic_y=_ci->offset_y;
  94. _info->fps_numerator=_ci->fps_numerator;
  95. _info->fps_denominator=_ci->fps_denominator;
  96. _info->aspect_numerator=_ci->aspect_numerator;
  97. _info->aspect_denominator=_ci->aspect_denominator;
  98. switch(_ci->colorspace){
  99. case OC_CS_ITU_REC_470M:_info->colorspace=TH_CS_ITU_REC_470M;break;
  100. case OC_CS_ITU_REC_470BG:_info->colorspace=TH_CS_ITU_REC_470BG;break;
  101. default:_info->colorspace=TH_CS_UNSPECIFIED;break;
  102. }
  103. switch(_ci->pixelformat){
  104. case OC_PF_420:_info->pixel_fmt=TH_PF_420;break;
  105. case OC_PF_422:_info->pixel_fmt=TH_PF_422;break;
  106. case OC_PF_444:_info->pixel_fmt=TH_PF_444;break;
  107. default:_info->pixel_fmt=TH_PF_RSVD;
  108. }
  109. _info->target_bitrate=_ci->target_bitrate;
  110. _info->quality=_ci->quality;
  111. _info->keyframe_granule_shift=_ci->keyframe_frequency_force>0?
  112. OC_MINI(31,oc_ilog(_ci->keyframe_frequency_force-1)):0;
  113. }
  114. int theora_packet_isheader(ogg_packet *_op){
  115. return th_packet_isheader(_op);
  116. }
  117. int theora_packet_iskeyframe(ogg_packet *_op){
  118. return th_packet_iskeyframe(_op);
  119. }
  120. int theora_granule_shift(theora_info *_ci){
  121. /*This breaks when keyframe_frequency_force is not positive or is larger than
  122. 2**31 (if your int is more than 32 bits), but that's what the original
  123. function does.*/
  124. return oc_ilog(_ci->keyframe_frequency_force-1);
  125. }
  126. void theora_comment_init(theora_comment *_tc){
  127. th_comment_init((th_comment *)_tc);
  128. }
  129. char *theora_comment_query(theora_comment *_tc,char *_tag,int _count){
  130. return th_comment_query((th_comment *)_tc,_tag,_count);
  131. }
  132. int theora_comment_query_count(theora_comment *_tc,char *_tag){
  133. return th_comment_query_count((th_comment *)_tc,_tag);
  134. }
  135. void theora_comment_clear(theora_comment *_tc){
  136. th_comment_clear((th_comment *)_tc);
  137. }
  138. void theora_comment_add(theora_comment *_tc,char *_comment){
  139. th_comment_add((th_comment *)_tc,_comment);
  140. }
  141. void theora_comment_add_tag(theora_comment *_tc, char *_tag, char *_value){
  142. th_comment_add_tag((th_comment *)_tc,_tag,_value);
  143. }