[FFmpeg-cvslog] r15804 - in trunk/libavcodec: avcodec.h beosthread.c dnxhdenc.c dv.c h264.c mpeg12.c mpegvideo_enc.c os2thread.c pthread.c utils.c w32thread.c

romansh subversion
Wed Nov 12 18:47:24 CET 2008


Author: romansh
Date: Wed Nov 12 18:47:23 2008
New Revision: 15804

Log:
Making it easier to send arbitrary structures as work orders to MT workers


Modified:
   trunk/libavcodec/avcodec.h
   trunk/libavcodec/beosthread.c
   trunk/libavcodec/dnxhdenc.c
   trunk/libavcodec/dv.c
   trunk/libavcodec/h264.c
   trunk/libavcodec/mpeg12.c
   trunk/libavcodec/mpegvideo_enc.c
   trunk/libavcodec/os2thread.c
   trunk/libavcodec/pthread.c
   trunk/libavcodec/utils.c
   trunk/libavcodec/w32thread.c

Modified: trunk/libavcodec/avcodec.h
==============================================================================
--- trunk/libavcodec/avcodec.h	(original)
+++ trunk/libavcodec/avcodec.h	Wed Nov 12 18:47:23 2008
@@ -1876,7 +1876,7 @@ typedef struct AVCodecContext {
      * - encoding: Set by libavcodec, user can override.
      * - decoding: Set by libavcodec, user can override.
      */
-    int (*execute)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg), void **arg2, int *ret, int count);
+    int (*execute)(struct AVCodecContext *c, int (*func)(struct AVCodecContext *c2, void *arg), void *arg2, int *ret, int count, int size);
 
     /**
      * thread opaque
@@ -2642,8 +2642,8 @@ enum PixelFormat avcodec_default_get_for
 
 int avcodec_thread_init(AVCodecContext *s, int thread_count);
 void avcodec_thread_free(AVCodecContext *s);
-int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count);
-int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count);
+int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size);
+int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size);
 //FIXME func typedef
 
 /**

Modified: trunk/libavcodec/beosthread.c
==============================================================================
--- trunk/libavcodec/beosthread.c	(original)
+++ trunk/libavcodec/beosthread.c	Wed Nov 12 18:47:23 2008
@@ -92,7 +92,7 @@ void avcodec_thread_free(AVCodecContext 
     av_freep(&s->thread_opaque);
 }
 
-int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count){
+int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size){
     ThreadContext *c= s->thread_opaque;
     int i;
 
@@ -102,7 +102,7 @@ int avcodec_thread_execute(AVCodecContex
     /* note, we can be certain that this is not called with the same AVCodecContext by different threads at the same time */
 
     for(i=0; i<count; i++){
-        c[i].arg= arg[i];
+        c[i].arg= (char*)arg + i*size;
         c[i].func= func;
         c[i].ret= 12345;
 

Modified: trunk/libavcodec/dnxhdenc.c
==============================================================================
--- trunk/libavcodec/dnxhdenc.c	(original)
+++ trunk/libavcodec/dnxhdenc.c	Wed Nov 12 18:47:23 2008
@@ -449,7 +449,7 @@ static av_always_inline int dnxhd_switch
 
 static int dnxhd_calc_bits_thread(AVCodecContext *avctx, void *arg)
 {
-    DNXHDEncContext *ctx = arg;
+    DNXHDEncContext *ctx = *(void**)arg;
     int mb_y, mb_x;
     int qscale = ctx->thread[0]->qscale;
 
@@ -499,7 +499,7 @@ static int dnxhd_calc_bits_thread(AVCode
 
 static int dnxhd_encode_thread(AVCodecContext *avctx, void *arg)
 {
-    DNXHDEncContext *ctx = arg;
+    DNXHDEncContext *ctx = *(void**)arg;
     int mb_y, mb_x;
 
     for (mb_y = ctx->m.start_mb_y; mb_y < ctx->m.end_mb_y; mb_y++) {
@@ -555,7 +555,7 @@ static void dnxhd_setup_threads_slices(D
 
 static int dnxhd_mb_var_thread(AVCodecContext *avctx, void *arg)
 {
-    DNXHDEncContext *ctx = arg;
+    DNXHDEncContext *ctx = *(void**)arg;
     int mb_y, mb_x;
     for (mb_y = ctx->m.start_mb_y; mb_y < ctx->m.end_mb_y; mb_y++) {
         for (mb_x = 0; mb_x < ctx->m.mb_width; mb_x++) {
@@ -578,7 +578,7 @@ static int dnxhd_encode_rdo(AVCodecConte
 
     for (q = 1; q < avctx->qmax; q++) {
         ctx->qscale = q;
-        avctx->execute(avctx, dnxhd_calc_bits_thread, (void**)&ctx->thread[0], NULL, avctx->thread_count);
+        avctx->execute(avctx, dnxhd_calc_bits_thread, (void**)&ctx->thread[0], NULL, avctx->thread_count, sizeof(void*));
     }
     up_step = down_step = 2<<LAMBDA_FRAC_BITS;
     lambda = ctx->lambda;
@@ -658,7 +658,7 @@ static int dnxhd_find_qscale(DNXHDEncCon
         bits = 0;
         ctx->qscale = qscale;
         // XXX avoid recalculating bits
-        ctx->m.avctx->execute(ctx->m.avctx, dnxhd_calc_bits_thread, (void**)&ctx->thread[0], NULL, ctx->m.avctx->thread_count);
+        ctx->m.avctx->execute(ctx->m.avctx, dnxhd_calc_bits_thread, (void**)&ctx->thread[0], NULL, ctx->m.avctx->thread_count, sizeof(void*));
         for (y = 0; y < ctx->m.mb_height; y++) {
             for (x = 0; x < ctx->m.mb_width; x++)
                 bits += ctx->mb_rc[qscale][y*ctx->m.mb_width+x].bits;
@@ -731,7 +731,7 @@ static int dnxhd_encode_fast(AVCodecCont
     }
     if (!ret) {
         if (RC_VARIANCE)
-            avctx->execute(avctx, dnxhd_mb_var_thread, (void**)&ctx->thread[0], NULL, avctx->thread_count);
+            avctx->execute(avctx, dnxhd_mb_var_thread, (void**)&ctx->thread[0], NULL, avctx->thread_count, sizeof(void*));
         qsort(ctx->mb_cmp, ctx->m.mb_num, sizeof(RCEntry), dnxhd_rc_cmp);
         for (x = 0; x < ctx->m.mb_num && max_bits > ctx->frame_bits; x++) {
             int mb = ctx->mb_cmp[x].mb;
@@ -803,7 +803,7 @@ static int dnxhd_encode_picture(AVCodecC
         assert(!(ctx->slice_size[i] & 3));
     }
 
-    avctx->execute(avctx, dnxhd_encode_thread, (void**)&ctx->thread[0], NULL, avctx->thread_count);
+    avctx->execute(avctx, dnxhd_encode_thread, (void**)&ctx->thread[0], NULL, avctx->thread_count, sizeof(void*));
 
     AV_WB32(buf + ctx->cid_table->coding_unit_size - 4, 0x600DC0DE); // EOF
 

Modified: trunk/libavcodec/dv.c
==============================================================================
--- trunk/libavcodec/dv.c	(original)
+++ trunk/libavcodec/dv.c	Wed Nov 12 18:47:23 2008
@@ -1013,14 +1013,14 @@ static inline void dv_encode_video_segme
 
 static int dv_decode_mt(AVCodecContext *avctx, void* sl)
 {
-    dv_decode_video_segment((DVVideoContext *)avctx->priv_data, (size_t)sl);
+    dv_decode_video_segment((DVVideoContext *)avctx->priv_data, *(size_t*)sl);
     return 0;
 }
 
 #ifdef CONFIG_DVVIDEO_ENCODER
 static int dv_encode_mt(AVCodecContext *avctx, void* sl)
 {
-    dv_encode_video_segment((DVVideoContext *)avctx->priv_data, (size_t)sl);
+    dv_encode_video_segment((DVVideoContext *)avctx->priv_data, *(size_t*)sl);
     return 0;
 }
 #endif
@@ -1056,7 +1056,7 @@ static int dvvideo_decode_frame(AVCodecC
 
     s->buf = buf;
     avctx->execute(avctx, dv_decode_mt, s->sys->work_chunks, NULL,
-                   dv_work_pool_size(s->sys));
+                   dv_work_pool_size(s->sys), sizeof(void*));
 
     emms_c();
 
@@ -1209,7 +1209,7 @@ static int dvvideo_encode_frame(AVCodecC
 
     s->buf = buf;
     c->execute(c, dv_encode_mt, s->sys->work_chunks, NULL,
-               dv_work_pool_size(s->sys));
+               dv_work_pool_size(s->sys), sizeof(void*));
 
     emms_c();
 

Modified: trunk/libavcodec/h264.c
==============================================================================
--- trunk/libavcodec/h264.c	(original)
+++ trunk/libavcodec/h264.c	Wed Nov 12 18:47:23 2008
@@ -6626,7 +6626,8 @@ static void filter_mb( H264Context *h, i
     }
 }
 
-static int decode_slice(struct AVCodecContext *avctx, H264Context *h){
+static int decode_slice(struct AVCodecContext *avctx, void *arg){
+    H264Context *h = *(void**)arg;
     MpegEncContext * const s = &h->s;
     const int part_mask= s->partitioned_frame ? (AC_END|AC_ERROR) : 0x7F;
 
@@ -7346,7 +7347,7 @@ static void execute_decode_slices(H264Co
         }
 
         avctx->execute(avctx, (void *)decode_slice,
-                       (void **)h->thread_context, NULL, context_count);
+                       (void **)h->thread_context, NULL, context_count, sizeof(void*));
 
         /* pull back stuff from slices to master context */
         hx = h->thread_context[context_count - 1];

Modified: trunk/libavcodec/mpeg12.c
==============================================================================
--- trunk/libavcodec/mpeg12.c	(original)
+++ trunk/libavcodec/mpeg12.c	Wed Nov 12 18:47:23 2008
@@ -1866,7 +1866,7 @@ eos: // end of slice
 }
 
 static int slice_decode_thread(AVCodecContext *c, void *arg){
-    MpegEncContext *s= arg;
+    MpegEncContext *s= *(void**)arg;
     const uint8_t *buf= s->gb.buffer;
     int mb_y= s->start_mb_y;
 
@@ -2299,7 +2299,7 @@ static int decode_chunks(AVCodecContext 
                 if(avctx->thread_count > 1){
                     int i;
 
-                    avctx->execute(avctx, slice_decode_thread,  (void**)&(s2->thread_context[0]), NULL, s->slice_count);
+                    avctx->execute(avctx, slice_decode_thread,  (void**)&(s2->thread_context[0]), NULL, s->slice_count, sizeof(void*));
                     for(i=0; i<s->slice_count; i++)
                         s2->error_count += s2->thread_context[i]->error_count;
                 }

Modified: trunk/libavcodec/mpegvideo_enc.c
==============================================================================
--- trunk/libavcodec/mpegvideo_enc.c	(original)
+++ trunk/libavcodec/mpegvideo_enc.c	Wed Nov 12 18:47:23 2008
@@ -1917,7 +1917,7 @@ static int sse_mb(MpegEncContext *s){
 }
 
 static int pre_estimate_motion_thread(AVCodecContext *c, void *arg){
-    MpegEncContext *s= arg;
+    MpegEncContext *s= *(void**)arg;
 
 
     s->me.pre_pass=1;
@@ -1936,7 +1936,7 @@ static int pre_estimate_motion_thread(AV
 }
 
 static int estimate_motion_thread(AVCodecContext *c, void *arg){
-    MpegEncContext *s= arg;
+    MpegEncContext *s= *(void**)arg;
 
     ff_check_alignment();
 
@@ -1963,7 +1963,7 @@ static int estimate_motion_thread(AVCode
 }
 
 static int mb_var_thread(AVCodecContext *c, void *arg){
-    MpegEncContext *s= arg;
+    MpegEncContext *s= *(void**)arg;
     int mb_x, mb_y;
 
     ff_check_alignment();
@@ -2005,7 +2005,7 @@ static void write_slice_end(MpegEncConte
 }
 
 static int encode_thread(AVCodecContext *c, void *arg){
-    MpegEncContext *s= arg;
+    MpegEncContext *s= *(void**)arg;
     int mb_x, mb_y, pdif = 0;
     int chr_h= 16>>s->chroma_y_shift;
     int i, j;
@@ -2779,11 +2779,11 @@ static int encode_picture(MpegEncContext
         s->lambda2= (s->lambda2* (int64_t)s->avctx->me_penalty_compensation + 128)>>8;
         if(s->pict_type != FF_B_TYPE && s->avctx->me_threshold==0){
             if((s->avctx->pre_me && s->last_non_b_pict_type==FF_I_TYPE) || s->avctx->pre_me==2){
-                s->avctx->execute(s->avctx, pre_estimate_motion_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count);
+                s->avctx->execute(s->avctx, pre_estimate_motion_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count, sizeof(void*));
             }
         }
 
-        s->avctx->execute(s->avctx, estimate_motion_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count);
+        s->avctx->execute(s->avctx, estimate_motion_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count, sizeof(void*));
     }else /* if(s->pict_type == FF_I_TYPE) */{
         /* I-Frame */
         for(i=0; i<s->mb_stride*s->mb_height; i++)
@@ -2791,7 +2791,7 @@ static int encode_picture(MpegEncContext
 
         if(!s->fixed_qscale){
             /* finding spatial complexity for I-frame rate control */
-            s->avctx->execute(s->avctx, mb_var_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count);
+            s->avctx->execute(s->avctx, mb_var_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count, sizeof(void*));
         }
     }
     for(i=1; i<s->avctx->thread_count; i++){
@@ -2931,7 +2931,7 @@ static int encode_picture(MpegEncContext
     for(i=1; i<s->avctx->thread_count; i++){
         update_duplicate_context_after_me(s->thread_context[i], s);
     }
-    s->avctx->execute(s->avctx, encode_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count);
+    s->avctx->execute(s->avctx, encode_thread, (void**)&(s->thread_context[0]), NULL, s->avctx->thread_count, sizeof(void*));
     for(i=1; i<s->avctx->thread_count; i++){
         merge_context_after_encode(s, s->thread_context[i]);
     }

Modified: trunk/libavcodec/os2thread.c
==============================================================================
--- trunk/libavcodec/os2thread.c	(original)
+++ trunk/libavcodec/os2thread.c	Wed Nov 12 18:47:23 2008
@@ -81,7 +81,7 @@ void avcodec_thread_free(AVCodecContext 
     av_freep(&s->thread_opaque);
 }
 
-int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count){
+int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size){
     ThreadContext *c= s->thread_opaque;
     int i;
 
@@ -92,7 +92,7 @@ int avcodec_thread_execute(AVCodecContex
 
     for(i=0; i<count; i++){
 
-        c[i].arg= arg[i];
+        c[i].arg= (char*)arg + i*size;
         c[i].func= func;
         c[i].ret= 12345;
 

Modified: trunk/libavcodec/pthread.c
==============================================================================
--- trunk/libavcodec/pthread.c	(original)
+++ trunk/libavcodec/pthread.c	Wed Nov 12 18:47:23 2008
@@ -30,10 +30,11 @@ typedef int (action_t)(AVCodecContext *c
 typedef struct ThreadContext {
     pthread_t *workers;
     action_t *func;
-    void **args;
+    void *args;
     int *rets;
     int rets_count;
     int job_count;
+    int job_size;
 
     pthread_cond_t last_job_cond;
     pthread_cond_t current_job_cond;
@@ -67,7 +68,7 @@ static void* attribute_align_arg worker(
         }
         pthread_mutex_unlock(&c->current_job_lock);
 
-        c->rets[our_job%c->rets_count] = c->func(avctx, c->args[our_job]);
+        c->rets[our_job%c->rets_count] = c->func(avctx, (char*)c->args + our_job*c->job_size);
 
         pthread_mutex_lock(&c->current_job_lock);
         our_job = c->current_job++;
@@ -100,7 +101,7 @@ void avcodec_thread_free(AVCodecContext 
     av_freep(&avctx->thread_opaque);
 }
 
-int avcodec_thread_execute(AVCodecContext *avctx, action_t* func, void **arg, int *ret, int job_count)
+int avcodec_thread_execute(AVCodecContext *avctx, action_t* func, void *arg, int *ret, int job_count, int job_size)
 {
     ThreadContext *c= avctx->thread_opaque;
     int dummy_ret;
@@ -112,6 +113,7 @@ int avcodec_thread_execute(AVCodecContex
 
     c->current_job = avctx->thread_count;
     c->job_count = job_count;
+    c->job_size = job_size;
     c->args = arg;
     c->func = func;
     if (ret) {
@@ -147,6 +149,7 @@ int avcodec_thread_init(AVCodecContext *
     avctx->thread_count = thread_count;
     c->current_job = 0;
     c->job_count = 0;
+    c->job_size = 0;
     c->done = 0;
     pthread_cond_init(&c->current_job_cond, NULL);
     pthread_cond_init(&c->last_job_cond, NULL);

Modified: trunk/libavcodec/utils.c
==============================================================================
--- trunk/libavcodec/utils.c	(original)
+++ trunk/libavcodec/utils.c	Wed Nov 12 18:47:23 2008
@@ -368,11 +368,11 @@ int avcodec_default_reget_buffer(AVCodec
     return 0;
 }
 
-int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count){
+int avcodec_default_execute(AVCodecContext *c, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size){
     int i;
 
     for(i=0; i<count; i++){
-        int r= func(c, arg[i]);
+        int r= func(c, (char*)arg + i*size);
         if(ret) ret[i]= r;
     }
     return 0;

Modified: trunk/libavcodec/w32thread.c
==============================================================================
--- trunk/libavcodec/w32thread.c	(original)
+++ trunk/libavcodec/w32thread.c	Wed Nov 12 18:47:23 2008
@@ -74,7 +74,7 @@ void avcodec_thread_free(AVCodecContext 
     av_freep(&s->thread_opaque);
 }
 
-int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void **arg, int *ret, int count){
+int avcodec_thread_execute(AVCodecContext *s, int (*func)(AVCodecContext *c2, void *arg2),void *arg, int *ret, int count, int size){
     ThreadContext *c= s->thread_opaque;
     int i;
 
@@ -84,7 +84,7 @@ int avcodec_thread_execute(AVCodecContex
     /* note, we can be certain that this is not called with the same AVCodecContext by different threads at the same time */
 
     for(i=0; i<count; i++){
-        c[i].arg= arg[i];
+        c[i].arg= (char*)arg + i*size;
         c[i].func= func;
         c[i].ret= 12345;
 




More information about the ffmpeg-cvslog mailing list