mediafoundation: Run gst-indent

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/2375>
This commit is contained in:
Seungha Yang 2021-07-03 22:56:48 +09:00
parent b269cd5319
commit 3f8632dc96
13 changed files with 502 additions and 473 deletions

View file

@ -43,7 +43,9 @@
#include <vector>
#include <string>
/* *INDENT-OFF* */
using namespace Microsoft::WRL;
/* *INDENT-ON* */
GST_DEBUG_CATEGORY (gst_mf_aac_enc_debug);
#define GST_CAT_DEFAULT gst_mf_aac_enc_debug
@ -70,6 +72,7 @@ typedef struct _GstMFAacEncClass
} GstMFAacEncClass;
/* *INDENT-OFF* */
typedef struct
{
GstCaps *sink_caps;
@ -79,6 +82,7 @@ typedef struct
guint device_index;
std::set<UINT32> bitrate_list;
} GstMFAacEncClassData;
/* *INDENT-ON* */
static GstElementClass *parent_class = NULL;
@ -110,25 +114,27 @@ gst_mf_aac_enc_class_init (GstMFAacEncClass * klass, gpointer data)
gobject_class->get_property = gst_mf_aac_enc_get_property;
gobject_class->set_property = gst_mf_aac_enc_set_property;
bitrate_blurb =
"Bitrate in bit/sec, (0 = auto), valid values are { 0";
bitrate_blurb = "Bitrate in bit/sec, (0 = auto), valid values are { 0";
/* *INDENT-OFF* */
for (auto iter: cdata->bitrate_list) {
bitrate_blurb += ", " + std::to_string (iter);
/* std::set<> stores values in a sorted fashion */
max_bitrate = iter;
}
bitrate_blurb += " }";
/* *INDENT-ON* */
g_object_class_install_property (gobject_class, PROP_BITRATE,
g_param_spec_uint ("bitrate", "Bitrate", bitrate_blurb.c_str(), 0,
g_param_spec_uint ("bitrate", "Bitrate", bitrate_blurb.c_str (), 0,
max_bitrate, DEFAULT_BITRATE,
(GParamFlags) (GST_PARAM_MUTABLE_READY | G_PARAM_READWRITE |
G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK)));
G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK)));
long_name = g_strdup_printf ("Media Foundation %s", cdata->device_name);
classification = g_strdup_printf ("Codec/Encoder/Audio%s",
(cdata->enum_flags & MFT_ENUM_FLAG_HARDWARE) == MFT_ENUM_FLAG_HARDWARE ?
"/Hardware" : "");
"/Hardware" : "");
gst_element_class_set_metadata (element_class, long_name,
classification,
"Microsoft Media Foundation AAC Encoder",
@ -147,8 +153,7 @@ gst_mf_aac_enc_class_init (GstMFAacEncClass * klass, gpointer data)
GST_DEBUG_FUNCPTR (gst_mf_aac_enc_get_output_type);
mfenc_class->get_input_type =
GST_DEBUG_FUNCPTR (gst_mf_aac_enc_get_input_type);
mfenc_class->set_src_caps =
GST_DEBUG_FUNCPTR (gst_mf_aac_enc_set_src_caps);
mfenc_class->set_src_caps = GST_DEBUG_FUNCPTR (gst_mf_aac_enc_set_src_caps);
mfenc_class->codec_id = MFAudioFormat_AAC;
mfenc_class->enum_flags = cdata->enum_flags;
@ -207,9 +212,9 @@ gst_mf_aac_enc_get_output_type (GstMFAudioEnc * mfenc, GstAudioInfo * info,
GstMFTransform *transform = mfenc->transform;
GList *output_list = NULL;
GList *iter;
ComPtr<IMFMediaType> target_output;
std::vector<ComPtr<IMFMediaType>> filtered_types;
std::set<UINT32> bitrate_list;
ComPtr < IMFMediaType > target_output;
std::vector < ComPtr < IMFMediaType >> filtered_types;
std::set < UINT32 > bitrate_list;
UINT32 bitrate;
UINT32 target_bitrate = 0;
HRESULT hr;
@ -268,12 +273,12 @@ gst_mf_aac_enc_get_output_type (GstMFAudioEnc * mfenc, GstAudioInfo * info,
g_list_free_full (output_list, (GDestroyNotify) gst_mf_media_type_release);
if (filtered_types.empty()) {
if (filtered_types.empty ()) {
GST_ERROR_OBJECT (self, "Couldn't find target output type");
return FALSE;
}
GST_DEBUG_OBJECT (self, "have %d candidate output", filtered_types.size());
GST_DEBUG_OBJECT (self, "have %d candidate output", filtered_types.size ());
/* 2. Find the best matching bitrate */
bitrate = self->bitrate;
@ -310,6 +315,8 @@ gst_mf_aac_enc_get_output_type (GstMFAudioEnc * mfenc, GstAudioInfo * info,
}
GST_DEBUG_OBJECT (self, "Available bitrates");
/* *INDENT-OFF* */
for (auto it: bitrate_list)
GST_DEBUG_OBJECT (self, "\t%d", it);
@ -335,13 +342,14 @@ gst_mf_aac_enc_get_output_type (GstMFAudioEnc * mfenc, GstAudioInfo * info,
break;
}
}
/* *INDENT-ON* */
if (!target_output) {
GST_ERROR_OBJECT (self, "Failed to decide final output type");
return FALSE;
}
*output_type = target_output.Detach();
*output_type = target_output.Detach ();
return TRUE;
}
@ -354,9 +362,9 @@ gst_mf_aac_enc_get_input_type (GstMFAudioEnc * mfenc, GstAudioInfo * info,
GstMFTransform *transform = mfenc->transform;
GList *input_list = NULL;
GList *iter;
ComPtr<IMFMediaType> target_input;
std::vector<ComPtr<IMFMediaType>> filtered_types;
std::set<UINT32> bitrate_list;
ComPtr < IMFMediaType > target_input;
std::vector < ComPtr < IMFMediaType >> filtered_types;
std::set < UINT32 > bitrate_list;
HRESULT hr;
if (!gst_mf_transform_get_input_available_types (transform, &input_list)) {
@ -407,25 +415,24 @@ gst_mf_aac_enc_get_input_type (GstMFAudioEnc * mfenc, GstAudioInfo * info,
g_list_free_full (input_list, (GDestroyNotify) gst_mf_media_type_release);
if (filtered_types.empty()) {
if (filtered_types.empty ()) {
GST_ERROR_OBJECT (self, "Couldn't find target input type");
return FALSE;
}
GST_DEBUG_OBJECT (self, "Total %d input types are available",
filtered_types.size());
filtered_types.size ());
/* Just select the first one */
target_input = *filtered_types.begin();
target_input = *filtered_types.begin ();
*input_type = target_input.Detach();
*input_type = target_input.Detach ();
return TRUE;
}
static gboolean
gst_mf_aac_enc_set_src_caps (GstMFAudioEnc * mfenc,
GstAudioInfo * info)
gst_mf_aac_enc_set_src_caps (GstMFAudioEnc * mfenc, GstAudioInfo * info)
{
GstMFAacEnc *self = (GstMFAacEnc *) mfenc;
HRESULT hr;
@ -434,10 +441,11 @@ gst_mf_aac_enc_set_src_caps (GstMFAudioEnc * mfenc,
UINT8 *blob = NULL;
UINT32 blob_size = 0;
gboolean ret;
ComPtr<IMFMediaType> output_type;
ComPtr < IMFMediaType > output_type;
static const guint config_data_offset = 12;
if (!gst_mf_transform_get_output_current_type (mfenc->transform, &output_type)) {
if (!gst_mf_transform_get_output_current_type (mfenc->transform,
&output_type)) {
GST_ERROR_OBJECT (self, "Couldn't get current output type");
return FALSE;
}
@ -480,7 +488,8 @@ gst_mf_aac_enc_set_src_caps (GstMFAudioEnc * mfenc,
blob + config_data_offset, blob_size - config_data_offset);
CoTaskMemFree (blob);
ret = gst_audio_encoder_set_output_format (GST_AUDIO_ENCODER (self), src_caps);
ret =
gst_audio_encoder_set_output_format (GST_AUDIO_ENCODER (self), src_caps);
if (!ret) {
GST_WARNING_OBJECT (self,
"Couldn't set output format %" GST_PTR_FORMAT, src_caps);
@ -494,7 +503,7 @@ static void
gst_mf_aac_enc_register (GstPlugin * plugin, guint rank,
const gchar * device_name, guint32 enum_flags, guint device_index,
GstCaps * sink_caps, GstCaps * src_caps,
const std::set<UINT32> &bitrate_list)
const std::set < UINT32 > &bitrate_list)
{
GType type;
gchar *type_name;
@ -562,9 +571,9 @@ gst_mf_aac_enc_plugin_init_internal (GstPlugin * plugin, guint rank,
gchar *device_name = NULL;
GList *output_list = NULL;
GList *iter;
std::set<UINT32> channels_list;
std::set<UINT32> rate_list;
std::set<UINT32> bitrate_list;
std::set < UINT32 > channels_list;
std::set < UINT32 > rate_list;
std::set < UINT32 > bitrate_list;
gboolean config_found = FALSE;
GValue channles_value = G_VALUE_INIT;
GValue rate_value = G_VALUE_INIT;
@ -583,7 +592,8 @@ gst_mf_aac_enc_plugin_init_internal (GstPlugin * plugin, guint rank,
goto done;
}
GST_INFO_OBJECT (transform, "Have %d output type", g_list_length (output_list));
GST_INFO_OBJECT (transform, "Have %d output type",
g_list_length (output_list));
for (iter = output_list, i = 0; iter; iter = g_list_next (iter), i++) {
UINT32 channels, rate, bitrate;
@ -652,6 +662,7 @@ gst_mf_aac_enc_plugin_init_internal (GstPlugin * plugin, guint rank,
g_value_init (&channles_value, GST_TYPE_LIST);
g_value_init (&rate_value, GST_TYPE_LIST);
/* *INDENT-OFF* */
for (auto it: channels_list) {
GValue channles = G_VALUE_INIT;
@ -667,6 +678,7 @@ gst_mf_aac_enc_plugin_init_internal (GstPlugin * plugin, guint rank,
g_value_set_int (&rate, (gint) it);
gst_value_list_append_and_take_value (&rate_value, &rate);
}
/* *INDENT-ON* */
gst_caps_set_value (src_caps, "channels", &channles_value);
gst_caps_set_value (sink_caps, "channels", &channles_value);
@ -680,7 +692,7 @@ gst_mf_aac_enc_plugin_init_internal (GstPlugin * plugin, guint rank,
gst_mf_aac_enc_register (plugin, rank, device_name, enum_flags, device_index,
sink_caps, src_caps, bitrate_list);
done:
done:
if (output_list)
g_list_free_full (output_list, (GDestroyNotify) gst_mf_media_type_release);
g_free (device_name);
@ -704,7 +716,7 @@ gst_mf_aac_enc_plugin_init (GstPlugin * plugin, guint rank)
enum_params.category = MFT_CATEGORY_AUDIO_ENCODER;
enum_params.enum_flags = (MFT_ENUM_FLAG_HARDWARE | MFT_ENUM_FLAG_ASYNCMFT |
MFT_ENUM_FLAG_SORTANDFILTER | MFT_ENUM_FLAG_SORTANDFILTER_APPROVED_ONLY);
MFT_ENUM_FLAG_SORTANDFILTER | MFT_ENUM_FLAG_SORTANDFILTER_APPROVED_ONLY);
enum_params.output_typeinfo = &output_type;
/* register hardware encoders first (likey no hardware audio encoder) */

View file

@ -26,7 +26,9 @@
#include <wrl.h>
#include <string.h>
/* *INDENT-OFF* */
using namespace Microsoft::WRL;
/* *INDENT-ON* */
GST_DEBUG_CATEGORY (gst_mf_audio_enc_debug);
#define GST_CAT_DEFAULT gst_mf_audio_enc_debug
@ -35,14 +37,14 @@ GST_DEBUG_CATEGORY (gst_mf_audio_enc_debug);
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GstMFAudioEnc, gst_mf_audio_enc,
GST_TYPE_AUDIO_ENCODER,
GST_DEBUG_CATEGORY_INIT (gst_mf_audio_enc_debug, "mfaudioenc", 0,
"mfaudioenc"));
"mfaudioenc"));
static gboolean gst_mf_audio_enc_open (GstAudioEncoder * enc);
static gboolean gst_mf_audio_enc_close (GstAudioEncoder * enc);
static gboolean gst_mf_audio_enc_set_format (GstAudioEncoder * enc,
GstAudioInfo * info);
static GstFlowReturn gst_mf_audio_enc_handle_frame (GstAudioEncoder * enc,
GstBuffer *buffer);
GstBuffer * buffer);
static GstFlowReturn gst_mf_audio_enc_drain (GstAudioEncoder * enc);
static void gst_mf_audio_enc_flush (GstAudioEncoder * enc);
@ -56,8 +58,7 @@ gst_mf_audio_enc_class_init (GstMFAudioEncClass * klass)
audioenc_class->set_format = GST_DEBUG_FUNCPTR (gst_mf_audio_enc_set_format);
audioenc_class->handle_frame =
GST_DEBUG_FUNCPTR (gst_mf_audio_enc_handle_frame);
audioenc_class->flush =
GST_DEBUG_FUNCPTR (gst_mf_audio_enc_flush);
audioenc_class->flush = GST_DEBUG_FUNCPTR (gst_mf_audio_enc_flush);
gst_type_mark_as_plugin_api (GST_TYPE_MF_AUDIO_ENC, (GstPluginAPIFlags) 0);
}
@ -112,8 +113,8 @@ gst_mf_audio_enc_set_format (GstAudioEncoder * enc, GstAudioInfo * info)
{
GstMFAudioEnc *self = GST_MF_AUDIO_ENC (enc);
GstMFAudioEncClass *klass = GST_MF_AUDIO_ENC_GET_CLASS (enc);
ComPtr<IMFMediaType> in_type;
ComPtr<IMFMediaType> out_type;
ComPtr < IMFMediaType > in_type;
ComPtr < IMFMediaType > out_type;
GST_DEBUG_OBJECT (self, "Set format");
@ -130,7 +131,7 @@ gst_mf_audio_enc_set_format (GstAudioEncoder * enc, GstAudioInfo * info)
return FALSE;
}
gst_mf_dump_attributes (out_type.Get(), "Set output type", GST_LEVEL_DEBUG);
gst_mf_dump_attributes (out_type.Get (), "Set output type", GST_LEVEL_DEBUG);
if (!gst_mf_transform_set_output_type (self->transform, out_type.Get ())) {
GST_ERROR_OBJECT (self, "Couldn't set output type");
@ -143,7 +144,7 @@ gst_mf_audio_enc_set_format (GstAudioEncoder * enc, GstAudioInfo * info)
return FALSE;
}
gst_mf_dump_attributes (in_type.Get(), "Set input type", GST_LEVEL_DEBUG);
gst_mf_dump_attributes (in_type.Get (), "Set input type", GST_LEVEL_DEBUG);
if (!gst_mf_transform_set_input_type (self->transform, in_type.Get ())) {
GST_ERROR_OBJECT (self, "Couldn't set input media type");
@ -175,8 +176,8 @@ static gboolean
gst_mf_audio_enc_process_input (GstMFAudioEnc * self, GstBuffer * buffer)
{
HRESULT hr;
ComPtr<IMFSample> sample;
ComPtr<IMFMediaBuffer> media_buffer;
ComPtr < IMFSample > sample;
ComPtr < IMFMediaBuffer > media_buffer;
BYTE *data;
gboolean res = FALSE;
GstMapInfo info;
@ -244,8 +245,8 @@ gst_mf_audio_enc_process_output (GstMFAudioEnc * self)
GstMFAudioEncClass *klass = GST_MF_AUDIO_ENC_GET_CLASS (self);
HRESULT hr;
BYTE *data;
ComPtr<IMFMediaBuffer> media_buffer;
ComPtr<IMFSample> sample;
ComPtr < IMFMediaBuffer > media_buffer;
ComPtr < IMFSample > sample;
GstBuffer *buffer;
GstFlowReturn res = GST_FLOW_ERROR;
DWORD buffer_len;
@ -273,8 +274,7 @@ gst_mf_audio_enc_process_output (GstMFAudioEnc * self)
}
static GstFlowReturn
gst_mf_audio_enc_handle_frame (GstAudioEncoder * enc,
GstBuffer *buffer)
gst_mf_audio_enc_handle_frame (GstAudioEncoder * enc, GstBuffer * buffer)
{
GstMFAudioEnc *self = GST_MF_AUDIO_ENC (enc);
GstFlowReturn ret;

View file

@ -30,6 +30,7 @@
#include <memory>
#include <algorithm>
/* *INDENT-OFF* */
using namespace Microsoft::WRL;
using namespace Microsoft::WRL::Wrappers;
using namespace ABI::Windows::Media::MediaProperties;
@ -42,6 +43,7 @@ GST_DEBUG_CATEGORY_EXTERN (gst_mf_source_object_debug);
#define GST_CAT_DEFAULT gst_mf_source_object_debug
G_END_DECLS
/* *INDENT-ON* */
enum
{
@ -74,7 +76,7 @@ struct _GstMFCaptureWinRT
typedef struct _GstMFCaptureWinRTFrame
{
IMediaFrameReference * frame;
IMediaFrameReference *frame;
GstClockTime clock_time;
} GstMFCaptureWinRTFrame;
@ -86,18 +88,18 @@ static void gst_mf_capture_winrt_set_property (GObject * object, guint prop_id,
const GValue * value, GParamSpec * pspec);
static gboolean gst_mf_capture_winrt_start (GstMFSourceObject * object);
static gboolean gst_mf_capture_winrt_stop (GstMFSourceObject * object);
static gboolean gst_mf_capture_winrt_stop (GstMFSourceObject * object);
static GstFlowReturn gst_mf_capture_winrt_fill (GstMFSourceObject * object,
GstBuffer * buffer);
static gboolean gst_mf_capture_winrt_unlock (GstMFSourceObject * object);
static gboolean gst_mf_capture_winrt_unlock_stop (GstMFSourceObject * object);
static GstCaps * gst_mf_capture_winrt_get_caps (GstMFSourceObject * object);
static GstCaps *gst_mf_capture_winrt_get_caps (GstMFSourceObject * object);
static gboolean gst_mf_capture_winrt_set_caps (GstMFSourceObject * object,
GstCaps * caps);
static HRESULT gst_mf_capture_winrt_on_frame (IMediaFrameReference * frame,
void * user_data);
static HRESULT gst_mf_capture_winrt_on_failed (const std::string &error,
UINT32 error_code, void * user_data);
void *user_data);
static HRESULT gst_mf_capture_winrt_on_failed (const std::string & error,
UINT32 error_code, void *user_data);
static gpointer gst_mf_capture_winrt_thread_func (GstMFCaptureWinRT * self);
static void
@ -122,7 +124,7 @@ gst_mf_capture_winrt_class_init (GstMFCaptureWinRTClass * klass)
g_param_spec_pointer ("dispatcher", "Dispatcher",
"ICoreDispatcher COM object to use",
(GParamFlags) (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS)));
G_PARAM_STATIC_STRINGS)));
source_class->start = GST_DEBUG_FUNCPTR (gst_mf_capture_winrt_start);
source_class->stop = GST_DEBUG_FUNCPTR (gst_mf_capture_winrt_stop);
@ -233,13 +235,13 @@ gst_mf_capture_winrt_thread_func (GstMFCaptureWinRT * self)
HRESULT hr;
guint index;
GSource *idle_source;
std::shared_ptr<GstWinRTMediaFrameSourceGroup> target_group;
std::vector<GstWinRTMediaFrameSourceGroup> group_list;
std::shared_ptr < GstWinRTMediaFrameSourceGroup > target_group;
std::vector < GstWinRTMediaFrameSourceGroup > group_list;
MediaCaptureWrapperCallbacks callbacks;
RoInitializeWrapper init_wrapper (RO_INIT_MULTITHREADED);
self->capture = new MediaCaptureWrapper(self->dispatcher);
self->capture = new MediaCaptureWrapper (self->dispatcher);
callbacks.frame_arrived = gst_mf_capture_winrt_on_frame;
callbacks.failed = gst_mf_capture_winrt_on_failed;
self->capture->RegisterCb (callbacks, self);
@ -252,8 +254,9 @@ gst_mf_capture_winrt_thread_func (GstMFCaptureWinRT * self)
g_source_attach (idle_source, self->context);
g_source_unref (idle_source);
hr = self->capture->EnumrateFrameSourceGroup(group_list);
hr = self->capture->EnumrateFrameSourceGroup (group_list);
/* *INDENT-OFF* */
#ifndef GST_DISABLE_GST_DEBUG
index = 0;
for (const auto& iter: group_list) {
@ -291,6 +294,7 @@ gst_mf_capture_winrt_thread_func (GstMFCaptureWinRT * self)
index++;
}
/* *INDENT-ON* */
if (!target_group) {
GST_WARNING_OBJECT (self, "No matching device");
@ -302,15 +306,17 @@ gst_mf_capture_winrt_thread_func (GstMFCaptureWinRT * self)
goto run_loop;
}
self->capture->SetSourceGroup(*target_group);
self->capture->SetSourceGroup (*target_group);
std::sort (target_group->source_list_.begin (),
target_group->source_list_.end (), WinRTCapsCompareFunc);
self->supported_caps = gst_caps_new_empty ();
/* *INDENT-OFF* */
for (auto iter: target_group->source_list_)
gst_caps_append (self->supported_caps, gst_caps_copy (iter.caps_));
/* *INDENT-ON* */
GST_DEBUG_OBJECT (self, "Available output caps %" GST_PTR_FORMAT,
self->supported_caps);
@ -318,10 +324,10 @@ gst_mf_capture_winrt_thread_func (GstMFCaptureWinRT * self)
source->opened = TRUE;
g_free (source->device_path);
source->device_path = g_strdup (target_group->id_.c_str());
source->device_path = g_strdup (target_group->id_.c_str ());
g_free (source->device_name);
source->device_name = g_strdup (target_group->display_name_.c_str());
source->device_name = g_strdup (target_group->display_name_.c_str ());
source->device_index = index;
@ -351,7 +357,7 @@ gst_mf_capture_winrt_start (GstMFSourceObject * object)
return FALSE;
}
hr = self->capture->StartCapture();
hr = self->capture->StartCapture ();
if (!gst_mf_result (hr)) {
GST_ERROR_OBJECT (self, "Capture object doesn't want to start capture");
return FALSE;
@ -371,7 +377,7 @@ gst_mf_capture_winrt_stop (GstMFSourceObject * object)
return FALSE;
}
hr = self->capture->StopCapture();
hr = self->capture->StopCapture ();
gst_queue_array_clear (self->queue);
@ -384,8 +390,7 @@ gst_mf_capture_winrt_stop (GstMFSourceObject * object)
}
static HRESULT
gst_mf_capture_winrt_on_frame (IMediaFrameReference * frame,
void * user_data)
gst_mf_capture_winrt_on_frame (IMediaFrameReference * frame, void *user_data)
{
GstMFCaptureWinRT *self = GST_MF_CAPTURE_WINRT (user_data);
GstMFCaptureWinRTFrame winrt_frame;
@ -409,12 +414,12 @@ gst_mf_capture_winrt_on_frame (IMediaFrameReference * frame,
}
static HRESULT
gst_mf_capture_winrt_on_failed (const std::string &error,
UINT32 error_code, void * user_data)
gst_mf_capture_winrt_on_failed (const std::string & error,
UINT32 error_code, void *user_data)
{
GstMFCaptureWinRT *self = GST_MF_CAPTURE_WINRT (user_data);
GST_DEBUG_OBJECT (self, "Have error %s (%d)", error.c_str(), error_code);
GST_DEBUG_OBJECT (self, "Have error %s (%d)", error.c_str (), error_code);
g_mutex_lock (&self->lock);
self->got_error = TRUE;
@ -432,7 +437,7 @@ gst_mf_capture_winrt_get_video_media_frame (GstMFCaptureWinRT * self,
GstMFCaptureWinRTFrame *winrt_frame = nullptr;
IMediaFrameReference *frame_ref;
HRESULT hr;
ComPtr<IReference<TimeSpan>> winrt_timestamp;
ComPtr < IReference < TimeSpan >> winrt_timestamp;
TimeSpan winrt_duration;
*media_frame = nullptr;
@ -500,12 +505,12 @@ gst_mf_capture_winrt_fill (GstMFSourceObject * object, GstBuffer * buffer)
BYTE *data;
UINT32 size;
gint i, j;
ComPtr<IVideoMediaFrame> video_frame;
ComPtr<ISoftwareBitmap> bitmap;
ComPtr<IBitmapBuffer> bitmap_buffer;
ComPtr<IMemoryBuffer> mem_buf;
ComPtr<IMemoryBufferReference> mem_ref;
ComPtr<Windows::Foundation::IMemoryBufferByteAccess> byte_access;
ComPtr < IVideoMediaFrame > video_frame;
ComPtr < ISoftwareBitmap > bitmap;
ComPtr < IBitmapBuffer > bitmap_buffer;
ComPtr < IMemoryBuffer > mem_buf;
ComPtr < IMemoryBufferReference > mem_ref;
ComPtr < Windows::Foundation::IMemoryBufferByteAccess > byte_access;
INT32 plane_count;
BitmapPlaneDescription desc[GST_VIDEO_MAX_PLANES];
GstClockTime timestamp = GST_CLOCK_TIME_NONE;
@ -568,7 +573,7 @@ gst_mf_capture_winrt_fill (GstMFSourceObject * object, GstBuffer * buffer)
return GST_FLOW_ERROR;
}
hr = mem_ref.As(&byte_access);
hr = mem_ref.As (&byte_access);
if (!gst_mf_result (hr)) {
GST_ERROR_OBJECT (self, "Cannot get IMemoryBufferByteAccess");
return GST_FLOW_ERROR;
@ -666,6 +671,7 @@ gst_mf_capture_winrt_get_caps (GstMFSourceObject * object)
return NULL;
}
/* *INDENT-OFF* */
static gboolean
gst_mf_capture_winrt_set_caps (GstMFSourceObject * object, GstCaps * caps)
{
@ -701,6 +707,7 @@ gst_mf_capture_winrt_set_caps (GstMFSourceObject * object, GstCaps * caps)
return TRUE;
}
/* *INDENT-ON* */
static void
gst_mf_capture_winrt_frame_clear (GstMFCaptureWinRTFrame * winrt_frame)
@ -720,7 +727,7 @@ gst_mf_capture_winrt_new (GstMFSourceType type, gint device_index,
const gchar * device_name, const gchar * device_path, gpointer dispatcher)
{
GstMFSourceObject *self;
ComPtr<ICoreDispatcher> core_dispatcher;
ComPtr < ICoreDispatcher > core_dispatcher;
/* Multiple COM init is allowed */
RoInitializeWrapper init_wrapper (RO_INIT_MULTITHREADED);

View file

@ -47,7 +47,9 @@
#include <gst/d3d11/gstd3d11.h>
#endif
/* *INDENT-OFF* */
using namespace Microsoft::WRL;
/* *INDENT-ON* */
GST_DEBUG_CATEGORY (gst_mf_h264_enc_debug);
#define GST_CAT_DEFAULT gst_mf_h264_enc_debug
@ -264,7 +266,7 @@ gst_mf_h264_enc_class_init (GstMFH264EncClass * klass, gpointer data)
"Rate Control Mode",
GST_TYPE_MF_H264_ENC_RC_MODE, DEFAULT_RC_MODE,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
/* NOTE: documentation will be done by only for default device */
if (cdata->is_default) {
@ -281,7 +283,7 @@ gst_mf_h264_enc_class_init (GstMFH264EncClass * klass, gpointer data)
"Quality applied when rc-mode is qvbr",
1, 100, DEFAULT_QUALITY_LEVEL,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->adaptive_mode) {
@ -290,12 +292,12 @@ gst_mf_h264_enc_class_init (GstMFH264EncClass * klass, gpointer data)
"Adaptive Mode", GST_TYPE_MF_H264_ENC_ADAPTIVE_MODE,
DEFAULT_ADAPTIVE_MODE,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
/* NOTE: documentation will be done by only for default device */
if (cdata->is_default) {
gst_type_mark_as_plugin_api (GST_TYPE_MF_H264_ENC_ADAPTIVE_MODE,
(GstPluginAPIFlags) 0);
(GstPluginAPIFlags) 0);
}
}
@ -305,7 +307,7 @@ gst_mf_h264_enc_class_init (GstMFH264EncClass * klass, gpointer data)
"VBV(HRD) Buffer Size in bytes (0 = MFT default)",
0, G_MAXUINT - 1, DEFAULT_BUFFER_SIZE,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->max_bitrate) {
@ -314,7 +316,7 @@ gst_mf_h264_enc_class_init (GstMFH264EncClass * klass, gpointer data)
"The maximum bitrate applied when rc-mode is \"pcvbr\" in kbit/sec",
0, (G_MAXUINT >> 10), DEFAULT_MAX_BITRATE,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->quality_vs_speed) {
@ -324,7 +326,7 @@ gst_mf_h264_enc_class_init (GstMFH264EncClass * klass, gpointer data)
"[34, 66]: Medium complexity, [67, 100]: High complexity", 0, 100,
DEFAULT_QUALITY_VS_SPEED,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->cabac) {
@ -333,7 +335,7 @@ gst_mf_h264_enc_class_init (GstMFH264EncClass * klass, gpointer data)
"Enable CABAC entropy coding",
DEFAULT_CABAC,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->sps_id) {
@ -342,7 +344,7 @@ gst_mf_h264_enc_class_init (GstMFH264EncClass * klass, gpointer data)
"The SPS id to use", 0, 31,
DEFAULT_SPS_ID,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->pps_id) {
@ -351,7 +353,7 @@ gst_mf_h264_enc_class_init (GstMFH264EncClass * klass, gpointer data)
"The PPS id to use", 0, 255,
DEFAULT_PPS_ID,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->bframes) {
@ -360,7 +362,7 @@ gst_mf_h264_enc_class_init (GstMFH264EncClass * klass, gpointer data)
"The maximum number of consecutive B frames", 0, 2,
DEFAULT_BFRAMES,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->gop_size) {
@ -371,7 +373,7 @@ gst_mf_h264_enc_class_init (GstMFH264EncClass * klass, gpointer data)
"produce only one keyframe at the beginning (-1 for automatic)",
-1, G_MAXINT, DEFAULT_GOP_SIZE,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->threads) {
@ -380,7 +382,7 @@ gst_mf_h264_enc_class_init (GstMFH264EncClass * klass, gpointer data)
"The number of worker threads used by a encoder, (0 = MFT default)",
0, 16, DEFAULT_THREADS,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->content_type) {
@ -389,7 +391,7 @@ gst_mf_h264_enc_class_init (GstMFH264EncClass * klass, gpointer data)
"Indicates the type of video content",
GST_TYPE_MF_H264_ENC_CONTENT_TYPE, DEFAULT_CONTENT_TYPE,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
/* NOTE: documentation will be done by only for default device */
if (cdata->is_default) {
@ -404,7 +406,7 @@ gst_mf_h264_enc_class_init (GstMFH264EncClass * klass, gpointer data)
"QP applied when rc-mode is \"qvbr\"", 16, 51,
DEFAULT_QP,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->low_latency) {
@ -413,7 +415,7 @@ gst_mf_h264_enc_class_init (GstMFH264EncClass * klass, gpointer data)
"Enable low latency encoding",
DEFAULT_LOW_LATENCY,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->min_qp) {
@ -422,7 +424,7 @@ gst_mf_h264_enc_class_init (GstMFH264EncClass * klass, gpointer data)
"The minimum allowed QP applied to all rc-mode", 0, 51,
DEFAULT_MIN_QP,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->max_qp) {
@ -431,7 +433,7 @@ gst_mf_h264_enc_class_init (GstMFH264EncClass * klass, gpointer data)
"The maximum allowed QP applied to all rc-mode", 0, 51,
DEFAULT_MAX_QP,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->frame_type_qp) {
@ -440,21 +442,21 @@ gst_mf_h264_enc_class_init (GstMFH264EncClass * klass, gpointer data)
"QP applied to I frames", 0, 51,
DEFAULT_QP_I,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_QP_P,
g_param_spec_uint ("qp-p", "QP P",
"QP applied to P frames", 0, 51,
DEFAULT_QP_P,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_QP_B,
g_param_spec_uint ("qp-b", "QP B",
"QP applied to B frames", 0, 51,
DEFAULT_QP_B,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->max_num_ref) {
@ -464,7 +466,7 @@ gst_mf_h264_enc_class_init (GstMFH264EncClass * klass, gpointer data)
device_caps->max_num_ref_low, device_caps->max_num_ref_high,
DEFAULT_REF,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
g_object_class_install_property (gobject_class, PROP_D3D11_AWARE,
@ -479,13 +481,13 @@ gst_mf_h264_enc_class_init (GstMFH264EncClass * klass, gpointer data)
"DXGI Adapter index for creating device",
0, G_MAXUINT32, device_caps->adapter,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
}
long_name = g_strdup_printf ("Media Foundation %s", cdata->device_name);
classification = g_strdup_printf ("Codec/Encoder/Video%s",
(cdata->enum_flags & MFT_ENUM_FLAG_HARDWARE) == MFT_ENUM_FLAG_HARDWARE ?
"/Hardware" : "");
"/Hardware" : "");
gst_element_class_set_metadata (element_class, long_name,
classification,
"Microsoft Media Foundation H.264 Encoder",
@ -867,8 +869,7 @@ gst_mf_h264_enc_set_option (GstMFVideoEnc * mfenc, GstVideoCodecState * state,
if (device_caps->adaptive_mode) {
guint adaptive_mode;
adaptive_mode =
gst_mf_h264_enc_adaptive_mode_to_enum (self->adaptive_mode);
adaptive_mode = gst_mf_h264_enc_adaptive_mode_to_enum (self->adaptive_mode);
if (adaptive_mode != G_MAXUINT) {
hr = gst_mf_transform_set_codec_api_uint32 (transform,
&CODECAPI_AVEncAdaptiveMode, adaptive_mode);
@ -891,8 +892,7 @@ gst_mf_h264_enc_set_option (GstMFVideoEnc * mfenc, GstVideoCodecState * state,
if (device_caps->quality_vs_speed) {
hr = gst_mf_transform_set_codec_api_uint32 (transform,
&CODECAPI_AVEncCommonQualityVsSpeed,
self->quality_vs_speed);
&CODECAPI_AVEncCommonQualityVsSpeed, self->quality_vs_speed);
WARNING_HR (hr, CODECAPI_AVEncCommonQualityVsSpeed);
}

View file

@ -40,7 +40,9 @@
#include "gstmfh265enc.h"
#include <wrl.h>
/* *INDENT-OFF* */
using namespace Microsoft::WRL;
/* *INDENT-ON* */
GST_DEBUG_CATEGORY (gst_mf_h265_enc_debug);
#define GST_CAT_DEFAULT gst_mf_h265_enc_debug
@ -207,12 +209,12 @@ gst_mf_h265_enc_class_init (GstMFH265EncClass * klass, gpointer data)
"Rate Control Mode",
GST_TYPE_MF_H265_ENC_RC_MODE, DEFAULT_RC_MODE,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
/* NOTE: documentation will be done by only for default device */
if (cdata->is_default) {
gst_type_mark_as_plugin_api (GST_TYPE_MF_H265_ENC_RC_MODE,
(GstPluginAPIFlags) 0);
(GstPluginAPIFlags) 0);
}
}
@ -222,7 +224,7 @@ gst_mf_h265_enc_class_init (GstMFH265EncClass * klass, gpointer data)
"VBV(HRD) Buffer Size in bytes (0 = MFT default)",
0, G_MAXUINT - 1, DEFAULT_BUFFER_SIZE,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->max_bitrate) {
@ -231,7 +233,7 @@ gst_mf_h265_enc_class_init (GstMFH265EncClass * klass, gpointer data)
"The maximum bitrate applied when rc-mode is \"pcvbr\" in kbit/sec "
"(0 = MFT default)", 0, (G_MAXUINT >> 10), DEFAULT_MAX_BITRATE,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->quality_vs_speed) {
@ -241,7 +243,7 @@ gst_mf_h265_enc_class_init (GstMFH265EncClass * klass, gpointer data)
"[34, 66]: Medium complexity, [67, 100]: High complexity",
0, 100, DEFAULT_QUALITY_VS_SPEED,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->bframes) {
@ -250,7 +252,7 @@ gst_mf_h265_enc_class_init (GstMFH265EncClass * klass, gpointer data)
"The maximum number of consecutive B frames",
0, 2, DEFAULT_BFRAMES,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->gop_size) {
@ -261,7 +263,7 @@ gst_mf_h265_enc_class_init (GstMFH265EncClass * klass, gpointer data)
"produce only one keyframe at the beginning (-1 for automatic)",
-1, G_MAXINT, DEFAULT_GOP_SIZE,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->threads) {
@ -270,7 +272,7 @@ gst_mf_h265_enc_class_init (GstMFH265EncClass * klass, gpointer data)
"The number of worker threads used by a encoder, (0 = MFT default)",
0, 16, DEFAULT_THREADS,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->content_type) {
@ -279,7 +281,7 @@ gst_mf_h265_enc_class_init (GstMFH265EncClass * klass, gpointer data)
"Indicates the type of video content",
GST_TYPE_MF_H265_ENC_CONTENT_TYPE, DEFAULT_CONTENT_TYPE,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
/* NOTE: documentation will be done by only for default device */
if (cdata->is_default) {
@ -293,7 +295,7 @@ gst_mf_h265_enc_class_init (GstMFH265EncClass * klass, gpointer data)
g_param_spec_uint ("qp", "qp",
"QP applied when rc-mode is \"qvbr\"", 16, 51, DEFAULT_QP,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->low_latency) {
@ -301,7 +303,7 @@ gst_mf_h265_enc_class_init (GstMFH265EncClass * klass, gpointer data)
g_param_spec_boolean ("low-latency", "Low Latency",
"Enable low latency encoding", DEFAULT_LOW_LATENCY,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->min_qp) {
@ -310,7 +312,7 @@ gst_mf_h265_enc_class_init (GstMFH265EncClass * klass, gpointer data)
"The minimum allowed QP applied to all rc-mode",
0, 51, DEFAULT_MIN_QP,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->max_qp) {
@ -319,7 +321,7 @@ gst_mf_h265_enc_class_init (GstMFH265EncClass * klass, gpointer data)
"The maximum allowed QP applied to all rc-mode",
0, 51, DEFAULT_MAX_QP,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->frame_type_qp) {
@ -328,21 +330,21 @@ gst_mf_h265_enc_class_init (GstMFH265EncClass * klass, gpointer data)
"QP applied to I frames", 0, 51,
DEFAULT_QP_I,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_QP_P,
g_param_spec_uint ("qp-p", "QP P",
"QP applied to P frames", 0, 51,
DEFAULT_QP_P,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_QP_B,
g_param_spec_uint ("qp-b", "QP B",
"QP applied to B frames", 0, 51,
DEFAULT_QP_B,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->max_num_ref) {
@ -352,7 +354,7 @@ gst_mf_h265_enc_class_init (GstMFH265EncClass * klass, gpointer data)
device_caps->max_num_ref_low, device_caps->max_num_ref_high,
DEFAULT_REF,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
g_object_class_install_property (gobject_class, PROP_D3D11_AWARE,
@ -367,13 +369,13 @@ gst_mf_h265_enc_class_init (GstMFH265EncClass * klass, gpointer data)
"DXGI Adapter index for creating device",
0, G_MAXUINT32, device_caps->adapter,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
}
long_name = g_strdup_printf ("Media Foundation %s", cdata->device_name);
classification = g_strdup_printf ("Codec/Encoder/Video%s",
(cdata->enum_flags & MFT_ENUM_FLAG_HARDWARE) == MFT_ENUM_FLAG_HARDWARE ?
"/Hardware" : "");
"/Hardware" : "");
gst_element_class_set_metadata (element_class, long_name,
classification,
"Microsoft Media Foundation H.265 Encoder",
@ -647,8 +649,7 @@ gst_mf_h265_enc_set_option (GstMFVideoEnc * mfenc, GstVideoCodecState * state,
if (device_caps->quality_vs_speed) {
hr = gst_mf_transform_set_codec_api_uint32 (transform,
&CODECAPI_AVEncCommonQualityVsSpeed,
self->quality_vs_speed);
&CODECAPI_AVEncCommonQualityVsSpeed, self->quality_vs_speed);
WARNING_HR (hr, CODECAPI_AVEncCommonQualityVsSpeed);
}
@ -807,4 +808,4 @@ gst_mf_h265_enc_plugin_init (GstPlugin * plugin, guint rank,
GST_DEBUG_CATEGORY_INIT (gst_mf_h265_enc_debug, "mfh265enc", 0, "mfh265enc");
gst_mf_video_enc_register (plugin, rank, &subtype, &type_info, d3d11_device);
}
}

View file

@ -43,7 +43,9 @@
#include <vector>
#include <string>
/* *INDENT-OFF* */
using namespace Microsoft::WRL;
/* *INDENT-ON* */
GST_DEBUG_CATEGORY (gst_mf_mp3_enc_debug);
#define GST_CAT_DEFAULT gst_mf_mp3_enc_debug
@ -70,6 +72,7 @@ typedef struct _GstMFMp3EncClass
} GstMFMp3EncClass;
/* *INDENT-OFF* */
typedef struct
{
GstCaps *sink_caps;
@ -79,6 +82,7 @@ typedef struct
guint device_index;
std::set<UINT32> bitrate_list;
} GstMFMp3EncClassData;
/* *INDENT-ON* */
static GstElementClass *parent_class = NULL;
@ -110,25 +114,27 @@ gst_mf_mp3_enc_class_init (GstMFMp3EncClass * klass, gpointer data)
gobject_class->get_property = gst_mf_mp3_enc_get_property;
gobject_class->set_property = gst_mf_mp3_enc_set_property;
bitrate_blurb =
"Bitrate in bit/sec, (0 = auto), valid values are { 0";
bitrate_blurb = "Bitrate in bit/sec, (0 = auto), valid values are { 0";
/* *INDENT-OFF* */
for (auto iter: cdata->bitrate_list) {
bitrate_blurb += ", " + std::to_string (iter);
/* std::set<> stores values in a sorted fashion */
max_bitrate = iter;
}
bitrate_blurb += " }";
/* *INDENT-ON* */
g_object_class_install_property (gobject_class, PROP_BITRATE,
g_param_spec_uint ("bitrate", "Bitrate", bitrate_blurb.c_str(), 0,
g_param_spec_uint ("bitrate", "Bitrate", bitrate_blurb.c_str (), 0,
max_bitrate, DEFAULT_BITRATE,
(GParamFlags) (GST_PARAM_MUTABLE_READY | G_PARAM_READWRITE |
G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK)));
G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK)));
long_name = g_strdup_printf ("Media Foundation %s", cdata->device_name);
classification = g_strdup_printf ("Codec/Encoder/Audio%s",
(cdata->enum_flags & MFT_ENUM_FLAG_HARDWARE) == MFT_ENUM_FLAG_HARDWARE ?
"/Hardware" : "");
"/Hardware" : "");
gst_element_class_set_metadata (element_class, long_name,
classification,
"Microsoft Media Foundation MP3 Encoder",
@ -147,8 +153,7 @@ gst_mf_mp3_enc_class_init (GstMFMp3EncClass * klass, gpointer data)
GST_DEBUG_FUNCPTR (gst_mf_mp3_enc_get_output_type);
mfenc_class->get_input_type =
GST_DEBUG_FUNCPTR (gst_mf_mp3_enc_get_input_type);
mfenc_class->set_src_caps =
GST_DEBUG_FUNCPTR (gst_mf_mp3_enc_set_src_caps);
mfenc_class->set_src_caps = GST_DEBUG_FUNCPTR (gst_mf_mp3_enc_set_src_caps);
mfenc_class->codec_id = MFAudioFormat_MP3;
mfenc_class->enum_flags = cdata->enum_flags;
@ -207,9 +212,9 @@ gst_mf_mp3_enc_get_output_type (GstMFAudioEnc * mfenc, GstAudioInfo * info,
GstMFTransform *transform = mfenc->transform;
GList *output_list = NULL;
GList *iter;
ComPtr<IMFMediaType> target_output;
std::vector<ComPtr<IMFMediaType>> filtered_types;
std::set<UINT32> bitrate_list;
ComPtr < IMFMediaType > target_output;
std::vector < ComPtr < IMFMediaType >> filtered_types;
std::set < UINT32 > bitrate_list;
UINT32 bitrate;
UINT32 target_bitrate = 0;
HRESULT hr;
@ -268,12 +273,12 @@ gst_mf_mp3_enc_get_output_type (GstMFAudioEnc * mfenc, GstAudioInfo * info,
g_list_free_full (output_list, (GDestroyNotify) gst_mf_media_type_release);
if (filtered_types.empty()) {
if (filtered_types.empty ()) {
GST_ERROR_OBJECT (self, "Couldn't find target output type");
return FALSE;
}
GST_DEBUG_OBJECT (self, "have %d candidate output", filtered_types.size());
GST_DEBUG_OBJECT (self, "have %d candidate output", filtered_types.size ());
/* 2. Find the best matching bitrate */
bitrate = self->bitrate;
@ -294,6 +299,8 @@ gst_mf_mp3_enc_get_output_type (GstMFAudioEnc * mfenc, GstAudioInfo * info,
}
GST_DEBUG_OBJECT (self, "Available bitrates");
/* *INDENT-OFF* */
for (auto it: bitrate_list)
GST_DEBUG_OBJECT (self, "\t%d", it);
@ -319,13 +326,14 @@ gst_mf_mp3_enc_get_output_type (GstMFAudioEnc * mfenc, GstAudioInfo * info,
break;
}
}
/* *INDENT-ON* */
if (!target_output) {
GST_ERROR_OBJECT (self, "Failed to decide final output type");
return FALSE;
}
*output_type = target_output.Detach();
*output_type = target_output.Detach ();
return TRUE;
}
@ -338,9 +346,9 @@ gst_mf_mp3_enc_get_input_type (GstMFAudioEnc * mfenc, GstAudioInfo * info,
GstMFTransform *transform = mfenc->transform;
GList *input_list = NULL;
GList *iter;
ComPtr<IMFMediaType> target_input;
std::vector<ComPtr<IMFMediaType>> filtered_types;
std::set<UINT32> bitrate_list;
ComPtr < IMFMediaType > target_input;
std::vector < ComPtr < IMFMediaType >> filtered_types;
std::set < UINT32 > bitrate_list;
HRESULT hr;
if (!gst_mf_transform_get_input_available_types (transform, &input_list)) {
@ -391,33 +399,33 @@ gst_mf_mp3_enc_get_input_type (GstMFAudioEnc * mfenc, GstAudioInfo * info,
g_list_free_full (input_list, (GDestroyNotify) gst_mf_media_type_release);
if (filtered_types.empty()) {
if (filtered_types.empty ()) {
GST_ERROR_OBJECT (self, "Couldn't find target input type");
return FALSE;
}
GST_DEBUG_OBJECT (self, "Total %d input types are available",
filtered_types.size());
filtered_types.size ());
/* Just select the first one */
target_input = *filtered_types.begin();
target_input = *filtered_types.begin ();
*input_type = target_input.Detach();
*input_type = target_input.Detach ();
return TRUE;
}
static gboolean
gst_mf_mp3_enc_set_src_caps (GstMFAudioEnc * mfenc,
GstAudioInfo * info)
gst_mf_mp3_enc_set_src_caps (GstMFAudioEnc * mfenc, GstAudioInfo * info)
{
GstMFMp3Enc *self = (GstMFMp3Enc *) mfenc;
GstCaps *src_caps;
gboolean ret;
ComPtr<IMFMediaType> output_type;
ComPtr < IMFMediaType > output_type;
gint version = 1;
if (!gst_mf_transform_get_output_current_type (mfenc->transform, &output_type)) {
if (!gst_mf_transform_get_output_current_type (mfenc->transform,
&output_type)) {
GST_ERROR_OBJECT (self, "Couldn't get current output type");
return FALSE;
}
@ -434,10 +442,10 @@ gst_mf_mp3_enc_set_src_caps (GstMFAudioEnc * mfenc,
"mpegaudioversion", G_TYPE_INT, version,
"layer", G_TYPE_INT, 3,
"channels", G_TYPE_INT, GST_AUDIO_INFO_CHANNELS (info),
"rate", G_TYPE_INT, GST_AUDIO_INFO_RATE (info),
NULL);
"rate", G_TYPE_INT, GST_AUDIO_INFO_RATE (info), NULL);
ret = gst_audio_encoder_set_output_format (GST_AUDIO_ENCODER (self), src_caps);
ret =
gst_audio_encoder_set_output_format (GST_AUDIO_ENCODER (self), src_caps);
if (!ret) {
GST_WARNING_OBJECT (self,
"Couldn't set output format %" GST_PTR_FORMAT, src_caps);
@ -451,7 +459,7 @@ static void
gst_mf_mp3_enc_register (GstPlugin * plugin, guint rank,
const gchar * device_name, guint32 enum_flags, guint device_index,
GstCaps * sink_caps, GstCaps * src_caps,
const std::set<UINT32> &bitrate_list)
const std::set < UINT32 > &bitrate_list)
{
GType type;
gchar *type_name;
@ -509,41 +517,42 @@ gst_mf_mp3_enc_register (GstPlugin * plugin, guint rank,
}
static gboolean
gst_mf_mp3_enc_create_template_caps (const std::set<UINT32> &rate_list,
gst_mf_mp3_enc_create_template_caps (const std::set < UINT32 > &rate_list,
gint channels, GstCaps ** sink_caps, GstCaps ** src_caps)
{
GstCaps *sink = NULL;
GstCaps *src = NULL;
GValue rate_value = G_VALUE_INIT;
if (rate_list.empty()) {
if (rate_list.empty ()) {
GST_WARNING ("No available rate for channels %d", channels);
return FALSE;
}
if (channels != 0) {
sink =
gst_caps_from_string ("audio/x-raw, "
"format = (string) " GST_AUDIO_NE (S16)
", layout = (string) interleaved");
gst_caps_from_string ("audio/x-raw, "
"format = (string) " GST_AUDIO_NE (S16)
", layout = (string) interleaved");
src =
gst_caps_from_string ("audio/mpeg, mpegversion = (int) 1,"
"layer = (int) 3");
gst_caps_from_string ("audio/mpeg, mpegversion = (int) 1,"
"layer = (int) 3");
gst_caps_set_simple (sink, "channels", G_TYPE_INT, channels, NULL);
gst_caps_set_simple (src, "channels", G_TYPE_INT, channels, NULL);
} else {
sink =
gst_caps_from_string ("audio/x-raw, "
"format = (string) " GST_AUDIO_NE (S16)
", layout = (string) interleaved, channels = (int) [ 1, 2 ]");
gst_caps_from_string ("audio/x-raw, "
"format = (string) " GST_AUDIO_NE (S16)
", layout = (string) interleaved, channels = (int) [ 1, 2 ]");
src =
gst_caps_from_string ("audio/mpeg, mpegversion = (int) 1,"
"layer = (int) 3, channels = (int) [ 1, 2 ]");
gst_caps_from_string ("audio/mpeg, mpegversion = (int) 1,"
"layer = (int) 3, channels = (int) [ 1, 2 ]");
}
g_value_init (&rate_value, GST_TYPE_LIST);
/* *INDENT-OFF* */
for (const auto &it: rate_list) {
GValue rate = G_VALUE_INIT;
@ -551,6 +560,7 @@ gst_mf_mp3_enc_create_template_caps (const std::set<UINT32> &rate_list,
g_value_set_int (&rate, (gint) it);
gst_value_list_append_and_take_value (&rate_value, &rate);
}
/* *INDENT-ON* */
gst_caps_set_value (src, "rate", &rate_value);
gst_caps_set_value (sink, "rate", &rate_value);
@ -581,9 +591,9 @@ gst_mf_mp3_enc_plugin_init_internal (GstPlugin * plugin, guint rank,
gchar *device_name = NULL;
GList *output_list = NULL;
GList *iter;
std::set<UINT32> mono_rate_list;
std::set<UINT32> stereo_rate_list;
std::set<UINT32> bitrate_list;
std::set < UINT32 > mono_rate_list;
std::set < UINT32 > stereo_rate_list;
std::set < UINT32 > bitrate_list;
gboolean config_found = FALSE;
if (!gst_mf_transform_open (transform))
@ -600,7 +610,8 @@ gst_mf_mp3_enc_plugin_init_internal (GstPlugin * plugin, guint rank,
goto done;
}
GST_INFO_OBJECT (transform, "Have %d output type", g_list_length (output_list));
GST_INFO_OBJECT (transform, "Have %d output type",
g_list_length (output_list));
for (iter = output_list, i = 0; iter; iter = g_list_next (iter), i++) {
UINT32 channels, rate, bitrate;
@ -646,11 +657,11 @@ gst_mf_mp3_enc_plugin_init_internal (GstPlugin * plugin, guint rank,
continue;
if (channels == 1)
mono_rate_list.insert(rate);
mono_rate_list.insert (rate);
else if (channels == 2)
stereo_rate_list.insert(rate);
stereo_rate_list.insert (rate);
else
g_assert_not_reached();
g_assert_not_reached ();
/* convert bytes to bit */
bitrate_list.insert (bitrate * 8);
@ -668,17 +679,17 @@ gst_mf_mp3_enc_plugin_init_internal (GstPlugin * plugin, guint rank,
*
* Configure caps per channels if supported rate values are different
*/
if (!mono_rate_list.empty() && !stereo_rate_list.empty() &&
if (!mono_rate_list.empty () && !stereo_rate_list.empty () &&
mono_rate_list == stereo_rate_list) {
gst_mf_mp3_enc_create_template_caps (mono_rate_list,
0, &sink_caps, &src_caps);
0, &sink_caps, &src_caps);
} else {
if (!mono_rate_list.empty()) {
if (!mono_rate_list.empty ()) {
gst_mf_mp3_enc_create_template_caps (mono_rate_list,
1, &sink_caps, &src_caps);
}
if (!stereo_rate_list.empty()) {
if (!stereo_rate_list.empty ()) {
gst_mf_mp3_enc_create_template_caps (stereo_rate_list,
2, &sink_caps, &src_caps);
}
@ -697,7 +708,7 @@ gst_mf_mp3_enc_plugin_init_internal (GstPlugin * plugin, guint rank,
gst_mf_mp3_enc_register (plugin, rank, device_name, enum_flags, device_index,
sink_caps, src_caps, bitrate_list);
done:
done:
if (output_list)
g_list_free_full (output_list, (GDestroyNotify) gst_mf_media_type_release);
g_free (device_name);
@ -719,7 +730,7 @@ gst_mf_mp3_enc_plugin_init (GstPlugin * plugin, guint rank)
enum_params.category = MFT_CATEGORY_AUDIO_ENCODER;
enum_params.enum_flags = (MFT_ENUM_FLAG_HARDWARE | MFT_ENUM_FLAG_ASYNCMFT |
MFT_ENUM_FLAG_SORTANDFILTER | MFT_ENUM_FLAG_SORTANDFILTER_APPROVED_ONLY);
MFT_ENUM_FLAG_SORTANDFILTER | MFT_ENUM_FLAG_SORTANDFILTER_APPROVED_ONLY);
enum_params.output_typeinfo = &output_type;
/* register hardware encoders first (likey no hardware audio encoder) */

View file

@ -31,6 +31,7 @@
#include <vector>
#include <algorithm>
/* *INDENT-OFF* */
using namespace Microsoft::WRL;
G_BEGIN_DECLS
@ -39,6 +40,7 @@ GST_DEBUG_CATEGORY_EXTERN (gst_mf_source_object_debug);
#define GST_CAT_DEFAULT gst_mf_source_object_debug
G_END_DECLS
/* *INDENT-ON* */
typedef struct _GstMFStreamMediaType
{
@ -96,14 +98,14 @@ static void gst_mf_source_reader_constructed (GObject * object);
static void gst_mf_source_reader_finalize (GObject * object);
static gboolean gst_mf_source_reader_start (GstMFSourceObject * object);
static gboolean gst_mf_source_reader_stop (GstMFSourceObject * object);
static gboolean gst_mf_source_reader_stop (GstMFSourceObject * object);
static GstFlowReturn gst_mf_source_reader_fill (GstMFSourceObject * object,
GstBuffer * buffer);
static GstFlowReturn gst_mf_source_reader_create (GstMFSourceObject * object,
GstBuffer ** buffer);
static gboolean gst_mf_source_reader_unlock (GstMFSourceObject * object);
static gboolean gst_mf_source_reader_unlock_stop (GstMFSourceObject * object);
static GstCaps * gst_mf_source_reader_get_caps (GstMFSourceObject * object);
static GstCaps *gst_mf_source_reader_get_caps (GstMFSourceObject * object);
static gboolean gst_mf_source_reader_set_caps (GstMFSourceObject * object,
GstCaps * caps);
static void
@ -176,7 +178,7 @@ gst_mf_enum_media_type_from_source_reader (IMFSourceReader * source_reader,
gint i, j;
HRESULT hr;
GList *list = NULL;
std::vector<std::string> unhandled_caps;
std::vector < std::string > unhandled_caps;
g_return_val_if_fail (source_reader != NULL, FALSE);
g_return_val_if_fail (media_types != NULL, FALSE);
@ -190,7 +192,7 @@ gst_mf_enum_media_type_from_source_reader (IMFSourceReader * source_reader,
*/
i = MF_SOURCE_READER_FIRST_VIDEO_STREAM;
for (j = 0;; j++) {
ComPtr<IMFMediaType> media_type;
ComPtr < IMFMediaType > media_type;
hr = source_reader->GetNativeMediaType (i, j, &media_type);
@ -210,10 +212,10 @@ gst_mf_enum_media_type_from_source_reader (IMFSourceReader * source_reader,
name = gst_structure_get_name (s);
if (name != "video/x-raw" && name != "image/jpeg") {
auto it =
std::find(unhandled_caps.begin(), unhandled_caps.end(), name);
if (it == unhandled_caps.end()) {
GST_FIXME ("Skip not supported format %s", name.c_str());
unhandled_caps.push_back(name);
std::find (unhandled_caps.begin (), unhandled_caps.end (), name);
if (it == unhandled_caps.end ()) {
GST_FIXME ("Skip not supported format %s", name.c_str ());
unhandled_caps.push_back (name);
}
gst_caps_unref (caps);
continue;
@ -247,7 +249,7 @@ done:
list = g_list_reverse (list);
*media_types = list;
return ! !list;
return !!list;
}
static void
@ -280,9 +282,9 @@ gst_mf_source_reader_open (GstMFSourceReader * self, IMFActivate * activate)
{
GList *iter;
HRESULT hr;
ComPtr<IMFSourceReader> reader;
ComPtr<IMFMediaSource> source;
ComPtr<IMFAttributes> attr;
ComPtr < IMFSourceReader > reader;
ComPtr < IMFMediaSource > source;
ComPtr < IMFAttributes > attr;
hr = activate->ActivateObject (IID_IMFMediaSource, (void **) &source);
if (!gst_mf_result (hr))
@ -443,7 +445,7 @@ gst_mf_source_reader_read_sample (GstMFSourceReader * self)
GstMFSourceReaderSample reader_sample;
hr = self->reader->ReadSample (type->stream_index, 0, NULL, &stream_flags,
NULL, &sample);
NULL, &sample);
if (!gst_mf_result (hr)) {
GST_ERROR_OBJECT (self, "Failed to read sample");
@ -538,7 +540,7 @@ gst_mf_source_reader_fill (GstMFSourceObject * object, GstBuffer * buffer)
{
GstMFSourceReader *self = GST_MF_SOURCE_READER (object);
GstFlowReturn ret = GST_FLOW_OK;
ComPtr<IMFMediaBuffer> media_buffer;
ComPtr < IMFMediaBuffer > media_buffer;
GstVideoFrame frame;
BYTE *data;
gint i, j;
@ -601,7 +603,7 @@ gst_mf_source_reader_create (GstMFSourceObject * object, GstBuffer ** buffer)
{
GstMFSourceReader *self = GST_MF_SOURCE_READER (object);
GstFlowReturn ret = GST_FLOW_OK;
ComPtr<IMFMediaBuffer> media_buffer;
ComPtr < IMFMediaBuffer > media_buffer;
HRESULT hr;
BYTE *data;
DWORD len = 0;
@ -820,7 +822,7 @@ gst_mf_source_enum_device_activate (GstMFSourceReader * self,
{
HRESULT hr;
GList *ret = NULL;
ComPtr<IMFAttributes> attr;
ComPtr < IMFAttributes > attr;
IMFActivate **devices = NULL;
UINT32 i, count = 0;
@ -854,9 +856,9 @@ gst_mf_source_enum_device_activate (GstMFSourceReader * self,
switch (source_type) {
case GST_MF_SOURCE_TYPE_VIDEO:
hr = activate->GetAllocatedString (
MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK,
&name, &name_len);
hr = activate->GetAllocatedString
(MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_SYMBOLIC_LINK, &name,
&name_len);
break;
default:
g_assert_not_reached ();
@ -890,7 +892,7 @@ done:
*device_sources = ret;
return ! !ret;
return !!ret;
}
static void
@ -941,4 +943,4 @@ gst_mf_source_reader_new (GstMFSourceType type, gint device_index,
}
return self;
}
}

View file

@ -31,6 +31,7 @@
#include <string.h>
#include <wrl.h>
/* *INDENT-OFF* */
using namespace Microsoft::WRL;
G_BEGIN_DECLS
@ -254,6 +255,7 @@ private:
bool running_;
};
/* *INDENT-ON* */
enum
{
@ -277,7 +279,7 @@ struct _GstMFTransform
IMFActivate *activate;
IMFTransform *transform;
ICodecAPI * codec_api;
ICodecAPI *codec_api;
GstMFTransformAsyncCallback *callback_object;
GQueue *output_queue;
@ -340,7 +342,7 @@ gst_mf_transform_class_init (GstMFTransformClass * klass)
g_param_spec_pointer ("enum-params", "Enum Params",
"GstMFTransformEnumParams for MFTEnumEx",
(GParamFlags) (G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY |
G_PARAM_STATIC_STRINGS)));
G_PARAM_STATIC_STRINGS)));
g_object_class_install_property (gobject_class, PROP_D3D11_AWARE,
g_param_spec_boolean ("d3d11-aware", "D3D11 Aware",
"Whether Direct3D11 supports Direct3D11", FALSE,
@ -378,7 +380,7 @@ gst_mf_transform_constructed (GObject * object)
}
static void
gst_mf_transform_clear_enum_params (GstMFTransformEnumParams *params)
gst_mf_transform_clear_enum_params (GstMFTransformEnumParams * params)
{
g_free (params->input_typeinfo);
params->input_typeinfo = NULL;
@ -508,7 +510,7 @@ gst_mf_transform_thread_func (GstMFTransform * self)
#if GST_MF_HAVE_D3D11
if (GstMFTEnum2Func && self->enum_params.adapter_luid &&
(self->enum_params.enum_flags & MFT_ENUM_FLAG_HARDWARE) != 0) {
ComPtr<IMFAttributes> attr;
ComPtr < IMFAttributes > attr;
LUID luid;
hr = MFCreateAttributes (&attr, 1);
@ -524,7 +526,7 @@ gst_mf_transform_thread_func (GstMFTransform * self)
luid.LowPart = (DWORD) (self->enum_params.adapter_luid & 0xffffffff);
luid.HighPart = (LONG) (self->enum_params.adapter_luid >> 32);
hr = attr->SetBlob (GST_GUID_MFT_ENUM_ADAPTER_LUID, (BYTE *) &luid,
hr = attr->SetBlob (GST_GUID_MFT_ENUM_ADAPTER_LUID, (BYTE *) & luid,
sizeof (LUID));
if (!gst_mf_result (hr)) {
GST_ERROR_OBJECT (self, "Couldn't set MFT_ENUM_ADAPTER_LUID");
@ -564,7 +566,7 @@ gst_mf_transform_thread_func (GstMFTransform * self)
devices[i]->Release ();
hr = self->activate->GetAllocatedString (MFT_FRIENDLY_NAME_Attribute,
&name, NULL);
&name, NULL);
if (gst_mf_result (hr)) {
self->device_name = g_utf16_to_utf8 ((const gunichar2 *) name,
@ -576,7 +578,7 @@ gst_mf_transform_thread_func (GstMFTransform * self)
CoTaskMemFree (devices);
self->hardware = ! !(self->enum_params.enum_flags & MFT_ENUM_FLAG_HARDWARE);
self->hardware = !!(self->enum_params.enum_flags & MFT_ENUM_FLAG_HARDWARE);
self->initialized = TRUE;
run_loop:
@ -620,11 +622,10 @@ gst_mf_transform_process_output (GstMFTransform * self)
if ((out_stream_info.dwFlags & (MFT_OUTPUT_STREAM_PROVIDES_SAMPLES |
MFT_OUTPUT_STREAM_CAN_PROVIDE_SAMPLES)) == 0) {
ComPtr<IMFMediaBuffer> buffer;
ComPtr<IMFSample> new_sample;
ComPtr < IMFMediaBuffer > buffer;
ComPtr < IMFSample > new_sample;
hr = MFCreateMemoryBuffer (out_stream_info.cbSize,
buffer.GetAddressOf ());
hr = MFCreateMemoryBuffer (out_stream_info.cbSize, buffer.GetAddressOf ());
if (!gst_mf_result (hr)) {
GST_ERROR_OBJECT (self, "Couldn't create memory buffer");
return GST_FLOW_ERROR;
@ -653,7 +654,7 @@ gst_mf_transform_process_output (GstMFTransform * self)
GST_LOG_OBJECT (self, "Need more input data");
ret = GST_MF_TRANSFORM_FLOW_NEED_DATA;
} else if (hr == MF_E_TRANSFORM_STREAM_CHANGE) {
ComPtr<IMFMediaType> output_type;
ComPtr < IMFMediaType > output_type;
GST_DEBUG_OBJECT (self, "Stream change, set output type again");
@ -686,7 +687,7 @@ gst_mf_transform_process_output (GstMFTransform * self)
done:
if (ret != GST_FLOW_OK) {
if (out_data.pSample)
out_data.pSample->Release();
out_data.pSample->Release ();
return ret;
}
@ -709,8 +710,7 @@ done:
/* Must be called with event_lock */
static gboolean
gst_mf_transform_process_input_sync (GstMFTransform * self,
IMFSample * sample)
gst_mf_transform_process_input_sync (GstMFTransform * self, IMFSample * sample)
{
HRESULT hr;
@ -723,8 +723,7 @@ gst_mf_transform_process_input_sync (GstMFTransform * self,
}
gboolean
gst_mf_transform_process_input (GstMFTransform * object,
IMFSample * sample)
gst_mf_transform_process_input (GstMFTransform * object, IMFSample * sample)
{
HRESULT hr;
gboolean ret = FALSE;
@ -792,8 +791,7 @@ done:
}
GstFlowReturn
gst_mf_transform_get_output (GstMFTransform * object,
IMFSample ** sample)
gst_mf_transform_get_output (GstMFTransform * object, IMFSample ** sample)
{
GstFlowReturn ret;
@ -916,7 +914,7 @@ gst_mf_transform_open_internal (GstMFTransformOpenData * data)
}
if (object->hardware) {
ComPtr<IMFAttributes> attr;
ComPtr < IMFAttributes > attr;
UINT32 supports_d3d11 = 0;
hr = object->transform->GetAttributes (attr.GetAddressOf ());
@ -1085,8 +1083,7 @@ gst_mf_transform_event_type_to_string (MediaEventType event)
}
static HRESULT
gst_mf_transform_on_event (MediaEventType event,
GstMFTransform * self)
gst_mf_transform_on_event (MediaEventType event, GstMFTransform * self)
{
GST_TRACE_OBJECT (self, "Have event %s (%d)",
gst_mf_transform_event_type_to_string (event), (gint) event);
@ -1142,8 +1139,7 @@ gst_mf_transform_get_codec_api_handle (GstMFTransform * object)
g_return_val_if_fail (GST_IS_MF_TRANSFORM (object), NULL);
if (!object->codec_api) {
GST_WARNING_OBJECT (object,
"ICodecAPI is not configured, open MFT first");
GST_WARNING_OBJECT (object, "ICodecAPI is not configured, open MFT first");
return NULL;
}
@ -1409,4 +1405,3 @@ gst_mf_transform_set_codec_api_boolean (GstMFTransform * object,
return gst_mf_result (hr);
}

View file

@ -27,6 +27,7 @@
#include "gstmfutils.h"
#include <wrl.h>
/* *INDENT-OFF* */
using namespace Microsoft::WRL;
G_BEGIN_DECLS
@ -80,6 +81,7 @@ static struct
{MFVideoFormat_VP90, "video/x-vp9"},
{MFVideoFormat_MJPG, "image/jpeg"},
};
/* *INDENT-ON* */
GstVideoFormat
gst_mf_video_subtype_to_video_format (const GUID * subtype)
@ -395,178 +397,178 @@ _gst_mf_result (HRESULT hr, GstDebugCategory * cat, const gchar * file,
} G_STMT_END
static const gchar *
gst_mf_guid_to_static_string (const GUID& guid)
gst_mf_guid_to_static_string (const GUID & guid)
{
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_MAJOR_TYPE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_MAJOR_TYPE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_SUBTYPE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_ALL_SAMPLES_INDEPENDENT);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_FIXED_SIZE_SAMPLES);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_COMPRESSED);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_SAMPLE_SIZE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_WRAPPED_TYPE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AUDIO_NUM_CHANNELS);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AUDIO_SAMPLES_PER_SECOND);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AUDIO_FLOAT_SAMPLES_PER_SECOND);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AUDIO_AVG_BYTES_PER_SECOND);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AUDIO_BLOCK_ALIGNMENT);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AUDIO_BITS_PER_SAMPLE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AUDIO_VALID_BITS_PER_SAMPLE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AUDIO_SAMPLES_PER_BLOCK);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AUDIO_CHANNEL_MASK);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AUDIO_FOLDDOWN_MATRIX);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AUDIO_WMADRC_PEAKREF);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AUDIO_WMADRC_PEAKTARGET);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AUDIO_WMADRC_AVGREF);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AUDIO_WMADRC_AVGTARGET);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AUDIO_PREFER_WAVEFORMATEX);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AAC_PAYLOAD_TYPE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AAC_AUDIO_PROFILE_LEVEL_INDICATION);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_FRAME_SIZE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_FRAME_RATE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_FRAME_RATE_RANGE_MAX);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_FRAME_RATE_RANGE_MIN);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_PIXEL_ASPECT_RATIO);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_DRM_FLAGS);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_PAD_CONTROL_FLAGS);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_SOURCE_CONTENT_HINT);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_VIDEO_CHROMA_SITING);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_INTERLACE_MODE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_TRANSFER_FUNCTION);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_VIDEO_PRIMARIES);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_YUV_MATRIX);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_VIDEO_LIGHTING);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_VIDEO_NOMINAL_RANGE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_GEOMETRIC_APERTURE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_MINIMUM_DISPLAY_APERTURE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_PAN_SCAN_APERTURE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_PAN_SCAN_ENABLED);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AVG_BITRATE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AVG_BIT_ERROR_RATE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_MAX_KEYFRAME_SPACING);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_DEFAULT_STRIDE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_PALETTE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_USER_DATA);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_MPEG_START_TIME_CODE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_MPEG2_PROFILE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_MPEG2_LEVEL);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_MPEG2_FLAGS);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_MPEG_SEQUENCE_HEADER);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_DV_AAUX_SRC_PACK_0);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_DV_AAUX_CTRL_PACK_0);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_DV_AAUX_SRC_PACK_1);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_DV_AAUX_CTRL_PACK_1);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_DV_VAUX_SRC_PACK);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_DV_VAUX_CTRL_PACK);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_IMAGE_LOSS_TOLERANT);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_MPEG4_SAMPLE_DESCRIPTION);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_MPEG4_CURRENT_SAMPLE_ENTRY);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_MAJOR_TYPE);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_MAJOR_TYPE);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_SUBTYPE);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_ALL_SAMPLES_INDEPENDENT);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_FIXED_SIZE_SAMPLES);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_COMPRESSED);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_SAMPLE_SIZE);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_WRAPPED_TYPE);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_AUDIO_NUM_CHANNELS);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_AUDIO_SAMPLES_PER_SECOND);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_AUDIO_FLOAT_SAMPLES_PER_SECOND);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_AUDIO_AVG_BYTES_PER_SECOND);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_AUDIO_BLOCK_ALIGNMENT);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_AUDIO_BITS_PER_SAMPLE);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_AUDIO_VALID_BITS_PER_SAMPLE);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_AUDIO_SAMPLES_PER_BLOCK);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_AUDIO_CHANNEL_MASK);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_AUDIO_FOLDDOWN_MATRIX);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_AUDIO_WMADRC_PEAKREF);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_AUDIO_WMADRC_PEAKTARGET);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_AUDIO_WMADRC_AVGREF);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_AUDIO_WMADRC_AVGTARGET);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_AUDIO_PREFER_WAVEFORMATEX);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_AAC_PAYLOAD_TYPE);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_AAC_AUDIO_PROFILE_LEVEL_INDICATION);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_FRAME_SIZE);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_FRAME_RATE);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_FRAME_RATE_RANGE_MAX);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_FRAME_RATE_RANGE_MIN);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_PIXEL_ASPECT_RATIO);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_DRM_FLAGS);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_PAD_CONTROL_FLAGS);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_SOURCE_CONTENT_HINT);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_VIDEO_CHROMA_SITING);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_INTERLACE_MODE);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_TRANSFER_FUNCTION);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_VIDEO_PRIMARIES);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_YUV_MATRIX);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_VIDEO_LIGHTING);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_VIDEO_NOMINAL_RANGE);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_GEOMETRIC_APERTURE);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_MINIMUM_DISPLAY_APERTURE);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_PAN_SCAN_APERTURE);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_PAN_SCAN_ENABLED);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_AVG_BITRATE);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_AVG_BIT_ERROR_RATE);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_MAX_KEYFRAME_SPACING);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_DEFAULT_STRIDE);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_PALETTE);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_USER_DATA);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_MPEG_START_TIME_CODE);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_MPEG2_PROFILE);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_MPEG2_LEVEL);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_MPEG2_FLAGS);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_MPEG_SEQUENCE_HEADER);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_DV_AAUX_SRC_PACK_0);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_DV_AAUX_CTRL_PACK_0);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_DV_AAUX_SRC_PACK_1);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_DV_AAUX_CTRL_PACK_1);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_DV_VAUX_SRC_PACK);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_DV_VAUX_CTRL_PACK);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_IMAGE_LOSS_TOLERANT);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_MPEG4_SAMPLE_DESCRIPTION);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_MPEG4_CURRENT_SAMPLE_ENTRY);
GST_MF_IF_EQUAL_RETURN(guid, MFMediaType_Audio);
GST_MF_IF_EQUAL_RETURN(guid, MFMediaType_Video);
GST_MF_IF_EQUAL_RETURN(guid, MFMediaType_Protected);
GST_MF_IF_EQUAL_RETURN(guid, MFMediaType_SAMI);
GST_MF_IF_EQUAL_RETURN(guid, MFMediaType_Script);
GST_MF_IF_EQUAL_RETURN(guid, MFMediaType_Image);
GST_MF_IF_EQUAL_RETURN(guid, MFMediaType_HTML);
GST_MF_IF_EQUAL_RETURN(guid, MFMediaType_Binary);
GST_MF_IF_EQUAL_RETURN(guid, MFMediaType_FileTransfer);
GST_MF_IF_EQUAL_RETURN (guid, MFMediaType_Audio);
GST_MF_IF_EQUAL_RETURN (guid, MFMediaType_Video);
GST_MF_IF_EQUAL_RETURN (guid, MFMediaType_Protected);
GST_MF_IF_EQUAL_RETURN (guid, MFMediaType_SAMI);
GST_MF_IF_EQUAL_RETURN (guid, MFMediaType_Script);
GST_MF_IF_EQUAL_RETURN (guid, MFMediaType_Image);
GST_MF_IF_EQUAL_RETURN (guid, MFMediaType_HTML);
GST_MF_IF_EQUAL_RETURN (guid, MFMediaType_Binary);
GST_MF_IF_EQUAL_RETURN (guid, MFMediaType_FileTransfer);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_AI44);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_ARGB32);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_AYUV);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_DV25);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_DV50);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_DVH1);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_DVSD);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_DVSL);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_H264);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_H265);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_HEVC);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_HEVC_ES);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_I420);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_IYUV);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_M4S2);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_MJPG);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_MP43);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_MP4S);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_MP4V);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_MPG1);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_MSS1);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_MSS2);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_NV11);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_NV12);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_P010);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_P016);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_P210);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_P216);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_RGB24);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_RGB32);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_RGB555);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_RGB565);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_RGB8);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_UYVY);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_v210);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_v410);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_VP80);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_VP90);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_WMV1);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_WMV2);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_WMV3);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_WVC1);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_Y210);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_Y216);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_Y410);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_Y416);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_Y41P);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_Y41T);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_YUY2);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_YV12);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_YVYU);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_AI44);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_ARGB32);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_AYUV);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_DV25);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_DV50);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_DVH1);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_DVSD);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_DVSL);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_H264);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_H265);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_HEVC);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_HEVC_ES);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_I420);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_IYUV);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_M4S2);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_MJPG);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_MP43);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_MP4S);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_MP4V);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_MPG1);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_MSS1);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_MSS2);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_NV11);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_NV12);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_P010);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_P016);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_P210);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_P216);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_RGB24);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_RGB32);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_RGB555);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_RGB565);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_RGB8);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_UYVY);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_v210);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_v410);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_VP80);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_VP90);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_WMV1);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_WMV2);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_WMV3);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_WVC1);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_Y210);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_Y216);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_Y410);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_Y416);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_Y41P);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_Y41T);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_YUY2);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_YV12);
GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_YVYU);
/* WAVE_FORMAT_PCM */
GST_MF_IF_EQUAL_RETURN(guid, MFAudioFormat_PCM);
GST_MF_IF_EQUAL_RETURN (guid, MFAudioFormat_PCM);
/* WAVE_FORMAT_IEEE_FLOAT */
GST_MF_IF_EQUAL_RETURN(guid, MFAudioFormat_Float);
GST_MF_IF_EQUAL_RETURN (guid, MFAudioFormat_Float);
/* WAVE_FORMAT_DTS */
GST_MF_IF_EQUAL_RETURN(guid, MFAudioFormat_DTS);
GST_MF_IF_EQUAL_RETURN (guid, MFAudioFormat_DTS);
/* WAVE_FORMAT_DOLBY_AC3_SPDIF */
GST_MF_IF_EQUAL_RETURN(guid, MFAudioFormat_Dolby_AC3_SPDIF);
GST_MF_IF_EQUAL_RETURN (guid, MFAudioFormat_Dolby_AC3_SPDIF);
/* WAVE_FORMAT_DRM */
GST_MF_IF_EQUAL_RETURN(guid, MFAudioFormat_DRM);
GST_MF_IF_EQUAL_RETURN (guid, MFAudioFormat_DRM);
/* WAVE_FORMAT_WMAUDIO2 */
GST_MF_IF_EQUAL_RETURN(guid, MFAudioFormat_WMAudioV8);
GST_MF_IF_EQUAL_RETURN (guid, MFAudioFormat_WMAudioV8);
/* WAVE_FORMAT_WMAUDIO3 */
GST_MF_IF_EQUAL_RETURN(guid, MFAudioFormat_WMAudioV9);
GST_MF_IF_EQUAL_RETURN (guid, MFAudioFormat_WMAudioV9);
/* WAVE_FORMAT_WMAUDIO_LOSSLESS */
GST_MF_IF_EQUAL_RETURN(guid, MFAudioFormat_WMAudio_Lossless);
GST_MF_IF_EQUAL_RETURN (guid, MFAudioFormat_WMAudio_Lossless);
/* WAVE_FORMAT_WMASPDIF */
GST_MF_IF_EQUAL_RETURN(guid, MFAudioFormat_WMASPDIF);
GST_MF_IF_EQUAL_RETURN (guid, MFAudioFormat_WMASPDIF);
/* WAVE_FORMAT_WMAVOICE9 */
GST_MF_IF_EQUAL_RETURN(guid, MFAudioFormat_MSP1);
GST_MF_IF_EQUAL_RETURN (guid, MFAudioFormat_MSP1);
/* WAVE_FORMAT_MPEGLAYER3 */
GST_MF_IF_EQUAL_RETURN(guid, MFAudioFormat_MP3);
GST_MF_IF_EQUAL_RETURN (guid, MFAudioFormat_MP3);
/* WAVE_FORMAT_MPEG */
GST_MF_IF_EQUAL_RETURN(guid, MFAudioFormat_MPEG);
GST_MF_IF_EQUAL_RETURN (guid, MFAudioFormat_MPEG);
/* WAVE_FORMAT_MPEG_HEAAC */
GST_MF_IF_EQUAL_RETURN(guid, MFAudioFormat_AAC);
GST_MF_IF_EQUAL_RETURN (guid, MFAudioFormat_AAC);
/* WAVE_FORMAT_MPEG_ADTS_AAC */
GST_MF_IF_EQUAL_RETURN(guid, MFAudioFormat_ADTS);
GST_MF_IF_EQUAL_RETURN (guid, MFAudioFormat_ADTS);
#if GST_MF_WINAPI_DESKTOP
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_CUSTOM_VIDEO_PRIMARIES);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AM_FORMAT_TYPE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_ARBITRARY_HEADER);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_ARBITRARY_FORMAT);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_ORIGINAL_4CC);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_ORIGINAL_WAVE_FORMAT_TAG);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_CUSTOM_VIDEO_PRIMARIES);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_AM_FORMAT_TYPE);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_ARBITRARY_HEADER);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_ARBITRARY_FORMAT);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_ORIGINAL_4CC);
GST_MF_IF_EQUAL_RETURN (guid, MF_MT_ORIGINAL_WAVE_FORMAT_TAG);
#endif
return NULL;
}
static gchar *
gst_mf_guid_to_string (const GUID& guid)
gst_mf_guid_to_string (const GUID & guid)
{
const gchar *str = NULL;
HRESULT hr;
@ -589,14 +591,14 @@ gst_mf_guid_to_string (const GUID& guid)
ret = g_strdup_printf
("%8.8x-%4.4x-%4.4x-%2.2x%2.2x-%2.2x%2.2x%2.2x%2.2x%2.2x%2.2x",
(guint) guid.Data1, (guint) guid.Data2, (guint) guid.Data3,
guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3],
guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3],
guid.Data4[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
return ret;
}
static gchar *
gst_mf_attribute_value_to_string (const GUID& guid, const PROPVARIANT& var)
gst_mf_attribute_value_to_string (const GUID & guid, const PROPVARIANT & var)
{
if (IsEqualGUID (guid, MF_MT_FRAME_RATE) ||
IsEqualGUID (guid, MF_MT_FRAME_RATE_RANGE_MAX) ||
@ -605,7 +607,7 @@ gst_mf_attribute_value_to_string (const GUID& guid, const PROPVARIANT& var)
IsEqualGUID (guid, MF_MT_PIXEL_ASPECT_RATIO)) {
UINT32 high = 0, low = 0;
Unpack2UINT32AsUINT64(var.uhVal.QuadPart, &high, &low);
Unpack2UINT32AsUINT64 (var.uhVal.QuadPart, &high, &low);
return g_strdup_printf ("%dx%d", high, low);
}
@ -639,8 +641,8 @@ gst_mf_attribute_value_to_string (const GUID& guid, const PROPVARIANT& var)
static void
gst_mf_dump_attribute_value_by_index (IMFAttributes * attr, const gchar * msg,
guint index, GstDebugLevel level, GstDebugCategory * cat, const gchar * file,
const gchar * function, gint line)
guint index, GstDebugLevel level, GstDebugCategory * cat,
const gchar * file, const gchar * function, gint line)
{
gchar *guid_name = NULL;
gchar *value = NULL;
@ -648,9 +650,9 @@ gst_mf_dump_attribute_value_by_index (IMFAttributes * attr, const gchar * msg,
HRESULT hr;
PROPVARIANT var;
PropVariantInit(&var);
PropVariantInit (&var);
hr = attr->GetItemByIndex(index, &guid, &var);
hr = attr->GetItemByIndex (index, &guid, &var);
if (!gst_mf_result (hr))
goto done;
@ -663,11 +665,10 @@ gst_mf_dump_attribute_value_by_index (IMFAttributes * attr, const gchar * msg,
goto done;
gst_debug_log (cat, level, file, function, line,
NULL, "%s attribute %d, %s: %s", msg ? msg : "", index, guid_name,
value);
NULL, "%s attribute %d, %s: %s", msg ? msg : "", index, guid_name, value);
done:
PropVariantClear(&var);
PropVariantClear (&var);
g_free (guid_name);
g_free (value);
}
@ -693,4 +694,4 @@ _gst_mf_dump_attributes (IMFAttributes * attr, const gchar * msg,
msg, i, level, cat, file, function, line);
}
#endif
}
}

View file

@ -20,6 +20,7 @@
#include "gstmfvideobuffer.h"
#include <string.h>
/* *INDENT-OFF* */
G_BEGIN_DECLS
GST_DEBUG_CATEGORY_EXTERN (gst_mf_video_buffer_debug);
@ -504,3 +505,5 @@ IGstMFVideoBuffer::ContiguousCopyFrom (const BYTE * src_buffer,
return S_OK;
}
/* *INDENT-ON* */

View file

@ -33,6 +33,7 @@
#include <d3d10.h>
#endif
/* *INDENT-OFF* */
using namespace Microsoft::WRL;
G_BEGIN_DECLS
@ -41,6 +42,7 @@ GST_DEBUG_CATEGORY_EXTERN (gst_mf_video_enc_debug);
#define GST_CAT_DEFAULT gst_mf_video_enc_debug
G_END_DECLS
/* *INDENT-ON* */
#define gst_mf_video_enc_parent_class parent_class
G_DEFINE_ABSTRACT_TYPE (GstMFVideoEnc, gst_mf_video_enc,
@ -89,10 +91,8 @@ gst_mf_video_enc_class_init (GstMFVideoEncClass * klass)
videoenc_class->flush = GST_DEBUG_FUNCPTR (gst_mf_video_enc_flush);
videoenc_class->propose_allocation =
GST_DEBUG_FUNCPTR (gst_mf_video_enc_propose_allocation);
videoenc_class->sink_query =
GST_DEBUG_FUNCPTR (gst_mf_video_enc_sink_query);
videoenc_class->src_query =
GST_DEBUG_FUNCPTR (gst_mf_video_enc_src_query);
videoenc_class->sink_query = GST_DEBUG_FUNCPTR (gst_mf_video_enc_sink_query);
videoenc_class->src_query = GST_DEBUG_FUNCPTR (gst_mf_video_enc_src_query);
gst_type_mark_as_plugin_api (GST_TYPE_MF_VIDEO_ENC, (GstPluginAPIFlags) 0);
}
@ -142,7 +142,7 @@ gst_mf_video_enc_open (GstVideoEncoder * enc)
if (device_caps->d3d11_aware) {
HRESULT hr;
ID3D11Device *device_handle;
ComPtr<ID3D10Multithread> multi_thread;
ComPtr < ID3D10Multithread > multi_thread;
GstD3D11Device *device;
if (!gst_d3d11_ensure_element_data (GST_ELEMENT_CAST (self),
@ -162,8 +162,7 @@ gst_mf_video_enc_open (GstVideoEncoder * enc)
device = self->d3d11_device;
hr = MFCreateDXGIDeviceManager (&self->reset_token,
&self->device_manager);
hr = MFCreateDXGIDeviceManager (&self->reset_token, &self->device_manager);
if (!gst_mf_result (hr)) {
GST_ERROR_OBJECT (self, "Couldn't create DXGI device manager");
gst_clear_object (&self->other_d3d11_device);
@ -187,8 +186,7 @@ gst_mf_video_enc_open (GstVideoEncoder * enc)
hr = self->device_manager->ResetDevice ((IUnknown *) device_handle,
self->reset_token);
if (!gst_mf_result (hr)) {
GST_ERROR_OBJECT (self,
"Couldn't reset device with given d3d11 device");
GST_ERROR_OBJECT (self, "Couldn't reset device with given d3d11 device");
gst_clear_object (&self->other_d3d11_device);
gst_clear_object (&self->d3d11_device);
return FALSE;
@ -227,11 +225,10 @@ gst_mf_video_enc_open (GstVideoEncoder * enc)
* internal worker queue thread */
if (self->transform &&
(enum_params.enum_flags & MFT_ENUM_FLAG_HARDWARE) ==
MFT_ENUM_FLAG_HARDWARE) {
MFT_ENUM_FLAG_HARDWARE) {
self->async_mft = TRUE;
gst_mf_transform_set_new_sample_callback (self->transform,
(GstMFTransformNewSampleCallback) gst_mf_video_on_new_sample,
self);
(GstMFTransformNewSampleCallback) gst_mf_video_on_new_sample, self);
} else {
self->async_mft = FALSE;
}
@ -250,7 +247,6 @@ gst_mf_video_enc_close (GstVideoEncoder * enc)
gst_video_codec_state_unref (self->input_state);
self->input_state = NULL;
}
#if GST_MF_HAVE_D3D11
if (self->device_manager) {
self->device_manager->Release ();
@ -286,8 +282,8 @@ gst_mf_video_enc_set_format (GstVideoEncoder * enc, GstVideoCodecState * state)
GstMFVideoEnc *self = GST_MF_VIDEO_ENC (enc);
GstMFVideoEncClass *klass = GST_MF_VIDEO_ENC_GET_CLASS (enc);
GstVideoInfo *info = &state->info;
ComPtr<IMFMediaType> in_type;
ComPtr<IMFMediaType> out_type;
ComPtr < IMFMediaType > in_type;
ComPtr < IMFMediaType > out_type;
GList *input_types = NULL;
GList *iter;
HRESULT hr;
@ -309,11 +305,10 @@ gst_mf_video_enc_set_format (GstVideoEncoder * enc, GstVideoCodecState * state)
GST_ERROR_OBJECT (self, "Failed to open MFT");
return FALSE;
}
#if GST_MF_HAVE_D3D11
if (self->device_manager) {
if (!gst_mf_transform_set_device_manager (self->transform,
self->device_manager)) {
self->device_manager)) {
GST_ERROR_OBJECT (self, "Couldn't set device manager");
return FALSE;
} else {
@ -384,7 +379,7 @@ gst_mf_video_enc_set_format (GstVideoEncoder * enc, GstVideoCodecState * state)
}
if (!gst_mf_transform_get_input_available_types (self->transform,
&input_types)) {
&input_types)) {
GST_ERROR_OBJECT (self, "Couldn't get available input types");
return FALSE;
}
@ -460,7 +455,6 @@ gst_mf_video_enc_set_format (GstVideoEncoder * enc, GstVideoCodecState * state)
GST_ERROR_OBJECT (self, "subclass couldn't set src caps");
return FALSE;
}
#if GST_MF_HAVE_D3D11
if (self->mf_allocator) {
self->mf_allocator->UninitializeSampleAllocator ();
@ -471,7 +465,7 @@ gst_mf_video_enc_set_format (GstVideoEncoder * enc, GstVideoCodecState * state)
/* Check whether upstream is d3d11 element */
if (state->caps) {
GstCapsFeatures *features;
ComPtr<IMFVideoSampleAllocatorEx> allocator;
ComPtr < IMFVideoSampleAllocatorEx > allocator;
features = gst_caps_get_features (state->caps, 0);
@ -482,19 +476,20 @@ gst_mf_video_enc_set_format (GstVideoEncoder * enc, GstVideoCodecState * state)
hr = MFCreateVideoSampleAllocatorEx (IID_PPV_ARGS (&allocator));
if (!gst_mf_result (hr))
GST_WARNING_OBJECT (self, "IMFVideoSampleAllocatorEx interface is unavailable");
GST_WARNING_OBJECT (self,
"IMFVideoSampleAllocatorEx interface is unavailable");
}
if (allocator) {
do {
ComPtr<IMFAttributes> attr;
ComPtr < IMFAttributes > attr;
hr = MFCreateAttributes (&attr, 4);
if (!gst_mf_result (hr))
break;
/* Only one buffer per sample
* (multiple sample is usually for multi-view things) */
* (multiple sample is usually for multi-view things) */
hr = attr->SetUINT32 (GST_GUID_MF_SA_BUFFERS_PER_SAMPLE, 1);
if (!gst_mf_result (hr))
break;
@ -518,15 +513,13 @@ gst_mf_video_enc_set_format (GstVideoEncoder * enc, GstVideoCodecState * state)
break;
hr = allocator->InitializeSampleAllocatorEx (
/* min samples, since we are running on async mode,
* at least 2 samples would be required */
2,
/* max samples, why 16 + 2? it's just magic number
* (H264 max dpb size 16 + our min sample size 2) */
16 + 2,
attr.Get (),
in_type.Get ()
);
/* min samples, since we are running on async mode,
* at least 2 samples would be required */
2,
/* max samples, why 16 + 2? it's just magic number
* (H264 max dpb size 16 + our min sample size 2) */
16 + 2, attr.Get (), in_type.Get ()
);
if (!gst_mf_result (hr))
break;
@ -660,8 +653,9 @@ gst_mf_video_enc_process_input (GstMFVideoEnc * self,
if (!gst_mf_result (hr))
return FALSE;
hr = sample->SetSampleDuration (
GST_CLOCK_TIME_IS_VALID (frame->duration) ? frame->duration / 100 : 0);
hr = sample->
SetSampleDuration (GST_CLOCK_TIME_IS_VALID (frame->duration) ? frame->
duration / 100 : 0);
if (!gst_mf_result (hr))
return FALSE;
@ -685,7 +679,7 @@ gst_mf_video_enc_process_input (GstMFVideoEnc * self,
GST_VIDEO_ENCODER_STREAM_UNLOCK (self);
res = gst_mf_transform_process_input (self->transform, sample);
if (self->async_mft)
GST_VIDEO_ENCODER_STREAM_LOCK (self);
GST_VIDEO_ENCODER_STREAM_LOCK (self);
if (unset_force_keyframe) {
gst_mf_transform_set_codec_api_uint32 (self->transform,
@ -755,7 +749,7 @@ gst_mf_video_enc_finish_sample (GstMFVideoEnc * self, IMFSample * sample)
{
HRESULT hr = S_OK;
BYTE *data;
ComPtr<IMFMediaBuffer> media_buffer;
ComPtr < IMFMediaBuffer > media_buffer;
GstBuffer *buffer;
GstFlowReturn res = GST_FLOW_ERROR;
GstVideoCodecFrame *frame;
@ -871,8 +865,7 @@ gst_mf_video_enc_finish_sample (GstMFVideoEnc * self, IMFSample * sample)
/* make sure PTS > DTS */
if (GST_CLOCK_TIME_IS_VALID (frame->pts) &&
GST_CLOCK_TIME_IS_VALID (frame->dts) &&
frame->pts < frame->dts) {
GST_CLOCK_TIME_IS_VALID (frame->dts) && frame->pts < frame->dts) {
GST_WARNING_OBJECT (self, "Calculated DTS %" GST_TIME_FORMAT
" is larger than PTS %" GST_TIME_FORMAT, GST_TIME_ARGS (frame->pts),
GST_TIME_ARGS (frame->dts));
@ -882,7 +875,8 @@ gst_mf_video_enc_finish_sample (GstMFVideoEnc * self, IMFSample * sample)
}
GST_LOG_OBJECT (self, "Frame pts %" GST_TIME_FORMAT ", Frame DTS %"
GST_TIME_FORMAT, GST_TIME_ARGS (frame->pts), GST_TIME_ARGS (frame->dts));
GST_TIME_FORMAT, GST_TIME_ARGS (frame->pts),
GST_TIME_ARGS (frame->dts));
res = gst_video_encoder_finish_frame (GST_VIDEO_ENCODER (self), frame);
} else {
@ -913,7 +907,7 @@ done:
static GstFlowReturn
gst_mf_video_enc_process_output (GstMFVideoEnc * self)
{
ComPtr<IMFSample> sample;
ComPtr < IMFSample > sample;
GstFlowReturn res = GST_FLOW_ERROR;
res = gst_mf_transform_get_output (self->transform, &sample);
@ -931,9 +925,9 @@ gst_mf_video_enc_create_input_sample (GstMFVideoEnc * self,
GstVideoCodecFrame * frame, IMFSample ** sample)
{
HRESULT hr;
ComPtr<IMFSample> new_sample;
ComPtr<IMFMediaBuffer> media_buffer;
ComPtr<IGstMFVideoBuffer> video_buffer;
ComPtr < IMFSample > new_sample;
ComPtr < IMFMediaBuffer > media_buffer;
ComPtr < IGstMFVideoBuffer > video_buffer;
GstVideoInfo *info = &self->input_state->info;
gint i, j;
GstVideoFrame *vframe = NULL;
@ -960,8 +954,8 @@ gst_mf_video_enc_create_input_sample (GstMFVideoEnc * self,
} else {
GST_TRACE_OBJECT (self, "Can use input buffer without copy");
hr = IGstMFVideoBuffer::CreateInstanceWrapped (&vframe->info,
(BYTE *) GST_VIDEO_FRAME_PLANE_DATA (vframe, 0),
GST_VIDEO_INFO_SIZE (&vframe->info), &media_buffer);
(BYTE *) GST_VIDEO_FRAME_PLANE_DATA (vframe, 0),
GST_VIDEO_INFO_SIZE (&vframe->info), &media_buffer);
}
if (!gst_mf_result (hr))
@ -1040,13 +1034,13 @@ gst_mf_video_enc_create_input_sample_d3d11 (GstMFVideoEnc * self,
GstVideoCodecFrame * frame, IMFSample ** sample)
{
HRESULT hr;
ComPtr<IMFSample> new_sample;
ComPtr<IMFMediaBuffer> mf_buffer;
ComPtr<IMFDXGIBuffer> dxgi_buffer;
ComPtr<ID3D11Texture2D> mf_texture;
ComPtr<IDXGIResource> dxgi_resource;
ComPtr<ID3D11Texture2D> shared_texture;
ComPtr<ID3D11Query> query;
ComPtr < IMFSample > new_sample;
ComPtr < IMFMediaBuffer > mf_buffer;
ComPtr < IMFDXGIBuffer > dxgi_buffer;
ComPtr < ID3D11Texture2D > mf_texture;
ComPtr < IDXGIResource > dxgi_resource;
ComPtr < ID3D11Texture2D > shared_texture;
ComPtr < ID3D11Query > query;
D3D11_QUERY_DESC query_desc;
BOOL sync_done = FALSE;
HANDLE shared_handle;
@ -1071,7 +1065,7 @@ gst_mf_video_enc_create_input_sample_d3d11 (GstMFVideoEnc * self,
return FALSE;
}
dmem = (GstD3D11Memory * ) mem;
dmem = (GstD3D11Memory *) mem;
device_handle = gst_d3d11_device_get_device_handle (dmem->device);
context_handle = gst_d3d11_device_get_device_context_handle (dmem->device);
@ -1111,8 +1105,7 @@ gst_mf_video_enc_create_input_sample_d3d11 (GstMFVideoEnc * self,
hr = dxgi_resource->GetSharedHandle (&shared_handle);
if (!gst_mf_result (hr)) {
GST_WARNING_OBJECT (self,
"Couldn't get shared handle from IDXGIResource");
GST_WARNING_OBJECT (self, "Couldn't get shared handle from IDXGIResource");
return FALSE;
}
@ -1127,7 +1120,8 @@ gst_mf_video_enc_create_input_sample_d3d11 (GstMFVideoEnc * self,
/* 2) Copy upstream texture to mf's texture */
/* Map memory so that ensure pending upload from staging texture */
if (!gst_memory_map (mem, &info, (GstMapFlags) (GST_MAP_READ | GST_MAP_D3D11))) {
if (!gst_memory_map (mem, &info,
(GstMapFlags) (GST_MAP_READ | GST_MAP_D3D11))) {
GST_ERROR_OBJECT (self, "Couldn't map d3d11 memory");
return FALSE;
}
@ -1160,11 +1154,11 @@ gst_mf_video_enc_create_input_sample_d3d11 (GstMFVideoEnc * self,
gst_d3d11_device_lock (dmem->device);
context_handle->CopySubresourceRegion (shared_texture.Get (), 0, 0, 0, 0,
texture, subidx, &src_box);
context_handle->End (query.Get());
context_handle->End (query.Get ());
/* Wait until all issued GPU commands are finished */
do {
context_handle->GetData (query.Get(), &sync_done, sizeof (BOOL), 0);
context_handle->GetData (query.Get (), &sync_done, sizeof (BOOL), 0);
} while (!sync_done && (hr == S_OK || hr == S_FALSE));
if (!gst_d3d11_result (hr, dmem->device)) {
@ -1190,14 +1184,13 @@ gst_mf_video_enc_handle_frame (GstVideoEncoder * enc,
{
GstMFVideoEnc *self = GST_MF_VIDEO_ENC (enc);
GstFlowReturn ret = GST_FLOW_OK;
ComPtr<IMFSample> sample;
ComPtr < IMFSample > sample;
if (self->last_ret != GST_FLOW_OK) {
GST_DEBUG_OBJECT (self, "Last return was %s", gst_flow_get_name (ret));
ret = self->last_ret;
goto done;
}
#if GST_MF_HAVE_D3D11
if (self->mf_allocator &&
!gst_mf_video_enc_create_input_sample_d3d11 (self, frame, &sample)) {
@ -1291,8 +1284,7 @@ out:
}
static gboolean
gst_mf_video_enc_propose_allocation (GstVideoEncoder * enc,
GstQuery * query)
gst_mf_video_enc_propose_allocation (GstVideoEncoder * enc, GstQuery * query)
{
#if GST_MF_HAVE_D3D11
GstMFVideoEnc *self = GST_MF_VIDEO_ENC (enc);
@ -1390,12 +1382,12 @@ config_failed:
#else
return GST_VIDEO_ENCODER_CLASS (parent_class)->propose_allocation (enc,
query);
query);
#endif
}
static gboolean
gst_mf_video_enc_sink_query (GstVideoEncoder * enc, GstQuery *query)
gst_mf_video_enc_sink_query (GstVideoEncoder * enc, GstQuery * query)
{
#if GST_MF_HAVE_D3D11
GstMFVideoEnc *self = GST_MF_VIDEO_ENC (enc);
@ -1416,7 +1408,7 @@ gst_mf_video_enc_sink_query (GstVideoEncoder * enc, GstQuery *query)
}
static gboolean
gst_mf_video_enc_src_query (GstVideoEncoder * enc, GstQuery * query)
gst_mf_video_enc_src_query (GstVideoEncoder * enc, GstQuery * query)
{
#if GST_MF_HAVE_D3D11
GstMFVideoEnc *self = GST_MF_VIDEO_ENC (enc);
@ -1458,7 +1450,7 @@ typedef struct
} GstMFVideoEncProfileMap;
static void
gst_mf_video_enc_enum_internal (GstMFTransform * transform, GUID &subtype,
gst_mf_video_enc_enum_internal (GstMFTransform * transform, GUID & subtype,
GstObject * d3d11_device, GstMFVideoEncDeviceCaps * device_caps,
GstCaps ** sink_template, GstCaps ** src_template)
{
@ -1479,17 +1471,17 @@ gst_mf_video_enc_enum_internal (GstMFTransform * transform, GUID &subtype,
IMFActivate *activate;
IMFTransform *encoder;
ICodecAPI *codec_api;
ComPtr<IMFMediaType> out_type;
ComPtr < IMFMediaType > out_type;
GstMFVideoEncProfileMap h264_profile_map[] = {
{ eAVEncH264VProfile_High, "high" },
{ eAVEncH264VProfile_Main, "main" },
{ eAVEncH264VProfile_Base, "baseline" },
{ 0, NULL },
{eAVEncH264VProfile_High, "high"},
{eAVEncH264VProfile_Main, "main"},
{eAVEncH264VProfile_Base, "baseline"},
{0, NULL},
};
GstMFVideoEncProfileMap hevc_profile_map[] = {
{ eAVEncH265VProfile_Main_420_8, "main" },
{ eAVEncH265VProfile_Main_420_10, "main-10" },
{ 0, NULL },
{eAVEncH265VProfile_Main_420_8, "main"},
{eAVEncH265VProfile_Main_420_10, "main-10"},
{0, NULL},
};
GstMFVideoEncProfileMap *profile_to_check = NULL;
static gchar *h264_caps_str =
@ -1548,7 +1540,7 @@ gst_mf_video_enc_enum_internal (GstMFTransform * transform, GUID &subtype,
}
switch (format) {
/* media foundation has duplicated formats IYUV and I420 */
/* media foundation has duplicated formats IYUV and I420 */
case GST_VIDEO_FORMAT_I420:
if (have_I420)
continue;
@ -1610,7 +1602,8 @@ gst_mf_video_enc_enum_internal (GstMFTransform * transform, GUID &subtype,
if (!gst_mf_result (hr))
return;
hr = out_type->SetUINT32 (MF_MT_INTERLACE_MODE, MFVideoInterlace_Progressive);
hr = out_type->SetUINT32 (MF_MT_INTERLACE_MODE,
MFVideoInterlace_Progressive);
if (!gst_mf_result (hr))
return;
@ -1991,4 +1984,4 @@ done:
gst_clear_object (&transform);
gst_clear_caps (&sink_template);
gst_clear_caps (&src_template);
}
}

View file

@ -39,7 +39,9 @@
#include "gstmfvp9enc.h"
#include <wrl.h>
/* *INDENT-OFF* */
using namespace Microsoft::WRL;
/* *INDENT-ON* */
GST_DEBUG_CATEGORY (gst_mf_vp9_enc_debug);
#define GST_CAT_DEFAULT gst_mf_vp9_enc_debug
@ -178,7 +180,7 @@ gst_mf_vp9_enc_class_init (GstMFVP9EncClass * klass, gpointer data)
"Rate Control Mode",
GST_TYPE_MF_VP9_ENC_RC_MODE, DEFAULT_RC_MODE,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
/* NOTE: documentation will be done by only for default device */
if (cdata->is_default) {
@ -194,7 +196,7 @@ gst_mf_vp9_enc_class_init (GstMFVP9EncClass * klass, gpointer data)
"(0 = MFT default)", 0, (G_MAXUINT >> 10),
DEFAULT_MAX_BITRATE,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->quality_vs_speed) {
@ -204,7 +206,7 @@ gst_mf_vp9_enc_class_init (GstMFVP9EncClass * klass, gpointer data)
"[34, 66]: Medium complexity, [67, 100]: High complexity", 0, 100,
DEFAULT_QUALITY_VS_SPEED,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->gop_size) {
@ -215,7 +217,7 @@ gst_mf_vp9_enc_class_init (GstMFVP9EncClass * klass, gpointer data)
"produce only one keyframe at the beginning (-1 for automatic)",
-1, G_MAXINT, DEFAULT_GOP_SIZE,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->threads) {
@ -225,7 +227,7 @@ gst_mf_vp9_enc_class_init (GstMFVP9EncClass * klass, gpointer data)
"(0 = MFT default)", 0, 16,
DEFAULT_THREADS,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
if (device_caps->content_type) {
@ -234,7 +236,7 @@ gst_mf_vp9_enc_class_init (GstMFVP9EncClass * klass, gpointer data)
"Indicates the type of video content",
GST_TYPE_MF_VP9_ENC_CONTENT_TYPE, DEFAULT_CONTENT_TYPE,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
/* NOTE: documentation will be done by only for default device */
if (cdata->is_default) {
@ -249,7 +251,7 @@ gst_mf_vp9_enc_class_init (GstMFVP9EncClass * klass, gpointer data)
"Enable low latency encoding",
DEFAULT_LOW_LATENCY,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
}
g_object_class_install_property (gobject_class, PROP_D3D11_AWARE,
@ -264,13 +266,13 @@ gst_mf_vp9_enc_class_init (GstMFVP9EncClass * klass, gpointer data)
"DXGI Adapter index for creating device",
0, G_MAXUINT32, device_caps->adapter,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)));
}
long_name = g_strdup_printf ("Media Foundation %s", cdata->device_name);
classification = g_strdup_printf ("Codec/Encoder/Video%s",
(cdata->enum_flags & MFT_ENUM_FLAG_HARDWARE) == MFT_ENUM_FLAG_HARDWARE ?
"/Hardware" : "");
"/Hardware" : "");
gst_element_class_set_metadata (element_class, long_name,
classification,
"Microsoft Media Foundation VP9 Encoder",
@ -467,8 +469,7 @@ gst_mf_vp9_enc_set_option (GstMFVideoEnc * mfenc, GstVideoCodecState * state,
if (device_caps->quality_vs_speed) {
hr = gst_mf_transform_set_codec_api_uint32 (transform,
&CODECAPI_AVEncCommonQualityVsSpeed,
self->quality_vs_speed);
&CODECAPI_AVEncCommonQualityVsSpeed, self->quality_vs_speed);
WARNING_HR (hr, CODECAPI_AVEncCommonQualityVsSpeed);
}
@ -572,4 +573,4 @@ gst_mf_vp9_enc_plugin_init (GstPlugin * plugin, guint rank,
GST_DEBUG_CATEGORY_INIT (gst_mf_vp9_enc_debug, "mfvp9enc", 0, "mfvp9enc");
gst_mf_video_enc_register (plugin, rank, &subtype, &type_info, d3d11_device);
}
}

View file

@ -34,6 +34,7 @@
#include <algorithm>
#include <iterator>
/* *INDENT-OFF* */
using namespace ABI::Windows::ApplicationModel::Core;
using namespace ABI::Windows::Foundation::Collections;
using namespace ABI::Windows::Media::Devices;
@ -1175,4 +1176,6 @@ WinRTCapsCompareFunc (const GstWinRTMediaDescription & a,
const GstWinRTMediaDescription & b)
{
return gst_mf_source_object_caps_compare (a.caps_, b.caps_) < 0;
}
}
/* *INDENT-ON* */