Original patch by NVIDIA corporation.
Originally committed as revision 16431 to svn://svn.ffmpeg.org/ffmpeg/trunk
| ... | ... |
@@ -975,6 +975,7 @@ h261_encoder_select="aandct" |
| 975 | 975 |
h263_encoder_select="aandct" |
| 976 | 976 |
h263p_encoder_select="aandct" |
| 977 | 977 |
h264_decoder_select="golomb" |
| 978 |
+h264_vdpau_decoder_deps="vdpau" |
|
| 978 | 979 |
imc_decoder_select="fft mdct" |
| 979 | 980 |
jpegls_decoder_select="golomb" |
| 980 | 981 |
jpegls_encoder_select="golomb" |
| ... | ... |
@@ -100,6 +100,7 @@ OBJS-$(CONFIG_H263_ENCODER) += mpegvideo_enc.o motion_est.o ratecontr |
| 100 | 100 |
OBJS-$(CONFIG_H263P_ENCODER) += mpegvideo_enc.o motion_est.o ratecontrol.o h263.o mpeg12data.o mpegvideo.o error_resilience.o |
| 101 | 101 |
OBJS-$(CONFIG_H264_DECODER) += h264.o h264idct.o h264pred.o h264_parser.o cabac.o mpegvideo.o error_resilience.o |
| 102 | 102 |
OBJS-$(CONFIG_H264_ENCODER) += h264enc.o h264dspenc.o |
| 103 |
+OBJS-$(CONFIG_H264_VDPAU_DECODER) += vdpauvideo.o |
|
| 103 | 104 |
OBJS-$(CONFIG_HUFFYUV_DECODER) += huffyuv.o |
| 104 | 105 |
OBJS-$(CONFIG_HUFFYUV_ENCODER) += huffyuv.o |
| 105 | 106 |
OBJS-$(CONFIG_IDCIN_DECODER) += idcinvideo.o |
| ... | ... |
@@ -88,6 +88,7 @@ void avcodec_register_all(void) |
| 88 | 88 |
REGISTER_DECODER (H263I, h263i); |
| 89 | 89 |
REGISTER_ENCODER (H263P, h263p); |
| 90 | 90 |
REGISTER_DECODER (H264, h264); |
| 91 |
+ REGISTER_DECODER (H264_VDPAU, h264_vdpau); |
|
| 91 | 92 |
REGISTER_ENCDEC (HUFFYUV, huffyuv); |
| 92 | 93 |
REGISTER_DECODER (IDCIN, idcin); |
| 93 | 94 |
REGISTER_DECODER (INDEO2, indeo2); |
| ... | ... |
@@ -191,6 +191,9 @@ enum CodecID {
|
| 191 | 191 |
CODEC_ID_TGV, |
| 192 | 192 |
CODEC_ID_TGQ, |
| 193 | 193 |
|
| 194 |
+ /* "codecs" for HW decoding with VDPAU */ |
|
| 195 |
+ CODEC_ID_H264_VDPAU= 0x9000, |
|
| 196 |
+ |
|
| 194 | 197 |
/* various PCM "codecs" */ |
| 195 | 198 |
CODEC_ID_PCM_S16LE= 0x10000, |
| 196 | 199 |
CODEC_ID_PCM_S16BE, |
| ... | ... |
@@ -527,6 +530,10 @@ typedef struct RcOverride{
|
| 527 | 527 |
* This can be used to prevent truncation of the last audio samples. |
| 528 | 528 |
*/ |
| 529 | 529 |
#define CODEC_CAP_SMALL_LAST_FRAME 0x0040 |
| 530 |
+/** |
|
| 531 |
+ * Codec can export data for HW decoding (VDPAU). |
|
| 532 |
+ */ |
|
| 533 |
+#define CODEC_CAP_HWACCEL_VDPAU 0x0080 |
|
| 530 | 534 |
|
| 531 | 535 |
//The following defines may change, don't expect compatibility if you use them. |
| 532 | 536 |
#define MB_TYPE_INTRA4x4 0x0001 |
| ... | ... |
@@ -33,6 +33,7 @@ |
| 33 | 33 |
#include "h264_parser.h" |
| 34 | 34 |
#include "golomb.h" |
| 35 | 35 |
#include "rectangle.h" |
| 36 |
+#include "vdpau_internal.h" |
|
| 36 | 37 |
|
| 37 | 38 |
#include "cabac.h" |
| 38 | 39 |
#ifdef ARCH_X86 |
| ... | ... |
@@ -2188,6 +2189,8 @@ static av_cold int decode_init(AVCodecContext *avctx){
|
| 2188 | 2188 |
|
| 2189 | 2189 |
if(avctx->codec_id == CODEC_ID_SVQ3) |
| 2190 | 2190 |
avctx->pix_fmt= PIX_FMT_YUVJ420P; |
| 2191 |
+ else if(avctx->codec_id == CODEC_ID_H264_VDPAU) |
|
| 2192 |
+ avctx->pix_fmt= PIX_FMT_VDPAU_H264; |
|
| 2191 | 2193 |
else |
| 2192 | 2194 |
avctx->pix_fmt= PIX_FMT_YUV420P; |
| 2193 | 2195 |
|
| ... | ... |
@@ -7289,6 +7292,8 @@ static void execute_decode_slices(H264Context *h, int context_count){
|
| 7289 | 7289 |
H264Context *hx; |
| 7290 | 7290 |
int i; |
| 7291 | 7291 |
|
| 7292 |
+ if(avctx->codec_id == CODEC_ID_H264_VDPAU) |
|
| 7293 |
+ return; |
|
| 7292 | 7294 |
if(context_count == 1) {
|
| 7293 | 7295 |
decode_slice(avctx, &h); |
| 7294 | 7296 |
} else {
|
| ... | ... |
@@ -7416,8 +7421,14 @@ static int decode_nal_units(H264Context *h, const uint8_t *buf, int buf_size){
|
| 7416 | 7416 |
&& (avctx->skip_frame < AVDISCARD_NONREF || hx->nal_ref_idc) |
| 7417 | 7417 |
&& (avctx->skip_frame < AVDISCARD_BIDIR || hx->slice_type_nos!=FF_B_TYPE) |
| 7418 | 7418 |
&& (avctx->skip_frame < AVDISCARD_NONKEY || hx->slice_type_nos==FF_I_TYPE) |
| 7419 |
- && avctx->skip_frame < AVDISCARD_ALL) |
|
| 7419 |
+ && avctx->skip_frame < AVDISCARD_ALL){
|
|
| 7420 |
+ if(ENABLE_H264_VDPAU_DECODER && avctx->codec_id == CODEC_ID_H264_VDPAU){
|
|
| 7421 |
+ static const uint8_t start_code[] = {0x00, 0x00, 0x01};
|
|
| 7422 |
+ ff_VDPAU_h264_add_data_chunk(h, start_code, sizeof(start_code)); |
|
| 7423 |
+ ff_VDPAU_h264_add_data_chunk(h, &buf[buf_index - consumed], consumed ); |
|
| 7424 |
+ }else |
|
| 7420 | 7425 |
context_count++; |
| 7426 |
+ } |
|
| 7421 | 7427 |
break; |
| 7422 | 7428 |
case NAL_DPA: |
| 7423 | 7429 |
init_get_bits(&hx->s.gb, ptr, bit_length); |
| ... | ... |
@@ -7620,6 +7631,9 @@ static int decode_frame(AVCodecContext *avctx, |
| 7620 | 7620 |
h->prev_frame_num_offset= h->frame_num_offset; |
| 7621 | 7621 |
h->prev_frame_num= h->frame_num; |
| 7622 | 7622 |
|
| 7623 |
+ if (ENABLE_H264_VDPAU_DECODER && avctx->codec_id == CODEC_ID_H264_VDPAU) |
|
| 7624 |
+ ff_VDPAU_h264_picture_complete(h); |
|
| 7625 |
+ |
|
| 7623 | 7626 |
/* |
| 7624 | 7627 |
* FIXME: Error handling code does not seem to support interlaced |
| 7625 | 7628 |
* when slices span multiple rows |
| ... | ... |
@@ -7632,7 +7646,7 @@ static int decode_frame(AVCodecContext *avctx, |
| 7632 | 7632 |
* past end by one (callers fault) and resync_mb_y != 0 |
| 7633 | 7633 |
* causes problems for the first MB line, too. |
| 7634 | 7634 |
*/ |
| 7635 |
- if (!FIELD_PICTURE) |
|
| 7635 |
+ if (!avctx->codec_id == CODEC_ID_H264_VDPAU && !FIELD_PICTURE) |
|
| 7636 | 7636 |
ff_er_frame_end(s); |
| 7637 | 7637 |
|
| 7638 | 7638 |
MPV_frame_end(s); |
| ... | ... |
@@ -8005,4 +8019,20 @@ AVCodec h264_decoder = {
|
| 8005 | 8005 |
.long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"),
|
| 8006 | 8006 |
}; |
| 8007 | 8007 |
|
| 8008 |
+#ifdef CONFIG_H264_VDPAU_DECODER |
|
| 8009 |
+AVCodec h264_vdpau_decoder = {
|
|
| 8010 |
+ "h264_vdpau", |
|
| 8011 |
+ CODEC_TYPE_VIDEO, |
|
| 8012 |
+ CODEC_ID_H264_VDPAU, |
|
| 8013 |
+ sizeof(H264Context), |
|
| 8014 |
+ decode_init, |
|
| 8015 |
+ NULL, |
|
| 8016 |
+ decode_end, |
|
| 8017 |
+ decode_frame, |
|
| 8018 |
+ CODEC_CAP_DR1 | CODEC_CAP_DELAY | CODEC_CAP_HWACCEL_VDPAU, |
|
| 8019 |
+ .flush= flush_dpb, |
|
| 8020 |
+ .long_name = NULL_IF_CONFIG_SMALL("H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (VDPAU acceleration)"),
|
|
| 8021 |
+}; |
|
| 8022 |
+#endif |
|
| 8023 |
+ |
|
| 8008 | 8024 |
#include "svq3.c" |
| ... | ... |
@@ -267,6 +267,9 @@ static const PixFmtInfo pix_fmt_info[PIX_FMT_NB] = {
|
| 267 | 267 |
[PIX_FMT_XVMC_MPEG2_IDCT] = {
|
| 268 | 268 |
.name = "xvmcidct", |
| 269 | 269 |
}, |
| 270 |
+ [PIX_FMT_VDPAU_H264] = {
|
|
| 271 |
+ .name = "vdpau_h264", |
|
| 272 |
+ }, |
|
| 270 | 273 |
[PIX_FMT_UYYVYY411] = {
|
| 271 | 274 |
.name = "uyyvyy411", |
| 272 | 275 |
.nb_channels = 1, |
| ... | ... |
@@ -957,7 +957,11 @@ void MPV_frame_end(MpegEncContext *s) |
| 957 | 957 |
XVMC_field_end(s); |
| 958 | 958 |
}else |
| 959 | 959 |
#endif |
| 960 |
- if(s->unrestricted_mv && s->current_picture.reference && !s->intra_only && !(s->flags&CODEC_FLAG_EMU_EDGE)) {
|
|
| 960 |
+ if(!(s->avctx->codec->capabilities&CODEC_CAP_HWACCEL_VDPAU) |
|
| 961 |
+ && s->unrestricted_mv |
|
| 962 |
+ && s->current_picture.reference |
|
| 963 |
+ && !s->intra_only |
|
| 964 |
+ && !(s->flags&CODEC_FLAG_EMU_EDGE)) {
|
|
| 961 | 965 |
s->dsp.draw_edges(s->current_picture.data[0], s->linesize , s->h_edge_pos , s->v_edge_pos , EDGE_WIDTH ); |
| 962 | 966 |
s->dsp.draw_edges(s->current_picture.data[1], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2); |
| 963 | 967 |
s->dsp.draw_edges(s->current_picture.data[2], s->uvlinesize, s->h_edge_pos>>1, s->v_edge_pos>>1, EDGE_WIDTH/2); |
| 964 | 968 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,31 @@ |
| 0 |
+/* |
|
| 1 |
+ * Video Decode and Presentation API for UNIX (VDPAU) is used for |
|
| 2 |
+ * HW decode acceleration for MPEG-1/2, H.264 and VC-1. |
|
| 3 |
+ * |
|
| 4 |
+ * Copyright (C) 2008 NVIDIA. |
|
| 5 |
+ * |
|
| 6 |
+ * This file is part of FFmpeg. |
|
| 7 |
+ * |
|
| 8 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
| 9 |
+ * modify it under the terms of the GNU Lesser General Public |
|
| 10 |
+ * License as published by the Free Software Foundation; either |
|
| 11 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
| 12 |
+ * |
|
| 13 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
| 14 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 15 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 16 |
+ * Lesser General Public License for more details. |
|
| 17 |
+ * |
|
| 18 |
+ * You should have received a copy of the GNU Lesser General Public |
|
| 19 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
| 20 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
| 21 |
+ */ |
|
| 22 |
+ |
|
| 23 |
+#ifndef AVCODEC_VDPAU_INTERNAL_H |
|
| 24 |
+#define AVCODEC_VDPAU_INTERNAL_H |
|
| 25 |
+ |
|
| 26 |
+void ff_VDPAU_h264_add_data_chunk(H264Context *h, const uint8_t *buf, |
|
| 27 |
+ int buf_size); |
|
| 28 |
+void ff_VDPAU_h264_picture_complete(H264Context *h); |
|
| 29 |
+ |
|
| 30 |
+#endif /* AVCODEC_VDPAU_INTERNAL_H */ |
| 0 | 31 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,86 @@ |
| 0 |
+/* |
|
| 1 |
+ * Video Decode and Presentation API for UNIX (VDPAU) is used for |
|
| 2 |
+ * HW decode acceleration for MPEG-1/2, H.264 and VC-1. |
|
| 3 |
+ * |
|
| 4 |
+ * Copyright (C) 2008 NVIDIA. |
|
| 5 |
+ * |
|
| 6 |
+ * This file is part of FFmpeg. |
|
| 7 |
+ * |
|
| 8 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
| 9 |
+ * modify it under the terms of the GNU Lesser General Public |
|
| 10 |
+ * License as published by the Free Software Foundation; either |
|
| 11 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
| 12 |
+ * |
|
| 13 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
| 14 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 15 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 16 |
+ * Lesser General Public License for more details. |
|
| 17 |
+ * |
|
| 18 |
+ * You should have received a copy of the GNU Lesser General Public |
|
| 19 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
| 20 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
| 21 |
+ */ |
|
| 22 |
+ |
|
| 23 |
+#ifndef AVCODEC_VDPAU_RENDER_H |
|
| 24 |
+#define AVCODEC_VDPAU_RENDER_H |
|
| 25 |
+ |
|
| 26 |
+/** |
|
| 27 |
+ * \defgroup Decoder VDPAU Decoder and Renderer |
|
| 28 |
+ * |
|
| 29 |
+ * VDPAU HW acceleration has two modules |
|
| 30 |
+ * - VDPAU Decoding |
|
| 31 |
+ * - VDPAU Presentation |
|
| 32 |
+ * |
|
| 33 |
+ * VDPAU decoding module parses all headers using FFmpeg |
|
| 34 |
+ * parsing mechanism and uses VDPAU for the actual decoding. |
|
| 35 |
+ * |
|
| 36 |
+ * As per the current implementation, the actual decoding |
|
| 37 |
+ * and rendering (API calls) are done as part of VDPAU |
|
| 38 |
+ * presentation (vo_vdpau.c) module. |
|
| 39 |
+ * |
|
| 40 |
+ * @{
|
|
| 41 |
+ * \defgroup VDPAU_Decoding VDPAU Decoding |
|
| 42 |
+ * \ingroup Decoder |
|
| 43 |
+ * @{
|
|
| 44 |
+ */ |
|
| 45 |
+ |
|
| 46 |
+#include "vdpau/vdpau.h" |
|
| 47 |
+#include "vdpau/vdpau_x11.h" |
|
| 48 |
+ |
|
| 49 |
+/** |
|
| 50 |
+ * \brief The videoSurface is used for render. |
|
| 51 |
+ */ |
|
| 52 |
+#define FF_VDPAU_STATE_USED_FOR_RENDER 1 |
|
| 53 |
+ |
|
| 54 |
+/** |
|
| 55 |
+ * \brief The videoSurface is needed for reference/prediction, |
|
| 56 |
+ * codec manipulates this. |
|
| 57 |
+ */ |
|
| 58 |
+#define FF_VDPAU_STATE_USED_FOR_REFERENCE 2 |
|
| 59 |
+ |
|
| 60 |
+/** |
|
| 61 |
+ * \brief This structure is used as a CALL-BACK between the ffmpeg |
|
| 62 |
+ * decoder (vd_) and presentation (vo_) module. |
|
| 63 |
+ * This is used for defining a video-frame containing surface, |
|
| 64 |
+ * picture-parameter, bitstream informations etc which are passed |
|
| 65 |
+ * between ffmpeg decoder and its clients. |
|
| 66 |
+ */ |
|
| 67 |
+struct vdpau_render_state |
|
| 68 |
+ VdpVideoSurface surface; ///< used as rendered surface, never changed. |
|
| 69 |
+ |
|
| 70 |
+ int state; ///< Holds FF_VDPAU_STATE_* values |
|
| 71 |
+ |
|
| 72 |
+ /** Picture Parameter information for all supported codecs */ |
|
| 73 |
+ union _VdpPictureInfo {
|
|
| 74 |
+ VdpPictureInfoH264 h264; |
|
| 75 |
+ } info; |
|
| 76 |
+ |
|
| 77 |
+ /** Describe size/location of the compressed video data */ |
|
| 78 |
+ int bitstreamBuffersAlloced; |
|
| 79 |
+ int bitstreamBuffersUsed; |
|
| 80 |
+ VdpBitstreamBuffer *bitstreamBuffers; |
|
| 81 |
+}; |
|
| 82 |
+ |
|
| 83 |
+/* @}*/ |
|
| 84 |
+ |
|
| 85 |
+#endif /* AVCODEC_VDPAU_RENDER_H */ |
| 0 | 86 |
new file mode 100644 |
| ... | ... |
@@ -0,0 +1,183 @@ |
| 0 |
+/* |
|
| 1 |
+ * Video Decode and Presentation API for UNIX (VDPAU) is used for |
|
| 2 |
+ * HW decode acceleration for MPEG-1/2, H.264 and VC-1. |
|
| 3 |
+ * |
|
| 4 |
+ * Copyright (c) 2008 NVIDIA. |
|
| 5 |
+ * |
|
| 6 |
+ * This file is part of FFmpeg. |
|
| 7 |
+ * |
|
| 8 |
+ * FFmpeg is free software; you can redistribute it and/or |
|
| 9 |
+ * modify it under the terms of the GNU Lesser General Public |
|
| 10 |
+ * License as published by the Free Software Foundation; either |
|
| 11 |
+ * version 2.1 of the License, or (at your option) any later version. |
|
| 12 |
+ * |
|
| 13 |
+ * FFmpeg is distributed in the hope that it will be useful, |
|
| 14 |
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 15 |
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
| 16 |
+ * Lesser General Public License for more details. |
|
| 17 |
+ * |
|
| 18 |
+ * You should have received a copy of the GNU Lesser General Public |
|
| 19 |
+ * License along with FFmpeg; if not, write to the Free Software |
|
| 20 |
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
|
| 21 |
+ */ |
|
| 22 |
+ |
|
| 23 |
+#include <limits.h> |
|
| 24 |
+#include "avcodec.h" |
|
| 25 |
+#include "h264.h" |
|
| 26 |
+ |
|
| 27 |
+#undef NDEBUG |
|
| 28 |
+#include <assert.h> |
|
| 29 |
+ |
|
| 30 |
+#include "vdpau_render.h" |
|
| 31 |
+#include "vdpau_internal.h" |
|
| 32 |
+ |
|
| 33 |
+/** |
|
| 34 |
+ * \addtogroup VDPAU_Decoding |
|
| 35 |
+ * |
|
| 36 |
+ * @{
|
|
| 37 |
+ */ |
|
| 38 |
+ |
|
| 39 |
+static void VDPAU_h264_set_reference_frames(H264Context *h) |
|
| 40 |
+{
|
|
| 41 |
+ MpegEncContext * s = &h->s; |
|
| 42 |
+ struct vdpau_render_state * render, * render_ref; |
|
| 43 |
+ VdpReferenceFrameH264 * rf, * rf2; |
|
| 44 |
+ Picture * pic; |
|
| 45 |
+ int i, list, pic_frame_idx; |
|
| 46 |
+ |
|
| 47 |
+ render = (struct vdpau_render_state*)s->current_picture_ptr->data[0]; |
|
| 48 |
+ assert(render); |
|
| 49 |
+ |
|
| 50 |
+ rf = &render->info.h264.referenceFrames[0]; |
|
| 51 |
+#define H264_RF_COUNT FF_ARRAY_ELEMS(render->info.h264.referenceFrames) |
|
| 52 |
+ |
|
| 53 |
+ for (list = 0; list < 2; ++list) {
|
|
| 54 |
+ Picture **lp = list ? h->long_ref : h->short_ref; |
|
| 55 |
+ int ls = list ? h->long_ref_count : h->short_ref_count; |
|
| 56 |
+ |
|
| 57 |
+ for (i = 0; i < ls; ++i) {
|
|
| 58 |
+ pic = lp[i]; |
|
| 59 |
+ if (!pic || !pic->reference) |
|
| 60 |
+ continue; |
|
| 61 |
+ pic_frame_idx = pic->long_ref ? pic->pic_id : pic->frame_num; |
|
| 62 |
+ |
|
| 63 |
+ render_ref = (struct vdpau_render_state*)pic->data[0]; |
|
| 64 |
+ assert(render_ref); |
|
| 65 |
+ |
|
| 66 |
+ rf2 = &render->info.h264.referenceFrames[0]; |
|
| 67 |
+ while (rf2 != rf) {
|
|
| 68 |
+ if ( |
|
| 69 |
+ (rf2->surface == render_ref->surface) |
|
| 70 |
+ && (rf2->is_long_term == pic->long_ref) |
|
| 71 |
+ && (rf2->frame_idx == pic_frame_idx) |
|
| 72 |
+ ) |
|
| 73 |
+ break; |
|
| 74 |
+ ++rf2; |
|
| 75 |
+ } |
|
| 76 |
+ if (rf2 != rf) {
|
|
| 77 |
+ rf2->top_is_reference |= (pic->reference & PICT_TOP_FIELD) ? VDP_TRUE : VDP_FALSE; |
|
| 78 |
+ rf2->bottom_is_reference |= (pic->reference & PICT_BOTTOM_FIELD) ? VDP_TRUE : VDP_FALSE; |
|
| 79 |
+ continue; |
|
| 80 |
+ } |
|
| 81 |
+ |
|
| 82 |
+ if (rf >= &render->info.h264.referenceFrames[H264_RF_COUNT]) |
|
| 83 |
+ continue; |
|
| 84 |
+ |
|
| 85 |
+ rf->surface = render_ref->surface; |
|
| 86 |
+ rf->is_long_term = pic->long_ref; |
|
| 87 |
+ rf->top_is_reference = (pic->reference & PICT_TOP_FIELD) ? VDP_TRUE : VDP_FALSE; |
|
| 88 |
+ rf->bottom_is_reference = (pic->reference & PICT_BOTTOM_FIELD) ? VDP_TRUE : VDP_FALSE; |
|
| 89 |
+ rf->field_order_cnt[0] = pic->field_poc[0]; |
|
| 90 |
+ rf->field_order_cnt[1] = pic->field_poc[1]; |
|
| 91 |
+ rf->frame_idx = pic_frame_idx; |
|
| 92 |
+ |
|
| 93 |
+ ++rf; |
|
| 94 |
+ } |
|
| 95 |
+ } |
|
| 96 |
+ |
|
| 97 |
+ for (; rf < &render->info.h264.referenceFrames[H264_RF_COUNT]; ++rf) {
|
|
| 98 |
+ rf->surface = VDP_INVALID_HANDLE; |
|
| 99 |
+ rf->is_long_term = 0; |
|
| 100 |
+ rf->top_is_reference = 0; |
|
| 101 |
+ rf->bottom_is_reference = 0; |
|
| 102 |
+ rf->field_order_cnt[0] = 0; |
|
| 103 |
+ rf->field_order_cnt[1] = 0; |
|
| 104 |
+ rf->frame_idx = 0; |
|
| 105 |
+ } |
|
| 106 |
+} |
|
| 107 |
+ |
|
| 108 |
+void ff_VDPAU_h264_add_data_chunk(H264Context *h, const uint8_t *buf, int buf_size) |
|
| 109 |
+{
|
|
| 110 |
+ MpegEncContext * s = &h->s; |
|
| 111 |
+ struct vdpau_render_state * render; |
|
| 112 |
+ |
|
| 113 |
+ render = (struct vdpau_render_state*)s->current_picture_ptr->data[0]; |
|
| 114 |
+ assert(render); |
|
| 115 |
+ |
|
| 116 |
+ if (!render->bitstreamBuffersUsed) |
|
| 117 |
+ VDPAU_h264_set_reference_frames(h); |
|
| 118 |
+ |
|
| 119 |
+ render->bitstreamBuffers= av_fast_realloc( |
|
| 120 |
+ render->bitstreamBuffers, |
|
| 121 |
+ &render->bitstreamBuffersAlloced, |
|
| 122 |
+ sizeof(*render->bitstreamBuffers)*(render->bitstreamBuffersUsed + 1) |
|
| 123 |
+ ); |
|
| 124 |
+ |
|
| 125 |
+ render->bitstreamBuffers[render->bitstreamBuffersUsed].struct_version = VDP_BITSTREAM_BUFFER_VERSION; |
|
| 126 |
+ render->bitstreamBuffers[render->bitstreamBuffersUsed].bitstream = buf; |
|
| 127 |
+ render->bitstreamBuffers[render->bitstreamBuffersUsed].bitstream_bytes = buf_size; |
|
| 128 |
+ render->bitstreamBuffersUsed++; |
|
| 129 |
+} |
|
| 130 |
+ |
|
| 131 |
+void ff_VDPAU_h264_picture_complete(H264Context *h) |
|
| 132 |
+{
|
|
| 133 |
+ MpegEncContext * s = &h->s; |
|
| 134 |
+ struct vdpau_render_state * render; |
|
| 135 |
+ |
|
| 136 |
+ render = (struct vdpau_render_state*)s->current_picture_ptr->data[0]; |
|
| 137 |
+ assert(render); |
|
| 138 |
+ |
|
| 139 |
+ render->info.h264.slice_count = h->slice_num; |
|
| 140 |
+ if (render->info.h264.slice_count < 1) |
|
| 141 |
+ return; |
|
| 142 |
+ |
|
| 143 |
+ for (int i = 0; i < 2; ++i) {
|
|
| 144 |
+ int foc = s->current_picture_ptr->field_poc[i]; |
|
| 145 |
+ if (foc == INT_MAX) |
|
| 146 |
+ foc = 0; |
|
| 147 |
+ render->info.h264.field_order_cnt[i] = foc; |
|
| 148 |
+ } |
|
| 149 |
+ |
|
| 150 |
+ render->info.h264.is_reference = s->current_picture_ptr->reference ? VDP_TRUE : VDP_FALSE; |
|
| 151 |
+ render->info.h264.frame_num = h->frame_num; |
|
| 152 |
+ render->info.h264.field_pic_flag = s->picture_structure != PICT_FRAME; |
|
| 153 |
+ render->info.h264.bottom_field_flag = s->picture_structure == PICT_BOTTOM_FIELD; |
|
| 154 |
+ render->info.h264.num_ref_frames = h->sps.ref_frame_count; |
|
| 155 |
+ render->info.h264.mb_adaptive_frame_field_flag = h->sps.mb_aff; |
|
| 156 |
+ render->info.h264.constrained_intra_pred_flag = h->pps.constrained_intra_pred; |
|
| 157 |
+ render->info.h264.weighted_pred_flag = h->pps.weighted_pred; |
|
| 158 |
+ render->info.h264.weighted_bipred_idc = h->pps.weighted_bipred_idc; |
|
| 159 |
+ render->info.h264.frame_mbs_only_flag = h->sps.frame_mbs_only_flag; |
|
| 160 |
+ render->info.h264.transform_8x8_mode_flag = h->pps.transform_8x8_mode; |
|
| 161 |
+ render->info.h264.chroma_qp_index_offset = h->pps.chroma_qp_index_offset[0]; |
|
| 162 |
+ render->info.h264.second_chroma_qp_index_offset = h->pps.chroma_qp_index_offset[1]; |
|
| 163 |
+ render->info.h264.pic_init_qp_minus26 = h->pps.init_qp - 26; |
|
| 164 |
+ render->info.h264.num_ref_idx_l0_active_minus1 = h->pps.ref_count[0] - 1; |
|
| 165 |
+ render->info.h264.num_ref_idx_l1_active_minus1 = h->pps.ref_count[1] - 1; |
|
| 166 |
+ render->info.h264.log2_max_frame_num_minus4 = h->sps.log2_max_frame_num - 4; |
|
| 167 |
+ render->info.h264.pic_order_cnt_type = h->sps.poc_type; |
|
| 168 |
+ render->info.h264.log2_max_pic_order_cnt_lsb_minus4 = h->sps.log2_max_poc_lsb - 4; |
|
| 169 |
+ render->info.h264.delta_pic_order_always_zero_flag = h->sps.delta_pic_order_always_zero_flag; |
|
| 170 |
+ render->info.h264.direct_8x8_inference_flag = h->sps.direct_8x8_inference_flag; |
|
| 171 |
+ render->info.h264.entropy_coding_mode_flag = h->pps.cabac; |
|
| 172 |
+ render->info.h264.pic_order_present_flag = h->pps.pic_order_present; |
|
| 173 |
+ render->info.h264.deblocking_filter_control_present_flag = h->pps.deblocking_filter_parameters_present; |
|
| 174 |
+ render->info.h264.redundant_pic_cnt_present_flag = h->pps.redundant_pic_cnt_present; |
|
| 175 |
+ memcpy(render->info.h264.scaling_lists_4x4, h->pps.scaling_matrix4, sizeof(render->info.h264.scaling_lists_4x4)); |
|
| 176 |
+ memcpy(render->info.h264.scaling_lists_8x8, h->pps.scaling_matrix8, sizeof(render->info.h264.scaling_lists_8x8)); |
|
| 177 |
+ |
|
| 178 |
+ ff_draw_horiz_band(s, 0, s->avctx->height); |
|
| 179 |
+ render->bitstreamBuffersUsed = 0; |
|
| 180 |
+} |
|
| 181 |
+ |
|
| 182 |
+/* @}*/ |
| ... | ... |
@@ -121,6 +121,7 @@ enum PixelFormat {
|
| 121 | 121 |
PIX_FMT_YUV440P, ///< Planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples) |
| 122 | 122 |
PIX_FMT_YUVJ440P, ///< Planar YUV 4:4:0 full scale (jpeg) |
| 123 | 123 |
PIX_FMT_YUVA420P, ///< Planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples) |
| 124 |
+ PIX_FMT_VDPAU_H264,///< H264 HW decoding with VDPAU, data[0] contains a vdpau_render_state struct which contains the bitstream of the slices as well as various fields extracted from headers |
|
| 124 | 125 |
PIX_FMT_NB, ///< number of pixel formats, DO NOT USE THIS if you want to link with shared libav* because the number of formats might differ between versions |
| 125 | 126 |
}; |
| 126 | 127 |
|