INIT_VLC_STATIC(&mb_btype_vlc, MB_BTYPE_VLC_BITS, 11,
&table_mb_btype[0][1], 2, 1,
&table_mb_btype[0][0], 2, 1, 64);
- init_rl(&ff_rl_mpeg1, ff_mpeg12_static_rl_table_store[0]);
- init_rl(&ff_rl_mpeg2, ff_mpeg12_static_rl_table_store[1]);
+ ff_init_rl(&ff_rl_mpeg1, ff_mpeg12_static_rl_table_store[0]);
+ ff_init_rl(&ff_rl_mpeg2, ff_mpeg12_static_rl_table_store[1]);
INIT_2D_VLC_RL(ff_rl_mpeg1, 680);
INIT_2D_VLC_RL(ff_rl_mpeg2, 674);
#define MT_16X8 2
#define MT_DMV 3
-static int mpeg_decode_mb(Mpeg1Context *s1, DCTELEM block[12][64])
+static int mpeg_decode_mb(MpegEncContext *s, DCTELEM block[12][64])
{
- MpegEncContext *s = &s1->mpeg_enc_ctx;
int i, j, k, cbp, val, mb_type, motion_type;
const int mb_block_count = 4 + (1 << s->chroma_format);
s->mv[i][0][1]= s->last_mv[i][0][1]= s->last_mv[i][1][1] =
mpeg_decode_motion(s, s->mpeg_f_code[i][1], s->last_mv[i][0][1]);
/* full_pel: only for MPEG-1 */
- if (s1->full_pel[i]) {
+ if (s->full_pel[i]) {
s->mv[i][0][0] <<= 1;
s->mv[i][0][1] <<= 1;
}
for (i = 0; i < 64; i++)
s2->dsp.idct_permutation[i]=i;
- MPV_decode_defaults(s2);
+ ff_MPV_decode_defaults(s2);
s->mpeg_enc_ctx.avctx = avctx;
s->mpeg_enc_ctx.flags = avctx->flags;
if (s1->mpeg_enc_ctx_allocated) {
ParseContext pc = s->parse_context;
s->parse_context.buffer = 0;
- MPV_common_end(s);
+ ff_MPV_common_end(s);
s->parse_context = pc;
}
/* low_delay may be forced, in this case we will have B-frames
* that behave like P-frames. */
- avctx->has_b_frames = !(s->low_delay);
+ avctx->has_b_frames = !s->low_delay;
- assert((avctx->sub_id == 1) == (avctx->codec_id == CODEC_ID_MPEG1VIDEO));
if (avctx->codec_id == CODEC_ID_MPEG1VIDEO) {
//MPEG-1 fps
avctx->time_base.den = avpriv_frame_rate_tab[s->frame_rate_index].num;
* if DCT permutation is changed. */
memcpy(old_permutation, s->dsp.idct_permutation, 64 * sizeof(uint8_t));
- if (MPV_common_init(s) < 0)
+ if (ff_MPV_common_init(s) < 0)
return -2;
quant_matrix_rebuild(s->intra_matrix, old_permutation, s->dsp.idct_permutation);
vbv_delay = get_bits(&s->gb, 16);
if (s->pict_type == AV_PICTURE_TYPE_P || s->pict_type == AV_PICTURE_TYPE_B) {
- s1->full_pel[0] = get_bits1(&s->gb);
+ s->full_pel[0] = get_bits1(&s->gb);
f_code = get_bits(&s->gb, 3);
if (f_code == 0 && (avctx->err_recognition & AV_EF_BITSTREAM))
return -1;
s->mpeg_f_code[0][1] = f_code;
}
if (s->pict_type == AV_PICTURE_TYPE_B) {
- s1->full_pel[1] = get_bits1(&s->gb);
+ s->full_pel[1] = get_bits1(&s->gb);
f_code = get_bits(&s->gb, 3);
if (f_code == 0 && (avctx->err_recognition & AV_EF_BITSTREAM))
return -1;
av_dlog(s->avctx, "sequence extension\n");
s->codec_id = s->avctx->codec_id = CODEC_ID_MPEG2VIDEO;
- s->avctx->sub_id = 2; /* indicates MPEG-2 found */
if (s->avctx->debug & FF_DEBUG_PICT_INFO)
av_log(s->avctx, AV_LOG_DEBUG, "profile: %d, level: %d vbv buffer: %d, bitrate:%d\n",
{
MpegEncContext *s = &s1->mpeg_enc_ctx;
- s1->full_pel[0] = s1->full_pel[1] = 0;
+ s->full_pel[0] = s->full_pel[1] = 0;
s->mpeg_f_code[0][0] = get_bits(&s->gb, 4);
s->mpeg_f_code[0][1] = get_bits(&s->gb, 4);
s->mpeg_f_code[1][0] = get_bits(&s->gb, 4);
}
if (s->progressive_sequence && !s->frame_pred_frame_dct) {
- av_log(s->avctx, AV_LOG_ERROR, "invalid frame_pred_frame_dct\n");
- s->frame_pred_frame_dct = 1;
+ av_log(s->avctx, AV_LOG_WARNING, "invalid frame_pred_frame_dct\n");
}
if (s->picture_structure == PICT_FRAME) {
/* start frame decoding */
if (s->first_field || s->picture_structure == PICT_FRAME) {
- if (MPV_frame_start(s, avctx) < 0)
+ if (ff_MPV_frame_start(s, avctx) < 0)
return -1;
ff_er_frame_start(s);
return -1;
}
+ if (s->avctx->hwaccel &&
+ (s->avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD)) {
+ if (s->avctx->hwaccel->end_frame(s->avctx) < 0)
+ av_log(avctx, AV_LOG_ERROR, "hardware accelerator failed to decode first field\n");
+ }
+
for (i = 0; i < 4; i++) {
s->current_picture.f.data[i] = s->current_picture_ptr->f.data[i];
if (s->picture_structure == PICT_BOTTOM_FIELD) {
#define DECODE_SLICE_OK 0
/**
- * decodes a slice. MpegEncContext.mb_y must be set to the MB row from the startcode
- * @return DECODE_SLICE_ERROR if the slice is damaged<br>
- * DECODE_SLICE_OK if this slice is ok<br>
+ * Decode a slice.
+ * MpegEncContext.mb_y must be set to the MB row from the startcode.
+ * @return DECODE_SLICE_ERROR if the slice is damaged,
+ * DECODE_SLICE_OK if this slice is OK
*/
-static int mpeg_decode_slice(Mpeg1Context *s1, int mb_y,
+static int mpeg_decode_slice(MpegEncContext *s, int mb_y,
const uint8_t **buf, int buf_size)
{
- MpegEncContext *s = &s1->mpeg_enc_ctx;
AVCodecContext *avctx = s->avctx;
- const int lowres = s->avctx->lowres;
const int field_pic = s->picture_structure != PICT_FRAME;
s->resync_mb_x =
if (mb_y == 0 && s->codec_tag == AV_RL32("SLIF")) {
skip_bits1(&s->gb);
} else {
- for (;;) {
+ while (get_bits_left(&s->gb) > 0) {
int code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2);
if (code < 0) {
av_log(s->avctx, AV_LOG_ERROR, "first mb_incr damaged\n");
if (CONFIG_MPEG_XVMC_DECODER && s->avctx->xvmc_acceleration > 1)
ff_xvmc_init_block(s); // set s->block
- if (mpeg_decode_mb(s1, s->block) < 0)
+ if (mpeg_decode_mb(s, s->block) < 0)
return -1;
if (s->current_picture.f.motion_val[0] && !s->encoding) { // note motion_val is normally NULL unless we want to extract the MVs
}
}
- s->dest[0] += 16 >> lowres;
- s->dest[1] +=(16 >> lowres) >> s->chroma_x_shift;
- s->dest[2] +=(16 >> lowres) >> s->chroma_x_shift;
+ s->dest[0] += 16;
+ s->dest[1] += 16 >> s->chroma_x_shift;
+ s->dest[2] += 16 >> s->chroma_x_shift;
- MPV_decode_mb(s, s->block);
+ ff_MPV_decode_mb(s, s->block);
if (++s->mb_x >= s->mb_width) {
- const int mb_size = 16 >> s->avctx->lowres;
+ const int mb_size = 16;
ff_draw_horiz_band(s, mb_size*(s->mb_y >> field_pic), mb_size);
- MPV_report_decode_progress(s);
+ ff_MPV_report_decode_progress(s);
s->mb_x = 0;
s->mb_y += 1 << field_pic;
uint32_t start_code;
int ret;
- ret = mpeg_decode_slice((Mpeg1Context*)s, mb_y, &buf, s->gb.buffer_end - buf);
+ ret = mpeg_decode_slice(s, mb_y, &buf, s->gb.buffer_end - buf);
emms_c();
//av_log(c, AV_LOG_DEBUG, "ret:%d resync:%d/%d mb:%d/%d ts:%d/%d ec:%d\n",
//ret, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, s->start_mb_y, s->end_mb_y, s->error_count);
if (c->err_recognition & AV_EF_EXPLODE)
return ret;
if (s->resync_mb_x >= 0 && s->resync_mb_y >= 0)
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, AC_ERROR | DC_ERROR | MV_ERROR);
+ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x, s->mb_y, ER_AC_ERROR | ER_DC_ERROR | ER_MV_ERROR);
} else {
- ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, AC_END | DC_END | MV_END);
+ ff_er_add_slice(s, s->resync_mb_x, s->resync_mb_y, s->mb_x-1, s->mb_y, ER_AC_END | ER_DC_END | ER_MV_END);
}
if (s->mb_y == s->end_mb_y)
ff_er_frame_end(s);
- MPV_frame_end(s);
+ ff_MPV_frame_end(s);
if (s->pict_type == AV_PICTURE_TYPE_B || s->low_delay) {
- *pict = *(AVFrame*)s->current_picture_ptr;
+ *pict = s->current_picture_ptr->f;
ff_print_debug_info(s, pict);
} else {
if (avctx->active_thread_type & FF_THREAD_FRAME)
/* latency of 1 frame for I- and P-frames */
/* XXX: use another variable than picture_number */
if (s->last_picture_ptr != NULL) {
- *pict = *(AVFrame*)s->last_picture_ptr;
+ *pict = s->last_picture_ptr->f;
ff_print_debug_info(s, pict);
}
}
s->frame_pred_frame_dct = 1;
s->chroma_format = 1;
s->codec_id = s->avctx->codec_id = CODEC_ID_MPEG1VIDEO;
- avctx->sub_id = 1; /* indicates MPEG-1 */
s->out_format = FMT_MPEG1;
s->swap_uv = 0; // AFAIK VCR2 does not have SEQ_HEADER
if (s->flags & CODEC_FLAG_LOW_DELAY)
/* start new MPEG-1 context decoding */
s->out_format = FMT_MPEG1;
if (s1->mpeg_enc_ctx_allocated) {
- MPV_common_end(s);
+ ff_MPV_common_end(s);
}
s->width = avctx->coded_width;
s->height = avctx->coded_height;
if (avctx->idct_algo == FF_IDCT_AUTO)
avctx->idct_algo = FF_IDCT_SIMPLE;
- if (MPV_common_init(s) < 0)
+ if (ff_MPV_common_init(s) < 0)
return -1;
exchange_uv(s); // common init reset pblocks, so we swap them here
s->swap_uv = 1; // in case of xvmc we need to swap uv for each MB
s->frame_pred_frame_dct = 1;
s->chroma_format = 1;
s->codec_id = s->avctx->codec_id = CODEC_ID_MPEG2VIDEO;
- avctx->sub_id = 2; /* indicates MPEG-2 */
s1->save_width = s->width;
s1->save_height = s->height;
s1->save_progressive_seq = s->progressive_sequence;
time_code_seconds = get_bits(&s->gb, 6);
time_code_pictures = get_bits(&s->gb, 6);
- s->closed_gop = get_bits1(&s->gb);
+ s1->closed_gop = get_bits1(&s->gb);
/*broken_link indicate that after editing the
reference frames of the first B-Frames after GOP I-Frame
are missing (open gop)*/
if (s->avctx->debug & FF_DEBUG_PICT_INFO)
av_log(s->avctx, AV_LOG_DEBUG, "GOP (%2d:%02d:%02d.[%02d]) closed_gop=%d broken_link=%d\n",
time_code_hours, time_code_minutes, time_code_seconds,
- time_code_pictures, s->closed_gop, broken_link);
+ time_code_pictures, s1->closed_gop, broken_link);
}
/**
* Find the end of the current frame in the bitstream.
pc->frame_start_found = 4;
}
if (state == SEQ_END_CODE) {
+ pc->frame_start_found = 0;
pc->state=-1;
return i+1;
}
if (buf_size == 0 || (buf_size == 4 && AV_RB32(buf) == SEQ_END_CODE)) {
/* special case for last picture */
if (s2->low_delay == 0 && s2->next_picture_ptr) {
- *picture = *(AVFrame*)s2->next_picture_ptr;
+ *picture = s2->next_picture_ptr->f;
s2->next_picture_ptr = NULL;
*data_size = sizeof(AVFrame);
}
if (CONFIG_MPEG_VDPAU_DECODER && avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)
- ff_vdpau_mpeg_picture_complete(s, buf, buf_size, s->slice_count);
+ ff_vdpau_mpeg_picture_complete(s2, buf, buf_size, s->slice_count);
if (slice_end(avctx, picture)) {
if (s2->last_picture_ptr || s2->low_delay) //FIXME merge with the stuff in mpeg_decode_slice
if (s2->last_picture_ptr == NULL) {
/* Skip B-frames if we do not have reference frames and gop is not closed */
if (s2->pict_type == AV_PICTURE_TYPE_B) {
- if (!s2->closed_gop)
+ if (!s->closed_gop)
break;
}
}
}
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 +
+ s2->slice_context_count / 2) /
+ s2->slice_context_count;
if (threshold <= mb_y) {
MpegEncContext *thread_context = s2->thread_context[s->slice_count];
}
buf_ptr += 2; // FIXME add minimum number of bytes per slice
} else {
- ret = mpeg_decode_slice(s, mb_y, &buf_ptr, input_size);
+ ret = mpeg_decode_slice(s2, mb_y, &buf_ptr, input_size);
emms_c();
if (ret < 0) {
if (avctx->err_recognition & AV_EF_EXPLODE)
return ret;
if (s2->resync_mb_x >= 0 && s2->resync_mb_y >= 0)
- ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x, s2->mb_y, AC_ERROR | DC_ERROR | MV_ERROR);
+ ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x, s2->mb_y, ER_AC_ERROR | ER_DC_ERROR | ER_MV_ERROR);
} else {
- ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x-1, s2->mb_y, AC_END | DC_END | MV_END);
+ ff_er_add_slice(s2, s2->resync_mb_x, s2->resync_mb_y, s2->mb_x-1, s2->mb_y, ER_AC_END | ER_DC_END | ER_MV_END);
}
}
}
Mpeg1Context *s = avctx->priv_data;
s->sync=0;
+ s->closed_gop = 0;
ff_mpeg_flush(avctx);
}
Mpeg1Context *s = avctx->priv_data;
if (s->mpeg_enc_ctx_allocated)
- MPV_common_end(&s->mpeg_enc_ctx);
+ ff_MPV_common_end(&s->mpeg_enc_ctx);
return 0;
}
AVCodec ff_mpeg1video_decoder = {
- .name = "mpeg1video",
- .type = AVMEDIA_TYPE_VIDEO,
- .id = CODEC_ID_MPEG1VIDEO,
- .priv_data_size = sizeof(Mpeg1Context),
- .init = mpeg_decode_init,
- .close = mpeg_decode_end,
- .decode = mpeg_decode_frame,
- .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS,
- .flush = flush,
- .max_lowres = 3,
- .long_name = NULL_IF_CONFIG_SMALL("MPEG-1 video"),
+ .name = "mpeg1video",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = CODEC_ID_MPEG1VIDEO,
+ .priv_data_size = sizeof(Mpeg1Context),
+ .init = mpeg_decode_init,
+ .close = mpeg_decode_end,
+ .decode = mpeg_decode_frame,
+ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 |
+ CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY |
+ CODEC_CAP_SLICE_THREADS,
+ .flush = flush,
+ .long_name = NULL_IF_CONFIG_SMALL("MPEG-1 video"),
.update_thread_context = ONLY_IF_THREADS_ENABLED(mpeg_decode_update_thread_context)
};
.init = mpeg_decode_init,
.close = mpeg_decode_end,
.decode = mpeg_decode_frame,
- .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS,
+ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 |
+ CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY |
+ CODEC_CAP_SLICE_THREADS,
.flush = flush,
- .max_lowres = 3,
.long_name = NULL_IF_CONFIG_SMALL("MPEG-2 video"),
.profiles = NULL_IF_CONFIG_SMALL(mpeg2_video_profiles),
};
-//legacy decoder
-AVCodec ff_mpegvideo_decoder = {
- .name = "mpegvideo",
- .type = AVMEDIA_TYPE_VIDEO,
- .id = CODEC_ID_MPEG2VIDEO,
- .priv_data_size = sizeof(Mpeg1Context),
- .init = mpeg_decode_init,
- .close = mpeg_decode_end,
- .decode = mpeg_decode_frame,
- .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_DELAY | CODEC_CAP_SLICE_THREADS,
- .flush = flush,
- .max_lowres = 3,
- .long_name = NULL_IF_CONFIG_SMALL("MPEG-1 video"),
-};
-
#if CONFIG_MPEG_XVMC_DECODER
static av_cold int mpeg_mc_decode_init(AVCodecContext *avctx)
{
.init = mpeg_mc_decode_init,
.close = mpeg_decode_end,
.decode = mpeg_decode_frame,
- .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED| CODEC_CAP_HWACCEL | CODEC_CAP_DELAY,
+ .capabilities = CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1 |
+ CODEC_CAP_TRUNCATED| CODEC_CAP_HWACCEL | CODEC_CAP_DELAY,
.flush = flush,
.long_name = NULL_IF_CONFIG_SMALL("MPEG-1/2 video XvMC (X-Video Motion Compensation)"),
};
.init = mpeg_decode_init,
.close = mpeg_decode_end,
.decode = mpeg_decode_frame,
- .capabilities = CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED |
+ CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY,
.flush = flush,
.long_name = NULL_IF_CONFIG_SMALL("MPEG-1/2 video (VDPAU acceleration)"),
};
.init = mpeg_decode_init,
.close = mpeg_decode_end,
.decode = mpeg_decode_frame,
- .capabilities = CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED | CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY,
+ .capabilities = CODEC_CAP_DR1 | CODEC_CAP_TRUNCATED |
+ CODEC_CAP_HWACCEL_VDPAU | CODEC_CAP_DELAY,
.flush = flush,
.long_name = NULL_IF_CONFIG_SMALL("MPEG-1 video (VDPAU acceleration)"),
};
#endif
-