Commit 7111cef9 authored by Steve Lhomme's avatar Steve Lhomme

update/clean patchset

parent 3818025a
From c3e0d1d05ba98a04843db251fbcea159999de7b8 Mon Sep 17 00:00:00 2001
From 3412d6d26fb4d8ba2bb3a831692ceadfeec31289 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= <hugo@beauzee.fr>
Date: Tue, 10 Feb 2015 11:58:54 +0100
Subject: [PATCH 01/28] wasapi: Don't fail if the client is already initialized
......
From 7e26b4404b5164c3c04b26626d27207210580799 Mon Sep 17 00:00:00 2001
From 0d9c465ebf5ea99f3f492ae7754657e39bcebe1f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= <hugo@beauzee.fr>
Date: Wed, 11 May 2016 17:37:47 +0200
Subject: [PATCH 02/28] gnutls: Set cannot_unload_broken_library for winrt
......
From 3bddca74b880796c250aad691be13129f8fb1683 Mon Sep 17 00:00:00 2001
From 8a5f4fac5d78194b48cfa6bf48be6870c487b715 Mon Sep 17 00:00:00 2001
From: Jean-Baptiste Kempf <jb@videolan.org>
Date: Wed, 16 Apr 2014 16:09:53 +0200
Subject: [PATCH 03/28] Cheat for Windows Store subtitles
......
From f1a59782ccd3ff26a73cf0dc6d67606648f80714 Mon Sep 17 00:00:00 2001
From 07fe0d6cfa0c8dfe299fd30d496b8608158e642f Mon Sep 17 00:00:00 2001
From: Jean-Baptiste Kempf <jb@videolan.org>
Date: Wed, 12 Mar 2014 00:11:26 +0100
Subject: [PATCH 04/28] Accept the weird WinRT pathes
......
From 78dc28dca7dd0c620644f3c8df60239d0e490156 Mon Sep 17 00:00:00 2001
From 5129d8214d22e486ea25546c884b70d0912a2c99 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= <hugo@beauzee.fr>
Date: Tue, 2 Aug 2016 18:54:28 +0200
Subject: [PATCH 05/28] config: cmdline: Use msg_* instead of fprintf
......
From 88a9c4a7aa767a1506cb6464595105575adbe8fb Mon Sep 17 00:00:00 2001
From 8edba7fb19751d21e2a1fcc2a0328e57d49ed0b0 Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@videolabs.io>
Date: Fri, 30 Sep 2016 09:49:19 +0200
Subject: [PATCH 06/28] plugin cache: Windows doesn't like relative pathes in
......
From 495543392a431f63d1c56201d472f590cbfcfd67 Mon Sep 17 00:00:00 2001
From e5ce476faac1aab507958776db7f65ab6ef9333e Mon Sep 17 00:00:00 2001
From: Steve Lhomme <slhomme@matroska.org>
Date: Fri, 2 Dec 2016 11:14:40 +0100
Subject: [PATCH 07/28] TEMPORARY: disable cuda/nvenc when building for
......
From 9d5bf6681222d5ca390bcfac84cf1b2fef101c91 Mon Sep 17 00:00:00 2001
From 42cd4cd46ef9987628b20bd8ada88fb1c7b21ff9 Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@videolabs.io>
Date: Wed, 25 Jan 2017 10:49:37 +0100
Subject: [PATCH 08/28] core: avcodec requires 32-bytes memory alignment in
......
From 2818fc0a9e21fe117d651fc44981d869019660cb Mon Sep 17 00:00:00 2001
From cc9b7d8cd0650226c5f1f51fa14a17ce964ae95f Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Thu, 29 Mar 2018 15:46:11 +0200
Subject: [PATCH 09/28] contrib: ffmpeg: use bcrypt instead of the old wincrypt
......
From 87e261e528f5ff3213862b8bff9ab3833279592b Mon Sep 17 00:00:00 2001
From 227573a1b4ef2e47571cbaaf86fe9d009b3ccbb2 Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@videolabs.io>
Date: Tue, 19 Dec 2017 12:39:06 +0100
Subject: [PATCH 10/28] contrib:avcodec: use a more recent FFmpeg version
......
From 8f169dcc6a9bdaf040e5a6b69b1970c8845ea446 Mon Sep 17 00:00:00 2001
From 50b6b5898f2dc06b9cf506efcff61eabe340c7ff Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Tue, 20 Feb 2018 11:24:43 +0100
Subject: [PATCH 11/28] contrib:mpg123: don't use forbidden APIs on Phone apps
......
From 401b4bae3ccdab41ce01a23fce740b835cabd9dd Mon Sep 17 00:00:00 2001
From b6be67f5cb94d61932a5e9f255a45acb7fc6702c Mon Sep 17 00:00:00 2001
From: Carola Nitz <nitz.carola@googlemail.com>
Date: Fri, 29 Sep 2017 14:49:02 +0200
Subject: [PATCH 12/28] contrib: use live555 version that is compatible with
......
From e517b735fdf1692ce8c34bbf383b91797877ba12 Mon Sep 17 00:00:00 2001
From a8eace19aa8c3d735afa02860e7f3509f407044d Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Tue, 27 Mar 2018 18:57:41 +0200
Subject: [PATCH 13/28] rand: use bcrypt instead of CryptographicBufferStatics
......
From 1587fc6f4ac4f72e41fbcbd675e58f9f08013a58 Mon Sep 17 00:00:00 2001
From f4bce62f38bb9f23e09689eb12e179df8270746f Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Wed, 28 Mar 2018 09:10:39 +0200
Subject: [PATCH 14/28] keystore: CryptUnprotectData is officially found in
......
From bfa52f94346d14414cb123df59cab34ff8ea58cb Mon Sep 17 00:00:00 2001
From 351811034e4e60a7f04b6c39a672df5d87a33c07 Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@videolabs.io>
Date: Mon, 23 May 2016 09:18:17 +0200
Subject: [PATCH 15/28] contrib: gnutls: fix Winstore forbidden API calls
......
From c1f264bf979fdeb227d54238ff55dfe233044fde Mon Sep 17 00:00:00 2001
From 907613101d218570cdb38106213ef0258351db34 Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Thu, 29 Mar 2018 13:09:59 +0200
Subject: [PATCH 16/28] sap: use the same declaration signature as the
......
From a6139aae6ac57fc1a18c29e1756603ff1284b26e Mon Sep 17 00:00:00 2001
From e95beac3a1b1996955149be2cac05f02aaacb417 Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Thu, 29 Mar 2018 15:00:53 +0200
Subject: [PATCH 17/28] contrib: shout: respect the availability of strings.h
......
From 1110dee6efad99e4253d14677ac0ad97f4418b7e Mon Sep 17 00:00:00 2001
From 33abaf7dc9ad932994bf01a1f6599615146a0b2f Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Thu, 29 Mar 2018 15:03:37 +0200
Subject: [PATCH 18/28] contrib: shout: usleep() is not a Windows API
......
From c185223ad0eb49e9c50a785fbf43f41b97d2eded Mon Sep 17 00:00:00 2001
From 218eeb64d0302a1a3cac7b59a09c71f6675b7813 Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Thu, 29 Mar 2018 15:06:53 +0200
Subject: [PATCH 19/28] contrib: shout: timeval is defined in winsock2.h on
......
From aa82f3f6487527629e459b469cc24cfa396f660d Mon Sep 17 00:00:00 2001
From 4326dbeaade56ce805ef041a8aa02f2b4fd69352 Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Thu, 29 Mar 2018 15:13:55 +0200
Subject: [PATCH 20/28] contrib: shout: socklen_t can be found in ws2tcpip.h on
......
From 0a1d049358f5449ef484b16aee3aa966ef8968f7 Mon Sep 17 00:00:00 2001
From ed1b6edb720246403c6758c403770dcbbcc89825 Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Thu, 29 Mar 2018 15:46:50 +0200
Subject: [PATCH 21/28] contrib: ffmpeg: don't use libvpx at all in libavcodec
......
From f674574b20063e3f0d35e6d9458e6f7a7135be90 Mon Sep 17 00:00:00 2001
From ab9b5a436fe510c3751b5246a68897b0543febf9 Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Thu, 5 Apr 2018 13:29:40 +0200
Subject: [PATCH 22/28] contrib: gcrypt: use bcrypt rather than wincrypt
......
From 5602018e10e5f46a9e0a275be197d809a956627f Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Wed, 4 Apr 2018 12:10:17 +0200
Subject: [PATCH 22/26] transcode: do not include the decoder padding in the
output SAR
---
modules/stream_out/transcode/video.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/modules/stream_out/transcode/video.c b/modules/stream_out/transcode/video.c
index 779ff7c..74734ee 100644
--- a/modules/stream_out/transcode/video.c
+++ b/modules/stream_out/transcode/video.c
@@ -570,8 +570,10 @@ static void transcode_video_sar_init( sout_stream_t *p_stream,
{
vlc_ureduce( &id->p_encoder->fmt_out.video.i_sar_num,
&id->p_encoder->fmt_out.video.i_sar_den,
- (uint64_t)p_vid_out->i_sar_num * id->p_encoder->fmt_out.video.i_width * p_vid_out->i_height,
- (uint64_t)p_vid_out->i_sar_den * id->p_encoder->fmt_out.video.i_height * p_vid_out->i_width,
+ (uint64_t)p_vid_out->i_sar_num * (id->p_encoder->fmt_out.video.i_x_offset + id->p_encoder->fmt_out.video.i_visible_width)
+ * (p_vid_out->i_x_offset + p_vid_out->i_visible_height),
+ (uint64_t)p_vid_out->i_sar_den * (id->p_encoder->fmt_out.video.i_y_offset + id->p_encoder->fmt_out.video.i_visible_height)
+ * (p_vid_out->i_y_offset + p_vid_out->i_visible_width),
0 );
}
else
--
2.10.1.windows.1
From d8ac1f48c85678b1bc447e2d9fe30058c98add8c Mon Sep 17 00:00:00 2001
From c571b2c6da6c6574a3ee125d11c800dc268d9700 Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Thu, 5 Apr 2018 14:49:26 +0200
Subject: [PATCH 23/28] contrib: libarchive: use bcrypt rather than wincrypt
......
From c2eebd5eed92f33b8dbcd5bb1036cfef25d1e1ed Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@videolabs.io>
Date: Thu, 14 Dec 2017 14:20:25 +0100
Subject: [PATCH 23/26] transcode: the visible dimensions are unlikely to be 0
---
modules/stream_out/transcode/video.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/modules/stream_out/transcode/video.c b/modules/stream_out/transcode/video.c
index 74734ee..13df03c 100644
--- a/modules/stream_out/transcode/video.c
+++ b/modules/stream_out/transcode/video.c
@@ -439,9 +439,9 @@ static void transcode_video_size_init( sout_stream_t *p_stream,
int i_src_visible_width = p_vid_out->i_visible_width;
int i_src_visible_height = p_vid_out->i_visible_height;
- if (i_src_visible_width == 0)
+ if (unlikely(i_src_visible_width == 0))
i_src_visible_width = p_vid_out->i_width;
- if (i_src_visible_height == 0)
+ if (unlikely(i_src_visible_height == 0))
i_src_visible_height = p_vid_out->i_height;
--
2.10.1.windows.1
From ea990fc73d07d877e936ec4e08ffa2119f374776 Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@videolabs.io>
Date: Mon, 4 Sep 2017 13:59:25 +0200
Subject: [PATCH 24/26] codec: add a set of functions to use a plain FIFO
It's similar to the block FIFO but with no locking.
---
modules/codec/vlc_fifo_helper.h | 125 ++++++++++++++++++++++++++++++++++++++++
1 file changed, 125 insertions(+)
create mode 100644 modules/codec/vlc_fifo_helper.h
diff --git a/modules/codec/vlc_fifo_helper.h b/modules/codec/vlc_fifo_helper.h
new file mode 100644
index 0000000..49a99b4
--- /dev/null
+++ b/modules/codec/vlc_fifo_helper.h
@@ -0,0 +1,125 @@
+/*****************************************************************************
+ * vlc_fifo_helper.h: Basic FIFO helper functions
+ *****************************************************************************
+ * Copyright (C) 2017 VLC authors and VideoLAN
+ *
+ * Authors: Steve Lhomme <robux4@gmail.com>
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *****************************************************************************/
+
+#ifndef VLC_FIFO_HELPER_H
+#define VLC_FIFO_HELPER_H 1
+
+typedef struct FIFO_ITEM {
+ struct FIFO_ITEM *p_next;
+} fifo_item_t;
+
+typedef struct
+{
+ fifo_item_t *p_first;
+ fifo_item_t **pp_last;
+ size_t i_depth;
+} fifo_t;
+
+static inline void fifo_Init(fifo_t *p_fifo)
+{
+ p_fifo->p_first = NULL;
+ p_fifo->pp_last = &p_fifo->p_first;
+ p_fifo->i_depth = 0;
+}
+
+static inline void fifo_Release(fifo_t *fifo)
+{
+ assert(fifo->i_depth == 0); /* we should have poped all the items */
+}
+
+static inline size_t fifo_GetCount(fifo_t *fifo)
+{
+ return fifo->i_depth;
+}
+
+static inline fifo_item_t *fifo_Show(fifo_t *p_fifo)
+{
+ fifo_item_t *b;
+
+ assert(p_fifo->p_first != NULL);
+ b = p_fifo->p_first;
+
+ return b;
+}
+
+static inline fifo_item_t *fifo_Get(fifo_t *fifo)
+{
+ fifo_item_t *block = fifo->p_first;
+
+ if (block == NULL)
+ return NULL; /* Nothing to do */
+
+ fifo->p_first = block->p_next;
+ if (block->p_next == NULL)
+ fifo->pp_last = &fifo->p_first;
+ block->p_next = NULL;
+
+ assert(fifo->i_depth > 0);
+ fifo->i_depth--;
+
+ return block;
+}
+
+static inline void fifo_Put(fifo_t *fifo, fifo_item_t *p_item)
+{
+ *(fifo->pp_last) = p_item;
+
+ while (p_item != NULL)
+ {
+ fifo->pp_last = &p_item->p_next;
+ fifo->i_depth++;
+
+ p_item = p_item->p_next;
+ }
+}
+
+/* macro to get the proper item type in/out of the FIFO
+ * The item type must have a field fifo_item_t named fifo
+ */
+#define TYPED_FIFO(type, prefix) \
+static inline void prefix ## _fifo_Init(fifo_t *p_fifo) \
+{ \
+ fifo_Init(p_fifo); \
+} \
+static inline void prefix ## _fifo_Release(fifo_t *p_fifo) \
+{ \
+ fifo_Release(p_fifo); \
+} \
+static inline void prefix ## _fifo_Put(fifo_t *p_fifo, type *p_item) \
+{ \
+ fifo_Put(p_fifo, &p_item->fifo); \
+} \
+static inline type *prefix ## _fifo_Get(fifo_t *p_fifo) \
+{ \
+ return (type*)fifo_Get(p_fifo); \
+} \
+static inline type *prefix ## _fifo_Show(fifo_t *p_fifo) \
+{ \
+ return (type*)fifo_Show(p_fifo); \
+} \
+static inline size_t prefix ## _fifo_GetCount(fifo_t *fifo) \
+{ \
+ return fifo->i_depth; \
+}
+
+
+#endif /* VLC_FIFO_HELPER_H */
--
2.10.1.windows.1
From ad4538096f7f2327a6648b5d830095ed03a1ec5e Mon Sep 17 00:00:00 2001
From b09423d3f77397b24f4c81efcea9e26001739cfb Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@ycbcr.xyz>
Date: Wed, 4 Apr 2018 12:10:17 +0200
Subject: [PATCH 24/28] transcode: do not include the decoder padding in the
......
From 856b11ee2eaf6f6238c0276ab82a33c5a1fced84 Mon Sep 17 00:00:00 2001
From: Steve Lhomme <robux4@videolabs.io>
Date: Thu, 31 Aug 2017 18:02:31 +0200
Subject: [PATCH 25/26] qsv: CUMULATIVE PATCH to encode from CPU planes
properly
---
modules/codec/Makefile.am | 2 +-
modules/codec/qsv.c | 455 +++++++++++++++++++++++++++++-----------------
2 files changed, 294 insertions(+), 163 deletions(-)
diff --git a/modules/codec/Makefile.am b/modules/codec/Makefile.am
index 10132a9..c42f40e 100644
--- a/modules/codec/Makefile.am
+++ b/modules/codec/Makefile.am
@@ -595,7 +595,7 @@ libcrystalhd_plugin_la_LIBADD = $(LIBS_crystalhd)
EXTRA_LTLIBRARIES += libcrystalhd_plugin.la
codec_LTLIBRARIES += $(LTLIBcrystalhd)
-libqsv_plugin_la_SOURCES = codec/qsv.c
+libqsv_plugin_la_SOURCES = codec/qsv.c codec/vlc_fifo_helper.h
libqsv_plugin_la_CFLAGS = $(AM_CFLAGS) $(MFX_CFLAGS)
libqsv_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(codecdir)'
libqsv_plugin_la_LIBADD = $(MFX_LIBS)
diff --git a/modules/codec/qsv.c b/modules/codec/qsv.c
index 93752e7..0f865dd 100644
--- a/modules/codec/qsv.c
+++ b/modules/codec/qsv.c
@@ -32,15 +32,20 @@
#include <vlc_plugin.h>
#include <vlc_picture.h>
#include <vlc_codec.h>
+#include <vlc_picture_pool.h>
+
+#include <vlc_fifo_helper.h>
#include <mfx/mfxvideo.h>
#define SOUT_CFG_PREFIX "sout-qsv-"
-/* Default wait on Intel Media SDK SyncOperation. Almost useless when async-depth >= 2 */
-#define QSV_SYNCPOINT_WAIT (420)
+#define QSV_HAVE_CO2 (MFX_VERSION_MAJOR > 1 || (MFX_VERSION_MAJOR == 1 && MFX_VERSION_MINOR >= 6))
+
+/* Default wait on libavcodec */
+#define QSV_SYNCPOINT_WAIT (1000)
/* Encoder input synchronization busy wait loop time */
-#define QSV_BUSYWAIT_TIME (10000)
+#define QSV_BUSYWAIT_TIME VLC_HARD_MIN_SLEEP
/* The SDK doesn't have a default bitrate, so here's one. */
#define QSV_BITRATE_DEFAULT (842)
@@ -151,37 +156,41 @@ static void Close(vlc_object_t *);
"numbers may result on better throughput depending on hardware. " \
"MPEG2 needs at least 1 here.")
-static const int const profile_h264_list[] =
- { 0, MFX_PROFILE_AVC_BASELINE, MFX_PROFILE_AVC_MAIN,
+static const int profile_h264_list[] =
+ { MFX_PROFILE_UNKNOWN, MFX_PROFILE_AVC_CONSTRAINED_BASELINE, MFX_PROFILE_AVC_MAIN,
MFX_PROFILE_AVC_EXTENDED, MFX_PROFILE_AVC_HIGH };
static const char *const profile_h264_text[] =
{ "decide", "baseline", "main", "extended", "high" };
-static const int const profile_mpeg2_list[] =
- { 0, MFX_PROFILE_MPEG2_SIMPLE, MFX_PROFILE_MPEG2_MAIN,
+static const int profile_mpeg2_list[] =
+ { MFX_PROFILE_UNKNOWN, MFX_PROFILE_MPEG2_SIMPLE, MFX_PROFILE_MPEG2_MAIN,
MFX_PROFILE_MPEG2_HIGH };
static const char *const profile_mpeg2_text[] =
{ "decide", "simple", "main", "high" };
-static const int const level_h264_list[] =
- { 0, 10, 9, 12, 13, 20, 21, 22, 30, 31, 32, 40, 41, 42, 50, 51, 52};
+static const int level_h264_list[] =
+ { MFX_LEVEL_UNKNOWN, MFX_LEVEL_AVC_1, MFX_LEVEL_AVC_1b, MFX_LEVEL_AVC_12,
+ MFX_LEVEL_AVC_13, MFX_LEVEL_AVC_2, MFX_LEVEL_AVC_21, MFX_LEVEL_AVC_22,
+ MFX_LEVEL_AVC_3, MFX_LEVEL_AVC_31, MFX_LEVEL_AVC_32, MFX_LEVEL_AVC_4,
+ MFX_LEVEL_AVC_41, MFX_LEVEL_AVC_42, MFX_LEVEL_AVC_5, MFX_LEVEL_AVC_51,
+ MFX_LEVEL_AVC_52};
static const char *const level_h264_text[] =
{ "decide", "1", "1.1b", "1.2", "1.3", "2", "2.1", "2.2", "3", "3.1",
"3.2", "4", "4.1", "4.2", "5", "5.1", "5.2" };
-static const int const level_mpeg2_list[] =
- { 0, MFX_LEVEL_MPEG2_LOW, MFX_LEVEL_MPEG2_MAIN,
+static const int level_mpeg2_list[] =
+ { MFX_LEVEL_UNKNOWN, MFX_LEVEL_MPEG2_LOW, MFX_LEVEL_MPEG2_MAIN,
MFX_LEVEL_MPEG2_HIGH, MFX_LEVEL_MPEG2_HIGH1440 };
static const char *const level_mpeg2_text[] =
{ "decide", "low", "main", "high", "high1440" };
-static const int const target_usage_list[] =
- { 0, MFX_TARGETUSAGE_BEST_QUALITY, MFX_TARGETUSAGE_BALANCED,
+static const int target_usage_list[] =
+ { MFX_TARGETUSAGE_UNKNOWN, MFX_TARGETUSAGE_BEST_QUALITY, MFX_TARGETUSAGE_BALANCED,
MFX_TARGETUSAGE_BEST_SPEED };
static const char *const target_usage_text[] =
{ "decide", "quality", "balanced", "speed" };
-static const int const rc_method_list[] =
+static const int rc_method_list[] =
{ MFX_RATECONTROL_CBR, MFX_RATECONTROL_VBR,
MFX_RATECONTROL_CQP, MFX_RATECONTROL_AVBR};
static const char *const rc_method_text[] =
@@ -255,33 +264,39 @@ static const char *const sout_options[] = {
};
// Frame pool for QuickSync video encoder with Intel Media SDK's format frames.
-typedef struct qsv_frame_pool_t
+typedef struct _QSVFrame
{
- mfxFrameInfo fmt; // IntelMediaSDK format info.
- mfxFrameSurface1 *frames; // An allocated array of 'size' frames.
- size_t size; // The number of frame in the pool.
-} qsv_frame_pool_t;
+ struct _QSVFrame *next;
+ picture_t *pic;
+ mfxFrameSurface1 surface;
+ mfxEncodeCtrl enc_ctrl;
+ int used;
+} QSVFrame;
typedef struct async_task_t
{
+ fifo_item_t fifo;
mfxBitstream bs; // Intel's bitstream structure.
- mfxSyncPoint syncp; // Async Task Sync Point.
+ mfxSyncPoint *syncp; // Async Task Sync Point.
block_t *block; // VLC's block structure to be returned by Encode.
} async_task_t;
+TYPED_FIFO(async_task_t, async_task_t)
+
struct encoder_sys_t
{
mfxSession session; // Intel Media SDK Session.
mfxVideoParam params; // Encoding parameters.
- mfxIMPL impl; // Actual implementation (hw/sw).
- qsv_frame_pool_t frames; // IntelMediaSDK's frame pool.
+ QSVFrame *work_frames; // IntelMediaSDK's frame pool.
uint64_t dts_warn_counter; // DTS warning counter for rate-limiting of msg;
- uint64_t busy_warn_counter; // Device Bussy warning counter for rate-limiting of msg;
+ uint64_t busy_warn_counter; // Device Busy warning counter for rate-limiting of msg;
uint64_t async_depth; // Number of parallel encoding operations.
- uint64_t first_task; // The next sync point to be synchronized.
- async_task_t *tasks; // The async encoding tasks.
+ fifo_t packets; // FIFO of queued packets
mtime_t offset_pts; // The pts of the first frame, to avoid conversion overflow.
mtime_t last_dts; // The dts of the last frame, to interpolate over buggy dts
+
+ picture_pool_t *input_pool; // pool of pictures to feed the decoder
+ // as it doesn't like constantly changing buffers
};
static block_t *Encode(encoder_t *, picture_t *);
@@ -297,43 +312,16 @@ static inline uint64_t qsv_mtime_to_timestamp(mtime_t vlc_ts)
return vlc_ts / UINT64_C(100) * UINT64_C(9);
}
-/*
- * Create a new frame pool with 'size' frames in it. Pools cannot be resized.
- */
-static int qsv_frame_pool_Init(qsv_frame_pool_t *pool,
- mfxFrameAllocRequest *request,
- uint64_t async_depth)
-{
- size_t size = request->NumFrameSuggested + async_depth;
-
- pool->frames = calloc(size, sizeof(mfxFrameSurface1));
- if (unlikely(!pool->frames))
- return VLC_ENOMEM;
-
- pool->size = size;
- memcpy(&pool->fmt, &request->Info, sizeof(request->Info));
-
- for (size_t i = 0; i < size; i++) {
- memcpy(&pool->frames[i].Info, &request->Info, sizeof(request->Info));
- pool->frames[i].Data.Pitch = QSV_ALIGN(32, request->Info.Width);
- }
-
- return VLC_SUCCESS;
-}
-
-/*
- * Destroys a pool frame. Only call this function after a MFXClose
- * call since we doesn't check for Locked frames.
- */
-static void qsv_frame_pool_Destroy(qsv_frame_pool_t *pool)
+static void clear_unused_frames(encoder_sys_t *sys)
{
- for (size_t i = 0; i < pool->size; i++) {
- picture_t *pic = (picture_t *) pool->frames[i].Data.MemId;
- if (pic)
- picture_Release(pic);
+ QSVFrame *cur = sys->work_frames;
+ while (cur) {
+ if (cur->used && !cur->surface.Data.Locked) {
+ picture_Release(cur->pic);
+ cur->used = 0;
+ }
+ cur = cur->next;
}
-
- free(pool->frames);
}
/*
@@ -341,40 +329,38 @@ static void qsv_frame_pool_Destroy(qsv_frame_pool_t *pool)
* necessary associates the new picture with it and return the frame.
* Returns 0 if there's an error.
*/
-static mfxFrameSurface1 *qsv_frame_pool_Get(encoder_sys_t *sys, picture_t *pic)
+static int get_free_frame(encoder_sys_t *sys, QSVFrame **out)
{
- qsv_frame_pool_t *pool = &sys->frames;
- for (size_t i = 0; i < pool->size; i++) {
- mfxFrameSurface1 *frame = &pool->frames[i];
- if (frame->Data.Locked)
- continue;
- if (frame->Data.MemId)
- picture_Release((picture_t *)frame->Data.MemId);
-
- frame->Data.MemId = pic;
- frame->Data.Y = pic->p[0].p_pixels;
- frame->Data.U = pic->p[1].p_pixels;
- frame->Data.V = pic->p[1].p_pixels + 1;
- frame->Data.TimeStamp = qsv_mtime_to_timestamp(pic->date - sys->offset_pts);
-
- // Specify picture structure at runtime.
- if (pic->b_progressive)
- frame->Info.PicStruct = MFX_PICSTRUCT_PROGRESSIVE;
- else if (pic->b_top_field_first)
- frame->Info.PicStruct = MFX_PICSTRUCT_FIELD_TFF;
- else
- frame->Info.PicStruct = MFX_PICSTRUCT_FIELD_BFF;
+ QSVFrame *frame, **last;
+
+ clear_unused_frames(sys);
- picture_Hold(pic);
+ frame = sys->work_frames;
+ last = &sys->work_frames;
+ while (frame) {
+ if (!frame->used) {
+ *out = frame;
+ frame->used = 1;
+ return VLC_SUCCESS;
+ }
- return frame;
+ last = &frame->next;
+ frame = frame->next;
}
- return NULL;
+ frame = calloc(1,sizeof(QSVFrame));
+ if (unlikely(frame==NULL))
+ return VLC_ENOMEM;
+ *last = frame;
+
+ *out = frame;
+ frame->used = 1;
+
+ return VLC_SUCCESS;
}
static uint64_t qsv_params_get_value(const char *const *text,
- const int const *list,
+ const int *list,
size_t size, char *sel)
{
size_t result = 0;
@@ -401,13 +387,41 @@ static int Open(vlc_object_t *this)
encoder_sys_t *sys = NULL;
mfxStatus sts = MFX_ERR_NONE;
- mfxFrameAllocRequest alloc_request;
+ mfxFrameAllocRequest alloc_request = { 0 };
+ uint8_t sps_buf[128];
+ uint8_t pps_buf[128];
mfxExtCodingOptionSPSPPS headers;
- mfxExtBuffer *extended_params[1] = {(mfxExtBuffer *)&headers};
+ mfxExtCodingOption co = {
+ .Header.BufferId = MFX_EXTBUFF_CODING_OPTION,
+ .Header.BufferSz = sizeof(co),
+ .PicTimingSEI = MFX_CODINGOPTION_ON,
+ };
+#if QSV_HAVE_CO2
+ mfxExtCodingOption2 co2 = {
+ .Header.BufferId = MFX_EXTBUFF_CODING_OPTION2,
+ .Header.BufferSz = sizeof(co2),
+ };
+#endif
+ mfxExtBuffer *init_params[] =
+ {
+ (mfxExtBuffer*)&co,
+#if QSV_HAVE_CO2
+ (mfxExtBuffer*)&co2,
+#endif
+ };
+ mfxExtBuffer *extended_params[] = {
+ (mfxExtBuffer*)&headers,
+ (mfxExtBuffer*)&co,
+#if QSV_HAVE_CO2
+ (mfxExtBuffer*)&co2,
+#endif
+ };
+ mfxVersion ver = { { 1, 1 } };
+ mfxIMPL impl;
+ mfxVideoParam param_out = { 0 };
uint8_t *p_extra;
size_t i_extra;
- uint8_t nals[128];
if (enc->fmt_out.i_codec != VLC_CODEC_H264 &&
enc->fmt_out.i_codec != VLC_CODEC_MPGV && !enc->obj.force)
@@ -425,7 +439,7 @@ static int Open(vlc_object_t *this)
return VLC_ENOMEM;
/* Initialize dispatcher, it will loads the actual SW/HW Implementation */
- sts = MFXInit(MFX_IMPL_AUTO, 0, &sys->session);
+ sts = MFXInit(MFX_IMPL_AUTO_ANY, &ver, &sys->session);
if (sts != MFX_ERR_NONE) {
msg_Err(enc, "Unable to find an Intel Media SDK implementation.");
@@ -433,24 +447,19 @@ static int Open(vlc_object_t *this)
return VLC_EGENERIC;
}
+ enc->p_sys = sys;
+