| 1 |
|
| /* |
| 2 |
|
| * utils for libavcodec |
| 3 |
|
| * Copyright (c) 2001 Fabrice Bellard. |
| 4 |
|
| * |
| 5 |
|
| * This library is free software; you can redistribute it and/or |
| 6 |
|
| * modify it under the terms of the GNU Lesser General Public |
| 7 |
|
| * License as published by the Free Software Foundation; either |
| 8 |
|
| * version 2 of the License, or (at your option) any later version. |
| 9 |
|
| * |
| 10 |
|
| * This library is distributed in the hope that it will be useful, |
| 11 |
|
| * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
|
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
|
| * Lesser General Public License for more details. |
| 14 |
|
| * |
| 15 |
|
| * You should have received a copy of the GNU Lesser General Public |
| 16 |
|
| * License along with this library; if not, write to the Free Software |
| 17 |
|
| * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 |
|
| */ |
| 19 |
|
| |
| 20 |
|
| /** |
| 21 |
|
| * @file utils.c |
| 22 |
|
| * utils. |
| 23 |
|
| */ |
| 24 |
|
| |
| 25 |
|
| #include "avcodec.h" |
| 26 |
|
| #include "dsputil.h" |
| 27 |
|
| #include "mpegvideo.h" |
| 28 |
|
| |
| 29 |
|
| //void *av_mallocz(unsigned int size) |
| 30 |
|
| //{ |
| 31 |
|
| // void *ptr; |
| 32 |
|
| // |
| 33 |
|
| // ptr = av_malloc(size); |
| 34 |
|
| // if (!ptr) |
| 35 |
|
| // return NULL; |
| 36 |
|
| // memset(ptr, 0, size); |
| 37 |
|
| // return ptr; |
| 38 |
|
| //} |
| 39 |
|
| |
| 40 |
0 |
| char *av_strdup(const char *s) |
| 41 |
|
| { |
| 42 |
|
| char *ptr; |
| 43 |
|
| int len; |
| 44 |
0 |
| len = strlen(s) + 1; |
| 45 |
0 |
| ptr = av_malloc(len); |
| 46 |
0 |
▶ | if (!ptr) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ptr) |
0 |
0 |
0 |
|
| 47 |
0 |
| return NULL; |
| 48 |
0 |
| memcpy(ptr, s, len); |
| 49 |
0 |
| return ptr; |
| 50 |
|
| } |
| 51 |
|
| |
| 52 |
|
| /** |
| 53 |
|
| * realloc which does nothing if the block is large enough |
| 54 |
|
| */ |
| 55 |
0 |
| void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size) |
| 56 |
|
| { |
| 57 |
0 |
▶ | if(min_size < *size) |
Branch: 1 branch
| Branch | True | False | Total |
| if(min_size < *size) |
0 |
0 |
0 |
|
| 58 |
0 |
| return ptr; |
| 59 |
|
| |
| 60 |
0 |
| *size= min_size + 10*1024; |
| 61 |
|
| |
| 62 |
0 |
| return av_realloc(ptr, *size); |
| 63 |
|
| } |
| 64 |
|
| |
| 65 |
|
| |
| 66 |
|
| ///* allocation of static arrays - do not use for normal allocation */ |
| 67 |
|
| //static unsigned int last_static = 0; |
| 68 |
|
| //static char*** array_static = NULL; |
| 69 |
|
| //static const unsigned int grow_static = 64; // ^2 |
| 70 |
|
| //void *__av_mallocz_static(void** location, unsigned int size) |
| 71 |
|
| //{ |
| 72 |
|
| // unsigned int l = (last_static + grow_static) & ~(grow_static - 1); |
| 73 |
|
| // void *ptr = av_mallocz(size); |
| 74 |
|
| // if (!ptr) |
| 75 |
|
| // return NULL; |
| 76 |
|
| // |
| 77 |
|
| // if (location) |
| 78 |
|
| // { |
| 79 |
|
| // if (l > last_static) |
| 80 |
|
| // array_static = av_realloc(array_static, l); |
| 81 |
|
| // array_static[last_static++] = (char**) location; |
| 82 |
|
| // *location = ptr; |
| 83 |
|
| // } |
| 84 |
|
| // return ptr; |
| 85 |
|
| //} |
| 86 |
|
| ///* free all static arrays and reset pointers to 0 */ |
| 87 |
|
| //void av_free_static(void) |
| 88 |
|
| //{ |
| 89 |
|
| // if (array_static) |
| 90 |
|
| // { |
| 91 |
|
| // unsigned i; |
| 92 |
|
| // for (i = 0; i < last_static; i++) |
| 93 |
|
| // { |
| 94 |
|
| // av_free(*array_static[i]); |
| 95 |
|
| // *array_static[i] = NULL; |
| 96 |
|
| // } |
| 97 |
|
| // av_free(array_static); |
| 98 |
|
| // array_static = 0; |
| 99 |
|
| // } |
| 100 |
|
| // last_static = 0; |
| 101 |
|
| //} |
| 102 |
|
| |
| 103 |
|
| /* cannot call it directly because of 'void **' casting is not automatic */ |
| 104 |
0 |
| void __av_freep(void **ptr) |
| 105 |
|
| { |
| 106 |
0 |
| av_free(*ptr); |
| 107 |
0 |
| *ptr = NULL; |
| 108 |
0 |
| } |
| 109 |
|
| |
| 110 |
|
| /* encoder management */ |
| 111 |
|
| AVCodec *first_avcodec; |
| 112 |
|
| |
| 113 |
0 |
| void register_avcodec(AVCodec *format) |
| 114 |
|
| { |
| 115 |
|
| AVCodec **p; |
| 116 |
0 |
| p = &first_avcodec; |
| 117 |
0 |
▶ | while (*p != NULL) p = &(*p)->next; |
Branch: 1 branch
| Branch | True | False | Total |
| while (*p != NULL) p = &(*p)->next; |
0 |
0 |
0 |
|
| 118 |
0 |
| *p = format; |
| 119 |
0 |
| format->next = NULL; |
| 120 |
0 |
| } |
| 121 |
|
| |
| 122 |
|
| typedef struct InternalBuffer{ |
| 123 |
|
| int last_pic_num; |
| 124 |
|
| uint8_t *base[4]; |
| 125 |
|
| uint8_t *data[4]; |
| 126 |
|
| }InternalBuffer; |
| 127 |
|
| |
| 128 |
|
| #define INTERNAL_BUFFER_SIZE 32 |
| 129 |
|
| |
| 130 |
0 |
| int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){ |
| 131 |
|
| int i; |
| 132 |
0 |
| const int width = s->width; |
| 133 |
0 |
| const int height= s->height; |
| 134 |
|
| InternalBuffer *buf; |
| 135 |
|
| |
| 136 |
|
| assert(pic->data[0]==NULL); |
| 137 |
|
| assert(INTERNAL_BUFFER_SIZE > s->internal_buffer_count); |
| 138 |
|
| |
| 139 |
0 |
▶ | if(s->internal_buffer==NULL){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(s->internal_buffer==NULL){ |
0 |
0 |
0 |
|
| 140 |
0 |
| s->internal_buffer= av_mallocz(INTERNAL_BUFFER_SIZE*sizeof(InternalBuffer)); |
| 141 |
|
| } |
| 142 |
|
| #if 0 |
| 143 |
|
| s->internal_buffer= av_fast_realloc( |
| 144 |
|
| s->internal_buffer, |
| 145 |
|
| &s->internal_buffer_size, |
| 146 |
|
| sizeof(InternalBuffer)*FFMAX(99, s->internal_buffer_count+1)/*FIXME*/ |
| 147 |
|
| ); |
| 148 |
|
| #endif |
| 149 |
|
| |
| 150 |
0 |
| buf= &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count]; |
| 151 |
|
| |
| 152 |
0 |
▶ | if(buf->base[0]){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(buf->base[0]){ |
0 |
0 |
0 |
|
| 153 |
0 |
| pic->age= pic->coded_picture_number - buf->last_pic_num; |
| 154 |
0 |
| buf->last_pic_num= pic->coded_picture_number; |
| 155 |
|
| }else{ |
| 156 |
0 |
| int align, h_chroma_shift=0, v_chroma_shift=0; |
| 157 |
|
| int w, h, pixel_size; |
| 158 |
|
| |
| 159 |
|
| // avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift); |
| 160 |
0 |
| switch(s->pix_fmt){ |
| 161 |
0 |
| case PIX_FMT_RGB555: |
| 162 |
|
| case PIX_FMT_RGB565: |
| 163 |
|
| case PIX_FMT_YUV422: |
| 164 |
0 |
| pixel_size=2; |
| 165 |
0 |
| break; |
| 166 |
0 |
| case PIX_FMT_RGB24: |
| 167 |
|
| case PIX_FMT_BGR24: |
| 168 |
0 |
| pixel_size=3; |
| 169 |
0 |
| break; |
| 170 |
0 |
| case PIX_FMT_RGBA32: |
| 171 |
0 |
| pixel_size=4; |
| 172 |
0 |
| break; |
| 173 |
0 |
| default: |
| 174 |
0 |
| pixel_size=1; |
| 175 |
|
| } |
| 176 |
|
| |
| 177 |
0 |
▶ | if(s->codec_id==CODEC_ID_SVQ1) align=63; |
Branch: 1 branch
| Branch | True | False | Total |
| if(s->codec_id==CODEC_ID_SVQ1) align=63; |
0 |
0 |
0 |
|
| 178 |
0 |
| else align=15; |
| 179 |
|
| |
| 180 |
0 |
| w= (width +align)&~align; |
| 181 |
0 |
| h= (height+align)&~align; |
| 182 |
|
| |
| 183 |
0 |
▶ | if(!(s->flags&CODEC_FLAG_EMU_EDGE)){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(!(s->flags&CODEC_FLAG_EMU_EDGE)){ |
0 |
0 |
0 |
|
| 184 |
0 |
| w+= EDGE_WIDTH*2; |
| 185 |
0 |
| h+= EDGE_WIDTH*2; |
| 186 |
|
| } |
| 187 |
|
| |
| 188 |
0 |
| buf->last_pic_num= -256*256*256*64; |
| 189 |
|
| |
| 190 |
0 |
▶ | for(i=0; i<3; i++){ |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0; i<3; i++){ |
0 |
0 |
0 |
|
| 191 |
0 |
▶ | const int h_shift= i==0 ? 0 : h_chroma_shift; |
Branch: 1 branch
| Branch | True | False | Total |
| const int h_shift= i==0 ? 0 : h_chroma_shift; |
0 |
0 |
0 |
|
| 192 |
0 |
▶ | const int v_shift= i==0 ? 0 : v_chroma_shift; |
Branch: 1 branch
| Branch | True | False | Total |
| const int v_shift= i==0 ? 0 : v_chroma_shift; |
0 |
0 |
0 |
|
| 193 |
|
| |
| 194 |
0 |
| pic->linesize[i]= pixel_size*w>>h_shift; |
| 195 |
|
| |
| 196 |
0 |
| buf->base[i]= av_mallocz((pic->linesize[i]*h>>v_shift)+16); //FIXME 16 |
| 197 |
0 |
▶ | if(buf->base[i]==NULL) return -1; |
Branch: 1 branch
| Branch | True | False | Total |
| if(buf->base[i]==NULL) return -1; |
0 |
0 |
0 |
|
| 198 |
0 |
| memset(buf->base[i], 128, pic->linesize[i]*h>>v_shift); |
| 199 |
|
| |
| 200 |
0 |
▶ | if(s->flags&CODEC_FLAG_EMU_EDGE) |
Branch: 1 branch
| Branch | True | False | Total |
| if(s->flags&CODEC_FLAG_EMU_EDGE) |
0 |
0 |
0 |
|
| 201 |
0 |
| buf->data[i] = buf->base[i]; |
| 202 |
|
| else |
| 203 |
0 |
| buf->data[i] = buf->base[i] + (pic->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift); |
| 204 |
|
| } |
| 205 |
0 |
| pic->age= 256*256*256*64; |
| 206 |
0 |
| pic->type= FF_BUFFER_TYPE_INTERNAL; |
| 207 |
|
| } |
| 208 |
|
| |
| 209 |
0 |
▶ | for(i=0; i<4; i++){ |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0; i<4; i++){ |
0 |
0 |
0 |
|
| 210 |
0 |
| pic->base[i]= buf->base[i]; |
| 211 |
0 |
| pic->data[i]= buf->data[i]; |
| 212 |
|
| } |
| 213 |
0 |
| s->internal_buffer_count++; |
| 214 |
|
| |
| 215 |
0 |
| return 0; |
| 216 |
|
| } |
| 217 |
|
| |
| 218 |
0 |
| void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){ |
| 219 |
|
| int i; |
| 220 |
|
| InternalBuffer *buf, *last, temp; |
| 221 |
|
| |
| 222 |
|
| assert(pic->type==FF_BUFFER_TYPE_INTERNAL); |
| 223 |
|
| assert(s->internal_buffer_count); |
| 224 |
|
| |
| 225 |
0 |
| buf = NULL; /* avoids warning */ |
| 226 |
0 |
▶ | for(i=0; i<s->internal_buffer_count; i++){ //just 3-5 checks so is not worth to optimize |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0; i<s->internal_buffer_count; i++){ //just 3-5 checks so is not worth to optimize |
0 |
0 |
0 |
|
| 227 |
0 |
| buf= &((InternalBuffer*)s->internal_buffer)[i]; |
| 228 |
0 |
▶ | if(buf->data[0] == pic->data[0]) |
Branch: 1 branch
| Branch | True | False | Total |
| if(buf->data[0] == pic->data[0]) |
0 |
0 |
0 |
|
| 229 |
0 |
| break; |
| 230 |
|
| } |
| 231 |
|
| assert(i < s->internal_buffer_count); |
| 232 |
0 |
| s->internal_buffer_count--; |
| 233 |
0 |
| last = &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count]; |
| 234 |
|
| |
| 235 |
0 |
| temp= *buf; |
| 236 |
0 |
| *buf= *last; |
| 237 |
0 |
| *last= temp; |
| 238 |
|
| |
| 239 |
0 |
▶ | for(i=0; i<3; i++){ |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0; i<3; i++){ |
0 |
0 |
0 |
|
| 240 |
0 |
| pic->data[i]=NULL; |
| 241 |
|
| // pic->base[i]=NULL; |
| 242 |
|
| } |
| 243 |
|
| //printf("R%X\n", pic->opaque); |
| 244 |
0 |
| } |
| 245 |
|
| |
| 246 |
0 |
| enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt){ |
| 247 |
0 |
| return fmt[0]; |
| 248 |
|
| } |
| 249 |
|
| |
| 250 |
0 |
| void avcodec_get_context_defaults(AVCodecContext *s){ |
| 251 |
0 |
| s->bit_rate= 800*1000; |
| 252 |
0 |
| s->bit_rate_tolerance= s->bit_rate*10; |
| 253 |
0 |
| s->qmin= 2; |
| 254 |
0 |
| s->qmax= 31; |
| 255 |
0 |
| s->mb_qmin= 2; |
| 256 |
0 |
| s->mb_qmax= 31; |
| 257 |
0 |
| s->rc_eq= "tex^qComp"; |
| 258 |
0 |
| s->qcompress= 0.5; |
| 259 |
0 |
| s->max_qdiff= 3; |
| 260 |
0 |
| s->b_quant_factor=1.25; |
| 261 |
0 |
| s->b_quant_offset=1.25; |
| 262 |
0 |
| s->i_quant_factor=-0.8; |
| 263 |
0 |
| s->i_quant_offset=0.0; |
| 264 |
0 |
| s->error_concealment= 3; |
| 265 |
0 |
| s->error_resilience= 1; |
| 266 |
0 |
| s->workaround_bugs= FF_BUG_AUTODETECT; |
| 267 |
0 |
| s->frame_rate_base= 1; |
| 268 |
0 |
| s->frame_rate = 25; |
| 269 |
0 |
| s->gop_size= 50; |
| 270 |
0 |
| s->me_method= ME_EPZS; |
| 271 |
0 |
| s->get_buffer= avcodec_default_get_buffer; |
| 272 |
0 |
| s->release_buffer= avcodec_default_release_buffer; |
| 273 |
0 |
| s->get_format= avcodec_default_get_format; |
| 274 |
0 |
| s->me_subpel_quality=8; |
| 275 |
|
| |
| 276 |
0 |
| s->intra_quant_bias= FF_DEFAULT_QUANT_BIAS; |
| 277 |
0 |
| s->inter_quant_bias= FF_DEFAULT_QUANT_BIAS; |
| 278 |
0 |
| } |
| 279 |
|
| |
| 280 |
|
| /** |
| 281 |
|
| * allocates a AVCodecContext and set it to defaults. |
| 282 |
|
| * this can be deallocated by simply calling free() |
| 283 |
|
| */ |
| 284 |
0 |
| AVCodecContext *avcodec_alloc_context(void){ |
| 285 |
0 |
| AVCodecContext *avctx= av_mallocz(sizeof(AVCodecContext)); |
| 286 |
|
| |
| 287 |
0 |
▶ | if(avctx==NULL) return NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| if(avctx==NULL) return NULL; |
0 |
0 |
0 |
|
| 288 |
|
| |
| 289 |
0 |
| avcodec_get_context_defaults(avctx); |
| 290 |
|
| |
| 291 |
0 |
| return avctx; |
| 292 |
|
| } |
| 293 |
|
| |
| 294 |
|
| /** |
| 295 |
|
| * allocates a AVPFrame and set it to defaults. |
| 296 |
|
| * this can be deallocated by simply calling free() |
| 297 |
|
| */ |
| 298 |
0 |
| AVFrame *avcodec_alloc_frame(void){ |
| 299 |
0 |
| AVFrame *pic= av_mallocz(sizeof(AVFrame)); |
| 300 |
|
| |
| 301 |
0 |
| return pic; |
| 302 |
|
| } |
| 303 |
|
| |
| 304 |
0 |
| int avcodec_open(AVCodecContext *avctx, AVCodec *codec) |
| 305 |
|
| { |
| 306 |
|
| int ret; |
| 307 |
|
| |
| 308 |
0 |
▶ | if(avctx->codec) |
Branch: 1 branch
| Branch | True | False | Total |
| if(avctx->codec) |
0 |
0 |
0 |
|
| 309 |
0 |
| return -1; |
| 310 |
|
| |
| 311 |
0 |
| avctx->codec = codec; |
| 312 |
0 |
| avctx->codec_id = codec->id; |
| 313 |
0 |
| avctx->frame_number = 0; |
| 314 |
0 |
▶ | if (codec->priv_data_size > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (codec->priv_data_size > 0) { |
0 |
0 |
0 |
|
| 315 |
0 |
| avctx->priv_data = av_mallocz(codec->priv_data_size); |
| 316 |
0 |
▶ | if (!avctx->priv_data) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!avctx->priv_data) |
0 |
0 |
0 |
|
| 317 |
0 |
| return -ENOMEM; |
| 318 |
|
| } else { |
| 319 |
0 |
| avctx->priv_data = NULL; |
| 320 |
|
| } |
| 321 |
0 |
| ret = avctx->codec->init(avctx); |
| 322 |
0 |
▶ | if (ret < 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (ret < 0) { |
0 |
0 |
0 |
|
| 323 |
0 |
| av_freep(&avctx->priv_data); |
| 324 |
0 |
| return ret; |
| 325 |
|
| } |
| 326 |
0 |
| return 0; |
| 327 |
|
| } |
| 328 |
|
| |
| 329 |
0 |
| int avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size, |
| 330 |
|
| const short *samples) |
| 331 |
|
| { |
| 332 |
|
| int ret; |
| 333 |
|
| |
| 334 |
0 |
| ret = avctx->codec->encode(avctx, buf, buf_size, (void *)samples); |
| 335 |
0 |
| avctx->frame_number++; |
| 336 |
0 |
| return ret; |
| 337 |
|
| } |
| 338 |
|
| |
| 339 |
0 |
| int avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size, |
| 340 |
|
| const AVFrame *pict) |
| 341 |
|
| { |
| 342 |
|
| int ret; |
| 343 |
|
| |
| 344 |
0 |
| ret = avctx->codec->encode(avctx, buf, buf_size, (void *)pict); |
| 345 |
|
| |
| 346 |
|
| emms_c(); //needed to avoid a emms_c() call before every return; |
| 347 |
|
| |
| 348 |
0 |
| avctx->frame_number++; |
| 349 |
0 |
| return ret; |
| 350 |
|
| } |
| 351 |
|
| |
| 352 |
|
| /** |
| 353 |
|
| * decode a frame. |
| 354 |
|
| * @param buf bitstream buffer, must be FF_INPUT_BUFFER_PADDING_SIZE larger then the actual read bytes |
| 355 |
|
| * because some optimized bitstream readers read 32 or 64 bit at once and could read over the end |
| 356 |
|
| * @param buf_size the size of the buffer in bytes |
| 357 |
|
| * @param got_picture_ptr zero if no frame could be decompressed, Otherwise, it is non zero |
| 358 |
|
| * @return -1 if error, otherwise return the number of |
| 359 |
|
| * bytes used. |
| 360 |
|
| */ |
| 361 |
0 |
| int avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture, |
| 362 |
|
| int *got_picture_ptr, |
| 363 |
|
| uint8_t *buf, int buf_size) |
| 364 |
|
| { |
| 365 |
|
| int ret; |
| 366 |
|
| |
| 367 |
0 |
| ret = avctx->codec->decode(avctx, picture, got_picture_ptr, |
| 368 |
|
| buf, buf_size); |
| 369 |
|
| |
| 370 |
|
| emms_c(); //needed to avoid a emms_c() call before every return; |
| 371 |
|
| |
| 372 |
0 |
▶ | if (*got_picture_ptr) |
Branch: 1 branch
| Branch | True | False | Total |
| if (*got_picture_ptr) |
0 |
0 |
0 |
|
| 373 |
0 |
| avctx->frame_number++; |
| 374 |
0 |
| return ret; |
| 375 |
|
| } |
| 376 |
|
| |
| 377 |
|
| /* decode an audio frame. return -1 if error, otherwise return the |
| 378 |
|
| *number of bytes used. If no frame could be decompressed, |
| 379 |
|
| *frame_size_ptr is zero. Otherwise, it is the decompressed frame |
| 380 |
|
| *size in BYTES. */ |
| 381 |
0 |
| int avcodec_decode_audio(AVCodecContext *avctx, int16_t *samples, |
| 382 |
|
| int *frame_size_ptr, |
| 383 |
|
| uint8_t *buf, int buf_size) |
| 384 |
|
| { |
| 385 |
|
| int ret; |
| 386 |
|
| |
| 387 |
0 |
| ret = avctx->codec->decode(avctx, samples, frame_size_ptr, |
| 388 |
|
| buf, buf_size); |
| 389 |
0 |
| avctx->frame_number++; |
| 390 |
0 |
| return ret; |
| 391 |
|
| } |
| 392 |
|
| |
| 393 |
0 |
| int avcodec_close(AVCodecContext *avctx) |
| 394 |
|
| { |
| 395 |
0 |
▶ | if (avctx->codec->close) |
Branch: 1 branch
| Branch | True | False | Total |
| if (avctx->codec->close) |
0 |
0 |
0 |
|
| 396 |
0 |
| avctx->codec->close(avctx); |
| 397 |
0 |
| av_freep(&avctx->priv_data); |
| 398 |
0 |
| avctx->codec = NULL; |
| 399 |
0 |
| return 0; |
| 400 |
|
| } |
| 401 |
|
| |
| 402 |
0 |
| AVCodec *avcodec_find_encoder(enum CodecID id) |
| 403 |
|
| { |
| 404 |
|
| AVCodec *p; |
| 405 |
0 |
| p = first_avcodec; |
| 406 |
0 |
▶ | while (p) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p) { |
0 |
0 |
0 |
|
| 407 |
0 |
▶ | if (p->encode != NULL && p->id == id) |
Branch: 2 branches
| Branch | True | False | Total |
| if (p->encode != NULL && p->id == id) |
0 |
0 |
0 |
| if (p->encode != NULL && p->id == id) |
0 |
0 |
0 |
|
| 408 |
0 |
| return p; |
| 409 |
0 |
| p = p->next; |
| 410 |
|
| } |
| 411 |
0 |
| return NULL; |
| 412 |
|
| } |
| 413 |
|
| |
| 414 |
0 |
| AVCodec *avcodec_find_encoder_by_name(const char *name) |
| 415 |
|
| { |
| 416 |
|
| AVCodec *p; |
| 417 |
0 |
| p = first_avcodec; |
| 418 |
0 |
▶ | while (p) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p) { |
0 |
0 |
0 |
|
| 419 |
0 |
▶ | if (p->encode != NULL && strcmp(name,p->name) == 0) |
Branch: 2 branches
| Branch | True | False | Total |
| if (p->encode != NULL && strcmp(name,p->name) == 0) |
0 |
0 |
0 |
| if (p->encode != NULL && strcmp(name,p->name) == 0) |
0 |
0 |
0 |
|
| 420 |
0 |
| return p; |
| 421 |
0 |
| p = p->next; |
| 422 |
|
| } |
| 423 |
0 |
| return NULL; |
| 424 |
|
| } |
| 425 |
|
| |
| 426 |
0 |
| AVCodec *avcodec_find_decoder(enum CodecID id) |
| 427 |
|
| { |
| 428 |
|
| AVCodec *p; |
| 429 |
0 |
| p = first_avcodec; |
| 430 |
0 |
▶ | while (p) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p) { |
0 |
0 |
0 |
|
| 431 |
0 |
▶ | if (p->decode != NULL && p->id == id) |
Branch: 2 branches
| Branch | True | False | Total |
| if (p->decode != NULL && p->id == id) |
0 |
0 |
0 |
| if (p->decode != NULL && p->id == id) |
0 |
0 |
0 |
|
| 432 |
0 |
| return p; |
| 433 |
0 |
| p = p->next; |
| 434 |
|
| } |
| 435 |
0 |
| return NULL; |
| 436 |
|
| } |
| 437 |
|
| |
| 438 |
0 |
| AVCodec *avcodec_find_decoder_by_name(const char *name) |
| 439 |
|
| { |
| 440 |
|
| AVCodec *p; |
| 441 |
0 |
| p = first_avcodec; |
| 442 |
0 |
▶ | while (p) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p) { |
0 |
0 |
0 |
|
| 443 |
0 |
▶ | if (p->decode != NULL && strcmp(name,p->name) == 0) |
Branch: 2 branches
| Branch | True | False | Total |
| if (p->decode != NULL && strcmp(name,p->name) == 0) |
0 |
0 |
0 |
| if (p->decode != NULL && strcmp(name,p->name) == 0) |
0 |
0 |
0 |
|
| 444 |
0 |
| return p; |
| 445 |
0 |
| p = p->next; |
| 446 |
|
| } |
| 447 |
0 |
| return NULL; |
| 448 |
|
| } |
| 449 |
|
| |
| 450 |
0 |
| AVCodec *avcodec_find(enum CodecID id) |
| 451 |
|
| { |
| 452 |
|
| AVCodec *p; |
| 453 |
0 |
| p = first_avcodec; |
| 454 |
0 |
▶ | while (p) { |
Branch: 1 branch
| Branch | True | False | Total |
| while (p) { |
0 |
0 |
0 |
|
| 455 |
0 |
▶ | if (p->id == id) |
Branch: 1 branch
| Branch | True | False | Total |
| if (p->id == id) |
0 |
0 |
0 |
|
| 456 |
0 |
| return p; |
| 457 |
0 |
| p = p->next; |
| 458 |
|
| } |
| 459 |
0 |
| return NULL; |
| 460 |
|
| } |
| 461 |
|
| |
| 462 |
0 |
| void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) |
| 463 |
|
| { |
| 464 |
|
| const char *codec_name; |
| 465 |
|
| AVCodec *p; |
| 466 |
|
| char buf1[32]; |
| 467 |
|
| char channels_str[100]; |
| 468 |
|
| int bitrate; |
| 469 |
|
| |
| 470 |
0 |
▶ | if (encode) |
Branch: 1 branch
| Branch | True | False | Total |
| if (encode) |
0 |
0 |
0 |
|
| 471 |
0 |
| p = avcodec_find_encoder(enc->codec_id); |
| 472 |
|
| else |
| 473 |
0 |
| p = avcodec_find_decoder(enc->codec_id); |
| 474 |
|
| |
| 475 |
0 |
▶ | if (p) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p) { |
0 |
0 |
0 |
|
| 476 |
0 |
| codec_name = p->name; |
| 477 |
0 |
▶ | if (!encode && enc->codec_id == CODEC_ID_MP3) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (!encode && enc->codec_id == CODEC_ID_MP3) { |
0 |
0 |
0 |
| if (!encode && enc->codec_id == CODEC_ID_MP3) { |
0 |
0 |
0 |
|
| 478 |
0 |
▶ | if (enc->sub_id == 2) |
Branch: 1 branch
| Branch | True | False | Total |
| if (enc->sub_id == 2) |
0 |
0 |
0 |
|
| 479 |
0 |
| codec_name = "mp2"; |
| 480 |
0 |
▶ | else if (enc->sub_id == 1) |
Branch: 1 branch
| Branch | True | False | Total |
| else if (enc->sub_id == 1) |
0 |
0 |
0 |
|
| 481 |
0 |
| codec_name = "mp1"; |
| 482 |
|
| } |
| 483 |
0 |
▶ | } else if (enc->codec_name[0] != '\0') { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if (enc->codec_name[0] != '\0') { |
0 |
0 |
0 |
|
| 484 |
0 |
| codec_name = enc->codec_name; |
| 485 |
|
| } else { |
| 486 |
|
| /* output avi tags */ |
| 487 |
0 |
▶ | if (enc->codec_type == CODEC_TYPE_VIDEO) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (enc->codec_type == CODEC_TYPE_VIDEO) { |
0 |
0 |
0 |
|
| 488 |
0 |
| snprintf(buf1, sizeof(buf1), "%c%c%c%c", |
| 489 |
0 |
| enc->codec_tag & 0xff, |
| 490 |
0 |
| (enc->codec_tag >> 8) & 0xff, |
| 491 |
0 |
| (enc->codec_tag >> 16) & 0xff, |
| 492 |
0 |
| (enc->codec_tag >> 24) & 0xff); |
| 493 |
|
| } else { |
| 494 |
0 |
| snprintf(buf1, sizeof(buf1), "0x%04x", enc->codec_tag); |
| 495 |
|
| } |
| 496 |
0 |
| codec_name = buf1; |
| 497 |
|
| } |
| 498 |
|
| |
| 499 |
0 |
| switch(enc->codec_type) { |
| 500 |
0 |
| case CODEC_TYPE_VIDEO: |
| 501 |
0 |
| snprintf(buf, buf_size, |
| 502 |
|
| "Video: %s%s", |
| 503 |
0 |
▶ | codec_name, enc->mb_decision ? " (hq)" : ""); |
Branch: 1 branch
| Branch | True | False | Total |
| codec_name, enc->mb_decision ? " (hq)" : ""); |
0 |
0 |
0 |
|
| 504 |
0 |
▶ | if (enc->codec_id == CODEC_ID_RAWVIDEO) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (enc->codec_id == CODEC_ID_RAWVIDEO) { |
0 |
0 |
0 |
|
| 505 |
0 |
| snprintf(buf + strlen(buf), buf_size - strlen(buf), |
| 506 |
|
| ", %s" |
| 507 |
|
| // ,avcodec_get_pix_fmt_name(enc->pix_fmt) |
| 508 |
|
| ,""); |
| 509 |
|
| } |
| 510 |
0 |
▶ | if (enc->width) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (enc->width) { |
0 |
0 |
0 |
|
| 511 |
0 |
| snprintf(buf + strlen(buf), buf_size - strlen(buf), |
| 512 |
|
| ", %dx%d, %0.2f fps", |
| 513 |
|
| enc->width, enc->height, |
| 514 |
0 |
| (float)enc->frame_rate / enc->frame_rate_base); |
| 515 |
|
| } |
| 516 |
0 |
▶ | if (encode) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (encode) { |
0 |
0 |
0 |
|
| 517 |
0 |
| snprintf(buf + strlen(buf), buf_size - strlen(buf), |
| 518 |
|
| ", q=%d-%d", enc->qmin, enc->qmax); |
| 519 |
|
| } |
| 520 |
0 |
| bitrate = enc->bit_rate; |
| 521 |
0 |
| break; |
| 522 |
0 |
| case CODEC_TYPE_AUDIO: |
| 523 |
0 |
| snprintf(buf, buf_size, |
| 524 |
|
| "Audio: %s", |
| 525 |
|
| codec_name); |
| 526 |
0 |
| switch (enc->channels) { |
| 527 |
0 |
| case 1: |
| 528 |
0 |
| strcpy(channels_str, "mono"); |
| 529 |
0 |
| break; |
| 530 |
0 |
| case 2: |
| 531 |
0 |
| strcpy(channels_str, "stereo"); |
| 532 |
0 |
| break; |
| 533 |
0 |
| case 6: |
| 534 |
0 |
| strcpy(channels_str, "5:1"); |
| 535 |
0 |
| break; |
| 536 |
0 |
| default: |
| 537 |
0 |
| sprintf(channels_str, "%d channels", enc->channels); |
| 538 |
0 |
| break; |
| 539 |
|
| } |
| 540 |
0 |
▶ | if (enc->sample_rate) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (enc->sample_rate) { |
0 |
0 |
0 |
|
| 541 |
0 |
| snprintf(buf + strlen(buf), buf_size - strlen(buf), |
| 542 |
|
| ", %d Hz, %s", |
| 543 |
|
| enc->sample_rate, |
| 544 |
|
| channels_str); |
| 545 |
|
| } |
| 546 |
|
| |
| 547 |
|
| /* for PCM codecs, compute bitrate directly */ |
| 548 |
0 |
| switch(enc->codec_id) { |
| 549 |
0 |
| case CODEC_ID_PCM_S16LE: |
| 550 |
|
| case CODEC_ID_PCM_S16BE: |
| 551 |
|
| case CODEC_ID_PCM_U16LE: |
| 552 |
|
| case CODEC_ID_PCM_U16BE: |
| 553 |
0 |
| bitrate = enc->sample_rate * enc->channels * 16; |
| 554 |
0 |
| break; |
| 555 |
0 |
| case CODEC_ID_PCM_S8: |
| 556 |
|
| case CODEC_ID_PCM_U8: |
| 557 |
|
| case CODEC_ID_PCM_ALAW: |
| 558 |
|
| case CODEC_ID_PCM_MULAW: |
| 559 |
0 |
| bitrate = enc->sample_rate * enc->channels * 8; |
| 560 |
0 |
| break; |
| 561 |
0 |
| default: |
| 562 |
0 |
| bitrate = enc->bit_rate; |
| 563 |
0 |
| break; |
| 564 |
|
| } |
| 565 |
0 |
| break; |
| 566 |
0 |
| default: |
| 567 |
0 |
| av_abort(); |
| 568 |
|
| } |
| 569 |
0 |
▶ | if (encode) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (encode) { |
0 |
0 |
0 |
|
| 570 |
0 |
▶ | if (enc->flags & CODEC_FLAG_PASS1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (enc->flags & CODEC_FLAG_PASS1) |
0 |
0 |
0 |
|
| 571 |
0 |
| snprintf(buf + strlen(buf), buf_size - strlen(buf), |
| 572 |
|
| ", pass 1"); |
| 573 |
0 |
▶ | if (enc->flags & CODEC_FLAG_PASS2) |
Branch: 1 branch
| Branch | True | False | Total |
| if (enc->flags & CODEC_FLAG_PASS2) |
0 |
0 |
0 |
|
| 574 |
0 |
| snprintf(buf + strlen(buf), buf_size - strlen(buf), |
| 575 |
|
| ", pass 2"); |
| 576 |
|
| } |
| 577 |
0 |
▶ | if (bitrate != 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (bitrate != 0) { |
0 |
0 |
0 |
|
| 578 |
0 |
| snprintf(buf + strlen(buf), buf_size - strlen(buf), |
| 579 |
|
| ", %d kb/s", bitrate / 1000); |
| 580 |
|
| } |
| 581 |
0 |
| } |
| 582 |
|
| |
| 583 |
0 |
| unsigned avcodec_version( void ) |
| 584 |
|
| { |
| 585 |
0 |
| return LIBAVCODEC_VERSION_INT; |
| 586 |
|
| } |
| 587 |
|
| |
| 588 |
0 |
| unsigned avcodec_build( void ) |
| 589 |
|
| { |
| 590 |
0 |
| return LIBAVCODEC_BUILD; |
| 591 |
|
| } |
| 592 |
|
| |
| 593 |
|
| /* must be called before any other functions */ |
| 594 |
0 |
| void avcodec_init(void) |
| 595 |
|
| { |
| 596 |
|
| static int inited = 0; |
| 597 |
|
| |
| 598 |
0 |
▶ | if (inited != 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (inited != 0) |
0 |
0 |
0 |
|
| 599 |
0 |
| return; |
| 600 |
0 |
| inited = 1; |
| 601 |
|
| |
| 602 |
|
| // dsputil_static_init(); |
| 603 |
|
| } |
| 604 |
|
| |
| 605 |
|
| /** |
| 606 |
|
| * Flush buffers, should be called when seeking or when swicthing to a different stream. |
| 607 |
|
| */ |
| 608 |
0 |
| void avcodec_flush_buffers(AVCodecContext *avctx) |
| 609 |
|
| { |
| 610 |
0 |
▶ | if(avctx->codec->flush) |
Branch: 1 branch
| Branch | True | False | Total |
| if(avctx->codec->flush) |
0 |
0 |
0 |
|
| 611 |
0 |
| avctx->codec->flush(avctx); |
| 612 |
0 |
| } |
| 613 |
|
| |
| 614 |
0 |
| void avcodec_default_free_buffers(AVCodecContext *s){ |
| 615 |
|
| int i, j; |
| 616 |
|
| |
| 617 |
0 |
▶ | if(s->internal_buffer==NULL) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if(s->internal_buffer==NULL) return; |
0 |
0 |
0 |
|
| 618 |
|
| |
| 619 |
0 |
▶ | for(i=0; i<INTERNAL_BUFFER_SIZE; i++){ |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0; i<INTERNAL_BUFFER_SIZE; i++){ |
0 |
0 |
0 |
|
| 620 |
0 |
| InternalBuffer *buf= &((InternalBuffer*)s->internal_buffer)[i]; |
| 621 |
0 |
▶ | for(j=0; j<4; j++){ |
Branch: 1 branch
| Branch | True | False | Total |
| for(j=0; j<4; j++){ |
0 |
0 |
0 |
|
| 622 |
0 |
| av_freep(&buf->base[j]); |
| 623 |
0 |
| buf->data[j]= NULL; |
| 624 |
|
| } |
| 625 |
|
| } |
| 626 |
0 |
| av_freep(&s->internal_buffer); |
| 627 |
|
| |
| 628 |
0 |
| s->internal_buffer_count=0; |
| 629 |
|
| } |
| 630 |
|
| |
| 631 |
0 |
| char av_get_pict_type_char(int pict_type){ |
| 632 |
0 |
| switch(pict_type){ |
| 633 |
0 |
| case I_TYPE: return 'I'; |
| 634 |
0 |
| case P_TYPE: return 'P'; |
| 635 |
0 |
| case B_TYPE: return 'B'; |
| 636 |
0 |
| case S_TYPE: return 'S'; |
| 637 |
0 |
| case SI_TYPE:return 'i'; |
| 638 |
0 |
| case SP_TYPE:return 'p'; |
| 639 |
0 |
| default: return '?'; |
| 640 |
|
| } |
| 641 |
|
| } |
| 642 |
|
| |
| 643 |
0 |
| int av_reduce(int *dst_nom, int *dst_den, int64_t nom, int64_t den, int64_t max){ |
| 644 |
0 |
| int exact=1, sign=0; |
| 645 |
|
| int64_t gcd, larger; |
| 646 |
|
| |
| 647 |
|
| assert(den != 0); |
| 648 |
|
| |
| 649 |
0 |
▶ | if(den < 0){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(den < 0){ |
0 |
0 |
0 |
|
| 650 |
0 |
| den= -den; |
| 651 |
0 |
| nom= -nom; |
| 652 |
|
| } |
| 653 |
|
| |
| 654 |
0 |
▶ | if(nom < 0){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(nom < 0){ |
0 |
0 |
0 |
|
| 655 |
0 |
| nom= -nom; |
| 656 |
0 |
| sign= 1; |
| 657 |
|
| } |
| 658 |
|
| |
| 659 |
|
| for(;;){ //note is executed 1 or 2 times |
| 660 |
0 |
| gcd = ff_gcd(nom, den); |
| 661 |
0 |
| nom /= gcd; |
| 662 |
0 |
| den /= gcd; |
| 663 |
|
| |
| 664 |
0 |
| larger= FFMAX(nom, den); |
| 665 |
|
| |
| 666 |
0 |
▶ | if(larger > max){ |
Branch: 1 branch
| Branch | True | False | Total |
| if(larger > max){ |
0 |
0 |
0 |
|
| 667 |
0 |
| int64_t div= (larger + max - 1) / max; |
| 668 |
0 |
| nom = (nom + div/2)/div; |
| 669 |
0 |
| den = (den + div/2)/div; |
| 670 |
0 |
| exact=0; |
| 671 |
|
| }else |
| 672 |
0 |
| break; |
| 673 |
|
| } |
| 674 |
|
| |
| 675 |
0 |
▶ | if(sign) nom= -nom; |
Branch: 1 branch
| Branch | True | False | Total |
| if(sign) nom= -nom; |
0 |
0 |
0 |
|
| 676 |
|
| |
| 677 |
0 |
| *dst_nom = nom; |
| 678 |
0 |
| *dst_den = den; |
| 679 |
|
| |
| 680 |
0 |
| return exact; |
| 681 |
|
| } |
| 682 |
|
| |
| 683 |
0 |
| int64_t av_rescale(int64_t a, int64_t b, int64_t c){ |
| 684 |
|
| uint64_t h, l; |
| 685 |
|
| assert(c > 0); |
| 686 |
|
| assert(b >=0); |
| 687 |
|
| |
| 688 |
0 |
▶ | if(a<0) return -av_rescale(-a, b, c); |
Branch: 1 branch
| Branch | True | False | Total |
| if(a<0) return -av_rescale(-a, b, c); |
0 |
0 |
0 |
|
| 689 |
|
| |
| 690 |
0 |
| h= a>>32; |
| 691 |
0 |
▶ | if(h==0) return a*b/c; |
Branch: 1 branch
| Branch | True | False | Total |
| if(h==0) return a*b/c; |
0 |
0 |
0 |
|
| 692 |
|
| |
| 693 |
0 |
| l= a&0xFFFFFFFF; |
| 694 |
0 |
| l *= b; |
| 695 |
0 |
| h *= b; |
| 696 |
|
| |
| 697 |
0 |
| l += (h%c)<<32; |
| 698 |
|
| |
| 699 |
0 |
| return ((h/c)<<32) + l/c; |
| 700 |
|
| } |