History

Deprecate avcodec_thread_init()

As a side effect of the last commit, avcodec_open() now calls it automatically, so there is no longer any need for clients to call it. Instead they should set AVCodecContext.thread_count. avcodec_thread_free() is deprecated, and will be removed from avcodec.h at the next MAJOR libavcodec bump. Rename the functions to ff_thread_init/free, since they are now internal. Wrappers are provided to maintain API compatibility.

Alexander Strange committed 15 years ago

Commit 043d2ff1 parent 03e3cb88 files · +42 −20Browse files

Unified · Split

8 files
  1. doc/APIchanges +4 −0
  2. ffmpeg.c +3 −8
  3. ffplay.c +1 −1
  4. libavcodec/avcodec.h +7 −1
  5. libavcodec/pthread.c +3 −3
  6. libavcodec/thread.h +3 −0
  7. libavcodec/utils.c +17 −3
  8. libavcodec/w32thread.c +4 −4
doc/APIchanges+4−0
@@ -13,6 +13,10 @@ libavutil: 2009-03-08 · 12 unmodified lines
1313
1414 API changes, most recent first:
1515
16+2011-02-09 - XXXXXXX - lavc 52.112.0 - avcodec_thread_init()
17+ Deprecate avcodec_thread_init()/avcodec_thread_free() use; instead
18+ set thread_count before calling avcodec_open.
19+
1620 2011-02-09 - 778b08a - lavc 52.111.0 - threading API
1721 Add CODEC_CAP_FRAME_THREADS with new restrictions on get_buffer()/
1822 release_buffer()/draw_horiz_band() callbacks for appropriate codecs.
ffmpeg.c+3−8
@@ -707,11 +707,6 @@ static int read_ffserver_streams(AVFormatContext *s, const char *filename) · 706 unmodified lines
707707 choose_pixel_fmt(st, codec);
708708 }
709709
710− if(!st->codec->thread_count)
711− st->codec->thread_count = 1;
712− if(st->codec->thread_count>1)
713− avcodec_thread_init(st->codec, st->codec->thread_count);
714−
715710 if(st->codec->flags & CODEC_FLAG_BITEXACT)
716711 nopts = 1;
717712
@@ -3248,7 +3243,7 @@ static void opt_input_file(const char *filename) · 2530 unmodified lines
32483243 for(i=0;i<ic->nb_streams;i++) {
32493244 AVStream *st = ic->streams[i];
32503245 AVCodecContext *dec = st->codec;
3251− avcodec_thread_init(dec, thread_count);
3246+ dec->thread_count = thread_count;
32523247 input_codecs = grow_array(input_codecs, sizeof(*input_codecs), &nb_input_codecs, nb_input_codecs + 1);
32533248 switch (dec->codec_type) {
32543249 case AVMEDIA_TYPE_AUDIO:
@@ -3406,7 +3401,7 @@ static void new_video_stream(AVFormatContext *oc, int file_idx) · 151 unmodified lines
34063401 ost->bitstream_filters = video_bitstream_filters;
34073402 video_bitstream_filters= NULL;
34083403
3409− avcodec_thread_init(st->codec, thread_count);
3404+ st->codec->thread_count= thread_count;
34103405
34113406 video_enc = st->codec;
34123407
@@ -3553,7 +3548,7 @@ static void new_audio_stream(AVFormatContext *oc, int file_idx) · 140 unmodified lines
35533548 ost->bitstream_filters = audio_bitstream_filters;
35543549 audio_bitstream_filters= NULL;
35553550
3556− avcodec_thread_init(st->codec, thread_count);
3551+ st->codec->thread_count= thread_count;
35573552
35583553 audio_enc = st->codec;
35593554 audio_enc->codec_type = AVMEDIA_TYPE_AUDIO;
ffplay.c+1−1
@@ -2257,7 +2257,7 @@ static int stream_component_open(VideoState *is, int stream_index) · 2256 unmodified lines
22572257 avctx->skip_loop_filter= skip_loop_filter;
22582258 avctx->error_recognition= error_recognition;
22592259 avctx->error_concealment= error_concealment;
2260− avcodec_thread_init(avctx, thread_count);
2260+ avctx->thread_count= thread_count;
22612261
22622262 set_context_opts(avctx, avcodec_opts[avctx->codec_type], 0, codec);
22632263
libavcodec/avcodec.h+7−1
@@ -32,7 +32,7 @@ · 31 unmodified lines
3232 #include "libavutil/cpu.h"
3333
3434 #define LIBAVCODEC_VERSION_MAJOR 52
35−#define LIBAVCODEC_VERSION_MINOR 111
35+#define LIBAVCODEC_VERSION_MINOR 112
3636 #define LIBAVCODEC_VERSION_MICRO 0
3737
3838 #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \
@@ -3656,8 +3656,14 @@ int avcodec_check_dimensions(void *av_log_ctx, unsigned int w, unsigned int h); · 3617 unmodified lines
36563656
36573657 enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt);
36583658
3659+#if LIBAVCODEC_VERSION_MAJOR < 53
3660+/**
3661+ * @deprecated Set s->thread_count before calling avcodec_open() instead of calling this.
3662+ */
3663+attribute_deprecated
36593664 int avcodec_thread_init(AVCodecContext *s, int thread_count);
36603665 void avcodec_thread_free(AVCodecContext *s);
3666+#endif
36613667 int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size);
36623668 int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count);
36633669 //FIXME func typedef
libavcodec/pthread.c+3−3
@@ -256,7 +256,7 @@ static int thread_init(AVCodecContext *avctx) · 255 unmodified lines
256256 if(pthread_create(&c->workers[i], NULL, worker, avctx)) {
257257 avctx->thread_count = i;
258258 pthread_mutex_unlock(&c->current_job_lock);
259− avcodec_thread_free(avctx);
259+ ff_thread_free(avctx);
260260 return -1;
261261 }
262262 }
@@ -870,7 +870,7 @@ static void validate_thread_parameters(AVCodecContext *avctx) · 607 unmodified lines
870870 }
871871 }
872872
873−int avcodec_thread_init(AVCodecContext *avctx, int thread_count)
873+int ff_thread_init(AVCodecContext *avctx, int thread_count)
874874 {
875875 if (avctx->thread_opaque) {
876876 av_log(avctx, AV_LOG_ERROR, "avcodec_thread_init is ignored after avcodec_open\n");
@@ -891,7 +891,7 @@ int avcodec_thread_init(AVCodecContext *avctx, int thread_count) · 14 unmodified lines
891891 return 0;
892892 }
893893
894−void avcodec_thread_free(AVCodecContext *avctx)
894+void ff_thread_free(AVCodecContext *avctx)
895895 {
896896 if (avctx->active_thread_type&FF_THREAD_FRAME)
897897 frame_thread_free(avctx, avctx->thread_count);
libavcodec/thread.h+3−0
@@ -108,4 +108,7 @@ int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f); · 107 unmodified lines
108108 */
109109 void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f);
110110
111+int ff_thread_init(AVCodecContext *s, int thread_count);
112+void ff_thread_free(AVCodecContext *s);
113+
111114 #endif /* AVCODEC_THREAD_H */
libavcodec/utils.c+17−3
@@ -540,7 +540,7 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) · 539 unmodified lines
540540 avctx->frame_number = 0;
541541
542542 if (HAVE_THREADS && !avctx->thread_opaque) {
543− ret = avcodec_thread_init(avctx, avctx->thread_count);
543+ ret = ff_thread_init(avctx, avctx->thread_count);
544544 if (ret < 0) {
545545 goto free_and_end;
546546 }
@@ -819,7 +819,7 @@ av_cold int avcodec_close(AVCodecContext *avctx) · 272 unmodified lines
819819 }
820820
821821 if (HAVE_THREADS && avctx->thread_opaque)
822− avcodec_thread_free(avctx);
822+ ff_thread_free(avctx);
823823 if (avctx->codec && avctx->codec->close)
824824 avctx->codec->close(avctx);
825825 avcodec_default_free_buffers(avctx);
@@ -1180,7 +1180,7 @@ int av_get_bits_per_sample_format(enum AVSampleFormat sample_fmt) { · 354 unmodified lines
11801180 #endif
11811181
11821182 #if !HAVE_THREADS
1183−int avcodec_thread_init(AVCodecContext *s, int thread_count){
1183+int ff_thread_init(AVCodecContext *s, int thread_count){
11841184 s->thread_count = thread_count;
11851185 return -1;
11861186 }
@@ -1319,3 +1319,17 @@ void ff_thread_await_progress(AVFrame *f, int progress, int field) · 132 unmodified lines
13191319 }
13201320
13211321 #endif
1322+
1323+#if LIBAVCODEC_VERSION_MAJOR < 53
1324+
1325+int avcodec_thread_init(AVCodecContext *s, int thread_count)
1326+{
1327+ return ff_thread_init(s, thread_count);
1328+}
1329+
1330+void avcodec_thread_free(AVCodecContext *s)
1331+{
1332+ return ff_thread_free(s);
1333+}
1334+
1335+#endif
libavcodec/w32thread.c+4−4
@@ -69,10 +69,10 @@ static unsigned WINAPI attribute_align_arg thread_func(void *v){ · 68 unmodified lines
6969 }
7070
7171 /**
72− * Free what has been allocated by avcodec_thread_init().
72+ * Free what has been allocated by ff_thread_init().
7373 * Must be called after decoding has finished, especially do not call while avcodec_thread_execute() is running.
7474 */
75−void avcodec_thread_free(AVCodecContext *s){
75+void ff_thread_free(AVCodecContext *s){
7676 ThreadContext *c= s->thread_opaque;
7777 int i;
7878
@@ -124,7 +124,7 @@ static int avcodec_thread_execute2(AVCodecContext *s, int (*func)(AVCodecContext · 45 unmodified lines
124124 avcodec_thread_execute(s, NULL, arg, ret, count, 0);
125125 }
126126
127−int avcodec_thread_init(AVCodecContext *s, int thread_count){
127+int ff_thread_init(AVCodecContext *s, int thread_count){
128128 int i;
129129 ThreadContext *c;
130130 uint32_t threadid;
@@ -169,6 +169,6 @@ int avcodec_thread_init(AVCodecContext *s, int thread_count){ · 38 unmodified lines
169169
170170 return 0;
171171 fail:
172− avcodec_thread_free(s);
172+ ff_thread_free(s);
173173 return -1;
174174 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t