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.
Unified · Split
| @@ -13,6 +13,10 @@ libavutil: 2009-03-08 · 12 unmodified lines | |||
| 13 | 13 | ||
| 14 | API changes, most recent first: | 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 | 2011-02-09 - 778b08a - lavc 52.111.0 - threading API | 20 | 2011-02-09 - 778b08a - lavc 52.111.0 - threading API |
| 17 | Add CODEC_CAP_FRAME_THREADS with new restrictions on get_buffer()/ | 21 | Add CODEC_CAP_FRAME_THREADS with new restrictions on get_buffer()/ |
| 18 | release_buffer()/draw_horiz_band() callbacks for appropriate codecs. | 22 | release_buffer()/draw_horiz_band() callbacks for appropriate codecs. |
| @@ -707,11 +707,6 @@ static int read_ffserver_streams(AVFormatContext *s, const char *filename) · 706 unmodified lines | |||
| 707 | choose_pixel_fmt(st, codec); | 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 | if(st->codec->flags & CODEC_FLAG_BITEXACT) | 710 | if(st->codec->flags & CODEC_FLAG_BITEXACT) |
| 716 | nopts = 1; | 711 | nopts = 1; |
| 717 | 712 | ||
| @@ -3248,7 +3243,7 @@ static void opt_input_file(const char *filename) · 2530 unmodified lines | |||
| 3248 | for(i=0;i<ic->nb_streams;i++) { | 3243 | for(i=0;i<ic->nb_streams;i++) { |
| 3249 | AVStream *st = ic->streams[i]; | 3244 | AVStream *st = ic->streams[i]; |
| 3250 | AVCodecContext *dec = st->codec; | 3245 | AVCodecContext *dec = st->codec; |
| 3251 | avcodec_thread_init(dec, thread_count); | 3246 | dec->thread_count = thread_count; |
| 3252 | input_codecs = grow_array(input_codecs, sizeof(*input_codecs), &nb_input_codecs, nb_input_codecs + 1); | 3247 | input_codecs = grow_array(input_codecs, sizeof(*input_codecs), &nb_input_codecs, nb_input_codecs + 1); |
| 3253 | switch (dec->codec_type) { | 3248 | switch (dec->codec_type) { |
| 3254 | case AVMEDIA_TYPE_AUDIO: | 3249 | case AVMEDIA_TYPE_AUDIO: |
| @@ -3406,7 +3401,7 @@ static void new_video_stream(AVFormatContext *oc, int file_idx) · 151 unmodified lines | |||
| 3406 | ost->bitstream_filters = video_bitstream_filters; | 3401 | ost->bitstream_filters = video_bitstream_filters; |
| 3407 | video_bitstream_filters= NULL; | 3402 | video_bitstream_filters= NULL; |
| 3408 | 3403 | ||
| 3409 | avcodec_thread_init(st->codec, thread_count); | 3404 | st->codec->thread_count= thread_count; |
| 3410 | 3405 | ||
| 3411 | video_enc = st->codec; | 3406 | video_enc = st->codec; |
| 3412 | 3407 | ||
| @@ -3553,7 +3548,7 @@ static void new_audio_stream(AVFormatContext *oc, int file_idx) · 140 unmodified lines | |||
| 3553 | ost->bitstream_filters = audio_bitstream_filters; | 3548 | ost->bitstream_filters = audio_bitstream_filters; |
| 3554 | audio_bitstream_filters= NULL; | 3549 | audio_bitstream_filters= NULL; |
| 3555 | 3550 | ||
| 3556 | avcodec_thread_init(st->codec, thread_count); | 3551 | st->codec->thread_count= thread_count; |
| 3557 | 3552 | ||
| 3558 | audio_enc = st->codec; | 3553 | audio_enc = st->codec; |
| 3559 | audio_enc->codec_type = AVMEDIA_TYPE_AUDIO; | 3554 | audio_enc->codec_type = AVMEDIA_TYPE_AUDIO; |
| @@ -2257,7 +2257,7 @@ static int stream_component_open(VideoState *is, int stream_index) · 2256 unmodified lines | |||
| 2257 | avctx->skip_loop_filter= skip_loop_filter; | 2257 | avctx->skip_loop_filter= skip_loop_filter; |
| 2258 | avctx->error_recognition= error_recognition; | 2258 | avctx->error_recognition= error_recognition; |
| 2259 | avctx->error_concealment= error_concealment; | 2259 | avctx->error_concealment= error_concealment; |
| 2260 | avcodec_thread_init(avctx, thread_count); | 2260 | avctx->thread_count= thread_count; |
| 2261 | 2261 | ||
| 2262 | set_context_opts(avctx, avcodec_opts[avctx->codec_type], 0, codec); | 2262 | set_context_opts(avctx, avcodec_opts[avctx->codec_type], 0, codec); |
| 2263 | 2263 | ||
| @@ -32,7 +32,7 @@ · 31 unmodified lines | |||
| 32 | #include "libavutil/cpu.h" | 32 | #include "libavutil/cpu.h" |
| 33 | 33 | ||
| 34 | #define LIBAVCODEC_VERSION_MAJOR 52 | 34 | #define LIBAVCODEC_VERSION_MAJOR 52 |
| 35 | #define LIBAVCODEC_VERSION_MINOR 111 | 35 | #define LIBAVCODEC_VERSION_MINOR 112 |
| 36 | #define LIBAVCODEC_VERSION_MICRO 0 | 36 | #define LIBAVCODEC_VERSION_MICRO 0 |
| 37 | 37 | ||
| 38 | #define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \ | 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); · 3617 unmodified lines | |||
| 3656 | 3656 | ||
| 3657 | enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt); | 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 | int avcodec_thread_init(AVCodecContext *s, int thread_count); | 3664 | int avcodec_thread_init(AVCodecContext *s, int thread_count); |
| 3660 | void avcodec_thread_free(AVCodecContext *s); | 3665 | void avcodec_thread_free(AVCodecContext *s); |
| 3666 | #endif | ||
| 3661 | int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size); | 3667 | int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size); |
| 3662 | int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count); | 3668 | int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count); |
| 3663 | //FIXME func typedef | 3669 | //FIXME func typedef |
| @@ -256,7 +256,7 @@ static int thread_init(AVCodecContext *avctx) · 255 unmodified lines | |||
| 256 | if(pthread_create(&c->workers[i], NULL, worker, avctx)) { | 256 | if(pthread_create(&c->workers[i], NULL, worker, avctx)) { |
| 257 | avctx->thread_count = i; | 257 | avctx->thread_count = i; |
| 258 | pthread_mutex_unlock(&c->current_job_lock); | 258 | pthread_mutex_unlock(&c->current_job_lock); |
| 259 | avcodec_thread_free(avctx); | 259 | ff_thread_free(avctx); |
| 260 | return -1; | 260 | return -1; |
| 261 | } | 261 | } |
| 262 | } | 262 | } |
| @@ -870,7 +870,7 @@ static void validate_thread_parameters(AVCodecContext *avctx) · 607 unmodified lines | |||
| 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 | if (avctx->thread_opaque) { | 875 | if (avctx->thread_opaque) { |
| 876 | av_log(avctx, AV_LOG_ERROR, "avcodec_thread_init is ignored after avcodec_open\n"); | 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) · 14 unmodified lines | |||
| 891 | return 0; | 891 | return 0; |
| 892 | } | 892 | } |
| 893 | 893 | ||
| 894 | void avcodec_thread_free(AVCodecContext *avctx) | 894 | void ff_thread_free(AVCodecContext *avctx) |
| 895 | { | 895 | { |
| 896 | if (avctx->active_thread_type&FF_THREAD_FRAME) | 896 | if (avctx->active_thread_type&FF_THREAD_FRAME) |
| 897 | frame_thread_free(avctx, avctx->thread_count); | 897 | frame_thread_free(avctx, avctx->thread_count); |
| @@ -108,4 +108,7 @@ int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f); · 107 unmodified lines | |||
| 108 | */ | 108 | */ |
| 109 | void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f); | 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 | #endif /* AVCODEC_THREAD_H */ | 114 | #endif /* AVCODEC_THREAD_H */ |
| @@ -540,7 +540,7 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) · 539 unmodified lines | |||
| 540 | avctx->frame_number = 0; | 540 | avctx->frame_number = 0; |
| 541 | 541 | ||
| 542 | if (HAVE_THREADS && !avctx->thread_opaque) { | 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 | if (ret < 0) { | 544 | if (ret < 0) { |
| 545 | goto free_and_end; | 545 | goto free_and_end; |
| 546 | } | 546 | } |
| @@ -819,7 +819,7 @@ av_cold int avcodec_close(AVCodecContext *avctx) · 272 unmodified lines | |||
| 819 | } | 819 | } |
| 820 | 820 | ||
| 821 | if (HAVE_THREADS && avctx->thread_opaque) | 821 | if (HAVE_THREADS && avctx->thread_opaque) |
| 822 | avcodec_thread_free(avctx); | 822 | ff_thread_free(avctx); |
| 823 | if (avctx->codec && avctx->codec->close) | 823 | if (avctx->codec && avctx->codec->close) |
| 824 | avctx->codec->close(avctx); | 824 | avctx->codec->close(avctx); |
| 825 | avcodec_default_free_buffers(avctx); | 825 | avcodec_default_free_buffers(avctx); |
| @@ -1180,7 +1180,7 @@ int av_get_bits_per_sample_format(enum AVSampleFormat sample_fmt) { · 354 unmodified lines | |||
| 1180 | #endif | 1180 | #endif |
| 1181 | 1181 | ||
| 1182 | #if !HAVE_THREADS | 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 | s->thread_count = thread_count; | 1184 | s->thread_count = thread_count; |
| 1185 | return -1; | 1185 | return -1; |
| 1186 | } | 1186 | } |
| @@ -1319,3 +1319,17 @@ void ff_thread_await_progress(AVFrame *f, int progress, int field) · 132 unmodified lines | |||
| 1319 | } | 1319 | } |
| 1320 | 1320 | ||
| 1321 | #endif | 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){ · 68 unmodified lines | |||
| 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 | * Must be called after decoding has finished, especially do not call while avcodec_thread_execute() is running. | 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 | ThreadContext *c= s->thread_opaque; | 76 | ThreadContext *c= s->thread_opaque; |
| 77 | int i; | 77 | int i; |
| 78 | 78 | ||
| @@ -124,7 +124,7 @@ static int avcodec_thread_execute2(AVCodecContext *s, int (*func)(AVCodecContext · 45 unmodified lines | |||
| 124 | avcodec_thread_execute(s, NULL, arg, ret, count, 0); | 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 | int i; | 128 | int i; |
| 129 | ThreadContext *c; | 129 | ThreadContext *c; |
| 130 | uint32_t threadid; | 130 | uint32_t threadid; |
| @@ -169,6 +169,6 @@ int avcodec_thread_init(AVCodecContext *s, int thread_count){ · 38 unmodified lines | |||
| 169 | 169 | ||
| 170 | return 0; | 170 | return 0; |
| 171 | fail: | 171 | fail: |
| 172 | avcodec_thread_free(s); | 172 | ff_thread_free(s); |
| 173 | return -1; | 173 | return -1; |
| 174 | } | 174 | } |