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.

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