[FFmpeg-devel] [PATCH 2/2] mpegvideo: extract ff_print_debug_info2 to share between h264/mpeg.
Ronald S. Bultje
rsbultje at gmail.com
Sun Mar 3 01:57:27 CET 2013
From: "Ronald S. Bultje" <rsbultje at gmail.com>
---
libavcodec/Makefile | 5 +-
libavcodec/mpeg_picture.c | 409 ++++++++++++++++++++++++++++++++++++++++++++++
libavcodec/mpegvideo.c | 382 -------------------------------------------
3 files changed, 412 insertions(+), 384 deletions(-)
create mode 100644 libavcodec/mpeg_picture.c
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 52282e3..19a2e62 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -64,7 +64,8 @@ OBJS-$(CONFIG_MPEGAUDIODSP) += mpegaudiodsp.o \
mpegaudiodsp_data.o \
mpegaudiodsp_fixed.o \
mpegaudiodsp_float.o
-OBJS-$(CONFIG_MPEGVIDEO) += mpegvideo.o mpegvideo_motion.o
+OBJS-$(CONFIG_MPEGVIDEO) += mpegvideo.o mpegvideo_motion.o \
+ mpeg_picture.o
OBJS-$(CONFIG_MPEGVIDEOENC) += mpegvideo_enc.o mpeg12data.o \
motion_est.o ratecontrol.o
OBJS-$(CONFIG_RANGECODER) += rangecoder.o
@@ -223,7 +224,7 @@ OBJS-$(CONFIG_H263_VAAPI_HWACCEL) += vaapi_mpeg4.o
OBJS-$(CONFIG_H263_VDPAU_HWACCEL) += vdpau_mpeg4.o
OBJS-$(CONFIG_H263_ENCODER) += mpeg4videoenc.o mpeg4video.o \
h263.o ituh263enc.o flvenc.o
-OBJS-$(CONFIG_H264_DECODER) += h264.o \
+OBJS-$(CONFIG_H264_DECODER) += h264.o mpeg_picture.o \
h264_loopfilter.o h264_direct.o \
cabac.o h264_sei.o h264_ps.o \
h264_refs.o h264_cavlc.o h264_cabac.o
diff --git a/libavcodec/mpeg_picture.c b/libavcodec/mpeg_picture.c
new file mode 100644
index 0000000..ed558f5
--- /dev/null
+++ b/libavcodec/mpeg_picture.c
@@ -0,0 +1,409 @@
+/*
+ * The simplest mpeg encoder (well, it was the simplest!)
+ * Copyright (c) 2000,2001 Fabrice Bellard
+ * Copyright (c) 2002-2004 Michael Niedermayer <michaelni at gmx.at>
+ *
+ * 4MV & hq & B-frame encoding stuff by Michael Niedermayer <michaelni at gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * 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.
+ *
+ * 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 FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avcodec.h"
+#include "internal.h"
+#include "mpegvideo.h"
+
+/**
+ * Draw a line from (ex, ey) -> (sx, sy).
+ * @param w width of the image
+ * @param h height of the image
+ * @param stride stride/linesize of the image
+ * @param color color of the arrow
+ */
+static void draw_line(uint8_t *buf, int sx, int sy, int ex, int ey,
+ int w, int h, int stride, int color)
+{
+ int x, y, fr, f;
+
+ sx = av_clip(sx, 0, w - 1);
+ sy = av_clip(sy, 0, h - 1);
+ ex = av_clip(ex, 0, w - 1);
+ ey = av_clip(ey, 0, h - 1);
+
+ buf[sy * stride + sx] += color;
+
+ if (FFABS(ex - sx) > FFABS(ey - sy)) {
+ if (sx > ex) {
+ FFSWAP(int, sx, ex);
+ FFSWAP(int, sy, ey);
+ }
+ buf += sx + sy * stride;
+ ex -= sx;
+ f = ((ey - sy) << 16) / ex;
+ for (x = 0; x <= ex; x++) {
+ y = (x * f) >> 16;
+ fr = (x * f) & 0xFFFF;
+ buf[y * stride + x] += (color * (0x10000 - fr)) >> 16;
+ if(fr) buf[(y + 1) * stride + x] += (color * fr ) >> 16;
+ }
+ } else {
+ if (sy > ey) {
+ FFSWAP(int, sx, ex);
+ FFSWAP(int, sy, ey);
+ }
+ buf += sx + sy * stride;
+ ey -= sy;
+ if (ey)
+ f = ((ex - sx) << 16) / ey;
+ else
+ f = 0;
+ for(y= 0; y <= ey; y++){
+ x = (y*f) >> 16;
+ fr = (y*f) & 0xFFFF;
+ buf[y * stride + x] += (color * (0x10000 - fr)) >> 16;
+ if(fr) buf[y * stride + x + 1] += (color * fr ) >> 16;
+ }
+ }
+}
+
+/**
+ * Draw an arrow from (ex, ey) -> (sx, sy).
+ * @param w width of the image
+ * @param h height of the image
+ * @param stride stride/linesize of the image
+ * @param color color of the arrow
+ */
+static void draw_arrow(uint8_t *buf, int sx, int sy, int ex,
+ int ey, int w, int h, int stride, int color)
+{
+ int dx,dy;
+
+ sx = av_clip(sx, -100, w + 100);
+ sy = av_clip(sy, -100, h + 100);
+ ex = av_clip(ex, -100, w + 100);
+ ey = av_clip(ey, -100, h + 100);
+
+ dx = ex - sx;
+ dy = ey - sy;
+
+ if (dx * dx + dy * dy > 3 * 3) {
+ int rx = dx + dy;
+ int ry = -dx + dy;
+ int length = ff_sqrt((rx * rx + ry * ry) << 8);
+
+ // FIXME subpixel accuracy
+ rx = ROUNDED_DIV(rx * 3 << 4, length);
+ ry = ROUNDED_DIV(ry * 3 << 4, length);
+
+ draw_line(buf, sx, sy, sx + rx, sy + ry, w, h, stride, color);
+ draw_line(buf, sx, sy, sx - ry, sy + rx, w, h, stride, color);
+ }
+ draw_line(buf, sx, sy, ex, ey, w, h, stride, color);
+}
+
+/**
+ * Print debugging info for the given picture.
+ */
+void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict, uint8_t *mbskip_table,
+ uint8_t *visualization_buffer[3], int *low_delay,
+ int mb_width, int mb_height, int mb_stride, int quarter_sample)
+{
+ if ( avctx->hwaccel || !pict || !pict->mb_type
+ || (avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU))
+ return;
+
+
+ if (avctx->debug & (FF_DEBUG_SKIP | FF_DEBUG_QP | FF_DEBUG_MB_TYPE)) {
+ int x,y;
+
+ av_log(avctx, AV_LOG_DEBUG, "New frame, type: %c\n",
+ av_get_picture_type_char(pict->pict_type));
+ for (y = 0; y < mb_height; y++) {
+ for (x = 0; x < mb_width; x++) {
+ if (avctx->debug & FF_DEBUG_SKIP) {
+ int count = mbskip_table[x + y * mb_stride];
+ if (count > 9)
+ count = 9;
+ av_log(avctx, AV_LOG_DEBUG, "%1d", count);
+ }
+ if (avctx->debug & FF_DEBUG_QP) {
+ av_log(avctx, AV_LOG_DEBUG, "%2d",
+ pict->qscale_table[x + y * mb_stride]);
+ }
+ if (avctx->debug & FF_DEBUG_MB_TYPE) {
+ int mb_type = pict->mb_type[x + y * mb_stride];
+ // Type & MV direction
+ if (IS_PCM(mb_type))
+ av_log(avctx, AV_LOG_DEBUG, "P");
+ else if (IS_INTRA(mb_type) && IS_ACPRED(mb_type))
+ av_log(avctx, AV_LOG_DEBUG, "A");
+ else if (IS_INTRA4x4(mb_type))
+ av_log(avctx, AV_LOG_DEBUG, "i");
+ else if (IS_INTRA16x16(mb_type))
+ av_log(avctx, AV_LOG_DEBUG, "I");
+ else if (IS_DIRECT(mb_type) && IS_SKIP(mb_type))
+ av_log(avctx, AV_LOG_DEBUG, "d");
+ else if (IS_DIRECT(mb_type))
+ av_log(avctx, AV_LOG_DEBUG, "D");
+ else if (IS_GMC(mb_type) && IS_SKIP(mb_type))
+ av_log(avctx, AV_LOG_DEBUG, "g");
+ else if (IS_GMC(mb_type))
+ av_log(avctx, AV_LOG_DEBUG, "G");
+ else if (IS_SKIP(mb_type))
+ av_log(avctx, AV_LOG_DEBUG, "S");
+ else if (!USES_LIST(mb_type, 1))
+ av_log(avctx, AV_LOG_DEBUG, ">");
+ else if (!USES_LIST(mb_type, 0))
+ av_log(avctx, AV_LOG_DEBUG, "<");
+ else {
+ av_assert2(USES_LIST(mb_type, 0) && USES_LIST(mb_type, 1));
+ av_log(avctx, AV_LOG_DEBUG, "X");
+ }
+
+ // segmentation
+ if (IS_8X8(mb_type))
+ av_log(avctx, AV_LOG_DEBUG, "+");
+ else if (IS_16X8(mb_type))
+ av_log(avctx, AV_LOG_DEBUG, "-");
+ else if (IS_8X16(mb_type))
+ av_log(avctx, AV_LOG_DEBUG, "|");
+ else if (IS_INTRA(mb_type) || IS_16X16(mb_type))
+ av_log(avctx, AV_LOG_DEBUG, " ");
+ else
+ av_log(avctx, AV_LOG_DEBUG, "?");
+
+
+ if (IS_INTERLACED(mb_type))
+ av_log(avctx, AV_LOG_DEBUG, "=");
+ else
+ av_log(avctx, AV_LOG_DEBUG, " ");
+ }
+ }
+ av_log(avctx, AV_LOG_DEBUG, "\n");
+ }
+ }
+
+ if ((avctx->debug & (FF_DEBUG_VIS_QP | FF_DEBUG_VIS_MB_TYPE)) ||
+ (avctx->debug_mv)) {
+ const int shift = 1 + quarter_sample;
+ int mb_y;
+ uint8_t *ptr;
+ int i;
+ int h_chroma_shift, v_chroma_shift, block_height;
+ const int width = avctx->width;
+ const int height = avctx->height;
+ const int mv_sample_log2 = 4 - pict->motion_subsample_log2;
+ const int mv_stride = (mb_width << mv_sample_log2) +
+ (avctx->codec->id == AV_CODEC_ID_H264 ? 0 : 1);
+ *low_delay = 0; // needed to see the vectors without trashing the buffers
+
+ avcodec_get_chroma_sub_sample(avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift);
+
+ for (i = 0; i < 3; i++) {
+ size_t size= (i == 0) ? pict->linesize[i] * FFALIGN(height, 16):
+ pict->linesize[i] * FFALIGN(height, 16) >> v_chroma_shift;
+ visualization_buffer[i]= av_realloc(visualization_buffer[i], size);
+ memcpy(visualization_buffer[i], pict->data[i], size);
+ pict->data[i] = visualization_buffer[i];
+ }
+ pict->type = FF_BUFFER_TYPE_COPY;
+ pict->opaque= NULL;
+ ptr = pict->data[0];
+ block_height = 16 >> v_chroma_shift;
+
+ for (mb_y = 0; mb_y < mb_height; mb_y++) {
+ int mb_x;
+ for (mb_x = 0; mb_x < mb_width; mb_x++) {
+ const int mb_index = mb_x + mb_y * mb_stride;
+ if ((avctx->debug_mv) && pict->motion_val[0]) {
+ int type;
+ for (type = 0; type < 3; type++) {
+ int direction = 0;
+ switch (type) {
+ case 0:
+ if ((!(avctx->debug_mv & FF_DEBUG_VIS_MV_P_FOR)) ||
+ (pict->pict_type!= AV_PICTURE_TYPE_P))
+ continue;
+ direction = 0;
+ break;
+ case 1:
+ if ((!(avctx->debug_mv & FF_DEBUG_VIS_MV_B_FOR)) ||
+ (pict->pict_type!= AV_PICTURE_TYPE_B))
+ continue;
+ direction = 0;
+ break;
+ case 2:
+ if ((!(avctx->debug_mv & FF_DEBUG_VIS_MV_B_BACK)) ||
+ (pict->pict_type!= AV_PICTURE_TYPE_B))
+ continue;
+ direction = 1;
+ break;
+ }
+ if (!USES_LIST(pict->mb_type[mb_index], direction))
+ continue;
+
+ if (IS_8X8(pict->mb_type[mb_index])) {
+ int i;
+ for (i = 0; i < 4; i++) {
+ int sx = mb_x * 16 + 4 + 8 * (i & 1);
+ int sy = mb_y * 16 + 4 + 8 * (i >> 1);
+ int xy = (mb_x * 2 + (i & 1) +
+ (mb_y * 2 + (i >> 1)) * mv_stride) << (mv_sample_log2 - 1);
+ int mx = (pict->motion_val[direction][xy][0] >> shift) + sx;
+ int my = (pict->motion_val[direction][xy][1] >> shift) + sy;
+ draw_arrow(ptr, sx, sy, mx, my, width,
+ height, pict->linesize[0], 100);
+ }
+ } else if (IS_16X8(pict->mb_type[mb_index])) {
+ int i;
+ for (i = 0; i < 2; i++) {
+ int sx = mb_x * 16 + 8;
+ int sy = mb_y * 16 + 4 + 8 * i;
+ int xy = (mb_x * 2 + (mb_y * 2 + i) * mv_stride) << (mv_sample_log2 - 1);
+ int mx = (pict->motion_val[direction][xy][0] >> shift);
+ int my = (pict->motion_val[direction][xy][1] >> shift);
+
+ if (IS_INTERLACED(pict->mb_type[mb_index]))
+ my *= 2;
+
+ draw_arrow(ptr, sx, sy, mx + sx, my + sy, width,
+ height, pict->linesize[0], 100);
+ }
+ } else if (IS_8X16(pict->mb_type[mb_index])) {
+ int i;
+ for (i = 0; i < 2; i++) {
+ int sx = mb_x * 16 + 4 + 8 * i;
+ int sy = mb_y * 16 + 8;
+ int xy = (mb_x * 2 + i + mb_y * 2 * mv_stride) << (mv_sample_log2 - 1);
+ int mx = pict->motion_val[direction][xy][0] >> shift;
+ int my = pict->motion_val[direction][xy][1] >> shift;
+
+ if (IS_INTERLACED(pict->mb_type[mb_index]))
+ my *= 2;
+
+ draw_arrow(ptr, sx, sy, mx + sx, my + sy, width,
+ height, pict->linesize[0], 100);
+ }
+ } else {
+ int sx= mb_x * 16 + 8;
+ int sy= mb_y * 16 + 8;
+ int xy= (mb_x + mb_y * mv_stride) << mv_sample_log2;
+ int mx= (pict->motion_val[direction][xy][0]>>shift) + sx;
+ int my= (pict->motion_val[direction][xy][1]>>shift) + sy;
+ draw_arrow(ptr, sx, sy, mx, my, width, height, pict->linesize[0], 100);
+ }
+ }
+ }
+ if ((avctx->debug & FF_DEBUG_VIS_QP)) {
+ uint64_t c = (pict->qscale_table[mb_index] * 128 / 31) *
+ 0x0101010101010101ULL;
+ int y;
+ for (y = 0; y < block_height; y++) {
+ *(uint64_t *)(pict->data[1] + 8 * mb_x +
+ (block_height * mb_y + y) *
+ pict->linesize[1]) = c;
+ *(uint64_t *)(pict->data[2] + 8 * mb_x +
+ (block_height * mb_y + y) *
+ pict->linesize[2]) = c;
+ }
+ }
+ if ((avctx->debug & FF_DEBUG_VIS_MB_TYPE) &&
+ pict->motion_val[0]) {
+ int mb_type = pict->mb_type[mb_index];
+ uint64_t u,v;
+ int y;
+#define COLOR(theta, r) \
+ u = (int)(128 + r * cos(theta * 3.141592 / 180)); \
+ v = (int)(128 + r * sin(theta * 3.141592 / 180));
+
+
+ u = v = 128;
+ if (IS_PCM(mb_type)) {
+ COLOR(120, 48)
+ } else if ((IS_INTRA(mb_type) && IS_ACPRED(mb_type)) ||
+ IS_INTRA16x16(mb_type)) {
+ COLOR(30, 48)
+ } else if (IS_INTRA4x4(mb_type)) {
+ COLOR(90, 48)
+ } else if (IS_DIRECT(mb_type) && IS_SKIP(mb_type)) {
+ // COLOR(120, 48)
+ } else if (IS_DIRECT(mb_type)) {
+ COLOR(150, 48)
+ } else if (IS_GMC(mb_type) && IS_SKIP(mb_type)) {
+ COLOR(170, 48)
+ } else if (IS_GMC(mb_type)) {
+ COLOR(190, 48)
+ } else if (IS_SKIP(mb_type)) {
+ // COLOR(180, 48)
+ } else if (!USES_LIST(mb_type, 1)) {
+ COLOR(240, 48)
+ } else if (!USES_LIST(mb_type, 0)) {
+ COLOR(0, 48)
+ } else {
+ av_assert2(USES_LIST(mb_type, 0) && USES_LIST(mb_type, 1));
+ COLOR(300,48)
+ }
+
+ u *= 0x0101010101010101ULL;
+ v *= 0x0101010101010101ULL;
+ for (y = 0; y < block_height; y++) {
+ *(uint64_t *)(pict->data[1] + 8 * mb_x +
+ (block_height * mb_y + y) * pict->linesize[1]) = u;
+ *(uint64_t *)(pict->data[2] + 8 * mb_x +
+ (block_height * mb_y + y) * pict->linesize[2]) = v;
+ }
+
+ // segmentation
+ if (IS_8X8(mb_type) || IS_16X8(mb_type)) {
+ *(uint64_t *)(pict->data[0] + 16 * mb_x + 0 +
+ (16 * mb_y + 8) * pict->linesize[0]) ^= 0x8080808080808080ULL;
+ *(uint64_t *)(pict->data[0] + 16 * mb_x + 8 +
+ (16 * mb_y + 8) * pict->linesize[0]) ^= 0x8080808080808080ULL;
+ }
+ if (IS_8X8(mb_type) || IS_8X16(mb_type)) {
+ for (y = 0; y < 16; y++)
+ pict->data[0][16 * mb_x + 8 + (16 * mb_y + y) *
+ pict->linesize[0]] ^= 0x80;
+ }
+ if (IS_8X8(mb_type) && mv_sample_log2 >= 2) {
+ int dm = 1 << (mv_sample_log2 - 2);
+ for (i = 0; i < 4; i++) {
+ int sx = mb_x * 16 + 8 * (i & 1);
+ int sy = mb_y * 16 + 8 * (i >> 1);
+ int xy = (mb_x * 2 + (i & 1) +
+ (mb_y * 2 + (i >> 1)) * mv_stride) << (mv_sample_log2 - 1);
+ // FIXME bidir
+ int32_t *mv = (int32_t *) &pict->motion_val[0][xy];
+ if (mv[0] != mv[dm] ||
+ mv[dm * mv_stride] != mv[dm * (mv_stride + 1)])
+ for (y = 0; y < 8; y++)
+ pict->data[0][sx + 4 + (sy + y) * pict->linesize[0]] ^= 0x80;
+ if (mv[0] != mv[dm * mv_stride] || mv[dm] != mv[dm * (mv_stride + 1)])
+ *(uint64_t *)(pict->data[0] + sx + (sy + 4) *
+ pict->linesize[0]) ^= 0x8080808080808080ULL;
+ }
+ }
+
+ if (IS_INTERLACED(mb_type) &&
+ avctx->codec->id == AV_CODEC_ID_H264) {
+ // hmm
+ }
+ }
+ mbskip_table[mb_index] = 0;
+ }
+ }
+ }
+}
diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c
index 66a7ed5..c3e9b47 100644
--- a/libavcodec/mpegvideo.c
+++ b/libavcodec/mpegvideo.c
@@ -1704,388 +1704,6 @@ void ff_MPV_frame_end(MpegEncContext *s)
}
}
-/**
- * Draw a line from (ex, ey) -> (sx, sy).
- * @param w width of the image
- * @param h height of the image
- * @param stride stride/linesize of the image
- * @param color color of the arrow
- */
-static void draw_line(uint8_t *buf, int sx, int sy, int ex, int ey,
- int w, int h, int stride, int color)
-{
- int x, y, fr, f;
-
- sx = av_clip(sx, 0, w - 1);
- sy = av_clip(sy, 0, h - 1);
- ex = av_clip(ex, 0, w - 1);
- ey = av_clip(ey, 0, h - 1);
-
- buf[sy * stride + sx] += color;
-
- if (FFABS(ex - sx) > FFABS(ey - sy)) {
- if (sx > ex) {
- FFSWAP(int, sx, ex);
- FFSWAP(int, sy, ey);
- }
- buf += sx + sy * stride;
- ex -= sx;
- f = ((ey - sy) << 16) / ex;
- for (x = 0; x <= ex; x++) {
- y = (x * f) >> 16;
- fr = (x * f) & 0xFFFF;
- buf[y * stride + x] += (color * (0x10000 - fr)) >> 16;
- if(fr) buf[(y + 1) * stride + x] += (color * fr ) >> 16;
- }
- } else {
- if (sy > ey) {
- FFSWAP(int, sx, ex);
- FFSWAP(int, sy, ey);
- }
- buf += sx + sy * stride;
- ey -= sy;
- if (ey)
- f = ((ex - sx) << 16) / ey;
- else
- f = 0;
- for(y= 0; y <= ey; y++){
- x = (y*f) >> 16;
- fr = (y*f) & 0xFFFF;
- buf[y * stride + x] += (color * (0x10000 - fr)) >> 16;
- if(fr) buf[y * stride + x + 1] += (color * fr ) >> 16;
- }
- }
-}
-
-/**
- * Draw an arrow from (ex, ey) -> (sx, sy).
- * @param w width of the image
- * @param h height of the image
- * @param stride stride/linesize of the image
- * @param color color of the arrow
- */
-static void draw_arrow(uint8_t *buf, int sx, int sy, int ex,
- int ey, int w, int h, int stride, int color)
-{
- int dx,dy;
-
- sx = av_clip(sx, -100, w + 100);
- sy = av_clip(sy, -100, h + 100);
- ex = av_clip(ex, -100, w + 100);
- ey = av_clip(ey, -100, h + 100);
-
- dx = ex - sx;
- dy = ey - sy;
-
- if (dx * dx + dy * dy > 3 * 3) {
- int rx = dx + dy;
- int ry = -dx + dy;
- int length = ff_sqrt((rx * rx + ry * ry) << 8);
-
- // FIXME subpixel accuracy
- rx = ROUNDED_DIV(rx * 3 << 4, length);
- ry = ROUNDED_DIV(ry * 3 << 4, length);
-
- draw_line(buf, sx, sy, sx + rx, sy + ry, w, h, stride, color);
- draw_line(buf, sx, sy, sx - ry, sy + rx, w, h, stride, color);
- }
- draw_line(buf, sx, sy, ex, ey, w, h, stride, color);
-}
-
-/**
- * Print debugging info for the given picture.
- */
-void ff_print_debug_info2(AVCodecContext *avctx, AVFrame *pict, uint8_t *mbskip_table,
- uint8_t *visualization_buffer[3], int *low_delay,
- int mb_width, int mb_height, int mb_stride, int quarter_sample)
-{
- if ( avctx->hwaccel || !pict || !pict->mb_type
- || (avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU))
- return;
-
-
- if (avctx->debug & (FF_DEBUG_SKIP | FF_DEBUG_QP | FF_DEBUG_MB_TYPE)) {
- int x,y;
-
- av_log(avctx, AV_LOG_DEBUG, "New frame, type: %c\n",
- av_get_picture_type_char(pict->pict_type));
- for (y = 0; y < mb_height; y++) {
- for (x = 0; x < mb_width; x++) {
- if (avctx->debug & FF_DEBUG_SKIP) {
- int count = mbskip_table[x + y * mb_stride];
- if (count > 9)
- count = 9;
- av_log(avctx, AV_LOG_DEBUG, "%1d", count);
- }
- if (avctx->debug & FF_DEBUG_QP) {
- av_log(avctx, AV_LOG_DEBUG, "%2d",
- pict->qscale_table[x + y * mb_stride]);
- }
- if (avctx->debug & FF_DEBUG_MB_TYPE) {
- int mb_type = pict->mb_type[x + y * mb_stride];
- // Type & MV direction
- if (IS_PCM(mb_type))
- av_log(avctx, AV_LOG_DEBUG, "P");
- else if (IS_INTRA(mb_type) && IS_ACPRED(mb_type))
- av_log(avctx, AV_LOG_DEBUG, "A");
- else if (IS_INTRA4x4(mb_type))
- av_log(avctx, AV_LOG_DEBUG, "i");
- else if (IS_INTRA16x16(mb_type))
- av_log(avctx, AV_LOG_DEBUG, "I");
- else if (IS_DIRECT(mb_type) && IS_SKIP(mb_type))
- av_log(avctx, AV_LOG_DEBUG, "d");
- else if (IS_DIRECT(mb_type))
- av_log(avctx, AV_LOG_DEBUG, "D");
- else if (IS_GMC(mb_type) && IS_SKIP(mb_type))
- av_log(avctx, AV_LOG_DEBUG, "g");
- else if (IS_GMC(mb_type))
- av_log(avctx, AV_LOG_DEBUG, "G");
- else if (IS_SKIP(mb_type))
- av_log(avctx, AV_LOG_DEBUG, "S");
- else if (!USES_LIST(mb_type, 1))
- av_log(avctx, AV_LOG_DEBUG, ">");
- else if (!USES_LIST(mb_type, 0))
- av_log(avctx, AV_LOG_DEBUG, "<");
- else {
- av_assert2(USES_LIST(mb_type, 0) && USES_LIST(mb_type, 1));
- av_log(avctx, AV_LOG_DEBUG, "X");
- }
-
- // segmentation
- if (IS_8X8(mb_type))
- av_log(avctx, AV_LOG_DEBUG, "+");
- else if (IS_16X8(mb_type))
- av_log(avctx, AV_LOG_DEBUG, "-");
- else if (IS_8X16(mb_type))
- av_log(avctx, AV_LOG_DEBUG, "|");
- else if (IS_INTRA(mb_type) || IS_16X16(mb_type))
- av_log(avctx, AV_LOG_DEBUG, " ");
- else
- av_log(avctx, AV_LOG_DEBUG, "?");
-
-
- if (IS_INTERLACED(mb_type))
- av_log(avctx, AV_LOG_DEBUG, "=");
- else
- av_log(avctx, AV_LOG_DEBUG, " ");
- }
- }
- av_log(avctx, AV_LOG_DEBUG, "\n");
- }
- }
-
- if ((avctx->debug & (FF_DEBUG_VIS_QP | FF_DEBUG_VIS_MB_TYPE)) ||
- (avctx->debug_mv)) {
- const int shift = 1 + quarter_sample;
- int mb_y;
- uint8_t *ptr;
- int i;
- int h_chroma_shift, v_chroma_shift, block_height;
- const int width = avctx->width;
- const int height = avctx->height;
- const int mv_sample_log2 = 4 - pict->motion_subsample_log2;
- const int mv_stride = (mb_width << mv_sample_log2) +
- (avctx->codec->id == AV_CODEC_ID_H264 ? 0 : 1);
- *low_delay = 0; // needed to see the vectors without trashing the buffers
-
- avcodec_get_chroma_sub_sample(avctx->pix_fmt, &h_chroma_shift, &v_chroma_shift);
-
- for (i = 0; i < 3; i++) {
- size_t size= (i == 0) ? pict->linesize[i] * FFALIGN(height, 16):
- pict->linesize[i] * FFALIGN(height, 16) >> v_chroma_shift;
- visualization_buffer[i]= av_realloc(visualization_buffer[i], size);
- memcpy(visualization_buffer[i], pict->data[i], size);
- pict->data[i] = visualization_buffer[i];
- }
- pict->type = FF_BUFFER_TYPE_COPY;
- pict->opaque= NULL;
- ptr = pict->data[0];
- block_height = 16 >> v_chroma_shift;
-
- for (mb_y = 0; mb_y < mb_height; mb_y++) {
- int mb_x;
- for (mb_x = 0; mb_x < mb_width; mb_x++) {
- const int mb_index = mb_x + mb_y * mb_stride;
- if ((avctx->debug_mv) && pict->motion_val[0]) {
- int type;
- for (type = 0; type < 3; type++) {
- int direction = 0;
- switch (type) {
- case 0:
- if ((!(avctx->debug_mv & FF_DEBUG_VIS_MV_P_FOR)) ||
- (pict->pict_type!= AV_PICTURE_TYPE_P))
- continue;
- direction = 0;
- break;
- case 1:
- if ((!(avctx->debug_mv & FF_DEBUG_VIS_MV_B_FOR)) ||
- (pict->pict_type!= AV_PICTURE_TYPE_B))
- continue;
- direction = 0;
- break;
- case 2:
- if ((!(avctx->debug_mv & FF_DEBUG_VIS_MV_B_BACK)) ||
- (pict->pict_type!= AV_PICTURE_TYPE_B))
- continue;
- direction = 1;
- break;
- }
- if (!USES_LIST(pict->mb_type[mb_index], direction))
- continue;
-
- if (IS_8X8(pict->mb_type[mb_index])) {
- int i;
- for (i = 0; i < 4; i++) {
- int sx = mb_x * 16 + 4 + 8 * (i & 1);
- int sy = mb_y * 16 + 4 + 8 * (i >> 1);
- int xy = (mb_x * 2 + (i & 1) +
- (mb_y * 2 + (i >> 1)) * mv_stride) << (mv_sample_log2 - 1);
- int mx = (pict->motion_val[direction][xy][0] >> shift) + sx;
- int my = (pict->motion_val[direction][xy][1] >> shift) + sy;
- draw_arrow(ptr, sx, sy, mx, my, width,
- height, pict->linesize[0], 100);
- }
- } else if (IS_16X8(pict->mb_type[mb_index])) {
- int i;
- for (i = 0; i < 2; i++) {
- int sx = mb_x * 16 + 8;
- int sy = mb_y * 16 + 4 + 8 * i;
- int xy = (mb_x * 2 + (mb_y * 2 + i) * mv_stride) << (mv_sample_log2 - 1);
- int mx = (pict->motion_val[direction][xy][0] >> shift);
- int my = (pict->motion_val[direction][xy][1] >> shift);
-
- if (IS_INTERLACED(pict->mb_type[mb_index]))
- my *= 2;
-
- draw_arrow(ptr, sx, sy, mx + sx, my + sy, width,
- height, pict->linesize[0], 100);
- }
- } else if (IS_8X16(pict->mb_type[mb_index])) {
- int i;
- for (i = 0; i < 2; i++) {
- int sx = mb_x * 16 + 4 + 8 * i;
- int sy = mb_y * 16 + 8;
- int xy = (mb_x * 2 + i + mb_y * 2 * mv_stride) << (mv_sample_log2 - 1);
- int mx = pict->motion_val[direction][xy][0] >> shift;
- int my = pict->motion_val[direction][xy][1] >> shift;
-
- if (IS_INTERLACED(pict->mb_type[mb_index]))
- my *= 2;
-
- draw_arrow(ptr, sx, sy, mx + sx, my + sy, width,
- height, pict->linesize[0], 100);
- }
- } else {
- int sx= mb_x * 16 + 8;
- int sy= mb_y * 16 + 8;
- int xy= (mb_x + mb_y * mv_stride) << mv_sample_log2;
- int mx= (pict->motion_val[direction][xy][0]>>shift) + sx;
- int my= (pict->motion_val[direction][xy][1]>>shift) + sy;
- draw_arrow(ptr, sx, sy, mx, my, width, height, pict->linesize[0], 100);
- }
- }
- }
- if ((avctx->debug & FF_DEBUG_VIS_QP)) {
- uint64_t c = (pict->qscale_table[mb_index] * 128 / 31) *
- 0x0101010101010101ULL;
- int y;
- for (y = 0; y < block_height; y++) {
- *(uint64_t *)(pict->data[1] + 8 * mb_x +
- (block_height * mb_y + y) *
- pict->linesize[1]) = c;
- *(uint64_t *)(pict->data[2] + 8 * mb_x +
- (block_height * mb_y + y) *
- pict->linesize[2]) = c;
- }
- }
- if ((avctx->debug & FF_DEBUG_VIS_MB_TYPE) &&
- pict->motion_val[0]) {
- int mb_type = pict->mb_type[mb_index];
- uint64_t u,v;
- int y;
-#define COLOR(theta, r) \
- u = (int)(128 + r * cos(theta * 3.141592 / 180)); \
- v = (int)(128 + r * sin(theta * 3.141592 / 180));
-
-
- u = v = 128;
- if (IS_PCM(mb_type)) {
- COLOR(120, 48)
- } else if ((IS_INTRA(mb_type) && IS_ACPRED(mb_type)) ||
- IS_INTRA16x16(mb_type)) {
- COLOR(30, 48)
- } else if (IS_INTRA4x4(mb_type)) {
- COLOR(90, 48)
- } else if (IS_DIRECT(mb_type) && IS_SKIP(mb_type)) {
- // COLOR(120, 48)
- } else if (IS_DIRECT(mb_type)) {
- COLOR(150, 48)
- } else if (IS_GMC(mb_type) && IS_SKIP(mb_type)) {
- COLOR(170, 48)
- } else if (IS_GMC(mb_type)) {
- COLOR(190, 48)
- } else if (IS_SKIP(mb_type)) {
- // COLOR(180, 48)
- } else if (!USES_LIST(mb_type, 1)) {
- COLOR(240, 48)
- } else if (!USES_LIST(mb_type, 0)) {
- COLOR(0, 48)
- } else {
- av_assert2(USES_LIST(mb_type, 0) && USES_LIST(mb_type, 1));
- COLOR(300,48)
- }
-
- u *= 0x0101010101010101ULL;
- v *= 0x0101010101010101ULL;
- for (y = 0; y < block_height; y++) {
- *(uint64_t *)(pict->data[1] + 8 * mb_x +
- (block_height * mb_y + y) * pict->linesize[1]) = u;
- *(uint64_t *)(pict->data[2] + 8 * mb_x +
- (block_height * mb_y + y) * pict->linesize[2]) = v;
- }
-
- // segmentation
- if (IS_8X8(mb_type) || IS_16X8(mb_type)) {
- *(uint64_t *)(pict->data[0] + 16 * mb_x + 0 +
- (16 * mb_y + 8) * pict->linesize[0]) ^= 0x8080808080808080ULL;
- *(uint64_t *)(pict->data[0] + 16 * mb_x + 8 +
- (16 * mb_y + 8) * pict->linesize[0]) ^= 0x8080808080808080ULL;
- }
- if (IS_8X8(mb_type) || IS_8X16(mb_type)) {
- for (y = 0; y < 16; y++)
- pict->data[0][16 * mb_x + 8 + (16 * mb_y + y) *
- pict->linesize[0]] ^= 0x80;
- }
- if (IS_8X8(mb_type) && mv_sample_log2 >= 2) {
- int dm = 1 << (mv_sample_log2 - 2);
- for (i = 0; i < 4; i++) {
- int sx = mb_x * 16 + 8 * (i & 1);
- int sy = mb_y * 16 + 8 * (i >> 1);
- int xy = (mb_x * 2 + (i & 1) +
- (mb_y * 2 + (i >> 1)) * mv_stride) << (mv_sample_log2 - 1);
- // FIXME bidir
- int32_t *mv = (int32_t *) &pict->motion_val[0][xy];
- if (mv[0] != mv[dm] ||
- mv[dm * mv_stride] != mv[dm * (mv_stride + 1)])
- for (y = 0; y < 8; y++)
- pict->data[0][sx + 4 + (sy + y) * pict->linesize[0]] ^= 0x80;
- if (mv[0] != mv[dm * mv_stride] || mv[dm] != mv[dm * (mv_stride + 1)])
- *(uint64_t *)(pict->data[0] + sx + (sy + 4) *
- pict->linesize[0]) ^= 0x8080808080808080ULL;
- }
- }
-
- if (IS_INTERLACED(mb_type) &&
- avctx->codec->id == AV_CODEC_ID_H264) {
- // hmm
- }
- }
- mbskip_table[mb_index] = 0;
- }
- }
- }
-}
-
void ff_print_debug_info(MpegEncContext *s, AVFrame *pict)
{
ff_print_debug_info2(s->avctx, pict, s->mbskip_table, s->visualization_buffer, &s->low_delay,
--
1.7.11.3
More information about the ffmpeg-devel
mailing list