Statistics
| Branch: | Revision:

ffmpeg / libavcodec / utils.c @ eb285cfe

History | View | Annotate | Download (37.1 KB)

1
/*
2
 * utils for libavcodec
3
 * Copyright (c) 2001 Fabrice Bellard
4
 * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
5
 *
6
 * This file is part of FFmpeg.
7
 *
8
 * FFmpeg is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU Lesser General Public
10
 * License as published by the Free Software Foundation; either
11
 * version 2.1 of the License, or (at your option) any later version.
12
 *
13
 * FFmpeg is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16
 * Lesser General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU Lesser General Public
19
 * License along with FFmpeg; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
 */
22

    
23
/**
24
 * @file libavcodec/utils.c
25
 * utils.
26
 */
27

    
28
/* needed for mkstemp() */
29
#define _XOPEN_SOURCE 600
30

    
31
#include "libavutil/avstring.h"
32
#include "libavutil/integer.h"
33
#include "libavutil/crc.h"
34
#include "libavutil/pixdesc.h"
35
#include "avcodec.h"
36
#include "dsputil.h"
37
#include "opt.h"
38
#include "imgconvert.h"
39
#include "audioconvert.h"
40
#include "internal.h"
41
#include <stdlib.h>
42
#include <stdarg.h>
43
#include <limits.h>
44
#include <float.h>
45
#if !HAVE_MKSTEMP
46
#include <fcntl.h>
47
#endif
48

    
49
static int volatile entangled_thread_counter=0;
50
int (*ff_lockmgr_cb)(void **mutex, enum AVLockOp op);
51
static void *codec_mutex;
52

    
53
void *av_fast_realloc(void *ptr, unsigned int *size, unsigned int min_size)
54
{
55
    if(min_size < *size)
56
        return ptr;
57

    
58
    *size= FFMAX(17*min_size/16 + 32, min_size);
59

    
60
    ptr= av_realloc(ptr, *size);
61
    if(!ptr) //we could set this to the unmodified min_size but this is safer if the user lost the ptr and uses NULL now
62
        *size= 0;
63

    
64
    return ptr;
65
}
66

    
67
void av_fast_malloc(void *ptr, unsigned int *size, unsigned int min_size)
68
{
69
    void **p = ptr;
70
    if (min_size < *size)
71
        return;
72
    *size= FFMAX(17*min_size/16 + 32, min_size);
73
    av_free(*p);
74
    *p = av_malloc(*size);
75
    if (!*p) *size = 0;
76
}
77

    
78
/* encoder management */
79
static AVCodec *first_avcodec = NULL;
80

    
81
AVCodec *av_codec_next(AVCodec *c){
82
    if(c) return c->next;
83
    else  return first_avcodec;
84
}
85

    
86
void avcodec_register(AVCodec *codec)
87
{
88
    AVCodec **p;
89
    avcodec_init();
90
    p = &first_avcodec;
91
    while (*p != NULL) p = &(*p)->next;
92
    *p = codec;
93
    codec->next = NULL;
94
}
95

    
96
#if LIBAVCODEC_VERSION_MAJOR < 53
97
void register_avcodec(AVCodec *codec)
98
{
99
    avcodec_register(codec);
100
}
101
#endif
102

    
103
void avcodec_set_dimensions(AVCodecContext *s, int width, int height){
104
    s->coded_width = width;
105
    s->coded_height= height;
106
    s->width = -((-width )>>s->lowres);
107
    s->height= -((-height)>>s->lowres);
108
}
109

    
110
typedef struct InternalBuffer{
111
    int last_pic_num;
112
    uint8_t *base[4];
113
    uint8_t *data[4];
114
    int linesize[4];
115
    int width, height;
116
    enum PixelFormat pix_fmt;
117
}InternalBuffer;
118

    
119
#define INTERNAL_BUFFER_SIZE 32
120

    
121
void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, int linesize_align[4]){
122
    int w_align= 1;
123
    int h_align= 1;
124

    
125
    switch(s->pix_fmt){
126
    case PIX_FMT_YUV420P:
127
    case PIX_FMT_YUYV422:
128
    case PIX_FMT_UYVY422:
129
    case PIX_FMT_YUV422P:
130
    case PIX_FMT_YUV440P:
131
    case PIX_FMT_YUV444P:
132
    case PIX_FMT_GRAY8:
133
    case PIX_FMT_GRAY16BE:
134
    case PIX_FMT_GRAY16LE:
135
    case PIX_FMT_YUVJ420P:
136
    case PIX_FMT_YUVJ422P:
137
    case PIX_FMT_YUVJ440P:
138
    case PIX_FMT_YUVJ444P:
139
    case PIX_FMT_YUVA420P:
140
        w_align= 16; //FIXME check for non mpeg style codecs and use less alignment
141
        h_align= 16;
142
        if(s->codec_id == CODEC_ID_MPEG2VIDEO || s->codec_id == CODEC_ID_MJPEG || s->codec_id == CODEC_ID_AMV || s->codec_id == CODEC_ID_THP)
143
            h_align= 32; // interlaced is rounded up to 2 MBs
144
        break;
145
    case PIX_FMT_YUV411P:
146
    case PIX_FMT_UYYVYY411:
147
        w_align=32;
148
        h_align=8;
149
        break;
150
    case PIX_FMT_YUV410P:
151
        if(s->codec_id == CODEC_ID_SVQ1){
152
            w_align=64;
153
            h_align=64;
154
        }
155
    case PIX_FMT_RGB555:
156
        if(s->codec_id == CODEC_ID_RPZA){
157
            w_align=4;
158
            h_align=4;
159
        }
160
    case PIX_FMT_PAL8:
161
    case PIX_FMT_BGR8:
162
    case PIX_FMT_RGB8:
163
        if(s->codec_id == CODEC_ID_SMC){
164
            w_align=4;
165
            h_align=4;
166
        }
167
        break;
168
    case PIX_FMT_BGR24:
169
        if((s->codec_id == CODEC_ID_MSZH) || (s->codec_id == CODEC_ID_ZLIB)){
170
            w_align=4;
171
            h_align=4;
172
        }
173
        break;
174
    default:
175
        w_align= 1;
176
        h_align= 1;
177
        break;
178
    }
179

    
180
    *width = FFALIGN(*width , w_align);
181
    *height= FFALIGN(*height, h_align);
182
    if(s->codec_id == CODEC_ID_H264)
183
        *height+=2; // some of the optimized chroma MC reads one line too much
184

    
185
    linesize_align[0] =
186
    linesize_align[1] =
187
    linesize_align[2] =
188
    linesize_align[3] = STRIDE_ALIGN;
189
//STRIDE_ALIGN is 8 for SSE* but this does not work for SVQ1 chroma planes
190
//we could change STRIDE_ALIGN to 16 for x86/sse but it would increase the
191
//picture size unneccessarily in some cases. The solution here is not
192
//pretty and better ideas are welcome!
193
#if HAVE_MMX
194
    if(s->codec_id == CODEC_ID_SVQ1 || s->codec_id == CODEC_ID_VP5 ||
195
       s->codec_id == CODEC_ID_VP6 || s->codec_id == CODEC_ID_VP6F ||
196
       s->codec_id == CODEC_ID_VP6A) {
197
        linesize_align[0] =
198
        linesize_align[1] =
199
        linesize_align[2] = 16;
200
    }
201
#endif
202
}
203

    
204
void avcodec_align_dimensions(AVCodecContext *s, int *width, int *height){
205
    int chroma_shift = av_pix_fmt_descriptors[s->pix_fmt].log2_chroma_w;
206
    int linesize_align[4];
207
    int align;
208
    avcodec_align_dimensions2(s, width, height, linesize_align);
209
    align = FFMAX(linesize_align[0], linesize_align[3]);
210
    linesize_align[1] <<= chroma_shift;
211
    linesize_align[2] <<= chroma_shift;
212
    align = FFMAX3(align, linesize_align[1], linesize_align[2]);
213
    *width=FFALIGN(*width, align);
214
}
215

    
216
int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h){
217
    if((int)w>0 && (int)h>0 && (w+128)*(uint64_t)(h+128) < INT_MAX/8)
218
        return 0;
219

    
220
    av_log(av_log_ctx, AV_LOG_ERROR, "picture size invalid (%ux%u)\n", w, h);
221
    return -1;
222
}
223

    
224
int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
225
    int i;
226
    int w= s->width;
227
    int h= s->height;
228
    InternalBuffer *buf;
229
    int *picture_number;
230

    
231
    if(pic->data[0]!=NULL) {
232
        av_log(s, AV_LOG_ERROR, "pic->data[0]!=NULL in avcodec_default_get_buffer\n");
233
        return -1;
234
    }
235
    if(s->internal_buffer_count >= INTERNAL_BUFFER_SIZE) {
236
        av_log(s, AV_LOG_ERROR, "internal_buffer_count overflow (missing release_buffer?)\n");
237
        return -1;
238
    }
239

    
240
    if(avcodec_check_dimensions(s,w,h))
241
        return -1;
242

    
243
    if(s->internal_buffer==NULL){
244
        s->internal_buffer= av_mallocz((INTERNAL_BUFFER_SIZE+1)*sizeof(InternalBuffer));
245
    }
246
#if 0
247
    s->internal_buffer= av_fast_realloc(
248
        s->internal_buffer,
249
        &s->internal_buffer_size,
250
        sizeof(InternalBuffer)*FFMAX(99,  s->internal_buffer_count+1)/*FIXME*/
251
        );
252
#endif
253

    
254
    buf= &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
255
    picture_number= &(((InternalBuffer*)s->internal_buffer)[INTERNAL_BUFFER_SIZE]).last_pic_num; //FIXME ugly hack
256
    (*picture_number)++;
257

    
258
    if(buf->base[0] && (buf->width != w || buf->height != h || buf->pix_fmt != s->pix_fmt)){
259
        for(i=0; i<4; i++){
260
            av_freep(&buf->base[i]);
261
            buf->data[i]= NULL;
262
        }
263
    }
264

    
265
    if(buf->base[0]){
266
        pic->age= *picture_number - buf->last_pic_num;
267
        buf->last_pic_num= *picture_number;
268
    }else{
269
        int h_chroma_shift, v_chroma_shift;
270
        int size[4] = {0};
271
        int tmpsize;
272
        int unaligned;
273
        AVPicture picture;
274
        int stride_align[4];
275

    
276
        avcodec_get_chroma_sub_sample(s->pix_fmt, &h_chroma_shift, &v_chroma_shift);
277

    
278
        avcodec_align_dimensions2(s, &w, &h, stride_align);
279

    
280
        if(!(s->flags&CODEC_FLAG_EMU_EDGE)){
281
            w+= EDGE_WIDTH*2;
282
            h+= EDGE_WIDTH*2;
283
        }
284

    
285
        do {
286
            // NOTE: do not align linesizes individually, this breaks e.g. assumptions
287
            // that linesize[0] == 2*linesize[1] in the MPEG-encoder for 4:2:2
288
            ff_fill_linesize(&picture, s->pix_fmt, w);
289
            // increase alignment of w for next try (rhs gives the lowest bit set in w)
290
            w += w & ~(w-1);
291

    
292
            unaligned = 0;
293
            for (i=0; i<4; i++){
294
                unaligned |= picture.linesize[i] % stride_align[i];
295
            }
296
        } while (unaligned);
297

    
298
        tmpsize = ff_fill_pointer(&picture, NULL, s->pix_fmt, h);
299
        if (tmpsize < 0)
300
            return -1;
301

    
302
        for (i=0; i<3 && picture.data[i+1]; i++)
303
            size[i] = picture.data[i+1] - picture.data[i];
304
        size[i] = tmpsize - (picture.data[i] - picture.data[0]);
305

    
306
        buf->last_pic_num= -256*256*256*64;
307
        memset(buf->base, 0, sizeof(buf->base));
308
        memset(buf->data, 0, sizeof(buf->data));
309

    
310
        for(i=0; i<4 && size[i]; i++){
311
            const int h_shift= i==0 ? 0 : h_chroma_shift;
312
            const int v_shift= i==0 ? 0 : v_chroma_shift;
313

    
314
            buf->linesize[i]= picture.linesize[i];
315

    
316
            buf->base[i]= av_malloc(size[i]+16); //FIXME 16
317
            if(buf->base[i]==NULL) return -1;
318
            memset(buf->base[i], 128, size[i]);
319

    
320
            // no edge if EDEG EMU or not planar YUV
321
            if((s->flags&CODEC_FLAG_EMU_EDGE) || !size[2])
322
                buf->data[i] = buf->base[i];
323
            else
324
                buf->data[i] = buf->base[i] + FFALIGN((buf->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift), stride_align[i]);
325
        }
326
        if(size[1] && !size[2])
327
            ff_set_systematic_pal((uint32_t*)buf->data[1], s->pix_fmt);
328
        buf->width  = s->width;
329
        buf->height = s->height;
330
        buf->pix_fmt= s->pix_fmt;
331
        pic->age= 256*256*256*64;
332
    }
333
    pic->type= FF_BUFFER_TYPE_INTERNAL;
334

    
335
    for(i=0; i<4; i++){
336
        pic->base[i]= buf->base[i];
337
        pic->data[i]= buf->data[i];
338
        pic->linesize[i]= buf->linesize[i];
339
    }
340
    s->internal_buffer_count++;
341

    
342
    pic->reordered_opaque= s->reordered_opaque;
343

    
344
    if(s->debug&FF_DEBUG_BUFFERS)
345
        av_log(s, AV_LOG_DEBUG, "default_get_buffer called on pic %p, %d buffers used\n", pic, s->internal_buffer_count);
346

    
347
    return 0;
348
}
349

    
350
void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
351
    int i;
352
    InternalBuffer *buf, *last;
353

    
354
    assert(pic->type==FF_BUFFER_TYPE_INTERNAL);
355
    assert(s->internal_buffer_count);
356

    
357
    buf = NULL; /* avoids warning */
358
    for(i=0; i<s->internal_buffer_count; i++){ //just 3-5 checks so is not worth to optimize
359
        buf= &((InternalBuffer*)s->internal_buffer)[i];
360
        if(buf->data[0] == pic->data[0])
361
            break;
362
    }
363
    assert(i < s->internal_buffer_count);
364
    s->internal_buffer_count--;
365
    last = &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
366

    
367
    FFSWAP(InternalBuffer, *buf, *last);
368

    
369
    for(i=0; i<4; i++){
370
        pic->data[i]=NULL;
371
//        pic->base[i]=NULL;
372
    }
373
//printf("R%X\n", pic->opaque);
374

    
375
    if(s->debug&FF_DEBUG_BUFFERS)
376
        av_log(s, AV_LOG_DEBUG, "default_release_buffer called on pic %p, %d buffers used\n", pic, s->internal_buffer_count);
377
}
378

    
379
int avcodec_default_reget_buffer(AVCodecContext *s, AVFrame *pic){
380
    AVFrame temp_pic;
381
    int i;
382

    
383
    /* If no picture return a new buffer */
384
    if(pic->data[0] == NULL) {
385
        /* We will copy from buffer, so must be readable */
386
        pic->buffer_hints |= FF_BUFFER_HINTS_READABLE;
387
        return s->get_buffer(s, pic);
388
    }
389

    
390
    /* If internal buffer type return the same buffer */
391
    if(pic->type == FF_BUFFER_TYPE_INTERNAL) {
392
        pic->reordered_opaque= s->reordered_opaque;
393
        return 0;
394
    }
395

    
396
    /*
397
     * Not internal type and reget_buffer not overridden, emulate cr buffer
398
     */
399
    temp_pic = *pic;
400
    for(i = 0; i < 4; i++)
401
        pic->data[i] = pic->base[i] = NULL;
402
    pic->opaque = NULL;
403
    /* Allocate new frame */
404
    if (s->get_buffer(s, pic))
405
        return -1;
406
    /* Copy image data from old buffer to new buffer */
407
    av_picture_copy((AVPicture*)pic, (AVPicture*)&temp_pic, s->pix_fmt, s->width,
408
             s->height);
409
    s->release_buffer(s, &temp_pic); // Release old frame
410
    return 0;
411
}
412

    
413
int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size){
414
    int i;
415

    
416
    for(i=0; i<count; i++){
417
        int r= func(c, (char*)arg + i*size);
418
        if(ret) ret[i]= r;
419
    }
420
    return 0;
421
}
422

    
423
int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int jobnr, int threadnr),void *arg, int *ret, int count){
424
    int i;
425

    
426
    for(i=0; i<count; i++){
427
        int r= func(c, arg, i, 0);
428
        if(ret) ret[i]= r;
429
    }
430
    return 0;
431
}
432

    
433
enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat *fmt){
434
    while (*fmt != PIX_FMT_NONE && ff_is_hwaccel_pix_fmt(*fmt))
435
        ++fmt;
436
    return fmt[0];
437
}
438

    
439
void avcodec_get_frame_defaults(AVFrame *pic){
440
    memset(pic, 0, sizeof(AVFrame));
441

    
442
    pic->pts= AV_NOPTS_VALUE;
443
    pic->key_frame= 1;
444
}
445

    
446
AVFrame *avcodec_alloc_frame(void){
447
    AVFrame *pic= av_malloc(sizeof(AVFrame));
448

    
449
    if(pic==NULL) return NULL;
450

    
451
    avcodec_get_frame_defaults(pic);
452

    
453
    return pic;
454
}
455

    
456
int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
457
{
458
    int ret= -1;
459

    
460
    /* If there is a user-supplied mutex locking routine, call it. */
461
    if (ff_lockmgr_cb) {
462
        if ((*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
463
            return -1;
464
    }
465

    
466
    entangled_thread_counter++;
467
    if(entangled_thread_counter != 1){
468
        av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
469
        goto end;
470
    }
471

    
472
    if(avctx->codec || !codec)
473
        goto end;
474

    
475
    if (codec->priv_data_size > 0) {
476
        avctx->priv_data = av_mallocz(codec->priv_data_size);
477
        if (!avctx->priv_data) {
478
            ret = AVERROR(ENOMEM);
479
            goto end;
480
        }
481
    } else {
482
        avctx->priv_data = NULL;
483
    }
484

    
485
    if(avctx->coded_width && avctx->coded_height)
486
        avcodec_set_dimensions(avctx, avctx->coded_width, avctx->coded_height);
487
    else if(avctx->width && avctx->height)
488
        avcodec_set_dimensions(avctx, avctx->width, avctx->height);
489

    
490
#define SANE_NB_CHANNELS 128U
491
    if (((avctx->coded_width || avctx->coded_height)
492
        && avcodec_check_dimensions(avctx, avctx->coded_width, avctx->coded_height))
493
        || avctx->channels > SANE_NB_CHANNELS) {
494
        ret = AVERROR(EINVAL);
495
        goto free_and_end;
496
    }
497

    
498
    avctx->codec = codec;
499
    if ((avctx->codec_type == CODEC_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&
500
        avctx->codec_id == CODEC_ID_NONE) {
501
        avctx->codec_type = codec->type;
502
        avctx->codec_id   = codec->id;
503
    }
504
    if(avctx->codec_id != codec->id || avctx->codec_type != codec->type){
505
        av_log(avctx, AV_LOG_ERROR, "codec type or id mismatches\n");
506
        goto free_and_end;
507
    }
508
    avctx->frame_number = 0;
509
    if(avctx->codec->init){
510
        ret = avctx->codec->init(avctx);
511
        if (ret < 0) {
512
            goto free_and_end;
513
        }
514
    }
515
    ret=0;
516
end:
517
    entangled_thread_counter--;
518

    
519
    /* Release any user-supplied mutex. */
520
    if (ff_lockmgr_cb) {
521
        (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
522
    }
523
    return ret;
524
free_and_end:
525
    av_freep(&avctx->priv_data);
526
    avctx->codec= NULL;
527
    goto end;
528
}
529

    
530
int attribute_align_arg avcodec_encode_audio(AVCodecContext *avctx, uint8_t *buf, int buf_size,
531
                         const short *samples)
532
{
533
    if(buf_size < FF_MIN_BUFFER_SIZE && 0){
534
        av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
535
        return -1;
536
    }
537
    if((avctx->codec->capabilities & CODEC_CAP_DELAY) || samples){
538
        int ret = avctx->codec->encode(avctx, buf, buf_size, samples);
539
        avctx->frame_number++;
540
        return ret;
541
    }else
542
        return 0;
543
}
544

    
545
int attribute_align_arg avcodec_encode_video(AVCodecContext *avctx, uint8_t *buf, int buf_size,
546
                         const AVFrame *pict)
547
{
548
    if(buf_size < FF_MIN_BUFFER_SIZE){
549
        av_log(avctx, AV_LOG_ERROR, "buffer smaller than minimum size\n");
550
        return -1;
551
    }
552
    if(avcodec_check_dimensions(avctx,avctx->width,avctx->height))
553
        return -1;
554
    if((avctx->codec->capabilities & CODEC_CAP_DELAY) || pict){
555
        int ret = avctx->codec->encode(avctx, buf, buf_size, pict);
556
        avctx->frame_number++;
557
        emms_c(); //needed to avoid an emms_c() call before every return;
558

    
559
        return ret;
560
    }else
561
        return 0;
562
}
563

    
564
int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
565
                            const AVSubtitle *sub)
566
{
567
    int ret;
568
    if(sub->start_display_time) {
569
        av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n");
570
        return -1;
571
    }
572
    if(sub->num_rects == 0 || !sub->rects)
573
        return -1;
574
    ret = avctx->codec->encode(avctx, buf, buf_size, sub);
575
    avctx->frame_number++;
576
    return ret;
577
}
578

    
579
#if LIBAVCODEC_VERSION_MAJOR < 53
580
int attribute_align_arg avcodec_decode_video(AVCodecContext *avctx, AVFrame *picture,
581
                         int *got_picture_ptr,
582
                         const uint8_t *buf, int buf_size)
583
{
584
    AVPacket avpkt;
585
    av_init_packet(&avpkt);
586
    avpkt.data = buf;
587
    avpkt.size = buf_size;
588
    // HACK for CorePNG to decode as normal PNG by default
589
    avpkt.flags = AV_PKT_FLAG_KEY;
590

    
591
    return avcodec_decode_video2(avctx, picture, got_picture_ptr, &avpkt);
592
}
593
#endif
594

    
595
int attribute_align_arg avcodec_decode_video2(AVCodecContext *avctx, AVFrame *picture,
596
                         int *got_picture_ptr,
597
                         AVPacket *avpkt)
598
{
599
    int ret;
600

    
601
    *got_picture_ptr= 0;
602
    if((avctx->coded_width||avctx->coded_height) && avcodec_check_dimensions(avctx,avctx->coded_width,avctx->coded_height))
603
        return -1;
604
    if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size){
605
        ret = avctx->codec->decode(avctx, picture, got_picture_ptr,
606
                                avpkt);
607

    
608
        emms_c(); //needed to avoid an emms_c() call before every return;
609

    
610
        if (*got_picture_ptr)
611
            avctx->frame_number++;
612
    }else
613
        ret= 0;
614

    
615
    return ret;
616
}
617

    
618
#if LIBAVCODEC_VERSION_MAJOR < 53
619
int attribute_align_arg avcodec_decode_audio2(AVCodecContext *avctx, int16_t *samples,
620
                         int *frame_size_ptr,
621
                         const uint8_t *buf, int buf_size)
622
{
623
    AVPacket avpkt;
624
    av_init_packet(&avpkt);
625
    avpkt.data = buf;
626
    avpkt.size = buf_size;
627

    
628
    return avcodec_decode_audio3(avctx, samples, frame_size_ptr, &avpkt);
629
}
630
#endif
631

    
632
int attribute_align_arg avcodec_decode_audio3(AVCodecContext *avctx, int16_t *samples,
633
                         int *frame_size_ptr,
634
                         AVPacket *avpkt)
635
{
636
    int ret;
637

    
638
    if((avctx->codec->capabilities & CODEC_CAP_DELAY) || avpkt->size){
639
        //FIXME remove the check below _after_ ensuring that all audio check that the available space is enough
640
        if(*frame_size_ptr < AVCODEC_MAX_AUDIO_FRAME_SIZE){
641
            av_log(avctx, AV_LOG_ERROR, "buffer smaller than AVCODEC_MAX_AUDIO_FRAME_SIZE\n");
642
            return -1;
643
        }
644
        if(*frame_size_ptr < FF_MIN_BUFFER_SIZE ||
645
        *frame_size_ptr < avctx->channels * avctx->frame_size * sizeof(int16_t)){
646
            av_log(avctx, AV_LOG_ERROR, "buffer %d too small\n", *frame_size_ptr);
647
            return -1;
648
        }
649

    
650
        ret = avctx->codec->decode(avctx, samples, frame_size_ptr, avpkt);
651
        avctx->frame_number++;
652
    }else{
653
        ret= 0;
654
        *frame_size_ptr=0;
655
    }
656
    return ret;
657
}
658

    
659
#if LIBAVCODEC_VERSION_MAJOR < 53
660
int avcodec_decode_subtitle(AVCodecContext *avctx, AVSubtitle *sub,
661
                            int *got_sub_ptr,
662
                            const uint8_t *buf, int buf_size)
663
{
664
    AVPacket avpkt;
665
    av_init_packet(&avpkt);
666
    avpkt.data = buf;
667
    avpkt.size = buf_size;
668

    
669
    return avcodec_decode_subtitle2(avctx, sub, got_sub_ptr, &avpkt);
670
}
671
#endif
672

    
673
int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
674
                            int *got_sub_ptr,
675
                            AVPacket *avpkt)
676
{
677
    int ret;
678

    
679
    *got_sub_ptr = 0;
680
    ret = avctx->codec->decode(avctx, sub, got_sub_ptr, avpkt);
681
    if (*got_sub_ptr)
682
        avctx->frame_number++;
683
    return ret;
684
}
685

    
686
av_cold int avcodec_close(AVCodecContext *avctx)
687
{
688
    /* If there is a user-supplied mutex locking routine, call it. */
689
    if (ff_lockmgr_cb) {
690
        if ((*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
691
            return -1;
692
    }
693

    
694
    entangled_thread_counter++;
695
    if(entangled_thread_counter != 1){
696
        av_log(avctx, AV_LOG_ERROR, "insufficient thread locking around avcodec_open/close()\n");
697
        entangled_thread_counter--;
698
        return -1;
699
    }
700

    
701
    if (HAVE_THREADS && avctx->thread_opaque)
702
        avcodec_thread_free(avctx);
703
    if (avctx->codec && avctx->codec->close)
704
        avctx->codec->close(avctx);
705
    avcodec_default_free_buffers(avctx);
706
    av_freep(&avctx->priv_data);
707
    if(avctx->codec->encode)
708
        av_freep(&avctx->extradata);
709
    avctx->codec = NULL;
710
    entangled_thread_counter--;
711

    
712
    /* Release any user-supplied mutex. */
713
    if (ff_lockmgr_cb) {
714
        (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
715
    }
716
    return 0;
717
}
718

    
719
AVCodec *avcodec_find_encoder(enum CodecID id)
720
{
721
    AVCodec *p;
722
    p = first_avcodec;
723
    while (p) {
724
        if (p->encode != NULL && p->id == id)
725
            return p;
726
        p = p->next;
727
    }
728
    return NULL;
729
}
730

    
731
AVCodec *avcodec_find_encoder_by_name(const char *name)
732
{
733
    AVCodec *p;
734
    if (!name)
735
        return NULL;
736
    p = first_avcodec;
737
    while (p) {
738
        if (p->encode != NULL && strcmp(name,p->name) == 0)
739
            return p;
740
        p = p->next;
741
    }
742
    return NULL;
743
}
744

    
745
AVCodec *avcodec_find_decoder(enum CodecID id)
746
{
747
    AVCodec *p;
748
    p = first_avcodec;
749
    while (p) {
750
        if (p->decode != NULL && p->id == id)
751
            return p;
752
        p = p->next;
753
    }
754
    return NULL;
755
}
756

    
757
AVCodec *avcodec_find_decoder_by_name(const char *name)
758
{
759
    AVCodec *p;
760
    if (!name)
761
        return NULL;
762
    p = first_avcodec;
763
    while (p) {
764
        if (p->decode != NULL && strcmp(name,p->name) == 0)
765
            return p;
766
        p = p->next;
767
    }
768
    return NULL;
769
}
770

    
771
int av_get_bit_rate(AVCodecContext *ctx)
772
{
773
    int bit_rate;
774
    int bits_per_sample;
775

    
776
    switch(ctx->codec_type) {
777
    case CODEC_TYPE_VIDEO:
778
        bit_rate = ctx->bit_rate;
779
        break;
780
    case CODEC_TYPE_AUDIO:
781
        bits_per_sample = av_get_bits_per_sample(ctx->codec_id);
782
        bit_rate = bits_per_sample ? ctx->sample_rate * ctx->channels * bits_per_sample : ctx->bit_rate;
783
        break;
784
    case CODEC_TYPE_DATA:
785
        bit_rate = ctx->bit_rate;
786
        break;
787
    case CODEC_TYPE_SUBTITLE:
788
        bit_rate = ctx->bit_rate;
789
        break;
790
    case CODEC_TYPE_ATTACHMENT:
791
        bit_rate = ctx->bit_rate;
792
        break;
793
    default:
794
        bit_rate = 0;
795
        break;
796
    }
797
    return bit_rate;
798
}
799

    
800
void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode)
801
{
802
    const char *codec_name;
803
    AVCodec *p;
804
    char buf1[32];
805
    int bitrate;
806
    AVRational display_aspect_ratio;
807

    
808
    if (encode)
809
        p = avcodec_find_encoder(enc->codec_id);
810
    else
811
        p = avcodec_find_decoder(enc->codec_id);
812

    
813
    if (p) {
814
        codec_name = p->name;
815
    } else if (enc->codec_id == CODEC_ID_MPEG2TS) {
816
        /* fake mpeg2 transport stream codec (currently not
817
           registered) */
818
        codec_name = "mpeg2ts";
819
    } else if (enc->codec_name[0] != '\0') {
820
        codec_name = enc->codec_name;
821
    } else {
822
        /* output avi tags */
823
        if(   isprint(enc->codec_tag&0xFF) && isprint((enc->codec_tag>>8)&0xFF)
824
           && isprint((enc->codec_tag>>16)&0xFF) && isprint((enc->codec_tag>>24)&0xFF)){
825
            snprintf(buf1, sizeof(buf1), "%c%c%c%c / 0x%04X",
826
                     enc->codec_tag & 0xff,
827
                     (enc->codec_tag >> 8) & 0xff,
828
                     (enc->codec_tag >> 16) & 0xff,
829
                     (enc->codec_tag >> 24) & 0xff,
830
                      enc->codec_tag);
831
        } else {
832
            snprintf(buf1, sizeof(buf1), "0x%04x", enc->codec_tag);
833
        }
834
        codec_name = buf1;
835
    }
836

    
837
    switch(enc->codec_type) {
838
    case CODEC_TYPE_VIDEO:
839
        snprintf(buf, buf_size,
840
                 "Video: %s%s",
841
                 codec_name, enc->mb_decision ? " (hq)" : "");
842
        if (enc->pix_fmt != PIX_FMT_NONE) {
843
            snprintf(buf + strlen(buf), buf_size - strlen(buf),
844
                     ", %s",
845
                     avcodec_get_pix_fmt_name(enc->pix_fmt));
846
        }
847
        if (enc->width) {
848
            snprintf(buf + strlen(buf), buf_size - strlen(buf),
849
                     ", %dx%d",
850
                     enc->width, enc->height);
851
            if (enc->sample_aspect_ratio.num) {
852
                av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
853
                          enc->width*enc->sample_aspect_ratio.num,
854
                          enc->height*enc->sample_aspect_ratio.den,
855
                          1024*1024);
856
                snprintf(buf + strlen(buf), buf_size - strlen(buf),
857
                         " [PAR %d:%d DAR %d:%d]",
858
                         enc->sample_aspect_ratio.num, enc->sample_aspect_ratio.den,
859
                         display_aspect_ratio.num, display_aspect_ratio.den);
860
            }
861
            if(av_log_get_level() >= AV_LOG_DEBUG){
862
                int g= av_gcd(enc->time_base.num, enc->time_base.den);
863
                snprintf(buf + strlen(buf), buf_size - strlen(buf),
864
                     ", %d/%d",
865
                     enc->time_base.num/g, enc->time_base.den/g);
866
            }
867
        }
868
        if (encode) {
869
            snprintf(buf + strlen(buf), buf_size - strlen(buf),
870
                     ", q=%d-%d", enc->qmin, enc->qmax);
871
        }
872
        break;
873
    case CODEC_TYPE_AUDIO:
874
        snprintf(buf, buf_size,
875
                 "Audio: %s",
876
                 codec_name);
877
        if (enc->sample_rate) {
878
            snprintf(buf + strlen(buf), buf_size - strlen(buf),
879
                     ", %d Hz", enc->sample_rate);
880
        }
881
        av_strlcat(buf, ", ", buf_size);
882
        avcodec_get_channel_layout_string(buf + strlen(buf), buf_size - strlen(buf), enc->channels, enc->channel_layout);
883
        if (enc->sample_fmt != SAMPLE_FMT_NONE) {
884
            snprintf(buf + strlen(buf), buf_size - strlen(buf),
885
                     ", %s", avcodec_get_sample_fmt_name(enc->sample_fmt));
886
        }
887
        break;
888
    case CODEC_TYPE_DATA:
889
        snprintf(buf, buf_size, "Data: %s", codec_name);
890
        break;
891
    case CODEC_TYPE_SUBTITLE:
892
        snprintf(buf, buf_size, "Subtitle: %s", codec_name);
893
        break;
894
    case CODEC_TYPE_ATTACHMENT:
895
        snprintf(buf, buf_size, "Attachment: %s", codec_name);
896
        break;
897
    default:
898
        snprintf(buf, buf_size, "Invalid Codec type %d", enc->codec_type);
899
        return;
900
    }
901
    if (encode) {
902
        if (enc->flags & CODEC_FLAG_PASS1)
903
            snprintf(buf + strlen(buf), buf_size - strlen(buf),
904
                     ", pass 1");
905
        if (enc->flags & CODEC_FLAG_PASS2)
906
            snprintf(buf + strlen(buf), buf_size - strlen(buf),
907
                     ", pass 2");
908
    }
909
    bitrate = av_get_bit_rate(enc);
910
    if (bitrate != 0) {
911
        snprintf(buf + strlen(buf), buf_size - strlen(buf),
912
                 ", %d kb/s", bitrate / 1000);
913
    }
914
}
915

    
916
unsigned avcodec_version( void )
917
{
918
  return LIBAVCODEC_VERSION_INT;
919
}
920

    
921
const char *avcodec_configuration(void)
922
{
923
    return FFMPEG_CONFIGURATION;
924
}
925

    
926
const char *avcodec_license(void)
927
{
928
#define LICENSE_PREFIX "libavcodec license: "
929
    return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
930
}
931

    
932
void avcodec_init(void)
933
{
934
    static int initialized = 0;
935

    
936
    if (initialized != 0)
937
        return;
938
    initialized = 1;
939

    
940
    dsputil_static_init();
941
}
942

    
943
void avcodec_flush_buffers(AVCodecContext *avctx)
944
{
945
    if(avctx->codec->flush)
946
        avctx->codec->flush(avctx);
947
}
948

    
949
void avcodec_default_free_buffers(AVCodecContext *s){
950
    int i, j;
951

    
952
    if(s->internal_buffer==NULL) return;
953

    
954
    if (s->internal_buffer_count)
955
        av_log(s, AV_LOG_WARNING, "Found %i unreleased buffers!\n", s->internal_buffer_count);
956
    for(i=0; i<INTERNAL_BUFFER_SIZE; i++){
957
        InternalBuffer *buf= &((InternalBuffer*)s->internal_buffer)[i];
958
        for(j=0; j<4; j++){
959
            av_freep(&buf->base[j]);
960
            buf->data[j]= NULL;
961
        }
962
    }
963
    av_freep(&s->internal_buffer);
964

    
965
    s->internal_buffer_count=0;
966
}
967

    
968
char av_get_pict_type_char(int pict_type){
969
    switch(pict_type){
970
    case FF_I_TYPE: return 'I';
971
    case FF_P_TYPE: return 'P';
972
    case FF_B_TYPE: return 'B';
973
    case FF_S_TYPE: return 'S';
974
    case FF_SI_TYPE:return 'i';
975
    case FF_SP_TYPE:return 'p';
976
    case FF_BI_TYPE:return 'b';
977
    default:        return '?';
978
    }
979
}
980

    
981
int av_get_bits_per_sample(enum CodecID codec_id){
982
    switch(codec_id){
983
    case CODEC_ID_ADPCM_SBPRO_2:
984
        return 2;
985
    case CODEC_ID_ADPCM_SBPRO_3:
986
        return 3;
987
    case CODEC_ID_ADPCM_SBPRO_4:
988
    case CODEC_ID_ADPCM_CT:
989
    case CODEC_ID_ADPCM_IMA_WAV:
990
    case CODEC_ID_ADPCM_MS:
991
    case CODEC_ID_ADPCM_YAMAHA:
992
        return 4;
993
    case CODEC_ID_PCM_ALAW:
994
    case CODEC_ID_PCM_MULAW:
995
    case CODEC_ID_PCM_S8:
996
    case CODEC_ID_PCM_U8:
997
    case CODEC_ID_PCM_ZORK:
998
        return 8;
999
    case CODEC_ID_PCM_S16BE:
1000
    case CODEC_ID_PCM_S16LE:
1001
    case CODEC_ID_PCM_S16LE_PLANAR:
1002
    case CODEC_ID_PCM_U16BE:
1003
    case CODEC_ID_PCM_U16LE:
1004
        return 16;
1005
    case CODEC_ID_PCM_S24DAUD:
1006
    case CODEC_ID_PCM_S24BE:
1007
    case CODEC_ID_PCM_S24LE:
1008
    case CODEC_ID_PCM_U24BE:
1009
    case CODEC_ID_PCM_U24LE:
1010
        return 24;
1011
    case CODEC_ID_PCM_S32BE:
1012
    case CODEC_ID_PCM_S32LE:
1013
    case CODEC_ID_PCM_U32BE:
1014
    case CODEC_ID_PCM_U32LE:
1015
    case CODEC_ID_PCM_F32BE:
1016
    case CODEC_ID_PCM_F32LE:
1017
        return 32;
1018
    case CODEC_ID_PCM_F64BE:
1019
    case CODEC_ID_PCM_F64LE:
1020
        return 64;
1021
    default:
1022
        return 0;
1023
    }
1024
}
1025

    
1026
int av_get_bits_per_sample_format(enum SampleFormat sample_fmt) {
1027
    switch (sample_fmt) {
1028
    case SAMPLE_FMT_U8:
1029
        return 8;
1030
    case SAMPLE_FMT_S16:
1031
        return 16;
1032
    case SAMPLE_FMT_S32:
1033
    case SAMPLE_FMT_FLT:
1034
        return 32;
1035
    case SAMPLE_FMT_DBL:
1036
        return 64;
1037
    default:
1038
        return 0;
1039
    }
1040
}
1041

    
1042
#if !HAVE_THREADS
1043
int avcodec_thread_init(AVCodecContext *s, int thread_count){
1044
    s->thread_count = thread_count;
1045
    return -1;
1046
}
1047
#endif
1048

    
1049
unsigned int av_xiphlacing(unsigned char *s, unsigned int v)
1050
{
1051
    unsigned int n = 0;
1052

    
1053
    while(v >= 0xff) {
1054
        *s++ = 0xff;
1055
        v -= 0xff;
1056
        n++;
1057
    }
1058
    *s = v;
1059
    n++;
1060
    return n;
1061
}
1062

    
1063
/* Wrapper to work around the lack of mkstemp() on mingw/cygin.
1064
 * Also, tries to create file in /tmp first, if possible.
1065
 * *prefix can be a character constant; *filename will be allocated internally.
1066
 * Returns file descriptor of opened file (or -1 on error)
1067
 * and opened file name in **filename. */
1068
int av_tempfile(char *prefix, char **filename) {
1069
    int fd=-1;
1070
#if !HAVE_MKSTEMP
1071
    *filename = tempnam(".", prefix);
1072
#else
1073
    size_t len = strlen(prefix) + 12; /* room for "/tmp/" and "XXXXXX\0" */
1074
    *filename = av_malloc(len);
1075
#endif
1076
    /* -----common section-----*/
1077
    if (*filename == NULL) {
1078
        av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot allocate file name\n");
1079
        return -1;
1080
    }
1081
#if !HAVE_MKSTEMP
1082
    fd = open(*filename, O_RDWR | O_BINARY | O_CREAT, 0444);
1083
#else
1084
    snprintf(*filename, len, "/tmp/%sXXXXXX", prefix);
1085
    fd = mkstemp(*filename);
1086
    if (fd < 0) {
1087
        snprintf(*filename, len, "./%sXXXXXX", prefix);
1088
        fd = mkstemp(*filename);
1089
    }
1090
#endif
1091
    /* -----common section-----*/
1092
    if (fd < 0) {
1093
        av_log(NULL, AV_LOG_ERROR, "ff_tempfile: Cannot open temporary file %s\n", *filename);
1094
        return -1;
1095
    }
1096
    return fd; /* success */
1097
}
1098

    
1099
typedef struct {
1100
    const char *abbr;
1101
    int width, height;
1102
} VideoFrameSizeAbbr;
1103

    
1104
typedef struct {
1105
    const char *abbr;
1106
    int rate_num, rate_den;
1107
} VideoFrameRateAbbr;
1108

    
1109
static const VideoFrameSizeAbbr video_frame_size_abbrs[] = {
1110
    { "ntsc",      720, 480 },
1111
    { "pal",       720, 576 },
1112
    { "qntsc",     352, 240 }, /* VCD compliant NTSC */
1113
    { "qpal",      352, 288 }, /* VCD compliant PAL */
1114
    { "sntsc",     640, 480 }, /* square pixel NTSC */
1115
    { "spal",      768, 576 }, /* square pixel PAL */
1116
    { "film",      352, 240 },
1117
    { "ntsc-film", 352, 240 },
1118
    { "sqcif",     128,  96 },
1119
    { "qcif",      176, 144 },
1120
    { "cif",       352, 288 },
1121
    { "4cif",      704, 576 },
1122
    { "16cif",    1408,1152 },
1123
    { "qqvga",     160, 120 },
1124
    { "qvga",      320, 240 },
1125
    { "vga",       640, 480 },
1126
    { "svga",      800, 600 },
1127
    { "xga",      1024, 768 },
1128
    { "uxga",     1600,1200 },
1129
    { "qxga",     2048,1536 },
1130
    { "sxga",     1280,1024 },
1131
    { "qsxga",    2560,2048 },
1132
    { "hsxga",    5120,4096 },
1133
    { "wvga",      852, 480 },
1134
    { "wxga",     1366, 768 },
1135
    { "wsxga",    1600,1024 },
1136
    { "wuxga",    1920,1200 },
1137
    { "woxga",    2560,1600 },
1138
    { "wqsxga",   3200,2048 },
1139
    { "wquxga",   3840,2400 },
1140
    { "whsxga",   6400,4096 },
1141
    { "whuxga",   7680,4800 },
1142
    { "cga",       320, 200 },
1143
    { "ega",       640, 350 },
1144
    { "hd480",     852, 480 },
1145
    { "hd720",    1280, 720 },
1146
    { "hd1080",   1920,1080 },
1147
};
1148

    
1149
static const VideoFrameRateAbbr video_frame_rate_abbrs[]= {
1150
    { "ntsc",      30000, 1001 },
1151
    { "pal",          25,    1 },
1152
    { "qntsc",     30000, 1001 }, /* VCD compliant NTSC */
1153
    { "qpal",         25,    1 }, /* VCD compliant PAL */
1154
    { "sntsc",     30000, 1001 }, /* square pixel NTSC */
1155
    { "spal",         25,    1 }, /* square pixel PAL */
1156
    { "film",         24,    1 },
1157
    { "ntsc-film", 24000, 1001 },
1158
};
1159

    
1160
int av_parse_video_frame_size(int *width_ptr, int *height_ptr, const char *str)
1161
{
1162
    int i;
1163
    int n = FF_ARRAY_ELEMS(video_frame_size_abbrs);
1164
    char *p;
1165
    int frame_width = 0, frame_height = 0;
1166

    
1167
    for(i=0;i<n;i++) {
1168
        if (!strcmp(video_frame_size_abbrs[i].abbr, str)) {
1169
            frame_width = video_frame_size_abbrs[i].width;
1170
            frame_height = video_frame_size_abbrs[i].height;
1171
            break;
1172
        }
1173
    }
1174
    if (i == n) {
1175
        p = str;
1176
        frame_width = strtol(p, &p, 10);
1177
        if (*p)
1178
            p++;
1179
        frame_height = strtol(p, &p, 10);
1180
    }
1181
    if (frame_width <= 0 || frame_height <= 0)
1182
        return -1;
1183
    *width_ptr = frame_width;
1184
    *height_ptr = frame_height;
1185
    return 0;
1186
}
1187

    
1188
int av_parse_video_frame_rate(AVRational *frame_rate, const char *arg)
1189
{
1190
    int i;
1191
    int n = FF_ARRAY_ELEMS(video_frame_rate_abbrs);
1192
    char* cp;
1193

    
1194
    /* First, we check our abbreviation table */
1195
    for (i = 0; i < n; ++i)
1196
         if (!strcmp(video_frame_rate_abbrs[i].abbr, arg)) {
1197
             frame_rate->num = video_frame_rate_abbrs[i].rate_num;
1198
             frame_rate->den = video_frame_rate_abbrs[i].rate_den;
1199
             return 0;
1200
         }
1201

    
1202
    /* Then, we try to parse it as fraction */
1203
    cp = strchr(arg, '/');
1204
    if (!cp)
1205
        cp = strchr(arg, ':');
1206
    if (cp) {
1207
        char* cpp;
1208
        frame_rate->num = strtol(arg, &cpp, 10);
1209
        if (cpp != arg || cpp == cp)
1210
            frame_rate->den = strtol(cp+1, &cpp, 10);
1211
        else
1212
           frame_rate->num = 0;
1213
    }
1214
    else {
1215
        /* Finally we give up and parse it as double */
1216
        AVRational time_base = av_d2q(strtod(arg, 0), 1001000);
1217
        frame_rate->den = time_base.den;
1218
        frame_rate->num = time_base.num;
1219
    }
1220
    if (!frame_rate->num || !frame_rate->den)
1221
        return -1;
1222
    else
1223
        return 0;
1224
}
1225

    
1226
int ff_match_2uint16(const uint16_t (*tab)[2], int size, int a, int b){
1227
    int i;
1228
    for(i=0; i<size && !(tab[i][0]==a && tab[i][1]==b); i++);
1229
    return i;
1230
}
1231

    
1232
void av_log_missing_feature(void *avc, const char *feature, int want_sample)
1233
{
1234
    av_log(avc, AV_LOG_WARNING, "%s not implemented. Update your FFmpeg "
1235
            "version to the newest one from SVN. If the problem still "
1236
            "occurs, it means that your file has a feature which has not "
1237
            "been implemented.", feature);
1238
    if(want_sample)
1239
        av_log_ask_for_sample(avc, NULL);
1240
    else
1241
        av_log(avc, AV_LOG_WARNING, "\n");
1242
}
1243

    
1244
void av_log_ask_for_sample(void *avc, const char *msg)
1245
{
1246
    if (msg)
1247
        av_log(avc, AV_LOG_WARNING, "%s ", msg);
1248
    av_log(avc, AV_LOG_WARNING, "If you want to help, upload a sample "
1249
            "of this file to ftp://upload.ffmpeg.org/MPlayer/incoming/ "
1250
            "and contact the ffmpeg-devel mailing list.\n");
1251
}
1252

    
1253
static AVHWAccel *first_hwaccel = NULL;
1254

    
1255
void av_register_hwaccel(AVHWAccel *hwaccel)
1256
{
1257
    AVHWAccel **p = &first_hwaccel;
1258
    while (*p)
1259
        p = &(*p)->next;
1260
    *p = hwaccel;
1261
    hwaccel->next = NULL;
1262
}
1263

    
1264
AVHWAccel *av_hwaccel_next(AVHWAccel *hwaccel)
1265
{
1266
    return hwaccel ? hwaccel->next : first_hwaccel;
1267
}
1268

    
1269
AVHWAccel *ff_find_hwaccel(enum CodecID codec_id, enum PixelFormat pix_fmt)
1270
{
1271
    AVHWAccel *hwaccel=NULL;
1272

    
1273
    while((hwaccel= av_hwaccel_next(hwaccel))){
1274
        if (   hwaccel->id      == codec_id
1275
            && hwaccel->pix_fmt == pix_fmt)
1276
            return hwaccel;
1277
    }
1278
    return NULL;
1279
}
1280

    
1281
int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
1282
{
1283
    if (ff_lockmgr_cb) {
1284
        if (ff_lockmgr_cb(&codec_mutex, AV_LOCK_DESTROY))
1285
            return -1;
1286
    }
1287

    
1288
    ff_lockmgr_cb = cb;
1289

    
1290
    if (ff_lockmgr_cb) {
1291
        if (ff_lockmgr_cb(&codec_mutex, AV_LOCK_CREATE))
1292
            return -1;
1293
    }
1294
    return 0;
1295
}