[FFmpeg-cvslog] Deprecate avcodec_thread_init()
Alexander Strange
git
Fri Feb 11 03:52:12 CET 2011
ffmpeg | branch: master | Alexander Strange <astrange at ithinksw.com> | Mon Feb 7 21:15:45 2011 -0500| [043d2ff2673933c0ac8995b74c76973bd93cdd3e] | committer: Michael Niedermayer
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.
Signed-off-by: Ronald S. Bultje <rsbultje at gmail.com>
(cherry picked from commit c0b102ca03fe92250f1ce620aec3836f529fc1d6)
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=043d2ff2673933c0ac8995b74c76973bd93cdd3e
---
doc/APIchanges | 4 ++++
ffmpeg.c | 11 +++--------
ffplay.c | 2 +-
libavcodec/avcodec.h | 8 +++++++-
libavcodec/pthread.c | 6 +++---
libavcodec/thread.h | 3 +++
libavcodec/utils.c | 20 +++++++++++++++++---
libavcodec/w32thread.c | 8 ++++----
8 files changed, 42 insertions(+), 20 deletions(-)
diff --git a/doc/APIchanges b/doc/APIchanges
index 3084bc3..14529b2 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -13,6 +13,10 @@ libavutil: 2009-03-08
API changes, most recent first:
+2011-02-09 - XXXXXXX - lavc 52.112.0 - avcodec_thread_init()
+ Deprecate avcodec_thread_init()/avcodec_thread_free() use; instead
+ set thread_count before calling avcodec_open.
+
2011-02-09 - 778b08a - lavc 52.111.0 - threading API
Add CODEC_CAP_FRAME_THREADS with new restrictions on get_buffer()/
release_buffer()/draw_horiz_band() callbacks for appropriate codecs.
diff --git a/ffmpeg.c b/ffmpeg.c
index 379ac04..eed4055 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -707,11 +707,6 @@ static int read_ffserver_streams(AVFormatContext *s, const char *filename)
choose_pixel_fmt(st, codec);
}
- if(!st->codec->thread_count)
- st->codec->thread_count = 1;
- if(st->codec->thread_count>1)
- avcodec_thread_init(st->codec, st->codec->thread_count);
-
if(st->codec->flags & CODEC_FLAG_BITEXACT)
nopts = 1;
@@ -3248,7 +3243,7 @@ static void opt_input_file(const char *filename)
for(i=0;i<ic->nb_streams;i++) {
AVStream *st = ic->streams[i];
AVCodecContext *dec = st->codec;
- avcodec_thread_init(dec, thread_count);
+ dec->thread_count = thread_count;
input_codecs = grow_array(input_codecs, sizeof(*input_codecs), &nb_input_codecs, nb_input_codecs + 1);
switch (dec->codec_type) {
case AVMEDIA_TYPE_AUDIO:
@@ -3406,7 +3401,7 @@ static void new_video_stream(AVFormatContext *oc, int file_idx)
ost->bitstream_filters = video_bitstream_filters;
video_bitstream_filters= NULL;
- avcodec_thread_init(st->codec, thread_count);
+ st->codec->thread_count= thread_count;
video_enc = st->codec;
@@ -3553,7 +3548,7 @@ static void new_audio_stream(AVFormatContext *oc, int file_idx)
ost->bitstream_filters = audio_bitstream_filters;
audio_bitstream_filters= NULL;
- avcodec_thread_init(st->codec, thread_count);
+ st->codec->thread_count= thread_count;
audio_enc = st->codec;
audio_enc->codec_type = AVMEDIA_TYPE_AUDIO;
diff --git a/ffplay.c b/ffplay.c
index 1595cd6..ba7e48c 100644
--- a/ffplay.c
+++ b/ffplay.c
@@ -2257,7 +2257,7 @@ static int stream_component_open(VideoState *is, int stream_index)
avctx->skip_loop_filter= skip_loop_filter;
avctx->error_recognition= error_recognition;
avctx->error_concealment= error_concealment;
- avcodec_thread_init(avctx, thread_count);
+ avctx->thread_count= thread_count;
set_context_opts(avctx, avcodec_opts[avctx->codec_type], 0, codec);
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 90446cd..850e3e7 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -32,7 +32,7 @@
#include "libavutil/cpu.h"
#define LIBAVCODEC_VERSION_MAJOR 52
-#define LIBAVCODEC_VERSION_MINOR 111
+#define LIBAVCODEC_VERSION_MINOR 112
#define LIBAVCODEC_VERSION_MICRO 0
#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);
enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, const enum PixelFormat * fmt);
+#if LIBAVCODEC_VERSION_MAJOR < 53
+/**
+ * @deprecated Set s->thread_count before calling avcodec_open() instead of calling this.
+ */
+attribute_deprecated
int avcodec_thread_init(AVCodecContext *s, int thread_count);
void avcodec_thread_free(AVCodecContext *s);
+#endif
int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size);
int avcodec_default_execute2(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2, int, int),void *arg, int *ret, int count);
//FIXME func typedef
diff --git a/libavcodec/pthread.c b/libavcodec/pthread.c
index 00e419b..0e033d3 100644
--- a/libavcodec/pthread.c
+++ b/libavcodec/pthread.c
@@ -256,7 +256,7 @@ static int thread_init(AVCodecContext *avctx)
if(pthread_create(&c->workers[i], NULL, worker, avctx)) {
avctx->thread_count = i;
pthread_mutex_unlock(&c->current_job_lock);
- avcodec_thread_free(avctx);
+ ff_thread_free(avctx);
return -1;
}
}
@@ -870,7 +870,7 @@ static void validate_thread_parameters(AVCodecContext *avctx)
}
}
-int avcodec_thread_init(AVCodecContext *avctx, int thread_count)
+int ff_thread_init(AVCodecContext *avctx, int thread_count)
{
if (avctx->thread_opaque) {
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)
return 0;
}
-void avcodec_thread_free(AVCodecContext *avctx)
+void ff_thread_free(AVCodecContext *avctx)
{
if (avctx->active_thread_type&FF_THREAD_FRAME)
frame_thread_free(avctx, avctx->thread_count);
diff --git a/libavcodec/thread.h b/libavcodec/thread.h
index d9186d6..485f4ec 100644
--- a/libavcodec/thread.h
+++ b/libavcodec/thread.h
@@ -108,4 +108,7 @@ int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f);
*/
void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f);
+int ff_thread_init(AVCodecContext *s, int thread_count);
+void ff_thread_free(AVCodecContext *s);
+
#endif /* AVCODEC_THREAD_H */
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 790d182..04f511f 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -540,7 +540,7 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
avctx->frame_number = 0;
if (HAVE_THREADS && !avctx->thread_opaque) {
- ret = avcodec_thread_init(avctx, avctx->thread_count);
+ ret = ff_thread_init(avctx, avctx->thread_count);
if (ret < 0) {
goto free_and_end;
}
@@ -819,7 +819,7 @@ av_cold int avcodec_close(AVCodecContext *avctx)
}
if (HAVE_THREADS && avctx->thread_opaque)
- avcodec_thread_free(avctx);
+ ff_thread_free(avctx);
if (avctx->codec && avctx->codec->close)
avctx->codec->close(avctx);
avcodec_default_free_buffers(avctx);
@@ -1180,7 +1180,7 @@ int av_get_bits_per_sample_format(enum AVSampleFormat sample_fmt) {
#endif
#if !HAVE_THREADS
-int avcodec_thread_init(AVCodecContext *s, int thread_count){
+int ff_thread_init(AVCodecContext *s, int thread_count){
s->thread_count = thread_count;
return -1;
}
@@ -1319,3 +1319,17 @@ void ff_thread_await_progress(AVFrame *f, int progress, int field)
}
#endif
+
+#if LIBAVCODEC_VERSION_MAJOR < 53
+
+int avcodec_thread_init(AVCodecContext *s, int thread_count)
+{
+ return ff_thread_init(s, thread_count);
+}
+
+void avcodec_thread_free(AVCodecContext *s)
+{
+ return ff_thread_free(s);
+}
+
+#endif
diff --git a/libavcodec/w32thread.c b/libavcodec/w32thread.c
index 007508e..1659fd3 100644
--- a/libavcodec/w32thread.c
+++ b/libavcodec/w32thread.c
@@ -69,10 +69,10 @@ static unsigned WINAPI attribute_align_arg thread_func(void *v){
}
/**
- * Free what has been allocated by avcodec_thread_init().
+ * Free what has been allocated by ff_thread_init().
* Must be called after decoding has finished, especially do not call while avcodec_thread_execute() is running.
*/
-void avcodec_thread_free(AVCodecContext *s){
+void ff_thread_free(AVCodecContext *s){
ThreadContext *c= s->thread_opaque;
int i;
@@ -124,7 +124,7 @@ static int avcodec_thread_execute2(AVCodecContext *s, int (*func)(AVCodecContext
avcodec_thread_execute(s, NULL, arg, ret, count, 0);
}
-int avcodec_thread_init(AVCodecContext *s, int thread_count){
+int ff_thread_init(AVCodecContext *s, int thread_count){
int i;
ThreadContext *c;
uint32_t threadid;
@@ -169,6 +169,6 @@ int avcodec_thread_init(AVCodecContext *s, int thread_count){
return 0;
fail:
- avcodec_thread_free(s);
+ ff_thread_free(s);
return -1;
}
More information about the ffmpeg-cvslog
mailing list