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.

1307 lines
54KB

  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, size[3];
  255. AVPicture picture;
  256. avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
  257. avcodec_align_dimensions(s, &w, &h);
  258. if(!(s->flags&CODEC_FLAG_EMU_EDGE)){
  259. w+= EDGE_WIDTH*2;
  260. h+= EDGE_WIDTH*2;
  261. }
  262. avpicture_fill(&picture, NULL, s->pix_fmt, w, h);
  263. pixel_size= picture.linesize[0]*8 / w;
  264. //av_log(NULL, AV_LOG_ERROR, "%d %d %d %d\n", (int)picture.data[1], w, h, s->pix_fmt);
  265. assert(pixel_size>=1);
  266. //FIXME next ensures that linesize= 2^x uvlinesize, thats needed because some MC code assumes it
  267. if(pixel_size == 3*8)
  268. w= ALIGN(w, STRIDE_ALIGN<<h_chroma_shift);
  269. else
  270. w= ALIGN(pixel_size*w, STRIDE_ALIGN<<(h_chroma_shift+3)) / pixel_size;
  271. size[1] = avpicture_fill(&picture, NULL, s->pix_fmt, w, h);
  272. size[0] = picture.linesize[0] * h;
  273. size[1] -= size[0];
  274. if(picture.data[2])
  275. size[1]= size[2]= size[1]/2;
  276. else
  277. size[2]= 0;
  278. buf->last_pic_num= -256*256*256*64;
  279. memset(buf->base, 0, sizeof(buf->base));
  280. memset(buf->data, 0, sizeof(buf->data));
  281. for(i=0; i<3 && size[i]; i++){
  282. const int h_shift= i==0 ? 0 : h_chroma_shift;
  283. const int v_shift= i==0 ? 0 : v_chroma_shift;
  284. buf->linesize[i]= picture.linesize[i];
  285. buf->base[i]= av_malloc(size[i]+16); //FIXME 16
  286. if(buf->base[i]==NULL) return -1;
  287. memset(buf->base[i], 128, size[i]);
  288. // no edge if EDEG EMU or not planar YUV, we check for PAL8 redundantly to protect against a exploitable bug regression ...
  289. if((s->flags&CODEC_FLAG_EMU_EDGE) || (s->pix_fmt == PIX_FMT_PAL8) || !size[2])
  290. buf->data[i] = buf->base[i];
  291. else
  292. buf->data[i] = buf->base[i] + ALIGN((buf->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift), STRIDE_ALIGN);
  293. }
  294. pic->age= 256*256*256*64;
  295. }
  296. pic->type= FF_BUFFER_TYPE_INTERNAL;
  297. for(i=0; i<4; i++){
  298. pic->base[i]= buf->base[i];
  299. pic->data[i]= buf->data[i];
  300. pic->linesize[i]= buf->linesize[i];
  301. }
  302. s->internal_buffer_count++;
  303. return 0;
  304. }
  305. void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
  306. int i;
  307. InternalBuffer *buf, *last, temp;
  308. assert(pic->type==FF_BUFFER_TYPE_INTERNAL);
  309. assert(s->internal_buffer_count);
  310. buf = NULL; /* avoids warning */
  311. for(i=0; i<s->internal_buffer_count; i++){ //just 3-5 checks so is not worth to optimize
  312. buf= &((InternalBuffer*)s->internal_buffer)[i];
  313. if(buf->data[0] == pic->data[0])
  314. break;
  315. }
  316. assert(i < s->internal_buffer_count);
  317. s->internal_buffer_count--;
  318. last = &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
  319. temp= *buf;
  320. *buf= *last;
  321. *last= temp;
  322. for(i=0; i<3; i++){
  323. pic->data[i]=NULL;
  324. // pic->base[i]=NULL;
  325. }
  326. //printf("R%X\n", pic->opaque);
  327. }
  328. int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){
  329. AVFrame temp_pic;
  330. int i;
  331. /* If no picture return a new buffer */
  332. if(pic->data[0] == NULL) {
  333. /* We will copy from buffer, so must be readable */
  334. pic->buffer_hints |= FF_BUFFER_HINTS_READABLE;
  335. return s->get_buffer(s, pic);
  336. }
  337. /* If internal buffer type return the same buffer */
  338. if(pic->type == FF_BUFFER_TYPE_INTERNAL)
  339. return 0;
  340. /*
  341. * Not internal type and reget_buffer not overridden, emulate cr buffer
  342. */
  343. temp_pic = *pic;
  344. for(i = 0; i < 4; i++)
  345. pic->data[i] = pic->base[i] = NULL;
  346. pic->opaque = NULL;
  347. /* Allocate new frame */
  348. if (s->get_buffer(s, pic))
  349. return -1;
  350. /* Copy image data from old buffer to new buffer */
  351. img_copy((AVPicture*)pic, (AVPicture*)&temp_pic, s->pix_fmt, s->width,
  352. s->height);
  353. s->release_buffer(s, &temp_pic); // Release old frame
  354. return 0;
  355. }
  356. int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count){
  357. int i;
  358. for(i=0; i<count; i++){
  359. int r= func(c, arg[i]);
  360. if(ret) ret[i]= r;
  361. }
  362. return 0;
  363. }
  364. enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt){
  365. return fmt[0];
  366. }
  367. static const char* context_to_name(void* ptr) {
  368. AVCodecContext *avc= ptr;
  369. if(avc && avc->codec && avc->codec->name)
  370. return avc->codec->name;
  371. else
  372. return "NULL";
  373. }
  374. #define OFFSET(x) (int)&((AVCodecContext*)0)->x
  375. #define DEFAULT 0 //should be NAN but it doesnt work as its not a constant in glibc as required by ANSI/ISO C
  376. //these names are too long to be readable
  377. #define V AV_OPT_FLAG_VIDEO_PARAM
  378. #define A AV_OPT_FLAG_AUDIO_PARAM
  379. #define S AV_OPT_FLAG_SUBTITLE_PARAM
  380. #define E AV_OPT_FLAG_ENCODING_PARAM
  381. #define D AV_OPT_FLAG_DECODING_PARAM
  382. static AVOption options[]={
  383. {"bit_rate", NULL, OFFSET(bit_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|A|E},
  384. {"bit_rate_tolerance", NULL, OFFSET(bit_rate_tolerance), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  385. {"flags", NULL, OFFSET(flags), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX, V|A|E|D, "flags"},
  386. {"mv4", "use four motion vector by macroblock (mpeg4)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_4MV, INT_MIN, INT_MAX, V|E, "flags"},
  387. {"obmc", "use overlapped block motion compensation (h263+)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_OBMC, INT_MIN, INT_MAX, V|E, "flags"},
  388. {"qpel", "use 1/4 pel motion compensation", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_QPEL, INT_MIN, INT_MAX, V|E, "flags"},
  389. {"loop", "use loop filter", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_LOOP_FILTER, INT_MIN, INT_MAX, V|E, "flags"},
  390. {"qscale", "use fixed qscale", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_QSCALE, INT_MIN, INT_MAX, 0, "flags"},
  391. {"gmc", "use gmc", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_GMC, INT_MIN, INT_MAX, V|E, "flags"},
  392. {"mv0", "always try a mb with mv=<0,0>", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_MV0, INT_MIN, INT_MAX, V|E, "flags"},
  393. {"part", "use data partitioning", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PART, INT_MIN, INT_MAX, V|E, "flags"},
  394. {"input_preserved", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_INPUT_PRESERVED, INT_MIN, INT_MAX, 0, "flags"},
  395. {"pass1", "use internal 2pass ratecontrol in first pass mode", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PASS1, INT_MIN, INT_MAX, 0, "flags"},
  396. {"pass2", "use internal 2pass ratecontrol in second pass mode", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PASS2, INT_MIN, INT_MAX, 0, "flags"},
  397. {"extern_huff", "use external huffman table (for mjpeg)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_EXTERN_HUFF, INT_MIN, INT_MAX, 0, "flags"},
  398. {"gray", "only decode/encode grayscale", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_GRAY, INT_MIN, INT_MAX, V|E|D, "flags"},
  399. {"emu_edge", "don't draw edges", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_EMU_EDGE, INT_MIN, INT_MAX, 0, "flags"},
  400. {"psnr", "error[?] variables will be set during encoding", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_PSNR, INT_MIN, INT_MAX, V|E, "flags"},
  401. {"truncated", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_TRUNCATED, INT_MIN, INT_MAX, 0, "flags"},
  402. {"naq", "normalize adaptive quantization", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_NORMALIZE_AQP, INT_MIN, INT_MAX, V|E, "flags"},
  403. {"ildct", "use interlaced dct", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_INTERLACED_DCT, INT_MIN, INT_MAX, V|E, "flags"},
  404. {"low_delay", "force low delay", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_LOW_DELAY, INT_MIN, INT_MAX, V|D, "flags"},
  405. {"alt", "enable alternate scantable (mpeg2/mpeg4)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_ALT_SCAN, INT_MIN, INT_MAX, V|E, "flags"},
  406. {"trell", "use trellis quantization", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_TRELLIS_QUANT, INT_MIN, INT_MAX, V|E, "flags"},
  407. {"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"},
  408. {"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"},
  409. {"aic", "h263 advanced intra coding / mpeg4 ac prediction", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_AC_PRED, INT_MIN, INT_MAX, V|E, "flags"},
  410. {"umv", "use unlimited motion vectors", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_H263P_UMV, INT_MIN, INT_MAX, V|E, "flags"},
  411. {"cbp", "use rate distortion optimization for cbp", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_CBP_RD, INT_MIN, INT_MAX, V|E, "flags"},
  412. {"qprd", "use rate distortion optimization for qp selection", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_QP_RD, INT_MIN, INT_MAX, V|E, "flags"},
  413. {"aiv", "h263 alternative inter vlc", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_H263P_AIV, INT_MIN, INT_MAX, V|E, "flags"},
  414. {"slice", NULL, 0, FF_OPT_TYPE_CONST, CODEC_FLAG_H263P_SLICE_STRUCT, INT_MIN, INT_MAX, V|E, "flags"},
  415. {"ilme", "interlaced motion estimation", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_INTERLACED_ME, INT_MIN, INT_MAX, V|E, "flags"},
  416. {"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"},
  417. {"cgop", "closed gop", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_CLOSED_GOP, INT_MIN, INT_MAX, V|E, "flags"},
  418. {"fast", "allow non spec compliant speedup tricks", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_FAST, INT_MIN, INT_MAX, V|E, "flags2"},
  419. {"sgop", "strictly enforce gop size", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_STRICT_GOP, INT_MIN, INT_MAX, V|E, "flags2"},
  420. {"noout", "skip bitstream encoding", 0, FF_OPT_TYPE_CONST, CODEC_FLAG2_NO_OUTPUT, INT_MIN, INT_MAX, V|E, "flags2"},
  421. {"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"},
  422. {"sub_id", NULL, OFFSET(sub_id), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  423. {"me_method", NULL, OFFSET(me_method), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "me_method"},
  424. {"extradata_size", NULL, OFFSET(extradata_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  425. {"time_base", NULL, OFFSET(time_base), FF_OPT_TYPE_RATIONAL, DEFAULT, INT_MIN, INT_MAX},
  426. {"gop_size", NULL, OFFSET(gop_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  427. {"rate_emu", NULL, OFFSET(rate_emu), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  428. {"sample_rate", NULL, OFFSET(sample_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  429. {"channels", NULL, OFFSET(channels), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  430. {"frame_size", NULL, OFFSET(frame_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  431. {"frame_number", NULL, OFFSET(frame_number), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  432. {"real_pict_num", NULL, OFFSET(real_pict_num), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  433. {"delay", NULL, OFFSET(delay), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  434. {"qcompress", NULL, OFFSET(qcompress), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
  435. {"qblur", NULL, OFFSET(qblur), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
  436. {"qmin", NULL, OFFSET(qmin), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  437. {"qmax", NULL, OFFSET(qmax), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  438. {"max_qdiff", NULL, OFFSET(max_qdiff), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  439. {"max_b_frames", NULL, OFFSET(max_b_frames), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  440. {"b_quant_factor", NULL, OFFSET(b_quant_factor), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
  441. {"rc_strategy", NULL, OFFSET(rc_strategy), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  442. {"b_strategy", NULL, OFFSET(b_frame_strategy), FF_OPT_TYPE_INT, 0, INT_MIN, INT_MAX, V|E},
  443. {"hurry_up", NULL, OFFSET(hurry_up), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D},
  444. {"rtp_mode", NULL, OFFSET(rtp_mode), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  445. {"rtp_payload_size", NULL, OFFSET(rtp_payload_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  446. {"mv_bits", NULL, OFFSET(mv_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  447. {"header_bits", NULL, OFFSET(header_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  448. {"i_tex_bits", NULL, OFFSET(i_tex_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  449. {"p_tex_bits", NULL, OFFSET(p_tex_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  450. {"i_count", NULL, OFFSET(i_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  451. {"p_count", NULL, OFFSET(p_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  452. {"skip_count", NULL, OFFSET(skip_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  453. {"misc_bits", NULL, OFFSET(misc_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  454. {"frame_bits", NULL, OFFSET(frame_bits), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  455. {"codec_tag", NULL, OFFSET(codec_tag), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  456. {"bugs", NULL, OFFSET(workaround_bugs), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D, "bug"},
  457. {"autodetect", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_AUTODETECT, INT_MIN, INT_MAX, V|D, "bug"},
  458. {"old_msmpeg4", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_OLD_MSMPEG4, INT_MIN, INT_MAX, V|D, "bug"},
  459. {"xvid_ilace", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_XVID_ILACE, INT_MIN, INT_MAX, V|D, "bug"},
  460. {"ump4", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_UMP4, INT_MIN, INT_MAX, V|D, "bug"},
  461. {"no_padding", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_NO_PADDING, INT_MIN, INT_MAX, V|D, "bug"},
  462. {"amv", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_AMV, INT_MIN, INT_MAX, V|D, "bug"},
  463. {"ac_vlc", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_AC_VLC, INT_MIN, INT_MAX, V|D, "bug"},
  464. {"qpel_chroma", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_QPEL_CHROMA, INT_MIN, INT_MAX, V|D, "bug"},
  465. {"std_qpel", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_STD_QPEL, INT_MIN, INT_MAX, V|D, "bug"},
  466. {"qpel_chroma2", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_QPEL_CHROMA2, INT_MIN, INT_MAX, V|D, "bug"},
  467. {"direct_blocksize", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_DIRECT_BLOCKSIZE, INT_MIN, INT_MAX, V|D, "bug"},
  468. {"edge", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_EDGE, INT_MIN, INT_MAX, V|D, "bug"},
  469. {"hpel_chroma", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_HPEL_CHROMA, INT_MIN, INT_MAX, V|D, "bug"},
  470. {"dc_clip", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_DC_CLIP, INT_MIN, INT_MAX, V|D, "bug"},
  471. {"ms", NULL, 0, FF_OPT_TYPE_CONST, FF_BUG_MS, INT_MIN, INT_MAX, V|D, "bug"},
  472. {"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},
  473. {"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},
  474. {"strict", NULL, OFFSET(strict_std_compliance), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "strict"},
  475. {"very", NULL, 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_VERY_STRICT, INT_MIN, INT_MAX, V|E, "strict"},
  476. {"strict", NULL, 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_STRICT, INT_MIN, INT_MAX, V|E, "strict"},
  477. {"normal", NULL, 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_NORMAL, INT_MIN, INT_MAX, V|E, "strict"},
  478. {"inofficial", NULL, 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_INOFFICIAL, INT_MIN, INT_MAX, V|E, "strict"},
  479. {"experimental", NULL, 0, FF_OPT_TYPE_CONST, FF_COMPLIANCE_EXPERIMENTAL, INT_MIN, INT_MAX, V|E, "strict"},
  480. {"b_quant_offset", NULL, OFFSET(b_quant_offset), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
  481. {"er", NULL, OFFSET(error_resilience), FF_OPT_TYPE_INT, FF_ER_CAREFUL, INT_MIN, INT_MAX, V|D, "er"},
  482. {"careful", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_CAREFUL, INT_MIN, INT_MAX, V|D, "er"},
  483. {"compliant", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_COMPLIANT, INT_MIN, INT_MAX, V|D, "er"},
  484. {"aggressive", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_AGGRESSIVE, INT_MIN, INT_MAX, V|D, "er"},
  485. {"very_aggressive", NULL, 0, FF_OPT_TYPE_CONST, FF_ER_VERY_AGGRESSIVE, INT_MIN, INT_MAX, V|D, "er"},
  486. {"has_b_frames", NULL, OFFSET(has_b_frames), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  487. {"block_align", NULL, OFFSET(block_align), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  488. {"parse_only", NULL, OFFSET(parse_only), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  489. {"mpeg_quant", NULL, OFFSET(mpeg_quant), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  490. {"stats_out", NULL, OFFSET(stats_out), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX},
  491. {"stats_in", NULL, OFFSET(stats_in), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX},
  492. {"rc_qsquish", NULL, OFFSET(rc_qsquish), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
  493. {"rc_qmod_amp", NULL, OFFSET(rc_qmod_amp), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
  494. {"rc_qmod_freq", NULL, OFFSET(rc_qmod_freq), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  495. {"rc_override_count", NULL, OFFSET(rc_override_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  496. {"rc_eq", NULL, OFFSET(rc_eq), FF_OPT_TYPE_STRING, DEFAULT, CHAR_MIN, CHAR_MAX, V|E},
  497. {"rc_max_rate", NULL, OFFSET(rc_max_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  498. {"rc_min_rate", NULL, OFFSET(rc_min_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  499. {"rc_buffer_size", NULL, OFFSET(rc_buffer_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  500. {"rc_buf_aggressivity", NULL, OFFSET(rc_buffer_aggressivity), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
  501. {"i_quant_factor", NULL, OFFSET(i_quant_factor), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
  502. {"i_quant_offset", NULL, OFFSET(i_quant_offset), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
  503. {"rc_initial_cplx", NULL, OFFSET(rc_initial_cplx), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
  504. {"dct", NULL, OFFSET(dct_algo), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, V|E, "dct"},
  505. {"auto", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_AUTO, INT_MIN, INT_MAX, V|E, "dct"},
  506. {"fastint", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_FASTINT, INT_MIN, INT_MAX, V|E, "dct"},
  507. {"int", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_INT, INT_MIN, INT_MAX, V|E, "dct"},
  508. {"mmx", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_MMX, INT_MIN, INT_MAX, V|E, "dct"},
  509. {"mlib", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_MLIB, INT_MIN, INT_MAX, V|E, "dct"},
  510. {"altivec", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_ALTIVEC, INT_MIN, INT_MAX, V|E, "dct"},
  511. {"faan", NULL, 0, FF_OPT_TYPE_CONST, FF_DCT_FAAN, INT_MIN, INT_MAX, V|E, "dct"},
  512. {"lumi_mask", "lumimasking", OFFSET(lumi_masking), FF_OPT_TYPE_FLOAT, 0, FLT_MIN, FLT_MAX, V|E},
  513. {"tcplx_mask", "temporal complexity masking", OFFSET(temporal_cplx_masking), FF_OPT_TYPE_FLOAT, 0, FLT_MIN, FLT_MAX, V|E},
  514. {"scplx_mask", "spatial complexity masking", OFFSET(spatial_cplx_masking), FF_OPT_TYPE_FLOAT, 0, FLT_MIN, FLT_MAX, V|E},
  515. {"p_mask", "inter masking", OFFSET(p_masking), FF_OPT_TYPE_FLOAT, 0, FLT_MIN, FLT_MAX, V|E},
  516. {"dark_mask", "darkness masking", OFFSET(dark_masking), FF_OPT_TYPE_FLOAT, 0, FLT_MIN, FLT_MAX, V|E},
  517. {"unused", NULL, OFFSET(unused), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  518. {"idct", NULL, OFFSET(idct_algo), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, V|E|D, "idct"},
  519. {"auto", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_AUTO, INT_MIN, INT_MAX, V|E|D, "idct"},
  520. {"int", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_INT, INT_MIN, INT_MAX, V|E|D, "idct"},
  521. {"simple", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLE, INT_MIN, INT_MAX, V|E|D, "idct"},
  522. {"simplemmx", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLEMMX, INT_MIN, INT_MAX, V|E|D, "idct"},
  523. {"libmpeg2mmx", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_LIBMPEG2MMX, INT_MIN, INT_MAX, V|E|D, "idct"},
  524. {"ps2", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_PS2, INT_MIN, INT_MAX, V|E|D, "idct"},
  525. {"mlib", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_MLIB, INT_MIN, INT_MAX, V|E|D, "idct"},
  526. {"arm", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_ARM, INT_MIN, INT_MAX, V|E|D, "idct"},
  527. {"altivec", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_ALTIVEC, INT_MIN, INT_MAX, V|E|D, "idct"},
  528. {"sh4", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SH4, INT_MIN, INT_MAX, V|E|D, "idct"},
  529. {"simplearm", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_SIMPLEARM, INT_MIN, INT_MAX, V|E|D, "idct"},
  530. {"h264", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_H264, INT_MIN, INT_MAX, V|E|D, "idct"},
  531. {"vp3", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_VP3, INT_MIN, INT_MAX, V|E|D, "idct"},
  532. {"ipp", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_IPP, INT_MIN, INT_MAX, V|E|D, "idct"},
  533. {"xvidmmx", NULL, 0, FF_OPT_TYPE_CONST, FF_IDCT_XVIDMMX, INT_MIN, INT_MAX, V|E|D, "idct"},
  534. {"slice_count", NULL, OFFSET(slice_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  535. {"ec", NULL, OFFSET(error_concealment), FF_OPT_TYPE_FLAGS, 3, INT_MIN, INT_MAX, V|D, "ec"},
  536. {"guess_mvs", NULL, 0, FF_OPT_TYPE_CONST, FF_EC_GUESS_MVS, INT_MIN, INT_MAX, V|D, "ec"},
  537. {"deblock", NULL, 0, FF_OPT_TYPE_CONST, FF_EC_DEBLOCK, INT_MIN, INT_MAX, V|D, "ec"},
  538. {"bits_per_sample", NULL, OFFSET(bits_per_sample), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  539. {"pred", "prediction method", OFFSET(prediction_method), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "pred"},
  540. {"left", NULL, 0, FF_OPT_TYPE_CONST, FF_PRED_LEFT, INT_MIN, INT_MAX, V|E, "pred"},
  541. {"plane", NULL, 0, FF_OPT_TYPE_CONST, FF_PRED_PLANE, INT_MIN, INT_MAX, V|E, "pred"},
  542. {"median", NULL, 0, FF_OPT_TYPE_CONST, FF_PRED_MEDIAN, INT_MIN, INT_MAX, V|E, "pred"},
  543. {"aspect", NULL, OFFSET(sample_aspect_ratio), FF_OPT_TYPE_RATIONAL, DEFAULT, 0, 10, V|E},
  544. {"debug", "print specific debug info", OFFSET(debug), FF_OPT_TYPE_FLAGS, DEFAULT, 0, INT_MAX, V|A|S|E|D, "debug"},
  545. {"pict", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_PICT_INFO, INT_MIN, INT_MAX, V|D, "debug"},
  546. {"rc", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_RC, INT_MIN, INT_MAX, V|E, "debug"},
  547. {"bitstream", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_BITSTREAM, INT_MIN, INT_MAX, V|D, "debug"},
  548. {"mb_type", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_MB_TYPE, INT_MIN, INT_MAX, V|D, "debug"},
  549. {"qp", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_QP, INT_MIN, INT_MAX, V|D, "debug"},
  550. {"mv", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_MV, INT_MIN, INT_MAX, V|D, "debug"},
  551. {"dct_coeff", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_DCT_COEFF, INT_MIN, INT_MAX, V|D, "debug"},
  552. {"skip", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_SKIP, INT_MIN, INT_MAX, V|D, "debug"},
  553. {"startcode", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_STARTCODE, INT_MIN, INT_MAX, V|D, "debug"},
  554. {"pts", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_PTS, INT_MIN, INT_MAX, V|D, "debug"},
  555. {"er", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_ER, INT_MIN, INT_MAX, V|D, "debug"},
  556. {"mmco", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_MMCO, INT_MIN, INT_MAX, V|D, "debug"},
  557. {"bugs", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_BUGS, INT_MIN, INT_MAX, V|D, "debug"},
  558. {"vis_qp", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_QP, INT_MIN, INT_MAX, V|D, "debug"},
  559. {"vis_mb_type", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MB_TYPE, INT_MIN, INT_MAX, V|D, "debug"},
  560. {"vismv", "visualize motion vectors", OFFSET(debug_mv), FF_OPT_TYPE_INT, DEFAULT, 0, INT_MAX, V|D, "debug_mv"},
  561. {"pf", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MV_P_FOR, INT_MIN, INT_MAX, V|D, "debug_mv"},
  562. {"bf", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MV_B_FOR, INT_MIN, INT_MAX, V|D, "debug_mv"},
  563. {"bb", NULL, 0, FF_OPT_TYPE_CONST, FF_DEBUG_VIS_MV_B_BACK, INT_MIN, INT_MAX, V|D, "debug_mv"},
  564. {"mb_qmin", NULL, OFFSET(mb_qmin), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  565. {"mb_qmax", NULL, OFFSET(mb_qmax), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  566. {"cmp", "full pel me compare function", OFFSET(me_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
  567. {"subcmp", "sub pel me compare function", OFFSET(me_sub_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
  568. {"mbcmp", "macroblock compare function", OFFSET(mb_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
  569. {"ildctcmp", "interlaced dct compare function", OFFSET(ildct_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
  570. {"dia_size", NULL, OFFSET(dia_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  571. {"last_pred", NULL, OFFSET(last_predictor_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  572. {"preme", NULL, OFFSET(pre_me), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  573. {"precmp", "pre motion estimation compare function", OFFSET(me_pre_cmp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "cmp_func"},
  574. {"sad", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_SAD, INT_MIN, INT_MAX, V|E, "cmp_func"},
  575. {"sse", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_SSE, INT_MIN, INT_MAX, V|E, "cmp_func"},
  576. {"satd", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_SATD, INT_MIN, INT_MAX, V|E, "cmp_func"},
  577. {"dct", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_DCT, INT_MIN, INT_MAX, V|E, "cmp_func"},
  578. {"psnr", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_PSNR, INT_MIN, INT_MAX, V|E, "cmp_func"},
  579. {"bit", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_BIT, INT_MIN, INT_MAX, V|E, "cmp_func"},
  580. {"rd", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_RD, INT_MIN, INT_MAX, V|E, "cmp_func"},
  581. {"zero", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_ZERO, INT_MIN, INT_MAX, V|E, "cmp_func"},
  582. {"vsad", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_VSAD, INT_MIN, INT_MAX, V|E, "cmp_func"},
  583. {"vsse", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_VSSE, INT_MIN, INT_MAX, V|E, "cmp_func"},
  584. {"nsse", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_NSSE, INT_MIN, INT_MAX, V|E, "cmp_func"},
  585. {"w53", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_W53, INT_MIN, INT_MAX, V|E, "cmp_func"},
  586. {"w97", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_W97, INT_MIN, INT_MAX, V|E, "cmp_func"},
  587. {"dctmax", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_DCTMAX, INT_MIN, INT_MAX, V|E, "cmp_func"},
  588. {"chroma", NULL, 0, FF_OPT_TYPE_CONST, FF_CMP_CHROMA, INT_MIN, INT_MAX, V|E, "cmp_func"},
  589. {"pre_dia_size", NULL, OFFSET(pre_dia_size), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  590. {"subq", "sub pel motion estimation quality", OFFSET(me_subpel_quality), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  591. {"dtg_active_format", NULL, OFFSET(dtg_active_format), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  592. {"me_range", NULL, OFFSET(me_range), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  593. {"ibias", NULL, OFFSET(intra_quant_bias), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  594. {"pbias", NULL, OFFSET(inter_quant_bias), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  595. {"color_table_id", NULL, OFFSET(color_table_id), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  596. {"internal_buffer_count", NULL, OFFSET(internal_buffer_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  597. {"global_quality", NULL, OFFSET(global_quality), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  598. {"coder", NULL, OFFSET(coder_type), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "coder"},
  599. {"vlc", "variable length coder / huffman coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_VLC, INT_MIN, INT_MAX, V|E, "coder"},
  600. {"ac", "arithmetic coder", 0, FF_OPT_TYPE_CONST, FF_CODER_TYPE_AC, INT_MIN, INT_MAX, V|E, "coder"},
  601. {"context", "context model", OFFSET(context_model), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  602. {"slice_flags", NULL, OFFSET(slice_flags), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  603. {"xvmc_acceleration", NULL, OFFSET(xvmc_acceleration), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  604. {"mbd", NULL, OFFSET(mb_decision), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E, "mbd"},
  605. {"simple", NULL, 0, FF_OPT_TYPE_CONST, FF_MB_DECISION_SIMPLE, INT_MIN, INT_MAX, V|E, "mbd"},
  606. {"bits", NULL, 0, FF_OPT_TYPE_CONST, FF_MB_DECISION_BITS, INT_MIN, INT_MAX, V|E, "mbd"},
  607. {"rd", NULL, 0, FF_OPT_TYPE_CONST, FF_MB_DECISION_RD, INT_MIN, INT_MAX, V|E, "mbd"},
  608. {"stream_codec_tag", NULL, OFFSET(stream_codec_tag), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  609. {"sc_threshold", NULL, OFFSET(scenechange_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  610. {"lmin", "min lagrange factor", OFFSET(lmin), FF_OPT_TYPE_INT, 2*FF_QP2LAMBDA, 0, INT_MAX, V|E},
  611. {"lmax", "max lagrange factor", OFFSET(lmax), FF_OPT_TYPE_INT, 31*FF_QP2LAMBDA, 0, INT_MAX, V|E},
  612. {"nr", "noise reduction", OFFSET(noise_reduction), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  613. {"rc_init_occupancy", NULL, OFFSET(rc_initial_buffer_occupancy), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  614. {"inter_threshold", NULL, OFFSET(inter_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  615. {"flags2", NULL, OFFSET(flags2), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX},
  616. {"error_rate", NULL, OFFSET(error_rate), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  617. {"antialias", NULL, OFFSET(antialias_algo), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D, "aa"},
  618. {"auto", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_AUTO, INT_MIN, INT_MAX, V|D, "aa"},
  619. {"fastint", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_FASTINT, INT_MIN, INT_MAX, V|D, "aa"},
  620. {"int", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_INT, INT_MIN, INT_MAX, V|D, "aa"},
  621. {"float", NULL, 0, FF_OPT_TYPE_CONST, FF_AA_FLOAT, INT_MIN, INT_MAX, V|D, "aa"},
  622. {"qns", "quantizer noise shaping", OFFSET(quantizer_noise_shaping), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  623. {"thread_count", NULL, OFFSET(thread_count), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E|D},
  624. {"me_threshold", "motion estimaton threshold", OFFSET(me_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  625. {"mb_threshold", NULL, OFFSET(mb_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX},
  626. {"dc", NULL, OFFSET(intra_dc_precision), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  627. {"nssew", "nsse weight", OFFSET(nsse_weight), FF_OPT_TYPE_INT, 8, INT_MIN, INT_MAX, V|E},
  628. {"skip_top", NULL, OFFSET(skip_top), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D},
  629. {"skip_bottom", NULL, OFFSET(skip_bottom), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|D},
  630. {"profile", NULL, OFFSET(profile), FF_OPT_TYPE_INT, FF_PROFILE_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "profile"},
  631. {"unknown", NULL, 0, FF_OPT_TYPE_CONST, FF_PROFILE_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "profile"},
  632. {"level", NULL, OFFSET(level), FF_OPT_TYPE_INT, FF_LEVEL_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "level"},
  633. {"unknown", NULL, 0, FF_OPT_TYPE_CONST, FF_LEVEL_UNKNOWN, INT_MIN, INT_MAX, V|A|E, "level"},
  634. {"lowres", NULL, OFFSET(lowres), FF_OPT_TYPE_INT, 0, 0, INT_MAX, V|D},
  635. {"frame_skip_threshold", NULL, OFFSET(frame_skip_threshold), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  636. {"frame_skip_factor", NULL, OFFSET(frame_skip_factor), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  637. {"frame_skip_exp", NULL, OFFSET(frame_skip_exp), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  638. {"skipcmp", "frame skip compare function", OFFSET(frame_skip_cmp), FF_OPT_TYPE_INT, FF_CMP_DCTMAX, INT_MIN, INT_MAX, V|E, "cmp_func"},
  639. {"border_mask", NULL, OFFSET(border_masking), FF_OPT_TYPE_FLOAT, DEFAULT, FLT_MIN, FLT_MAX, V|E},
  640. {"mb_lmin", NULL, OFFSET(mb_lmin), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  641. {"mb_lmax", NULL, OFFSET(mb_lmax), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  642. {"me_penalty_compensation", NULL, OFFSET(me_penalty_compensation), FF_OPT_TYPE_INT, DEFAULT, INT_MIN, INT_MAX, V|E},
  643. {"bidir_refine", NULL, OFFSET(bidir_refine), FF_OPT_TYPE_INT, DEFAULT, 0, 4, V|E},
  644. {"brd_scale", NULL, OFFSET(brd_scale), FF_OPT_TYPE_INT, DEFAULT, 0, 10, V|E},
  645. {NULL},
  646. };
  647. #undef A
  648. #undef V
  649. static AVClass av_codec_context_class = { "AVCodecContext", context_to_name, options };
  650. void avcodec_get_context_defaults(AVCodecContext *s){
  651. memset(s, 0, sizeof(AVCodecContext));
  652. s->av_class= &av_codec_context_class;
  653. s->bit_rate= 800*1000;
  654. s->bit_rate_tolerance= s->bit_rate*10;
  655. s->qmin= 2;
  656. s->qmax= 31;
  657. s->mb_lmin= FF_QP2LAMBDA * 2;
  658. s->mb_lmax= FF_QP2LAMBDA * 31;
  659. s->rc_eq= "tex^qComp";
  660. s->qcompress= 0.5;
  661. s->max_qdiff= 3;
  662. s->b_quant_factor=1.25;
  663. s->b_quant_offset=1.25;
  664. s->i_quant_factor=-0.8;
  665. s->i_quant_offset=0.0;
  666. s->error_concealment= 3;
  667. s->error_resilience= 1;
  668. s->workaround_bugs= FF_BUG_AUTODETECT;
  669. s->time_base= (AVRational){0,1};
  670. s->gop_size= 50;
  671. s->me_method= ME_EPZS;
  672. s->get_buffer= avcodec_default_get_buffer;
  673. s->release_buffer= avcodec_default_release_buffer;
  674. s->get_format= avcodec_default_get_format;
  675. s->execute= avcodec_default_execute;
  676. s->thread_count=1;
  677. s->me_subpel_quality=8;
  678. s->lmin= FF_QP2LAMBDA * s->qmin;
  679. s->lmax= FF_QP2LAMBDA * s->qmax;
  680. s->sample_aspect_ratio= (AVRational){0,1};
  681. s->ildct_cmp= FF_CMP_VSAD;
  682. s->profile= FF_PROFILE_UNKNOWN;
  683. s->level= FF_LEVEL_UNKNOWN;
  684. s->me_penalty_compensation= 256;
  685. s->pix_fmt= PIX_FMT_NONE;
  686. s->frame_skip_cmp= FF_CMP_DCTMAX;
  687. s->nsse_weight= 8;
  688. s->intra_quant_bias= FF_DEFAULT_QUANT_BIAS;
  689. s->inter_quant_bias= FF_DEFAULT_QUANT_BIAS;
  690. s->palctrl = NULL;
  691. s->reget_buffer= avcodec_default_reget_buffer;
  692. }
  693. /**
  694. * allocates a AVCodecContext and set it to defaults.
  695. * this can be deallocated by simply calling free()
  696. */
  697. AVCodecContext *avcodec_alloc_context(void){
  698. AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));
  699. if(avctx==NULL) return NULL;
  700. avcodec_get_context_defaults(avctx);
  701. return avctx;
  702. }
  703. void avcodec_get_frame_defaults(AVFrame *pic){
  704. memset(pic, 0, sizeof(AVFrame));
  705. pic->pts= AV_NOPTS_VALUE;
  706. pic->key_frame= 1;
  707. }
  708. /**
  709. * allocates a AVPFrame and set it to defaults.
  710. * this can be deallocated by simply calling free()
  711. */
  712. AVFrame *avcodec_alloc_frame(void){
  713. AVFrame *pic= av_malloc(sizeof(AVFrame));
  714. if(pic==NULL) return NULL;
  715. avcodec_get_frame_defaults(pic);
  716. return pic;
  717. }
  718. int avcodec_open(AVCodecContext *avctx, AVCodec *codec)
  719. {
  720. int ret= -1;
  721. entangled_thread_counter++;
  722. if(entangled_thread_counter != 1){
  723. av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
  724. goto end;
  725. }
  726. if(avctx->codec)
  727. goto end;
  728. avctx->codec = codec;
  729. avctx->codec_id = codec->id;
  730. avctx->frame_number = 0;
  731. if (codec->priv_data_size > 0) {
  732. avctx->priv_data = av_mallocz(codec->priv_data_size);
  733. if (!avctx->priv_data)
  734. goto end;
  735. } else {
  736. avctx->priv_data = NULL;
  737. }
  738. if(avctx->coded_width && avctx->coded_height)
  739. avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
  740. else if(avctx->width && avctx->height)
  741. avcodec_set_dimensions(avctx, avctx->width, avctx->height);
  742. if((avctx->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height)){
  743. av_freep(&avctx->priv_data);
  744. goto end;
  745. }
  746. ret = avctx->codec->init(avctx);
  747. if (ret < 0) {
  748. av_freep(&avctx->priv_data);
  749. goto end;
  750. }
  751. ret=0;
  752. end:
  753. entangled_thread_counter--;
  754. return ret;
  755. }
  756. int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  757. const short *samples)
  758. {
  759. if(buf_size < FF_MIN_BUFFER_SIZE && 0){
  760. av_log(avctx, AV_LOG_ERROR, "buffer smaller then minimum size\n");
  761. return -1;
  762. }
  763. if((avctx->codec->capabilities & CODEC_CAP_DELAY) || samples){
  764. int ret = avctx->codec->encode(avctx, buf, buf_size, (void *)samples);
  765. avctx->frame_number++;
  766. return ret;
  767. }else
  768. return 0;
  769. }
  770. int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  771. const AVFrame *pict)
  772. {
  773. if(buf_size < FF_MIN_BUFFER_SIZE){
  774. av_log(avctx, AV_LOG_ERROR, "buffer smaller then minimum size\n");
  775. return -1;
  776. }
  777. if(avcodec_check_dimensions(avctx,avctx->width,avctx->height))
  778. return -1;
  779. if((avctx->codec->capabilities & CODEC_CAP_DELAY) || pict){
  780. int ret = avctx->codec->encode(avctx, buf, buf_size, (void *)pict);
  781. avctx->frame_number++;
  782. emms_c(); //needed to avoid an emms_c() call before every return;
  783. return ret;
  784. }else
  785. return 0;
  786. }
  787. int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
  788. const AVSubtitle *sub)
  789. {
  790. int ret;
  791. ret = avctx->codec->encode(avctx, buf, buf_size, (void *)sub);
  792. avctx->frame_number++;
  793. return ret;
  794. }
  795. /**
  796. * decode a frame.
  797. * @param buf bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE larger then the actual read bytes
  798. * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end
  799. * @param buf_size the size of the buffer in bytes
  800. * @param got_picture_ptr zero if no frame could be decompressed, Otherwise, it is non zero
  801. * @return -1 if error, otherwise return the number of
  802. * bytes used.
  803. */
  804. int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
  805. int *got_picture_ptr,
  806. uint8_t *buf, int buf_size)
  807. {
  808. int ret;
  809. *got_picture_ptr= 0;
  810. if((avctx->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height))
  811. return -1;
  812. if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){
  813. ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
  814. buf, buf_size);
  815. emms_c(); //needed to avoid an emms_c() call before every return;
  816. if (*got_picture_ptr)
  817. avctx->frame_number++;
  818. }else
  819. ret= 0;
  820. return ret;
  821. }
  822. /* decode an audio frame. return -1 if error, otherwise return the
  823. *number of bytes used. If no frame could be decompressed,
  824. *frame_size_ptr is zero. Otherwise, it is the decompressed frame
  825. *size in BYTES. */
  826. int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples,
  827. int *frame_size_ptr,
  828. uint8_t *buf, int buf_size)
  829. {
  830. int ret;
  831. *frame_size_ptr= 0;
  832. if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){
  833. ret = avctx->codec->decode(avctx, samples, frame_size_ptr,
  834. buf, buf_size);
  835. avctx->frame_number++;
  836. }else
  837. ret= 0;
  838. return ret;
  839. }
  840. /* decode a subtitle message. return -1 if error, otherwise return the
  841. *number of bytes used. If no subtitle could be decompressed,
  842. *got_sub_ptr is zero. Otherwise, the subtitle is stored in *sub. */
  843. int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub,
  844. int *got_sub_ptr,
  845. const uint8_t *buf, int buf_size)
  846. {
  847. int ret;
  848. *got_sub_ptr = 0;
  849. ret = avctx->codec->decode(avctx, sub, got_sub_ptr,
  850. (uint8_t *)buf, buf_size);
  851. if (*got_sub_ptr)
  852. avctx->frame_number++;
  853. return ret;
  854. }
  855. int avcodec_close(AVCodecContext *avctx)
  856. {
  857. entangled_thread_counter++;
  858. if(entangled_thread_counter != 1){
  859. av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
  860. entangled_thread_counter--;
  861. return -1;
  862. }
  863. if (avctx->codec->close)
  864. avctx->codec->close(avctx);
  865. avcodec_default_free_buffers(avctx);
  866. av_freep(&avctx->priv_data);
  867. avctx->codec = NULL;
  868. entangled_thread_counter--;
  869. return 0;
  870. }
  871. AVCodec *avcodec_find_encoder(enum CodecID id)
  872. {
  873. AVCodec *p;
  874. p = first_avcodec;
  875. while (p) {
  876. if (p->encode != NULL && p->id == id)
  877. return p;
  878. p = p->next;
  879. }
  880. return NULL;
  881. }
  882. AVCodec *avcodec_find_encoder_by_name(const char *name)
  883. {
  884. AVCodec *p;
  885. p = first_avcodec;
  886. while (p) {
  887. if (p->encode != NULL && strcmp(name,p->name) == 0)
  888. return p;
  889. p = p->next;
  890. }
  891. return NULL;
  892. }
  893. AVCodec *avcodec_find_decoder(enum CodecID id)
  894. {
  895. AVCodec *p;
  896. p = first_avcodec;
  897. while (p) {
  898. if (p->decode != NULL && p->id == id)
  899. return p;
  900. p = p->next;
  901. }
  902. return NULL;
  903. }
  904. AVCodec *avcodec_find_decoder_by_name(const char *name)
  905. {
  906. AVCodec *p;
  907. p = first_avcodec;
  908. while (p) {
  909. if (p->decode != NULL && strcmp(name,p->name) == 0)
  910. return p;
  911. p = p->next;
  912. }
  913. return NULL;
  914. }
  915. void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
  916. {
  917. const char *codec_name;
  918. AVCodec *p;
  919. char buf1[32];
  920. char channels_str[100];
  921. int bitrate;
  922. if (encode)
  923. p = avcodec_find_encoder(enc->codec_id);
  924. else
  925. p = avcodec_find_decoder(enc->codec_id);
  926. if (p) {
  927. codec_name = p->name;
  928. if (!encode && enc->codec_id == CODEC_ID_MP3) {
  929. if (enc->sub_id == 2)
  930. codec_name = "mp2";
  931. else if (enc->sub_id == 1)
  932. codec_name = "mp1";
  933. }
  934. } else if (enc->codec_id == CODEC_ID_MPEG2TS) {
  935. /* fake mpeg2 transport stream codec (currently not
  936. registered) */
  937. codec_name = "mpeg2ts";
  938. } else if (enc->codec_name[0] != '\0') {
  939. codec_name = enc->codec_name;
  940. } else {
  941. /* output avi tags */
  942. if( isprint(enc->codec_tag&0xFF) && isprint((enc->codec_tag>>8)&0xFF)
  943. && isprint((enc->codec_tag>>16)&0xFF) && isprint((enc->codec_tag>>24)&0xFF)){
  944. snprintf(buf1, sizeof(buf1), "%c%c%c%c / 0x%04X",
  945. enc->codec_tag & 0xff,
  946. (enc->codec_tag >> 8) & 0xff,
  947. (enc->codec_tag >> 16) & 0xff,
  948. (enc->codec_tag >> 24) & 0xff,
  949. enc->codec_tag);
  950. } else {
  951. snprintf(buf1, sizeof(buf1), "0x%04x", enc->codec_tag);
  952. }
  953. codec_name = buf1;
  954. }
  955. switch(enc->codec_type) {
  956. case CODEC_TYPE_VIDEO:
  957. snprintf(buf, buf_size,
  958. "Video: %s%s",
  959. codec_name, enc->mb_decision ? " (hq)" : "");
  960. if (enc->pix_fmt != PIX_FMT_NONE) {
  961. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  962. ", %s",
  963. avcodec_get_pix_fmt_name(enc->pix_fmt));
  964. }
  965. if (enc->width) {
  966. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  967. ", %dx%d",
  968. enc->width, enc->height);
  969. if(av_log_get_level() >= AV_LOG_DEBUG){
  970. int g= ff_gcd(enc->time_base.num, enc->time_base.den);
  971. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  972. ", %d/%d",
  973. enc->time_base.num/g, enc->time_base.den/g);
  974. }
  975. }
  976. if (encode) {
  977. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  978. ", q=%d-%d", enc->qmin, enc->qmax);
  979. }
  980. bitrate = enc->bit_rate;
  981. break;
  982. case CODEC_TYPE_AUDIO:
  983. snprintf(buf, buf_size,
  984. "Audio: %s",
  985. codec_name);
  986. switch (enc->channels) {
  987. case 1:
  988. strcpy(channels_str, "mono");
  989. break;
  990. case 2:
  991. strcpy(channels_str, "stereo");
  992. break;
  993. case 6:
  994. strcpy(channels_str, "5:1");
  995. break;
  996. default:
  997. snprintf(channels_str, sizeof(channels_str), "%d channels", enc->channels);
  998. break;
  999. }
  1000. if (enc->sample_rate) {
  1001. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  1002. ", %d Hz, %s",
  1003. enc->sample_rate,
  1004. channels_str);
  1005. }
  1006. /* for PCM codecs, compute bitrate directly */
  1007. switch(enc->codec_id) {
  1008. case CODEC_ID_PCM_S32LE:
  1009. case CODEC_ID_PCM_S32BE:
  1010. case CODEC_ID_PCM_U32LE:
  1011. case CODEC_ID_PCM_U32BE:
  1012. bitrate = enc->sample_rate * enc->channels * 32;
  1013. break;
  1014. case CODEC_ID_PCM_S24LE:
  1015. case CODEC_ID_PCM_S24BE:
  1016. case CODEC_ID_PCM_U24LE:
  1017. case CODEC_ID_PCM_U24BE:
  1018. case CODEC_ID_PCM_S24DAUD:
  1019. bitrate = enc->sample_rate * enc->channels * 24;
  1020. break;
  1021. case CODEC_ID_PCM_S16LE:
  1022. case CODEC_ID_PCM_S16BE:
  1023. case CODEC_ID_PCM_U16LE:
  1024. case CODEC_ID_PCM_U16BE:
  1025. bitrate = enc->sample_rate * enc->channels * 16;
  1026. break;
  1027. case CODEC_ID_PCM_S8:
  1028. case CODEC_ID_PCM_U8:
  1029. case CODEC_ID_PCM_ALAW:
  1030. case CODEC_ID_PCM_MULAW:
  1031. bitrate = enc->sample_rate * enc->channels * 8;
  1032. break;
  1033. default:
  1034. bitrate = enc->bit_rate;
  1035. break;
  1036. }
  1037. break;
  1038. case CODEC_TYPE_DATA:
  1039. snprintf(buf, buf_size, "Data: %s", codec_name);
  1040. bitrate = enc->bit_rate;
  1041. break;
  1042. case CODEC_TYPE_SUBTITLE:
  1043. snprintf(buf, buf_size, "Subtitle: %s", codec_name);
  1044. bitrate = enc->bit_rate;
  1045. break;
  1046. default:
  1047. snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type);
  1048. return;
  1049. }
  1050. if (encode) {
  1051. if (enc->flags & CODEC_FLAG_PASS1)
  1052. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  1053. ", pass 1");
  1054. if (enc->flags & CODEC_FLAG_PASS2)
  1055. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  1056. ", pass 2");
  1057. }
  1058. if (bitrate != 0) {
  1059. snprintf(buf + strlen(buf), buf_size - strlen(buf),
  1060. ", %d kb/s", bitrate / 1000);
  1061. }
  1062. }
  1063. unsigned avcodec_version( void )
  1064. {
  1065. return LIBAVCODEC_VERSION_INT;
  1066. }
  1067. unsigned avcodec_build( void )
  1068. {
  1069. return LIBAVCODEC_BUILD;
  1070. }
  1071. /* must be called before any other functions */
  1072. void avcodec_init(void)
  1073. {
  1074. static int inited = 0;
  1075. if (inited != 0)
  1076. return;
  1077. inited = 1;
  1078. dsputil_static_init();
  1079. }
  1080. /**
  1081. * Flush buffers, should be called when seeking or when swicthing to a different stream.
  1082. */
  1083. void avcodec_flush_buffers(AVCodecContext *avctx)
  1084. {
  1085. if(avctx->codec->flush)
  1086. avctx->codec->flush(avctx);
  1087. }
  1088. void avcodec_default_free_buffers(AVCodecContext *s){
  1089. int i, j;
  1090. if(s->internal_buffer==NULL) return;
  1091. for(i=0; i<INTERNAL_BUFFER_SIZE; i++){
  1092. InternalBuffer *buf= &((InternalBuffer*)s->internal_buffer)[i];
  1093. for(j=0; j<4; j++){
  1094. av_freep(&buf->base[j]);
  1095. buf->data[j]= NULL;
  1096. }
  1097. }
  1098. av_freep(&s->internal_buffer);
  1099. s->internal_buffer_count=0;
  1100. }
  1101. char av_get_pict_type_char(int pict_type){
  1102. switch(pict_type){
  1103. case I_TYPE: return 'I';
  1104. case P_TYPE: return 'P';
  1105. case B_TYPE: return 'B';
  1106. case S_TYPE: return 'S';
  1107. case SI_TYPE:return 'i';
  1108. case SP_TYPE:return 'p';
  1109. default: return '?';
  1110. }
  1111. }
  1112. /* av_log API */
  1113. static int av_log_level = AV_LOG_INFO;
  1114. static void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
  1115. {
  1116. static int print_prefix=1;
  1117. AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
  1118. if(level>av_log_level)
  1119. return;
  1120. #undef fprintf
  1121. if(print_prefix && avc) {
  1122. fprintf(stderr, "[%s @ %p]", avc->item_name(ptr), avc);
  1123. }
  1124. #define fprintf please_use_av_log
  1125. print_prefix= strstr(fmt, "\n") != NULL;
  1126. vfprintf(stderr, fmt, vl);
  1127. }
  1128. static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback;
  1129. void av_log(void* avcl, int level, const char *fmt, ...)
  1130. {
  1131. va_list vl;
  1132. va_start(vl, fmt);
  1133. av_vlog(avcl, level, fmt, vl);
  1134. va_end(vl);
  1135. }
  1136. void av_vlog(void* avcl, int level, const char *fmt, va_list vl)
  1137. {
  1138. av_log_callback(avcl, level, fmt, vl);
  1139. }
  1140. int av_log_get_level(void)
  1141. {
  1142. return av_log_level;
  1143. }
  1144. void av_log_set_level(int level)
  1145. {
  1146. av_log_level = level;
  1147. }
  1148. void av_log_set_callback(void (*callback)(void*, int, const char*, va_list))
  1149. {
  1150. av_log_callback = callback;
  1151. }
  1152. #if !defined(HAVE_THREADS)
  1153. int avcodec_thread_init(AVCodecContext *s, int thread_count){
  1154. return -1;
  1155. }
  1156. #endif
  1157. unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
  1158. {
  1159. unsigned int n = 0;
  1160. while(v >= 0xff) {
  1161. *s++ = 0xff;
  1162. v -= 0xff;
  1163. n++;
  1164. }
  1165. *s = v;
  1166. n++;
  1167. return n;
  1168. }