Compare commits

...

4 commits

Author SHA1 Message Date
Seungha Yang ff4bb302ef Merge branch 'd3d12-more-enc' into 'main'
Draft: d3d12: Add H.265 encoder

See merge request gstreamer/gstreamer!6705
2024-04-27 17:55:07 +00:00
Nirbheek Chauhan d7eeb62f38 meson: Fix Python library searching on Windows
Neither LIBDIR nor LIBPL are set with the native windows Python
(unlike MSYS2), so we need to use `prefix` which takes us to the
rootdir of the Python installation.

The name is also different: it's python312.dll, not python3.12.dll.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6734>
2024-04-27 01:30:21 +00:00
Nirbheek Chauhan 753aeccde7 meson: Fix Python library name fetching on Windows
`python.get_variable('FOO', [])` becomes `python.get_variable('FOO')`
due to how Meson treats empty arrays in arguments, which breaks the
fallback feature of get_variable().

So we need to actually check whether the variable exists before trying
to fetch it.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6734>
2024-04-27 01:30:21 +00:00
Seungha Yang fb92af246f d3d12: Add H.265 encoder 2024-04-21 21:07:08 +09:00
8 changed files with 2929 additions and 20 deletions

View file

@ -441,12 +441,13 @@ gst_d3d12_encoder_src_query (GstVideoEncoder * encoder, GstQuery * query)
}
static GstBufferPool *
gst_d3d12_encoder_create_upload_pool (GstD3D12Encoder * self)
gst_d3d12_encoder_create_upload_pool (GstD3D12Encoder * self,
GstVideoFormat format)
{
auto priv = self->priv;
GstVideoInfo info;
gst_video_info_set_format (&info, GST_VIDEO_FORMAT_NV12,
gst_video_info_set_format (&info, format,
priv->config.resolution.Width, priv->config.resolution.Height);
auto caps = gst_video_info_to_caps (&info);
auto pool = gst_d3d12_buffer_pool_new (self->device);
@ -609,7 +610,7 @@ gst_d3d12_encoder_set_format (GstVideoEncoder * encoder,
auto & resource_req = priv->resource_req;
resource_req.Codec = klass->codec;
resource_req.Profile = config.profile_desc;
resource_req.InputFormat = DXGI_FORMAT_NV12;
resource_req.InputFormat = config.encoder_format;
resource_req.PictureTargetResolution = config.resolution;
auto hr = video_device->CheckFeatureSupport
(D3D12_FEATURE_VIDEO_ENCODER_RESOURCE_REQUIREMENTS,
@ -628,7 +629,7 @@ gst_d3d12_encoder_set_format (GstVideoEncoder * encoder,
}
auto device = gst_d3d12_device_get_device_handle (self->device);
priv->format_info.Format = DXGI_FORMAT_NV12;
priv->format_info.Format = config.encoder_format;
hr = device->CheckFeatureSupport (D3D12_FEATURE_FORMAT_INFO,
&priv->format_info, sizeof (priv->format_info));
if (!gst_d3d12_result (hr, self->device)) {
@ -686,7 +687,8 @@ gst_d3d12_encoder_set_format (GstVideoEncoder * encoder,
resource_req.MaxEncoderOutputMetadataBufferSize,
resolved_metadata_size, bitstream_size, ASYNC_DEPTH);
session->upload_pool = gst_d3d12_encoder_create_upload_pool (self);
session->upload_pool = gst_d3d12_encoder_create_upload_pool (self,
GST_VIDEO_INFO_FORMAT (&state->info));
if (!session->upload_pool)
return FALSE;
@ -1401,7 +1403,7 @@ gst_d3d12_encoder_handle_frame (GstVideoEncoder * encoder,
meta_in_args.EncoderCodec = klass->codec;
meta_in_args.EncoderProfile = config.profile_desc;
meta_in_args.EncoderInputFormat = DXGI_FORMAT_NV12;
meta_in_args.EncoderInputFormat = config.encoder_format;
meta_in_args.EncodedPictureEffectiveResolution = config.resolution;
meta_in_args.HWLayoutMetadata.pBuffer = metadata.Get ();
meta_in_args.HWLayoutMetadata.Offset = 0;

View file

@ -50,6 +50,7 @@ struct GstD3D12EncoderConfig
D3D12_VIDEO_ENCODER_RATE_CONTROL_QVBR qvbr;
D3D12_VIDEO_ENCODER_RATE_CONTROL rate_control;
guint max_subregions;
DXGI_FORMAT encoder_format;
};
enum GstD3D12EncoderSeiInsertMode

View file

@ -647,6 +647,7 @@ gst_d3d12_h264_enc_class_init (GstD3D12H264EncClass * klass, gpointer data)
encoder_class->transform_meta =
GST_DEBUG_FUNCPTR (gst_d3d12_h264_enc_transform_meta);
d3d12enc_class->codec = D3D12_VIDEO_ENCODER_CODEC_H264;
d3d12enc_class->adapter_luid = cdata->luid;
d3d12enc_class->device_id = cdata->device_id;
d3d12enc_class->vendor_id = cdata->vendor_id;
@ -1831,6 +1832,8 @@ gst_d3d12_h264_enc_new_sequence (GstD3D12Encoder * encoder,
config->resolution.Width = GST_ROUND_UP_16 (info->width);
config->resolution.Height = GST_ROUND_UP_16 (info->height);
config->encoder_format = DXGI_FORMAT_NV12;
priv->selected_profile = GST_H264_PROFILE_MAIN;
priv->profile_h264 = D3D12_VIDEO_ENCODER_PROFILE_H264_MAIN;

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,33 @@
/* GStreamer
* Copyright (C) 2024 Seungha Yang <seungha@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#pragma once
#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstd3d12.h"
G_BEGIN_DECLS
void gst_d3d12_h265_enc_register (GstPlugin * plugin,
GstD3D12Device * device,
ID3D12VideoDevice * video_device,
guint rank);
G_END_DECLS

View file

@ -12,6 +12,7 @@ d3d12_sources = [
'gstd3d12h264dec.cpp',
'gstd3d12h264enc.cpp',
'gstd3d12h265dec.cpp',
'gstd3d12h265enc.cpp',
'gstd3d12ipc.cpp',
'gstd3d12ipcclient.cpp',
'gstd3d12ipcserver.cpp',

View file

@ -42,6 +42,7 @@
#include "gstd3d12h264dec.h"
#include "gstd3d12h264enc.h"
#include "gstd3d12h265dec.h"
#include "gstd3d12h265enc.h"
#include "gstd3d12vp8dec.h"
#include "gstd3d12vp9dec.h"
#include "gstd3d12av1dec.h"
@ -108,6 +109,8 @@ plugin_init (GstPlugin * plugin)
gst_d3d12_h264_enc_register (plugin, device, video_device.Get (),
GST_RANK_NONE);
gst_d3d12_h265_enc_register (plugin, device, video_device.Get (),
GST_RANK_NONE);
gst_object_unref (device);
}

View file

@ -45,35 +45,53 @@ pylib_loc = get_option('libpython-dir')
fsmod = import('fs')
pylib_prefix = 'lib'
pylib_suffix = 'so'
pylib_ver = python_dep.version()
pylib_locs = []
if host_system == 'windows'
if cc.get_argument_syntax() == 'msvc'
pylib_prefix = ''
endif
pylib_suffix = 'dll'
pylib_ver = pylib_ver.replace('.', '')
elif host_system == 'darwin'
pylib_suffix = 'dylib'
endif
pylib_fnames = []
# Library name with soversion, non-devel package
pylib_fnames += python.get_variable('INSTSONAME', [])
if python.has_variable('INSTSONAME')
# For example, libpython3.12.so.1.0 (Linux), libpython3.11.dll.a (MSYS2), etc.
pylib_fnames += python.get_variable('INSTSONAME')
endif
# Library name without soversion, devel package, framework, etc.
pylib_fnames += python.get_variable('LDLIBRARY', [])
if python.has_variable('LDLIBRARY')
# For example, libpython3.12.so (Linux), libpython3.11.dll.a (MSYS2), etc.
pylib_fnames += python.get_variable('LDLIBRARY')
endif
# Manually construct name as a fallback
pylib_fnames += [
pylib_prefix + 'python' + python_dep.version() + python_abi_flags + '.' + pylib_suffix
pylib_prefix + 'python' + pylib_ver + python_abi_flags + '.' + pylib_suffix
]
if pylib_loc != ''
pylib_locs = [pylib_loc]
else
pylib_locs = [
python.get_variable('LIBDIR', ''),
python.get_variable('LIBPL', ''),
]
if python.has_variable('LIBDIR')
pylib_locs += python.get_variable('LIBDIR')
endif
if python.has_variable('LIBPL')
pylib_locs += python.get_variable('LIBPL')
endif
# On Windows, python312.dll is in the rootdir where Python is installed,
# which is configured as the "prefix" in sysconfig.
if host_system == 'windows'
pylib_locs += python.get_variable('prefix')
endif
endif
pylib_fname = ''
foreach loc: pylib_locs
foreach fname: pylib_fnames
if fsmod.exists(loc / fname)
fpath = loc / fname
debug(f'Looking for Python library at: @fpath@')
if fsmod.exists(fpath)
pylib_fname = fname
message(f'PY_LIB_FNAME = @fname@ (@loc@)')
break
@ -81,12 +99,7 @@ foreach loc: pylib_locs
endforeach
endforeach
if pylib_fname == ''
error_msg = 'Could not find python library to load'
if python_opt.enabled()
error(error_msg)
else
message(error_msg)
endif
message('Could not find python library to load, will try loading at runtime')
endif
pygi_override_dir = get_option('pygi-overrides-dir')