summaryrefslogtreecommitdiffstats
path: root/libavcodec/mpeg12.c
diff options
context:
space:
mode:
Diffstat (limited to 'libavcodec/mpeg12.c')
-rw-r--r--libavcodec/mpeg12.c148
1 files changed, 109 insertions, 39 deletions
diff --git a/libavcodec/mpeg12.c b/libavcodec/mpeg12.c
index eefcb7b..3bc857d 100644
--- a/libavcodec/mpeg12.c
+++ b/libavcodec/mpeg12.c
@@ -3,20 +3,20 @@
* Copyright (c) 2000, 2001 Fabrice Bellard
* Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
*
- * This file is part of Libav.
+ * This file is part of FFmpeg.
*
- * Libav is free software; you can redistribute it and/or
+ * FFmpeg is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
- * Libav is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
- * License along with Libav; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@@ -30,6 +30,7 @@
#include "avcodec.h"
#include "dsputil.h"
#include "mpegvideo.h"
+#include "libavutil/avassert.h"
#include "mpeg12.h"
#include "mpeg12data.h"
@@ -956,6 +957,7 @@ static int mpeg_decode_mb(MpegEncContext *s, DCTELEM block[12][64])
}
}
} else {
+ av_assert0(!s->progressive_sequence);
mb_type |= MB_TYPE_16x16 | MB_TYPE_INTERLACED;
for (i = 0; i < 2; i++) {
if (USES_LIST(mb_type, i)) {
@@ -972,6 +974,10 @@ static int mpeg_decode_mb(MpegEncContext *s, DCTELEM block[12][64])
}
break;
case MT_DMV:
+ if(s->progressive_sequence){
+ av_log(s->avctx, AV_LOG_ERROR, "MT_DMV in progressive_sequence\n");
+ return -1;
+ }
s->mv_type = MV_TYPE_DMV;
for (i = 0; i < 2; i++) {
if (USES_LIST(mb_type, i)) {
@@ -1171,31 +1177,61 @@ static void quant_matrix_rebuild(uint16_t *matrix, const uint8_t *old_perm,
}
}
-static const enum PixelFormat pixfmt_xvmc_mpg2_420[] = {
+static const enum PixelFormat mpeg1_hwaccel_pixfmt_list_420[] = {
+#if CONFIG_MPEG_XVMC_DECODER
+ PIX_FMT_XVMC_MPEG2_IDCT,
+ PIX_FMT_XVMC_MPEG2_MC,
+#endif
+#if CONFIG_MPEG1_VDPAU_HWACCEL
+ PIX_FMT_VDPAU_MPEG1,
+#endif
+ PIX_FMT_YUV420P,
+ PIX_FMT_NONE
+};
+
+static const enum PixelFormat mpeg2_hwaccel_pixfmt_list_420[] = {
+#if CONFIG_MPEG_XVMC_DECODER
PIX_FMT_XVMC_MPEG2_IDCT,
PIX_FMT_XVMC_MPEG2_MC,
- PIX_FMT_NONE };
+#endif
+#if CONFIG_MPEG2_VDPAU_HWACCEL
+ PIX_FMT_VDPAU_MPEG2,
+#endif
+#if CONFIG_MPEG2_DXVA2_HWACCEL
+ PIX_FMT_DXVA2_VLD,
+#endif
+#if CONFIG_MPEG2_VAAPI_HWACCEL
+ PIX_FMT_VAAPI_VLD,
+#endif
+ PIX_FMT_YUV420P,
+ PIX_FMT_NONE
+};
+
+static inline int uses_vdpau(AVCodecContext *avctx) {
+ return avctx->pix_fmt == PIX_FMT_VDPAU_MPEG1 || avctx->pix_fmt == PIX_FMT_VDPAU_MPEG2;
+}
static enum PixelFormat mpeg_get_pixelformat(AVCodecContext *avctx)
{
Mpeg1Context *s1 = avctx->priv_data;
MpegEncContext *s = &s1->mpeg_enc_ctx;
- 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 == CODEC_ID_MPEG1VIDEO)
- return PIX_FMT_VDPAU_MPEG1;
- else
- return PIX_FMT_VDPAU_MPEG2;
- } else {
- if (s->chroma_format < 2)
- return avctx->get_format(avctx, ff_hwaccel_pixfmt_list_420);
- else if (s->chroma_format == 2)
- return PIX_FMT_YUV422P;
- else
- return PIX_FMT_YUV444P;
- }
+ if(s->chroma_format < 2) {
+ enum PixelFormat res;
+ res = avctx->get_format(avctx,
+ avctx->codec_id == CODEC_ID_MPEG1VIDEO ?
+ mpeg1_hwaccel_pixfmt_list_420 :
+ mpeg2_hwaccel_pixfmt_list_420);
+ if (res != PIX_FMT_XVMC_MPEG2_IDCT && res != PIX_FMT_XVMC_MPEG2_MC) {
+ avctx->xvmc_acceleration = 0;
+ } else if (!avctx->xvmc_acceleration) {
+ avctx->xvmc_acceleration = 2;
+ }
+ return res;
+ } else if(s->chroma_format == 2)
+ return PIX_FMT_YUV422P;
+ else
+ return PIX_FMT_YUV444P;
}
/* Call this function when we know all parameters.
@@ -1289,8 +1325,7 @@ static int mpeg_decode_postinit(AVCodecContext *avctx)
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 == 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;
@@ -1524,7 +1559,6 @@ static void mpeg_decode_picture_coding_extension(Mpeg1Context *s1)
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;
}
if (s->picture_structure == PICT_FRAME) {
@@ -1904,7 +1938,7 @@ static int slice_end(AVCodecContext *avctx, AVFrame *pict)
ff_xvmc_field_end(s);
/* end of slice reached */
- if (/*s->mb_y << field_pic == s->mb_height &&*/ !s->first_field) {
+ if (/*s->mb_y << field_pic == s->mb_height &&*/ !s->first_field && !s->first_slice) {
/* end of image */
s->current_picture_ptr->f.qscale_type = FF_QSCALE_TYPE_MPEG2;
@@ -2031,8 +2065,7 @@ static int vcr2_init_sequence(AVCodecContext *avctx)
avctx->pix_fmt = mpeg_get_pixelformat(avctx);
avctx->hwaccel = ff_find_hwaccel(avctx->codec->id, avctx->pix_fmt);
- if (avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT || avctx->hwaccel ||
- s->avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)
+ if( avctx->pix_fmt == PIX_FMT_XVMC_MPEG2_IDCT || avctx->hwaccel )
if (avctx->idct_algo == FF_IDCT_AUTO)
avctx->idct_algo = FF_IDCT_SIMPLE;
@@ -2070,8 +2103,22 @@ static int vcr2_init_sequence(AVCodecContext *avctx)
static void mpeg_decode_user_data(AVCodecContext *avctx,
const uint8_t *p, int buf_size)
{
+ Mpeg1Context *s = avctx->priv_data;
const uint8_t *buf_end = p + buf_size;
+ if(buf_size > 29){
+ int i;
+ for(i=0; i<20; i++)
+ if(!memcmp(p+i, "\0TMPGEXS\0", 9)){
+ s->tmpgexs= 1;
+ }
+
+/* for(i=0; !(!p[i-2] && !p[i-1] && p[i]==1) && i<buf_size; i++){
+ av_log(0,0, "%c", p[i]);
+ }
+ av_log(0,0, "\n");*/
+ }
+
/* we parse the DTG active format information */
if (buf_end - p >= 5 &&
p[0] == 'D' && p[1] == 'T' && p[2] == 'G' && p[3] == '1') {
@@ -2095,30 +2142,31 @@ static void mpeg_decode_gop(AVCodecContext *avctx,
Mpeg1Context *s1 = avctx->priv_data;
MpegEncContext *s = &s1->mpeg_enc_ctx;
+ int drop_frame_flag;
int time_code_hours, time_code_minutes;
int time_code_seconds, time_code_pictures;
int broken_link;
init_get_bits(&s->gb, buf, buf_size*8);
- skip_bits1(&s->gb); /* drop_frame_flag */
-
+ drop_frame_flag = get_bits(&s->gb, 1);
time_code_hours = get_bits(&s->gb, 5);
time_code_minutes = get_bits(&s->gb, 6);
skip_bits1(&s->gb); // marker bit
time_code_seconds = get_bits(&s->gb, 6);
time_code_pictures = get_bits(&s->gb, 6);
- s1->closed_gop = get_bits1(&s->gb);
+ s->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)*/
broken_link = get_bits1(&s->gb);
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",
+ av_log(s->avctx, AV_LOG_DEBUG, "GOP (%02d:%02d:%02d%c%02d) closed_gop=%d broken_link=%d\n",
time_code_hours, time_code_minutes, time_code_seconds,
- time_code_pictures, s1->closed_gop, broken_link);
+ drop_frame_flag ? ';' : ':',
+ time_code_pictures, s->closed_gop, broken_link);
}
/**
* Find the end of the current frame in the bitstream.
@@ -2250,15 +2298,17 @@ static int decode_chunks(AVCodecContext *avctx,
if (s2->pict_type != AV_PICTURE_TYPE_B || avctx->skip_frame <= AVDISCARD_DEFAULT) {
if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE)) {
int i;
+ av_assert0(avctx->thread_count > 1);
avctx->execute(avctx, slice_decode_thread, &s2->thread_context[0], NULL, s->slice_count, sizeof(void*));
for (i = 0; i < s->slice_count; i++)
s2->error_count += s2->thread_context[i]->error_count;
}
- if (CONFIG_MPEG_VDPAU_DECODER && avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU)
+ if (CONFIG_VDPAU && uses_vdpau(avctx))
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
*data_size = sizeof(AVPicture);
@@ -2279,7 +2329,8 @@ static int decode_chunks(AVCodecContext *avctx,
case SEQ_START_CODE:
if (last_code == 0) {
mpeg1_decode_sequence(avctx, buf_ptr, input_size);
- s->sync=1;
+ if(buf != avctx->extradata)
+ s->sync=1;
} else {
av_log(avctx, AV_LOG_ERROR, "ignoring SEQ_START_CODE after %X\n", last_code);
if (avctx->err_recognition & AV_EF_EXPLODE)
@@ -2288,6 +2339,10 @@ static int decode_chunks(AVCodecContext *avctx,
break;
case PICTURE_START_CODE:
+ if(s->tmpgexs){
+ s2->intra_dc_precision= 3;
+ s2->intra_matrix[0]= 1;
+ }
if (HAVE_THREADS && (avctx->active_thread_type & FF_THREAD_SLICE) && s->slice_count) {
int i;
@@ -2381,11 +2436,11 @@ static int decode_chunks(AVCodecContext *avctx,
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 (!s2->closed_gop)
break;
}
}
- if (s2->pict_type == AV_PICTURE_TYPE_I)
+ if (s2->pict_type == AV_PICTURE_TYPE_I || (s2->flags2 & CODEC_FLAG2_SHOW_ALL))
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. */
@@ -2421,13 +2476,14 @@ static int decode_chunks(AVCodecContext *avctx,
return AVERROR_INVALIDDATA;
}
- if (avctx->codec->capabilities & CODEC_CAP_HWACCEL_VDPAU) {
+ if (uses_vdpau(avctx)) {
s->slice_count++;
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 + avctx->thread_count/2) / avctx->thread_count;
+ av_assert0(avctx->thread_count > 1);
if (threshold <= mb_y) {
MpegEncContext *thread_context = s2->thread_context[s->slice_count];
@@ -2465,7 +2521,6 @@ static void flush(AVCodecContext *avctx)
Mpeg1Context *s = avctx->priv_data;
s->sync=0;
- s->closed_gop = 0;
ff_mpeg_flush(avctx);
}
@@ -2522,6 +2577,21 @@ AVCodec ff_mpeg2video_decoder = {
.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)
{
OpenPOWER on IntegriCloud