Commit b536d0aa authored by Michael Niedermayer's avatar Michael Niedermayer

field pic decoding cleanup

Originally committed as revision 1686 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 1c6dcb0f
......@@ -187,6 +187,12 @@ static const int Motion_Est_QTab[] = { ME_ZERO, ME_PHODS, ME_LOG,
#define CODEC_CAP_TRUNCATED 0x0008
#define FF_COMMON_FRAME \
/**\
* pointer to the picture planes.\
* this might be different from the first allocated byte\
* - encoding: \
* - decoding: \
*/\
uint8_t *data[4];\
int linesize[4];\
/**\
......@@ -306,8 +312,8 @@ static const int Motion_Est_QTab[] = { ME_ZERO, ME_PHODS, ME_LOG,
#define FF_BUFFER_TYPE_INTERNAL 1
#define FF_BUFFER_TYPE_USER 2 // Direct rendering buffers
#define FF_BUFFER_TYPE_SHARED 4 // input frame for encoding(wont be dealloced)
#define FF_BUFFER_TYPE_USER 2 ///< Direct rendering buffers
#define FF_BUFFER_TYPE_SHARED 4 ///< buffer from somewher else, dont dealloc
#define FF_I_TYPE 1 // Intra
......
......@@ -534,7 +534,7 @@ score_sum+= best_score;
static int is_intra_more_likely(MpegEncContext *s){
int is_intra_likely, i, j, undamaged_count, skip_amount, mb_x, mb_y;
if(s->last_picture.data[0]==NULL) return 1; //no previous frame available -> use spatial prediction
if(s->last_picture_ptr==NULL) return 1; //no previous frame available -> use spatial prediction
undamaged_count=0;
for(i=0; i<s->mb_num; i++){
......
......@@ -621,7 +621,7 @@ retry:
s->current_picture.key_frame= s->pict_type == I_TYPE;
/* skip b frames if we dont have reference frames */
if(s->last_picture.data[0]==NULL && s->pict_type==B_TYPE) return get_consumed_bytes(s, buf_size);
if(s->last_picture_ptr==NULL && s->pict_type==B_TYPE) return get_consumed_bytes(s, buf_size);
/* skip b frames if we are in a hurry */
if(avctx->hurry_up && s->pict_type==B_TYPE) return get_consumed_bytes(s, buf_size);
/* skip everything if we are in a hurry>=5 */
......@@ -731,7 +731,7 @@ retry:
MPV_frame_end(s);
if((avctx->debug&FF_DEBUG_VIS_MV) && s->last_picture.data[0]){
if((avctx->debug&FF_DEBUG_VIS_MV) && s->last_picture_ptr){
const int shift= 1 + s->quarter_sample;
int mb_y;
uint8_t *ptr= s->last_picture.data[0];
......@@ -789,7 +789,7 @@ retry:
avctx->frame_number = s->picture_number - 1;
/* dont output the last pic after seeking */
if(s->last_picture.data[0] || s->low_delay)
if(s->last_picture_ptr || s->low_delay)
*data_size = sizeof(AVFrame);
#ifdef PRINT_FRAME_TIME
printf("%Ld\n", rdtsc()-time);
......
......@@ -229,7 +229,7 @@ static void mpeg1_encode_sequence_header(MpegEncContext *s)
put_bits(&s->pb, 4, s->aspect_ratio_info);
put_bits(&s->pb, 4, s->frame_rate_index);
v = s->bit_rate / 400;
v = (s->bit_rate + 399) / 400;
if (v > 0x3ffff)
v = 0x3ffff;
put_bits(&s->pb, 18, v);
......@@ -1803,7 +1803,8 @@ static int mpeg_decode_slice(AVCodecContext *avctx,
memset(s->last_mv, 0, sizeof(s->last_mv));
/* start frame decoding */
if (s->first_slice && (s->first_field || s->picture_structure==PICT_FRAME)) {
if (s->first_slice) {
if(s->first_field || s->picture_structure==PICT_FRAME){
if(MPV_frame_start(s, avctx) < 0)
return DECODE_SLICE_FATAL_ERROR;
/* first check if we must repeat the frame */
......@@ -1829,6 +1830,15 @@ static int mpeg_decode_slice(AVCodecContext *avctx,
s->intra_dc_precision, s->picture_structure, s->frame_pred_frame_dct, s->concealment_motion_vectors,
s->q_scale_type, s->intra_vlc_format, s->repeat_first_field, s->chroma_420_type ? "420" :"");
}
}else{ //second field
int i;
for(i=0; i<4; i++){
s->current_picture.data[i] = s->current_picture_ptr->data[i];
if(s->picture_structure == PICT_BOTTOM_FIELD){
s->current_picture.data[i] += s->current_picture_ptr->linesize[i];
}
}
}
}
s->first_slice = 0;
......@@ -1865,27 +1875,8 @@ static int mpeg_decode_slice(AVCodecContext *avctx,
dprintf("ret=%d\n", ret);
if (ret < 0)
return -1;
//printf("%d %d\n", s->mb_x, s->mb_y);
//FIXME this isnt the most beautifull way to solve the problem ...
if(s->picture_structure!=PICT_FRAME){
if(s->picture_structure == PICT_BOTTOM_FIELD){
s->current_picture.data[0] += s->linesize;
s->current_picture.data[1] += s->uvlinesize;
s->current_picture.data[2] += s->uvlinesize;
}
s->linesize *= 2;
s->uvlinesize *= 2;
}
MPV_decode_mb(s, s->block);
if(s->picture_structure!=PICT_FRAME){
s->linesize /= 2;
s->uvlinesize /= 2;
if(s->picture_structure == PICT_BOTTOM_FIELD){
s->current_picture.data[0] -= s->linesize;
s->current_picture.data[1] -= s->uvlinesize;
s->current_picture.data[2] -= s->uvlinesize;
}
}
if (++s->mb_x >= s->mb_width) {
if(s->picture_structure==PICT_FRAME){
......@@ -1945,7 +1936,7 @@ eos: //end of slice
s->picture_number++;
/* latency of 1 frame for I and P frames */
/* XXX: use another variable than picture_number */
if (s->last_picture.data[0] == NULL) {
if (s->last_picture_ptr == NULL) {
return DECODE_SLICE_OK;
} else {
*pict= *(AVFrame*)&s->last_picture;
......@@ -2196,7 +2187,7 @@ static int mpeg_decode_frame(AVCodecContext *avctx,
start_code <= SLICE_MAX_START_CODE) {
/* skip b frames if we dont have reference frames */
if(s2->last_picture.data[0]==NULL && s2->pict_type==B_TYPE) break;
if(s2->last_picture_ptr==NULL && s2->pict_type==B_TYPE) break;
/* skip b frames if we are in a hurry */
if(avctx->hurry_up && s2->pict_type==B_TYPE) break;
/* skip everything if we are in a hurry>=5 */
......
This diff is collapsed.
......@@ -238,10 +238,35 @@ typedef struct MpegEncContext {
Picture picture[MAX_PICTURE_COUNT]; ///< main picture buffer
Picture *input_picture[MAX_PICTURE_COUNT]; ///< next pictures on display order for encoding
Picture *reordered_input_picture[MAX_PICTURE_COUNT]; ///< pointer to the next pictures in codedorder for encoding
Picture last_picture; ///< previous picture
Picture next_picture; ///< previous picture (for bidir pred)
Picture new_picture; ///< source picture for encoding
/**
* copy of the previous picture structure.
* note, linesize & data, might not match the previous picture (for field pictures)
*/
Picture last_picture;
/**
* copy of the next picture structure.
* note, linesize & data, might not match the next picture (for field pictures)
*/
Picture next_picture;
/**
* copy of the source picture structure for encoding.
* note, linesize & data, might not match the source picture (for field pictures)
*/
Picture new_picture;
/**
* copy of the current picture structure.
* note, linesize & data, might not match the current picture (for field pictures)
*/
Picture current_picture; ///< buffer to store the decompressed current picture
Picture *last_picture_ptr; ///< pointer to the previous picture.
Picture *next_picture_ptr; ///< pointer to the next picture (for bidir pred)
Picture *new_picture_ptr; ///< pointer to the source picture for encoding
Picture *current_picture_ptr; ///< pointer to the current picture
int last_dc[3]; ///< last DC values for MPEG1
int16_t *dc_val[3]; ///< used for mpeg4 DC prediction, all 3 arrays must be continuous
int y_dc_scale, c_dc_scale;
......
......@@ -1126,7 +1126,7 @@ static int svq1_decode_frame(AVCodecContext *avctx,
//FIXME this avoids some confusion for "B frames" without 2 references
//this should be removed after libavcodec can handle more flaxible picture types & ordering
if(s->pict_type==B_TYPE && s->last_picture.data[0]==NULL) return buf_size;
if(s->pict_type==B_TYPE && s->last_picture_ptr==NULL) return buf_size;
if(avctx->hurry_up && s->pict_type==B_TYPE) return buf_size;
......
......@@ -192,9 +192,9 @@ int avcodec_default_get_buffer(AVCodecContext *s, AVFrame *pic){
memset(pic->base[i], 128, pic->linesize[i]*h>>v_shift);
if(s->flags&CODEC_FLAG_EMU_EDGE)
pic->data[i] = pic->base[i] + 16; //FIXME 16
pic->data[i] = pic->base[i];
else
pic->data[i] = pic->base[i] + (pic->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift) + 16; //FIXME 16
pic->data[i] = pic->base[i] + (pic->linesize[i]*EDGE_WIDTH>>v_shift) + (EDGE_WIDTH>>h_shift);
opaque->data[i]= pic->data[i];
}
......@@ -581,7 +581,7 @@ void avcodec_flush_buffers(AVCodecContext *avctx)
|| s->picture[i].type == FF_BUFFER_TYPE_USER))
avctx->release_buffer(avctx, (AVFrame*)&s->picture[i]);
}
s->last_picture.data[0] = s->next_picture.data[0] = NULL;
s->last_picture_ptr = s->next_picture_ptr = NULL;
break;
default:
//FIXME
......
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