Commit d375c104 authored by Michael Niedermayer's avatar Michael Niedermayer

Fake-Merge remote-tracking branch 'ffmpeg-mt/master'

parent 038566a5
...@@ -725,10 +725,12 @@ typedef struct RcOverride{ ...@@ -725,10 +725,12 @@ typedef struct RcOverride{
* Codec should fill in channel configuration and samplerate instead of container * Codec should fill in channel configuration and samplerate instead of container
*/ */
#define CODEC_CAP_CHANNEL_CONF 0x0400 #define CODEC_CAP_CHANNEL_CONF 0x0400
/** /**
* Codec is able to deal with negative linesizes * Codec is able to deal with negative linesizes
*/ */
#define CODEC_CAP_NEG_LINESIZES 0x0800 #define CODEC_CAP_NEG_LINESIZES 0x0800
/** /**
* Codec supports frame-level multithreading. * Codec supports frame-level multithreading.
*/ */
...@@ -2983,7 +2985,9 @@ typedef struct AVCodec { ...@@ -2983,7 +2985,9 @@ typedef struct AVCodec {
const enum AVSampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1 const enum AVSampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1
const int64_t *channel_layouts; ///< array of support channel layouts, or NULL if unknown. array is terminated by 0 const int64_t *channel_layouts; ///< array of support channel layouts, or NULL if unknown. array is terminated by 0
uint8_t max_lowres; ///< maximum value for lowres supported by the decoder uint8_t max_lowres; ///< maximum value for lowres supported by the decoder
AVClass *priv_class; ///< AVClass for the private context AVClass *priv_class; ///< AVClass for the private context
const AVProfile *profiles; ///< array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN} const AVProfile *profiles; ///< array of recognized profiles, or NULL if unknown, array is terminated by {FF_PROFILE_UNKNOWN}
/** /**
......
...@@ -298,7 +298,7 @@ static int sse16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h) ...@@ -298,7 +298,7 @@ static int sse16_c(void *v, uint8_t *pix1, uint8_t *pix2, int line_size, int h)
/* draw the edges of width 'w' of an image of size width, height */ /* draw the edges of width 'w' of an image of size width, height */
//FIXME check that this is ok for mpeg4 interlaced //FIXME check that this is ok for mpeg4 interlaced
static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w) static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w, int sides)
{ {
uint8_t *ptr, *last_line; uint8_t *ptr, *last_line;
int i; int i;
...@@ -306,8 +306,8 @@ static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w) ...@@ -306,8 +306,8 @@ static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w)
last_line = buf + (height - 1) * wrap; last_line = buf + (height - 1) * wrap;
for(i=0;i<w;i++) { for(i=0;i<w;i++) {
/* top and bottom */ /* top and bottom */
memcpy(buf - (i + 1) * wrap, buf, width); if (sides&EDGE_TOP) memcpy(buf - (i + 1) * wrap, buf, width);
memcpy(last_line + (i + 1) * wrap, last_line, width); if (sides&EDGE_BOTTOM) memcpy(last_line + (i + 1) * wrap, last_line, width);
} }
/* left and right */ /* left and right */
ptr = buf; ptr = buf;
...@@ -318,10 +318,15 @@ static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w) ...@@ -318,10 +318,15 @@ static void draw_edges_c(uint8_t *buf, int wrap, int width, int height, int w)
} }
/* corners */ /* corners */
for(i=0;i<w;i++) { for(i=0;i<w;i++) {
memset(buf - (i + 1) * wrap - w, buf[0], w); /* top left */ if (sides&EDGE_TOP) {
memset(buf - (i + 1) * wrap + width, buf[width-1], w); /* top right */ memset(buf - (i + 1) * wrap - w, buf[0], w); /* top left */
memset(last_line + (i + 1) * wrap - w, last_line[0], w); /* top left */ memset(buf - (i + 1) * wrap + width, buf[width-1], w); /* top right */
memset(last_line + (i + 1) * wrap + width, last_line[width-1], w); /* top right */ }
if (sides&EDGE_BOTTOM) {
memset(last_line + (i + 1) * wrap - w, last_line[0], w); /* top left */
memset(last_line + (i + 1) * wrap + width, last_line[width-1], w); /* top right */
}
} }
} }
......
...@@ -492,8 +492,10 @@ typedef struct DSPContext { ...@@ -492,8 +492,10 @@ typedef struct DSPContext {
#define BASIS_SHIFT 16 #define BASIS_SHIFT 16
#define RECON_SHIFT 6 #define RECON_SHIFT 6
void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w); void (*draw_edges)(uint8_t *buf, int wrap, int width, int height, int w, int sides);
#define EDGE_WIDTH 16 #define EDGE_WIDTH 16
#define EDGE_TOP 1
#define EDGE_BOTTOM 2
void (*prefetch)(void *mem, int stride, int h); void (*prefetch)(void *mem, int stride, int h);
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include "mpeg4video_parser.h" #include "mpeg4video_parser.h"
#include "msmpeg4.h" #include "msmpeg4.h"
#include "vdpau_internal.h" #include "vdpau_internal.h"
#include "thread.h"
#include "flv.h" #include "flv.h"
#include "mpeg4video.h" #include "mpeg4video.h"
...@@ -235,6 +236,7 @@ static int decode_slice(MpegEncContext *s){ ...@@ -235,6 +236,7 @@ static int decode_slice(MpegEncContext *s){
if(++s->mb_x >= s->mb_width){ if(++s->mb_x >= s->mb_width){
s->mb_x=0; s->mb_x=0;
ff_draw_horiz_band(s, s->mb_y*mb_size, mb_size); ff_draw_horiz_band(s, s->mb_y*mb_size, mb_size);
MPV_report_decode_progress(s);
s->mb_y++; s->mb_y++;
} }
return 0; return 0;
...@@ -255,6 +257,7 @@ static int decode_slice(MpegEncContext *s){ ...@@ -255,6 +257,7 @@ static int decode_slice(MpegEncContext *s){
} }
ff_draw_horiz_band(s, s->mb_y*mb_size, mb_size); ff_draw_horiz_band(s, s->mb_y*mb_size, mb_size);
MPV_report_decode_progress(s);
s->mb_x= 0; s->mb_x= 0;
} }
...@@ -639,6 +642,8 @@ retry: ...@@ -639,6 +642,8 @@ retry:
if(MPV_frame_start(s, avctx) < 0) if(MPV_frame_start(s, avctx) < 0)
return -1; return -1;
if (!s->divx_packed) ff_thread_finish_setup(avctx);
if (CONFIG_MPEG4_VDPAU_DECODER && (s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)) { if (CONFIG_MPEG4_VDPAU_DECODER && (s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)) {
ff_vdpau_mpeg4_decode_picture(s, s->gb.buffer, s->gb.buffer_end - s->gb.buffer); ff_vdpau_mpeg4_decode_picture(s, s->gb.buffer, s->gb.buffer_end - s->gb.buffer);
goto frame_end; goto frame_end;
......
This diff is collapsed.
...@@ -392,9 +392,9 @@ typedef struct H264Context{ ...@@ -392,9 +392,9 @@ typedef struct H264Context{
/** /**
* num_ref_idx_l0/1_active_minus1 + 1 * num_ref_idx_l0/1_active_minus1 + 1
*/ */
uint8_t *list_counts; ///< Array of list_count per MB specifying the slice type
unsigned int ref_count[2]; ///< counts frames or fields, depending on current mb mode unsigned int ref_count[2]; ///< counts frames or fields, depending on current mb mode
unsigned int list_count; unsigned int list_count;
uint8_t *list_counts; ///< Array of list_count per MB specifying the slice type
Picture ref_list[2][48]; /**< 0..15: frame refs, 16..47: mbaff field refs. Picture ref_list[2][48]; /**< 0..15: frame refs, 16..47: mbaff field refs.
Reordered version of default_ref_list Reordered version of default_ref_list
according to picture reordering in slice header */ according to picture reordering in slice header */
...@@ -504,7 +504,9 @@ typedef struct H264Context{ ...@@ -504,7 +504,9 @@ typedef struct H264Context{
Picture *long_ref[32]; Picture *long_ref[32];
Picture default_ref_list[2][32]; ///< base reference list for all slices of a coded picture Picture default_ref_list[2][32]; ///< base reference list for all slices of a coded picture
Picture *delayed_pic[MAX_DELAYED_PIC_COUNT+2]; //FIXME size? Picture *delayed_pic[MAX_DELAYED_PIC_COUNT+2]; //FIXME size?
Picture *next_output_pic;
int outputed_poc; int outputed_poc;
int next_outputed_poc;
/** /**
* memory management control operations buffer. * memory management control operations buffer.
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "mpegvideo.h" #include "mpegvideo.h"
#include "h264.h" #include "h264.h"
#include "rectangle.h" #include "rectangle.h"
#include "thread.h"
//#undef NDEBUG //#undef NDEBUG
#include <assert.h> #include <assert.h>
...@@ -126,7 +127,7 @@ void ff_h264_direct_ref_list_init(H264Context * const h){ ...@@ -126,7 +127,7 @@ void ff_h264_direct_ref_list_init(H264Context * const h){
h->col_parity= (FFABS(col_poc[0] - cur_poc) >= FFABS(col_poc[1] - cur_poc)); h->col_parity= (FFABS(col_poc[0] - cur_poc) >= FFABS(col_poc[1] - cur_poc));
ref1sidx=sidx= h->col_parity; ref1sidx=sidx= h->col_parity;
}else if(!(s->picture_structure & h->ref_list[1][0].reference) && !h->ref_list[1][0].mbaff){ // FL -> FL & differ parity }else if(!(s->picture_structure & h->ref_list[1][0].reference) && !h->ref_list[1][0].mbaff){ // FL -> FL & differ parity
h->col_fieldoff= s->mb_stride*(2*(h->ref_list[1][0].reference) - 3); h->col_fieldoff= 2*(h->ref_list[1][0].reference) - 3;
} }
if(cur->pict_type != FF_B_TYPE || h->direct_spatial_mv_pred) if(cur->pict_type != FF_B_TYPE || h->direct_spatial_mv_pred)
...@@ -140,11 +141,27 @@ void ff_h264_direct_ref_list_init(H264Context * const h){ ...@@ -140,11 +141,27 @@ void ff_h264_direct_ref_list_init(H264Context * const h){
} }
} }
static void await_reference_mb_row(H264Context * const h, Picture *ref, int mb_y)
{
int ref_field = ref->reference - 1;
int ref_field_picture = ref->field_picture;
int ref_height = 16*h->s.mb_height >> ref_field_picture;
if(!HAVE_PTHREADS || !(h->s.avctx->active_thread_type&FF_THREAD_FRAME))
return;
//FIXME it can be safe to access mb stuff
//even if pixels aren't deblocked yet
ff_thread_await_progress((AVFrame*)ref, FFMIN(16*mb_y >> ref_field_picture, ref_height-1),
ref_field_picture && ref_field);
}
static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){ static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){
MpegEncContext * const s = &h->s; MpegEncContext * const s = &h->s;
int b8_stride = 2; int b8_stride = 2;
int b4_stride = h->b_stride; int b4_stride = h->b_stride;
int mb_xy = h->mb_xy; int mb_xy = h->mb_xy, mb_y = s->mb_y;
int mb_type_col[2]; int mb_type_col[2];
const int16_t (*l1mv0)[2], (*l1mv1)[2]; const int16_t (*l1mv0)[2], (*l1mv1)[2];
const int8_t *l1ref0, *l1ref1; const int8_t *l1ref0, *l1ref1;
...@@ -157,6 +174,8 @@ static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){ ...@@ -157,6 +174,8 @@ static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){
assert(h->ref_list[1][0].reference&3); assert(h->ref_list[1][0].reference&3);
await_reference_mb_row(h, &h->ref_list[1][0], s->mb_y + !!IS_INTERLACED(*mb_type));
#define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16|MB_TYPE_INTRA4x4|MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM) #define MB_TYPE_16x16_OR_INTRA (MB_TYPE_16x16|MB_TYPE_INTRA4x4|MB_TYPE_INTRA16x16|MB_TYPE_INTRA_PCM)
...@@ -217,14 +236,17 @@ static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){ ...@@ -217,14 +236,17 @@ static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){
if(IS_INTERLACED(h->ref_list[1][0].mb_type[mb_xy])){ // AFL/AFR/FR/FL -> AFL/FL if(IS_INTERLACED(h->ref_list[1][0].mb_type[mb_xy])){ // AFL/AFR/FR/FL -> AFL/FL
if(!IS_INTERLACED(*mb_type)){ // AFR/FR -> AFL/FL if(!IS_INTERLACED(*mb_type)){ // AFR/FR -> AFL/FL
mb_y = (s->mb_y&~1) + h->col_parity;
mb_xy= s->mb_x + ((s->mb_y&~1) + h->col_parity)*s->mb_stride; mb_xy= s->mb_x + ((s->mb_y&~1) + h->col_parity)*s->mb_stride;
b8_stride = 0; b8_stride = 0;
}else{ }else{
mb_xy += h->col_fieldoff; // non zero for FL -> FL & differ parity mb_y += h->col_fieldoff;
mb_xy += s->mb_stride*h->col_fieldoff; // non zero for FL -> FL & differ parity
} }
goto single_col; goto single_col;
}else{ // AFL/AFR/FR/FL -> AFR/FR }else{ // AFL/AFR/FR/FL -> AFR/FR
if(IS_INTERLACED(*mb_type)){ // AFL /FL -> AFR/FR if(IS_INTERLACED(*mb_type)){ // AFL /FL -> AFR/FR
mb_y = s->mb_y&~1;
mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride; mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride;
mb_type_col[0] = h->ref_list[1][0].mb_type[mb_xy]; mb_type_col[0] = h->ref_list[1][0].mb_type[mb_xy];
mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy + s->mb_stride]; mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy + s->mb_stride];
...@@ -260,6 +282,8 @@ single_col: ...@@ -260,6 +282,8 @@ single_col:
} }
} }
await_reference_mb_row(h, &h->ref_list[1][0], mb_y);
l1mv0 = &h->ref_list[1][0].motion_val[0][h->mb2b_xy [mb_xy]]; l1mv0 = &h->ref_list[1][0].motion_val[0][h->mb2b_xy [mb_xy]];
l1mv1 = &h->ref_list[1][0].motion_val[1][h->mb2b_xy [mb_xy]]; l1mv1 = &h->ref_list[1][0].motion_val[1][h->mb2b_xy [mb_xy]];
l1ref0 = &h->ref_list[1][0].ref_index [0][4*mb_xy]; l1ref0 = &h->ref_list[1][0].ref_index [0][4*mb_xy];
...@@ -384,7 +408,7 @@ static void pred_temp_direct_motion(H264Context * const h, int *mb_type){ ...@@ -384,7 +408,7 @@ static void pred_temp_direct_motion(H264Context * const h, int *mb_type){
MpegEncContext * const s = &h->s; MpegEncContext * const s = &h->s;
int b8_stride = 2; int b8_stride = 2;
int b4_stride = h->b_stride; int b4_stride = h->b_stride;
int mb_xy = h->mb_xy; int mb_xy = h->mb_xy, mb_y = s->mb_y;
int mb_type_col[2]; int mb_type_col[2];
const int16_t (*l1mv0)[2], (*l1mv1)[2]; const int16_t (*l1mv0)[2], (*l1mv1)[2];
const int8_t *l1ref0, *l1ref1; const int8_t *l1ref0, *l1ref1;
...@@ -394,16 +418,21 @@ static void pred_temp_direct_motion(H264Context * const h, int *mb_type){ ...@@ -394,16 +418,21 @@ static void pred_temp_direct_motion(H264Context * const h, int *mb_type){
assert(h->ref_list[1][0].reference&3); assert(h->ref_list[1][0].reference&3);
await_reference_mb_row(h, &h->ref_list[1][0], s->mb_y + !!IS_INTERLACED(*mb_type));
if(IS_INTERLACED(h->ref_list[1][0].mb_type[mb_xy])){ // AFL/AFR/FR/FL -> AFL/FL if(IS_INTERLACED(h->ref_list[1][0].mb_type[mb_xy])){ // AFL/AFR/FR/FL -> AFL/FL
if(!IS_INTERLACED(*mb_type)){ // AFR/FR -> AFL/FL if(!IS_INTERLACED(*mb_type)){ // AFR/FR -> AFL/FL
mb_y = (s->mb_y&~1) + h->col_parity;
mb_xy= s->mb_x + ((s->mb_y&~1) + h->col_parity)*s->mb_stride; mb_xy= s->mb_x + ((s->mb_y&~1) + h->col_parity)*s->mb_stride;
b8_stride = 0; b8_stride = 0;
}else{ }else{
mb_xy += h->col_fieldoff; // non zero for FL -> FL & differ parity mb_y += h->col_fieldoff;
mb_xy += s->mb_stride*h->col_fieldoff; // non zero for FL -> FL & differ parity
} }
goto single_col; goto single_col;
}else{ // AFL/AFR/FR/FL -> AFR/FR }else{ // AFL/AFR/FR/FL -> AFR/FR
if(IS_INTERLACED(*mb_type)){ // AFL /FL -> AFR/FR if(IS_INTERLACED(*mb_type)){ // AFL /FL -> AFR/FR
mb_y = s->mb_y&~1;
mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride; mb_xy= s->mb_x + (s->mb_y&~1)*s->mb_stride;
mb_type_col[0] = h->ref_list[1][0].mb_type[mb_xy]; mb_type_col[0] = h->ref_list[1][0].mb_type[mb_xy];
mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy + s->mb_stride]; mb_type_col[1] = h->ref_list[1][0].mb_type[mb_xy + s->mb_stride];
...@@ -440,6 +469,8 @@ single_col: ...@@ -440,6 +469,8 @@ single_col:
} }
} }
await_reference_mb_row(h, &h->ref_list[1][0], mb_y);
l1mv0 = &h->ref_list[1][0].motion_val[0][h->mb2b_xy [mb_xy]]; l1mv0 = &h->ref_list[1][0].motion_val[0][h->mb2b_xy [mb_xy]];
l1mv1 = &h->ref_list[1][0].motion_val[1][h->mb2b_xy [mb_xy]]; l1mv1 = &h->ref_list[1][0].motion_val[1][h->mb2b_xy [mb_xy]];
l1ref0 = &h->ref_list[1][0].ref_index [0][4*mb_xy]; l1ref0 = &h->ref_list[1][0].ref_index [0][4*mb_xy];
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "dsputil.h" #include "dsputil.h"
#include "mpegvideo.h" #include "mpegvideo.h"
#include "mpeg12.h" #include "mpeg12.h"
#include "thread.h"
typedef struct MDECContext{ typedef struct MDECContext{
AVCodecContext *avctx; AVCodecContext *avctx;
...@@ -162,10 +163,10 @@ static int decode_frame(AVCodecContext *avctx, ...@@ -162,10 +163,10 @@ static int decode_frame(AVCodecContext *avctx,
int i; int i;
if(p->data[0]) if(p->data[0])
avctx->release_buffer(avctx, p); ff_thread_release_buffer(avctx, p);
p->reference= 0; p->reference= 0;
if(avctx->get_buffer(avctx, p) < 0){ if(ff_thread_get_buffer(avctx, p) < 0){
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return -1; return -1;
} }
...@@ -238,6 +239,18 @@ static av_cold int decode_init(AVCodecContext *avctx){ ...@@ -238,6 +239,18 @@ static av_cold int decode_init(AVCodecContext *avctx){
return 0; return 0;
} }
static av_cold int decode_init_thread_copy(AVCodecContext *avctx){
MDECContext * const a = avctx->priv_data;
AVFrame *p = (AVFrame*)&a->picture;
avctx->coded_frame= p;
a->avctx= avctx;
p->qscale_table= av_mallocz( p->qstride * a->mb_height);
return 0;
}
static av_cold int decode_end(AVCodecContext *avctx){ static av_cold int decode_end(AVCodecContext *avctx){
MDECContext * const a = avctx->priv_data; MDECContext * const a = avctx->priv_data;
...@@ -259,7 +272,8 @@ AVCodec ff_mdec_decoder = { ...@@ -259,7 +272,8 @@ AVCodec ff_mdec_decoder = {
NULL, NULL,
decode_end, decode_end,
decode_frame, decode_frame,
CODEC_CAP_DR1, CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS,
.long_name= NULL_IF_CONFIG_SMALL("Sony PlayStation MDEC (Motion DECoder)"), .long_name= NULL_IF_CONFIG_SMALL("Sony PlayStation MDEC (Motion DECoder)"),
.init_thread_copy= ONLY_IF_THREADS_ENABLED(decode_init_thread_copy)
}; };
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#include "get_bits.h" #include "get_bits.h"
#include "bytestream.h" #include "bytestream.h"
#include "dsputil.h" #include "dsputil.h"
#include "thread.h"
#define MIMIC_HEADER_SIZE 20 #define MIMIC_HEADER_SIZE 20
...@@ -51,6 +52,10 @@ typedef struct { ...@@ -51,6 +52,10 @@ typedef struct {
ScanTable scantable; ScanTable scantable;
DSPContext dsp; DSPContext dsp;
VLC vlc; VLC vlc;
/* Kept in the context so multithreading can have a constant to read from */
int next_cur_index;
int next_prev_index;
} MimicContext; } MimicContext;
static const uint32_t huffcodes[] = { static const uint32_t huffcodes[] = {
...@@ -121,6 +126,23 @@ static av_cold int mimic_decode_init(AVCodecContext *avctx) ...@@ -121,6 +126,23 @@ static av_cold int mimic_decode_init(AVCodecContext *avctx)
return 0; return 0;
} }
static int mimic_decode_update_thread_context(AVCodecContext *avctx, const AVCodecContext *avctx_from)
{
MimicContext *dst = avctx->priv_data, *src = avctx_from->priv_data;
if (avctx == avctx_from) return 0;
dst->cur_index = src->next_cur_index;
dst->prev_index = src->next_prev_index;
memcpy(dst->buf_ptrs, src->buf_ptrs, sizeof(src->buf_ptrs));
memcpy(dst->flipped_ptrs, src->flipped_ptrs, sizeof(src->flipped_ptrs));
memset(&dst->buf_ptrs[dst->cur_index], 0, sizeof(AVFrame));
return 0;
}
static const int8_t vlcdec_lookup[9][64] = { static const int8_t vlcdec_lookup[9][64] = {
{ 0, }, { 0, },
{ -1, 1, }, { -1, 1, },
...@@ -205,7 +227,7 @@ static int vlc_decode_block(MimicContext *ctx, int num_coeffs, int qscale) ...@@ -205,7 +227,7 @@ static int vlc_decode_block(MimicContext *ctx, int num_coeffs, int qscale)
static int decode(MimicContext *ctx, int quality, int num_coeffs, static int decode(MimicContext *ctx, int quality, int num_coeffs,
int is_iframe) int is_iframe)
{ {
int y, x, plane; int y, x, plane, cur_row = 0;
for(plane = 0; plane < 3; plane++) { for(plane = 0; plane < 3; plane++) {
const int is_chroma = !!plane; const int is_chroma = !!plane;
...@@ -236,6 +258,7 @@ static int decode(MimicContext *ctx, int quality, int num_coeffs, ...@@ -236,6 +258,7 @@ static int decode(MimicContext *ctx, int quality, int num_coeffs,
int index = (ctx->cur_index+backref)&15; int index = (ctx->cur_index+backref)&15;
uint8_t *p = ctx->flipped_ptrs[index].data[0]; uint8_t *p = ctx->flipped_ptrs[index].data[0];
ff_thread_await_progress(&ctx->buf_ptrs[index], cur_row, 0);
if(p) { if(p) {
p += src - p += src -
ctx->flipped_ptrs[ctx->prev_index].data[plane]; ctx->flipped_ptrs[ctx->prev_index].data[plane];
...@@ -246,6 +269,7 @@ static int decode(MimicContext *ctx, int quality, int num_coeffs, ...@@ -246,6 +269,7 @@ static int decode(MimicContext *ctx, int quality, int num_coeffs,
} }
} }
} else { } else {
ff_thread_await_progress(&ctx->buf_ptrs[ctx->prev_index], cur_row, 0);
ctx->dsp.put_pixels_tab[1][0](dst, src, stride, 8); ctx->dsp.put_pixels_tab[1][0](dst, src, stride, 8);
} }
src += 8; src += 8;
...@@ -253,6 +277,8 @@ static int decode(MimicContext *ctx, int quality, int num_coeffs, ...@@ -253,6 +277,8 @@ static int decode(MimicContext *ctx, int quality, int num_coeffs,
} }
src += (stride - ctx->num_hblocks[plane])<<3; src += (stride - ctx->num_hblocks[plane])<<3;
dst += (stride - ctx->num_hblocks[plane])<<3; dst += (stride - ctx->num_hblocks[plane])<<3;
ff_thread_report_progress(&ctx->buf_ptrs[ctx->cur_index], cur_row++, 0);
} }
} }
...@@ -326,14 +352,20 @@ static int mimic_decode_frame(AVCodecContext *avctx, void *data, ...@@ -326,14 +352,20 @@ static int mimic_decode_frame(AVCodecContext *avctx, void *data,
} }
ctx->buf_ptrs[ctx->cur_index].reference = 1; ctx->buf_ptrs[ctx->cur_index].reference = 1;
if(avctx->get_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index])) { ctx->buf_ptrs[ctx->cur_index].pict_type = is_pframe ? FF_P_TYPE:FF_I_TYPE;
if(ff_thread_get_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index])) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return -1; return -1;
} }
ctx->next_prev_index = ctx->cur_index;
ctx->next_cur_index = (ctx->cur_index - 1) & 15;
prepare_avpic(ctx, &ctx->flipped_ptrs[ctx->cur_index], prepare_avpic(ctx, &ctx->flipped_ptrs[ctx->cur_index],
(AVPicture*) &ctx->buf_ptrs[ctx->cur_index]); (AVPicture*) &ctx->buf_ptrs[ctx->cur_index]);
ff_thread_finish_setup(avctx);
av_fast_malloc(&ctx->swap_buf, &ctx->swap_buf_size, av_fast_malloc(&ctx->swap_buf, &ctx->swap_buf_size,
swap_buf_size + FF_INPUT_BUFFER_PADDING_SIZE); swap_buf_size + FF_INPUT_BUFFER_PADDING_SIZE);
if(!ctx->swap_buf) if(!ctx->swap_buf)
...@@ -345,21 +377,23 @@ static int mimic_decode_frame(AVCodecContext *avctx, void *data, ...@@ -345,21 +377,23 @@ static int mimic_decode_frame(AVCodecContext *avctx, void *data,
init_get_bits(&ctx->gb, ctx->swap_buf, swap_buf_size << 3); init_get_bits(&ctx->gb, ctx->swap_buf, swap_buf_size << 3);
if(!decode(ctx, quality, num_coeffs, !is_pframe)) { if(!decode(ctx, quality, num_coeffs, !is_pframe)) {
avctx->release_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index]); if (avctx->active_thread_type&FF_THREAD_FRAME)
return -1; ff_thread_report_progress(&ctx->buf_ptrs[ctx->cur_index], INT_MAX, 0);
else {
ff_thread_release_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index]);
return -1;
}
} }
ctx->buf_ptrs[ctx->cur_index].pict_type = is_pframe ? FF_P_TYPE:FF_I_TYPE;
*(AVFrame*)data = ctx->buf_ptrs[ctx->cur_index]; *(AVFrame*)data = ctx->buf_ptrs[ctx->cur_index];
*data_size = sizeof(AVFrame); *data_size = sizeof(AVFrame);
ctx->prev_index = ctx->cur_index; ctx->prev_index = ctx->next_prev_index;
ctx->cur_index--; ctx->cur_index = ctx->next_cur_index;
ctx->cur_index &= 15;
/* Only release frames that aren't used for backreferences anymore */ /* Only release frames that aren't used for backreferences anymore */
if(ctx->buf_ptrs[ctx->cur_index].data[0]) if(ctx->buf_ptrs[ctx->cur_index].data[0])
avctx->release_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index]); ff_thread_release_buffer(avctx, &ctx->buf_ptrs[ctx->cur_index]);
return buf_size; return buf_size;
} }
...@@ -370,9 +404,12 @@ static av_cold int mimic_decode_end(AVCodecContext *avctx) ...@@ -370,9 +404,12 @@ static av_cold int mimic_decode_end(AVCodecContext *avctx)
int i; int i;
av_free(ctx->swap_buf); av_free(ctx->swap_buf);
if(avctx->is_copy) return 0;
for(i = 0; i < 16; i++) for(i = 0; i < 16; i++)
if(ctx->buf_ptrs[i].data[0]) if(ctx->buf_ptrs[i].data[0])
avctx->release_buffer(avctx, &ctx->buf_ptrs[i]); ff_thread_release_buffer(avctx, &ctx->buf_ptrs[i]);
free_vlc(&ctx->vlc); free_vlc(&ctx->vlc);
return 0; return 0;
...@@ -387,6 +424,7 @@ AVCodec ff_mimic_decoder = { ...@@ -387,6 +424,7 @@ AVCodec ff_mimic_decoder = {
NULL, NULL,
mimic_decode_end, mimic_decode_end,
mimic_decode_frame, mimic_decode_frame,
CODEC_CAP_DR1, CODEC_CAP_DR1 | CODEC_CAP_FRAME_THREADS,
.long_name = NULL_IF_CONFIG_SMALL("Mimic"), .long_name = NULL_IF_CONFIG_SMALL("Mimic"),
.update_thread_context = ONLY_IF_THREADS_ENABLED(mimic_decode_update_thread_context)
}; };
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "bytestream.h" #include "bytestream.h"
#include "vdpau_internal.h" #include "vdpau_internal.h"
#include "xvmc_internal.h" #include "xvmc_internal.h"
#include "thread.h"
//#undef NDEBUG //#undef NDEBUG
//#include <assert.h> //#include <assert.h>
...@@ -1179,6 +1180,27 @@ static av_cold int mpeg_decode_init(AVCodecContext *avctx) ...@@ -1179,6 +1180,27 @@ static av_cold int mpeg_decode_init(AVCodecContext *avctx)
return 0; return 0;
} }
static int mpeg_decode_update_thread_context(AVCodecContext *avctx, const AVCodecContext *avctx_from)
{
Mpeg1Context *ctx = avctx->priv_data, *ctx_from = avctx_from->priv_data;
MpegEncContext *s = &ctx->mpeg_enc_ctx, *s1 = &ctx_from->mpeg_enc_ctx;
int err;
if(avctx == avctx_from || !ctx_from->mpeg_enc_ctx_allocated || !s1->context_initialized)
return 0;
err = ff_mpeg_update_thread_context(avctx, avctx_from);
if(err) return err;
if(!ctx->mpeg_enc_ctx_allocated)
memcpy(s + 1, s1 + 1, sizeof(Mpeg1Context) - sizeof(MpegEncContext));
if(!(s->pict_type == FF_B_TYPE || s->low_delay))
s->picture_number++;
return 0;
}
static void quant_matrix_rebuild(uint16_t *matrix, const uint8_t *old_perm, static void quant_matrix_rebuild(uint16_t *matrix, const uint8_t *old_perm,
const uint8_t *new_perm){ const uint8_t *new_perm){
uint16_t temp_matrix[64]; uint16_t temp_matrix[64];
...@@ -1595,6 +1617,9 @@ static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size) ...@@ -1595,6 +1617,9 @@ static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size)
} }
*s->current_picture_ptr->pan_scan= s1->pan_scan; *s->current_picture_ptr->pan_scan= s1->pan_scan;
if (HAVE_PTHREADS && avctx->active_thread_type&FF_THREAD_FRAME)
ff_thread_finish_setup(avctx);
}else{ //second field }else{ //second field
int i; int i;
...@@ -1769,6 +1794,7 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y, ...@@ -1769,6 +1794,7 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y,
const int mb_size= 16>>s->avctx->lowres; const int mb_size= 16>>s->avctx->lowres;
ff_draw_horiz_band(s, mb_size*(s->mb_y>>field_pic), mb_size); ff_draw_horiz_band(s, mb_size*(s->mb_y>>field_pic), mb_size);
MPV_report_decode_progress(s);
s->mb_x = 0; s->mb_x = 0;
s->mb_y += 1<<field_pic; s->mb_y += 1<<field_pic;
...@@ -1924,7 +1950,8 @@ static int slice_end(AVCodecContext *avctx, AVFrame *pict) ...@@ -1924,7 +1950,8 @@ static int slice_end(AVCodecContext *avctx, AVFrame *pict)
*pict= *(AVFrame*)s->current_picture_ptr; *pict= *(AVFrame*)s->current_picture_ptr;
ff_print_debug_info(s, pict); ff_print_debug_info(s, pict);
} else { } else {
s->picture_number++; if (avctx->active_thread_type&FF_THREAD_FRAME)
s->picture_number++;
/* latency of 1 frame for I- and P-frames */ /* latency of 1 frame for I- and P-frames */
/* XXX: use another variable than picture_number */ /* XXX: use another variable than picture_number */
if (s->last_picture_ptr != NULL) { if (s->last_picture_ptr != NULL) {
...@@ -2260,7 +2287,7 @@ static int decode_chunks(AVCodecContext *avctx, ...@@ -2260,7 +2287,7 @@ static int decode_chunks(AVCodecContext *avctx,
buf_ptr = ff_find_start_code(buf_ptr,buf_end, &start_code); buf_ptr = ff_find_start_code(buf_ptr,buf_end, &start_code);
if (start_code > 0x1ff){ if (start_code > 0x1ff){
if(s2->pict_type != FF_B_TYPE || avctx->skip_frame <= AVDISCARD_DEFAULT){ if(s2->pict_type != FF_B_TYPE || avctx->skip_frame <= AVDISCARD_DEFAULT){
if(avctx->thread_count > 1){ if(HAVE_THREADS && avctx->active_thread_type&FF_THREAD_SLICE){
int i; int i;
avctx->execute(avctx, slice_decode_thread, &s2->thread_context[0], NULL, s->slice_count, sizeof(void*)); avctx->execute(avctx, slice_decode_thread, &s2->thread_context[0], NULL, s->slice_count, sizeof(void*));
...@@ -2422,7 +2449,7 @@ static int decode_chunks(AVCodecContext *avctx, ...@@ -2422,7 +2449,7 @@ static int decode_chunks(AVCodecContext *avctx,
break; break;
} }
if(avctx->thread_count > 1){ if(HAVE_THREADS && avctx->active_thread_type&FF_THREAD_SLICE){
int threshold= (s2->mb_height*s->slice_count + avctx->thread_count/2) / avctx->thread_count; int threshold= (s2->mb_height*s->slice_count + avctx->thread_count/2) / avctx->thread_count;
if(threshold <= mb_y){ if(threshold <= mb_y){
MpegEncContext *thread_context= s2->thread_context[s->slice_count]; MpegEncContext *thread_context= s2->thread_context[s->slice_count];
...@@ -2496,6 +2523,7 @@ AVCodec ff_mpeg1video_decoder = { ...@@ -2496,6 +2523,7 @@ AVCodec ff_mpeg1video_decoder = {
.flush= flush, .flush= flush,
.max_lowres= 3, .max_lowres= 3,
.long_name= NULL_IF_CONFIG_SMALL("MPEG-1 video"), .long_name= NULL_IF_CONFIG_SMALL("MPEG-1 video"),
.update_thread_context= ONLY_IF_THREADS_ENABLED(mpeg_decode_update_thread_context)
}; };
AVCodec ff_mpeg2video_decoder = { AVCodec ff_mpeg2video_decoder = {
...@@ -2532,7 +2560,7 @@ AVCodec ff_mpegvideo_decoder = { ...@@ -2532,7 +2560,7 @@ AVCodec ff_mpegvideo_decoder = {
#if CONFIG_MPEG_XVMC_DECODER #if CONFIG_MPEG_XVMC_DECODER
static av_cold int mpeg_mc_decode_init(AVCodecContext *avctx){ static av_cold int mpeg_mc_decode_init(AVCodecContext *avctx){
if( avctx->thread_count > 1) if( avctx->active_thread_type & FF_THREAD_SLICE )
return -1; return -1;
if( !(avctx->slice_flags & SLICE_FLAG_CODED_ORDER) ) if( !(avctx->slice_flags & SLICE_FLAG_CODED_ORDER) )
return -1; return -1;
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include "mpegvideo.h" #include "mpegvideo.h"
#include "mpeg4video.h" #include "mpeg4video.h"
#include "h263.h" #include "h263.h"
#include "thread.h"
// The defines below define the number of bits that are read at once for // The defines below define the number of bits that are read at once for
// reading vlc values. Changing these may improve speed and data cache needs // reading vlc values. Changing these may improve speed and data cache needs
...@@ -373,7 +374,13 @@ int mpeg4_decode_video_packet_header(MpegEncContext *s) ...@@ -373,7 +374,13 @@ int mpeg4_decode_video_packet_header(MpegEncContext *s)
return -1; return -1;
} }
if(s->pict_type == FF_B_TYPE){ if(s->pict_type == FF_B_TYPE){
while(s->next_picture.mbskip_table[ s->mb_index2xy[ mb_num ] ]) mb_num++; int mb_x = 0, mb_y = 0;
while(s->next_picture.mbskip_table[ s->mb_index2xy[ mb_num ] ]) {
if (!mb_x) ff_thread_await_progress((AVFrame*)s->next_picture_ptr, mb_y++, 0);
mb_num++;
if (++mb_x == s->mb_width) mb_x = 0;
}
if(mb_num >= s->mb_num) return -1; // slice contains just skipped MBs which where already decoded if(mb_num >= s->mb_num) return -1; // slice contains just skipped MBs which where already decoded
} }
...@@ -1303,6 +1310,8 @@ static int mpeg4_decode_mb(MpegEncContext *s, ...@@ -1303,6 +1310,8 @@ static int mpeg4_decode_mb(MpegEncContext *s,
s->last_mv[i][1][0]= s->last_mv[i][1][0]=
s->last_mv[i][1][1]= 0; s->last_mv[i][1][1]= 0;
} }
ff_thread_await_progress((AVFrame*)s->next_picture_ptr, s->mb_y, 0);
} }
/* if we skipped it in the future P Frame than skip it now too */ /* if we skipped it in the future P Frame than skip it now too */
...@@ -1482,6 +1491,12 @@ end: ...@@ -1482,6 +1491,12 @@ end:
if(s->codec_id==CODEC_ID_MPEG4){ if(s->codec_id==CODEC_ID_MPEG4){
if(mpeg4_is_resync(s)){ if(mpeg4_is_resync(s)){
const int delta= s->mb_x + 1 == s->mb_width ? 2 : 1; const int delta= s->mb_x + 1 == s->mb_width ? 2 : 1;
if(s->pict_type==FF_B_TYPE){
ff_thread_await_progress((AVFrame*)s->next_picture_ptr,
(s->mb_x + delta >= s->mb_width) ? FFMIN(s->mb_y+1, s->mb_height-1) : s->mb_y, 0);
}
if(s->pict_type==FF_B_TYPE && s->next_picture.mbskip_table[xy + delta]) if(s->pict_type==FF_B_TYPE && s->next_picture.mbskip_table[xy + delta])
return SLICE_OK; return SLICE_OK;
return SLICE_END; return SLICE_END;
...@@ -2239,11 +2254,12 @@ AVCodec ff_mpeg4_decoder = { ...@@ -2239,11 +2254,12 @@ AVCodec ff_mpeg4_decoder = {
NULL, NULL,
ff_h263_decode_end, ff_h263_decode_end,
ff_h263_decode_frame, ff_h263_decode_frame,
CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY, CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_FRAME_THREADS,
.flush= ff_mpeg_flush, .flush= ff_mpeg_flush,
.max_lowres= 3, .max_lowres= 3,
.long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2"), .long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2"),
.pix_fmts= ff_hwaccel_pixfmt_list_420, .pix_fmts= ff_hwaccel_pixfmt_list_420,
.update_thread_context= ONLY_IF_THREADS_ENABLED(ff_mpeg_update_thread_context)
}; };
......
This diff is collapsed.
...@@ -123,6 +123,7 @@ typedef struct Picture{ ...@@ -123,6 +123,7 @@ typedef struct Picture{
int ref_poc[2][2][16]; ///< h264 POCs of the frames used as reference (FIXME need per slice) int ref_poc[2][2][16]; ///< h264 POCs of the frames used as reference (FIXME need per slice)
int ref_count[2][2]; ///< number of entries in ref_poc (FIXME need per slice) int ref_count[2][2]; ///< number of entries in ref_poc (FIXME need per slice)
int mbaff; ///< h264 1 -> MBAFF frame 0-> not MBAFF int mbaff; ///< h264 1 -> MBAFF frame 0-> not MBAFF
int field_picture; ///< whether or not the picture was encoded in seperate fields
int mb_var_sum; ///< sum of MB variance for current frame int mb_var_sum; ///< sum of MB variance for current frame
int mc_mb_var_sum; ///< motion compensated MB variance for current frame int mc_mb_var_sum; ///< motion compensated MB variance for current frame
...@@ -292,6 +293,8 @@ typedef struct MpegEncContext { ...@@ -292,6 +293,8 @@ typedef struct MpegEncContext {
Picture *last_picture_ptr; ///< pointer to the previous picture. Picture *last_picture_ptr; ///< pointer to the previous picture.
Picture *next_picture_ptr; ///< pointer to the next picture (for bidir pred) Picture *next_picture_ptr; ///< pointer to the next picture (for bidir pred)
Picture *current_picture_ptr; ///< pointer to the current picture Picture *current_picture_ptr; ///< pointer to the current picture
int picture_count; ///< number of allocated pictures (MAX_PICTURE_COUNT * avctx->thread_count)
int picture_range_start, picture_range_end; ///< the part of picture that this context can allocate in
uint8_t *visualization_buffer[3]; //< temporary buffer vor MV visualization uint8_t *visualization_buffer[3]; //< temporary buffer vor MV visualization
int last_dc[3]; ///< last DC values for MPEG1 int last_dc[3]; ///< last DC values for MPEG1
int16_t *dc_val_base; int16_t *dc_val_base;
...@@ -681,6 +684,7 @@ typedef struct MpegEncContext { ...@@ -681,6 +684,7 @@ typedef struct MpegEncContext {
void (*denoise_dct)(struct MpegEncContext *s, DCTELEM *block); void (*denoise_dct)(struct MpegEncContext *s, DCTELEM *block);
} MpegEncContext; } MpegEncContext;
#define REBASE_PICTURE(pic, new_ctx, old_ctx) (pic ? &new_ctx->picture[pic - old_ctx->picture] : NULL)
void MPV_decode_defaults(MpegEncContext *s); void MPV_decode_defaults(MpegEncContext *s);
int MPV_common_init(MpegEncContext *s); int MPV_common_init(MpegEncContext *s);
...@@ -706,6 +710,9 @@ void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix); ...@@ -706,6 +710,9 @@ void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix);
int ff_find_unused_picture(MpegEncContext *s, int shared); int ff_find_unused_picture(MpegEncContext *s, int shared);
void ff_denoise_dct(MpegEncContext *s, DCTELEM *block); void ff_denoise_dct(MpegEncContext *s, DCTELEM *block);
void ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src); void ff_update_duplicate_context(MpegEncContext *dst, MpegEncContext *src);
int MPV_lowest_referenced_row(MpegEncContext *s, int dir);
void MPV_report_decode_progress(MpegEncContext *s);
int ff_mpeg_update_thread_context(AVCodecContext *dst, const AVCodecContext *src);
const uint8_t *ff_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state); const uint8_t *ff_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state);
void ff_set_qscale(MpegEncContext * s, int qscale); void ff_set_qscale(MpegEncContext * s, int qscale);
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "mjpegenc.h" #include "mjpegenc.h"
#include "msmpeg4.h" #include "msmpeg4.h"
#include "faandct.h" #include "faandct.h"
#include "thread.h"
#include "aandcttab.h" #include "aandcttab.h"
#include "flv.h" #include "flv.h"
#include "mpeg4video.h" #include "mpeg4video.h"
...@@ -1238,9 +1239,9 @@ int MPV_encode_picture(AVCodecContext *avctx, ...@@ -1238,9 +1239,9 @@ int MPV_encode_picture(AVCodecContext *avctx,
{ {
MpegEncContext *s = avctx->priv_data; MpegEncContext *s = avctx->priv_data;
AVFrame *pic_arg = data; AVFrame *pic_arg = data;
int i, stuffing_count; int i, stuffing_count, context_count = avctx->active_thread_type&FF_THREAD_SLICE ? avctx->thread_count : 1;
for(i=0; i<avctx->thread_count; i++){ for(i=0; i<context_count; i++){
int start_y= s->thread_context[i]->start_mb_y; int start_y= s->thread_context[i]->start_mb_y;
int end_y= s->thread_context[i]-> end_mb_y; int end_y= s->thread_context[i]-> end_mb_y;
int h= s->mb_height; int h= s->mb_height;
...@@ -1304,7 +1305,7 @@ vbv_retry: ...@@ -1304,7 +1305,7 @@ vbv_retry:
s->last_non_b_time= s->time - s->pp_time; s->last_non_b_time= s->time - s->pp_time;
} }
// av_log(NULL, AV_LOG_ERROR, "R:%d ", s->next_lambda); // av_log(NULL, AV_LOG_ERROR, "R:%d ", s->next_lambda);
for(i=0; i<avctx->thread_count; i++){ for(i=0; i<context_count; i++){
PutBitContext *pb= &s->thread_context[i]->pb; PutBitContext *pb= &s->thread_context[i]->pb;
init_put_bits(pb, pb->buf, pb->buf_end - pb->buf); init_put_bits(pb, pb->buf, pb->buf_end - pb->buf);
} }
...@@ -2771,6 +2772,7 @@ static int encode_picture(MpegEncContext *s, int picture_number) ...@@ -2771,6 +2772,7 @@ static int encode_picture(MpegEncContext *s, int picture_number)
{ {
int i; int i;
int bits; int bits;
int context_count = s->avctx->active_thread_type&FF_THREAD_SLICE ? s->avctx->thread_count : 1;
s->picture_number = picture_number; s->picture_number = picture_number;
...@@ -2810,7 +2812,7 @@ static int encode_picture(MpegEncContext *s, int picture_number) ...@@ -2810,7 +2812,7 @@ static int encode_picture(MpegEncContext *s, int picture_number)
} }
s->mb_intra=0; //for the rate distortion & bit compare functions s->mb_intra=0; //for the rate distortion & bit compare functions
for(i=1; i<s->avctx->thread_count; i++){ for(i=1; i<context_count; i++){
ff_update_duplicate_context(s->thread_context[i], s); ff_update_duplicate_context(s->thread_context[i], s);
} }
...@@ -2823,11 +2825,11 @@ static int encode_picture(MpegEncContext *s, int picture_number) ...@@ -2823,11 +2825,11 @@ static int encode_picture(MpegEncContext *s, int picture_number)
s->lambda2= (s->lambda2* (int64_t)s->avctx->me_penalty_compensation + 128)>>8; 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->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){ 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, &s->thread_context[0], NULL, s->avctx->thread_count, sizeof(void*)); s->avctx->execute(s->avctx, pre_estimate_motion_thread, &s->thread_context[0], NULL, context_count, sizeof(void*));
} }
} }
s->avctx->execute(s->avctx, estimate_motion_thread, &s->thread_context[0], NULL, s->avctx->thread_count, sizeof(void*)); s->avctx->execute(s->avctx, estimate_motion_thread, &s->thread_context[0], NULL, context_count, sizeof(void*));
}else /* if(s->pict_type == FF_I_TYPE) */{ }else /* if(s->pict_type == FF_I_TYPE) */{
/* I-Frame */ /* I-Frame */
for(i=0; i<s->mb_stride*s->mb_height; i++) for(i=0; i<s->mb_stride*s->mb_height; i++)
...@@ -2835,10 +2837,10 @@ static int encode_picture(MpegEncContext *s, int picture_number) ...@@ -2835,10 +2837,10 @@ static int encode_picture(MpegEncContext *s, int picture_number)
if(!s->fixed_qscale){ if(!s->fixed_qscale){
/* finding spatial complexity for I-frame rate control */ /* finding spatial complexity for I-frame rate control */
s->avctx->execute(s->avctx, mb_var_thread, &s->thread_context[0], NULL, s->avctx->thread_count, sizeof(void*)); s->avctx->execute(s->avctx, mb_var_thread, &s->thread_context[0], NULL, context_count, sizeof(void*));
} }
} }
for(i=1; i<s->avctx->thread_count; i++){ for(i=1; i<context_count; i++){
merge_context_after_me(s, s->thread_context[i]); merge_context_after_me(s, s->thread_context[i]);
} }
s->current_picture.mc_mb_var_sum= s->current_picture_ptr->mc_mb_var_sum= s->me.mc_mb_var_sum_temp; s->current_picture.mc_mb_var_sum= s->current_picture_ptr->mc_mb_var_sum= s->me.mc_mb_var_sum_temp;
...@@ -2974,11 +2976,11 @@ static int encode_picture(MpegEncContext *s, int picture_number) ...@@ -2974,11 +2976,11 @@ static int encode_picture(MpegEncContext *s, int picture_number)
bits= put_bits_count(&s->pb); bits= put_bits_count(&s->pb);
s->header_bits= bits - s->last_bits; s->header_bits= bits - s->last_bits;
for(i=1; i<s->avctx->thread_count; i++){ for(i=1; i<context_count; i++){
update_duplicate_context_after_me(s->thread_context[i], s); update_duplicate_context_after_me(s->thread_context[i], s);
} }
s->avctx->execute(s->avctx, encode_thread, &s->thread_context[0], NULL, s->avctx->thread_count, sizeof(void*)); s->avctx->execute(s->avctx, encode_thread, &s->thread_context[0], NULL, context_count, sizeof(void*));
for(i=1; i<s->avctx->thread_count; i++){ for(i=1; i<context_count; i++){
merge_context_after_encode(s, s->thread_context[i]); merge_context_after_encode(s, s->thread_context[i]);
} }
emms_c(); emms_c();
......
...@@ -1976,9 +1976,9 @@ static int frame_start(SnowContext *s){ ...@@ -1976,9 +1976,9 @@ static int frame_start(SnowContext *s){
int h= s->avctx->height; int h= s->avctx->height;
if(s->current_picture.data[0]){ if(s->current_picture.data[0]){
s->dsp.draw_edges(s->current_picture.data[0], s->current_picture.linesize[0], w , h , EDGE_WIDTH ); s->dsp.draw_edges(s->current_picture.data[0], s->current_picture.linesize[0], w , h , EDGE_WIDTH , EDGE_TOP|EDGE_BOTTOM);
s->dsp.draw_edges(s->current_picture.data[1], s->current_picture.linesize[1], w>>1, h>>1, EDGE_WIDTH/2); s->dsp.draw_edges(s->current_picture.data[1], s->current_picture.linesize[1], w>>1, h>>1, EDGE_WIDTH/2, EDGE_TOP|EDGE_BOTTOM);
s->dsp.draw_edges(s->current_picture.data[2], s->current_picture.linesize[2], w>>1, h>>1, EDGE_WIDTH/2); s->dsp.draw_edges(s->current_picture.data[2], s->current_picture.linesize[2], w>>1, h>>1, EDGE_WIDTH/2, EDGE_TOP|EDGE_BOTTOM);
} }
release_buffer(s->avctx); release_buffer(s->avctx);
......
...@@ -366,6 +366,7 @@ void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){ ...@@ -366,6 +366,7 @@ void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
assert(pic->type==FF_BUFFER_TYPE_INTERNAL); assert(pic->type==FF_BUFFER_TYPE_INTERNAL);
assert(s->internal_buffer_count); assert(s->internal_buffer_count);
if(s->internal_buffer){
buf = NULL; /* avoids warning */ buf = NULL; /* avoids warning */
for(i=0; i<s->internal_buffer_count; i++){ //just 3-5 checks so is not worth to optimize for(i=0; i<s->internal_buffer_count; i++){ //just 3-5 checks so is not worth to optimize
buf= &((InternalBuffer*)s->internal_buffer)[i]; buf= &((InternalBuffer*)s->internal_buffer)[i];
...@@ -377,6 +378,7 @@ void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){ ...@@ -377,6 +378,7 @@ void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
last = &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count]; last = &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
FFSWAP(InternalBuffer, *buf, *last); FFSWAP(InternalBuffer, *buf, *last);
}
for(i=0; i<4; i++){ for(i=0; i<4; i++){
pic->data[i]=NULL; pic->data[i]=NULL;
...@@ -572,6 +574,7 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec) ...@@ -572,6 +574,7 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
goto free_and_end; goto free_and_end;
} }
} }
ret=0; ret=0;
end: end:
entangled_thread_counter--; entangled_thread_counter--;
...@@ -1298,9 +1301,9 @@ int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op)) ...@@ -1298,9 +1301,9 @@ int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
unsigned int ff_toupper4(unsigned int x) unsigned int ff_toupper4(unsigned int x)
{ {
return toupper( x &0xFF) return toupper( x &0xFF)
+ (toupper((x>>8 )&0xFF)<<8 ) + (toupper((x>>8 )&0xFF)<<8 )
+ (toupper((x>>16)&0xFF)<<16) + (toupper((x>>16)&0xFF)<<16)
+ (toupper((x>>24)&0xFF)<<24); + (toupper((x>>24)&0xFF)<<24);
} }
#if !HAVE_PTHREADS #if !HAVE_PTHREADS
......
...@@ -471,7 +471,7 @@ void decode_mvs(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y) ...@@ -471,7 +471,7 @@ void decode_mvs(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y)
mb - 1 /* left */, mb - 1 /* left */,
mb + 1 /* top-left */ }; mb + 1 /* top-left */ };
enum { CNT_ZERO, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV }; enum { CNT_ZERO, CNT_NEAREST, CNT_NEAR, CNT_SPLITMV };
enum { EDGE_TOP, EDGE_LEFT, EDGE_TOPLEFT }; enum { VP8_EDGE_TOP, VP8_EDGE_LEFT, VP8_EDGE_TOPLEFT };
int idx = CNT_ZERO; int idx = CNT_ZERO;
int cur_sign_bias = s->sign_bias[mb->ref_frame]; int cur_sign_bias = s->sign_bias[mb->ref_frame];
int8_t *sign_bias = s->sign_bias; int8_t *sign_bias = s->sign_bias;
...@@ -512,7 +512,7 @@ void decode_mvs(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y) ...@@ -512,7 +512,7 @@ void decode_mvs(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y)
mb->mode = VP8_MVMODE_MV; mb->mode = VP8_MVMODE_MV;
/* If we have three distinct MVs, merge first and last if they're the same */ /* If we have three distinct MVs, merge first and last if they're the same */
if (cnt[CNT_SPLITMV] && AV_RN32A(&near_mv[1+EDGE_TOP]) == AV_RN32A(&near_mv[1+EDGE_TOPLEFT])) if (cnt[CNT_SPLITMV] && AV_RN32A(&near_mv[1+VP8_EDGE_TOP]) == AV_RN32A(&near_mv[1+VP8_EDGE_TOPLEFT]))
cnt[CNT_NEAREST] += 1; cnt[CNT_NEAREST] += 1;
/* Swap near and nearest if necessary */ /* Swap near and nearest if necessary */
...@@ -526,9 +526,9 @@ void decode_mvs(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y) ...@@ -526,9 +526,9 @@ void decode_mvs(VP8Context *s, VP8Macroblock *mb, int mb_x, int mb_y)
/* Choose the best mv out of 0,0 and the nearest mv */ /* Choose the best mv out of 0,0 and the nearest mv */
clamp_mv(s, &mb->mv, &near_mv[CNT_ZERO + (cnt[CNT_NEAREST] >= cnt[CNT_ZERO])]); clamp_mv(s, &mb->mv, &near_mv[CNT_ZERO + (cnt[CNT_NEAREST] >= cnt[CNT_ZERO])]);
cnt[CNT_SPLITMV] = ((mb_edge[EDGE_LEFT]->mode == VP8_MVMODE_SPLIT) + cnt[CNT_SPLITMV] = ((mb_edge[VP8_EDGE_LEFT]->mode == VP8_MVMODE_SPLIT) +
(mb_edge[EDGE_TOP]->mode == VP8_MVMODE_SPLIT)) * 2 + (mb_edge[VP8_EDGE_TOP]->mode == VP8_MVMODE_SPLIT)) * 2 +
(mb_edge[EDGE_TOPLEFT]->mode == VP8_MVMODE_SPLIT); (mb_edge[VP8_EDGE_TOPLEFT]->mode == VP8_MVMODE_SPLIT);
if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_SPLITMV]][3])) { if (vp56_rac_get_prob_branchy(c, vp8_mode_contexts[cnt[CNT_SPLITMV]][3])) {
mb->mode = VP8_MVMODE_SPLIT; mb->mode = VP8_MVMODE_SPLIT;
......
...@@ -783,7 +783,7 @@ static void h263_h_loop_filter_mmx(uint8_t *src, int stride, int qscale){ ...@@ -783,7 +783,7 @@ static void h263_h_loop_filter_mmx(uint8_t *src, int stride, int qscale){
/* draw the edges of width 'w' of an image of size width, height /* draw the edges of width 'w' of an image of size width, height
this mmx version can only handle w==8 || w==16 */ this mmx version can only handle w==8 || w==16 */
static void draw_edges_mmx(uint8_t *buf, int wrap, int width, int height, int w) static void draw_edges_mmx(uint8_t *buf, int wrap, int width, int height, int w, int sides)
{ {
uint8_t *ptr, *last_line; uint8_t *ptr, *last_line;
int i; int i;
...@@ -838,34 +838,39 @@ static void draw_edges_mmx(uint8_t *buf, int wrap, int width, int height, int w) ...@@ -838,34 +838,39 @@ static void draw_edges_mmx(uint8_t *buf, int wrap, int width, int height, int w)
for(i=0;i<w;i+=4) { for(i=0;i<w;i+=4) {
/* top and bottom (and hopefully also the corners) */ /* top and bottom (and hopefully also the corners) */
ptr= buf - (i + 1) * wrap - w; if (sides&EDGE_TOP) {
__asm__ volatile( ptr= buf - (i + 1) * wrap - w;
"1: \n\t" __asm__ volatile(
"movq (%1, %0), %%mm0 \n\t" "1: \n\t"
"movq %%mm0, (%0) \n\t" "movq (%1, %0), %%mm0 \n\t"
"movq %%mm0, (%0, %2) \n\t" "movq %%mm0, (%0) \n\t"
"movq %%mm0, (%0, %2, 2) \n\t" "movq %%mm0, (%0, %2) \n\t"
"movq %%mm0, (%0, %3) \n\t" "movq %%mm0, (%0, %2, 2) \n\t"
"add $8, %0 \n\t" "movq %%mm0, (%0, %3) \n\t"
"cmp %4, %0 \n\t" "add $8, %0 \n\t"
" jb 1b \n\t" "cmp %4, %0 \n\t"
: "+r" (ptr) " jb 1b \n\t"
: "r" ((x86_reg)buf - (x86_reg)ptr - w), "r" ((x86_reg)-wrap), "r" ((x86_reg)-wrap*3), "r" (ptr+width+2*w) : "+r" (ptr)
); : "r" ((x86_reg)buf - (x86_reg)ptr - w), "r" ((x86_reg)-wrap), "r" ((x86_reg)-wrap*3), "r" (ptr+width+2*w)
ptr= last_line + (i + 1) * wrap - w; );
__asm__ volatile( }
"1: \n\t"
"movq (%1, %0), %%mm0 \n\t" if (sides&EDGE_BOTTOM) {
"movq %%mm0, (%0) \n\t" ptr= last_line + (i + 1) * wrap - w;
"movq %%mm0, (%0, %2) \n\t" __asm__ volatile(
"movq %%mm0, (%0, %2, 2) \n\t" "1: \n\t"
"movq %%mm0, (%0, %3) \n\t" "movq (%1, %0), %%mm0 \n\t"
"add $8, %0 \n\t" "movq %%mm0, (%0) \n\t"
"cmp %4, %0 \n\t" "movq %%mm0, (%0, %2) \n\t"
" jb 1b \n\t" "movq %%mm0, (%0, %2, 2) \n\t"
: "+r" (ptr) "movq %%mm0, (%0, %3) \n\t"
: "r" ((x86_reg)last_line - (x86_reg)ptr - w), "r" ((x86_reg)wrap), "r" ((x86_reg)wrap*3), "r" (ptr+width+2*w) "add $8, %0 \n\t"
); "cmp %4, %0 \n\t"
" jb 1b \n\t"
: "+r" (ptr)
: "r" ((x86_reg)last_line - (x86_reg)ptr - w), "r" ((x86_reg)wrap), "r" ((x86_reg)wrap*3), "r" (ptr+width+2*w)
);
}
} }
} }
......
...@@ -181,7 +181,6 @@ ...@@ -181,7 +181,6 @@
# define NULL_IF_CONFIG_SMALL(x) x # define NULL_IF_CONFIG_SMALL(x) x
#endif #endif
/** /**
* Define a function with only the non-default version specified. * Define a function with only the non-default version specified.
* *
......
#!/bin/sh -v
# args [where to put patches] [smtp server] [destination]
git format-patch -o "$1" --inline --subject-prefix=soc --thread origin
git send-email --no-chain-reply-to --smtp-server $2 --to $3 --dry-run "$1"
diff --git a/libmpcodecs/vd_ffmpeg.c b/libmpcodecs/vd_ffmpeg.c
index 7c68a20..135e6b1 100644
--- a/libmpcodecs/vd_ffmpeg.c
+++ b/libmpcodecs/vd_ffmpeg.c
@@ -280,7 +280,7 @@ static int init(sh_video_t *sh){
return 0;
}
- if(vd_use_slices && (lavc_codec->capabilities&CODEC_CAP_DRAW_HORIZ_BAND) && !do_vis_debug)
+ if(vd_use_slices && (lavc_codec->capabilities&CODEC_CAP_DRAW_HORIZ_BAND) && !do_vis_debug && lavc_param_threads <= 1)
ctx->do_slices=1;
if(lavc_codec->capabilities&CODEC_CAP_DR1 && !do_vis_debug && lavc_codec->id != CODEC_ID_H264 && lavc_codec->id != CODEC_ID_INTERPLAY_VIDEO && lavc_codec->id != CODEC_ID_ROQ && lavc_codec->id != CODEC_ID_VP8 && lavc_codec->id != CODEC_ID_LAGARITH)
#!/bin/bash
fn=`basename "$1"`
for th in 1 4; do
time ./ffmpeg_g -threads $th -skip_loop_filter all -vsync 0 -y -t 30 -i "$1" -an -f rawvideo "raw/n-$fn-$th.yuv"
done
#for th in 1 4; do
# time ./ffmpeg_g -threads $th -vsync 0 -y -t 30 -i "$1" -an -f rawvideo "raw/$fn-$th.yuv"
#done
This diff is collapsed.
#!/bin/bash
fn=`basename "$1"`
for th in 1 2 3 4; do
time ./ffmpeg_g -threads $th -flags2 +fast -vsync 0 -y -t 30 -i "$1" -an -f framecrc "crc/$fn-$th.txt" >/dev/null 2>&1
done
./ffmpeg_g -threads 1 -y -t 10 -i "$1" -an -f framecrc "crc/$fn-1-vsync.txt" >/dev/null 2>&1
./ffmpeg_g -threads 3 -y -t 10 -i "$1" -an -f framecrc "crc/$fn-3-vsync.txt" >/dev/null 2>&1
md5 "crc/$fn-"[1234].txt
echo
md5 "crc/$fn-"*vsync.txt
Todo
-- For other people
- Multithread vp8 or vc1.
- Multithread an intra codec like mjpeg.
- Fix mpeg1 (see below).
- Try the first three items under Optimization.
- Fix h264 (see below).
- Try mpeg4 (see below).
-- Bug fixes
General critical:
- Error resilience has to run before ff_report_frame_progress()
is called. Otherwise there will be race conditions. (This might already
work.) In general testing error paths should be done more.
h264:
- Files split at the wrong NAL unit don't (and can't)
be decoded with threads (e.g. TS split so PPS is after
the frame, PAFF with two fields in a packet). Scan the
packet at the start of decode and don't finish setup
until all PPS/SPS have been encountered.
mpeg4:
- Packed B-frames need to be explicitly split up
when frame threading is on. It's not very fast
without this.
- The buffer age optimization is disabled due to
the way buffers are allocated across threads. The
branch 'fix_buffer_age' has an attempt to fix it
which breaks ffplay.
- Support interlaced.
mpeg1/2:
- Seeking always prints "first frame not a keyframe"
with threads on. Currently disabled for this reason.
-- Prove correct
- decode_update_progress() in h264.c
h264_race_checking branch has some work on h264,
but not that function. It might be worth putting
the branch under #ifdef DEBUG in mainline, but
the code would have to be cleaner.
- MPV_lowest_referenced_row() and co in mpegvideo.c
- Same in vp3.
-- Optimization
- EMU_EDGE is always set for h264 PAFF+MT
because draw_edges() writes into the other field's
thread's pixels.
- Check update_thread_context() functions and make
sure they only copy what they need to.
- Try some more optimization of the "ref < 48; ref++"
loop in h264.c await_references(), try turning the list0/list1 check
above into a loop without being slower.
- Support frame+slice threading at the same time
by assigning slice_count threads for frame threads
to use with execute(). This is simpler but unbalanced
if only one frame thread uses any.
-- Features
- Support streams with width/height changing. This
requires flushing all current frames (and buffering
the input in the meantime), closing the codec and
reopening it. Or don't support it.
- Support encoding. Might need more threading primitives
for good ratecontrol; would be nice for audio and libavfilter too.
- Async decoding part 1: instead of trying to
start every thread at the beginning, return a picture
if the earliest thread is already done, but don't wait
for it. Not sure what effect this would have.
- Part 2: have an API that doesn't wait for the decoding
thread, only returns EAGAIN if it's not ready. What will
it do with the next input packet if it returns that?
- Have an API that returns finished pictures but doesn't
require sending new ones. Maybe allow NULL avpkt when
not at the end of the stream.
-- Samples
http://astrange.ithinksw.net/ffmpeg/mt-samples/
See yuvcmp.c in this directory to compare decoded samples.
For debugging, try commenting out ff_thread_finish_setup calls so
that only one thread runs at once, and then binary search+
scatter printfs to look for differences in codec contexts.
#!/bin/bash
valgrind --leak-check=full ./ffmpeg_g -threads 3 -vsync 0 -y -t 30 -i "$1" -an -f framecrc /dev/null
\ No newline at end of file
/*
* originally by Andreas Öman (andoma)
* some changes by Alexander Strange
*/
#include <string.h>
#include <stdlib.h>
#include <inttypes.h>
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
int
main(int argc, char **argv)
{
int fd[2];
int print_pixels = 0;
int dump_blocks = 0;
int width;
int height;
int to_skip = 0;
if (argc < 6) {
fprintf(stderr, "%s [YUV file 1] [YUV file 2] width height pixelcmp|blockdump (# to skip)\n", argv[0]);
return 1;
}
width = atoi(argv[3]);
height = atoi(argv[4]);
if (argc > 6)
to_skip = atoi(argv[6]);
uint8_t *Y[2], *C[2][2];
int i, v, c, p;
int lsiz = width * height;
int csiz = width * height / 4;
int x, y;
int cwidth = width / 2;
int fr = to_skip;
int mb;
char *mberrors;
int mb_x, mb_y;
uint8_t *a;
uint8_t *b;
int die = 0;
print_pixels = strstr(argv[5], "pixelcmp") ? 1 : 0;
dump_blocks = strstr(argv[5], "blockdump") ? 1 : 0;
for(i = 0; i < 2; i++) {
Y[i] = malloc(lsiz);
C[0][i] = malloc(csiz);
C[1][i] = malloc(csiz);
fd[i] = open(argv[1 + i], O_RDONLY);
if(fd[i] == -1) {
perror("open");
exit(1);
}
fcntl(fd[i], F_NOCACHE, 1);
if (to_skip)
lseek(fd[i], to_skip * (lsiz + 2*csiz), SEEK_SET);
}
mb_x = width / 16;
mb_y = height / 16;
mberrors = malloc(mb_x * mb_y);
while(!die) {
memset(mberrors, 0, mb_x * mb_y);
printf("Loading frame %d\n", ++fr);
for(i = 0; i < 2; i++) {
v = read(fd[i], Y[i], lsiz);
if(v != lsiz) {
fprintf(stderr, "Unable to read Y from file %d, exiting\n", i + 1);
return 1;
}
}
for(c = 0; c < lsiz; c++) {
if(Y[0][c] != Y[1][c]) {
x = c % width;
y = c / width;
mb = x / 16 + (y / 16) * mb_x;
if(print_pixels)
printf("Luma diff 0x%02x != 0x%02x at pixel (%4d,%-4d) mb(%d,%d) #%d\n",
Y[0][c],
Y[1][c],
x, y,
x / 16,
y / 16,
mb);
mberrors[mb] |= 1;
}
}
/* Chroma planes */
for(p = 0; p < 2; p++) {
for(i = 0; i < 2; i++) {
v = read(fd[i], C[p][i], csiz);
if(v != csiz) {
fprintf(stderr, "Unable to read %c from file %d, exiting\n",
"UV"[p], i + 1);
return 1;
}
}
for(c = 0; c < csiz; c++) {
if(C[p][0][c] != C[p][1][c]) {
x = c % cwidth;
y = c / cwidth;
mb = x / 8 + (y / 8) * mb_x;
mberrors[mb] |= 2 << p;
if(print_pixels)
printf("c%c diff 0x%02x != 0x%02x at pixel (%4d,%-4d) "
"mb(%3d,%-3d) #%d\n",
p ? 'r' : 'b',
C[p][0][c],
C[p][1][c],
x, y,
x / 8,
y / 8,
x / 8 + y / 8 * cwidth / 8);
}
}
}
for(i = 0; i < mb_x * mb_y; i++) {
x = i % mb_x;
y = i / mb_x;
if(mberrors[i]) {
die = 1;
printf("MB (%3d,%-3d) %4d %d %c%c%c damaged\n",
x, y, i, mberrors[i],
mberrors[i] & 1 ? 'Y' : ' ',
mberrors[i] & 2 ? 'U' : ' ',
mberrors[i] & 4 ? 'V' : ' ');
if(dump_blocks) {
a = Y[0] + x * 16 + y * 16 * width;
b = Y[1] + x * 16 + y * 16 * width;
for(y = 0; y < 16; y++) {
printf("%c ", "TB"[y&1]);
for(x = 0; x < 16; x++)
printf("%02x%c", a[x + y * width],
a[x + y * width] != b[x + y * width] ? '<' : ' ');
printf("| ");
for(x = 0; x < 16; x++)
printf("%02x%c", b[x + y * width],
a[x + y * width] != b[x + y * width] ? '<' : ' ');
printf("\n");
}
}
}
}
}
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment