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

View file

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

View file

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

View file

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

View file

@ -40,7 +40,9 @@
#include "gstmfh265enc.h" #include "gstmfh265enc.h"
#include <wrl.h> #include <wrl.h>
/* *INDENT-OFF* */
using namespace Microsoft::WRL; using namespace Microsoft::WRL;
/* *INDENT-ON* */
GST_DEBUG_CATEGORY (gst_mf_h265_enc_debug); GST_DEBUG_CATEGORY (gst_mf_h265_enc_debug);
#define GST_CAT_DEFAULT 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", "Rate Control Mode",
GST_TYPE_MF_H265_ENC_RC_MODE, DEFAULT_RC_MODE, GST_TYPE_MF_H265_ENC_RC_MODE, DEFAULT_RC_MODE,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE | (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 */ /* NOTE: documentation will be done by only for default device */
if (cdata->is_default) { if (cdata->is_default) {
gst_type_mark_as_plugin_api (GST_TYPE_MF_H265_ENC_RC_MODE, 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)", "VBV(HRD) Buffer Size in bytes (0 = MFT default)",
0, G_MAXUINT - 1, DEFAULT_BUFFER_SIZE, 0, G_MAXUINT - 1, DEFAULT_BUFFER_SIZE,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE | (GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
} }
if (device_caps->max_bitrate) { 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 " "The maximum bitrate applied when rc-mode is \"pcvbr\" in kbit/sec "
"(0 = MFT default)", 0, (G_MAXUINT >> 10), DEFAULT_MAX_BITRATE, "(0 = MFT default)", 0, (G_MAXUINT >> 10), DEFAULT_MAX_BITRATE,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE | (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) { 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", "[34, 66]: Medium complexity, [67, 100]: High complexity",
0, 100, DEFAULT_QUALITY_VS_SPEED, 0, 100, DEFAULT_QUALITY_VS_SPEED,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE | (GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
} }
if (device_caps->bframes) { 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", "The maximum number of consecutive B frames",
0, 2, DEFAULT_BFRAMES, 0, 2, DEFAULT_BFRAMES,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE | (GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
} }
if (device_caps->gop_size) { 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)", "produce only one keyframe at the beginning (-1 for automatic)",
-1, G_MAXINT, DEFAULT_GOP_SIZE, -1, G_MAXINT, DEFAULT_GOP_SIZE,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE | (GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
} }
if (device_caps->threads) { 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)", "The number of worker threads used by a encoder, (0 = MFT default)",
0, 16, DEFAULT_THREADS, 0, 16, DEFAULT_THREADS,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE | (GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
} }
if (device_caps->content_type) { 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", "Indicates the type of video content",
GST_TYPE_MF_H265_ENC_CONTENT_TYPE, DEFAULT_CONTENT_TYPE, GST_TYPE_MF_H265_ENC_CONTENT_TYPE, DEFAULT_CONTENT_TYPE,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE | (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 */ /* NOTE: documentation will be done by only for default device */
if (cdata->is_default) { if (cdata->is_default) {
@ -293,7 +295,7 @@ gst_mf_h265_enc_class_init (GstMFH265EncClass * klass, gpointer data)
g_param_spec_uint ("qp", "qp", g_param_spec_uint ("qp", "qp",
"QP applied when rc-mode is \"qvbr\"", 16, 51, DEFAULT_QP, "QP applied when rc-mode is \"qvbr\"", 16, 51, DEFAULT_QP,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE | (GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
} }
if (device_caps->low_latency) { 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", g_param_spec_boolean ("low-latency", "Low Latency",
"Enable low latency encoding", DEFAULT_LOW_LATENCY, "Enable low latency encoding", DEFAULT_LOW_LATENCY,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE | (GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
} }
if (device_caps->min_qp) { 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", "The minimum allowed QP applied to all rc-mode",
0, 51, DEFAULT_MIN_QP, 0, 51, DEFAULT_MIN_QP,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE | (GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE |
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS))); G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)));
} }
if (device_caps->max_qp) { 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", "The maximum allowed QP applied to all rc-mode",
0, 51, DEFAULT_MAX_QP, 0, 51, DEFAULT_MAX_QP,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE | (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) { 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, "QP applied to I frames", 0, 51,
DEFAULT_QP_I, DEFAULT_QP_I,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE | (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_object_class_install_property (gobject_class, PROP_QP_P,
g_param_spec_uint ("qp-p", "QP P", g_param_spec_uint ("qp-p", "QP P",
"QP applied to P frames", 0, 51, "QP applied to P frames", 0, 51,
DEFAULT_QP_P, DEFAULT_QP_P,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE | (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_object_class_install_property (gobject_class, PROP_QP_B,
g_param_spec_uint ("qp-b", "QP B", g_param_spec_uint ("qp-b", "QP B",
"QP applied to B frames", 0, 51, "QP applied to B frames", 0, 51,
DEFAULT_QP_B, DEFAULT_QP_B,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE | (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) { 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, device_caps->max_num_ref_low, device_caps->max_num_ref_high,
DEFAULT_REF, DEFAULT_REF,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE | (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, 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", "DXGI Adapter index for creating device",
0, G_MAXUINT32, device_caps->adapter, 0, G_MAXUINT32, device_caps->adapter,
(GParamFlags) (GST_PARAM_CONDITIONALLY_AVAILABLE | (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); long_name = g_strdup_printf ("Media Foundation %s", cdata->device_name);
classification = g_strdup_printf ("Codec/Encoder/Video%s", classification = g_strdup_printf ("Codec/Encoder/Video%s",
(cdata->enum_flags & MFT_ENUM_FLAG_HARDWARE) == MFT_ENUM_FLAG_HARDWARE ? (cdata->enum_flags & MFT_ENUM_FLAG_HARDWARE) == MFT_ENUM_FLAG_HARDWARE ?
"/Hardware" : ""); "/Hardware" : "");
gst_element_class_set_metadata (element_class, long_name, gst_element_class_set_metadata (element_class, long_name,
classification, classification,
"Microsoft Media Foundation H.265 Encoder", "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) { if (device_caps->quality_vs_speed) {
hr = gst_mf_transform_set_codec_api_uint32 (transform, hr = gst_mf_transform_set_codec_api_uint32 (transform,
&CODECAPI_AVEncCommonQualityVsSpeed, &CODECAPI_AVEncCommonQualityVsSpeed, self->quality_vs_speed);
self->quality_vs_speed);
WARNING_HR (hr, CODECAPI_AVEncCommonQualityVsSpeed); 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_DEBUG_CATEGORY_INIT (gst_mf_h265_enc_debug, "mfh265enc", 0, "mfh265enc");
gst_mf_video_enc_register (plugin, rank, &subtype, &type_info, d3d11_device); gst_mf_video_enc_register (plugin, rank, &subtype, &type_info, d3d11_device);
} }

View file

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

View file

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

View file

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

View file

@ -27,6 +27,7 @@
#include "gstmfutils.h" #include "gstmfutils.h"
#include <wrl.h> #include <wrl.h>
/* *INDENT-OFF* */
using namespace Microsoft::WRL; using namespace Microsoft::WRL;
G_BEGIN_DECLS G_BEGIN_DECLS
@ -80,6 +81,7 @@ static struct
{MFVideoFormat_VP90, "video/x-vp9"}, {MFVideoFormat_VP90, "video/x-vp9"},
{MFVideoFormat_MJPG, "image/jpeg"}, {MFVideoFormat_MJPG, "image/jpeg"},
}; };
/* *INDENT-ON* */
GstVideoFormat GstVideoFormat
gst_mf_video_subtype_to_video_format (const GUID * subtype) 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 } G_STMT_END
static const gchar * 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_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_SUBTYPE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_ALL_SAMPLES_INDEPENDENT); 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_FIXED_SIZE_SAMPLES);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_COMPRESSED); 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_SAMPLE_SIZE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_WRAPPED_TYPE); 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_NUM_CHANNELS);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AUDIO_SAMPLES_PER_SECOND); 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_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_AVG_BYTES_PER_SECOND);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AUDIO_BLOCK_ALIGNMENT); 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_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_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_SAMPLES_PER_BLOCK);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AUDIO_CHANNEL_MASK); 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_FOLDDOWN_MATRIX);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AUDIO_WMADRC_PEAKREF); 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_PEAKTARGET);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AUDIO_WMADRC_AVGREF); 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_WMADRC_AVGTARGET);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AUDIO_PREFER_WAVEFORMATEX); 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_PAYLOAD_TYPE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AAC_AUDIO_PROFILE_LEVEL_INDICATION); 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_SIZE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_FRAME_RATE); 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_MAX);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_FRAME_RATE_RANGE_MIN); 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_PIXEL_ASPECT_RATIO);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_DRM_FLAGS); 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_PAD_CONTROL_FLAGS);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_SOURCE_CONTENT_HINT); 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_VIDEO_CHROMA_SITING);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_INTERLACE_MODE); 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_TRANSFER_FUNCTION);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_VIDEO_PRIMARIES); 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_YUV_MATRIX);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_VIDEO_LIGHTING); 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_VIDEO_NOMINAL_RANGE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_GEOMETRIC_APERTURE); 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_MINIMUM_DISPLAY_APERTURE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_PAN_SCAN_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_PAN_SCAN_ENABLED);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_AVG_BITRATE); 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_AVG_BIT_ERROR_RATE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_MAX_KEYFRAME_SPACING); 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_DEFAULT_STRIDE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_PALETTE); 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_USER_DATA);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_MPEG_START_TIME_CODE); 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_PROFILE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_MPEG2_LEVEL); 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_MPEG2_FLAGS);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_MPEG_SEQUENCE_HEADER); 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_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_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_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_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_SRC_PACK);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_DV_VAUX_CTRL_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_IMAGE_LOSS_TOLERANT);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_MPEG4_SAMPLE_DESCRIPTION); 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_MPEG4_CURRENT_SAMPLE_ENTRY);
GST_MF_IF_EQUAL_RETURN(guid, MFMediaType_Audio); GST_MF_IF_EQUAL_RETURN (guid, MFMediaType_Audio);
GST_MF_IF_EQUAL_RETURN(guid, MFMediaType_Video); GST_MF_IF_EQUAL_RETURN (guid, MFMediaType_Video);
GST_MF_IF_EQUAL_RETURN(guid, MFMediaType_Protected); GST_MF_IF_EQUAL_RETURN (guid, MFMediaType_Protected);
GST_MF_IF_EQUAL_RETURN(guid, MFMediaType_SAMI); GST_MF_IF_EQUAL_RETURN (guid, MFMediaType_SAMI);
GST_MF_IF_EQUAL_RETURN(guid, MFMediaType_Script); GST_MF_IF_EQUAL_RETURN (guid, MFMediaType_Script);
GST_MF_IF_EQUAL_RETURN(guid, MFMediaType_Image); GST_MF_IF_EQUAL_RETURN (guid, MFMediaType_Image);
GST_MF_IF_EQUAL_RETURN(guid, MFMediaType_HTML); GST_MF_IF_EQUAL_RETURN (guid, MFMediaType_HTML);
GST_MF_IF_EQUAL_RETURN(guid, MFMediaType_Binary); GST_MF_IF_EQUAL_RETURN (guid, MFMediaType_Binary);
GST_MF_IF_EQUAL_RETURN(guid, MFMediaType_FileTransfer); GST_MF_IF_EQUAL_RETURN (guid, MFMediaType_FileTransfer);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_AI44); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_AI44);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_ARGB32); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_ARGB32);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_AYUV); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_AYUV);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_DV25); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_DV25);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_DV50); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_DV50);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_DVH1); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_DVH1);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_DVSD); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_DVSD);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_DVSL); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_DVSL);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_H264); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_H264);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_H265); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_H265);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_HEVC); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_HEVC);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_HEVC_ES); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_HEVC_ES);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_I420); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_I420);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_IYUV); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_IYUV);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_M4S2); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_M4S2);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_MJPG); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_MJPG);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_MP43); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_MP43);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_MP4S); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_MP4S);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_MP4V); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_MP4V);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_MPG1); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_MPG1);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_MSS1); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_MSS1);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_MSS2); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_MSS2);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_NV11); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_NV11);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_NV12); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_NV12);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_P010); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_P010);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_P016); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_P016);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_P210); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_P210);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_P216); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_P216);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_RGB24); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_RGB24);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_RGB32); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_RGB32);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_RGB555); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_RGB555);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_RGB565); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_RGB565);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_RGB8); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_RGB8);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_UYVY); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_UYVY);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_v210); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_v210);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_v410); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_v410);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_VP80); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_VP80);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_VP90); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_VP90);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_WMV1); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_WMV1);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_WMV2); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_WMV2);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_WMV3); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_WMV3);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_WVC1); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_WVC1);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_Y210); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_Y210);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_Y216); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_Y216);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_Y410); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_Y410);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_Y416); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_Y416);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_Y41P); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_Y41P);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_Y41T); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_Y41T);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_YUY2); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_YUY2);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_YV12); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_YV12);
GST_MF_IF_EQUAL_RETURN(guid, MFVideoFormat_YVYU); GST_MF_IF_EQUAL_RETURN (guid, MFVideoFormat_YVYU);
/* WAVE_FORMAT_PCM */ /* WAVE_FORMAT_PCM */
GST_MF_IF_EQUAL_RETURN(guid, MFAudioFormat_PCM); GST_MF_IF_EQUAL_RETURN (guid, MFAudioFormat_PCM);
/* WAVE_FORMAT_IEEE_FLOAT */ /* WAVE_FORMAT_IEEE_FLOAT */
GST_MF_IF_EQUAL_RETURN(guid, MFAudioFormat_Float); GST_MF_IF_EQUAL_RETURN (guid, MFAudioFormat_Float);
/* WAVE_FORMAT_DTS */ /* WAVE_FORMAT_DTS */
GST_MF_IF_EQUAL_RETURN(guid, MFAudioFormat_DTS); GST_MF_IF_EQUAL_RETURN (guid, MFAudioFormat_DTS);
/* WAVE_FORMAT_DOLBY_AC3_SPDIF */ /* 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 */ /* WAVE_FORMAT_DRM */
GST_MF_IF_EQUAL_RETURN(guid, MFAudioFormat_DRM); GST_MF_IF_EQUAL_RETURN (guid, MFAudioFormat_DRM);
/* WAVE_FORMAT_WMAUDIO2 */ /* WAVE_FORMAT_WMAUDIO2 */
GST_MF_IF_EQUAL_RETURN(guid, MFAudioFormat_WMAudioV8); GST_MF_IF_EQUAL_RETURN (guid, MFAudioFormat_WMAudioV8);
/* WAVE_FORMAT_WMAUDIO3 */ /* WAVE_FORMAT_WMAUDIO3 */
GST_MF_IF_EQUAL_RETURN(guid, MFAudioFormat_WMAudioV9); GST_MF_IF_EQUAL_RETURN (guid, MFAudioFormat_WMAudioV9);
/* WAVE_FORMAT_WMAUDIO_LOSSLESS */ /* 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 */ /* WAVE_FORMAT_WMASPDIF */
GST_MF_IF_EQUAL_RETURN(guid, MFAudioFormat_WMASPDIF); GST_MF_IF_EQUAL_RETURN (guid, MFAudioFormat_WMASPDIF);
/* WAVE_FORMAT_WMAVOICE9 */ /* WAVE_FORMAT_WMAVOICE9 */
GST_MF_IF_EQUAL_RETURN(guid, MFAudioFormat_MSP1); GST_MF_IF_EQUAL_RETURN (guid, MFAudioFormat_MSP1);
/* WAVE_FORMAT_MPEGLAYER3 */ /* WAVE_FORMAT_MPEGLAYER3 */
GST_MF_IF_EQUAL_RETURN(guid, MFAudioFormat_MP3); GST_MF_IF_EQUAL_RETURN (guid, MFAudioFormat_MP3);
/* WAVE_FORMAT_MPEG */ /* WAVE_FORMAT_MPEG */
GST_MF_IF_EQUAL_RETURN(guid, MFAudioFormat_MPEG); GST_MF_IF_EQUAL_RETURN (guid, MFAudioFormat_MPEG);
/* WAVE_FORMAT_MPEG_HEAAC */ /* 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 */ /* 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 #if GST_MF_WINAPI_DESKTOP
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_CUSTOM_VIDEO_PRIMARIES); 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_AM_FORMAT_TYPE);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_ARBITRARY_HEADER); 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_ARBITRARY_FORMAT);
GST_MF_IF_EQUAL_RETURN(guid, MF_MT_ORIGINAL_4CC); 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_ORIGINAL_WAVE_FORMAT_TAG);
#endif #endif
return NULL; return NULL;
} }
static gchar * static gchar *
gst_mf_guid_to_string (const GUID& guid) gst_mf_guid_to_string (const GUID & guid)
{ {
const gchar *str = NULL; const gchar *str = NULL;
HRESULT hr; HRESULT hr;
@ -589,14 +591,14 @@ gst_mf_guid_to_string (const GUID& guid)
ret = g_strdup_printf 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", ("%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, (guint) guid.Data1, (guint) guid.Data2, (guint) guid.Data3,
guid.Data4[0], guid.Data4[1], guid.Data4[2], guid.Data4[3], 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[4], guid.Data4[5], guid.Data4[6], guid.Data4[7]);
return ret; return ret;
} }
static gchar * 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) || if (IsEqualGUID (guid, MF_MT_FRAME_RATE) ||
IsEqualGUID (guid, MF_MT_FRAME_RATE_RANGE_MAX) || 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)) { IsEqualGUID (guid, MF_MT_PIXEL_ASPECT_RATIO)) {
UINT32 high = 0, low = 0; 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); 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 static void
gst_mf_dump_attribute_value_by_index (IMFAttributes * attr, const gchar * msg, gst_mf_dump_attribute_value_by_index (IMFAttributes * attr, const gchar * msg,
guint index, GstDebugLevel level, GstDebugCategory * cat, const gchar * file, guint index, GstDebugLevel level, GstDebugCategory * cat,
const gchar * function, gint line) const gchar * file, const gchar * function, gint line)
{ {
gchar *guid_name = NULL; gchar *guid_name = NULL;
gchar *value = NULL; gchar *value = NULL;
@ -648,9 +650,9 @@ gst_mf_dump_attribute_value_by_index (IMFAttributes * attr, const gchar * msg,
HRESULT hr; HRESULT hr;
PROPVARIANT var; PROPVARIANT var;
PropVariantInit(&var); PropVariantInit (&var);
hr = attr->GetItemByIndex(index, &guid, &var); hr = attr->GetItemByIndex (index, &guid, &var);
if (!gst_mf_result (hr)) if (!gst_mf_result (hr))
goto done; goto done;
@ -663,11 +665,10 @@ gst_mf_dump_attribute_value_by_index (IMFAttributes * attr, const gchar * msg,
goto done; goto done;
gst_debug_log (cat, level, file, function, line, gst_debug_log (cat, level, file, function, line,
NULL, "%s attribute %d, %s: %s", msg ? msg : "", index, guid_name, NULL, "%s attribute %d, %s: %s", msg ? msg : "", index, guid_name, value);
value);
done: done:
PropVariantClear(&var); PropVariantClear (&var);
g_free (guid_name); g_free (guid_name);
g_free (value); g_free (value);
} }
@ -693,4 +694,4 @@ _gst_mf_dump_attributes (IMFAttributes * attr, const gchar * msg,
msg, i, level, cat, file, function, line); msg, i, level, cat, file, function, line);
} }
#endif #endif
} }

View file

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

View file

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

View file

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

View file

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