On Wed, Jul 11, 2012 at 06:03:49PM -0700, Daniel Kang wrote:
> --- a/libavcodec/vp8.c
> +++ b/libavcodec/vp8.c
> @@ -22,6 +23,7 @@
>   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 
> USA
>   */
>  
> +
>  #include "libavutil/imgutils.h"
>  #include "avcodec.h"
>  #include "internal.h"

stray change

> @@ -121,14 +137,25 @@ static int update_dimensions(VP8Context *s, int width, 
> int height)
> +    for (i = 0; i < MAX_THREADS; i++) {
> +        s->thread_data[i].filter_strength = 
> av_mallocz(s->mb_width*sizeof(*s->thread_data[0].filter_strength));
> +        //pthread_mutex_init(&s->thread_data[i]->lock, NULL);
> +        //pthread_cond_init(&s->thread_data[i]->cond, NULL);
> +    }

http://thecodelesscode.com/case/41

> @@ -664,11 +716,12 @@ void decode_mb_mode(VP8Context *s, VP8Macroblock *mb, 
> int mb_x, int mb_y, uint8_
>          } else {
>              const uint32_t modes = vp8_pred4x4_mode[mb->mode] * 0x01010101u;
> -            AV_WN32A(s->intra4x4_pred_mode_top + 4 * mb_x, modes);
> -            AV_WN32A(s->intra4x4_pred_mode_left, modes);
> +            if (s->mlayout == 1) AV_WN32A(mb->intra4x4_pred_mode_top, modes);
> +            else                 AV_WN32A(s->intra4x4_pred_mode_top + 4 * 
> mb_x, modes);

Break these lines.

> @@ -1328,51 +1382,51 @@ void inter_predict(VP8Context *s, uint8_t *dst[3], 
> VP8Macroblock *mb,
>  
> -static av_always_inline void idct_mb(VP8Context *s, uint8_t *dst[3], 
> VP8Macroblock *mb)
> +static av_always_inline void idct_mb(VP8Context *s, VP8ThreadData *td, 
> uint8_t *dst[3], VP8Macroblock *mb)

Break this long line.

> @@ -1576,70 +1598,173 @@ static void release_queued_segmaps(VP8Context *s, 
> int is_close)
>  
> +#undef printf
> +#define check_thread_pos(td, otd, mb_x_check, mb_y_check)\
> +    do {\
> +        int tmp = (mb_y_check << 16) | (mb_x_check & 0xFFFF);\
> +        if (otd->thread_mb_pos < tmp) {\
> +            pthread_mutex_lock(&otd->lock);\
> +            td->wait_mb_pos = tmp;\
> +            do {\
> +                if (otd->thread_mb_pos >= tmp) break;\

Break this line.

> +                pthread_cond_wait(&otd->cond, &otd->lock);\
> +            } while (1);\
> +            td->wait_mb_pos = INT_MAX;\
> +            pthread_mutex_unlock(&otd->lock);\
> +        }\
> +    } while(0);
> +#define update_pos(td, mb_y, mb_x)\
> +    do {\
> +    int pos = (mb_y << 16) | (mb_x & 0xFFFF);\
> +    int sliced_threading = (avctx->active_thread_type == FF_THREAD_SLICE) && 
> (num_jobs > 1);\
> +    int is_null = (next_td == NULL) || (prev_td == NULL);\
> +    int pos_check = (is_null) ? 1 :\
> +                        (next_td != td && pos >= next_td->wait_mb_pos) ||\
> +                        (prev_td != td && pos >= prev_td->wait_mb_pos);\
> +    td->thread_mb_pos = pos;\
> +    if (sliced_threading && pos_check) {\
> +        pthread_mutex_lock(&td->lock);\
> +        pthread_cond_broadcast(&td->cond);\
> +        pthread_mutex_unlock(&td->lock);\
> +    }\
> +    } while(0);

Leave an empty line between macros.
Align the =, preferably on column 72.

> +/*#define check_thread_pos(td, otd, mb_x_check, mb_y_check)\
> +    if (avctx->active_thread_type == FF_THREAD_SLICE && num_jobs > 1) {\
> +        do {\
> +            int tmp = (mb_y_check << 16) | (mb_x_check & 0xFFFF);\
> +            if (otd->thread_mb_pos >= tmp) break;\
> +            pause_hint();\
> +            ff_thread_sleep(0);\
> +        } while(1);\
> +    }
> +#define update_pos(td, mb_y, mb_x)\
> +    if (avctx->active_thread_type == FF_THREAD_SLICE && num_jobs > 1) {\
> +        td->thread_mb_pos = (mb_y << 16) | (mb_x & 0xFFFF);\
> +    }*/

http://thecodelesscode.com/case/41

>      for (mb_x = 0; mb_x < s->mb_width; mb_x++, mb_xy++, mb++) {
> -        /* Prefetch the current frame, 4 MBs ahead */
> +        // Wait for previous thread to read mb_x+2, and reach mb_y-1.
> +        if (prev_td != td) {
> +            if (threadnr != 0) {
> +                check_thread_pos(td, prev_td, mb_x+1, mb_y-1);
> +            }
> +            else {
> +                check_thread_pos(td, prev_td, (s->mb_width+3) + (mb_x+1), 
> mb_y-1);

Move the else to the previous line.

> @@ -1648,22 +1773,103 @@ static void vp8_decode_mb_row(AVCodecContext *avctx, 
> AVFrame *curframe,
> +
> +        if (mb_x == s->mb_width+1) {
> +            update_pos(td, mb_y, s->mb_width+3);
> +        }
> +        else {
> +            update_pos(td, mb_y, mb_x);

ditto

> +    uint8_t *dst[3] = {
> +        curframe->data[0] + 16*mb_y*s->linesize,
> +        curframe->data[1] +  8*mb_y*s->uvlinesize,
> +        curframe->data[2] +  8*mb_y*s->uvlinesize
> +    };
> +
> +    if (s->mlayout == 1)
> +        mb = s->macroblocks_base + ((s->mb_width+1)*(mb_y + 1) + 1);
> +    else
> +        mb = s->macroblocks + (s->mb_height - mb_y - 1)*2;
> +
> +    if (mb_y == 0) prev_td = td;
> +    else           prev_td = &s->thread_data[(jobnr+num_jobs-1)%num_jobs];
> +    if (mb_y == s->mb_height-1) next_td = td;
> +    else                        next_td = 
> &s->thread_data[(jobnr+1)%num_jobs];

Here and in other places: Give the operators some room to breathe.

> +    for (mb_x = 0; mb_x < s->mb_width; mb_x++, mb++) {
> +        VP8FilterStrength *f = &td->filter_strength[mb_x];
> +        if (prev_td != td) {
> +            check_thread_pos(td, prev_td, (mb_x+1) + (s->mb_width+3), 
> mb_y-1);
> +        }
> +        if (next_td != td) {
> +            if (next_td != &s->thread_data[0]) {
> +                check_thread_pos(td, next_td, mb_x+1, mb_y+1);
> +            }
> +        }

Drop {}

> @@ -1754,13 +1960,17 @@ static int vp8_decode_frame(AVCodecContext *avctx, 
> void *data, int *data_size,
>  
> -    if (!s->edge_emu_buffer)
> -        s->edge_emu_buffer = av_malloc(21*s->linesize);
> +    if (!s->thread_data[0].edge_emu_buffer) {
> +        for (i = 0; i < MAX_THREADS; i++)
> +            s->thread_data[i].edge_emu_buffer = av_malloc(21*s->linesize);
> +    }

Drop {}

> @@ -1768,20 +1978,30 @@ static int vp8_decode_frame(AVCodecContext *avctx, 
> void *data, int *data_size,
> +    s->num_jobs = num_jobs;
> +    s->curframe = curframe;
> +    s->prev_frame = prev_frame;
> +    s->mv_min.y = -MARGIN;
> +    s->mv_max.y = ((s->mb_height - 1) << 6) + MARGIN;

Align the =.

> --- a/libavcodec/vp8.h
> +++ b/libavcodec/vp8.h
> @@ -247,6 +255,13 @@ typedef struct {
>      int maps_are_invalid;
> +    int num_jobs;
> +    /**
> +     * This describes the macroblock memory layout.
> +     * 0 -> Only width+height*2+1 macroblocks allocated (frame/single 
> thread).
> +     * 1 -> Macroblocks for entire frame alloced (sliced thread).
> +     */
> +    int mlayout;

Does not sound like a very good name to me - does 'm' stand for "memory"
or "macroblock"?

Diego
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to