Skip to content

Commit

Permalink
temporarily cancel 7baa3d8 submission
Browse files Browse the repository at this point in the history
  • Loading branch information
jocover committed Apr 30, 2021
1 parent 3dff99c commit 2006718
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 98 deletions.
156 changes: 82 additions & 74 deletions ffmpeg_nvmpi.patch
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
diff -Naur ffmpeg/configure ffmpeg2/configure
--- ffmpeg/configure 2020-07-09 16:17:46.000000000 +0700
+++ ffmpeg2/configure 2021-02-28 09:38:00.158190548 +0700
@@ -340,6 +340,7 @@
diff --git a/configure b/configure
index 6a7a85c..5810ab5 100755
--- a/configure
+++ b/configure
@@ -340,6 +340,7 @@ External library support:
--disable-vaapi disable Video Acceleration API (mainly Unix/Intel) code [autodetect]
--disable-vdpau disable Nvidia Video Decode and Presentation API for Unix code [autodetect]
--disable-videotoolbox disable VideoToolbox code [autodetect]
+ --enable-nvmpi enable nvmpi code

Toolchain options:
--arch=ARCH select architecture [$arch]
@@ -1851,6 +1852,7 @@
@@ -1851,6 +1852,7 @@ HWACCEL_LIBRARY_LIST="
mmal
omx
opencl
+ nvmpi
"

DOCUMENT_LIST="
@@ -3014,11 +3016,14 @@
@@ -3014,11 +3016,14 @@ h264_mediacodec_decoder_deps="mediacodec"
h264_mediacodec_decoder_select="h264_mp4toannexb_bsf h264_parser"
h264_mmal_decoder_deps="mmal"
h264_nvenc_encoder_deps="nvenc"
Expand All @@ -32,7 +33,7 @@ diff -Naur ffmpeg/configure ffmpeg2/configure
h264_vaapi_encoder_select="cbs_h264 vaapi_encode"
h264_v4l2m2m_decoder_deps="v4l2_m2m h264_v4l2_m2m"
h264_v4l2m2m_decoder_select="h264_mp4toannexb_bsf"
@@ -3029,10 +3034,13 @@
@@ -3029,10 +3034,13 @@ hevc_cuvid_decoder_select="hevc_mp4toannexb_bsf"
hevc_mediacodec_decoder_deps="mediacodec"
hevc_mediacodec_decoder_select="hevc_mp4toannexb_bsf hevc_parser"
hevc_nvenc_encoder_deps="nvenc"
Expand All @@ -46,92 +47,51 @@ diff -Naur ffmpeg/configure ffmpeg2/configure
hevc_vaapi_encoder_deps="VAEncPictureParameterBufferHEVC"
hevc_vaapi_encoder_select="cbs_h265 vaapi_encode"
hevc_v4l2m2m_decoder_deps="v4l2_m2m hevc_v4l2_m2m"
@@ -3047,6 +3055,7 @@
@@ -3047,6 +3055,7 @@ mpeg1_cuvid_decoder_deps="cuvid"
mpeg1_v4l2m2m_decoder_deps="v4l2_m2m mpeg1_v4l2_m2m"
mpeg2_crystalhd_decoder_select="crystalhd"
mpeg2_cuvid_decoder_deps="cuvid"
+mpeg2_nvmpi_decoder_deps="nvmpi"
mpeg2_mmal_decoder_deps="mmal"
mpeg2_mediacodec_decoder_deps="mediacodec"
mpeg2_qsv_decoder_select="qsvdec mpegvideo_parser"
@@ -3055,6 +3064,7 @@
@@ -3055,6 +3064,7 @@ mpeg2_vaapi_encoder_select="cbs_mpeg2 vaapi_encode"
mpeg2_v4l2m2m_decoder_deps="v4l2_m2m mpeg2_v4l2_m2m"
mpeg4_crystalhd_decoder_select="crystalhd"
mpeg4_cuvid_decoder_deps="cuvid"
+mpeg4_nvmpi_decoder_deps="nvmpi"
mpeg4_mediacodec_decoder_deps="mediacodec"
mpeg4_mmal_decoder_deps="mmal"
mpeg4_omx_encoder_deps="omx"
@@ -3069,6 +3079,7 @@
@@ -3069,6 +3079,7 @@ vc1_mmal_decoder_deps="mmal"
vc1_qsv_decoder_select="qsvdec vc1_parser"
vc1_v4l2m2m_decoder_deps="v4l2_m2m vc1_v4l2_m2m"
vp8_cuvid_decoder_deps="cuvid"
+vp8_nvmpi_decoder_deps="nvmpi"
vp8_mediacodec_decoder_deps="mediacodec"
vp8_qsv_decoder_select="qsvdec vp8_parser"
vp8_rkmpp_decoder_deps="rkmpp"
@@ -3077,6 +3088,7 @@
@@ -3077,6 +3088,7 @@ vp8_vaapi_encoder_select="vaapi_encode"
vp8_v4l2m2m_decoder_deps="v4l2_m2m vp8_v4l2_m2m"
vp8_v4l2m2m_encoder_deps="v4l2_m2m vp8_v4l2_m2m"
vp9_cuvid_decoder_deps="cuvid"
+vp9_nvmpi_decoder_deps="nvmpi"
vp9_mediacodec_decoder_deps="mediacodec"
vp9_rkmpp_decoder_deps="rkmpp"
vp9_vaapi_encoder_deps="VAEncPictureParameterBufferVP9"
@@ -6366,6 +6378,7 @@
@@ -6366,6 +6378,7 @@ enabled rkmpp && { require_pkg_config rkmpp rockchip_mpp rockchip/r
die "ERROR: rkmpp requires --enable-libdrm"; }
}
enabled vapoursynth && require_pkg_config vapoursynth "vapoursynth-script >= 42" VSScript.h vsscript_init
+enabled nvmpi && require_pkg_config nvmpi nvmpi nvmpi.h nvmpi_create_decoder


if enabled gcrypt; then
diff -Naur ffmpeg/libavcodec/allcodecs.c ffmpeg2/libavcodec/allcodecs.c
--- ffmpeg/libavcodec/allcodecs.c 2020-07-09 16:17:46.000000000 +0700
+++ ffmpeg2/libavcodec/allcodecs.c 2021-02-28 09:38:00.158190548 +0700
@@ -143,11 +143,15 @@
extern AVCodec ff_h264_mmal_decoder;
extern AVCodec ff_h264_qsv_decoder;
extern AVCodec ff_h264_rkmpp_decoder;
+extern AVCodec ff_h264_nvmpi_decoder;
+extern AVCodec ff_h264_nvmpi_encoder;
extern AVCodec ff_hap_encoder;
extern AVCodec ff_hap_decoder;
extern AVCodec ff_hevc_decoder;
extern AVCodec ff_hevc_qsv_decoder;
extern AVCodec ff_hevc_rkmpp_decoder;
+extern AVCodec ff_hevc_nvmpi_decoder;
+extern AVCodec ff_hevc_nvmpi_encoder;
extern AVCodec ff_hevc_v4l2m2m_decoder;
extern AVCodec ff_hnm4_video_decoder;
extern AVCodec ff_hq_hqa_decoder;
@@ -766,18 +770,22 @@
extern AVCodec ff_mjpeg_vaapi_encoder;
extern AVCodec ff_mpeg1_cuvid_decoder;
extern AVCodec ff_mpeg2_cuvid_decoder;
+extern AVCodec ff_mpeg2_nvmpi_decoder;
extern AVCodec ff_mpeg2_qsv_encoder;
extern AVCodec ff_mpeg2_vaapi_encoder;
extern AVCodec ff_mpeg4_cuvid_decoder;
+extern AVCodec ff_mpeg4_nvmpi_decoder;
extern AVCodec ff_mpeg4_mediacodec_decoder;
extern AVCodec ff_mpeg4_v4l2m2m_encoder;
extern AVCodec ff_vc1_cuvid_decoder;
extern AVCodec ff_vp8_cuvid_decoder;
+extern AVCodec ff_vp8_nvmpi_decoder;
extern AVCodec ff_vp8_mediacodec_decoder;
extern AVCodec ff_vp8_qsv_decoder;
extern AVCodec ff_vp8_v4l2m2m_encoder;
extern AVCodec ff_vp8_vaapi_encoder;
extern AVCodec ff_vp9_cuvid_decoder;
+extern AVCodec ff_vp9_nvmpi_decoder;
extern AVCodec ff_vp9_mediacodec_decoder;
extern AVCodec ff_vp9_vaapi_encoder;

diff -Naur ffmpeg/libavcodec/Makefile ffmpeg2/libavcodec/Makefile
--- ffmpeg/libavcodec/Makefile 2020-07-09 16:17:46.000000000 +0700
+++ ffmpeg2/libavcodec/Makefile 2021-02-28 09:38:00.158190548 +0700
@@ -354,6 +354,8 @@
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 3cd73fb..c3ed5cc 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -354,6 +354,8 @@ OBJS-$(CONFIG_H264_MMAL_DECODER) += mmaldec.o
OBJS-$(CONFIG_H264_NVENC_ENCODER) += nvenc_h264.o
OBJS-$(CONFIG_NVENC_ENCODER) += nvenc_h264.o
OBJS-$(CONFIG_NVENC_H264_ENCODER) += nvenc_h264.o
Expand All @@ -140,7 +100,7 @@ diff -Naur ffmpeg/libavcodec/Makefile ffmpeg2/libavcodec/Makefile
OBJS-$(CONFIG_H264_OMX_ENCODER) += omx.o
OBJS-$(CONFIG_H264_QSV_DECODER) += qsvdec_h2645.o
OBJS-$(CONFIG_H264_QSV_ENCODER) += qsvenc_h264.o
@@ -379,6 +381,8 @@
@@ -379,6 +381,8 @@ OBJS-$(CONFIG_HEVC_QSV_ENCODER) += qsvenc_hevc.o hevc_ps_enc.o \
OBJS-$(CONFIG_HEVC_RKMPP_DECODER) += rkmppdec.o
OBJS-$(CONFIG_HEVC_VAAPI_ENCODER) += vaapi_encode_h265.o h265_profile_level.o
OBJS-$(CONFIG_HEVC_V4L2M2M_DECODER) += v4l2_m2m_dec.o
Expand All @@ -149,7 +109,7 @@ diff -Naur ffmpeg/libavcodec/Makefile ffmpeg2/libavcodec/Makefile
OBJS-$(CONFIG_HEVC_V4L2M2M_ENCODER) += v4l2_m2m_enc.o
OBJS-$(CONFIG_HNM4_VIDEO_DECODER) += hnm4video.o
OBJS-$(CONFIG_HQ_HQA_DECODER) += hq_hqa.o hq_hqadata.o hq_hqadsp.o \
@@ -464,11 +468,13 @@
@@ -464,11 +468,13 @@ OBJS-$(CONFIG_MPEG2_QSV_ENCODER) += qsvenc_mpeg2.o
OBJS-$(CONFIG_MPEG2VIDEO_DECODER) += mpeg12dec.o mpeg12.o mpeg12data.o
OBJS-$(CONFIG_MPEG2VIDEO_ENCODER) += mpeg12enc.o mpeg12.o
OBJS-$(CONFIG_MPEG2_CUVID_DECODER) += cuviddec.o
Expand All @@ -163,25 +123,70 @@ diff -Naur ffmpeg/libavcodec/Makefile ffmpeg2/libavcodec/Makefile
OBJS-$(CONFIG_MPEG4_MEDIACODEC_DECODER) += mediacodecdec.o
OBJS-$(CONFIG_MPEG4_OMX_ENCODER) += omx.o
OBJS-$(CONFIG_MPEG4_V4L2M2M_DECODER) += v4l2_m2m_dec.o
@@ -669,6 +675,7 @@
@@ -669,6 +675,7 @@ OBJS-$(CONFIG_VP6_DECODER) += vp6.o vp56.o vp56data.o \
OBJS-$(CONFIG_VP7_DECODER) += vp8.o vp56rac.o
OBJS-$(CONFIG_VP8_DECODER) += vp8.o vp56rac.o
OBJS-$(CONFIG_VP8_CUVID_DECODER) += cuviddec.o
+OBJS-$(CONFIG_VP8_NVMPI_DECODER) += nvmpi_dec.o
OBJS-$(CONFIG_VP8_MEDIACODEC_DECODER) += mediacodecdec.o
OBJS-$(CONFIG_VP8_QSV_DECODER) += qsvdec_other.o
OBJS-$(CONFIG_VP8_RKMPP_DECODER) += rkmppdec.o
@@ -679,6 +686,7 @@
@@ -679,6 +686,7 @@ OBJS-$(CONFIG_VP9_DECODER) += vp9.o vp9data.o vp9dsp.o vp9lpf.o vp9r
vp9block.o vp9prob.o vp9mvs.o vp56rac.o \
vp9dsp_8bpp.o vp9dsp_10bpp.o vp9dsp_12bpp.o
OBJS-$(CONFIG_VP9_CUVID_DECODER) += cuviddec.o
+OBJS-$(CONFIG_VP9_NVMPI_DECODER) += nvmpi_dec.o
OBJS-$(CONFIG_VP9_MEDIACODEC_DECODER) += mediacodecdec.o
OBJS-$(CONFIG_VP9_RKMPP_DECODER) += rkmppdec.o
OBJS-$(CONFIG_VP9_VAAPI_ENCODER) += vaapi_encode_vp9.o
diff -Naur ffmpeg/libavcodec/nvmpi_dec.c ffmpeg2/libavcodec/nvmpi_dec.c
--- ffmpeg/libavcodec/nvmpi_dec.c 1970-01-01 08:00:00.000000000 +0800
+++ ffmpeg2/libavcodec/nvmpi_dec.c 2021-02-28 10:48:56.062551585 +0700
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index d2f9a39..04dc62b 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -143,11 +143,15 @@ extern AVCodec ff_h264_mediacodec_decoder;
extern AVCodec ff_h264_mmal_decoder;
extern AVCodec ff_h264_qsv_decoder;
extern AVCodec ff_h264_rkmpp_decoder;
+extern AVCodec ff_h264_nvmpi_decoder;
+extern AVCodec ff_h264_nvmpi_encoder;
extern AVCodec ff_hap_encoder;
extern AVCodec ff_hap_decoder;
extern AVCodec ff_hevc_decoder;
extern AVCodec ff_hevc_qsv_decoder;
extern AVCodec ff_hevc_rkmpp_decoder;
+extern AVCodec ff_hevc_nvmpi_decoder;
+extern AVCodec ff_hevc_nvmpi_encoder;
extern AVCodec ff_hevc_v4l2m2m_decoder;
extern AVCodec ff_hnm4_video_decoder;
extern AVCodec ff_hq_hqa_decoder;
@@ -766,18 +770,22 @@ extern AVCodec ff_mjpeg_qsv_encoder;
extern AVCodec ff_mjpeg_vaapi_encoder;
extern AVCodec ff_mpeg1_cuvid_decoder;
extern AVCodec ff_mpeg2_cuvid_decoder;
+extern AVCodec ff_mpeg2_nvmpi_decoder;
extern AVCodec ff_mpeg2_qsv_encoder;
extern AVCodec ff_mpeg2_vaapi_encoder;
extern AVCodec ff_mpeg4_cuvid_decoder;
+extern AVCodec ff_mpeg4_nvmpi_decoder;
extern AVCodec ff_mpeg4_mediacodec_decoder;
extern AVCodec ff_mpeg4_v4l2m2m_encoder;
extern AVCodec ff_vc1_cuvid_decoder;
extern AVCodec ff_vp8_cuvid_decoder;
+extern AVCodec ff_vp8_nvmpi_decoder;
extern AVCodec ff_vp8_mediacodec_decoder;
extern AVCodec ff_vp8_qsv_decoder;
extern AVCodec ff_vp8_v4l2m2m_encoder;
extern AVCodec ff_vp8_vaapi_encoder;
extern AVCodec ff_vp9_cuvid_decoder;
+extern AVCodec ff_vp9_nvmpi_decoder;
extern AVCodec ff_vp9_mediacodec_decoder;
extern AVCodec ff_vp9_vaapi_encoder;

diff --git a/libavcodec/nvmpi_dec.c b/libavcodec/nvmpi_dec.c
new file mode 100644
index 0000000..f82aa61
--- /dev/null
+++ b/libavcodec/nvmpi_dec.c
@@ -0,0 +1,171 @@
+#include <stdio.h>
+#include <stdlib.h>
Expand Down Expand Up @@ -238,8 +243,8 @@ diff -Naur ffmpeg/libavcodec/nvmpi_dec.c ffmpeg2/libavcodec/nvmpi_dec.c
+
+ if(avctx->pix_fmt ==AV_PIX_FMT_NONE){
+ avctx->pix_fmt=AV_PIX_FMT_YUV420P;
+ }else if(avctx-> pix_fmt != AV_PIX_FMT_YUV420P && avctx-> pix_fmt != AV_PIX_FMT_YUVJ420P){
+ av_log(avctx, AV_LOG_ERROR, "Invalid Pix_FMT for NVMPI Only yuv420p or yuvj420p is supported\n");
+ }else if(avctx-> pix_fmt != AV_PIX_FMT_YUV420P){
+ av_log(avctx, AV_LOG_ERROR, "Invalid Pix_FMT for NVMPI Only yuv420p is supported\n");
+ return AVERROR_INVALIDDATA;
+ }
+
Expand Down Expand Up @@ -354,10 +359,12 @@ diff -Naur ffmpeg/libavcodec/nvmpi_dec.c ffmpeg2/libavcodec/nvmpi_dec.c
+NVMPI_DEC(vp9, AV_CODEC_ID_VP9,NULL);
+NVMPI_DEC(vp8, AV_CODEC_ID_VP8,NULL);
+
diff -Naur ffmpeg/libavcodec/nvmpi_enc.c ffmpeg2/libavcodec/nvmpi_enc.c
--- ffmpeg/libavcodec/nvmpi_enc.c 1970-01-01 08:00:00.000000000 +0800
+++ ffmpeg2/libavcodec/nvmpi_enc.c 2021-03-01 11:38:35.700002819 +0700
@@ -0,0 +1,271 @@
diff --git a/libavcodec/nvmpi_enc.c b/libavcodec/nvmpi_enc.c
new file mode 100644
index 0000000..0e1390e
--- /dev/null
+++ b/libavcodec/nvmpi_enc.c
@@ -0,0 +1,272 @@
+#include <nvmpi.h>
+#include "avcodec.h"
+#include "internal.h"
Expand Down Expand Up @@ -499,13 +506,14 @@ diff -Naur ffmpeg/libavcodec/nvmpi_enc.c ffmpeg2/libavcodec/nvmpi_enc.c
+ _nvframe.payload[1]=frame->data[1];
+ _nvframe.payload[2]=frame->data[2];
+
+ _nvframe.payload_size[0]=frame->linesize[0]*frame->height;
+ _nvframe.payload_size[1]=frame->linesize[1]*frame->height/2;
+ _nvframe.payload_size[2]=frame->linesize[2]*frame->height/2;
+
+ _nvframe.linesize[0]=frame->linesize[0];
+ _nvframe.linesize[1]=frame->linesize[1];
+ _nvframe.linesize[2]=frame->linesize[2];
+
+ _nvframe.width = frame->width;
+ _nvframe.height = frame->height;
+
+ _nvframe.timestamp=frame->pts;
+
+ res=nvmpi_encoder_put_frame(nvmpi_context->ctx,&_nvframe);
Expand Down
30 changes: 6 additions & 24 deletions nvmpi_enc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ static bool encoder_capture_plane_dq_callback(struct v4l2_buffer *v4l2_buf, NvBu
nvmpictx* nvmpi_create_encoder(nvCodingType codingType,nvEncParam * param){

int ret;

log_level = LOG_LEVEL_INFO;
nvmpictx *ctx=new nvmpictx;
ctx->index=0;
Expand Down Expand Up @@ -374,26 +373,6 @@ nvmpictx* nvmpi_create_encoder(nvCodingType codingType,nvEncParam * param){
return ctx;
}

static void copy_image_plane(unsigned char* dst, const unsigned char* src, int dstPitch, int srcPitch, int height, uint32_t* byteCopied)
{
if(!dst || !src){
return;
}
if(dstPitch == srcPitch){
*byteCopied = srcPitch * height;
memcpy(dst, src, *byteCopied);
}
else{
int pitch = min(dstPitch, srcPitch);
*byteCopied = 0;
for(int i = 0; i < height; i++){
memcpy(dst, src, pitch);
dst += dstPitch;
src += srcPitch;
*byteCopied += pitch;
}
}
}

int nvmpi_encoder_put_frame(nvmpictx* ctx,nvFrame* frame){
int ret;
Expand Down Expand Up @@ -425,9 +404,12 @@ int nvmpi_encoder_put_frame(nvmpictx* ctx,nvFrame* frame){

}

copy_image_plane(nvBuffer->planes[0].data, frame->payload[0], nvBuffer->planes[0].fmt.stride, frame->linesize[0], frame->height, &nvBuffer->planes[0].bytesused);
copy_image_plane(nvBuffer->planes[1].data, frame->payload[1], nvBuffer->planes[1].fmt.stride, frame->linesize[1], frame->height >> 1, &nvBuffer->planes[1].bytesused);
copy_image_plane(nvBuffer->planes[2].data, frame->payload[2], nvBuffer->planes[2].fmt.stride, frame->linesize[2], frame->height >> 1, &nvBuffer->planes[2].bytesused);
memcpy(nvBuffer->planes[0].data,frame->payload[0],frame->payload_size[0]);
memcpy(nvBuffer->planes[1].data,frame->payload[1],frame->payload_size[1]);
memcpy(nvBuffer->planes[2].data,frame->payload[2],frame->payload_size[2]);
nvBuffer->planes[0].bytesused=frame->payload_size[0];
nvBuffer->planes[1].bytesused=frame->payload_size[1];
nvBuffer->planes[2].bytesused=frame->payload_size[2];

v4l2_buf.flags |= V4L2_BUF_FLAG_TIMESTAMP_COPY;
v4l2_buf.timestamp.tv_usec = frame->timestamp % 1000000;
Expand Down

0 comments on commit 2006718

Please sign in to comment.