Mercurial > libavcodec.hg
annotate utils.c @ 2809:75400dfbe117 libavcodec
fixing colocated mv if colocated block is L1 predicted for the temporal direct case
untested (none of the conformance streams laying around on my disk seems affected by this change)
author | michael |
---|---|
date | Wed, 27 Jul 2005 00:15:55 +0000 |
parents | af3a36e20010 |
children | b128802eb77b |
rev | line source |
---|---|
0 | 1 /* |
2 * utils for libavcodec | |
429 | 3 * Copyright (c) 2001 Fabrice Bellard. |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
4 * Copyright (c) 2003 Michel Bardiaux for the av_log API |
1739
07a484280a82
copyright year update of the files i touched and remembered, things look annoyingly unmaintained otherwise
michael
parents:
1730
diff
changeset
|
5 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at> |
0 | 6 * |
429 | 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. | |
0 | 11 * |
429 | 12 * This library is distributed in the hope that it will be useful, |
0 | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
429 | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 * Lesser General Public License for more details. | |
0 | 16 * |
429 | 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 | |
0 | 20 */ |
1106 | 21 |
22 /** | |
23 * @file utils.c | |
24 * utils. | |
25 */ | |
26 | |
394 | 27 #include "avcodec.h" |
0 | 28 #include "dsputil.h" |
341 | 29 #include "mpegvideo.h" |
2002
b737b5e96ee0
use AVInteger in av_rescale() so it can finally do 64*64/64 instead of just 64*32/32
michael
parents:
1996
diff
changeset
|
30 #include "integer.h" |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
31 #include <stdarg.h> |
2002
b737b5e96ee0
use AVInteger in av_rescale() so it can finally do 64*64/64 instead of just 64*32/32
michael
parents:
1996
diff
changeset
|
32 #include <limits.h> |
0 | 33 |
2398
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2370
diff
changeset
|
34 const uint8_t ff_sqrt_tab[128]={ |
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2370
diff
changeset
|
35 0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, |
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2370
diff
changeset
|
36 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, |
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2370
diff
changeset
|
37 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, |
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2370
diff
changeset
|
38 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11 |
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2370
diff
changeset
|
39 }; |
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2370
diff
changeset
|
40 |
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2370
diff
changeset
|
41 const uint8_t ff_log2_tab[256]={ |
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2370
diff
changeset
|
42 0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, |
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2370
diff
changeset
|
43 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, |
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2370
diff
changeset
|
44 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, |
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2370
diff
changeset
|
45 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, |
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2370
diff
changeset
|
46 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2370
diff
changeset
|
47 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2370
diff
changeset
|
48 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, |
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2370
diff
changeset
|
49 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7 |
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2370
diff
changeset
|
50 }; |
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2370
diff
changeset
|
51 |
2652
659b92488061
ff_reverse to utils.c patch by (Roine Gustafsson )roine users.sourceforge net)
michael
parents:
2637
diff
changeset
|
52 const uint8_t ff_reverse[256]={ |
659b92488061
ff_reverse to utils.c patch by (Roine Gustafsson )roine users.sourceforge net)
michael
parents:
2637
diff
changeset
|
53 0x00,0x80,0x40,0xC0,0x20,0xA0,0x60,0xE0,0x10,0x90,0x50,0xD0,0x30,0xB0,0x70,0xF0, |
659b92488061
ff_reverse to utils.c patch by (Roine Gustafsson )roine users.sourceforge net)
michael
parents:
2637
diff
changeset
|
54 0x08,0x88,0x48,0xC8,0x28,0xA8,0x68,0xE8,0x18,0x98,0x58,0xD8,0x38,0xB8,0x78,0xF8, |
659b92488061
ff_reverse to utils.c patch by (Roine Gustafsson )roine users.sourceforge net)
michael
parents:
2637
diff
changeset
|
55 0x04,0x84,0x44,0xC4,0x24,0xA4,0x64,0xE4,0x14,0x94,0x54,0xD4,0x34,0xB4,0x74,0xF4, |
659b92488061
ff_reverse to utils.c patch by (Roine Gustafsson )roine users.sourceforge net)
michael
parents:
2637
diff
changeset
|
56 0x0C,0x8C,0x4C,0xCC,0x2C,0xAC,0x6C,0xEC,0x1C,0x9C,0x5C,0xDC,0x3C,0xBC,0x7C,0xFC, |
659b92488061
ff_reverse to utils.c patch by (Roine Gustafsson )roine users.sourceforge net)
michael
parents:
2637
diff
changeset
|
57 0x02,0x82,0x42,0xC2,0x22,0xA2,0x62,0xE2,0x12,0x92,0x52,0xD2,0x32,0xB2,0x72,0xF2, |
659b92488061
ff_reverse to utils.c patch by (Roine Gustafsson )roine users.sourceforge net)
michael
parents:
2637
diff
changeset
|
58 0x0A,0x8A,0x4A,0xCA,0x2A,0xAA,0x6A,0xEA,0x1A,0x9A,0x5A,0xDA,0x3A,0xBA,0x7A,0xFA, |
659b92488061
ff_reverse to utils.c patch by (Roine Gustafsson )roine users.sourceforge net)
michael
parents:
2637
diff
changeset
|
59 0x06,0x86,0x46,0xC6,0x26,0xA6,0x66,0xE6,0x16,0x96,0x56,0xD6,0x36,0xB6,0x76,0xF6, |
659b92488061
ff_reverse to utils.c patch by (Roine Gustafsson )roine users.sourceforge net)
michael
parents:
2637
diff
changeset
|
60 0x0E,0x8E,0x4E,0xCE,0x2E,0xAE,0x6E,0xEE,0x1E,0x9E,0x5E,0xDE,0x3E,0xBE,0x7E,0xFE, |
659b92488061
ff_reverse to utils.c patch by (Roine Gustafsson )roine users.sourceforge net)
michael
parents:
2637
diff
changeset
|
61 0x01,0x81,0x41,0xC1,0x21,0xA1,0x61,0xE1,0x11,0x91,0x51,0xD1,0x31,0xB1,0x71,0xF1, |
659b92488061
ff_reverse to utils.c patch by (Roine Gustafsson )roine users.sourceforge net)
michael
parents:
2637
diff
changeset
|
62 0x09,0x89,0x49,0xC9,0x29,0xA9,0x69,0xE9,0x19,0x99,0x59,0xD9,0x39,0xB9,0x79,0xF9, |
659b92488061
ff_reverse to utils.c patch by (Roine Gustafsson )roine users.sourceforge net)
michael
parents:
2637
diff
changeset
|
63 0x05,0x85,0x45,0xC5,0x25,0xA5,0x65,0xE5,0x15,0x95,0x55,0xD5,0x35,0xB5,0x75,0xF5, |
659b92488061
ff_reverse to utils.c patch by (Roine Gustafsson )roine users.sourceforge net)
michael
parents:
2637
diff
changeset
|
64 0x0D,0x8D,0x4D,0xCD,0x2D,0xAD,0x6D,0xED,0x1D,0x9D,0x5D,0xDD,0x3D,0xBD,0x7D,0xFD, |
659b92488061
ff_reverse to utils.c patch by (Roine Gustafsson )roine users.sourceforge net)
michael
parents:
2637
diff
changeset
|
65 0x03,0x83,0x43,0xC3,0x23,0xA3,0x63,0xE3,0x13,0x93,0x53,0xD3,0x33,0xB3,0x73,0xF3, |
659b92488061
ff_reverse to utils.c patch by (Roine Gustafsson )roine users.sourceforge net)
michael
parents:
2637
diff
changeset
|
66 0x0B,0x8B,0x4B,0xCB,0x2B,0xAB,0x6B,0xEB,0x1B,0x9B,0x5B,0xDB,0x3B,0xBB,0x7B,0xFB, |
659b92488061
ff_reverse to utils.c patch by (Roine Gustafsson )roine users.sourceforge net)
michael
parents:
2637
diff
changeset
|
67 0x07,0x87,0x47,0xC7,0x27,0xA7,0x67,0xE7,0x17,0x97,0x57,0xD7,0x37,0xB7,0x77,0xF7, |
659b92488061
ff_reverse to utils.c patch by (Roine Gustafsson )roine users.sourceforge net)
michael
parents:
2637
diff
changeset
|
68 0x0F,0x8F,0x4F,0xCF,0x2F,0xAF,0x6F,0xEF,0x1F,0x9F,0x5F,0xDF,0x3F,0xBF,0x7F,0xFF, |
659b92488061
ff_reverse to utils.c patch by (Roine Gustafsson )roine users.sourceforge net)
michael
parents:
2637
diff
changeset
|
69 }; |
659b92488061
ff_reverse to utils.c patch by (Roine Gustafsson )roine users.sourceforge net)
michael
parents:
2637
diff
changeset
|
70 |
2806 | 71 static int volatile entangled_thread_counter=0; |
72 | |
2231 | 73 void avcodec_default_free_buffers(AVCodecContext *s); |
1994 | 74 |
862 | 75 void *av_mallocz(unsigned int size) |
394 | 76 { |
77 void *ptr; | |
908 | 78 |
394 | 79 ptr = av_malloc(size); |
80 if (!ptr) | |
81 return NULL; | |
82 memset(ptr, 0, size); | |
83 return ptr; | |
84 } | |
85 | |
1031
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
86 char *av_strdup(const char *s) |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
87 { |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
88 char *ptr; |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
89 int len; |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
90 len = strlen(s) + 1; |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
91 ptr = av_malloc(len); |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
92 if (!ptr) |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
93 return NULL; |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
94 memcpy(ptr, s, len); |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
95 return ptr; |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
96 } |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
97 |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
98 /** |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
99 * realloc which does nothing if the block is large enough |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
100 */ |
1057 | 101 void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size) |
1031
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
102 { |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
103 if(min_size < *size) |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
104 return ptr; |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
105 |
2422 | 106 *size= FFMAX(17*min_size/16 + 32, min_size); |
1031
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
107 |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
108 return av_realloc(ptr, *size); |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
109 } |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
110 |
19de1445beb2
use av_malloc() functions - added av_strdup and av_realloc()
bellard
parents:
998
diff
changeset
|
111 |
902
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
112 static unsigned int last_static = 0; |
1900
5cde80c5d929
static allocation rewrite (old code was plain a broken mess)
michael
parents:
1858
diff
changeset
|
113 static unsigned int allocated_static = 0; |
5cde80c5d929
static allocation rewrite (old code was plain a broken mess)
michael
parents:
1858
diff
changeset
|
114 static void** array_static = NULL; |
5cde80c5d929
static allocation rewrite (old code was plain a broken mess)
michael
parents:
1858
diff
changeset
|
115 |
5cde80c5d929
static allocation rewrite (old code was plain a broken mess)
michael
parents:
1858
diff
changeset
|
116 /** |
5cde80c5d929
static allocation rewrite (old code was plain a broken mess)
michael
parents:
1858
diff
changeset
|
117 * allocation of static arrays - do not use for normal allocation. |
5cde80c5d929
static allocation rewrite (old code was plain a broken mess)
michael
parents:
1858
diff
changeset
|
118 */ |
5cde80c5d929
static allocation rewrite (old code was plain a broken mess)
michael
parents:
1858
diff
changeset
|
119 void *av_mallocz_static(unsigned int size) |
902
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
120 { |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
121 void *ptr = av_mallocz(size); |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
122 |
1900
5cde80c5d929
static allocation rewrite (old code was plain a broken mess)
michael
parents:
1858
diff
changeset
|
123 if(ptr){ |
1901 | 124 array_static =av_fast_realloc(array_static, &allocated_static, sizeof(void*)*(last_static+1)); |
2422 | 125 if(!array_static) |
126 return NULL; | |
1900
5cde80c5d929
static allocation rewrite (old code was plain a broken mess)
michael
parents:
1858
diff
changeset
|
127 array_static[last_static++] = ptr; |
902
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
128 } |
1900
5cde80c5d929
static allocation rewrite (old code was plain a broken mess)
michael
parents:
1858
diff
changeset
|
129 |
902
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
130 return ptr; |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
131 } |
1900
5cde80c5d929
static allocation rewrite (old code was plain a broken mess)
michael
parents:
1858
diff
changeset
|
132 |
5cde80c5d929
static allocation rewrite (old code was plain a broken mess)
michael
parents:
1858
diff
changeset
|
133 /** |
2370
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2362
diff
changeset
|
134 * same as above, but does realloc |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2362
diff
changeset
|
135 */ |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2362
diff
changeset
|
136 |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2362
diff
changeset
|
137 void *av_realloc_static(void *ptr, unsigned int size) |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2362
diff
changeset
|
138 { |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2362
diff
changeset
|
139 int i; |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2362
diff
changeset
|
140 if(!ptr) |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2362
diff
changeset
|
141 return av_mallocz_static(size); |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2362
diff
changeset
|
142 /* Look for the old ptr */ |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2362
diff
changeset
|
143 for(i = 0; i < last_static; i++) { |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2362
diff
changeset
|
144 if(array_static[i] == ptr) { |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2362
diff
changeset
|
145 array_static[i] = av_realloc(array_static[i], size); |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2362
diff
changeset
|
146 return array_static[i]; |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2362
diff
changeset
|
147 } |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2362
diff
changeset
|
148 } |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2362
diff
changeset
|
149 return NULL; |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2362
diff
changeset
|
150 |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2362
diff
changeset
|
151 } |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2362
diff
changeset
|
152 |
26560d4fdb1f
Memory leak fix patch by (Burkhard Plaum <plaum >at< ipf.uni-stuttgart )dot( de>)
michael
parents:
2362
diff
changeset
|
153 /** |
1900
5cde80c5d929
static allocation rewrite (old code was plain a broken mess)
michael
parents:
1858
diff
changeset
|
154 * free all static arrays and reset pointers to 0. |
5cde80c5d929
static allocation rewrite (old code was plain a broken mess)
michael
parents:
1858
diff
changeset
|
155 */ |
1282 | 156 void av_free_static(void) |
902
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
157 { |
1900
5cde80c5d929
static allocation rewrite (old code was plain a broken mess)
michael
parents:
1858
diff
changeset
|
158 while(last_static){ |
5cde80c5d929
static allocation rewrite (old code was plain a broken mess)
michael
parents:
1858
diff
changeset
|
159 av_freep(&array_static[--last_static]); |
902
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
160 } |
1900
5cde80c5d929
static allocation rewrite (old code was plain a broken mess)
michael
parents:
1858
diff
changeset
|
161 av_freep(&array_static); |
902
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
162 } |
6acc8394960d
* two functions to handle allocation of static data more simple
kabi
parents:
862
diff
changeset
|
163 |
1854 | 164 /** |
165 * Frees memory and sets the pointer to NULL. | |
166 * @param arg pointer to the pointer which should be freed | |
167 */ | |
168 void av_freep(void *arg) | |
400 | 169 { |
1854 | 170 void **ptr= (void**)arg; |
400 | 171 av_free(*ptr); |
172 *ptr = NULL; | |
173 } | |
174 | |
0 | 175 /* encoder management */ |
2169
db8baace74d8
Minor Patch for shared libs on Mac OSX by (Bill May <wmay at cisco dot com>)
michael
parents:
2167
diff
changeset
|
176 AVCodec *first_avcodec = NULL; |
0 | 177 |
178 void register_avcodec(AVCodec *format) | |
179 { | |
180 AVCodec **p; | |
181 p = &first_avcodec; | |
182 while (*p != NULL) p = &(*p)->next; | |
183 *p = format; | |
184 format->next = NULL; | |
185 } | |
186 | |
2270 | 187 void avcodec_set_dimensions(AVCodecContext *s, int width, int height){ |
188 s->coded_width = width; | |
189 s->coded_height= height; | |
190 s->width = -((-width )>>s->lowres); | |
191 s->height= -((-height)>>s->lowres); | |
192 } | |
193 | |
1214 | 194 typedef struct InternalBuffer{ |
903 | 195 int last_pic_num; |
1214 | 196 uint8_t *base[4]; |
903 | 197 uint8_t *data[4]; |
1588
de5e2acd0f80
initalize various uninitalized variables and avoid coded_picture_number as its not always correct (later should be reversed after fixing the picture_number mess)
michael
parents:
1585
diff
changeset
|
198 int linesize[4]; |
1214 | 199 }InternalBuffer; |
200 | |
201 #define INTERNAL_BUFFER_SIZE 32 | |
903 | 202 |
1538 | 203 #define ALIGN(x, a) (((x)+(a)-1)&~((a)-1)) |
204 | |
205 void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){ | |
206 int w_align= 1; | |
207 int h_align= 1; | |
208 | |
209 switch(s->pix_fmt){ | |
210 case PIX_FMT_YUV420P: | |
211 case PIX_FMT_YUV422: | |
2137
ef47c0b1ff28
UYVY support patch by ("Todd.Kirby" <doubleshot at pacbell dot net>)
michael
parents:
2125
diff
changeset
|
212 case PIX_FMT_UYVY422: |
1538 | 213 case PIX_FMT_YUV422P: |
214 case PIX_FMT_YUV444P: | |
215 case PIX_FMT_GRAY8: | |
216 case PIX_FMT_YUVJ420P: | |
217 case PIX_FMT_YUVJ422P: | |
218 case PIX_FMT_YUVJ444P: | |
219 w_align= 16; //FIXME check for non mpeg style codecs and use less alignment | |
220 h_align= 16; | |
221 break; | |
222 case PIX_FMT_YUV411P: | |
2309 | 223 case PIX_FMT_UYVY411: |
1538 | 224 w_align=32; |
225 h_align=8; | |
226 break; | |
227 case PIX_FMT_YUV410P: | |
228 if(s->codec_id == CODEC_ID_SVQ1){ | |
229 w_align=64; | |
230 h_align=64; | |
231 } | |
2104 | 232 case PIX_FMT_RGB555: |
233 if(s->codec_id == CODEC_ID_RPZA){ | |
234 w_align=4; | |
235 h_align=4; | |
236 } | |
237 case PIX_FMT_PAL8: | |
238 if(s->codec_id == CODEC_ID_SMC){ | |
239 w_align=4; | |
240 h_align=4; | |
241 } | |
1538 | 242 break; |
2418
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
243 case PIX_FMT_BGR24: |
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
244 if((s->codec_id == CODEC_ID_MSZH) || (s->codec_id == CODEC_ID_ZLIB)){ |
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
245 w_align=4; |
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
246 h_align=4; |
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
247 } |
82af834636c2
Check pointers before writing to memory, fix possible integer overflows
rtognimp
parents:
2398
diff
changeset
|
248 break; |
1538 | 249 default: |
250 w_align= 1; | |
251 h_align= 1; | |
252 break; | |
253 } | |
254 | |
255 *width = ALIGN(*width , w_align); | |
256 *height= ALIGN(*height, h_align); | |
257 } | |
258 | |
2422 | 259 int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h){ |
260 if((int)w>0 && (int)h>0 && (w+128)*(uint64_t)(h+128) < INT_MAX/4) | |
261 return 0; | |
262 | |
263 av_log(av_log_ctx, AV_LOG_ERROR, "picture size invalid (%ux%u)\n", w, h); | |
264 return -1; | |
265 } | |
266 | |
925 | 267 int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){ |
903 | 268 int i; |
1538 | 269 int w= s->width; |
270 int h= s->height; | |
1214 | 271 InternalBuffer *buf; |
1588
de5e2acd0f80
initalize various uninitalized variables and avoid coded_picture_number as its not always correct (later should be reversed after fixing the picture_number mess)
michael
parents:
1585
diff
changeset
|
272 int *picture_number; |
2422 | 273 |
924 | 274 assert(pic->data[0]==NULL); |
1214 | 275 assert(INTERNAL_BUFFER_SIZE > s->internal_buffer_count); |
903 | 276 |
2422 | 277 if(avcodec_check_dimensions(s,w,h)) |
278 return -1; | |
279 | |
1214 | 280 if(s->internal_buffer==NULL){ |
281 s->internal_buffer= av_mallocz(INTERNAL_BUFFER_SIZE*sizeof(InternalBuffer)); | |
282 } | |
283 #if 0 | |
284 s->internal_buffer= av_fast_realloc( | |
285 s->internal_buffer, | |
286 &s->internal_buffer_size, | |
287 sizeof(InternalBuffer)*FFMAX(99, s->internal_buffer_count+1)/*FIXME*/ | |
288 ); | |
289 #endif | |
290 | |
291 buf= &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count]; | |
1588
de5e2acd0f80
initalize various uninitalized variables and avoid coded_picture_number as its not always correct (later should be reversed after fixing the picture_number mess)
michael
parents:
1585
diff
changeset
|
292 picture_number= &(((InternalBuffer*)s->internal_buffer)[INTERNAL_BUFFER_SIZE-1]).last_pic_num; //FIXME ugly hack |
de5e2acd0f80
initalize various uninitalized variables and avoid coded_picture_number as its not always correct (later should be reversed after fixing the picture_number mess)
michael
parents:
1585
diff
changeset
|
293 (*picture_number)++; |
de5e2acd0f80
initalize various uninitalized variables and avoid coded_picture_number as its not always correct (later should be reversed after fixing the picture_number mess)
michael
parents:
1585
diff
changeset
|
294 |
1214 | 295 if(buf->base[0]){ |
1588
de5e2acd0f80
initalize various uninitalized variables and avoid coded_picture_number as its not always correct (later should be reversed after fixing the picture_number mess)
michael
parents:
1585
diff
changeset
|
296 pic->age= *picture_number - buf->last_pic_num; |
de5e2acd0f80
initalize various uninitalized variables and avoid coded_picture_number as its not always correct (later should be reversed after fixing the picture_number mess)
michael
parents:
1585
diff
changeset
|
297 buf->last_pic_num= *picture_number; |
903 | 298 }else{ |
1538 | 299 int h_chroma_shift, v_chroma_shift; |
2324 | 300 int pixel_size; |
903 | 301 |
302 avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift); | |
1538 | 303 |
903 | 304 switch(s->pix_fmt){ |
1291 | 305 case PIX_FMT_RGB555: |
306 case PIX_FMT_RGB565: | |
903 | 307 case PIX_FMT_YUV422: |
2137
ef47c0b1ff28
UYVY support patch by ("Todd.Kirby" <doubleshot at pacbell dot net>)
michael
parents:
2125
diff
changeset
|
308 case PIX_FMT_UYVY422: |
903 | 309 pixel_size=2; |
310 break; | |
311 case PIX_FMT_RGB24: | |
312 case PIX_FMT_BGR24: | |
313 pixel_size=3; | |
314 break; | |
315 case PIX_FMT_RGBA32: | |
316 pixel_size=4; | |
317 break; | |
318 default: | |
319 pixel_size=1; | |
320 } | |
1538 | 321 |
322 avcodec_align_dimensions(s, &w, &h); | |
323 | |
903 | 324 if(!(s->flags&CODEC_FLAG_EMU_EDGE)){ |
325 w+= EDGE_WIDTH*2; | |
326 h+= EDGE_WIDTH*2; | |
327 } | |
328 | |
1214 | 329 buf->last_pic_num= -256*256*256*64; |
903 | 330 |
331 for(i=0; i<3; i++){ | |
1165 | 332 const int h_shift= i==0 ? 0 : h_chroma_shift; |
333 const int v_shift= i==0 ? 0 : v_chroma_shift; | |
903 | 334 |
1798
a3da4b429984
ppc chroma mess workaround (real bug is that the motion compensation code assumes that 2*uvlinesize == linesize and fixing this would mean a slowdown)
michael
parents:
1776
diff
changeset
|
335 //FIXME next ensures that linesize= 2^x uvlinesize, thats needed because some MC code assumes it |
2324 | 336 buf->linesize[i]= ALIGN(pixel_size*w>>h_shift, STRIDE_ALIGN<<(h_chroma_shift-h_shift)); |
903 | 337 |
2426
1ee03f2a6cd5
av_malloc vs av_mallocz patch by (Kurosu <kurosu inforezo org>)
michael
parents:
2423
diff
changeset
|
338 buf->base[i]= av_malloc((buf->linesize[i]*h>>v_shift)+16); //FIXME 16 |
1214 | 339 if(buf->base[i]==NULL) return -1; |
1588
de5e2acd0f80
initalize various uninitalized variables and avoid coded_picture_number as its not always correct (later should be reversed after fixing the picture_number mess)
michael
parents:
1585
diff
changeset
|
340 memset(buf->base[i], 128, buf->linesize[i]*h>>v_shift); |
903 | 341 |
342 if(s->flags&CODEC_FLAG_EMU_EDGE) | |
1214 | 343 buf->data[i] = buf->base[i]; |
903 | 344 else |
2324 | 345 buf->data[i] = buf->base[i] + ALIGN((buf->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift), STRIDE_ALIGN); |
903 | 346 } |
347 pic->age= 256*256*256*64; | |
348 } | |
1588
de5e2acd0f80
initalize various uninitalized variables and avoid coded_picture_number as its not always correct (later should be reversed after fixing the picture_number mess)
michael
parents:
1585
diff
changeset
|
349 pic->type= FF_BUFFER_TYPE_INTERNAL; |
903 | 350 |
1214 | 351 for(i=0; i<4; i++){ |
352 pic->base[i]= buf->base[i]; | |
353 pic->data[i]= buf->data[i]; | |
1588
de5e2acd0f80
initalize various uninitalized variables and avoid coded_picture_number as its not always correct (later should be reversed after fixing the picture_number mess)
michael
parents:
1585
diff
changeset
|
354 pic->linesize[i]= buf->linesize[i]; |
1214 | 355 } |
356 s->internal_buffer_count++; | |
357 | |
903 | 358 return 0; |
359 } | |
360 | |
925 | 361 void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){ |
903 | 362 int i; |
1214 | 363 InternalBuffer *buf, *last, temp; |
364 | |
924 | 365 assert(pic->type==FF_BUFFER_TYPE_INTERNAL); |
1396 | 366 assert(s->internal_buffer_count); |
1214 | 367 |
1455 | 368 buf = NULL; /* avoids warning */ |
1214 | 369 for(i=0; i<s->internal_buffer_count; i++){ //just 3-5 checks so is not worth to optimize |
370 buf= &((InternalBuffer*)s->internal_buffer)[i]; | |
371 if(buf->data[0] == pic->data[0]) | |
372 break; | |
373 } | |
374 assert(i < s->internal_buffer_count); | |
375 s->internal_buffer_count--; | |
376 last = &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count]; | |
377 | |
378 temp= *buf; | |
379 *buf= *last; | |
380 *last= temp; | |
381 | |
382 for(i=0; i<3; i++){ | |
903 | 383 pic->data[i]=NULL; |
1214 | 384 // pic->base[i]=NULL; |
385 } | |
903 | 386 //printf("R%X\n", pic->opaque); |
387 } | |
388 | |
1630 | 389 int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){ |
390 AVFrame temp_pic; | |
391 int i; | |
392 | |
393 /* If no picture return a new buffer */ | |
394 if(pic->data[0] == NULL) { | |
395 /* We will copy from buffer, so must be readable */ | |
396 pic->buffer_hints |= FF_BUFFER_HINTS_READABLE; | |
397 return s->get_buffer(s, pic); | |
398 } | |
399 | |
400 /* If internal buffer type return the same buffer */ | |
401 if(pic->type == FF_BUFFER_TYPE_INTERNAL) | |
402 return 0; | |
403 | |
404 /* | |
405 * Not internal type and reget_buffer not overridden, emulate cr buffer | |
406 */ | |
407 temp_pic = *pic; | |
408 for(i = 0; i < 4; i++) | |
409 pic->data[i] = pic->base[i] = NULL; | |
410 pic->opaque = NULL; | |
411 /* Allocate new frame */ | |
412 if (s->get_buffer(s, pic)) | |
413 return -1; | |
414 /* Copy image data from old buffer to new buffer */ | |
415 img_copy((AVPicture*)pic, (AVPicture*)&temp_pic, s->pix_fmt, s->width, | |
416 s->height); | |
417 s->release_buffer(s, &temp_pic); // Release old frame | |
418 return 0; | |
419 } | |
420 | |
1799 | 421 int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count){ |
422 int i; | |
423 | |
424 for(i=0; i<count; i++){ | |
425 int r= func(c, arg[i]); | |
426 if(ret) ret[i]= r; | |
427 } | |
428 return 0; | |
429 } | |
430 | |
1858 | 431 enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt){ |
998 | 432 return fmt[0]; |
433 } | |
434 | |
1856 | 435 static const char* context_to_name(void* ptr) { |
436 AVCodecContext *avc= ptr; | |
437 | |
438 if(avc && avc->codec && avc->codec->name) | |
439 return avc->codec->name; | |
440 else | |
441 return "NULL"; | |
442 } | |
443 | |
444 static AVClass av_codec_context_class = { "AVCodecContext", context_to_name }; | |
445 | |
681 | 446 void avcodec_get_context_defaults(AVCodecContext *s){ |
1831
cd2d7fcfab7a
use AVFrame.pts=AV_NOPTS_VALUE instead of AVFrame.pts=0
michael
parents:
1823
diff
changeset
|
447 memset(s, 0, sizeof(AVCodecContext)); |
cd2d7fcfab7a
use AVFrame.pts=AV_NOPTS_VALUE instead of AVFrame.pts=0
michael
parents:
1823
diff
changeset
|
448 |
1856 | 449 s->av_class= &av_codec_context_class; |
685 | 450 s->bit_rate= 800*1000; |
451 s->bit_rate_tolerance= s->bit_rate*10; | |
681 | 452 s->qmin= 2; |
453 s->qmax= 31; | |
2494
36d70fbb31c5
mb_lmin/max to limit the per mb quality for the ratecontrol independant from the frame limits
michael
parents:
2488
diff
changeset
|
454 s->mb_lmin= FF_QP2LAMBDA * 2; |
36d70fbb31c5
mb_lmin/max to limit the per mb quality for the ratecontrol independant from the frame limits
michael
parents:
2488
diff
changeset
|
455 s->mb_lmax= FF_QP2LAMBDA * 31; |
681 | 456 s->rc_eq= "tex^qComp"; |
457 s->qcompress= 0.5; | |
685 | 458 s->max_qdiff= 3; |
459 s->b_quant_factor=1.25; | |
460 s->b_quant_offset=1.25; | |
686
83d2c9d50d7d
fixing i_quant_factor, this should finally fix the bitrate bug with ffserver hopefully
michaelni
parents:
685
diff
changeset
|
461 s->i_quant_factor=-0.8; |
685 | 462 s->i_quant_offset=0.0; |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
742
diff
changeset
|
463 s->error_concealment= 3; |
762 | 464 s->error_resilience= 1; |
745
25d7fb7c89be
better/cleaner error resilience (done in a 2nd pass after decoding)
michaelni
parents:
742
diff
changeset
|
465 s->workaround_bugs= FF_BUG_AUTODETECT; |
2637 | 466 s->time_base= (AVRational){0,1}; |
762 | 467 s->gop_size= 50; |
468 s->me_method= ME_EPZS; | |
903 | 469 s->get_buffer= avcodec_default_get_buffer; |
470 s->release_buffer= avcodec_default_release_buffer; | |
998 | 471 s->get_format= avcodec_default_get_format; |
1799 | 472 s->execute= avcodec_default_execute; |
473 s->thread_count=1; | |
954 | 474 s->me_subpel_quality=8; |
1505
010f76d07a27
use lagrange multipler instead of qp for ratecontrol, this may break some things, tell me ASAP if u notice anything broken
michaelni
parents:
1456
diff
changeset
|
475 s->lmin= FF_QP2LAMBDA * s->qmin; |
010f76d07a27
use lagrange multipler instead of qp for ratecontrol, this may break some things, tell me ASAP if u notice anything broken
michaelni
parents:
1456
diff
changeset
|
476 s->lmax= FF_QP2LAMBDA * s->qmax; |
1548 | 477 s->sample_aspect_ratio= (AVRational){0,1}; |
1730 | 478 s->ildct_cmp= FF_CMP_VSAD; |
2167 | 479 s->profile= FF_PROFILE_UNKNOWN; |
480 s->level= FF_LEVEL_UNKNOWN; | |
2584 | 481 s->me_penalty_compensation= 256; |
2635 | 482 s->pix_fmt= PIX_FMT_NONE; |
1150 | 483 |
484 s->intra_quant_bias= FF_DEFAULT_QUANT_BIAS; | |
485 s->inter_quant_bias= FF_DEFAULT_QUANT_BIAS; | |
1585
6b224ca24033
revised palette API, courtesy of Roberto Togni (rtogni at freemail.it)
melanson
parents:
1582
diff
changeset
|
486 s->palctrl = NULL; |
1630 | 487 s->reget_buffer= avcodec_default_reget_buffer; |
681 | 488 } |
489 | |
490 /** | |
491 * allocates a AVCodecContext and set it to defaults. | |
492 * this can be deallocated by simply calling free() | |
493 */ | |
703 | 494 AVCodecContext *avcodec_alloc_context(void){ |
1831
cd2d7fcfab7a
use AVFrame.pts=AV_NOPTS_VALUE instead of AVFrame.pts=0
michael
parents:
1823
diff
changeset
|
495 AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext)); |
681 | 496 |
497 if(avctx==NULL) return NULL; | |
498 | |
499 avcodec_get_context_defaults(avctx); | |
500 | |
501 return avctx; | |
502 } | |
503 | |
1831
cd2d7fcfab7a
use AVFrame.pts=AV_NOPTS_VALUE instead of AVFrame.pts=0
michael
parents:
1823
diff
changeset
|
504 void avcodec_get_frame_defaults(AVFrame *pic){ |
cd2d7fcfab7a
use AVFrame.pts=AV_NOPTS_VALUE instead of AVFrame.pts=0
michael
parents:
1823
diff
changeset
|
505 memset(pic, 0, sizeof(AVFrame)); |
cd2d7fcfab7a
use AVFrame.pts=AV_NOPTS_VALUE instead of AVFrame.pts=0
michael
parents:
1823
diff
changeset
|
506 |
cd2d7fcfab7a
use AVFrame.pts=AV_NOPTS_VALUE instead of AVFrame.pts=0
michael
parents:
1823
diff
changeset
|
507 pic->pts= AV_NOPTS_VALUE; |
2488 | 508 pic->key_frame= 1; |
1831
cd2d7fcfab7a
use AVFrame.pts=AV_NOPTS_VALUE instead of AVFrame.pts=0
michael
parents:
1823
diff
changeset
|
509 } |
cd2d7fcfab7a
use AVFrame.pts=AV_NOPTS_VALUE instead of AVFrame.pts=0
michael
parents:
1823
diff
changeset
|
510 |
903 | 511 /** |
925 | 512 * allocates a AVPFrame and set it to defaults. |
903 | 513 * this can be deallocated by simply calling free() |
514 */ | |
925 | 515 AVFrame *avcodec_alloc_frame(void){ |
1831
cd2d7fcfab7a
use AVFrame.pts=AV_NOPTS_VALUE instead of AVFrame.pts=0
michael
parents:
1823
diff
changeset
|
516 AVFrame *pic= av_malloc(sizeof(AVFrame)); |
cd2d7fcfab7a
use AVFrame.pts=AV_NOPTS_VALUE instead of AVFrame.pts=0
michael
parents:
1823
diff
changeset
|
517 |
cd2d7fcfab7a
use AVFrame.pts=AV_NOPTS_VALUE instead of AVFrame.pts=0
michael
parents:
1823
diff
changeset
|
518 if(pic==NULL) return NULL; |
cd2d7fcfab7a
use AVFrame.pts=AV_NOPTS_VALUE instead of AVFrame.pts=0
michael
parents:
1823
diff
changeset
|
519 |
cd2d7fcfab7a
use AVFrame.pts=AV_NOPTS_VALUE instead of AVFrame.pts=0
michael
parents:
1823
diff
changeset
|
520 avcodec_get_frame_defaults(pic); |
903 | 521 |
522 return pic; | |
523 } | |
524 | |
0 | 525 int avcodec_open(AVCodecContext *avctx, AVCodec *codec) |
526 { | |
2806 | 527 int ret= -1; |
528 | |
529 entangled_thread_counter++; | |
530 if(entangled_thread_counter != 1){ | |
531 av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n"); | |
532 goto end; | |
533 } | |
0 | 534 |
1456
670fca257a69
detect avcodec_open() on an already opened AVCodecContext
michaelni
parents:
1455
diff
changeset
|
535 if(avctx->codec) |
2806 | 536 goto end; |
1456
670fca257a69
detect avcodec_open() on an already opened AVCodecContext
michaelni
parents:
1455
diff
changeset
|
537 |
0 | 538 avctx->codec = codec; |
927 | 539 avctx->codec_id = codec->id; |
0 | 540 avctx->frame_number = 0; |
374
02147e22f8c8
* Don't allocate 0 bytes of memory. It upsets electricFence!
philipjsg
parents:
362
diff
changeset
|
541 if (codec->priv_data_size > 0) { |
02147e22f8c8
* Don't allocate 0 bytes of memory. It upsets electricFence!
philipjsg
parents:
362
diff
changeset
|
542 avctx->priv_data = av_mallocz(codec->priv_data_size); |
02147e22f8c8
* Don't allocate 0 bytes of memory. It upsets electricFence!
philipjsg
parents:
362
diff
changeset
|
543 if (!avctx->priv_data) |
2806 | 544 goto end; |
374
02147e22f8c8
* Don't allocate 0 bytes of memory. It upsets electricFence!
philipjsg
parents:
362
diff
changeset
|
545 } else { |
02147e22f8c8
* Don't allocate 0 bytes of memory. It upsets electricFence!
philipjsg
parents:
362
diff
changeset
|
546 avctx->priv_data = NULL; |
02147e22f8c8
* Don't allocate 0 bytes of memory. It upsets electricFence!
philipjsg
parents:
362
diff
changeset
|
547 } |
2270 | 548 |
549 if(avctx->coded_width && avctx->coded_height) | |
550 avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height); | |
551 else if(avctx->width && avctx->height) | |
552 avcodec_set_dimensions(avctx, avctx->width, avctx->height); | |
553 | |
2422 | 554 if((avctx->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height)){ |
555 av_freep(&avctx->priv_data); | |
2806 | 556 goto end; |
2422 | 557 } |
558 | |
0 | 559 ret = avctx->codec->init(avctx); |
560 if (ret < 0) { | |
394 | 561 av_freep(&avctx->priv_data); |
2806 | 562 goto end; |
0 | 563 } |
2806 | 564 ret=0; |
565 end: | |
566 entangled_thread_counter--; | |
567 return ret; | |
0 | 568 } |
569 | |
1064 | 570 int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, |
0 | 571 const short *samples) |
572 { | |
2422 | 573 if(buf_size < FF_MIN_BUFFER_SIZE && 0){ |
574 av_log(avctx, AV_LOG_ERROR, "buffer smaller then minimum size\n"); | |
575 return -1; | |
576 } | |
2091 | 577 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || samples){ |
578 int ret = avctx->codec->encode(avctx, buf, buf_size, (void *)samples); | |
579 avctx->frame_number++; | |
580 return ret; | |
581 }else | |
582 return 0; | |
0 | 583 } |
584 | |
1064 | 585 int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size, |
925 | 586 const AVFrame *pict) |
0 | 587 { |
2422 | 588 if(buf_size < FF_MIN_BUFFER_SIZE){ |
589 av_log(avctx, AV_LOG_ERROR, "buffer smaller then minimum size\n"); | |
590 return -1; | |
591 } | |
592 if(avcodec_check_dimensions(avctx,avctx->width,avctx->height)) | |
593 return -1; | |
2091 | 594 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || pict){ |
595 int ret = avctx->codec->encode(avctx, buf, buf_size, (void *)pict); | |
596 avctx->frame_number++; | |
2764 | 597 emms_c(); //needed to avoid an emms_c() call before every return; |
814 | 598 |
2091 | 599 return ret; |
600 }else | |
601 return 0; | |
0 | 602 } |
603 | |
2756 | 604 int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, |
605 const AVSubtitle *sub) | |
606 { | |
607 int ret; | |
608 ret = avctx->codec->encode(avctx, buf, buf_size, (void *)sub); | |
609 avctx->frame_number++; | |
610 return ret; | |
611 } | |
612 | |
1249 | 613 /** |
614 * decode a frame. | |
615 * @param buf bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE larger then the actual read bytes | |
616 * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end | |
617 * @param buf_size the size of the buffer in bytes | |
618 * @param got_picture_ptr zero if no frame could be decompressed, Otherwise, it is non zero | |
619 * @return -1 if error, otherwise return the number of | |
620 * bytes used. | |
621 */ | |
925 | 622 int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture, |
0 | 623 int *got_picture_ptr, |
1064 | 624 uint8_t *buf, int buf_size) |
0 | 625 { |
626 int ret; | |
903 | 627 |
2028 | 628 *got_picture_ptr= 0; |
2422 | 629 if((avctx->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height)) |
630 return -1; | |
2453 | 631 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){ |
632 ret = avctx->codec->decode(avctx, picture, got_picture_ptr, | |
633 buf, buf_size); | |
814 | 634 |
2764 | 635 emms_c(); //needed to avoid an emms_c() call before every return; |
903 | 636 |
2453 | 637 if (*got_picture_ptr) |
638 avctx->frame_number++; | |
639 }else | |
640 ret= 0; | |
641 | |
0 | 642 return ret; |
643 } | |
644 | |
645 /* decode an audio frame. return -1 if error, otherwise return the | |
646 *number of bytes used. If no frame could be decompressed, | |
647 *frame_size_ptr is zero. Otherwise, it is the decompressed frame | |
648 *size in BYTES. */ | |
1064 | 649 int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples, |
0 | 650 int *frame_size_ptr, |
1064 | 651 uint8_t *buf, int buf_size) |
0 | 652 { |
653 int ret; | |
654 | |
2028 | 655 *frame_size_ptr= 0; |
2791 | 656 if((avctx->codec->capabilities & CODEC_CAP_DELAY) || buf_size){ |
657 ret = avctx->codec->decode(avctx, samples, frame_size_ptr, | |
658 buf, buf_size); | |
659 avctx->frame_number++; | |
660 }else | |
661 ret= 0; | |
0 | 662 return ret; |
663 } | |
664 | |
2756 | 665 /* decode a subtitle message. return -1 if error, otherwise return the |
666 *number of bytes used. If no subtitle could be decompressed, | |
667 *got_sub_ptr is zero. Otherwise, the subtitle is stored in *sub. */ | |
668 int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub, | |
669 int *got_sub_ptr, | |
670 const uint8_t *buf, int buf_size) | |
671 { | |
672 int ret; | |
673 | |
674 *got_sub_ptr = 0; | |
675 ret = avctx->codec->decode(avctx, sub, got_sub_ptr, | |
676 (uint8_t *)buf, buf_size); | |
677 if (*got_sub_ptr) | |
678 avctx->frame_number++; | |
679 return ret; | |
680 } | |
681 | |
0 | 682 int avcodec_close(AVCodecContext *avctx) |
683 { | |
2806 | 684 entangled_thread_counter++; |
685 if(entangled_thread_counter != 1){ | |
686 av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n"); | |
687 entangled_thread_counter--; | |
688 return -1; | |
689 } | |
690 | |
0 | 691 if (avctx->codec->close) |
692 avctx->codec->close(avctx); | |
1994 | 693 avcodec_default_free_buffers(avctx); |
394 | 694 av_freep(&avctx->priv_data); |
0 | 695 avctx->codec = NULL; |
2806 | 696 entangled_thread_counter--; |
0 | 697 return 0; |
698 } | |
699 | |
700 AVCodec *avcodec_find_encoder(enum CodecID id) | |
701 { | |
702 AVCodec *p; | |
703 p = first_avcodec; | |
704 while (p) { | |
705 if (p->encode != NULL && p->id == id) | |
706 return p; | |
707 p = p->next; | |
708 } | |
709 return NULL; | |
710 } | |
711 | |
177 | 712 AVCodec *avcodec_find_encoder_by_name(const char *name) |
713 { | |
714 AVCodec *p; | |
715 p = first_avcodec; | |
716 while (p) { | |
717 if (p->encode != NULL && strcmp(name,p->name) == 0) | |
718 return p; | |
719 p = p->next; | |
720 } | |
721 return NULL; | |
722 } | |
723 | |
0 | 724 AVCodec *avcodec_find_decoder(enum CodecID id) |
725 { | |
726 AVCodec *p; | |
727 p = first_avcodec; | |
728 while (p) { | |
729 if (p->decode != NULL && p->id == id) | |
730 return p; | |
731 p = p->next; | |
732 } | |
733 return NULL; | |
734 } | |
735 | |
736 AVCodec *avcodec_find_decoder_by_name(const char *name) | |
737 { | |
738 AVCodec *p; | |
739 p = first_avcodec; | |
740 while (p) { | |
741 if (p->decode != NULL && strcmp(name,p->name) == 0) | |
742 return p; | |
743 p = p->next; | |
744 } | |
745 return NULL; | |
746 } | |
747 | |
748 void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) | |
749 { | |
750 const char *codec_name; | |
751 AVCodec *p; | |
752 char buf1[32]; | |
337 | 753 char channels_str[100]; |
92 | 754 int bitrate; |
0 | 755 |
756 if (encode) | |
757 p = avcodec_find_encoder(enc->codec_id); | |
758 else | |
759 p = avcodec_find_decoder(enc->codec_id); | |
760 | |
761 if (p) { | |
762 codec_name = p->name; | |
1449
7fbe89a76b73
update sub_id in mpegaudio decoding (might need same method as MPEG2VIDEO too ?)
bellard
parents:
1396
diff
changeset
|
763 if (!encode && enc->codec_id == CODEC_ID_MP3) { |
7fbe89a76b73
update sub_id in mpegaudio decoding (might need same method as MPEG2VIDEO too ?)
bellard
parents:
1396
diff
changeset
|
764 if (enc->sub_id == 2) |
7fbe89a76b73
update sub_id in mpegaudio decoding (might need same method as MPEG2VIDEO too ?)
bellard
parents:
1396
diff
changeset
|
765 codec_name = "mp2"; |
7fbe89a76b73
update sub_id in mpegaudio decoding (might need same method as MPEG2VIDEO too ?)
bellard
parents:
1396
diff
changeset
|
766 else if (enc->sub_id == 1) |
7fbe89a76b73
update sub_id in mpegaudio decoding (might need same method as MPEG2VIDEO too ?)
bellard
parents:
1396
diff
changeset
|
767 codec_name = "mp1"; |
7fbe89a76b73
update sub_id in mpegaudio decoding (might need same method as MPEG2VIDEO too ?)
bellard
parents:
1396
diff
changeset
|
768 } |
1582
ece0ad14a35d
added fake codec CODEC_ID_MPEG2TS of type CODEC_TYPE_DATA (needed for simpler handling of raw transport streams in ffserver and RTP - better solutions are welcomed)
bellard
parents:
1549
diff
changeset
|
769 } else if (enc->codec_id == CODEC_ID_MPEG2TS) { |
ece0ad14a35d
added fake codec CODEC_ID_MPEG2TS of type CODEC_TYPE_DATA (needed for simpler handling of raw transport streams in ffserver and RTP - better solutions are welcomed)
bellard
parents:
1549
diff
changeset
|
770 /* fake mpeg2 transport stream codec (currently not |
ece0ad14a35d
added fake codec CODEC_ID_MPEG2TS of type CODEC_TYPE_DATA (needed for simpler handling of raw transport streams in ffserver and RTP - better solutions are welcomed)
bellard
parents:
1549
diff
changeset
|
771 registered) */ |
ece0ad14a35d
added fake codec CODEC_ID_MPEG2TS of type CODEC_TYPE_DATA (needed for simpler handling of raw transport streams in ffserver and RTP - better solutions are welcomed)
bellard
parents:
1549
diff
changeset
|
772 codec_name = "mpeg2ts"; |
0 | 773 } else if (enc->codec_name[0] != '\0') { |
774 codec_name = enc->codec_name; | |
775 } else { | |
776 /* output avi tags */ | |
777 if (enc->codec_type == CODEC_TYPE_VIDEO) { | |
778 snprintf(buf1, sizeof(buf1), "%c%c%c%c", | |
779 enc->codec_tag & 0xff, | |
780 (enc->codec_tag >> 8) & 0xff, | |
781 (enc->codec_tag >> 16) & 0xff, | |
782 (enc->codec_tag >> 24) & 0xff); | |
783 } else { | |
784 snprintf(buf1, sizeof(buf1), "0x%04x", enc->codec_tag); | |
785 } | |
786 codec_name = buf1; | |
787 } | |
788 | |
789 switch(enc->codec_type) { | |
790 case CODEC_TYPE_VIDEO: | |
791 snprintf(buf, buf_size, | |
792 "Video: %s%s", | |
1389 | 793 codec_name, enc->mb_decision ? " (hq)" : ""); |
2636
2344c6713011
print pix_fmt if its known instead of if the raw codec is used
michael
parents:
2635
diff
changeset
|
794 if (enc->pix_fmt != PIX_FMT_NONE) { |
55 | 795 snprintf(buf + strlen(buf), buf_size - strlen(buf), |
796 ", %s", | |
988
001b7d3045e5
moved avcodec_get_chroma_sub_sample() to imgconvert.c
bellard
parents:
963
diff
changeset
|
797 avcodec_get_pix_fmt_name(enc->pix_fmt)); |
55 | 798 } |
0 | 799 if (enc->width) { |
800 snprintf(buf + strlen(buf), buf_size - strlen(buf), | |
801 ", %dx%d, %0.2f fps", | |
802 enc->width, enc->height, | |
2637 | 803 1/av_q2d(enc->time_base)); |
0 | 804 } |
741 | 805 if (encode) { |
806 snprintf(buf + strlen(buf), buf_size - strlen(buf), | |
807 ", q=%d-%d", enc->qmin, enc->qmax); | |
808 } | |
92 | 809 bitrate = enc->bit_rate; |
0 | 810 break; |
811 case CODEC_TYPE_AUDIO: | |
812 snprintf(buf, buf_size, | |
813 "Audio: %s", | |
814 codec_name); | |
318
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
815 switch (enc->channels) { |
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
816 case 1: |
337 | 817 strcpy(channels_str, "mono"); |
318
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
818 break; |
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
819 case 2: |
337 | 820 strcpy(channels_str, "stereo"); |
318
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
821 break; |
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
822 case 6: |
337 | 823 strcpy(channels_str, "5:1"); |
318
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
824 break; |
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
825 default: |
2423 | 826 snprintf(channels_str, sizeof(channels_str), "%d channels", enc->channels); |
318
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
827 break; |
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
828 } |
0 | 829 if (enc->sample_rate) { |
830 snprintf(buf + strlen(buf), buf_size - strlen(buf), | |
831 ", %d Hz, %s", | |
832 enc->sample_rate, | |
318
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
833 channels_str); |
0 | 834 } |
318
21697f35a9ca
- Fixed AC3 decoding for 5:1 AC3 streams. Now when calling av_audio_decode for
pulento
parents:
315
diff
changeset
|
835 |
92 | 836 /* for PCM codecs, compute bitrate directly */ |
837 switch(enc->codec_id) { | |
838 case CODEC_ID_PCM_S16LE: | |
839 case CODEC_ID_PCM_S16BE: | |
840 case CODEC_ID_PCM_U16LE: | |
841 case CODEC_ID_PCM_U16BE: | |
94 | 842 bitrate = enc->sample_rate * enc->channels * 16; |
92 | 843 break; |
844 case CODEC_ID_PCM_S8: | |
845 case CODEC_ID_PCM_U8: | |
846 case CODEC_ID_PCM_ALAW: | |
847 case CODEC_ID_PCM_MULAW: | |
94 | 848 bitrate = enc->sample_rate * enc->channels * 8; |
92 | 849 break; |
850 default: | |
851 bitrate = enc->bit_rate; | |
852 break; | |
853 } | |
0 | 854 break; |
1582
ece0ad14a35d
added fake codec CODEC_ID_MPEG2TS of type CODEC_TYPE_DATA (needed for simpler handling of raw transport streams in ffserver and RTP - better solutions are welcomed)
bellard
parents:
1549
diff
changeset
|
855 case CODEC_TYPE_DATA: |
ece0ad14a35d
added fake codec CODEC_ID_MPEG2TS of type CODEC_TYPE_DATA (needed for simpler handling of raw transport streams in ffserver and RTP - better solutions are welcomed)
bellard
parents:
1549
diff
changeset
|
856 snprintf(buf, buf_size, "Data: %s", codec_name); |
ece0ad14a35d
added fake codec CODEC_ID_MPEG2TS of type CODEC_TYPE_DATA (needed for simpler handling of raw transport streams in ffserver and RTP - better solutions are welcomed)
bellard
parents:
1549
diff
changeset
|
857 bitrate = enc->bit_rate; |
ece0ad14a35d
added fake codec CODEC_ID_MPEG2TS of type CODEC_TYPE_DATA (needed for simpler handling of raw transport streams in ffserver and RTP - better solutions are welcomed)
bellard
parents:
1549
diff
changeset
|
858 break; |
2756 | 859 case CODEC_TYPE_SUBTITLE: |
860 snprintf(buf, buf_size, "Subtitle: %s", codec_name); | |
861 bitrate = enc->bit_rate; | |
862 break; | |
0 | 863 default: |
2281 | 864 snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type); |
865 return; | |
0 | 866 } |
741 | 867 if (encode) { |
868 if (enc->flags & CODEC_FLAG_PASS1) | |
869 snprintf(buf + strlen(buf), buf_size - strlen(buf), | |
870 ", pass 1"); | |
871 if (enc->flags & CODEC_FLAG_PASS2) | |
872 snprintf(buf + strlen(buf), buf_size - strlen(buf), | |
873 ", pass 2"); | |
874 } | |
92 | 875 if (bitrate != 0) { |
0 | 876 snprintf(buf + strlen(buf), buf_size - strlen(buf), |
92 | 877 ", %d kb/s", bitrate / 1000); |
0 | 878 } |
879 } | |
880 | |
362 | 881 unsigned avcodec_version( void ) |
882 { | |
883 return LIBAVCODEC_VERSION_INT; | |
884 } | |
55 | 885 |
379 | 886 unsigned avcodec_build( void ) |
887 { | |
888 return LIBAVCODEC_BUILD; | |
889 } | |
890 | |
0 | 891 /* must be called before any other functions */ |
892 void avcodec_init(void) | |
893 { | |
303
9a931fd8d06c
multiple init bugfix (patch by Alex Beregszaszi <alex@naxine.org>)
michaelni
parents:
267
diff
changeset
|
894 static int inited = 0; |
9a931fd8d06c
multiple init bugfix (patch by Alex Beregszaszi <alex@naxine.org>)
michaelni
parents:
267
diff
changeset
|
895 |
9a931fd8d06c
multiple init bugfix (patch by Alex Beregszaszi <alex@naxine.org>)
michaelni
parents:
267
diff
changeset
|
896 if (inited != 0) |
9a931fd8d06c
multiple init bugfix (patch by Alex Beregszaszi <alex@naxine.org>)
michaelni
parents:
267
diff
changeset
|
897 return; |
9a931fd8d06c
multiple init bugfix (patch by Alex Beregszaszi <alex@naxine.org>)
michaelni
parents:
267
diff
changeset
|
898 inited = 1; |
9a931fd8d06c
multiple init bugfix (patch by Alex Beregszaszi <alex@naxine.org>)
michaelni
parents:
267
diff
changeset
|
899 |
1201 | 900 dsputil_static_init(); |
0 | 901 } |
902 | |
1368 | 903 /** |
904 * Flush buffers, should be called when seeking or when swicthing to a different stream. | |
905 */ | |
341 | 906 void avcodec_flush_buffers(AVCodecContext *avctx) |
907 { | |
1368 | 908 if(avctx->codec->flush) |
909 avctx->codec->flush(avctx); | |
341 | 910 } |
911 | |
2231 | 912 void avcodec_default_free_buffers(AVCodecContext *s){ |
1214 | 913 int i, j; |
914 | |
915 if(s->internal_buffer==NULL) return; | |
916 | |
917 for(i=0; i<INTERNAL_BUFFER_SIZE; i++){ | |
918 InternalBuffer *buf= &((InternalBuffer*)s->internal_buffer)[i]; | |
919 for(j=0; j<4; j++){ | |
920 av_freep(&buf->base[j]); | |
921 buf->data[j]= NULL; | |
922 } | |
923 } | |
924 av_freep(&s->internal_buffer); | |
925 | |
926 s->internal_buffer_count=0; | |
927 } | |
928 | |
1264 | 929 char av_get_pict_type_char(int pict_type){ |
930 switch(pict_type){ | |
931 case I_TYPE: return 'I'; | |
932 case P_TYPE: return 'P'; | |
933 case B_TYPE: return 'B'; | |
934 case S_TYPE: return 'S'; | |
935 case SI_TYPE:return 'i'; | |
936 case SP_TYPE:return 'p'; | |
937 default: return '?'; | |
938 } | |
939 } | |
940 | |
1126
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
941 int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max){ |
2125 | 942 AVRational a0={0,1}, a1={1,0}; |
943 int sign= (nom<0) ^ (den<0); | |
944 int64_t gcd= ff_gcd(ABS(nom), ABS(den)); | |
1126
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
945 |
2125 | 946 nom = ABS(nom)/gcd; |
947 den = ABS(den)/gcd; | |
948 if(nom<=max && den<=max){ | |
949 a1= (AVRational){nom, den}; | |
950 den=0; | |
1126
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
951 } |
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
952 |
2125 | 953 while(den){ |
954 int64_t x = nom / den; | |
955 int64_t next_den= nom - den*x; | |
956 int64_t a2n= x*a1.num + a0.num; | |
957 int64_t a2d= x*a1.den + a0.den; | |
958 | |
959 if(a2n > max || a2d > max) break; | |
960 | |
961 a0= a1; | |
962 a1= (AVRational){a2n, a2d}; | |
963 nom= den; | |
964 den= next_den; | |
965 } | |
966 assert(ff_gcd(a1.num, a1.den) == 1); | |
1549
5e643dd7e889
use continued fractions to approximate a fraction if its numerator or denominator is too large
michael
parents:
1548
diff
changeset
|
967 |
2125 | 968 *dst_nom = sign ? -a1.num : a1.num; |
969 *dst_den = a1.den; | |
1126
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
970 |
2125 | 971 return den==0; |
1126
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
972 } |
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
973 |
2242 | 974 int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd){ |
975 AVInteger ai; | |
976 int64_t r=0; | |
1126
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
977 assert(c > 0); |
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
978 assert(b >=0); |
2242 | 979 assert(rnd >=0 && rnd<=5 && rnd!=4); |
1126
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
980 |
2301 | 981 if(a<0 && a != INT64_MIN) return -av_rescale_rnd(-a, b, c, rnd ^ ((rnd>>1)&1)); |
1126
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
982 |
2242 | 983 if(rnd==AV_ROUND_NEAR_INF) r= c/2; |
984 else if(rnd&1) r= c-1; | |
985 | |
2002
b737b5e96ee0
use AVInteger in av_rescale() so it can finally do 64*64/64 instead of just 64*32/32
michael
parents:
1996
diff
changeset
|
986 if(b<=INT_MAX && c<=INT_MAX){ |
b737b5e96ee0
use AVInteger in av_rescale() so it can finally do 64*64/64 instead of just 64*32/32
michael
parents:
1996
diff
changeset
|
987 if(a<=INT_MAX) |
2242 | 988 return (a * b + r)/c; |
2002
b737b5e96ee0
use AVInteger in av_rescale() so it can finally do 64*64/64 instead of just 64*32/32
michael
parents:
1996
diff
changeset
|
989 else |
2242 | 990 return a/c*b + (a%c*b + r)/c; |
2002
b737b5e96ee0
use AVInteger in av_rescale() so it can finally do 64*64/64 instead of just 64*32/32
michael
parents:
1996
diff
changeset
|
991 } |
1126
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
992 |
2002
b737b5e96ee0
use AVInteger in av_rescale() so it can finally do 64*64/64 instead of just 64*32/32
michael
parents:
1996
diff
changeset
|
993 ai= av_mul_i(av_int2i(a), av_int2i(b)); |
2242 | 994 ai= av_add_i(ai, av_int2i(r)); |
2002
b737b5e96ee0
use AVInteger in av_rescale() so it can finally do 64*64/64 instead of just 64*32/32
michael
parents:
1996
diff
changeset
|
995 |
2242 | 996 return av_i2int(av_div_i(ai, av_int2i(c))); |
997 } | |
998 | |
999 int64_t av_rescale(int64_t a, int64_t b, int64_t c){ | |
1000 return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF); | |
1126
77ccf7fe3bd0
per context frame_rate_base, this should finally fix frame_rate related av sync issues
michaelni
parents:
1106
diff
changeset
|
1001 } |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1002 |
2637 | 1003 int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq){ |
1004 int64_t b= bq.num * (int64_t)cq.den; | |
1005 int64_t c= cq.num * (int64_t)bq.den; | |
1006 return av_rescale_rnd(a, b, c, AV_ROUND_NEAR_INF); | |
1007 } | |
1008 | |
2398
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2370
diff
changeset
|
1009 int64_t ff_gcd(int64_t a, int64_t b){ |
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2370
diff
changeset
|
1010 if(b) return ff_gcd(b, a%b); |
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2370
diff
changeset
|
1011 else return a; |
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2370
diff
changeset
|
1012 } |
582e635cfa08
common.c -> bitstream.c (and the single non bitstream func -> utils.c)
michael
parents:
2370
diff
changeset
|
1013 |
2800 | 1014 double av_int2dbl(int64_t v){ |
1015 if(v+v > 0xFFELLU<<52) | |
1016 return 0.0/0.0; | |
1017 return ldexp(((v&(1LL<<52)-1) + (1LL<<52)) * (v>>63|1), (v>>52&0x7FF)-1075); | |
1018 } | |
1019 | |
1020 float av_int2flt(int32_t v){ | |
1021 if(v+v > 0xFF000000U) | |
1022 return 0.0/0.0; | |
1023 return ldexp(((v&0x7FFFFF) + (1<<23)) * (v>>31|1), (v>>23&0xFF)-150); | |
1024 } | |
1025 | |
1026 int64_t av_dbl2int(double d){ | |
1027 int e; | |
1028 if ( !d) return 0; | |
1029 else if(d-d) return 0x7FF0000000000000LL + ((int64_t)(d<0)<<63) + (d!=d); | |
1030 d= frexp(d, &e); | |
1031 return (int64_t)(d<0)<<63 | (e+1022LL)<<52 | (int64_t)((fabs(d)-0.5)*(1LL<<53)); | |
1032 } | |
1033 | |
1034 int32_t av_flt2int(float d){ | |
1035 int e; | |
1036 if ( !d) return 0; | |
1037 else if(d-d) return 0x7F800000 + ((d<0)<<31) + (d!=d); | |
1038 d= frexp(d, &e); | |
1039 return (d<0)<<31 | (e+126)<<23 | (int64_t)((fabs(d)-0.5)*(1<<24)); | |
1040 } | |
1041 | |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1042 /* av_log API */ |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1043 |
2733 | 1044 static int av_log_level = AV_LOG_INFO; |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1045 |
1855
bafde44145f9
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1854
diff
changeset
|
1046 static void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl) |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1047 { |
1600 | 1048 static int print_prefix=1; |
1856 | 1049 AVClass* avc= ptr ? *(AVClass**)ptr : NULL; |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1050 if(level>av_log_level) |
1855
bafde44145f9
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1854
diff
changeset
|
1051 return; |
1823
a660ef952580
(f)printf() is disallowed in libavcodec, compilation will fail now if its used, except that codecs which where added after the printf->av_log change which did ignore av_log() and used prinf are now silent and wont print anything, they should be changed to use av_log, i could do that, but its better if the orginal developer decides which AV_LOG level each message should get
michael
parents:
1799
diff
changeset
|
1052 #undef fprintf |
1856 | 1053 if(print_prefix && avc) { |
1054 fprintf(stderr, "[%s @ %p]", avc->item_name(ptr), avc); | |
1855
bafde44145f9
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1854
diff
changeset
|
1055 } |
1823
a660ef952580
(f)printf() is disallowed in libavcodec, compilation will fail now if its used, except that codecs which where added after the printf->av_log change which did ignore av_log() and used prinf are now silent and wont print anything, they should be changed to use av_log, i could do that, but its better if the orginal developer decides which AV_LOG level each message should get
michael
parents:
1799
diff
changeset
|
1056 #define fprintf please_use_av_log |
1600 | 1057 |
1776 | 1058 print_prefix= strstr(fmt, "\n") != NULL; |
1600 | 1059 |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1060 vfprintf(stderr, fmt, vl); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1061 } |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1062 |
1855
bafde44145f9
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1854
diff
changeset
|
1063 static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback; |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1064 |
1855
bafde44145f9
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1854
diff
changeset
|
1065 void av_log(void* avcl, int level, const char *fmt, ...) |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1066 { |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1067 va_list vl; |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1068 va_start(vl, fmt); |
1855
bafde44145f9
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1854
diff
changeset
|
1069 av_vlog(avcl, level, fmt, vl); |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1070 va_end(vl); |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1071 } |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1072 |
1855
bafde44145f9
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1854
diff
changeset
|
1073 void av_vlog(void* avcl, int level, const char *fmt, va_list vl) |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1074 { |
1855
bafde44145f9
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1854
diff
changeset
|
1075 av_log_callback(avcl, level, fmt, vl); |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1076 } |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1077 |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1078 int av_log_get_level(void) |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1079 { |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1080 return av_log_level; |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1081 } |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1082 |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1083 void av_log_set_level(int level) |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1084 { |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1085 av_log_level = level; |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1086 } |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1087 |
1855
bafde44145f9
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1854
diff
changeset
|
1088 void av_log_set_callback(void (*callback)(void*, int, const char*, va_list)) |
1598
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1089 { |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1090 av_log_callback = callback; |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1091 } |
932d306bf1dc
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
michael
parents:
1588
diff
changeset
|
1092 |
2362
7a6ff8cc7c95
BeOS threading support. changed some "if FOO_THREAD||BAR_THREAD" to a more generic "if HAVE_THREADS"
mmu_man
parents:
2324
diff
changeset
|
1093 #if !defined(HAVE_THREADS) |
2013
85e547a18d87
dummy avcodec_thread_init() to avoid linking issues
michael
parents:
2002
diff
changeset
|
1094 int avcodec_thread_init(AVCodecContext *s, int thread_count){ |
85e547a18d87
dummy avcodec_thread_init() to avoid linking issues
michael
parents:
2002
diff
changeset
|
1095 return -1; |
85e547a18d87
dummy avcodec_thread_init() to avoid linking issues
michael
parents:
2002
diff
changeset
|
1096 } |
85e547a18d87
dummy avcodec_thread_init() to avoid linking issues
michael
parents:
2002
diff
changeset
|
1097 #endif |
2676 | 1098 |
1099 unsigned int av_xiphlacing(unsigned char *s, unsigned int v) | |
1100 { | |
1101 unsigned int n = 0; | |
1102 | |
1103 while(v >= 0xff) { | |
1104 *s++ = 0xff; | |
1105 v -= 0xff; | |
1106 n++; | |
1107 } | |
1108 *s = v; | |
1109 n++; | |
1110 return n; | |
1111 } |