* MPEG-1/2 decoder
*/
-//#define DEBUG
+#include "libavutil/attributes.h"
#include "libavutil/internal.h"
#include "internal.h"
#include "avcodec.h"
#include "xvmc_internal.h"
#include "thread.h"
-//#undef NDEBUG
-//#include <assert.h>
+typedef struct Mpeg1Context {
+ MpegEncContext mpeg_enc_ctx;
+ int mpeg_enc_ctx_allocated; /* true if decoding context allocated */
+ int repeat_field; /* true if we must repeat the field */
+ AVPanScan pan_scan; /**< some temporary storage for the panscan */
+ int slice_count;
+ int swap_uv;//indicate VCR2
+ int save_aspect_info;
+ int save_width, save_height, save_progressive_seq;
+ AVRational frame_rate_ext; ///< MPEG-2 specific framerate modificator
+ int sync; ///< Did we reach a sync point like a GOP/SEQ/KEYFrame?
+ int closed_gop; ///< GOP is closed
+ int extradata_decoded;
+} Mpeg1Context;
/* as H.263, but only 17 codes */
static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred)
const uint8_t *buf_ptr = buf;
const uint8_t *buf_end = buf + buf_size;
int ret, input_size;
- int last_code = 0;
+ int last_code = 0, skip_frame = 0;
for (;;) {
/* find next start code */
uint32_t start_code = -1;
buf_ptr = avpriv_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 (!skip_frame) {
if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE)) {
int i;
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 (!s->closed_gop)
+ if (!s->closed_gop) {
+ skip_frame = 1;
break;
+ }
}
}
if (s2->pict_type == AV_PICTURE_TYPE_I)
s->sync=1;
if (s2->next_picture_ptr == NULL) {
/* Skip P-frames if we do not have a reference frame or we have an invalid header. */
- if (s2->pict_type == AV_PICTURE_TYPE_P && !s->sync) break;
+ if (s2->pict_type == AV_PICTURE_TYPE_P && !s->sync) {
+ skip_frame = 1;
+ break;
+ }
}
if ((avctx->skip_frame >= AVDISCARD_NONREF && s2->pict_type == AV_PICTURE_TYPE_B) ||
(avctx->skip_frame >= AVDISCARD_NONKEY && s2->pict_type != AV_PICTURE_TYPE_I) ||
- avctx->skip_frame >= AVDISCARD_ALL)
+ avctx->skip_frame >= AVDISCARD_ALL) {
+ skip_frame = 1;
break;
+ }
if (!s->mpeg_enc_ctx_allocated)
break;
}
if (s2->first_slice) {
+ skip_frame = 0;
s2->first_slice = 0;
if (mpeg_field_start(s2, buf, buf_size) < 0)
return -1;
ff_mpeg_flush(avctx);
}
-static int mpeg_decode_end(AVCodecContext *avctx)
+static av_cold int mpeg_decode_end(AVCodecContext *avctx)
{
Mpeg1Context *s = avctx->priv_data;