From: Rémi Bernon rbernon@codeweavers.com
--- dlls/winegstreamer/Makefile.in | 1 + dlls/winegstreamer/gst_private.h | 2 +- dlls/winegstreamer/main.c | 63 ++++- dlls/winegstreamer/mfplat.c | 8 + dlls/winegstreamer/unix_private.h | 9 +- dlls/winegstreamer/unixlib.h | 37 ++- dlls/winegstreamer/video_decoder.c | 10 +- dlls/winegstreamer/wg_format.c | 2 +- dlls/winegstreamer/wg_media_type.c | 425 +++++++++++++++++++++++++++++ dlls/winegstreamer/wg_parser.c | 31 ++- dlls/winegstreamer/wg_transform.c | 33 +-- 11 files changed, 569 insertions(+), 52 deletions(-) create mode 100644 dlls/winegstreamer/wg_media_type.c
diff --git a/dlls/winegstreamer/Makefile.in b/dlls/winegstreamer/Makefile.in index e33aa6c4d18..bbce2848bac 100644 --- a/dlls/winegstreamer/Makefile.in +++ b/dlls/winegstreamer/Makefile.in @@ -22,6 +22,7 @@ SOURCES = \ video_processor.c \ wg_allocator.c \ wg_format.c \ + wg_media_type.c \ wg_muxer.c \ wg_parser.c \ wg_sample.c \ diff --git a/dlls/winegstreamer/gst_private.h b/dlls/winegstreamer/gst_private.h index ba9064bc467..6b1208af802 100644 --- a/dlls/winegstreamer/gst_private.h +++ b/dlls/winegstreamer/gst_private.h @@ -88,7 +88,7 @@ HRESULT wg_transform_create_mf(IMFMediaType *input_type, IMFMediaType *output_ty HRESULT wg_transform_create_quartz(const AM_MEDIA_TYPE *input_format, const AM_MEDIA_TYPE *output_format, const struct wg_transform_attrs *attrs, wg_transform_t *transform); void wg_transform_destroy(wg_transform_t transform); -bool wg_transform_get_output_format(wg_transform_t transform, struct wg_format *format); +HRESULT wg_transform_get_output_type(wg_transform_t transform, IMFMediaType **media_type); bool wg_transform_set_output_format(wg_transform_t transform, struct wg_format *format); bool wg_transform_get_status(wg_transform_t transform, bool *accepts_input); HRESULT wg_transform_drain(wg_transform_t transform); diff --git a/dlls/winegstreamer/main.c b/dlls/winegstreamer/main.c index 747479daf40..e9e8c955d2a 100644 --- a/dlls/winegstreamer/main.c +++ b/dlls/winegstreamer/main.c @@ -70,6 +70,41 @@ bool array_reserve(void **elements, size_t *capacity, size_t count, size_t size) return TRUE; }
+static HRESULT media_type_from_video_format(const MFVIDEOFORMAT *format, IMFMediaType **media_type) +{ + HRESULT hr; + + if (FAILED(hr = MFCreateVideoMediaType(format, (IMFVideoMediaType **)media_type)) || format->dwSize <= sizeof(*format)) + return hr; + + /* fixup MPEG video formats here, so we can consistently use MFVIDEOFORMAT internally */ + if (IsEqualGUID(&format->guidFormat, &MEDIASUBTYPE_MPEG1Payload) + || IsEqualGUID(&format->guidFormat, &MEDIASUBTYPE_MPEG1Packet) + || IsEqualGUID(&format->guidFormat, &MEDIASUBTYPE_MPEG2_VIDEO)) + { + struct mpeg_video_format *mpeg = (struct mpeg_video_format *)format; + IMFMediaType_SetBlob(*media_type, &MF_MT_MPEG_SEQUENCE_HEADER, mpeg->sequence_header, mpeg->sequence_header_count); + IMFMediaType_SetUINT32(*media_type, &MF_MT_MPEG_START_TIME_CODE, mpeg->start_time_code); + IMFMediaType_SetUINT32(*media_type, &MF_MT_MPEG2_PROFILE, mpeg->profile); + IMFMediaType_SetUINT32(*media_type, &MF_MT_MPEG2_LEVEL, mpeg->level); + IMFMediaType_SetUINT32(*media_type, &MF_MT_MPEG2_FLAGS, mpeg->flags); + IMFMediaType_DeleteItem(*media_type, &MF_MT_USER_DATA); + } + + return hr; +} + +static HRESULT wg_media_type_to_mf(const struct wg_media_type *wg_media_type, IMFMediaType **media_type) +{ + if (IsEqualGUID(&wg_media_type->major, &MFMediaType_Video)) + return media_type_from_video_format(wg_media_type->u.video, media_type); + if (IsEqualGUID(&wg_media_type->major, &MFMediaType_Audio)) + return MFCreateAudioMediaType(wg_media_type->u.audio, (IMFAudioMediaType **)media_type); + + FIXME("Unsupported major type %s\n", debugstr_guid(&wg_media_type->major)); + return E_NOTIMPL; +} + wg_parser_t wg_parser_create(bool output_compressed) { struct wg_parser_create_params params = @@ -448,17 +483,35 @@ bool wg_transform_get_status(wg_transform_t transform, bool *accepts_input) return true; }
-bool wg_transform_get_output_format(wg_transform_t transform, struct wg_format *format) +HRESULT wg_transform_get_output_type(wg_transform_t transform, IMFMediaType **media_type) { - struct wg_transform_get_output_format_params params = + struct wg_transform_get_output_type_params params = { .transform = transform, - .format = format, }; + NTSTATUS status; + HRESULT hr;
- TRACE("transform %#I64x, format %p.\n", transform, format); + TRACE("transform %#I64x, media_type %p.\n", transform, media_type);
- return !WINE_UNIX_CALL(unix_wg_transform_get_output_format, ¶ms); + if ((status = WINE_UNIX_CALL(unix_wg_transform_get_output_type, ¶ms)) + && status == STATUS_BUFFER_TOO_SMALL) + { + if (!(params.media_type.u.format = CoTaskMemAlloc(params.media_type.format_size))) + return ERROR_OUTOFMEMORY; + status = WINE_UNIX_CALL(unix_wg_transform_get_output_type, ¶ms); + } + + if (status) + { + CoTaskMemFree(params.media_type.u.format); + WARN("Failed to get output media type, status %#lx\n", status); + return HRESULT_FROM_NT(status); + } + + hr = wg_media_type_to_mf(¶ms.media_type, media_type); + CoTaskMemFree(params.media_type.u.format); + return hr; }
bool wg_transform_set_output_format(wg_transform_t transform, struct wg_format *format) diff --git a/dlls/winegstreamer/mfplat.c b/dlls/winegstreamer/mfplat.c index 5775e8552db..db72892f434 100644 --- a/dlls/winegstreamer/mfplat.c +++ b/dlls/winegstreamer/mfplat.c @@ -17,6 +17,14 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
+#include <stddef.h> +#include <stdarg.h> + +#include "ntstatus.h" +#define WIN32_NO_STATUS +#include "windef.h" +#include "winbase.h" + #include "gst_private.h"
#include "ks.h" diff --git a/dlls/winegstreamer/unix_private.h b/dlls/winegstreamer/unix_private.h index 6f01b3a5a69..6f23e5f987e 100644 --- a/dlls/winegstreamer/unix_private.h +++ b/dlls/winegstreamer/unix_private.h @@ -25,6 +25,7 @@
#include <stdbool.h> #include <gst/gst.h> +#include <gst/audio/audio.h>
/* unixlib.c */
@@ -51,12 +52,13 @@ extern bool push_event(GstPad *pad, GstEvent *event); extern void wg_format_from_caps(struct wg_format *format, const GstCaps *caps); extern bool wg_format_compare(const struct wg_format *a, const struct wg_format *b); extern GstCaps *wg_format_to_caps(const struct wg_format *format); +extern uint32_t wg_channel_mask_from_gst(const GstAudioInfo *info);
/* wg_transform.c */
extern NTSTATUS wg_transform_create(void *args); extern NTSTATUS wg_transform_destroy(void *args); -extern NTSTATUS wg_transform_get_output_format(void *args); +extern NTSTATUS wg_transform_get_output_type(void *args); extern NTSTATUS wg_transform_set_output_format(void *args); extern NTSTATUS wg_transform_push_data(void *args); extern NTSTATUS wg_transform_read_data(void *args); @@ -65,6 +67,11 @@ extern NTSTATUS wg_transform_drain(void *args); extern NTSTATUS wg_transform_flush(void *args); extern NTSTATUS wg_transform_notify_qos(void *args);
+/* wg_media_type.c */ + +extern NTSTATUS caps_to_media_type(GstCaps *caps, struct wg_media_type *media_type, + UINT32 video_plane_align); + /* wg_muxer.c */
extern NTSTATUS wg_muxer_create(void *args); diff --git a/dlls/winegstreamer/unixlib.h b/dlls/winegstreamer/unixlib.h index 153b6c91306..a5f693a09de 100644 --- a/dlls/winegstreamer/unixlib.h +++ b/dlls/winegstreamer/unixlib.h @@ -26,9 +26,40 @@ #include "winternl.h" #include "wtypes.h" #include "mmreg.h" +#include "vfw.h" +#include "dshow.h" +#include "dvdmedia.h" +#include "mfobjects.h"
#include "wine/unixlib.h"
+/* same as MPEG1VIDEOINFO / MPEG2VIDEOINFO but with MFVIDEOFORMAT */ +struct mpeg_video_format +{ + MFVIDEOFORMAT hdr; + UINT32 start_time_code; + UINT32 profile; + UINT32 level; + UINT32 flags; + UINT32 sequence_header_count; + UINT32 __pad; + BYTE sequence_header[]; +}; + +C_ASSERT(sizeof(struct mpeg_video_format) == offsetof(struct mpeg_video_format, sequence_header[0])); + +struct wg_media_type +{ + GUID major; + UINT32 format_size; + union + { + void *format; + WAVEFORMATEX *audio; + MFVIDEOFORMAT *video; + } u; +}; + typedef UINT32 wg_major_type; enum wg_major_type { @@ -328,10 +359,10 @@ struct wg_transform_read_data_params HRESULT result; };
-struct wg_transform_get_output_format_params +struct wg_transform_get_output_type_params { wg_transform_t transform; - struct wg_format *format; + struct wg_media_type media_type; };
struct wg_transform_set_output_format_params @@ -415,7 +446,7 @@ enum unix_funcs
unix_wg_transform_create, unix_wg_transform_destroy, - unix_wg_transform_get_output_format, + unix_wg_transform_get_output_type, unix_wg_transform_set_output_format,
unix_wg_transform_push_data, diff --git a/dlls/winegstreamer/video_decoder.c b/dlls/winegstreamer/video_decoder.c index 891d2d10e83..9c50743eac7 100644 --- a/dlls/winegstreamer/video_decoder.c +++ b/dlls/winegstreamer/video_decoder.c @@ -855,15 +855,15 @@ static HRESULT output_sample(struct video_decoder *decoder, IMFSample **out, IMF static HRESULT handle_stream_type_change(struct video_decoder *decoder) { UINT64 frame_size, frame_rate; - struct wg_format format; HRESULT hr;
if (decoder->stream_type) IMFMediaType_Release(decoder->stream_type); - if (!(wg_transform_get_output_format(decoder->wg_transform, &format))) - return E_FAIL; - if (!(decoder->stream_type = mf_media_type_from_wg_format(&format))) - return E_OUTOFMEMORY; + if (FAILED(hr = wg_transform_get_output_type(decoder->wg_transform, &decoder->stream_type))) + { + WARN("Failed to get transform output type, hr %#lx\n", hr); + return hr; + }
if (SUCCEEDED(IMFMediaType_GetUINT64(decoder->output_type, &MF_MT_FRAME_RATE, &frame_rate)) && FAILED(hr = IMFMediaType_SetUINT64(decoder->stream_type, &MF_MT_FRAME_RATE, frame_rate))) diff --git a/dlls/winegstreamer/wg_format.c b/dlls/winegstreamer/wg_format.c index ec239142339..dac618fd7f5 100644 --- a/dlls/winegstreamer/wg_format.c +++ b/dlls/winegstreamer/wg_format.c @@ -96,7 +96,7 @@ static uint32_t wg_channel_position_from_gst(GstAudioChannelPosition position) return 0; }
-static uint32_t wg_channel_mask_from_gst(const GstAudioInfo *info) +uint32_t wg_channel_mask_from_gst(const GstAudioInfo *info) { uint32_t mask = 0, position; unsigned int i; diff --git a/dlls/winegstreamer/wg_media_type.c b/dlls/winegstreamer/wg_media_type.c new file mode 100644 index 00000000000..29dd0356dd5 --- /dev/null +++ b/dlls/winegstreamer/wg_media_type.c @@ -0,0 +1,425 @@ +/* + * Copyright 2024 Rémi Bernon for CodeWeavers + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#if 0 +#pragma makedep unix +#endif + +#include "config.h" + +#include <stdarg.h> +#include <stddef.h> + +#include <gst/gst.h> +#include <gst/video/video.h> +#include <gst/audio/audio.h> + +#include "ntstatus.h" +#define WIN32_NO_STATUS +#include "winternl.h" +#include "windef.h" +#include "winbase.h" + +#include "initguid.h" +#include "d3d9types.h" +#include "mfapi.h" +#include "wmcodecdsp.h" + +#include "unix_private.h" +#include "wine/debug.h" + +static const GUID GUID_NULL; + +DEFINE_MEDIATYPE_GUID(MFAudioFormat_RAW_AAC,WAVE_FORMAT_RAW_AAC1); +DEFINE_MEDIATYPE_GUID(MFAudioFormat_MSAudio1,WAVE_FORMAT_MSAUDIO1); + +DEFINE_MEDIATYPE_GUID(MFVideoFormat_CVID,MAKEFOURCC('c','v','i','d')); +DEFINE_MEDIATYPE_GUID(MFVideoFormat_IV50,MAKEFOURCC('I','V','5','0')); +DEFINE_MEDIATYPE_GUID(MFVideoFormat_VC1S,MAKEFOURCC('V','C','1','S')); +DEFINE_MEDIATYPE_GUID(MFVideoFormat_ABGR32,D3DFMT_A8B8G8R8); + +static WORD wave_format_tag_from_gst_audio_format(GstAudioFormat audio_format) +{ + switch (audio_format) + { + case GST_AUDIO_FORMAT_U8: return WAVE_FORMAT_PCM; + case GST_AUDIO_FORMAT_S16LE: return WAVE_FORMAT_PCM; + case GST_AUDIO_FORMAT_S24LE: return WAVE_FORMAT_PCM; + case GST_AUDIO_FORMAT_S32LE: return WAVE_FORMAT_PCM; + case GST_AUDIO_FORMAT_F32LE: return WAVE_FORMAT_IEEE_FLOAT; + case GST_AUDIO_FORMAT_F64LE: return WAVE_FORMAT_IEEE_FLOAT; + default: return WAVE_FORMAT_EXTENSIBLE; + } +} + +static GUID subtype_from_gst_audio_format(GstAudioFormat audio_format) +{ + switch (audio_format) + { + case GST_AUDIO_FORMAT_U8: return MFAudioFormat_PCM; + case GST_AUDIO_FORMAT_S16LE: return MFAudioFormat_PCM; + case GST_AUDIO_FORMAT_S24LE: return MFAudioFormat_PCM; + case GST_AUDIO_FORMAT_S32LE: return MFAudioFormat_PCM; + case GST_AUDIO_FORMAT_F32LE: return MFAudioFormat_Float; + case GST_AUDIO_FORMAT_F64LE: return MFAudioFormat_Float; + default: return GUID_NULL; + } +} + +static void init_wave_format_ex_from_gst_caps(const GstCaps *caps, WORD format_tag, gint depth, + WAVEFORMATEX *format, UINT32 format_size) +{ + const GstStructure *structure = gst_caps_get_structure(caps, 0); + gint bitrate, channels, rate, block_align; + + memset(format, 0, format_size); + format->cbSize = format_size - sizeof(*format); + format->wFormatTag = format_tag; + format->wBitsPerSample = depth; + + if (gst_structure_get_int(structure, "channels", &channels)) + format->nChannels = channels; + if (gst_structure_get_int(structure, "rate", &rate)) + format->nSamplesPerSec = rate; + if (gst_structure_get_int(structure, "depth", &depth)) + format->wBitsPerSample = depth; + + format->nBlockAlign = format->wBitsPerSample * format->nChannels / 8; + format->nAvgBytesPerSec = format->nSamplesPerSec * format->nBlockAlign; + + if (gst_structure_get_int(structure, "block_align", &block_align)) + format->nBlockAlign = block_align; + if (gst_structure_get_int(structure, "bitrate", &bitrate)) + format->nAvgBytesPerSec = bitrate / 8; +} + +static GstBuffer *wg_caps_get_buffer(const GstCaps *caps, const char *name, UINT32 *buffer_size) +{ + const GstStructure *structure = gst_caps_get_structure(caps, 0); + const GValue *buffer_value; + + if ((buffer_value = gst_structure_get_value(structure, name))) + { + GstBuffer *buffer = gst_value_get_buffer(buffer_value); + *buffer_size = gst_buffer_get_size(buffer); + return buffer; + } + + *buffer_size = 0; + return NULL; +} + +static NTSTATUS wave_format_extensible_from_gst_caps(const GstCaps *caps, const GUID *subtype, UINT32 depth, + UINT64 channel_mask, WAVEFORMATEXTENSIBLE *format, UINT32 *format_size) +{ + UINT32 capacity = *format_size, codec_data_size; + GstBuffer *codec_data = wg_caps_get_buffer(caps, "codec_data", &codec_data_size); + + *format_size = sizeof(*format) + codec_data_size; + if (*format_size > capacity) + return STATUS_BUFFER_TOO_SMALL; + + init_wave_format_ex_from_gst_caps(caps, WAVE_FORMAT_EXTENSIBLE, depth, &format->Format, *format_size); + format->Samples.wValidBitsPerSample = 0; + format->dwChannelMask = channel_mask; + format->SubFormat = *subtype; + + if (codec_data) + gst_buffer_extract(codec_data, 0, format + 1, codec_data_size); + + return STATUS_SUCCESS; +} + +static NTSTATUS wave_format_ex_from_gst_caps(const GstCaps *caps, WORD format_tag, UINT32 depth, + UINT32 wave_format_size, WAVEFORMATEX *format, UINT32 *format_size) +{ + UINT32 capacity = *format_size, codec_data_size; + GstBuffer *codec_data = wg_caps_get_buffer(caps, "codec_data", &codec_data_size); + + *format_size = max(wave_format_size, sizeof(*format) + codec_data_size); + if (*format_size > capacity) + return STATUS_BUFFER_TOO_SMALL; + + init_wave_format_ex_from_gst_caps(caps, format_tag, depth, format, *format_size); + + if (codec_data) + gst_buffer_extract(codec_data, 0, format + 1, codec_data_size); + + return STATUS_SUCCESS; +} + +static NTSTATUS wave_format_from_gst_caps(const GstCaps *caps, void *format, UINT32 *format_size) +{ + const GstStructure *structure = gst_caps_get_structure(caps, 0); + GstAudioFormat audio_format = GST_AUDIO_FORMAT_ENCODED; + WORD format_tag = WAVE_FORMAT_EXTENSIBLE; + gint channels, depth = 0; + const gchar *str_value; + guint64 channel_mask; + + if ((str_value = gst_structure_get_string(structure, "format"))) + { + audio_format = gst_audio_format_from_string(str_value); + format_tag = wave_format_tag_from_gst_audio_format(audio_format); + depth = GST_AUDIO_FORMAT_INFO_DEPTH(gst_audio_format_get_info(audio_format)); + } + + if (!gst_structure_get_int(structure, "channels", &channels)) + channels = 1; + if (!gst_structure_get(structure, "channel-mask", GST_TYPE_BITMASK, &channel_mask, NULL)) + channel_mask = 0; + + if (format_tag == WAVE_FORMAT_EXTENSIBLE || channel_mask != 0) + { + GUID subtype = subtype_from_gst_audio_format(audio_format); + return wave_format_extensible_from_gst_caps(caps, &subtype, depth, channel_mask, format, format_size); + } + + return wave_format_ex_from_gst_caps(caps, format_tag, depth, sizeof(WAVEFORMATEX), format, format_size); +} + +static NTSTATUS mpeg_wave_format_from_gst_caps(const GstCaps *caps, void *format, UINT32 *format_size) +{ + const GstStructure *structure = gst_caps_get_structure(caps, 0); + NTSTATUS status; + gint layer; + + if (!gst_structure_get_int(structure, "layer", &layer)) + { + GST_WARNING("Missing "layer" value in %" GST_PTR_FORMAT ".", caps); + return STATUS_INVALID_PARAMETER; + } + + if (layer == 3) + return wave_format_ex_from_gst_caps(caps, WAVE_FORMAT_MPEGLAYER3, 0, sizeof(MPEGLAYER3WAVEFORMAT), format, format_size); + + if (!(status = wave_format_ex_from_gst_caps(caps, WAVE_FORMAT_MPEG, 0, sizeof(MPEG1WAVEFORMAT), format, format_size))) + { + MPEG1WAVEFORMAT *mpeg = format; + mpeg->fwHeadLayer = layer; + } + + return status; +} + +static NTSTATUS wma_wave_format_from_gst_caps(const GstCaps *caps, void *format, UINT32 *format_size) +{ + const GstStructure *structure = gst_caps_get_structure(caps, 0); + gint wmaversion; + + if (!gst_structure_get_int(structure, "wmaversion", &wmaversion)) + { + GST_WARNING("Missing "wmaversion" value in %" GST_PTR_FORMAT ".", caps); + return STATUS_INVALID_PARAMETER; + } + + if (wmaversion == 1) + return wave_format_ex_from_gst_caps(caps, WAVE_FORMAT_MSAUDIO1, 0, sizeof(MSAUDIO1WAVEFORMAT), format, format_size); + if (wmaversion == 2) + return wave_format_ex_from_gst_caps(caps, WAVE_FORMAT_WMAUDIO2, 0, sizeof(WMAUDIO2WAVEFORMAT), format, format_size); + if (wmaversion == 3) + return wave_format_ex_from_gst_caps(caps, WAVE_FORMAT_WMAUDIO3, 0, sizeof(WMAUDIO3WAVEFORMAT), format, format_size); + + GST_FIXME("Unsupported wmaversion %u\n", wmaversion); + return STATUS_NOT_IMPLEMENTED; +} + +static GUID subtype_from_gst_video_format(GstVideoFormat video_format) +{ + switch (video_format) + { + case GST_VIDEO_FORMAT_BGRA: return MFVideoFormat_ARGB32; + case GST_VIDEO_FORMAT_BGRx: return MFVideoFormat_RGB32; + case GST_VIDEO_FORMAT_BGR: return MFVideoFormat_RGB24; + case GST_VIDEO_FORMAT_RGBA: return MFVideoFormat_ABGR32; + case GST_VIDEO_FORMAT_RGB15: return MFVideoFormat_RGB555; + case GST_VIDEO_FORMAT_RGB16: return MFVideoFormat_RGB565; + case GST_VIDEO_FORMAT_AYUV: return MFVideoFormat_AYUV; + case GST_VIDEO_FORMAT_I420: return MFVideoFormat_I420; + case GST_VIDEO_FORMAT_NV12: return MFVideoFormat_NV12; + case GST_VIDEO_FORMAT_UYVY: return MFVideoFormat_UYVY; + case GST_VIDEO_FORMAT_YUY2: return MFVideoFormat_YUY2; + case GST_VIDEO_FORMAT_YV12: return MFVideoFormat_YV12; + case GST_VIDEO_FORMAT_YVYU: return MFVideoFormat_YVYU; + default: return GUID_NULL; + } +} + +static void init_mf_video_format_from_gst_caps(const GstCaps *caps, const GUID *subtype, + MFVIDEOFORMAT *format, UINT32 format_size, UINT32 video_plane_align) +{ + const GstStructure *structure = gst_caps_get_structure(caps, 0); + gint width = 0, height = 0, num_value, den_value; + const gchar *str_value; + + memset(format, 0, format_size); + format->dwSize = format_size; + + if (subtype) + format->guidFormat = *subtype; + else if ((str_value = gst_structure_get_string(structure, "format"))) + { + GstVideoFormat video_format = gst_video_format_from_string(str_value); + format->guidFormat = subtype_from_gst_video_format(video_format); + } + + if (gst_structure_get_int(structure, "width", &width)) + format->videoInfo.dwWidth = (width + video_plane_align) & ~video_plane_align; + if (gst_structure_get_int(structure, "height", &height)) + format->videoInfo.dwHeight = (height + video_plane_align) & ~video_plane_align; + if (format->videoInfo.dwWidth != width || format->videoInfo.dwHeight != height) + { + format->videoInfo.MinimumDisplayAperture.Area.cx = width; + format->videoInfo.MinimumDisplayAperture.Area.cy = height; + } + format->videoInfo.GeometricAperture = format->videoInfo.MinimumDisplayAperture; + format->videoInfo.PanScanAperture = format->videoInfo.MinimumDisplayAperture; + + if (gst_structure_get_fraction(structure, "pixel-aspect-ratio", &num_value, &den_value)) + { + format->videoInfo.PixelAspectRatio.Numerator = num_value; + format->videoInfo.PixelAspectRatio.Denominator = den_value; + } + if (gst_structure_get_fraction(structure, "framerate", &num_value, &den_value)) + { + format->videoInfo.FramesPerSecond.Numerator = num_value; + format->videoInfo.FramesPerSecond.Denominator = den_value; + } +} + +static NTSTATUS video_format_from_gst_caps(const GstCaps *caps, const GUID *subtype, + MFVIDEOFORMAT *format, UINT32 *format_size, UINT32 video_plane_align) +{ + UINT32 capacity = *format_size, codec_data_size; + GstBuffer *codec_data = wg_caps_get_buffer(caps, "codec_data", &codec_data_size); + + *format_size = sizeof(*format) + codec_data_size; + if (*format_size > capacity) + return STATUS_BUFFER_TOO_SMALL; + + init_mf_video_format_from_gst_caps(caps, subtype, format, *format_size, video_plane_align); + + if (codec_data) + gst_buffer_extract(codec_data, 0, format + 1, codec_data_size); + + return STATUS_SUCCESS; +} + +static NTSTATUS wmv_video_format_from_gst_caps(const GstCaps *caps, MFVIDEOFORMAT *format, + UINT32 *format_size, UINT32 video_plane_align) +{ + const GstStructure *structure = gst_caps_get_structure(caps, 0); + gchar format_buffer[5] = {'W','M','V','0',0}; + const gchar *wmv_format_str; + gint wmv_version = 0; + const GUID *subtype; + + if (!(wmv_format_str = gst_structure_get_string(structure, "format"))) + { + if (!gst_structure_get_int(structure, "wmvversion", &wmv_version)) + GST_WARNING("Unable to get WMV format."); + format_buffer[3] += wmv_version; + wmv_format_str = format_buffer; + } + + if (!strcmp(wmv_format_str, "WMV1")) + subtype = &MFVideoFormat_WMV1; + else if (!strcmp(wmv_format_str, "WMV2")) + subtype = &MFVideoFormat_WMV2; + else if (!strcmp(wmv_format_str, "WMV3")) + subtype = &MFVideoFormat_WMV3; + else if (!strcmp(wmv_format_str, "WMVA")) + subtype = &MEDIASUBTYPE_WMVA; + else if (!strcmp(wmv_format_str, "WVC1")) + subtype = &MFVideoFormat_WVC1; + else + { + GST_WARNING("Unknown "wmvversion" value."); + return STATUS_INVALID_PARAMETER; + } + + return video_format_from_gst_caps(caps, subtype, format, format_size, video_plane_align); +} + +static NTSTATUS mpeg_video_format_from_gst_caps(const GstCaps *caps, + struct mpeg_video_format *format, UINT32 *format_size, UINT32 video_plane_align) +{ + UINT32 capacity = *format_size, codec_data_size; + GstBuffer *codec_data = wg_caps_get_buffer(caps, "codec_data", &codec_data_size); + + *format_size = sizeof(*format) + codec_data_size; + if (*format_size > capacity) + return STATUS_BUFFER_TOO_SMALL; + + init_mf_video_format_from_gst_caps(caps, &MEDIASUBTYPE_MPEG1Payload, &format->hdr, *format_size, video_plane_align); + + if (codec_data) + { + gst_buffer_extract(codec_data, 0, format->sequence_header, codec_data_size); + format->sequence_header_count = codec_data_size; + } + + return STATUS_SUCCESS; +} + +NTSTATUS caps_to_media_type(GstCaps *caps, struct wg_media_type *media_type, UINT32 video_plane_align) +{ + const GstStructure *structure = gst_caps_get_structure(caps, 0); + const char *name = gst_structure_get_name(structure); + gboolean parsed; + + GST_ERROR("caps %"GST_PTR_FORMAT, caps); + + if (g_str_has_prefix(name, "audio/")) + { + media_type->major = MFMediaType_Audio; + + if (!strcmp(name, "audio/x-raw")) + return wave_format_from_gst_caps(caps, media_type->u.audio, &media_type->format_size); + if (!strcmp(name, "audio/mpeg") && gst_structure_get_boolean(structure, "parsed", &parsed) && parsed) + return mpeg_wave_format_from_gst_caps(caps, media_type->u.audio, &media_type->format_size); + if (!strcmp(name, "audio/x-wma")) + return wma_wave_format_from_gst_caps(caps, media_type->u.audio, &media_type->format_size); + + GST_FIXME("Unhandled caps %" GST_PTR_FORMAT ".", caps); + return STATUS_UNSUCCESSFUL; + } + else if (g_str_has_prefix(name, "video/")) + { + media_type->major = MFMediaType_Video; + + if (!strcmp(name, "video/x-raw")) + return video_format_from_gst_caps(caps, NULL, media_type->u.video, &media_type->format_size, video_plane_align); + if (!strcmp(name, "video/x-cinepak")) + return video_format_from_gst_caps(caps, &MFVideoFormat_CVID, media_type->u.video, &media_type->format_size, video_plane_align); + if (!strcmp(name, "video/x-wmv")) + return wmv_video_format_from_gst_caps(caps, media_type->u.video, &media_type->format_size, video_plane_align); + if (!strcmp(name, "video/mpeg") && gst_structure_get_boolean(structure, "parsed", &parsed) && parsed) + return mpeg_video_format_from_gst_caps(caps, media_type->u.format, &media_type->format_size, video_plane_align); + + GST_FIXME("Unhandled caps %" GST_PTR_FORMAT ".", caps); + return STATUS_UNSUCCESSFUL; + } + else + { + GST_FIXME("Unhandled caps %" GST_PTR_FORMAT ".", caps); + return STATUS_UNSUCCESSFUL; + } + + return STATUS_SUCCESS; +} diff --git a/dlls/winegstreamer/wg_parser.c b/dlls/winegstreamer/wg_parser.c index f9b76b12f8f..b9c33e60f0b 100644 --- a/dlls/winegstreamer/wg_parser.c +++ b/dlls/winegstreamer/wg_parser.c @@ -1889,7 +1889,7 @@ const unixlib_entry_t __wine_unix_call_funcs[] =
X(wg_transform_create), X(wg_transform_destroy), - X(wg_transform_get_output_format), + X(wg_transform_get_output_type), X(wg_transform_set_output_format),
X(wg_transform_push_data), @@ -1914,6 +1914,13 @@ C_ASSERT(ARRAYSIZE(__wine_unix_call_funcs) == unix_wg_funcs_count);
typedef ULONG PTR32;
+struct wg_media_type32 +{ + GUID major; + UINT32 format_size; + PTR32 format; +}; + static NTSTATUS wow64_wg_parser_connect(void *args) { struct @@ -2075,19 +2082,29 @@ NTSTATUS wow64_wg_transform_create(void *args) return ret; }
-NTSTATUS wow64_wg_transform_get_output_format(void *args) +NTSTATUS wow64_wg_transform_get_output_type(void *args) { struct { wg_transform_t transform; - PTR32 format; + struct wg_media_type32 media_type; } *params32 = args; - struct wg_transform_get_output_format_params params = + struct wg_transform_get_output_type_params params = { .transform = params32->transform, - .format = ULongToPtr(params32->format), + .media_type = + { + .major = params32->media_type.major, + .format_size = params32->media_type.format_size, + .u.format = ULongToPtr(params32->media_type.format), + }, }; - return wg_transform_get_output_format(¶ms); + NTSTATUS status; + + status = wg_transform_get_output_type(¶ms); + params32->media_type.major = params.media_type.major; + params32->media_type.format_size = params.media_type.format_size; + return status; }
NTSTATUS wow64_wg_transform_set_output_format(void *args) @@ -2254,7 +2271,7 @@ const unixlib_entry_t __wine_unix_call_wow64_funcs[] =
X64(wg_transform_create), X(wg_transform_destroy), - X64(wg_transform_get_output_format), + X64(wg_transform_get_output_type), X64(wg_transform_set_output_format),
X64(wg_transform_push_data), diff --git a/dlls/winegstreamer/wg_transform.c b/dlls/winegstreamer/wg_transform.c index 08c2c678024..4f678573e83 100644 --- a/dlls/winegstreamer/wg_transform.c +++ b/dlls/winegstreamer/wg_transform.c @@ -36,6 +36,7 @@ #define WIN32_NO_STATUS #include "winternl.h" #include "mferror.h" +#include "mfapi.h"
#include "unix_private.h"
@@ -616,12 +617,10 @@ out: return status; }
-NTSTATUS wg_transform_get_output_format(void *args) +NTSTATUS wg_transform_get_output_type(void *args) { - struct wg_transform_get_output_format_params *params = args; + struct wg_transform_get_output_type_params *params = args; struct wg_transform *transform = get_transform(params->transform); - struct wg_format *format = params->format; - GstVideoInfo video_info; GstCaps *output_caps;
if (transform->output_sample) @@ -631,31 +630,7 @@ NTSTATUS wg_transform_get_output_format(void *args)
GST_INFO("transform %p output caps %"GST_PTR_FORMAT, transform, output_caps);
- wg_format_from_caps(format, output_caps); - - if (stream_type_from_caps(output_caps) == GST_STREAM_TYPE_VIDEO - && gst_video_info_from_caps(&video_info, output_caps)) - { - gsize plane_align = transform->attrs.output_plane_align; - GstVideoAlignment align = {0}; - - /* set the desired output buffer alignment on the dest video info */ - align_video_info_planes(plane_align, &video_info, &align); - - GST_INFO("Returning video alignment left %u, top %u, right %u, bottom %u.", align.padding_left, - align.padding_top, align.padding_right, align.padding_bottom); - - format->u.video.padding.left = align.padding_left; - format->u.video.width += format->u.video.padding.left; - format->u.video.padding.right = align.padding_right; - format->u.video.width += format->u.video.padding.right; - format->u.video.padding.top = align.padding_top; - format->u.video.height += format->u.video.padding.top; - format->u.video.padding.bottom = align.padding_bottom; - format->u.video.height += format->u.video.padding.bottom; - } - - return STATUS_SUCCESS; + return caps_to_media_type(output_caps, ¶ms->media_type, transform->attrs.output_plane_align); }
NTSTATUS wg_transform_set_output_format(void *args)