@@ -435,55 +435,59 @@ void wg_parser_stream_seek(wg_parser_stream_t stream, double rate,
435
435
WINE_UNIX_CALL (unix_wg_parser_stream_seek , & params );
436
436
}
437
437
438
- wg_transform_t wg_transform_create ( const struct wg_format * input_format ,
439
- const struct wg_format * output_format , const struct wg_transform_attrs * attrs )
438
+ HRESULT wg_transform_create_mf ( IMFMediaType * input_type , IMFMediaType * output_type ,
439
+ const struct wg_transform_attrs * attrs , wg_transform_t * transform )
440
440
{
441
441
struct wg_transform_create_params params =
442
442
{
443
- .input_format = input_format ,
444
- .output_format = output_format ,
445
- .attrs = attrs ,
443
+ .attrs = * attrs ,
446
444
};
445
+ NTSTATUS status ;
446
+ HRESULT hr ;
447
447
448
- TRACE ("input_format %p, output_format %p.\n" , input_format , output_format );
449
-
450
- if (WINE_UNIX_CALL (unix_wg_transform_create , & params ))
451
- return 0 ;
448
+ TRACE ("input_type %p, output_type %p.\n" , input_type , output_type );
452
449
453
- TRACE ("Returning transform %#I64x.\n" , params .transform );
454
- return params .transform ;
455
- }
456
-
457
- HRESULT wg_transform_create_mf (IMFMediaType * input_type , IMFMediaType * output_type ,
458
- const struct wg_transform_attrs * attrs , wg_transform_t * transform )
459
- {
460
- struct wg_format input_format , output_format ;
450
+ if (FAILED (hr = wg_media_type_from_mf (input_type , & params .input_type )))
451
+ return hr ;
452
+ if (FAILED (hr = wg_media_type_from_mf (output_type , & params .output_type )))
453
+ {
454
+ CoTaskMemFree (params .input_type .u .format );
455
+ return hr ;
456
+ }
461
457
462
- mf_media_type_to_wg_format (input_type , & input_format );
463
- if (input_format .major_type == WG_MAJOR_TYPE_UNKNOWN )
464
- return MF_E_INVALIDMEDIATYPE ;
465
- mf_media_type_to_wg_format (output_type , & output_format );
466
- if (output_format .major_type == WG_MAJOR_TYPE_UNKNOWN )
467
- return MF_E_INVALIDMEDIATYPE ;
458
+ if ((status = WINE_UNIX_CALL (unix_wg_transform_create , & params )))
459
+ {
460
+ WARN ("Failed to create transform, status %#lx\n" , status );
461
+ hr = HRESULT_FROM_NT (status );
462
+ }
468
463
469
- if (!(* transform = wg_transform_create (& input_format , & output_format , attrs )))
470
- return E_FAIL ;
471
- return S_OK ;
464
+ CoTaskMemFree (params .output_type .u .format );
465
+ CoTaskMemFree (params .input_type .u .format );
466
+ * transform = params .transform ;
467
+ return hr ;
472
468
}
473
469
474
- HRESULT wg_transform_create_quartz (const AM_MEDIA_TYPE * input_type , const AM_MEDIA_TYPE * output_type ,
470
+ HRESULT wg_transform_create_quartz (const AM_MEDIA_TYPE * input_format , const AM_MEDIA_TYPE * output_format ,
475
471
const struct wg_transform_attrs * attrs , wg_transform_t * transform )
476
472
{
477
- struct wg_format input_format , output_format ;
473
+ IMFMediaType * input_type , * output_type ;
474
+ HRESULT hr ;
478
475
479
- if (!amt_to_wg_format (input_type , & input_format ))
480
- return E_FAIL ;
481
- if (!amt_to_wg_format (output_type , & output_format ))
482
- return E_FAIL ;
476
+ TRACE ("input_format %p, output_format %p.\n" , input_format , output_format );
483
477
484
- if (!(* transform = wg_transform_create (& input_format , & output_format , attrs )))
485
- return E_FAIL ;
486
- return S_OK ;
478
+ /* through IMFMediaType to normalize representation to MFVIDEOFORMAT / WAVEFORMATEX */
479
+ if (FAILED (hr = MFCreateMediaTypeFromRepresentation (AM_MEDIA_TYPE_REPRESENTATION , (void * )input_format , & input_type )))
480
+ return 0 ;
481
+ if (FAILED (hr = MFCreateMediaTypeFromRepresentation (AM_MEDIA_TYPE_REPRESENTATION , (void * )output_format , & output_type )))
482
+ {
483
+ IMFMediaType_Release (input_type );
484
+ return 0 ;
485
+ }
486
+
487
+ hr = wg_transform_create_mf (input_type , output_type , attrs , transform );
488
+ IMFMediaType_Release (output_type );
489
+ IMFMediaType_Release (input_type );
490
+ return hr ;
487
491
}
488
492
489
493
void wg_transform_destroy (wg_transform_t transform )
@@ -773,54 +777,61 @@ HRESULT wg_muxer_finalize(wg_muxer_t muxer)
773
777
return S_OK ;
774
778
}
775
779
776
- HRESULT check_audio_transform_support (const WAVEFORMATEX * input , const WAVEFORMATEX * output )
780
+ static HRESULT check_transform_support (const struct wg_media_type * input , const struct wg_media_type * output )
777
781
{
778
782
IMFMediaType * input_type , * output_type ;
779
783
struct wg_transform_attrs attrs = {0 };
780
784
wg_transform_t transform ;
781
785
HRESULT hr ;
782
786
783
- if (FAILED (hr = MFCreateMediaType ( & input_type )))
787
+ if (FAILED (hr = wg_media_type_to_mf ( input , & input_type )))
784
788
return hr ;
785
- if (FAILED (hr = MFCreateMediaType ( & output_type )))
789
+ if (FAILED (hr = wg_media_type_to_mf ( output , & output_type )))
786
790
{
787
791
IMFMediaType_Release (input_type );
788
792
return hr ;
789
793
}
790
794
791
- if (SUCCEEDED (hr = MFInitMediaTypeFromWaveFormatEx (input_type , input , sizeof (* input ) + input -> cbSize ))
792
- && SUCCEEDED (hr = MFInitMediaTypeFromWaveFormatEx (output_type , output , sizeof (* output ) + output -> cbSize ))
793
- && SUCCEEDED (hr = wg_transform_create_mf (input_type , output_type , & attrs , & transform )))
795
+ if (SUCCEEDED (hr = wg_transform_create_mf (input_type , output_type , & attrs , & transform )))
794
796
wg_transform_destroy (transform );
795
797
796
798
IMFMediaType_Release (output_type );
797
799
IMFMediaType_Release (input_type );
798
800
return hr ;
799
801
}
800
802
801
- HRESULT check_video_transform_support (const MFVIDEOFORMAT * input , const MFVIDEOFORMAT * output )
803
+ HRESULT check_audio_transform_support (const WAVEFORMATEX * input , const WAVEFORMATEX * output )
802
804
{
803
- IMFMediaType * input_type , * output_type ;
804
- struct wg_transform_attrs attrs = {0 };
805
- wg_transform_t transform ;
806
- HRESULT hr ;
807
-
808
- if (FAILED (hr = MFCreateMediaType (& input_type )))
809
- return hr ;
810
- if (FAILED (hr = MFCreateMediaType (& output_type )))
805
+ const struct wg_media_type input_type =
811
806
{
812
- IMFMediaType_Release (input_type );
813
- return hr ;
814
- }
815
-
816
- if (SUCCEEDED (hr = MFInitMediaTypeFromMFVideoFormat (input_type , input , input -> dwSize ))
817
- && SUCCEEDED (hr = MFInitMediaTypeFromMFVideoFormat (output_type , output , output -> dwSize ))
818
- && SUCCEEDED (hr = wg_transform_create_mf (input_type , output_type , & attrs , & transform )))
819
- wg_transform_destroy (transform );
807
+ .major = MFMediaType_Audio ,
808
+ .format_size = sizeof (* input ) + input -> cbSize ,
809
+ .u .audio = (WAVEFORMATEX * )input ,
810
+ };
811
+ const struct wg_media_type output_type =
812
+ {
813
+ .major = MFMediaType_Audio ,
814
+ .format_size = sizeof (* output ) + output -> cbSize ,
815
+ .u .audio = (WAVEFORMATEX * )output ,
816
+ };
817
+ return check_transform_support (& input_type , & output_type );
818
+ }
820
819
821
- IMFMediaType_Release (output_type );
822
- IMFMediaType_Release (input_type );
823
- return hr ;
820
+ HRESULT check_video_transform_support (const MFVIDEOFORMAT * input , const MFVIDEOFORMAT * output )
821
+ {
822
+ const struct wg_media_type input_type =
823
+ {
824
+ .major = MFMediaType_Video ,
825
+ .format_size = input -> dwSize ,
826
+ .u .video = (MFVIDEOFORMAT * )input ,
827
+ };
828
+ const struct wg_media_type output_type =
829
+ {
830
+ .major = MFMediaType_Video ,
831
+ .format_size = output -> dwSize ,
832
+ .u .video = (MFVIDEOFORMAT * )output ,
833
+ };
834
+ return check_transform_support (& input_type , & output_type );
824
835
}
825
836
826
837
#define ALIGN (n , alignment ) (((n) + (alignment) - 1) & ~((alignment) - 1))
0 commit comments