Browse code

lavc: make avcodec_alloc_context3 officially public.

Deprecate avcodec_alloc_context/2.

Anton Khirnov authored on 2011/06/18 20:40:48
Showing 11 changed files
... ...
@@ -63,7 +63,7 @@ void init_opts(void)
63 63
 {
64 64
     int i;
65 65
     for (i = 0; i < AVMEDIA_TYPE_NB; i++)
66
-        avcodec_opts[i] = avcodec_alloc_context2(i);
66
+        avcodec_opts[i] = avcodec_alloc_context3(NULL);
67 67
     avformat_opts = avformat_alloc_context();
68 68
 #if CONFIG_SWSCALE
69 69
     sws_opts = sws_getContext(16, 16, 0, 16, 16, 0, SWS_BICUBIC, NULL, NULL, NULL);
... ...
@@ -3468,7 +3468,7 @@ static AVStream *add_av_stream1(FFStream *stream, AVCodecContext *codec, int cop
3468 3468
     if (!fst)
3469 3469
         return NULL;
3470 3470
     if (copy) {
3471
-        fst->codec= avcodec_alloc_context();
3471
+        fst->codec = avcodec_alloc_context3(NULL);
3472 3472
         memcpy(fst->codec, codec, sizeof(AVCodecContext));
3473 3473
         if (codec->extradata_size) {
3474 3474
             fst->codec->extradata = av_malloc(codec->extradata_size);
... ...
@@ -3885,7 +3885,7 @@ static void add_codec(FFStream *stream, AVCodecContext *av)
3885 3885
     st = av_mallocz(sizeof(AVStream));
3886 3886
     if (!st)
3887 3887
         return;
3888
-    st->codec = avcodec_alloc_context();
3888
+    st->codec = avcodec_alloc_context3(NULL);
3889 3889
     stream->streams[stream->nb_streams++] = st;
3890 3890
     memcpy(st->codec, av, sizeof(AVCodecContext));
3891 3891
 }
... ...
@@ -65,7 +65,7 @@ static void audio_encode_example(const char *filename)
65 65
         exit(1);
66 66
     }
67 67
 
68
-    c= avcodec_alloc_context();
68
+    c = avcodec_alloc_context3(codec);
69 69
 
70 70
     /* put sample parameters */
71 71
     c->bit_rate = 64000;
... ...
@@ -135,7 +135,7 @@ static void audio_decode_example(const char *outfilename, const char *filename)
135 135
         exit(1);
136 136
     }
137 137
 
138
-    c= avcodec_alloc_context();
138
+    c = avcodec_alloc_context3(codec);
139 139
 
140 140
     /* open it */
141 141
     if (avcodec_open(c, codec) < 0) {
... ...
@@ -216,7 +216,7 @@ static void video_encode_example(const char *filename)
216 216
         exit(1);
217 217
     }
218 218
 
219
-    c= avcodec_alloc_context();
219
+    c = avcodec_alloc_context3(codec);
220 220
     picture= avcodec_alloc_frame();
221 221
 
222 222
     /* put sample parameters */
... ...
@@ -347,7 +347,7 @@ static void video_decode_example(const char *outfilename, const char *filename)
347 347
         exit(1);
348 348
     }
349 349
 
350
-    c= avcodec_alloc_context();
350
+    c = avcodec_alloc_context3(codec);
351 351
     picture= avcodec_alloc_frame();
352 352
 
353 353
     if(codec->capabilities&CODEC_CAP_TRUNCATED)
... ...
@@ -3529,21 +3529,38 @@ void avcodec_get_context_defaults2(AVCodecContext *s, enum AVMediaType);
3529 3529
  *  we WILL change its arguments and name a few times! */
3530 3530
 int avcodec_get_context_defaults3(AVCodecContext *s, AVCodec *codec);
3531 3531
 
3532
+#if FF_API_ALLOC_CONTEXT
3532 3533
 /**
3533 3534
  * Allocate an AVCodecContext and set its fields to default values.  The
3534 3535
  * resulting struct can be deallocated by simply calling av_free().
3535 3536
  *
3536 3537
  * @return An AVCodecContext filled with default values or NULL on failure.
3537 3538
  * @see avcodec_get_context_defaults
3539
+ *
3540
+ * @deprecated use avcodec_alloc_context3()
3538 3541
  */
3542
+attribute_deprecated
3539 3543
 AVCodecContext *avcodec_alloc_context(void);
3540 3544
 
3541 3545
 /** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
3542 3546
  *  we WILL change its arguments and name a few times! */
3547
+attribute_deprecated
3543 3548
 AVCodecContext *avcodec_alloc_context2(enum AVMediaType);
3549
+#endif
3544 3550
 
3545
-/** THIS FUNCTION IS NOT YET PART OF THE PUBLIC API!
3546
- *  we WILL change its arguments and name a few times! */
3551
+/**
3552
+ * Allocate an AVCodecContext and set its fields to default values.  The
3553
+ * resulting struct can be deallocated by simply calling av_free().
3554
+ *
3555
+ * @param codec if non-NULL, allocate private data and initialize defaults
3556
+ *              for the given codec. It is illegal to then call avcodec_open()
3557
+ *              with a different codec.
3558
+ *
3559
+ * @return An AVCodecContext filled with default values or NULL on failure.
3560
+ * @see avcodec_get_context_defaults
3561
+ *
3562
+ * @deprecated use avcodec_alloc_context3()
3563
+ */
3547 3564
 AVCodecContext *avcodec_alloc_context3(AVCodec *codec);
3548 3565
 
3549 3566
 /**
... ...
@@ -3553,7 +3570,7 @@ AVCodecContext *avcodec_alloc_context3(AVCodec *codec);
3553 3553
  * can use this AVCodecContext to decode/encode video/audio data.
3554 3554
  *
3555 3555
  * @param dest target codec context, should be initialized with
3556
- *             avcodec_alloc_context(), but otherwise uninitialized
3556
+ *             avcodec_alloc_context3(), but otherwise uninitialized
3557 3557
  * @param src source codec context
3558 3558
  * @return AVERROR() on error (e.g. memory allocation error), 0 on success
3559 3559
  */
... ...
@@ -3640,7 +3657,7 @@ int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2,
3640 3640
  * if (!codec)
3641 3641
  *     exit(1);
3642 3642
  *
3643
- * context = avcodec_alloc_context();
3643
+ * context = avcodec_alloc_context3(codec);
3644 3644
  *
3645 3645
  * if (avcodec_open(context, codec) < 0)
3646 3646
  *     exit(1);
... ...
@@ -3649,7 +3666,7 @@ int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2,
3649 3649
  * @param avctx The context which will be set up to use the given codec.
3650 3650
  * @param codec The codec to use within the context.
3651 3651
  * @return zero on success, a negative value on error
3652
- * @see avcodec_alloc_context, avcodec_find_decoder, avcodec_find_encoder, avcodec_close
3652
+ * @see avcodec_alloc_context3, avcodec_find_decoder, avcodec_find_encoder, avcodec_close
3653 3653
  *
3654 3654
  * @deprecated use avcodec_open2
3655 3655
  */
... ...
@@ -144,7 +144,7 @@ int main(int argc, char **argv)
144 144
 
145 145
     printf("ffmpeg motion test\n");
146 146
 
147
-    ctx = avcodec_alloc_context();
147
+    ctx = avcodec_alloc_context3(NULL);
148 148
     ctx->dsp_mask = AV_CPU_FLAG_FORCE;
149 149
     dsputil_init(&cctx, ctx);
150 150
     for (c = 0; c < flags_size; c++) {
... ...
@@ -944,7 +944,7 @@ static int skip_check(MpegEncContext *s, Picture *p, Picture *ref){
944 944
 
945 945
 static int estimate_best_b_count(MpegEncContext *s){
946 946
     AVCodec *codec= avcodec_find_encoder(s->avctx->codec_id);
947
-    AVCodecContext *c= avcodec_alloc_context();
947
+    AVCodecContext *c = avcodec_alloc_context3(NULL);
948 948
     AVFrame input[FF_MAX_B_FRAMES+2];
949 949
     const int scale= s->avctx->brd_scale;
950 950
     int i, j, out_size, p_lambda, b_lambda, lambda2;
... ...
@@ -540,6 +540,7 @@ AVCodecContext *avcodec_alloc_context3(AVCodec *codec){
540 540
     return avctx;
541 541
 }
542 542
 
543
+#if FF_API_ALLOC_CONTEXT
543 544
 AVCodecContext *avcodec_alloc_context2(enum AVMediaType codec_type){
544 545
     AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));
545 546
 
... ...
@@ -549,14 +550,17 @@ AVCodecContext *avcodec_alloc_context2(enum AVMediaType codec_type){
549 549
 
550 550
     return avctx;
551 551
 }
552
+#endif
552 553
 
553 554
 void avcodec_get_context_defaults(AVCodecContext *s){
554 555
     avcodec_get_context_defaults2(s, AVMEDIA_TYPE_UNKNOWN);
555 556
 }
556 557
 
558
+#if FF_API_ALLOC_CONTEXT
557 559
 AVCodecContext *avcodec_alloc_context(void){
558 560
     return avcodec_alloc_context2(AVMEDIA_TYPE_UNKNOWN);
559 561
 }
562
+#endif
560 563
 
561 564
 int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
562 565
 {
... ...
@@ -68,6 +68,9 @@
68 68
 #ifndef FF_API_GET_PIX_FMT_NAME
69 69
 #define FF_API_GET_PIX_FMT_NAME (LIBAVCODEC_VERSION_MAJOR < 54)
70 70
 #endif
71
+#ifndef FF_API_ALLOC_CONTEXT
72
+#define FF_API_ALLOC_CONTEXT    (LIBAVCODEC_VERSION_MAJOR < 54)
73
+#endif
71 74
 #ifndef FF_API_AVCODEC_OPEN
72 75
 #define FF_API_AVCODEC_OPEN     (LIBAVCODEC_VERSION_MAJOR < 54)
73 76
 #endif
... ...
@@ -2102,7 +2102,7 @@ static void mov_create_chapter_track(AVFormatContext *s, int tracknum)
2102 2102
     track->mode = mov->mode;
2103 2103
     track->tag = MKTAG('t','e','x','t');
2104 2104
     track->timescale = MOV_TIMESCALE;
2105
-    track->enc = avcodec_alloc_context();
2105
+    track->enc = avcodec_alloc_context3(NULL);
2106 2106
     track->enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
2107 2107
 
2108 2108
     for (i = 0; i < s->nb_chapters; i++) {
... ...
@@ -36,7 +36,7 @@ int ff_mov_init_hinting(AVFormatContext *s, int index, int src_index)
36 36
     track->tag = MKTAG('r','t','p',' ');
37 37
     track->src_track = src_index;
38 38
 
39
-    track->enc = avcodec_alloc_context();
39
+    track->enc = avcodec_alloc_context3(NULL);
40 40
     if (!track->enc)
41 41
         goto fail;
42 42
     track->enc->codec_type = AVMEDIA_TYPE_DATA;
... ...
@@ -2668,7 +2668,7 @@ AVStream *av_new_stream(AVFormatContext *s, int id)
2668 2668
         return NULL;
2669 2669
     }
2670 2670
 
2671
-    st->codec= avcodec_alloc_context();
2671
+    st->codec = avcodec_alloc_context3(NULL);
2672 2672
     if (s->iformat) {
2673 2673
         /* no default bitrate if decoding */
2674 2674
         st->codec->bit_rate = 0;