Commit 6a9c8594 authored by Alexander Strange's avatar Alexander Strange Committed by Ronald S. Bultje

H264/MPEG frame-level multi-threading.

Signed-off-by: 's avatarRonald S. Bultje <rsbultje@gmail.com>
parent 53be7b23
......@@ -32,6 +32,7 @@
#include "mpegvideo.h"
#include "h264.h"
#include "rectangle.h"
#include "thread.h"
/*
* H264 redefines mb_intra so it is not mistakely used (its uninitialized in h264)
......@@ -428,8 +429,7 @@ int score_sum=0;
int best_score=256*256*256*64;
int best_pred=0;
const int mot_index= (mb_x + mb_y*mot_stride) * mot_step;
int prev_x= s->current_picture.motion_val[0][mot_index][0];
int prev_y= s->current_picture.motion_val[0][mot_index][1];
int prev_x, prev_y, prev_ref;
if((mb_x^mb_y^pass)&1) continue;
......@@ -527,11 +527,26 @@ skip_mean_and_median:
/* zero MV */
pred_count++;
if (!fixed[mb_xy]) {
if (s->avctx->codec_id == CODEC_ID_H264) {
// FIXME
} else {
ff_thread_await_progress((AVFrame *) s->last_picture_ptr,
mb_y, 0);
}
prev_x = s->last_picture.motion_val[0][mot_index][0];
prev_y = s->last_picture.motion_val[0][mot_index][1];
prev_ref = s->last_picture.ref_index[0][4*mb_xy];
} else {
prev_x = s->current_picture.motion_val[0][mot_index][0];
prev_y = s->current_picture.motion_val[0][mot_index][1];
prev_ref = s->current_picture.ref_index[0][4*mb_xy];
}
/* last MV */
mv_predictor[pred_count][0]= s->current_picture.motion_val[0][mot_index][0];
mv_predictor[pred_count][1]= s->current_picture.motion_val[0][mot_index][1];
ref [pred_count] = s->current_picture.ref_index[0][4*mb_xy];
pred_count++;
mv_predictor[pred_count][0]= prev_x;
mv_predictor[pred_count][1]= prev_y;
ref [pred_count] = prev_ref;
s->mv_dir = MV_DIR_FORWARD;
s->mb_intra=0;
......@@ -662,6 +677,12 @@ static int is_intra_more_likely(MpegEncContext *s){
uint8_t *mb_ptr = s->current_picture.data[0] + mb_x*16 + mb_y*16*s->linesize;
uint8_t *last_mb_ptr= s->last_picture.data [0] + mb_x*16 + mb_y*16*s->linesize;
if (s->avctx->codec_id == CODEC_ID_H264) {
// FIXME
} else {
ff_thread_await_progress((AVFrame *) s->last_picture_ptr,
mb_y, 0);
}
is_intra_likely += s->dsp.sad[0](NULL, last_mb_ptr, mb_ptr , s->linesize, 16);
is_intra_likely -= s->dsp.sad[0](NULL, last_mb_ptr, last_mb_ptr+s->linesize*16, s->linesize, 16);
}else{
......@@ -681,6 +702,7 @@ void ff_er_frame_start(MpegEncContext *s){
memset(s->error_status_table, MV_ERROR|AC_ERROR|DC_ERROR|VP_START|AC_END|DC_END|MV_END, s->mb_stride*s->mb_height*sizeof(uint8_t));
s->error_count= 3*s->mb_num;
s->error_occurred = 0;
}
/**
......@@ -720,7 +742,10 @@ void ff_er_add_slice(MpegEncContext *s, int startx, int starty, int endx, int en
s->error_count -= end_i - start_i + 1;
}
if(status & (AC_ERROR|DC_ERROR|MV_ERROR)) s->error_count= INT_MAX;
if(status & (AC_ERROR|DC_ERROR|MV_ERROR)) {
s->error_occurred = 1;
s->error_count= INT_MAX;
}
if(mask == ~0x7F){
memset(&s->error_status_table[start_xy], 0, (end_xy - start_xy) * sizeof(uint8_t));
......@@ -995,6 +1020,12 @@ void ff_er_frame_end(MpegEncContext *s){
int time_pp= s->pp_time;
int time_pb= s->pb_time;
if (s->avctx->codec_id == CODEC_ID_H264) {
//FIXME
} else {
ff_thread_await_progress((AVFrame *) s->next_picture_ptr,
mb_y, 0);
}
s->mv[0][0][0] = s->next_picture.motion_val[0][xy][0]*time_pb/time_pp;
s->mv[0][0][1] = s->next_picture.motion_val[0][xy][1]*time_pb/time_pp;
s->mv[1][0][0] = s->next_picture.motion_val[0][xy][0]*(time_pb - time_pp)/time_pp;
......
......@@ -35,6 +35,7 @@
#include "mpeg4video_parser.h"
#include "msmpeg4.h"
#include "vdpau_internal.h"
#include "thread.h"
#include "flv.h"
#include "mpeg4video.h"
......@@ -229,6 +230,7 @@ static int decode_slice(MpegEncContext *s){
if(++s->mb_x >= s->mb_width){
s->mb_x=0;
ff_draw_horiz_band(s, s->mb_y*mb_size, mb_size);
MPV_report_decode_progress(s);
s->mb_y++;
}
return 0;
......@@ -249,6 +251,7 @@ static int decode_slice(MpegEncContext *s){
}
ff_draw_horiz_band(s, s->mb_y*mb_size, mb_size);
MPV_report_decode_progress(s);
s->mb_x= 0;
}
......@@ -609,6 +612,8 @@ retry:
if(MPV_frame_start(s, avctx) < 0)
return -1;
if (!s->divx_packed) ff_thread_finish_setup(avctx);
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);
goto frame_end;
......@@ -639,8 +644,11 @@ retry:
if(s->slice_height==0 || s->mb_x!=0 || (s->mb_y%s->slice_height)!=0 || get_bits_count(&s->gb) > s->gb.size_in_bits)
break;
}else{
int prev_x=s->mb_x, prev_y=s->mb_y;
if(ff_h263_resync(s)<0)
break;
if (prev_y * s->mb_width + prev_x < s->mb_y * s->mb_width + s->mb_x)
s->error_occurred = 1;
}
if(s->msmpeg4_version<4 && s->h263_pred)
......
This diff is collapsed.
......@@ -506,7 +506,9 @@ typedef struct H264Context{
Picture *long_ref[32];
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 *next_output_pic;
int outputed_poc;
int next_outputed_poc;
/**
* memory management control operations buffer.
......
......@@ -31,6 +31,7 @@
#include "mpegvideo.h"
#include "h264.h"
#include "rectangle.h"
#include "thread.h"
//#undef NDEBUG
#include <assert.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));
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
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 != AV_PICTURE_TYPE_B || h->direct_spatial_mv_pred)
......@@ -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){
MpegEncContext * const s = &h->s;
int b8_stride = 2;
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];
const int16_t (*l1mv0)[2], (*l1mv1)[2];
const int8_t *l1ref0, *l1ref1;
......@@ -157,6 +174,8 @@ static void pred_spatial_direct_motion(H264Context * const h, int *mb_type){
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)
......@@ -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(*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;
b8_stride = 0;
}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;
}else{ // AFL/AFR/FR/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_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];
......@@ -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]];
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];
......@@ -384,7 +408,7 @@ static void pred_temp_direct_motion(H264Context * const h, int *mb_type){
MpegEncContext * const s = &h->s;
int b8_stride = 2;
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];
const int16_t (*l1mv0)[2], (*l1mv1)[2];
const int8_t *l1ref0, *l1ref1;
......@@ -394,16 +418,21 @@ static void pred_temp_direct_motion(H264Context * const h, int *mb_type){
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(*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;
b8_stride = 0;
}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;
}else{ // AFL/AFR/FR/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_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];
......@@ -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]];
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];
......
......@@ -37,6 +37,7 @@
#include "bytestream.h"
#include "vdpau_internal.h"
#include "xvmc_internal.h"
#include "thread.h"
//#undef NDEBUG
//#include <assert.h>
......@@ -1179,6 +1180,27 @@ static av_cold int mpeg_decode_init(AVCodecContext *avctx)
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,
const uint8_t *new_perm){
uint16_t temp_matrix[64];
......@@ -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;
if (HAVE_PTHREADS && (avctx->active_thread_type & FF_THREAD_FRAME))
ff_thread_finish_setup(avctx);
}else{ //second field
int i;
......@@ -1769,6 +1794,7 @@ static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y,
const int mb_size= 16>>s->avctx->lowres;
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_y += 1<<field_pic;
......@@ -1926,7 +1952,8 @@ static int slice_end(AVCodecContext *avctx, AVFrame *pict)
*pict= *(AVFrame*)s->current_picture_ptr;
ff_print_debug_info(s, pict);
} else {
s->picture_number++;
if (avctx->active_thread_type & FF_THREAD_FRAME)
s->picture_number++;
/* latency of 1 frame for I- and P-frames */
/* XXX: use another variable than picture_number */
if (s->last_picture_ptr != NULL) {
......@@ -2262,7 +2289,7 @@ static int decode_chunks(AVCodecContext *avctx,
buf_ptr = ff_find_start_code(buf_ptr,buf_end, &start_code);
if (start_code > 0x1ff){
if(s2->pict_type != AV_PICTURE_TYPE_B || avctx->skip_frame <= AVDISCARD_DEFAULT){
if((avctx->active_thread_type & FF_THREAD_SLICE) && avctx->thread_count > 1){
if(HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE)){
int i;
avctx->execute(avctx, slice_decode_thread, &s2->thread_context[0], NULL, s->slice_count, sizeof(void*));
......@@ -2430,7 +2457,7 @@ static int decode_chunks(AVCodecContext *avctx,
break;
}
if((avctx->active_thread_type & FF_THREAD_SLICE) && 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;
if(threshold <= mb_y){
MpegEncContext *thread_context= s2->thread_context[s->slice_count];
......@@ -2505,6 +2532,7 @@ AVCodec ff_mpeg1video_decoder = {
.flush= flush,
.max_lowres= 3,
.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 = {
......@@ -2541,7 +2569,7 @@ AVCodec ff_mpegvideo_decoder = {
#if CONFIG_MPEG_XVMC_DECODER
static av_cold int mpeg_mc_decode_init(AVCodecContext *avctx){
if((avctx->active_thread_type & FF_THREAD_SLICE) && avctx->thread_count > 1)
if( avctx->active_thread_type & FF_THREAD_SLICE )
return -1;
if( !(avctx->slice_flags & SLICE_FLAG_CODED_ORDER) )
return -1;
......
......@@ -23,6 +23,7 @@
#include "mpegvideo.h"
#include "mpeg4video.h"
#include "h263.h"
#include "thread.h"
// 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
......@@ -373,7 +374,13 @@ int mpeg4_decode_video_packet_header(MpegEncContext *s)
return -1;
}
if(s->pict_type == AV_PICTURE_TYPE_B){
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
}
......@@ -1303,6 +1310,8 @@ static int mpeg4_decode_mb(MpegEncContext *s,
s->last_mv[i][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 */
......@@ -1482,6 +1491,12 @@ end:
if(s->codec_id==CODEC_ID_MPEG4){
if(mpeg4_is_resync(s)){
const int delta= s->mb_x + 1 == s->mb_width ? 2 : 1;
if(s->pict_type==AV_PICTURE_TYPE_B && s->next_picture.mbskip_table[xy + delta]){
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==AV_PICTURE_TYPE_B && s->next_picture.mbskip_table[xy + delta])
return SLICE_OK;
return SLICE_END;
......@@ -2235,11 +2250,12 @@ AVCodec ff_mpeg4_decoder = {
NULL,
ff_h263_decode_end,
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,
.max_lowres= 3,
.long_name= NULL_IF_CONFIG_SMALL("MPEG-4 part 2"),
.pix_fmts= ff_hwaccel_pixfmt_list_420,
.update_thread_context= ONLY_IF_THREADS_ENABLED(ff_mpeg_update_thread_context)
};
......
This diff is collapsed.
......@@ -76,6 +76,8 @@ enum OutputFormat {
#define EXT_START_CODE 0x000001b5
#define USER_START_CODE 0x000001b2
struct MpegEncContext;
/**
* Picture.
*/
......@@ -123,6 +125,7 @@ typedef struct Picture{
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 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 mc_mb_var_sum; ///< motion compensated MB variance for current frame
......@@ -131,10 +134,9 @@ typedef struct Picture{
uint8_t *mb_mean; ///< Table for MB luminance
int32_t *mb_cmp_score; ///< Table for MB cmp scores, for mb decision FIXME remove
int b_frame_score; /* */
struct MpegEncContext *owner2; ///< pointer to the MpegEncContext that allocated this picture
} Picture;
struct MpegEncContext;
/**
* Motion estimation context.
*/
......@@ -291,6 +293,8 @@ typedef struct MpegEncContext {
Picture *last_picture_ptr; ///< pointer to the previous picture.
Picture *next_picture_ptr; ///< pointer to the next picture (for bidir pred)
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
int last_dc[3]; ///< last DC values for MPEG1
int16_t *dc_val_base;
......@@ -470,7 +474,7 @@ typedef struct MpegEncContext {
int last_bits; ///< temp var used for calculating the above vars
/* error concealment / resync */
int error_count;
int error_count, error_occurred;
uint8_t *error_status_table; ///< table of the error status of each MB
#define VP_START 1 ///< current MB is the first after a resync marker
#define AC_ERROR 2
......@@ -677,6 +681,10 @@ typedef struct MpegEncContext {
void (*denoise_dct)(struct MpegEncContext *s, DCTELEM *block);
} MpegEncContext;
#define REBASE_PICTURE(pic, new_ctx, old_ctx) (pic ? \
(pic >= old_ctx->picture && pic < old_ctx->picture+old_ctx->picture_count ?\
&new_ctx->picture[pic - old_ctx->picture] : pic - (Picture*)old_ctx + (Picture*)new_ctx)\
: NULL)
void MPV_decode_defaults(MpegEncContext *s);
int MPV_common_init(MpegEncContext *s);
......@@ -699,9 +707,13 @@ void ff_draw_horiz_band(MpegEncContext *s, int y, int h);
void ff_mpeg_flush(AVCodecContext *avctx);
void ff_print_debug_info(MpegEncContext *s, AVFrame *pict);
void ff_write_quant_matrix(PutBitContext *pb, uint16_t *matrix);
void ff_release_unused_pictures(MpegEncContext *s, int remove_current);
int ff_find_unused_picture(MpegEncContext *s, int shared);
void ff_denoise_dct(MpegEncContext *s, DCTELEM *block);
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);
void ff_set_qscale(MpegEncContext * s, int qscale);
......
......@@ -36,6 +36,7 @@
#include "mjpegenc.h"
#include "msmpeg4.h"
#include "faandct.h"
#include "thread.h"
#include "aandcttab.h"
#include "flv.h"
#include "mpeg4video.h"
......@@ -1225,9 +1226,9 @@ int MPV_encode_picture(AVCodecContext *avctx,
{
MpegEncContext *s = avctx->priv_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 end_y= s->thread_context[i]-> end_mb_y;
int h= s->mb_height;
......@@ -1291,7 +1292,7 @@ vbv_retry:
s->last_non_b_time= s->time - s->pp_time;
}
// 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;
init_put_bits(pb, pb->buf, pb->buf_end - pb->buf);
}
......@@ -2758,6 +2759,7 @@ static int encode_picture(MpegEncContext *s, int picture_number)
{
int i;
int bits;
int context_count = (s->avctx->active_thread_type & FF_THREAD_SLICE) ? s->avctx->thread_count : 1;
s->picture_number = picture_number;
......@@ -2797,7 +2799,7 @@ static int encode_picture(MpegEncContext *s, int picture_number)
}
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);
}
......@@ -2810,11 +2812,11 @@ static int encode_picture(MpegEncContext *s, int picture_number)
s->lambda2= (s->lambda2* (int64_t)s->avctx->me_penalty_compensation + 128)>>8;
if(s->pict_type != AV_PICTURE_TYPE_B && s->avctx->me_threshold==0){
if((s->avctx->pre_me && s->last_non_b_pict_type==AV_PICTURE_TYPE_I) || 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 == AV_PICTURE_TYPE_I) */{
/* I-Frame */
for(i=0; i<s->mb_stride*s->mb_height; i++)
......@@ -2822,10 +2824,10 @@ static int encode_picture(MpegEncContext *s, int picture_number)
if(!s->fixed_qscale){
/* 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]);
}
s->current_picture.mc_mb_var_sum= s->current_picture_ptr->mc_mb_var_sum= s->me.mc_mb_var_sum_temp;
......@@ -2961,11 +2963,11 @@ static int encode_picture(MpegEncContext *s, int picture_number)
bits= put_bits_count(&s->pb);
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);
}
s->avctx->execute(s->avctx, encode_thread, &s->thread_context[0], NULL, s->avctx->thread_count, sizeof(void*));
for(i=1; i<s->avctx->thread_count; i++){
s->avctx->execute(s->avctx, encode_thread, &s->thread_context[0], NULL, context_count, sizeof(void*));
for(i=1; i<context_count; i++){
merge_context_after_encode(s, s->thread_context[i]);
}
emms_c();
......
......@@ -55,7 +55,7 @@ typedef struct ThreadContext {
} ThreadContext;
/// Max number of frame buffers that can be allocated when using frame threads.
#define MAX_BUFFERS 32
#define MAX_BUFFERS (32+1)
/**
* Context used by codec threads and stored in their AVCodecContext thread_opaque.
......
......@@ -115,7 +115,7 @@ typedef struct InternalBuffer{
enum PixelFormat pix_fmt;
}InternalBuffer;
#define INTERNAL_BUFFER_SIZE 32
#define INTERNAL_BUFFER_SIZE (32+1)
void avcodec_align_dimensions2(AVCodecContext *s, int *width, int *height, int linesize_align[4]){
int w_align= 1;
......@@ -360,6 +360,7 @@ void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
assert(pic->type==FF_BUFFER_TYPE_INTERNAL);
assert(s->internal_buffer_count);
if(s->internal_buffer){
buf = NULL; /* avoids warning */
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];
......@@ -371,6 +372,7 @@ void avcodec_default_release_buffer(AVCodecContext *s, AVFrame *pic){
last = &((InternalBuffer*)s->internal_buffer)[s->internal_buffer_count];
FFSWAP(InternalBuffer, *buf, *last);
}
for(i=0; i<4; i++){
pic->data[i]=NULL;
......
This diff is collapsed.
7416dfd319f04044d4575dc9d1b406e1 *./tests/data/vsynth1/error-mpeg4-adv.avi
756836 ./tests/data/vsynth1/error-mpeg4-adv.avi
ef8bfcd6e0883daba95d0f32486ebe2d *./tests/data/error.vsynth1.out.yuv
stddev: 18.05 PSNR: 23.00 MAXDIFF: 245 bytes: 7603200/ 7603200
756836 ./tests/data/vsynth1/error-mpeg4-adv.avi
54342963593ba08bcde95244a011efe5 *./tests/data/error.vsynth1.out.yuv
stddev: 17.59 PSNR: 23.22 MAXDIFF: 240 bytes: 7603200/ 7603200
90e65096aa9ebafa3fe3f44a5a47cdc4 *./tests/data/vsynth2/error-mpeg4-adv.avi
176588 ./tests/data/vsynth2/error-mpeg4-adv.avi
9fe1082179f80179439953c7397a46ef *./tests/data/error.vsynth2.out.yuv
stddev: 9.00 PSNR: 29.04 MAXDIFF: 168 bytes: 7603200/ 7603200
176588 ./tests/data/vsynth2/error-mpeg4-adv.avi
ce12aa852126f2740838dd2da9e21a03 *./tests/data/error.vsynth2.out.yuv
stddev: 10.06 PSNR: 28.08 MAXDIFF: 193 bytes: 7603200/ 7603200
......@@ -102,7 +102,7 @@ do_ffmpeg_crc()
do_video_decoding()
{
do_ffmpeg $raw_dst $DEC_OPTS $1 -i $target_path/$file -f rawvideo $ENC_OPTS $2
do_ffmpeg $raw_dst $DEC_OPTS $1 -i $target_path/$file -f rawvideo $ENC_OPTS -vsync 0 $2
}
do_video_encoding()
......
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