1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-23 12:43:46 +02:00

Remove unnecessary parameter from ff_thread_init() and fix behavior

thread_count passed to ff_thread_init() is only used to set AVCodecContext.
thread_count, and can be removed. Instead move it to the legacy implementation
of avcodec_thread_init().

This also fixes the problem that calling avcodec_thread_init() with pthreads
enabled did not set it since ff1efc524c.

Signed-off-by: Janne Grunau <janne-libav@jannau.net>
This commit is contained in:
Alexander Strange 2011-03-29 17:18:21 -04:00 committed by Janne Grunau
parent d6f66edd65
commit ba9ef8d04e
4 changed files with 10 additions and 11 deletions

View File

@ -882,7 +882,7 @@ static void validate_thread_parameters(AVCodecContext *avctx)
} }
} }
int ff_thread_init(AVCodecContext *avctx, int thread_count) int ff_thread_init(AVCodecContext *avctx)
{ {
if (avctx->thread_opaque) { if (avctx->thread_opaque) {
av_log(avctx, AV_LOG_ERROR, "avcodec_thread_init is ignored after avcodec_open\n"); av_log(avctx, AV_LOG_ERROR, "avcodec_thread_init is ignored after avcodec_open\n");

View File

@ -108,7 +108,7 @@ int ff_thread_get_buffer(AVCodecContext *avctx, AVFrame *f);
*/ */
void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f); void ff_thread_release_buffer(AVCodecContext *avctx, AVFrame *f);
int ff_thread_init(AVCodecContext *s, int thread_count); int ff_thread_init(AVCodecContext *s);
void ff_thread_free(AVCodecContext *s); void ff_thread_free(AVCodecContext *s);
#endif /* AVCODEC_THREAD_H */ #endif /* AVCODEC_THREAD_H */

View File

@ -539,7 +539,7 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
avctx->frame_number = 0; avctx->frame_number = 0;
if (HAVE_THREADS && !avctx->thread_opaque) { if (HAVE_THREADS && !avctx->thread_opaque) {
ret = ff_thread_init(avctx, avctx->thread_count); ret = ff_thread_init(avctx);
if (ret < 0) { if (ret < 0) {
goto free_and_end; goto free_and_end;
} }
@ -1147,8 +1147,7 @@ int av_get_bits_per_sample_format(enum AVSampleFormat sample_fmt) {
#endif #endif
#if !HAVE_THREADS #if !HAVE_THREADS
int ff_thread_init(AVCodecContext *s, int thread_count){ int ff_thread_init(AVCodecContext *s){
s->thread_count = thread_count;
return -1; return -1;
} }
#endif #endif
@ -1291,7 +1290,8 @@ void ff_thread_await_progress(AVFrame *f, int progress, int field)
int avcodec_thread_init(AVCodecContext *s, int thread_count) int avcodec_thread_init(AVCodecContext *s, int thread_count)
{ {
return ff_thread_init(s, thread_count); s->thread_count = thread_count;
return ff_thread_init(s);
} }
void avcodec_thread_free(AVCodecContext *s) void avcodec_thread_free(AVCodecContext *s)

View File

@ -125,7 +125,7 @@ static int avcodec_thread_execute2(AVCodecContext *s, int (*func)(AVCodecContext
avcodec_thread_execute(s, NULL, arg, ret, count, 0); avcodec_thread_execute(s, NULL, arg, ret, count, 0);
} }
int ff_thread_init(AVCodecContext *s, int thread_count){ int ff_thread_init(AVCodecContext *s){
int i; int i;
ThreadContext *c; ThreadContext *c;
uint32_t threadid; uint32_t threadid;
@ -135,14 +135,13 @@ int ff_thread_init(AVCodecContext *s, int thread_count){
return 0; return 0;
} }
s->thread_count= thread_count;
s->active_thread_type= FF_THREAD_SLICE; s->active_thread_type= FF_THREAD_SLICE;
if (thread_count <= 1) if (s->thread_count <= 1)
return 0; return 0;
assert(!s->thread_opaque); assert(!s->thread_opaque);
c= av_mallocz(sizeof(ThreadContext)*thread_count); c= av_mallocz(sizeof(ThreadContext)*s->thread_count);
s->thread_opaque= c; s->thread_opaque= c;
if(!(c[0].work_sem = CreateSemaphore(NULL, 0, INT_MAX, NULL))) if(!(c[0].work_sem = CreateSemaphore(NULL, 0, INT_MAX, NULL)))
goto fail; goto fail;
@ -151,7 +150,7 @@ int ff_thread_init(AVCodecContext *s, int thread_count){
if(!(c[0].done_sem = CreateSemaphore(NULL, 0, INT_MAX, NULL))) if(!(c[0].done_sem = CreateSemaphore(NULL, 0, INT_MAX, NULL)))
goto fail; goto fail;
for(i=0; i<thread_count; i++){ for(i=0; i<s->thread_count; i++){
//printf("init semaphors %d\n", i); fflush(stdout); //printf("init semaphors %d\n", i); fflush(stdout);
c[i].avctx= s; c[i].avctx= s;
c[i].work_sem = c[0].work_sem; c[i].work_sem = c[0].work_sem;