You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1297 lines
53KB

  1. /*
  2. * utils for libavcodec
  3. * Copyright (c) 2001 Fabrice Bellard.
  4. * Copyright (c) 2003 Michel Bardiaux for the av_log API
  5. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. /**
  22. * @file utils.c
  23. * utils.
  24. */
  25. #include "avcodec.h"
  26. #include "dsputil.h"
  27. #include "mpegvideo.h"
  28. #include "integer.h"
  29. #include <stdarg.h>
  30. #include <limits.h>
  31. #include <float.h>
  32. const uint8_t ff_reverse[256]={
  33. 0x00,0x80,0x40,0xC0,0x20,0xA0,0x60,0xE0,0x10,0x90,0x50,0xD0,0x30,0xB0,0x70,0xF0,
  34. 0x08,0x88,0x48,0xC8,0x28,0xA8,0x68,0xE8,0x18,0x98,0x58,0xD8,0x38,0xB8,0x78,0xF8,
  35. 0x04,0x84,0x44,0xC4,0x24,0xA4,0x64,0xE4,0x14,0x94,0x54,0xD4,0x34,0xB4,0x74,0xF4,
  36. 0x0C,0x8C,0x4C,0xCC,0x2C,0xAC,0x6C,0xEC,0x1C,0x9C,0x5C,0xDC,0x3C,0xBC,0x7C,0xFC,
  37. 0x02,0x82,0x42,0xC2,0x22,0xA2,0x62,0xE2,0x12,0x92,0x52,0xD2,0x32,0xB2,0x72,0xF2,
  38. 0x0A,0x8A,0x4A,0xCA,0x2A,0xAA,0x6A,0xEA,0x1A,0x9A,0x5A,0xDA,0x3A,0xBA,0x7A,0xFA,
  39. 0x06,0x86,0x46,0xC6,0x26,0xA6,0x66,0xE6,0x16,0x96,0x56,0xD6,0x36,0xB6,0x76,0xF6,
  40. 0x0E,0x8E,0x4E,0xCE,0x2E,0xAE,0x6E,0xEE,0x1E,0x9E,0x5E,0xDE,0x3E,0xBE,0x7E,0xFE,
  41. 0x01,0x81,0x41,0xC1,0x21,0xA1,0x61,0xE1,0x11,0x91,0x51,0xD1,0x31,0xB1,0x71,0xF1,
  42. 0x09,0x89,0x49,0xC9,0x29,0xA9,0x69,0xE9,0x19,0x99,0x59,0xD9,0x39,0xB9,0x79,0xF9,
  43. 0x05,0x85,0x45,0xC5,0x25,0xA5,0x65,0xE5,0x15,0x95,0x55,0xD5,0x35,0xB5,0x75,0xF5,
  44. 0x0D,0x8D,0x4D,0xCD,0x2D,0xAD,0x6D,0xED,0x1D,0x9D,0x5D,0xDD,0x3D,0xBD,0x7D,0xFD,
  45. 0x03,0x83,0x43,0xC3,0x23,0xA3,0x63,0xE3,0x13,0x93,0x53,0xD3,0x33,0xB3,0x73,0xF3,
  46. 0x0B,0x8B,0x4B,0xCB,0x2B,0xAB,0x6B,0xEB,0x1B,0x9B,0x5B,0xDB,0x3B,0xBB,0x7B,0xFB,
  47. 0x07,0x87,0x47,0xC7,0x27,0xA7,0x67,0xE7,0x17,0x97,0x57,0xD7,0x37,0xB7,0x77,0xF7,
  48. 0x0F,0x8F,0x4F,0xCF,0x2F,0xAF,0x6F,0xEF,0x1F,0x9F,0x5F,0xDF,0x3F,0xBF,0x7F,0xFF,
  49. };
  50. static int volatile entangled_thread_counter=0;
  51. void avcodec_default_free_buffers(AVCodecContext *s);
  52. void *av_mallocz(unsigned int size)
  53. {
  54. void *ptr;
  55. ptr = av_malloc(size);
  56. if (!ptr)
  57. return NULL;
  58. memset(ptr, 0, size);
  59. return ptr;
  60. }
  61. char *av_strdup(const char *s)
  62. {
  63. char *ptr;
  64. int len;
  65. len = strlen(s) + 1;
  66. ptr = av_malloc(len);
  67. if (!ptr)
  68. return NULL;
  69. memcpy(ptr, s, len);
  70. return ptr;
  71. }
  72. /**
  73. * realloc which does nothing if the block is large enough
  74. */
  75. void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size)
  76. {
  77. if(min_size < *size)
  78. return ptr;
  79. *size= FFMAX(17*min_size/16 + 32, min_size);
  80. return av_realloc(ptr, *size);
  81. }
  82. static unsigned int last_static = 0;
  83. static unsigned int allocated_static = 0;
  84. static void** array_static = NULL;
  85. /**
  86. * allocation of static arrays - do not use for normal allocation.
  87. */
  88. void *av_mallocz_static(unsigned int size)
  89. {
  90. void *ptr = av_mallocz(size);
  91. if(ptr){
  92. array_static =av_fast_realloc(array_static, &allocated_static, sizeof(void*)*(last_static+1));
  93. if(!array_static)
  94. return NULL;
  95. array_static[last_static++] = ptr;
  96. }
  97. return ptr;
  98. }
  99. /**
  100. * same as above, but does realloc
  101. */
  102. void *av_realloc_static(void *ptr, unsigned int size)
  103. {
  104. int i;
  105. if(!ptr)
  106. return av_mallocz_static(size);
  107. /* Look for the old ptr */
  108. for(i = 0; i < last_static; i++) {
  109. if(array_static[i] == ptr) {
  110. array_static[i] = av_realloc(array_static[i], size);
  111. return array_static[i];
  112. }
  113. }
  114. return NULL;
  115. }
  116. /**
  117. * free all static arrays and reset pointers to 0.
  118. */
  119. void av_free_static(void)
  120. {
  121. while(last_static){
  122. av_freep(&array_static[--last_static]);
  123. }
  124. av_freep(&array_static);
  125. }
  126. /**
  127. * Call av_free_static automatically before it's too late
  128. */
  129. static void do_free() __attribute__ ((destructor));
  130. static void do_free()
  131. {
  132. av_free_static();
  133. }
  134. /**
  135. * Frees memory and sets the pointer to NULL.
  136. * @param arg pointer to the pointer which should be freed
  137. */
  138. void av_freep(void *arg)
  139. {
  140. void **ptr= (void**)arg;
  141. av_free(*ptr);
  142. *ptr = NULL;
  143. }
  144. /* encoder management */
  145. AVCodec *first_avcodec = NULL;
  146. void register_avcodec(AVCodec *format)
  147. {
  148. AVCodec **p;
  149. p = &first_avcodec;
  150. while (*p != NULL) p = &(*p)->next;
  151. *p = format;
  152. format->next = NULL;
  153. }
  154. void avcodec_set_dimensions(AVCodecContext *s, int width, int height){
  155. s->coded_width = width;
  156. s->coded_height= height;
  157. s->width = -((-width )>>s->lowres);
  158. s->height= -((-height)>>s->lowres);
  159. }
  160. typedef struct InternalBuffer{
  161. int last_pic_num;
  162. uint8_t *base[4];
  163. uint8_t *data[4];
  164. int linesize[4];
  165. }InternalBuffer;
  166. #define INTERNAL_BUFFER_SIZE 32
  167. #define ALIGN(x, a) (((x)+(a)-1)&~((a)-1))
  168. void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){
  169. int w_align= 1;
  170. int h_align= 1;
  171. switch(s->pix_fmt){
  172. case PIX_FMT_YUV420P:
  173. case PIX_FMT_YUV422:
  174. case PIX_FMT_UYVY422:
  175. case PIX_FMT_YUV422P:
  176. case PIX_FMT_YUV444P:
  177. case PIX_FMT_GRAY8:
  178. case PIX_FMT_YUVJ420P:
  179. case PIX_FMT_YUVJ422P:
  180. case PIX_FMT_YUVJ444P:
  181. w_align= 16; //FIXME check for non mpeg style codecs and use less alignment
  182. h_align= 16;
  183. break;
  184. case PIX_FMT_YUV411P:
  185. case PIX_FMT_UYVY411:
  186. w_align=32;
  187. h_align=8;
  188. break;
  189. case PIX_FMT_YUV410P:
  190. if(s->codec_id == CODEC_ID_SVQ1){
  191. w_align=64;
  192. h_align=64;
  193. }
  194. case PIX_FMT_RGB555:
  195. if(s->codec_id == CODEC_ID_RPZA){
  196. w_align=4;
  197. h_align=4;
  198. }
  199. case PIX_FMT_PAL8:
  200. if(s->codec_id == CODEC_ID_SMC){
  201. w_align=4;
  202. h_align=4;
  203. }
  204. break;
  205. case PIX_FMT_BGR24:
  206. if((s->codec_id == CODEC_ID_MSZH) || (s->codec_id == CODEC_ID_ZLIB)){
  207. w_align=4;
  208. h_align=4;
  209. }
  210. break;
  211. default:
  212. w_align= 1;
  213. h_align= 1;
  214. break;
  215. }
  216. *width = ALIGN(*width , w_align);
  217. *height= ALIGN(*height, h_align);
  218. }
  219. int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h){
  220. if((int)w>0 && (int)h>0 && (w+128)*(uint64_t)(h+128) < INT_MAX/4)
  221. return 0;
  222. av_log(av_log_ctx, AV_LOG_ERROR, "picture size invalid (%ux%u)\n", w, h);
  223. return -1;
  224. }
  225. int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
  226. int i;
  227. int w= s->width;
  228. int h= s->height;
  229. InternalBuffer *buf;
  230. int *picture_number;
  231. assert(pic->data[0]==NULL);
  232. assert(INTERNAL_BUFFER_SIZE > s->internal_buffer_count);
  233. if(avcodec_check_dimensions(s,w,h))
  234. return -1;
  235. if(s->internal_buffer==NULL){
  236. s->internal_buffer= av_mallocz(INTERNAL_BUFFER_SIZE*sizeof(InternalBuffer));
  237. }
  238. #if 0
  239. s->internal_buffer= av_fast_realloc(
  240. s->internal_buffer,
  241. &s->internal_buffer_size,
  242. sizeof(InternalBuffer)*FFMAX(99, s->internal_buffer_count+1)/*FIXME*/
  243. );
  244. #endif
  245. buf= &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
  246. picture_number= &(((InternalBuffer*)s->internal_buffer)[INTERNAL_BUFFER_SIZE-1]).last_pic_num; //FIXME ugly hack
  247. (*picture_number)++;
  248. if(buf->base[0]){
  249. pic->age= *picture_number - buf->last_pic_num;
  250. buf->last_pic_num= *picture_number;
  251. }else{
  252. int h_chroma_shift, v_chroma_shift;
  253. int pixel_size;
  254. avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
  255. switch(s->pix_fmt){
  256. case PIX_FMT_RGB555:
  257. case PIX_FMT_RGB565:
  258. case PIX_FMT_YUV422:
  259. case PIX_FMT_UYVY422:
  260. pixel_size=2;
  261. break;
  262. case PIX_FMT_RGB24:
  263. case PIX_FMT_BGR24:
  264. pixel_size=3;
  265. break;
  266. case PIX_FMT_RGBA32:
  267. pixel_size=4;
  268. break;
  269. default:
  270. pixel_size=1;
  271. }
  272. avcodec_align_dimensions(s, &w, &h);
  273. if(!(s->flags&CODEC_FLAG_EMU_EDGE)){
  274. w+= EDGE_WIDTH*2;
  275. h+= EDGE_WIDTH*2;
  276. }
  277. buf->last_pic_num= -256*256*256*64;
  278. for(i=0; i<3; i++){
  279. const int h_shift= i==0 ? 0 : h_chroma_shift;
  280. const int v_shift= i==0 ? 0 : v_chroma_shift;
  281. //FIXME next ensures that linesize= 2^x uvlinesize, thats needed because some MC code assumes it
  282. buf->linesize[i]= ALIGN(pixel_size*w>>h_shift, STRIDE_ALIGN<<(h_chroma_shift-h_shift));
  283. buf->base[i]= av_malloc((buf->linesize[i]*h>>v_shift)+16); //FIXME 16
  284. if(buf->base[i]==NULL) return -1;
  285. memset(buf->base[i], 128, buf->linesize[i]*h>>v_shift);
  286. if(s->flags&CODEC_FLAG_EMU_EDGE)
  287. buf->data[i] = buf->base[i];
  288. else
  289. buf->data[i] = buf->base[i] + ALIGN((buf->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift), STRIDE_ALIGN);
  290. }
  291. pic->age= 256*256*256*64;
  292. }
  293. pic->type= FF_BUFFER_TYPE_INTERNAL;
  294. for(i=0; i<4; i++){
  295. pic->base[i]= buf->base[i];
  296. pic->data[i]= buf->data[i];
  297. pic->linesize[i]= buf->linesize[i];
  298. }
  299. s->internal_buffer_count++;
  300. return 0;
  301. }
  302. void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
  303. int i;
  304. InternalBuffer *buf, *last, temp;
  305. assert(pic->type==FF_BUFFER_TYPE_INTERNAL);
  306. assert(s->internal_buffer_count);
  307. buf = NULL; /* avoids warning */
  308. for(i=0; i<s->internal_buffer_count; i++){ //just 3-5 checks so is not worth to optimize
  309. buf= &((InternalBuffer*)s->internal_buffer)[i];
  310. if(buf->data[0] == pic->data[0])
  311. break;
  312. }
  313. assert(i < s->internal_buffer_count);
  314. s->internal_buffer_count--;
  315. last = &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
  316. temp= *buf;
  317. *buf= *last;
  318. *last= temp;
  319. for(i=0; i<3; i++){
  320. pic->data[i]=NULL;
  321. // pic->base[i]=NULL;
  322. }
  323. //printf("R%X\n", pic->opaque);
  324. }
  325. int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){
  326. AVFrame temp_pic;
  327. int i;
  328. /* If no picture return a new buffer */
  329. if(pic->data[0] == NULL) {
  330. /* We will copy from buffer, so must be readable */
  331. pic->buffer_hints |= FF_BUFFER_HINTS_READABLE;
  332. return s->get_buffer(s, pic);
  333. }
  334. /* If internal buffer type return the same buffer */
  335. if(pic->type == FF_BUFFER_TYPE_INTERNAL)
  336. return 0;
  337. /*
  338. * Not internal type and reget_buffer not overridden, emulate cr buffer
  339. */
  340. temp_pic = *pic;
  341. for(i = 0; i < 4; i++)
  342. pic->data[i] = pic->base[i] = NULL;
  343. pic->opaque = NULL;
  344. /* Allocate new frame */
  345. if (s->get_buffer(s, pic))
  346. return -1;
  347. /* Copy image data from old buffer to new buffer */
  348. img_copy((AVPicture*)pic, (AVPicture*)&temp_pic, s->pix_fmt, s->width,
  349. s->height);
  350. s->release_buffer(s, &temp_pic); // Release old frame
  351. return 0;
  352. }
  353. int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count){
  354. int i;
  355. for(i=0; i<count; i++){
  356. int r= func(c, arg[i]);
  357. if(ret) ret[i]= r;
  358. }
  359. return 0;
  360. }
  361. enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt){
  362. return fmt[0];
  363. }
  364. static const char* context_to_name(void* ptr) {
  365. AVCodecContext *avc= ptr;
  366. if(avc && avc->codec && avc->codec->name)
  367. return avc->codec->name;
  368. else
  369. return "NULL";
  370. }
  371. #define OFFSET(x) (int)&((AVCodecContext*)0)->x
  372. #define DEFAULT 0 //should be NAN but it doesnt work as its not a constant in glibc as required by ANSI/ISO C
  373. //these names are too long to be readable
  374. #define V AV_OPT_FLAG_VIDEO_PARAM
  375. #define A AV_OPT_FLAG_AUDIO_PARAM
  376. #define S AV_OPT_FLAG_SUBTITLE_PARAM
  377. #define E AV_OPT_FLAG_ENCODING_PARAM
  378. #define D AV_OPT_FLAG_DECODING_PARAM
  379. static AVOption options[]={
  380. {"bit_rate", NULL, OFFSET(bit_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|A|E},
  381. {"bit_rate_tolerance", NULL, OFFSET(bit_rate_tolerance), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  382. {"flags", NULL, OFFSET(flags), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX, V|A|E|D, "flags"},
  383. {"MV4", "use four motion vector by macroblock (MPEG4)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_4MV, INT_MIN, INT_MAX, V|E, "flags"},
  384. {"OBMC", "use overlapped block motion compensation (h263+)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_OBMC, INT_MIN, INT_MAX, V|E, "flags"},
  385. {"QPEL", "use 1/4 pel motion compensation", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_QPEL, INT_MIN, INT_MAX, V|E, "flags"},
  386. {"LOOP", "use loop filter", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_LOOP_FILTER, INT_MIN, INT_MAX, V|E, "flags"},
  387. {"QSCALE", "use fixed qscale", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_QSCALE, INT_MIN, INT_MAX, 0, "flags"},
  388. {"GMC", "use GMC", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_GMC, INT_MIN, INT_MAX, V|E, "flags"},
  389. {"MV0", "always try a MB with MV=<0,0>", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_MV0, INT_MIN, INT_MAX, V|E, "flags"},
  390. {"PART", "use data partitioning", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PART, INT_MIN, INT_MAX, V|E, "flags"},
  391. {"INPUT_PRESERVED", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_INPUT_PRESERVED, INT_MIN, INT_MAX, 0, "flags"},
  392. {"PASS1", "use internal 2pass ratecontrol in first pass mode", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PASS1, INT_MIN, INT_MAX, 0, "flags"},
  393. {"PASS2", "use internal 2pass ratecontrol in second pass mode", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PASS2, INT_MIN, INT_MAX, 0, "flags"},
  394. {"EXTERN_HUFF", "use external huffman table (for mjpeg)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_EXTERN_HUFF, INT_MIN, INT_MAX, 0, "flags"},
  395. {"GRAY", "only decode/encode grayscale", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_GRAY, INT_MIN, INT_MAX, V|E|D, "flags"},
  396. {"EMU_EDGE", "don't draw edges", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_EMU_EDGE, INT_MIN, INT_MAX, 0, "flags"},
  397. {"PSNR", "error[?] variables will be set during encoding", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PSNR, INT_MIN, INT_MAX, V|E, "flags"},
  398. {"TRUNCATED", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_TRUNCATED, INT_MIN, INT_MAX, 0, "flags"},
  399. {"NAQ", "normalize adaptive quantization", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_NORMALIZE_AQP, INT_MIN, INT_MAX, V|E, "flags"},
  400. {"ILDCT", "use interlaced dct", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_INTERLACED_DCT, INT_MIN, INT_MAX, V|E, "flags"},
  401. {"LOW_DELAY", "force low delay", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_LOW_DELAY, INT_MIN, INT_MAX, V|D, "flags"},
  402. {"ALT", "enable alternate scantable (MPEG2/MPEG4)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_ALT_SCAN, INT_MIN, INT_MAX, V|E, "flags"},
  403. {"TRELL", "use trellis quantization", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_TRELLIS_QUANT, INT_MIN, INT_MAX, V|E, "flags"},
  404. {"GLOBAL_HEADER", "place global headers in extradata instead of every keyframe", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_GLOBAL_HEADER, INT_MIN, INT_MAX, 0, "flags"},
  405. {"BITEXACT", "use only bitexact stuff (except (i)dct)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_BITEXACT, INT_MIN, INT_MAX, A|V|S|D|E, "flags"},
  406. {"AIC", "H263 Advanced intra coding / MPEG4 AC prediction", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_AC_PRED, INT_MIN, INT_MAX, V|E, "flags"},
  407. {"UMV", "use unlimited motion vectors", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_H263P_UMV, INT_MIN, INT_MAX, V|E, "flags"},
  408. {"CBP", "use rate distortion optimization for cbp", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_CBP_RD, INT_MIN, INT_MAX, V|E, "flags"},
  409. {"QPRD", "use rate distortion optimization for qp selectioon", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_QP_RD, INT_MIN, INT_MAX, V|E, "flags"},
  410. {"AIV", "H263 Alternative inter vlc", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_H263P_AIV, INT_MIN, INT_MAX, V|E, "flags"},
  411. {"SLICE", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_H263P_SLICE_STRUCT, INT_MIN, INT_MAX, V|E, "flags"},
  412. {"ILME", "interlaced motion estimation", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_INTERLACED_ME, INT_MIN, INT_MAX, V|E, "flags"},
  413. {"SCAN_OFFSET", "will reserve space for SVCD scan offset user data", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_SVCD_SCAN_OFFSET, INT_MIN, INT_MAX, V|E, "flags"},
  414. {"CGOP", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_CLOSED_GOP, INT_MIN, INT_MAX, V|E, "flags"},
  415. {"FAST", "allow non spec compliant speedup tricks", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_FAST, INT_MIN, INT_MAX, V|E, "flags2"},
  416. {"SGOP", "strictly enforce GOP size", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_STRICT_GOP, INT_MIN, INT_MAX, V|E, "flags2"},
  417. {"NOOUT", "skip bitstream encoding", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_NO_OUTPUT, INT_MIN, INT_MAX, V|E, "flags2"},
  418. {"LOCAL_HEADER", "place global headers at every keyframe instead of in extradata", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_LOCAL_HEADER, INT_MIN, INT_MAX, V|E, "flags2"},
  419. {"sub_id", NULL, OFFSET(sub_id), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  420. {"me_method", NULL, OFFSET(me_method), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "me_method"},
  421. {"extradata_size", NULL, OFFSET(extradata_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  422. {"time_base", NULL, OFFSET(time_base), FF_OPT_TYPE_RATIONAL, DEFAULT, INT_MIN, INT_MAX},
  423. {"gop_size", NULL, OFFSET(gop_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  424. {"rate_emu", NULL, OFFSET(rate_emu), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  425. {"sample_rate", NULL, OFFSET(sample_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  426. {"channels", NULL, OFFSET(channels), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  427. {"frame_size", NULL, OFFSET(frame_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  428. {"frame_number", NULL, OFFSET(frame_number), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  429. {"real_pict_num", NULL, OFFSET(real_pict_num), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  430. {"delay", NULL, OFFSET(delay), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  431. {"qcompress", NULL, OFFSET(qcompress), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
  432. {"qblur", NULL, OFFSET(qblur), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
  433. {"qmin", NULL, OFFSET(qmin), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  434. {"qmax", NULL, OFFSET(qmax), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  435. {"max_qdiff", NULL, OFFSET(max_qdiff), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  436. {"max_b_frames", NULL, OFFSET(max_b_frames), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  437. {"b_quant_factor", NULL, OFFSET(b_quant_factor), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
  438. {"rc_strategy", NULL, OFFSET(rc_strategy), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  439. {"b_frame_strategy", NULL, OFFSET(b_frame_strategy), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  440. {"hurry_up", NULL, OFFSET(hurry_up), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D},
  441. {"rtp_mode", NULL, OFFSET(rtp_mode), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  442. {"rtp_payload_size", NULL, OFFSET(rtp_payload_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  443. {"mv_bits", NULL, OFFSET(mv_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  444. {"header_bits", NULL, OFFSET(header_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  445. {"i_tex_bits", NULL, OFFSET(i_tex_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  446. {"p_tex_bits", NULL, OFFSET(p_tex_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  447. {"i_count", NULL, OFFSET(i_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  448. {"p_count", NULL, OFFSET(p_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  449. {"skip_count", NULL, OFFSET(skip_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  450. {"misc_bits", NULL, OFFSET(misc_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  451. {"frame_bits", NULL, OFFSET(frame_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  452. {"codec_tag", NULL, OFFSET(codec_tag), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  453. {"bugs", NULL, OFFSET(workaround_bugs), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D, "bug"},
  454. {"AUTODETECT", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_AUTODETECT, INT_MIN, INT_MAX, V|D, "bug"},
  455. {"OLD_MSMPEG4", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_OLD_MSMPEG4, INT_MIN, INT_MAX, V|D, "bug"},
  456. {"XVID_ILACE", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_XVID_ILACE, INT_MIN, INT_MAX, V|D, "bug"},
  457. {"UMP4", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_UMP4, INT_MIN, INT_MAX, V|D, "bug"},
  458. {"NO_PADDING", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_NO_PADDING, INT_MIN, INT_MAX, V|D, "bug"},
  459. {"AMV", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_AMV, INT_MIN, INT_MAX, V|D, "bug"},
  460. {"AC_VLC", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_AC_VLC, INT_MIN, INT_MAX, V|D, "bug"},
  461. {"QPEL_CHROMA", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_QPEL_CHROMA, INT_MIN, INT_MAX, V|D, "bug"},
  462. {"STD_QPEL", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_STD_QPEL, INT_MIN, INT_MAX, V|D, "bug"},
  463. {"QPEL_CHROMA2", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_QPEL_CHROMA2, INT_MIN, INT_MAX, V|D, "bug"},
  464. {"DIRECT_BLOCKSIZE", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_DIRECT_BLOCKSIZE, INT_MIN, INT_MAX, V|D, "bug"},
  465. {"EDGE", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_EDGE, INT_MIN, INT_MAX, V|D, "bug"},
  466. {"HPEL_CHROMA", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_HPEL_CHROMA, INT_MIN, INT_MAX, V|D, "bug"},
  467. {"DC_CLIP", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_DC_CLIP, INT_MIN, INT_MAX, V|D, "bug"},
  468. {"MS", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_MS, INT_MIN, INT_MAX, V|D, "bug"},
  469. {"lelim", "single coefficient elimination threshold for luminance (negative values also consider DC coefficient)", OFFSET(luma_elim_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  470. {"celim", "single coefficient elimination threshold for chrominance (negative values also consider DC coefficient)", OFFSET(chroma_elim_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  471. {"strict", NULL, OFFSET(strict_std_compliance), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "strict"},
  472. {"VERY", NULL, 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_VERY_STRICT, INT_MIN, INT_MAX, V|E, "strict"},
  473. {"STRICT", NULL, 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_STRICT, INT_MIN, INT_MAX, V|E, "strict"},
  474. {"NORMAL", NULL, 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_NORMAL, INT_MIN, INT_MAX, V|E, "strict"},
  475. {"INOFFICIAL", NULL, 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_INOFFICIAL, INT_MIN, INT_MAX, V|E, "strict"},
  476. {"EXPERIMENTAL", NULL, 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_EXPERIMENTAL, INT_MIN, INT_MAX, V|E, "strict"},
  477. {"b_quant_offset", NULL, OFFSET(b_quant_offset), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
  478. {"error_resilience", NULL, OFFSET(error_resilience), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D, "er"},
  479. {"CAREFUL", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_CAREFUL, INT_MIN, INT_MAX, V|D, "er"},
  480. {"COMPLIANT", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_COMPLIANT, INT_MIN, INT_MAX, V|D, "er"},
  481. {"AGGRESSIVE", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_AGGRESSIVE, INT_MIN, INT_MAX, V|D, "er"},
  482. {"VERY_AGGRESSIVE", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_VERY_AGGRESSIVE, INT_MIN, INT_MAX, V|D, "er"},
  483. {"has_b_frames", NULL, OFFSET(has_b_frames), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  484. {"block_align", NULL, OFFSET(block_align), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  485. {"parse_only", NULL, OFFSET(parse_only), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  486. {"mpeg_quant", NULL, OFFSET(mpeg_quant), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  487. {"stats_out", NULL, OFFSET(stats_out), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX},
  488. {"stats_in", NULL, OFFSET(stats_in), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX},
  489. {"rc_qsquish", NULL, OFFSET(rc_qsquish), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
  490. {"rc_qmod_amp", NULL, OFFSET(rc_qmod_amp), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
  491. {"rc_qmod_freq", NULL, OFFSET(rc_qmod_freq), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  492. {"rc_override_count", NULL, OFFSET(rc_override_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  493. {"rc_eq", NULL, OFFSET(rc_eq), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX, V|E},
  494. {"rc_max_rate", NULL, OFFSET(rc_max_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  495. {"rc_min_rate", NULL, OFFSET(rc_min_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  496. {"rc_buffer_size", NULL, OFFSET(rc_buffer_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  497. {"rc_buf_aggressivity", NULL, OFFSET(rc_buffer_aggressivity), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
  498. {"i_quant_factor", NULL, OFFSET(i_quant_factor), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
  499. {"i_quant_offset", NULL, OFFSET(i_quant_offset), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
  500. {"rc_initial_cplx", NULL, OFFSET(rc_initial_cplx), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
  501. {"dct", NULL, OFFSET(dct_algo), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, V|E, "dct"},
  502. {"AUTO", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_AUTO, INT_MIN, INT_MAX, V|E, "dct"},
  503. {"FASTINT", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_FASTINT, INT_MIN, INT_MAX, V|E, "dct"},
  504. {"INT", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_INT, INT_MIN, INT_MAX, V|E, "dct"},
  505. {"MMX", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_MMX, INT_MIN, INT_MAX, V|E, "dct"},
  506. {"MLIB", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_MLIB, INT_MIN, INT_MAX, V|E, "dct"},
  507. {"ALTIVEC", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_ALTIVEC, INT_MIN, INT_MAX, V|E, "dct"},
  508. {"FAAN", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_FAAN, INT_MIN, INT_MAX, V|E, "dct"},
  509. {"lumi_mask", NULL, OFFSET(lumi_masking), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
  510. {"tcplx_mask", NULL, OFFSET(temporal_cplx_masking), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
  511. {"scplx_mask", NULL, OFFSET(spatial_cplx_masking), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
  512. {"p_mask", NULL, OFFSET(p_masking), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
  513. {"dark_mask", NULL, OFFSET(dark_masking), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
  514. {"unused", NULL, OFFSET(unused), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  515. {"idct", NULL, OFFSET(idct_algo), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, V|E|D, "idct"},
  516. {"AUTO", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_AUTO, INT_MIN, INT_MAX, V|E|D, "idct"},
  517. {"INT", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_INT, INT_MIN, INT_MAX, V|E|D, "idct"},
  518. {"SIMPLE", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLE, INT_MIN, INT_MAX, V|E|D, "idct"},
  519. {"SIMPLEMMX", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLEMMX, INT_MIN, INT_MAX, V|E|D, "idct"},
  520. {"LIBMPEG2MMX", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_LIBMPEG2MMX, INT_MIN, INT_MAX, V|E|D, "idct"},
  521. {"PS2", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_PS2, INT_MIN, INT_MAX, V|E|D, "idct"},
  522. {"MLIB", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_MLIB, INT_MIN, INT_MAX, V|E|D, "idct"},
  523. {"ARM", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_ARM, INT_MIN, INT_MAX, V|E|D, "idct"},
  524. {"ALTIVEC", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_ALTIVEC, INT_MIN, INT_MAX, V|E|D, "idct"},
  525. {"SH4", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SH4, INT_MIN, INT_MAX, V|E|D, "idct"},
  526. {"SIMPLEARM", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLEARM, INT_MIN, INT_MAX, V|E|D, "idct"},
  527. {"H264", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_H264, INT_MIN, INT_MAX, V|E|D, "idct"},
  528. {"VP3", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_VP3, INT_MIN, INT_MAX, V|E|D, "idct"},
  529. {"IPP", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_IPP, INT_MIN, INT_MAX, V|E|D, "idct"},
  530. {"XVIDMMX", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_XVIDMMX, INT_MIN, INT_MAX, V|E|D, "idct"},
  531. {"slice_count", NULL, OFFSET(slice_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  532. {"ec", NULL, OFFSET(error_concealment), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX, V|D, "ec"},
  533. {"GUESS_MVS", NULL, 0, FF_OPT_TYPE_CONST, FF_EC_GUESS_MVS, INT_MIN, INT_MAX, V|D, "ec"},
  534. {"DEBLOCK", NULL, 0, FF_OPT_TYPE_CONST, FF_EC_DEBLOCK, INT_MIN, INT_MAX, V|D, "ec"},
  535. {"bits_per_sample", NULL, OFFSET(bits_per_sample), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  536. {"pred", NULL, OFFSET(prediction_method), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "pred"},
  537. {"LEFT", NULL, 0, FF_OPT_TYPE_CONST, FF_PRED_LEFT, INT_MIN, INT_MAX, V|E, "pred"},
  538. {"PLANE", NULL, 0, FF_OPT_TYPE_CONST, FF_PRED_PLANE, INT_MIN, INT_MAX, V|E, "pred"},
  539. {"MEDIAN", NULL, 0, FF_OPT_TYPE_CONST, FF_PRED_MEDIAN, INT_MIN, INT_MAX, V|E, "pred"},
  540. {"aspect", NULL, OFFSET(sample_aspect_ratio), FF_OPT_TYPE_RATIONAL, DEFAULT, 0, 10, V|E},
  541. {"debug", "print specific debug info", OFFSET(debug), FF_OPT_TYPE_FLAGS, DEFAULT, 0, INT_MAX, V|A|S|E|D, "debug"},
  542. {"PICT", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_PICT_INFO, INT_MIN, INT_MAX, V|D, "debug"},
  543. {"RC", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_RC, INT_MIN, INT_MAX, V|E, "debug"},
  544. {"BITSTREAM", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_BITSTREAM, INT_MIN, INT_MAX, V|D, "debug"},
  545. {"MB_TYPE", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_MB_TYPE, INT_MIN, INT_MAX, V|D, "debug"},
  546. {"QP", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_QP, INT_MIN, INT_MAX, V|D, "debug"},
  547. {"MV", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_MV, INT_MIN, INT_MAX, V|D, "debug"},
  548. {"DCT_COEFF", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_DCT_COEFF, INT_MIN, INT_MAX, V|D, "debug"},
  549. {"SKIP", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_SKIP, INT_MIN, INT_MAX, V|D, "debug"},
  550. {"STARTCODE", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_STARTCODE, INT_MIN, INT_MAX, V|D, "debug"},
  551. {"PTS", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_PTS, INT_MIN, INT_MAX, V|D, "debug"},
  552. {"ER", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_ER, INT_MIN, INT_MAX, V|D, "debug"},
  553. {"MMCO", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_MMCO, INT_MIN, INT_MAX, V|D, "debug"},
  554. {"BUGS", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_BUGS, INT_MIN, INT_MAX, V|D, "debug"},
  555. {"VIS_QP", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_QP, INT_MIN, INT_MAX, V|D, "debug"},
  556. {"VIS_MB_TYPE", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MB_TYPE, INT_MIN, INT_MAX, V|D, "debug"},
  557. {"vismv", "visualize motion vectors", OFFSET(debug_mv), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, V|D, "debug_mv"},
  558. {"PF", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MV_P_FOR, INT_MIN, INT_MAX, V|D, "debug_mv"},
  559. {"BF", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MV_B_FOR, INT_MIN, INT_MAX, V|D, "debug_mv"},
  560. {"BB", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MV_B_BACK, INT_MIN, INT_MAX, V|D, "debug_mv"},
  561. {"mb_qmin", NULL, OFFSET(mb_qmin), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  562. {"mb_qmax", NULL, OFFSET(mb_qmax), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  563. {"cmp", "full pel ME compare function", OFFSET(me_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
  564. {"subcmp", "sub pel ME compare function", OFFSET(me_sub_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
  565. {"mbcmp", "macroblock compare function", OFFSET(mb_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
  566. {"ildctcmp", "interlaced dct compare function", OFFSET(ildct_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
  567. {"dia_size", NULL, OFFSET(dia_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  568. {"last_pred", NULL, OFFSET(last_predictor_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  569. {"preme", NULL, OFFSET(pre_me), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  570. {"precmp", "pre motion estimation compare function", OFFSET(me_pre_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
  571. {"SAD", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_SAD, INT_MIN, INT_MAX, V|E, "cmp_func"},
  572. {"SSE", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_SSE, INT_MIN, INT_MAX, V|E, "cmp_func"},
  573. {"SATD", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_SATD, INT_MIN, INT_MAX, V|E, "cmp_func"},
  574. {"DCT", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_DCT, INT_MIN, INT_MAX, V|E, "cmp_func"},
  575. {"PSNR", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_PSNR, INT_MIN, INT_MAX, V|E, "cmp_func"},
  576. {"BIT", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_BIT, INT_MIN, INT_MAX, V|E, "cmp_func"},
  577. {"RD", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_RD, INT_MIN, INT_MAX, V|E, "cmp_func"},
  578. {"ZERO", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_ZERO, INT_MIN, INT_MAX, V|E, "cmp_func"},
  579. {"VSAD", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_VSAD, INT_MIN, INT_MAX, V|E, "cmp_func"},
  580. {"VSSE", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_VSSE, INT_MIN, INT_MAX, V|E, "cmp_func"},
  581. {"NSSE", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_NSSE, INT_MIN, INT_MAX, V|E, "cmp_func"},
  582. {"W53", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_W53, INT_MIN, INT_MAX, V|E, "cmp_func"},
  583. {"W97", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_W97, INT_MIN, INT_MAX, V|E, "cmp_func"},
  584. {"DCTMAX", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_DCTMAX, INT_MIN, INT_MAX, V|E, "cmp_func"},
  585. {"CHROMA", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_CHROMA, INT_MIN, INT_MAX, V|E, "cmp_func"},
  586. {"pre_dia_size", NULL, OFFSET(pre_dia_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  587. {"subq", NULL, OFFSET(me_subpel_quality), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  588. {"dtg_active_format", NULL, OFFSET(dtg_active_format), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  589. {"me_range", NULL, OFFSET(me_range), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  590. {"ibias", NULL, OFFSET(intra_quant_bias), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  591. {"pbias", NULL, OFFSET(inter_quant_bias), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  592. {"color_table_id", NULL, OFFSET(color_table_id), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  593. {"internal_buffer_count", NULL, OFFSET(internal_buffer_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  594. {"global_quality", NULL, OFFSET(global_quality), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  595. {"coder", NULL, OFFSET(coder_type), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "coder"},
  596. {"VLC", NULL, 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_VLC, INT_MIN, INT_MAX, V|E, "coder"},
  597. {"AC", NULL, 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_AC, INT_MIN, INT_MAX, V|E, "coder"},
  598. {"context_model", NULL, OFFSET(context_model), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  599. {"slice_flags", NULL, OFFSET(slice_flags), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  600. {"xvmc_acceleration", NULL, OFFSET(xvmc_acceleration), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  601. {"mbd", NULL, OFFSET(mb_decision), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "mbd"},
  602. {"SIMPLE", NULL, 0, FF_OPT_TYPE_CONST, FF_MB_DECISION_SIMPLE, INT_MIN, INT_MAX, V|E, "mbd"},
  603. {"BITS", NULL, 0, FF_OPT_TYPE_CONST, FF_MB_DECISION_BITS, INT_MIN, INT_MAX, V|E, "mbd"},
  604. {"RD", NULL, 0, FF_OPT_TYPE_CONST, FF_MB_DECISION_RD, INT_MIN, INT_MAX, V|E, "mbd"},
  605. {"stream_codec_tag", NULL, OFFSET(stream_codec_tag), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  606. {"sc_threshold", NULL, OFFSET(scenechange_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  607. {"lmin", "min lagrange factor", OFFSET(lmin), FF_OPT_TYPE_INT, 2*FF_QP2LAMBDA, 0, INT_MAX, V|E},
  608. {"lmax", "max lagrange factor", OFFSET(lmax), FF_OPT_TYPE_INT, 31*FF_QP2LAMBDA, 0, INT_MAX, V|E},
  609. {"noise_reduction", NULL, OFFSET(noise_reduction), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  610. {"rc_init_occupancy", NULL, OFFSET(rc_initial_buffer_occupancy), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  611. {"inter_threshold", NULL, OFFSET(inter_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  612. {"flags2", NULL, OFFSET(flags2), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  613. {"error_rate", NULL, OFFSET(error_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  614. {"antialias", NULL, OFFSET(antialias_algo), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D, "aa"},
  615. {"AUTO", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_AUTO, INT_MIN, INT_MAX, V|D, "aa"},
  616. {"FASTINT", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_FASTINT, INT_MIN, INT_MAX, V|D, "aa"},
  617. {"INT", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_INT, INT_MIN, INT_MAX, V|D, "aa"},
  618. {"FLOAT", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_FLOAT, INT_MIN, INT_MAX, V|D, "aa"},
  619. {"qns", NULL, OFFSET(quantizer_noise_shaping), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  620. {"thread_count", NULL, OFFSET(thread_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E|D},
  621. {"me_threshold", "motion estimaton threshold", OFFSET(me_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  622. {"mb_threshold", NULL, OFFSET(mb_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  623. {"dc", NULL, OFFSET(intra_dc_precision), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  624. {"nsse_weight", NULL, OFFSET(nsse_weight), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  625. {"skip_top", NULL, OFFSET(skip_top), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D},
  626. {"skip_bottom", NULL, OFFSET(skip_bottom), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D},
  627. {"profile", NULL, OFFSET(profile), FF_OPT_TYPE_INT, FF_PROFILE_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "profile"},
  628. {"UNKNOWN", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "profile"},
  629. {"level", NULL, OFFSET(level), FF_OPT_TYPE_INT, FF_LEVEL_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "level"},
  630. {"UNKNOWN", NULL, 0, FF_OPT_TYPE_CONST, FF_LEVEL_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "level"},
  631. {"lowres", NULL, OFFSET(lowres), FF_OPT_TYPE_INT, 0, 0, INT_MAX, V|D},
  632. {"frame_skip_threshold", NULL, OFFSET(frame_skip_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  633. {"frame_skip_factor", NULL, OFFSET(frame_skip_factor), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  634. {"frame_skip_exp", NULL, OFFSET(frame_skip_exp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  635. {"skipcmp", "frame skip comapare function", OFFSET(frame_skip_cmp), FF_OPT_TYPE_INT, FF_CMP_DCTMAX, INT_MIN, INT_MAX, V|E, "cmp_func"},
  636. {"border_mask", NULL, OFFSET(border_masking), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
  637. {"mb_lmin", NULL, OFFSET(mb_lmin), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  638. {"mb_lmax", NULL, OFFSET(mb_lmax), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  639. {"me_penalty_compensation", NULL, OFFSET(me_penalty_compensation), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  640. {NULL},
  641. };
  642. #undef A
  643. #undef V
  644. static AVClass av_codec_context_class = { "AVCodecContext", context_to_name, options };
  645. void avcodec_get_context_defaults(AVCodecContext *s){
  646. memset(s, 0, sizeof(AVCodecContext));
  647. s->av_class= &av_codec_context_class;
  648. s->bit_rate= 800*1000;
  649. s->bit_rate_tolerance= s->bit_rate*10;
  650. s->qmin= 2;
  651. s->qmax= 31;
  652. s->mb_lmin= FF_QP2LAMBDA * 2;
  653. s->mb_lmax= FF_QP2LAMBDA * 31;
  654. s->rc_eq= "tex^qComp";
  655. s->qcompress= 0.5;
  656. s->max_qdiff= 3;
  657. s->b_quant_factor=1.25;
  658. s->b_quant_offset=1.25;
  659. s->i_quant_factor=-0.8;
  660. s->i_quant_offset=0.0;
  661. s->error_concealment= 3;
  662. s->error_resilience= 1;
  663. s->workaround_bugs= FF_BUG_AUTODETECT;
  664. s->time_base= (AVRational){0,1};
  665. s->gop_size= 50;
  666. s->me_method= ME_EPZS;
  667. s->get_buffer= avcodec_default_get_buffer;
  668. s->release_buffer= avcodec_default_release_buffer;
  669. s->get_format= avcodec_default_get_format;
  670. s->execute= avcodec_default_execute;
  671. s->thread_count=1;
  672. s->me_subpel_quality=8;
  673. s->lmin= FF_QP2LAMBDA * s->qmin;
  674. s->lmax= FF_QP2LAMBDA * s->qmax;
  675. s->sample_aspect_ratio= (AVRational){0,1};
  676. s->ildct_cmp= FF_CMP_VSAD;
  677. s->profile= FF_PROFILE_UNKNOWN;
  678. s->level= FF_LEVEL_UNKNOWN;
  679. s->me_penalty_compensation= 256;
  680. s->pix_fmt= PIX_FMT_NONE;
  681. s->frame_skip_cmp= FF_CMP_DCTMAX;
  682. s->intra_quant_bias= FF_DEFAULT_QUANT_BIAS;
  683. s->inter_quant_bias= FF_DEFAULT_QUANT_BIAS;
  684. s->palctrl = NULL;
  685. s->reget_buffer= avcodec_default_reget_buffer;
  686. }
  687. /**
  688. * allocates a AVCodecContext and set it to defaults.
  689. * this can be deallocated by simply calling free()
  690. */
  691. AVCodecContext *avcodec_alloc_context(void){
  692. AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));
  693. if(avctx==NULL) return NULL;
  694. avcodec_get_context_defaults(avctx);
  695. return avctx;
  696. }
  697. void avcodec_get_frame_defaults(AVFrame *pic){
  698. memset(pic, 0, sizeof(AVFrame));
  699. pic->pts= AV_NOPTS_VALUE;
  700. pic->key_frame= 1;
  701. }
  702. /**
  703. * allocates a AVPFrame and set it to defaults.
  704. * this can be deallocated by simply calling free()
  705. */
  706. AVFrame *avcodec_alloc_frame(void){
  707. AVFrame *pic= av_malloc(sizeof(AVFrame));
  708. if(pic==NULL) return NULL;
  709. avcodec_get_frame_defaults(pic);
  710. return pic;
  711. }
  712. int avcodec_open(AVCodecContext *avctx, AVCodec *codec)
  713. {
  714. int ret= -1;
  715. entangled_thread_counter++;
  716. if(entangled_thread_counter != 1){
  717. av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
  718. goto end;
  719. }
  720. if(avctx->codec)
  721. goto end;
  722. avctx->codec = codec;
  723. avctx->codec_id = codec->id;
  724. avctx->frame_number = 0;
  725. if (codec->priv_data_size > 0) {
  726. avctx->priv_data = av_mallocz(codec->priv_data_size);
  727. if (!avctx->priv_data)
  728. goto end;
  729. } else {
  730. avctx->priv_data = NULL;
  731. }
  732. if(avctx->coded_width && avctx->coded_height)
  733. avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
  734. else if(avctx->width && avctx->height)
  735. avcodec_set_dimensions(avctx, avctx->width, avctx->height);
  736. if((avctx->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height)){
  737. av_freep(&avctx->priv_data);
  738. goto end;
  739. }
  740. ret = avctx->codec->init(avctx);
  741. if (ret < 0) {
  742. av_freep(&avctx->priv_data);
  743. goto end;
  744. }
  745. ret=0;
  746. end:
  747. entangled_thread_counter--;
  748. return ret;
  749. }
  750. int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  751. const short *samples)
  752. {
  753. if(buf_size < FF_MIN_BUFFER_SIZE && 0){
  754. av_log(avctx, AV_LOG_ERROR, "buffer smaller then minimum size\n");
  755. return -1;
  756. }
  757. if((avctx->codec->capabilities & CODEC_CAP_DELAY) || samples){
  758. int ret = avctx->codec->encode(avctx, buf, buf_size, (void *)samples);
  759. avctx->frame_number++;
  760. return ret;
  761. }else
  762. return 0;
  763. }
  764. int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  765. const AVFrame *pict)
  766. {
  767. if(buf_size < FF_MIN_BUFFER_SIZE){
  768. av_log(avctx, AV_LOG_ERROR, "buffer smaller then minimum size\n");
  769. return -1;
  770. }
  771. if(avcodec_check_dimensions(avctx,avctx->width,avctx->height))
  772. return -1;
  773. if((avctx->codec->capabilities & CODEC_CAP_DELAY) || pict){
  774. int ret = avctx->codec->encode(avctx, buf, buf_size, (void *)pict);
  775. avctx->frame_number++;
  776. emms_c(); //needed to avoid an emms_c() call before every return;
  777. return ret;
  778. }else
  779. return 0;
  780. }
  781. int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  782. const AVSubtitle *sub)
  783. {
  784. int ret;
  785. ret = avctx->codec->encode(avctx, buf, buf_size, (void *)sub);
  786. avctx->frame_number++;
  787. return ret;
  788. }
  789. /**
  790. * decode a frame.
  791. * @param buf bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE larger then the actual read bytes
  792. * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end
  793. * @param buf_size the size of the buffer in bytes
  794. * @param got_picture_ptr zero if no frame could be decompressed, Otherwise, it is non zero
  795. * @return -1 if error, otherwise return the number of
  796. * bytes used.
  797. */
  798. int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
  799. int *got_picture_ptr,
  800. uint8_t *buf, int buf_size)
  801. {
  802. int ret;
  803. *got_picture_ptr= 0;
  804. if((avctx->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height))
  805. return -1;
  806. if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){
  807. ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
  808. buf, buf_size);
  809. emms_c(); //needed to avoid an emms_c() call before every return;
  810. if (*got_picture_ptr)
  811. avctx->frame_number++;
  812. }else
  813. ret= 0;
  814. return ret;
  815. }
  816. /* decode an audio frame. return -1 if error, otherwise return the
  817. *number of bytes used. If no frame could be decompressed,
  818. *frame_size_ptr is zero. Otherwise, it is the decompressed frame
  819. *size in BYTES. */
  820. int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples,
  821. int *frame_size_ptr,
  822. uint8_t *buf, int buf_size)
  823. {
  824. int ret;
  825. *frame_size_ptr= 0;
  826. if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){
  827. ret = avctx->codec->decode(avctx, samples, frame_size_ptr,
  828. buf, buf_size);
  829. avctx->frame_number++;
  830. }else
  831. ret= 0;
  832. return ret;
  833. }
  834. /* decode a subtitle message. return -1 if error, otherwise return the
  835. *number of bytes used. If no subtitle could be decompressed,
  836. *got_sub_ptr is zero. Otherwise, the subtitle is stored in *sub. */
  837. int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub,
  838. int *got_sub_ptr,
  839. const uint8_t *buf, int buf_size)
  840. {
  841. int ret;
  842. *got_sub_ptr = 0;
  843. ret = avctx->codec->decode(avctx, sub, got_sub_ptr,
  844. (uint8_t *)buf, buf_size);
  845. if (*got_sub_ptr)
  846. avctx->frame_number++;
  847. return ret;
  848. }
  849. int avcodec_close(AVCodecContext *avctx)
  850. {
  851. entangled_thread_counter++;
  852. if(entangled_thread_counter != 1){
  853. av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
  854. entangled_thread_counter--;
  855. return -1;
  856. }
  857. if (avctx->codec->close)
  858. avctx->codec->close(avctx);
  859. avcodec_default_free_buffers(avctx);
  860. av_freep(&avctx->priv_data);
  861. avctx->codec = NULL;
  862. entangled_thread_counter--;
  863. return 0;
  864. }
  865. AVCodec *avcodec_find_encoder(enum CodecID id)
  866. {
  867. AVCodec *p;
  868. p = first_avcodec;
  869. while (p) {
  870. if (p->encode != NULL && p->id == id)
  871. return p;
  872. p = p->next;
  873. }
  874. return NULL;
  875. }
  876. AVCodec *avcodec_find_encoder_by_name(const char *name)
  877. {
  878. AVCodec *p;
  879. p = first_avcodec;
  880. while (p) {
  881. if (p->encode != NULL && strcmp(name,p->name) == 0)
  882. return p;
  883. p = p->next;
  884. }
  885. return NULL;
  886. }
  887. AVCodec *avcodec_find_decoder(enum CodecID id)
  888. {
  889. AVCodec *p;
  890. p = first_avcodec;
  891. while (p) {
  892. if (p->decode != NULL && p->id == id)
  893. return p;
  894. p = p->next;
  895. }
  896. return NULL;
  897. }
  898. AVCodec *avcodec_find_decoder_by_name(const char *name)
  899. {
  900. AVCodec *p;
  901. p = first_avcodec;
  902. while (p) {
  903. if (p->decode != NULL && strcmp(name,p->name) == 0)
  904. return p;
  905. p = p->next;
  906. }
  907. return NULL;
  908. }
  909. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
  910. {
  911. const char *codec_name;
  912. AVCodec *p;
  913. char buf1[32];
  914. char channels_str[100];
  915. int bitrate;
  916. if (encode)
  917. p = avcodec_find_encoder(enc->codec_id);
  918. else
  919. p = avcodec_find_decoder(enc->codec_id);
  920. if (p) {
  921. codec_name = p->name;
  922. if (!encode && enc->codec_id == CODEC_ID_MP3) {
  923. if (enc->sub_id == 2)
  924. codec_name = "mp2";
  925. else if (enc->sub_id == 1)
  926. codec_name = "mp1";
  927. }
  928. } else if (enc->codec_id == CODEC_ID_MPEG2TS) {
  929. /* fake mpeg2 transport stream codec (currently not
  930. registered) */
  931. codec_name = "mpeg2ts";
  932. } else if (enc->codec_name[0] != '\0') {
  933. codec_name = enc->codec_name;
  934. } else {
  935. /* output avi tags */
  936. if( isprint(enc->codec_tag&0xFF) && isprint((enc->codec_tag>>8)&0xFF)
  937. && isprint((enc->codec_tag>>16)&0xFF) && isprint((enc->codec_tag>>24)&0xFF)){
  938. snprintf(buf1, sizeof(buf1), "%c%c%c%c / 0x%04X",
  939. enc->codec_tag & 0xff,
  940. (enc->codec_tag >> 8) & 0xff,
  941. (enc->codec_tag >> 16) & 0xff,
  942. (enc->codec_tag >> 24) & 0xff,
  943. enc->codec_tag);
  944. } else {
  945. snprintf(buf1, sizeof(buf1), "0x%04x", enc->codec_tag);
  946. }
  947. codec_name = buf1;
  948. }
  949. switch(enc->codec_type) {
  950. case CODEC_TYPE_VIDEO:
  951. snprintf(buf, buf_size,
  952. "Video: %s%s",
  953. codec_name, enc->mb_decision ? " (hq)" : "");
  954. if (enc->pix_fmt != PIX_FMT_NONE) {
  955. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  956. ", %s",
  957. avcodec_get_pix_fmt_name(enc->pix_fmt));
  958. }
  959. if (enc->width) {
  960. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  961. ", %dx%d, %0.2f fps",
  962. enc->width, enc->height,
  963. 1/av_q2d(enc->time_base));
  964. }
  965. if (encode) {
  966. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  967. ", q=%d-%d", enc->qmin, enc->qmax);
  968. }
  969. bitrate = enc->bit_rate;
  970. break;
  971. case CODEC_TYPE_AUDIO:
  972. snprintf(buf, buf_size,
  973. "Audio: %s",
  974. codec_name);
  975. switch (enc->channels) {
  976. case 1:
  977. strcpy(channels_str, "mono");
  978. break;
  979. case 2:
  980. strcpy(channels_str, "stereo");
  981. break;
  982. case 6:
  983. strcpy(channels_str, "5:1");
  984. break;
  985. default:
  986. snprintf(channels_str, sizeof(channels_str), "%d channels", enc->channels);
  987. break;
  988. }
  989. if (enc->sample_rate) {
  990. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  991. ", %d Hz, %s",
  992. enc->sample_rate,
  993. channels_str);
  994. }
  995. /* for PCM codecs, compute bitrate directly */
  996. switch(enc->codec_id) {
  997. case CODEC_ID_PCM_S32LE:
  998. case CODEC_ID_PCM_S32BE:
  999. case CODEC_ID_PCM_U32LE:
  1000. case CODEC_ID_PCM_U32BE:
  1001. bitrate = enc->sample_rate * enc->channels * 32;
  1002. break;
  1003. case CODEC_ID_PCM_S24LE:
  1004. case CODEC_ID_PCM_S24BE:
  1005. case CODEC_ID_PCM_U24LE:
  1006. case CODEC_ID_PCM_U24BE:
  1007. case CODEC_ID_PCM_S24DAUD:
  1008. bitrate = enc->sample_rate * enc->channels * 24;
  1009. break;
  1010. case CODEC_ID_PCM_S16LE:
  1011. case CODEC_ID_PCM_S16BE:
  1012. case CODEC_ID_PCM_U16LE:
  1013. case CODEC_ID_PCM_U16BE:
  1014. bitrate = enc->sample_rate * enc->channels * 16;
  1015. break;
  1016. case CODEC_ID_PCM_S8:
  1017. case CODEC_ID_PCM_U8:
  1018. case CODEC_ID_PCM_ALAW:
  1019. case CODEC_ID_PCM_MULAW:
  1020. bitrate = enc->sample_rate * enc->channels * 8;
  1021. break;
  1022. default:
  1023. bitrate = enc->bit_rate;
  1024. break;
  1025. }
  1026. break;
  1027. case CODEC_TYPE_DATA:
  1028. snprintf(buf, buf_size, "Data: %s", codec_name);
  1029. bitrate = enc->bit_rate;
  1030. break;
  1031. case CODEC_TYPE_SUBTITLE:
  1032. snprintf(buf, buf_size, "Subtitle: %s", codec_name);
  1033. bitrate = enc->bit_rate;
  1034. break;
  1035. default:
  1036. snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type);
  1037. return;
  1038. }
  1039. if (encode) {
  1040. if (enc->flags & CODEC_FLAG_PASS1)
  1041. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  1042. ", pass 1");
  1043. if (enc->flags & CODEC_FLAG_PASS2)
  1044. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  1045. ", pass 2");
  1046. }
  1047. if (bitrate != 0) {
  1048. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  1049. ", %d kb/s", bitrate / 1000);
  1050. }
  1051. }
  1052. unsigned avcodec_version( void )
  1053. {
  1054. return LIBAVCODEC_VERSION_INT;
  1055. }
  1056. unsigned avcodec_build( void )
  1057. {
  1058. return LIBAVCODEC_BUILD;
  1059. }
  1060. /* must be called before any other functions */
  1061. void avcodec_init(void)
  1062. {
  1063. static int inited = 0;
  1064. if (inited != 0)
  1065. return;
  1066. inited = 1;
  1067. dsputil_static_init();
  1068. }
  1069. /**
  1070. * Flush buffers, should be called when seeking or when swicthing to a different stream.
  1071. */
  1072. void avcodec_flush_buffers(AVCodecContext *avctx)
  1073. {
  1074. if(avctx->codec->flush)
  1075. avctx->codec->flush(avctx);
  1076. }
  1077. void avcodec_default_free_buffers(AVCodecContext *s){
  1078. int i, j;
  1079. if(s->internal_buffer==NULL) return;
  1080. for(i=0; i<INTERNAL_BUFFER_SIZE; i++){
  1081. InternalBuffer *buf= &((InternalBuffer*)s->internal_buffer)[i];
  1082. for(j=0; j<4; j++){
  1083. av_freep(&buf->base[j]);
  1084. buf->data[j]= NULL;
  1085. }
  1086. }
  1087. av_freep(&s->internal_buffer);
  1088. s->internal_buffer_count=0;
  1089. }
  1090. char av_get_pict_type_char(int pict_type){
  1091. switch(pict_type){
  1092. case I_TYPE: return 'I';
  1093. case P_TYPE: return 'P';
  1094. case B_TYPE: return 'B';
  1095. case S_TYPE: return 'S';
  1096. case SI_TYPE:return 'i';
  1097. case SP_TYPE:return 'p';
  1098. default: return '?';
  1099. }
  1100. }
  1101. /* av_log API */
  1102. static int av_log_level = AV_LOG_INFO;
  1103. static void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
  1104. {
  1105. static int print_prefix=1;
  1106. AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
  1107. if(level>av_log_level)
  1108. return;
  1109. #undef fprintf
  1110. if(print_prefix && avc) {
  1111. fprintf(stderr, "[%s @ %p]", avc->item_name(ptr), avc);
  1112. }
  1113. #define fprintf please_use_av_log
  1114. print_prefix= strstr(fmt, "\n") != NULL;
  1115. vfprintf(stderr, fmt, vl);
  1116. }
  1117. static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback;
  1118. void av_log(void* avcl, int level, const char *fmt, ...)
  1119. {
  1120. va_list vl;
  1121. va_start(vl, fmt);
  1122. av_vlog(avcl, level, fmt, vl);
  1123. va_end(vl);
  1124. }
  1125. void av_vlog(void* avcl, int level, const char *fmt, va_list vl)
  1126. {
  1127. av_log_callback(avcl, level, fmt, vl);
  1128. }
  1129. int av_log_get_level(void)
  1130. {
  1131. return av_log_level;
  1132. }
  1133. void av_log_set_level(int level)
  1134. {
  1135. av_log_level = level;
  1136. }
  1137. void av_log_set_callback(void (*callback)(void*, int, const char*, va_list))
  1138. {
  1139. av_log_callback = callback;
  1140. }
  1141. #if !defined(HAVE_THREADS)
  1142. int avcodec_thread_init(AVCodecContext *s, int thread_count){
  1143. return -1;
  1144. }
  1145. #endif
  1146. unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
  1147. {
  1148. unsigned int n = 0;
  1149. while(v >= 0xff) {
  1150. *s++ = 0xff;
  1151. v -= 0xff;
  1152. n++;
  1153. }
  1154. *s = v;
  1155. n++;
  1156. return n;
  1157. }