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.
Signed-off-by: Ronald S. Bultje <rsbultje@gmail.com>
(cherry picked from commit c0b102ca03fe92250f1ce620aec3836f529fc1d6)
... | ... |
@@ -13,6 +13,10 @@ libavutil: 2009-03-08 |
13 | 13 |
|
14 | 14 |
API changes, most recent first: |
15 | 15 |
|
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 |
+ |
|
16 | 20 |
2011-02-09 - 778b08a - lavc 52.111.0 - threading API |
17 | 21 |
Add CODEC_CAP_FRAME_THREADS with new restrictions on get_buffer()/ |
18 | 22 |
release_buffer()/draw_horiz_band() callbacks for appropriate codecs. |
... | ... |
@@ -707,11 +707,6 @@ static int read_ffserver_streams(AVFormatContext *s, const char *filename) |
707 | 707 |
choose_pixel_fmt(st, codec); |
708 | 708 |
} |
709 | 709 |
|
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 |
- |
|
715 | 710 |
if(st->codec->flags & CODEC_FLAG_BITEXACT) |
716 | 711 |
nopts = 1; |
717 | 712 |
|
... | ... |
@@ -3248,7 +3243,7 @@ static void opt_input_file(const char *filename) |
3248 | 3248 |
for(i=0;i<ic->nb_streams;i++) { |
3249 | 3249 |
AVStream *st = ic->streams[i]; |
3250 | 3250 |
AVCodecContext *dec = st->codec; |
3251 |
- avcodec_thread_init(dec, thread_count); |
|
3251 |
+ dec->thread_count = thread_count; |
|
3252 | 3252 |
input_codecs = grow_array(input_codecs, sizeof(*input_codecs), &nb_input_codecs, nb_input_codecs + 1); |
3253 | 3253 |
switch (dec->codec_type) { |
3254 | 3254 |
case AVMEDIA_TYPE_AUDIO: |
... | ... |
@@ -3406,7 +3401,7 @@ static void new_video_stream(AVFormatContext *oc, int file_idx) |
3406 | 3406 |
ost->bitstream_filters = video_bitstream_filters; |
3407 | 3407 |
video_bitstream_filters= NULL; |
3408 | 3408 |
|
3409 |
- avcodec_thread_init(st->codec, thread_count); |
|
3409 |
+ st->codec->thread_count= thread_count; |
|
3410 | 3410 |
|
3411 | 3411 |
video_enc = st->codec; |
3412 | 3412 |
|
... | ... |
@@ -3553,7 +3548,7 @@ static void new_audio_stream(AVFormatContext *oc, int file_idx) |
3553 | 3553 |
ost->bitstream_filters = audio_bitstream_filters; |
3554 | 3554 |
audio_bitstream_filters= NULL; |
3555 | 3555 |
|
3556 |
- avcodec_thread_init(st->codec, thread_count); |
|
3556 |
+ st->codec->thread_count= thread_count; |
|
3557 | 3557 |
|
3558 | 3558 |
audio_enc = st->codec; |
3559 | 3559 |
audio_enc->codec_type = AVMEDIA_TYPE_AUDIO; |
... | ... |
@@ -2257,7 +2257,7 @@ static int stream_component_open(VideoState *is, int stream_index) |
2257 | 2257 |
avctx->skip_loop_filter= skip_loop_filter; |
2258 | 2258 |
avctx->error_recognition= error_recognition; |
2259 | 2259 |
avctx->error_concealment= error_concealment; |
2260 |
- avcodec_thread_init(avctx, thread_count); |
|
2260 |
+ avctx->thread_count= thread_count; |
|
2261 | 2261 |
|
2262 | 2262 |
set_context_opts(avctx, avcodec_opts[avctx->codec_type], 0, codec); |
2263 | 2263 |
|
... | ... |
@@ -32,7 +32,7 @@ |
32 | 32 |
#include "libavutil/cpu.h" |
33 | 33 |
|
34 | 34 |
#define LIBAVCODEC_VERSION_MAJOR 52 |
35 |
-#define LIBAVCODEC_VERSION_MINOR 111 |
|
35 |
+#define LIBAVCODEC_VERSION_MINOR 112 |
|
36 | 36 |
#define LIBAVCODEC_VERSION_MICRO 0 |
37 | 37 |
|
38 | 38 |
#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); |
3656 | 3656 |
|
3657 | 3657 |
enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt); |
3658 | 3658 |
|
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 |
|
3659 | 3664 |
int avcodec_thread_init(AVCodecContext *s, int thread_count); |
3660 | 3665 |
void avcodec_thread_free(AVCodecContext *s); |
3666 |
+#endif |
|
3661 | 3667 |
int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size); |
3662 | 3668 |
int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count); |
3663 | 3669 |
//FIXME func typedef |
... | ... |
@@ -256,7 +256,7 @@ static int thread_init(AVCodecContext *avctx) |
256 | 256 |
if(pthread_create(&c->workers[i], NULL, worker, avctx)) { |
257 | 257 |
avctx->thread_count = i; |
258 | 258 |
pthread_mutex_unlock(&c->current_job_lock); |
259 |
- avcodec_thread_free(avctx); |
|
259 |
+ ff_thread_free(avctx); |
|
260 | 260 |
return -1; |
261 | 261 |
} |
262 | 262 |
} |
... | ... |
@@ -870,7 +870,7 @@ static void validate_thread_parameters(AVCodecContext *avctx) |
870 | 870 |
} |
871 | 871 |
} |
872 | 872 |
|
873 |
-int avcodec_thread_init(AVCodecContext *avctx, int thread_count) |
|
873 |
+int ff_thread_init(AVCodecContext *avctx, int thread_count) |
|
874 | 874 |
{ |
875 | 875 |
if (avctx->thread_opaque) { |
876 | 876 |
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) |
891 | 891 |
return 0; |
892 | 892 |
} |
893 | 893 |
|
894 |
-void avcodec_thread_free(AVCodecContext *avctx) |
|
894 |
+void ff_thread_free(AVCodecContext *avctx) |
|
895 | 895 |
{ |
896 | 896 |
if (avctx->active_thread_type&FF_THREAD_FRAME) |
897 | 897 |
frame_thread_free(avctx, avctx->thread_count); |
... | ... |
@@ -108,4 +108,7 @@ int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f); |
108 | 108 |
*/ |
109 | 109 |
void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f); |
110 | 110 |
|
111 |
+int ff_thread_init(AVCodecContext *s, int thread_count); |
|
112 |
+void ff_thread_free(AVCodecContext *s); |
|
113 |
+ |
|
111 | 114 |
#endif /* AVCODEC_THREAD_H */ |
... | ... |
@@ -540,7 +540,7 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) |
540 | 540 |
avctx->frame_number = 0; |
541 | 541 |
|
542 | 542 |
if (HAVE_THREADS && !avctx->thread_opaque) { |
543 |
- ret = avcodec_thread_init(avctx, avctx->thread_count); |
|
543 |
+ ret = ff_thread_init(avctx, avctx->thread_count); |
|
544 | 544 |
if (ret < 0) { |
545 | 545 |
goto free_and_end; |
546 | 546 |
} |
... | ... |
@@ -819,7 +819,7 @@ av_cold int avcodec_close(AVCodecContext *avctx) |
819 | 819 |
} |
820 | 820 |
|
821 | 821 |
if (HAVE_THREADS && avctx->thread_opaque) |
822 |
- avcodec_thread_free(avctx); |
|
822 |
+ ff_thread_free(avctx); |
|
823 | 823 |
if (avctx->codec && avctx->codec->close) |
824 | 824 |
avctx->codec->close(avctx); |
825 | 825 |
avcodec_default_free_buffers(avctx); |
... | ... |
@@ -1180,7 +1180,7 @@ int av_get_bits_per_sample_format(enum AVSampleFormat sample_fmt) { |
1180 | 1180 |
#endif |
1181 | 1181 |
|
1182 | 1182 |
#if !HAVE_THREADS |
1183 |
-int avcodec_thread_init(AVCodecContext *s, int thread_count){ |
|
1183 |
+int ff_thread_init(AVCodecContext *s, int thread_count){ |
|
1184 | 1184 |
s->thread_count = thread_count; |
1185 | 1185 |
return -1; |
1186 | 1186 |
} |
... | ... |
@@ -1319,3 +1319,17 @@ void ff_thread_await_progress(AVFrame *f, int progress, int field) |
1319 | 1319 |
} |
1320 | 1320 |
|
1321 | 1321 |
#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 |
... | ... |
@@ -69,10 +69,10 @@ static unsigned WINAPI attribute_align_arg thread_func(void *v){ |
69 | 69 |
} |
70 | 70 |
|
71 | 71 |
/** |
72 |
- * Free what has been allocated by avcodec_thread_init(). |
|
72 |
+ * Free what has been allocated by ff_thread_init(). |
|
73 | 73 |
* Must be called after decoding has finished, especially do not call while avcodec_thread_execute() is running. |
74 | 74 |
*/ |
75 |
-void avcodec_thread_free(AVCodecContext *s){ |
|
75 |
+void ff_thread_free(AVCodecContext *s){ |
|
76 | 76 |
ThreadContext *c= s->thread_opaque; |
77 | 77 |
int i; |
78 | 78 |
|
... | ... |
@@ -124,7 +124,7 @@ static int avcodec_thread_execute2(AVCodecContext *s, int (*func)(AVCodecContext |
124 | 124 |
avcodec_thread_execute(s, NULL, arg, ret, count, 0); |
125 | 125 |
} |
126 | 126 |
|
127 |
-int avcodec_thread_init(AVCodecContext *s, int thread_count){ |
|
127 |
+int ff_thread_init(AVCodecContext *s, int thread_count){ |
|
128 | 128 |
int i; |
129 | 129 |
ThreadContext *c; |
130 | 130 |
uint32_t threadid; |
... | ... |
@@ -169,6 +169,6 @@ int avcodec_thread_init(AVCodecContext *s, int thread_count){ |
169 | 169 |
|
170 | 170 |
return 0; |
171 | 171 |
fail: |
172 |
- avcodec_thread_free(s); |
|
172 |
+ ff_thread_free(s); |
|
173 | 173 |
return -1; |
174 | 174 |
} |