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.

1352 lines
57KB

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