]> git.sesse.net Git - vlc/blobdiff - modules/codec/mft.c
fix teletext framing code in DVB PES packets ignored
[vlc] / modules / codec / mft.c
index 143a3085d10cd099c8884bc2bb0db49361257d02..22e647fd885a511acb5ef635713493f737a6a292 100644 (file)
@@ -37,6 +37,8 @@
 # define STDCALL __stdcall
 #endif
 
+#include <assert.h>
+
 #include <vlc_common.h>
 #include <vlc_plugin.h>
 #include <vlc_codec.h>
@@ -64,13 +66,13 @@ vlc_module_end()
 typedef struct
 {
     HINSTANCE mfplat_dll;
-    HRESULT (STDCALL *MFTEnumEx)(GUID guidCategory, UINT32 Flags,
+    HRESULT (STDCALL *fptr_MFTEnumEx)(GUID guidCategory, UINT32 Flags,
                                  const MFT_REGISTER_TYPE_INFO *pInputType,
                                  const MFT_REGISTER_TYPE_INFO *pOutputType,
                                  IMFActivate ***pppMFTActivate, UINT32 *pcMFTActivate);
-    HRESULT (STDCALL *MFCreateSample)(IMFSample **ppIMFSample);
-    HRESULT (STDCALL *MFCreateMemoryBuffer)(DWORD cbMaxLength, IMFMediaBuffer **ppBuffer);
-    HRESULT (STDCALL *MFCreateAlignedMemoryBuffer)(DWORD cbMaxLength, DWORD fAlignmentFlags, IMFMediaBuffer **ppBuffer);
+    HRESULT (STDCALL *fptr_MFCreateSample)(IMFSample **ppIMFSample);
+    HRESULT (STDCALL *fptr_MFCreateMemoryBuffer)(DWORD cbMaxLength, IMFMediaBuffer **ppBuffer);
+    HRESULT (STDCALL *fptr_MFCreateAlignedMemoryBuffer)(DWORD cbMaxLength, DWORD fAlignmentFlags, IMFMediaBuffer **ppBuffer);
 } MFHandle;
 
 struct decoder_sys_t
@@ -172,7 +174,9 @@ static const pair_format_guid video_format_table[] =
     { 0, NULL }
 };
 
+#if defined(__MINGW64_VERSION_MAJOR) && __MINGW64_VERSION_MAJOR < 4
 DEFINE_GUID(MFAudioFormat_Dolby_AC3, 0xe06d802c, 0xdb46, 0x11cf, 0xb4, 0xd1, 0x00, 0x80, 0x5f, 0x6c, 0xbb, 0xea);
+#endif
 /*
  * We cannot use the FOURCC code for audio either since the
  * WAVE_FORMAT value is used to create the GUID.
@@ -461,13 +465,13 @@ static int AllocateInputSample(decoder_t *p_dec, DWORD stream_id, IMFSample** re
     if (FAILED(hr))
         goto error;
 
-    hr = mf->MFCreateSample(&input_sample);
+    hr = mf->fptr_MFCreateSample(&input_sample);
     if (FAILED(hr))
         goto error;
 
     IMFMediaBuffer *input_media_buffer = NULL;
     DWORD allocation_size = __MAX(input_info.cbSize, size);
-    hr = mf->MFCreateMemoryBuffer(allocation_size, &input_media_buffer);
+    hr = mf->fptr_MFCreateMemoryBuffer(allocation_size, &input_media_buffer);
     if (FAILED(hr))
         goto error;
 
@@ -518,7 +522,7 @@ static int AllocateOutputSample(decoder_t *p_dec, DWORD stream_id, IMFSample **r
     if ((output_info.dwFlags & expected_flags) != expected_flags)
         goto error;
 
-    hr = mf->MFCreateSample(&output_sample);
+    hr = mf->fptr_MFCreateSample(&output_sample);
     if (FAILED(hr))
         goto error;
 
@@ -526,9 +530,9 @@ static int AllocateOutputSample(decoder_t *p_dec, DWORD stream_id, IMFSample **r
     DWORD allocation_size = output_info.cbSize;
     DWORD alignment = output_info.cbAlignment;
     if (alignment > 0)
-        hr = mf->MFCreateAlignedMemoryBuffer(allocation_size, alignment - 1, &output_media_buffer);
+        hr = mf->fptr_MFCreateAlignedMemoryBuffer(allocation_size, alignment - 1, &output_media_buffer);
     else
-        hr = mf->MFCreateMemoryBuffer(allocation_size, &output_media_buffer);
+        hr = mf->fptr_MFCreateMemoryBuffer(allocation_size, &output_media_buffer);
     if (FAILED(hr))
         goto error;
 
@@ -557,7 +561,7 @@ static int ProcessInputStream(decoder_t *p_dec, DWORD stream_id, block_t *p_bloc
         goto error;
 
     IMFMediaBuffer *input_media_buffer = NULL;
-    hr = IMFSample_GetBufferByIndex(input_sample, stream_id, &input_media_buffer);
+    hr = IMFSample_GetBufferByIndex(input_sample, 0, &input_media_buffer);
     if (FAILED(hr))
         goto error;
 
@@ -1060,7 +1064,7 @@ static int FindMFT(decoder_t *p_dec)
     MFT_REGISTER_TYPE_INFO input_type = { *p_sys->major_type, *p_sys->subtype };
     IMFActivate **activate_objects = NULL;
     UINT32 activate_objects_count = 0;
-    hr = mf->MFTEnumEx(category, flags, &input_type, NULL, &activate_objects, &activate_objects_count);
+    hr = mf->fptr_MFTEnumEx(category, flags, &input_type, NULL, &activate_objects, &activate_objects_count);
     if (FAILED(hr))
         return VLC_EGENERIC;
 
@@ -1088,16 +1092,23 @@ static int FindMFT(decoder_t *p_dec)
 
 static int LoadMFTLibrary(MFHandle *mf)
 {
+#if _WIN32_WINNT < 0x601
     mf->mfplat_dll = LoadLibrary(TEXT("mfplat.dll"));
     if (!mf->mfplat_dll)
         return VLC_EGENERIC;
 
-    mf->MFTEnumEx = (void*)GetProcAddress(mf->mfplat_dll, "MFTEnumEx");
-    mf->MFCreateSample = (void*)GetProcAddress(mf->mfplat_dll, "MFCreateSample");
-    mf->MFCreateMemoryBuffer = (void*)GetProcAddress(mf->mfplat_dll, "MFCreateMemoryBuffer");
-    mf->MFCreateAlignedMemoryBuffer = (void*)GetProcAddress(mf->mfplat_dll, "MFCreateAlignedMemoryBuffer");
-    if (!mf->MFTEnumEx || !mf->MFCreateSample || !mf->MFCreateMemoryBuffer || !mf->MFCreateAlignedMemoryBuffer)
+    mf->fptr_MFTEnumEx = (void*)GetProcAddress(mf->mfplat_dll, "MFTEnumEx");
+    mf->fptr_MFCreateSample = (void*)GetProcAddress(mf->mfplat_dll, "MFCreateSample");
+    mf->fptr_MFCreateMemoryBuffer = (void*)GetProcAddress(mf->mfplat_dll, "MFCreateMemoryBuffer");
+    mf->fptr_MFCreateAlignedMemoryBuffer = (void*)GetProcAddress(mf->mfplat_dll, "MFCreateAlignedMemoryBuffer");
+    if (!mf->fptr_MFTEnumEx || !mf->fptr_MFCreateSample || !mf->fptr_MFCreateMemoryBuffer || !mf->fptr_MFCreateAlignedMemoryBuffer)
         return VLC_EGENERIC;
+#else
+    mf->fptr_MFTEnumEx = &MFTEnumEx;
+    mf->fptr_MFCreateSample = &MFCreateSample;
+    mf->fptr_MFCreateMemoryBuffer = &MFCreateMemoryBuffer;
+    mf->fptr_MFCreateAlignedMemoryBuffer = &MFCreateAlignedMemoryBuffer;
+#endif
 
     return VLC_SUCCESS;
 }
@@ -1114,7 +1125,8 @@ int Open(vlc_object_t *p_this)
     if (!p_sys)
         return VLC_ENOMEM;
 
-    CoInitializeEx(NULL, COINIT_MULTITHREADED);
+    if( FAILED(CoInitializeEx(NULL, COINIT_MULTITHREADED)) )
+        vlc_assert_unreachable();
 
     if (LoadMFTLibrary(&p_sys->mf_handle))
     {