* MPEG-1/2 decoder
*/
-//#define DEBUG
+#include "libavutil/attributes.h"
#include "libavutil/internal.h"
#include "internal.h"
#include "avcodec.h"
#include "error_resilience.h"
#include "mpeg12.h"
#include "mpeg12data.h"
-#include "mpeg12decdata.h"
#include "bytestream.h"
-#include "vdpau_internal.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 extradata_decoded;
} Mpeg1Context;
+#define MB_TYPE_ZERO_MV 0x20000000
+
+static const uint32_t ptype2mb_type[7] = {
+ MB_TYPE_INTRA,
+ MB_TYPE_L0 | MB_TYPE_CBP | MB_TYPE_ZERO_MV | MB_TYPE_16x16,
+ MB_TYPE_L0,
+ MB_TYPE_L0 | MB_TYPE_CBP,
+ MB_TYPE_QUANT | MB_TYPE_INTRA,
+ MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_CBP | MB_TYPE_ZERO_MV | MB_TYPE_16x16,
+ MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_CBP,
+};
+
+static const uint32_t btype2mb_type[11] = {
+ MB_TYPE_INTRA,
+ MB_TYPE_L1,
+ MB_TYPE_L1 | MB_TYPE_CBP,
+ MB_TYPE_L0,
+ MB_TYPE_L0 | MB_TYPE_CBP,
+ MB_TYPE_L0L1,
+ MB_TYPE_L0L1 | MB_TYPE_CBP,
+ MB_TYPE_QUANT | MB_TYPE_INTRA,
+ MB_TYPE_QUANT | MB_TYPE_L1 | MB_TYPE_CBP,
+ MB_TYPE_QUANT | MB_TYPE_L0 | MB_TYPE_CBP,
+ MB_TYPE_QUANT | MB_TYPE_L0L1 | MB_TYPE_CBP,
+};
+
+static const uint8_t non_linear_qscale[32] = {
+ 0, 1, 2, 3, 4, 5, 6, 7,
+ 8,10,12,14,16,18,20,22,
+ 24,28,32,36,40,44,48,52,
+ 56,64,72,80,88,96,104,112,
+};
+
/* as H.263, but only 17 codes */
static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred)
{
if (avctx->xvmc_acceleration)
return avctx->get_format(avctx, pixfmt_xvmc_mpg2_420);
- else if (avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) {
- if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO)
- return AV_PIX_FMT_VDPAU_MPEG1;
- else
- return AV_PIX_FMT_VDPAU_MPEG2;
- } else {
+ else {
if (s->chroma_format < 2)
return avctx->get_format(avctx, mpeg12_hwaccel_pixfmt_list_420);
else if (s->chroma_format == 2)
avctx->hwaccel = ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt);
// until then pix_fmt may be changed right after codec init
if (avctx->pix_fmt == AV_PIX_FMT_XVMC_MPEG2_IDCT ||
- avctx->hwaccel ||
- s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)
+ avctx->hwaccel)
if (avctx->idct_algo == FF_IDCT_AUTO)
avctx->idct_algo = FF_IDCT_SIMPLE;
avctx->pix_fmt = mpeg_get_pixelformat(avctx);
avctx->hwaccel = ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt);
- if (avctx->pix_fmt == AV_PIX_FMT_XVMC_MPEG2_IDCT || avctx->hwaccel ||
- s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)
+ if (avctx->pix_fmt == AV_PIX_FMT_XVMC_MPEG2_IDCT || avctx->hwaccel)
if (avctx->idct_algo == FF_IDCT_AUTO)
avctx->idct_algo = FF_IDCT_SIMPLE;
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 (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE)) {
+ if (!skip_frame) {
+ if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE) &&
+ !avctx->hwaccel) {
int i;
avctx->execute(avctx, slice_decode_thread, &s2->thread_context[0], NULL, s->slice_count, sizeof(void*));
s2->er.error_count += s2->thread_context[i]->er.error_count;
}
- if ((CONFIG_MPEG_VDPAU_DECODER || CONFIG_MPEG1_VDPAU_DECODER)
- && avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)
- ff_vdpau_mpeg_picture_complete(s2, buf, buf_size, s->slice_count);
-
ret = slice_end(avctx, picture);
if (ret < 0)
return ret;
return AVERROR_INVALIDDATA;
}
- if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE) && s->slice_count) {
+ if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE) &&
+ !avctx->hwaccel && s->slice_count) {
int i;
avctx->execute(avctx, slice_decode_thread,
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;
return AVERROR_INVALIDDATA;
}
- if (avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) {
- s->slice_count++;
- break;
- }
-
- if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE)) {
+ if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE) &&
+ !avctx->hwaccel) {
int threshold = (s2->mb_height * s->slice_count +
s2->slice_context_count / 2) /
s2->slice_context_count;
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;
};
#endif
-
-#if CONFIG_MPEG_VDPAU_DECODER
-AVCodec ff_mpeg_vdpau_decoder = {
- .name = "mpegvideo_vdpau",
- .type = AVMEDIA_TYPE_VIDEO,
- .id = AV_CODEC_ID_MPEG2VIDEO,
- .priv_data_size = sizeof(Mpeg1Context),
- .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,
- .flush = flush,
- .long_name = NULL_IF_CONFIG_SMALL("MPEG-1/2 video (VDPAU acceleration)"),
-};
-#endif
-
-#if CONFIG_MPEG1_VDPAU_DECODER
-AVCodec ff_mpeg1_vdpau_decoder = {
- .name = "mpeg1video_vdpau",
- .type = AVMEDIA_TYPE_VIDEO,
- .id = AV_CODEC_ID_MPEG1VIDEO,
- .priv_data_size = sizeof(Mpeg1Context),
- .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,
- .flush = flush,
- .long_name = NULL_IF_CONFIG_SMALL("MPEG-1 video (VDPAU acceleration)"),
-};
-#endif