xvid.c
上传用户:sun1608
上传日期:2007-02-02
资源大小:6116k
文件大小:7k
源码类别:

流媒体/Mpeg4/MP4

开发平台:

Visual C++

  1. /**************************************************************************
  2.  *
  3.  * XVID MPEG-4 VIDEO CODEC
  4.  * native api
  5.  *
  6.  * This program is an implementation of a part of one or more MPEG-4
  7.  * Video tools as specified in ISO/IEC 14496-2 standard.  Those intending
  8.  * to use this software module in hardware or software products are
  9.  * advised that its use may infringe existing patents or copyrights, and
  10.  * any such use would be at such party's own risk.  The original
  11.  * developer of this software module and his/her company, and subsequent
  12.  * editors and their companies, will have no liability for use of this
  13.  * software or modifications or derivatives thereof.
  14.  *
  15.  * This program is free software; you can redistribute it and/or modify
  16.  * it under the terms of the GNU General Public License as published by
  17.  * the Free Software Foundation; either version 2 of the License, or
  18.  * (at your option) any later version.
  19.  *
  20.  * This program is distributed in the hope that it will be useful,
  21.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  23.  * GNU General Public License for more details.
  24.  *
  25.  * You should have received a copy of the GNU General Public License
  26.  * along with this program; if not, write to the Free Software
  27.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  28.  *
  29.  *************************************************************************/
  30. /**************************************************************************
  31.  *
  32.  * History:
  33.  *
  34.  * 17.03.2002 Added interpolate8x8_halfpel_hv_xmm
  35.  *  22.12.2001  API change: added xvid_init() - Isibaar
  36.  * 16.12.2001 inital version; (c)2001 peter ross <pross@cs.rmit.edu.au>
  37.  *
  38.  *************************************************************************/
  39. #include "xvid.h"
  40. #include "decoder.h"
  41. #include "encoder.h"
  42. #include "bitstream/cbp.h"
  43. #include "dct/idct.h"
  44. #include "dct/fdct.h"
  45. #include "image/colorspace.h"
  46. #include "image/interpolate8x8.h"
  47. #include "utils/mem_transfer.h"
  48. #include "quant/quant_h263.h"
  49. #include "quant/quant_mpeg4.h"
  50. #include "motion/sad.h"
  51. #include "utils/emms.h"
  52. #include "utils/timer.h"
  53. #include "bitstream/mbcoding.h"
  54. int xvid_init(void *handle, int opt, void *param1, void *param2)
  55. {
  56. int cpu_flags;
  57. XVID_INIT_PARAM *init_param;
  58. init_param = (XVID_INIT_PARAM *) param1;
  59. // force specific cpu settings?
  60. if((init_param->cpu_flags & XVID_CPU_FORCE) > 0)
  61. cpu_flags = init_param->cpu_flags;
  62. else {
  63. #ifdef ARCH_X86
  64. cpu_flags = check_cpu_features();
  65. #else
  66. cpu_flags = 0;
  67. #endif
  68. init_param->cpu_flags = cpu_flags;
  69. }
  70. // initialize the function pointers
  71. idct_int32_init();
  72. init_vlc_tables();
  73. fdct = fdct_int32;
  74. idct = idct_int32;
  75. sadInit = 0;
  76. emms = emms_c;
  77. quant_intra = quant_intra_c;
  78. dequant_intra = dequant_intra_c;
  79. quant_inter = quant_inter_c;
  80. dequant_inter = dequant_inter_c;
  81. quant4_intra = quant4_intra_c;
  82. dequant4_intra = dequant4_intra_c;
  83. quant4_inter = quant4_inter_c;
  84. dequant4_inter = dequant4_inter_c;
  85. transfer_8to16copy = transfer_8to16copy_c;
  86. transfer_16to8copy = transfer_16to8copy_c;
  87. transfer_8to16sub = transfer_8to16sub_c;
  88. transfer_16to8add = transfer_16to8add_c;
  89. transfer8x8_copy = transfer8x8_copy_c;
  90. interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_c;
  91. interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_c;
  92. interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_c;
  93. colorspace_init();
  94. rgb555_to_yv12 = rgb555_to_yv12_c;
  95. rgb565_to_yv12 = rgb565_to_yv12_c;
  96. rgb24_to_yv12 = rgb24_to_yv12_c;
  97. rgb32_to_yv12 = rgb32_to_yv12_c;
  98. yuv_to_yv12 = yuv_to_yv12_c;
  99. yuyv_to_yv12 = yuyv_to_yv12_c;
  100. uyvy_to_yv12 = uyvy_to_yv12_c;
  101. yv12_to_rgb555 = yv12_to_rgb555_c;
  102. yv12_to_rgb565 = yv12_to_rgb565_c;
  103. yv12_to_rgb24 = yv12_to_rgb24_c;
  104. yv12_to_rgb32 = yv12_to_rgb32_c;
  105. yv12_to_yuv = yv12_to_yuv_c;
  106. yv12_to_yuyv = yv12_to_yuyv_c;
  107. yv12_to_uyvy = yv12_to_uyvy_c;
  108. calc_cbp = calc_cbp_c;
  109. sad16 = sad16_c;
  110. sad8 = sad8_c;
  111. dev16 = dev16_c;
  112. #ifdef ARCH_X86
  113. if((cpu_flags & XVID_CPU_MMX) > 0) {
  114. fdct = fdct_mmx;
  115. idct = idct_mmx;
  116. emms = emms_mmx;
  117. quant_intra = quant_intra_mmx;
  118. dequant_intra = dequant_intra_mmx;
  119. quant_inter = quant_inter_mmx;
  120. dequant_inter = dequant_inter_mmx;
  121. quant4_intra = quant4_intra_mmx;
  122. dequant4_intra = dequant4_intra_mmx;
  123. quant4_inter = quant4_inter_mmx;
  124. dequant4_inter = dequant4_inter_mmx;
  125. transfer_8to16copy = transfer_8to16copy_mmx;
  126. transfer_16to8copy = transfer_16to8copy_mmx;
  127. transfer_8to16sub = transfer_8to16sub_mmx;
  128. transfer_16to8add = transfer_16to8add_mmx;
  129. transfer8x8_copy = transfer8x8_copy_mmx;
  130. interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_mmx;
  131. interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_mmx;
  132. interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_mmx;
  133. rgb24_to_yv12 = rgb24_to_yv12_mmx;
  134. rgb32_to_yv12 = rgb32_to_yv12_mmx;
  135. yuv_to_yv12 = yuv_to_yv12_mmx;
  136. yuyv_to_yv12 = yuyv_to_yv12_mmx;
  137. uyvy_to_yv12 = uyvy_to_yv12_mmx;
  138. yv12_to_rgb24 = yv12_to_rgb24_mmx;
  139. yv12_to_rgb32 = yv12_to_rgb32_mmx;
  140. yv12_to_yuyv = yv12_to_yuyv_mmx;
  141. yv12_to_uyvy = yv12_to_uyvy_mmx;
  142. calc_cbp = calc_cbp_mmx;
  143. sad16 = sad16_mmx;
  144. sad8 = sad8_mmx;
  145. dev16 = dev16_mmx;
  146. }
  147. if((cpu_flags & XVID_CPU_MMXEXT) > 0) {
  148. idct = idct_xmm;
  149. interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_xmm;
  150. interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_xmm;
  151. interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_xmm;
  152. yuv_to_yv12 = yuv_to_yv12_xmm;
  153. sad16 = sad16_xmm;
  154. sad8 = sad8_xmm;
  155. dev16 = dev16_xmm;
  156. }
  157. if((cpu_flags & XVID_CPU_3DNOW) > 0) {
  158. interpolate8x8_halfpel_h = interpolate8x8_halfpel_h_3dn;
  159. interpolate8x8_halfpel_v = interpolate8x8_halfpel_v_3dn;
  160. interpolate8x8_halfpel_hv = interpolate8x8_halfpel_hv_3dn;
  161. }
  162. #ifdef MPEG4IP
  163. if((cpu_flags & XVID_CPU_SSE2) > 0) {
  164. sad16 = sad16_sse2;
  165. }
  166. #endif
  167. #endif
  168. #ifdef ARCH_PPC
  169. #ifdef ARCH_PPC_ALTIVEC
  170. calc_cbp = calc_cbp_altivec;
  171. fdct = fdct_altivec;
  172. idct = idct_altivec;
  173. sadInit = sadInit_altivec;
  174. sad16 = sad16_altivec;
  175. sad8 = sad8_altivec;
  176. dev16 = dev16_altivec;
  177. #else
  178. calc_cbp = calc_cbp_ppc;
  179. #endif
  180. #endif
  181. // API version
  182. init_param->api_version = API_VERSION;
  183. // something clever has to be done for this
  184. init_param->core_build = 1000;
  185. return XVID_ERR_OK;
  186. }
  187. int xvid_decore(void * handle, int opt, void * param1, void * param2)
  188. {
  189. switch (opt)
  190. {
  191. case XVID_DEC_DECODE :
  192. return decoder_decode((DECODER *) handle, (XVID_DEC_FRAME *) param1);
  193. case XVID_DEC_CREATE :
  194. return decoder_create((XVID_DEC_PARAM *) param1);
  195. case XVID_DEC_DESTROY :
  196. return decoder_destroy((DECODER *) handle);
  197. case XVID_DEC_ALLOC:
  198.   return decoder_alloc((XVID_DEC_PARAM *)param1);
  199. case XVID_DEC_FIND_VOL:
  200.   return decoder_find_vol((DECODER *)handle, 
  201.   (XVID_DEC_FRAME *)param1,
  202.   (XVID_DEC_PARAM *)param2);
  203. default:
  204. return XVID_ERR_FAIL;
  205.     }
  206. }
  207. int xvid_encore(void * handle, int opt, void * param1, void * param2)
  208. {
  209. switch (opt)
  210. {
  211. case XVID_ENC_ENCODE :
  212. return encoder_encode((Encoder *) handle, (XVID_ENC_FRAME *) param1, (XVID_ENC_STATS *) param2);
  213. case XVID_ENC_CREATE :
  214. return encoder_create((XVID_ENC_PARAM *) param1);
  215. case XVID_ENC_DESTROY :
  216. return encoder_destroy((Encoder *) handle);
  217. default:
  218. return XVID_ERR_FAIL;
  219.     }
  220. }