diff --git a/modules/wmf/sample_grabber_callback.cpp b/modules/wmf/media_grabber_callback.cpp similarity index 74% rename from modules/wmf/sample_grabber_callback.cpp rename to modules/wmf/media_grabber_callback.cpp index ec68d63223ce..b1f2d9bed767 100644 --- a/modules/wmf/sample_grabber_callback.cpp +++ b/modules/wmf/media_grabber_callback.cpp @@ -1,4 +1,4 @@ -#include "sample_grabber_callback.h" +#include "media_grabber_callback.h" #include "core/string/print_string.h" #include "video_stream_wmf.h" #include @@ -16,12 +16,12 @@ } \ } -SampleGrabberCallback::SampleGrabberCallback(VideoStreamPlaybackWMF *playback, Mutex &mtx) : - m_cRef(1), playback(playback), mtx(mtx) { +MediaGrabberCallback::MediaGrabberCallback(VideoStreamPlaybackWMF *p_playback) : + m_cRef(1), playback(p_playback) { } -HRESULT SampleGrabberCallback::CreateInstance(SampleGrabberCallback **ppCB, VideoStreamPlaybackWMF *playback, Mutex &mtx) { - *ppCB = new (std::nothrow) SampleGrabberCallback(playback, mtx); +HRESULT MediaGrabberCallback::CreateInstance(MediaGrabberCallback **ppCB, VideoStreamPlaybackWMF *p_playback) { + *ppCB = new (std::nothrow) MediaGrabberCallback(p_playback); if (ppCB == nullptr) { return E_OUTOFMEMORY; @@ -29,27 +29,27 @@ HRESULT SampleGrabberCallback::CreateInstance(SampleGrabberCallback **ppCB, Vide return S_OK; } -SampleGrabberCallback::~SampleGrabberCallback() { +MediaGrabberCallback::~MediaGrabberCallback() { } -STDMETHODIMP SampleGrabberCallback::QueryInterface(REFIID riid, void **ppv) { +STDMETHODIMP MediaGrabberCallback::QueryInterface(REFIID riid, void **ppv) { static const QITAB qit[] = { #pragma clang diagnostic ignored "-Wc++11-narrowing" - QITABENT(SampleGrabberCallback, IMFSampleGrabberSinkCallback), + QITABENT(MediaGrabberCallback, IMFSampleGrabberSinkCallback), #pragma clang diagnostic ignored "-Wc++11-narrowing" - QITABENT(SampleGrabberCallback, IMFClockStateSink), + QITABENT(MediaGrabberCallback, IMFClockStateSink), { 0 } }; return QISearch(this, qit, riid, ppv); } STDMETHODIMP_(ULONG) -SampleGrabberCallback::AddRef() { +MediaGrabberCallback::AddRef() { return InterlockedIncrement(&m_cRef); } STDMETHODIMP_(ULONG) -SampleGrabberCallback::Release() { +MediaGrabberCallback::Release() { ULONG cRef = InterlockedDecrement(&m_cRef); if (cRef == 0) { delete this; @@ -62,33 +62,33 @@ SampleGrabberCallback::Release() { // In these example, the IMFClockStateSink methods do not perform any actions. // You can use these methods to track the state of the sample grabber sink. -STDMETHODIMP SampleGrabberCallback::OnClockStart(MFTIME hnsSystemTime, LONGLONG llClockStartOffset) { +STDMETHODIMP MediaGrabberCallback::OnClockStart(MFTIME hnsSystemTime, LONGLONG llClockStartOffset) { return S_OK; } -STDMETHODIMP SampleGrabberCallback::OnClockStop(MFTIME hnsSystemTime) { +STDMETHODIMP MediaGrabberCallback::OnClockStop(MFTIME hnsSystemTime) { return S_OK; } -STDMETHODIMP SampleGrabberCallback::OnClockPause(MFTIME hnsSystemTime) { +STDMETHODIMP MediaGrabberCallback::OnClockPause(MFTIME hnsSystemTime) { return S_OK; } -STDMETHODIMP SampleGrabberCallback::OnClockRestart(MFTIME hnsSystemTime) { +STDMETHODIMP MediaGrabberCallback::OnClockRestart(MFTIME hnsSystemTime) { return S_OK; } -STDMETHODIMP SampleGrabberCallback::OnClockSetRate(MFTIME hnsSystemTime, float flRate) { +STDMETHODIMP MediaGrabberCallback::OnClockSetRate(MFTIME hnsSystemTime, float flRate) { return S_OK; } // IMFSampleGrabberSink methods. -STDMETHODIMP SampleGrabberCallback::OnSetPresentationClock(IMFPresentationClock *pClock) { +STDMETHODIMP MediaGrabberCallback::OnSetPresentationClock(IMFPresentationClock *pClock) { return S_OK; } -HRESULT SampleGrabberCallback::CreateMediaSample(DWORD cbData, IMFSample **ppSample) { +HRESULT MediaGrabberCallback::CreateMediaSample(DWORD cbData, IMFSample **ppSample) { assert(ppSample); HRESULT hr = S_OK; @@ -106,7 +106,7 @@ HRESULT SampleGrabberCallback::CreateMediaSample(DWORD cbData, IMFSample **ppSam return hr; } -STDMETHODIMP SampleGrabberCallback::OnProcessSample(REFGUID guidMajorMediaType, +STDMETHODIMP MediaGrabberCallback::OnProcessSample(REFGUID guidMajorMediaType, DWORD dwSampleFlags, LONGLONG llSampleTime, LONGLONG llSampleDuration, @@ -193,12 +193,12 @@ STDMETHODIMP SampleGrabberCallback::OnProcessSample(REFGUID guidMajorMediaType, return S_OK; } -STDMETHODIMP SampleGrabberCallback::OnShutdown() { +STDMETHODIMP MediaGrabberCallback::OnShutdown() { print_line(__FUNCTION__); return S_OK; } -void SampleGrabberCallback::set_frame_size(int w, int h) { +void MediaGrabberCallback::set_frame_size(int w, int h) { width = w; height = h; } diff --git a/modules/wmf/sample_grabber_callback.h b/modules/wmf/media_grabber_callback.h similarity index 71% rename from modules/wmf/sample_grabber_callback.h rename to modules/wmf/media_grabber_callback.h index c325a9a5ab9d..a2b687a6e642 100644 --- a/modules/wmf/sample_grabber_callback.h +++ b/modules/wmf/media_grabber_callback.h @@ -1,5 +1,5 @@ -#ifndef SAMPLEGRABBERCALLBACK_H -#define SAMPLEGRABBERCALLBACK_H +#ifndef MediaGrabberCallback_H +#define MediaGrabberCallback_H #include "core/io/resource_loader.h" #include "core/os/mutex.h" @@ -8,22 +8,21 @@ class VideoStreamPlaybackWMF; -class SampleGrabberCallback : public IMFSampleGrabberSinkCallback { - long m_cRef; +class MediaGrabberCallback : public IMFSampleGrabberSinkCallback { + long m_cRef = 0; VideoStreamPlaybackWMF *playback; - Mutex &mtx; - int width; - int height; + int width = 0; + int height = 0; IMFTransform *m_pColorTransform = nullptr; IMFSample *m_pSample = nullptr; IMFSample *m_pOutSample = nullptr; - SampleGrabberCallback(VideoStreamPlaybackWMF *playback, Mutex &mtx); + MediaGrabberCallback(VideoStreamPlaybackWMF *playback); public: - static HRESULT CreateInstance(SampleGrabberCallback **ppCB, VideoStreamPlaybackWMF *playback, Mutex &mtx); - ~SampleGrabberCallback(); + static HRESULT CreateInstance(MediaGrabberCallback **ppCB, VideoStreamPlaybackWMF *playback); + virtual ~MediaGrabberCallback(); // IUnknown methods STDMETHODIMP QueryInterface(REFIID iid, void **ppv); @@ -32,14 +31,12 @@ class SampleGrabberCallback : public IMFSampleGrabberSinkCallback { STDMETHODIMP_(ULONG) Release(); - // IMFClockStateSink methods STDMETHODIMP OnClockStart(MFTIME hnsSystemTime, LONGLONG llClockStartOffset); STDMETHODIMP OnClockStop(MFTIME hnsSystemTime); STDMETHODIMP OnClockPause(MFTIME hnsSystemTime); STDMETHODIMP OnClockRestart(MFTIME hnsSystemTime); STDMETHODIMP OnClockSetRate(MFTIME hnsSystemTime, float flRate); - // IMFSampleGrabberSinkCallback methods STDMETHODIMP OnSetPresentationClock(IMFPresentationClock *pClock); STDMETHODIMP OnProcessSample(REFGUID guidMajorMediaType, DWORD dwSampleFlags, LONGLONG llSampleTime, LONGLONG llSampleDuration, const BYTE *pSampleBuffer, @@ -48,7 +45,6 @@ class SampleGrabberCallback : public IMFSampleGrabberSinkCallback { HRESULT CreateMediaSample(DWORD cbData, IMFSample **ppSample); - // custom methods void set_frame_size(int w, int h); void set_color_transform(IMFTransform *mft) { m_pColorTransform = mft; } }; diff --git a/modules/wmf/resource_importer_wmf_video.h b/modules/wmf/resource_importer_wmf_video.h index adcdcf091879..2c49c580bcd1 100644 --- a/modules/wmf/resource_importer_wmf_video.h +++ b/modules/wmf/resource_importer_wmf_video.h @@ -7,18 +7,18 @@ class ResourceImporterWMFVideo : public ResourceImporter { GDCLASS(ResourceImporterWMFVideo, ResourceImporter) public: - virtual String get_importer_name() const; - virtual String get_visible_name() const; - virtual void get_recognized_extensions(List *p_extensions) const; - virtual String get_save_extension() const; - virtual String get_resource_type() const; + virtual String get_importer_name() const override; + virtual String get_visible_name() const override; + virtual void get_recognized_extensions(List *p_extensions) const override; + virtual String get_save_extension() const override; + virtual String get_resource_type() const override; - virtual int get_preset_count() const; - virtual String get_preset_name(int p_idx) const; - virtual void get_import_options(const String &p_path, List *r_options, int p_preset = 0) const; - virtual bool get_option_visibility(const String &p_path, const String &p_option, const HashMap &p_options) const; + virtual int get_preset_count() const override; + virtual String get_preset_name(int p_idx) const override; + virtual void get_import_options(const String &p_path, List *r_options, int p_preset = 0) const override; + virtual bool get_option_visibility(const String &p_path, const String &p_option, const HashMap &p_options) const override; - virtual Error import(const String &p_source_file, const String &p_save_path, const HashMap &p_options, List *r_platform_variants, List *r_gen_files = NULL, Variant *r_metadata = NULL); + virtual Error import(const String &p_source_file, const String &p_save_path, const HashMap &p_options, List *r_platform_variants, List *r_gen_files, Variant *r_metadata) override; ResourceImporterWMFVideo(); }; diff --git a/modules/wmf/video_stream_wmf.cpp b/modules/wmf/video_stream_wmf.cpp index 57c9cdb73c47..842fc7986dbe 100644 --- a/modules/wmf/video_stream_wmf.cpp +++ b/modules/wmf/video_stream_wmf.cpp @@ -1,11 +1,10 @@ #include "video_stream_wmf.h" #include "core/io/file_access.h" -#include "sample_grabber_callback.h" +#include "media_grabber_callback.h" #include #include #include -#include #include #define CHECK_HR(func) \ @@ -71,12 +70,9 @@ HRESULT AddColourConversionNode(IMFTopology *pTopology, IMFMediaType *inputType, IMFTransform **ppColorTransform) { HRESULT hr = S_OK; - IMFTransform *colorTransform; CoCreateInstance(CLSID_CColorConvertDMO, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&colorTransform)); - IMFMediaType *pInType = nullptr; - UINT32 uWidth, uHeight; MFGetAttributeSize(inputType, MF_MT_FRAME_SIZE, &uWidth, &uHeight); UINT32 interlaceMode; @@ -86,23 +82,16 @@ HRESULT AddColourConversionNode(IMFTopology *pTopology, CHECK_HR(pInType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video)); CHECK_HR(pInType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_NV12)); CHECK_HR(MFSetAttributeSize(pInType, MF_MT_FRAME_SIZE, uWidth, uHeight)); - - HRESULT hr_in = (colorTransform->SetInputType(0, pInType, 0)); - IMFMediaType *pOutType = nullptr; CHECK_HR(MFCreateMediaType(&pOutType)); - hr = pOutType->SetGUID(MF_MT_MAJOR_TYPE, MFMediaType_Video); hr = pOutType->SetGUID(MF_MT_SUBTYPE, MFVideoFormat_RGB24); CHECK_HR(MFSetAttributeSize(pOutType, MF_MT_FRAME_SIZE, uWidth, uHeight)); - - HRESULT hr_out = (colorTransform->SetOutputType(0, pOutType, 0)); - *ppColorTransform = colorTransform; return hr; } -HRESULT CreateSampleGrabber(UINT width, UINT height, SampleGrabberCallback *pSampleGrabber, IMFActivate **pSinkActivate) { +HRESULT CreateSampleGrabber(UINT width, UINT height, MediaGrabberCallback *pSampleGrabber, IMFActivate **pSinkActivate) { HRESULT hr = S_OK; IMFMediaType *pType = NULL; @@ -119,14 +108,13 @@ HRESULT CreateSampleGrabber(UINT width, UINT height, SampleGrabberCallback *pSam return hr; } -HRESULT CreateTopology(IMFMediaSource *pSource, SampleGrabberCallback *pSampleGrabber, IMFTopology **ppTopo, VideoStreamPlaybackWMF::StreamInfo *info) { +HRESULT CreateTopology(IMFMediaSource *pSource, MediaGrabberCallback *pSampleGrabber, IMFTopology **ppTopo, VideoStreamPlaybackWMF::StreamInfo *info) { IMFTopology *pTopology = NULL; IMFPresentationDescriptor *pPD = NULL; IMFStreamDescriptor *pSD = NULL; IMFMediaTypeHandler *pHandler = NULL; IMFTopologyNode *inputNode = NULL; IMFTopologyNode *outputNode = NULL; - IMFTopologyNode *colorNode = NULL; IMFTopologyNode *inputNodeAudio = NULL; IMFTopologyNode *outputNodeAudio = NULL; IMFActivate *audioActivate = NULL; @@ -324,13 +312,6 @@ bool VideoStreamPlaybackWMF::is_paused() const { return !is_video_paused; } -void VideoStreamPlaybackWMF::set_loop(bool p_enabled) { -} - -bool VideoStreamPlaybackWMF::has_loop() const { - return false; -} - double VideoStreamPlaybackWMF::get_length() const { return stream_info.duration; } @@ -377,15 +358,13 @@ void VideoStreamPlaybackWMF::set_file(const String &p_file) { CHECK_HR(CreateMediaSource(p_file, &media_source)); CHECK_HR(MFCreateMediaSession(nullptr, &media_session)); - CHECK_HR(SampleGrabberCallback::CreateInstance(&sample_grabber_callback, this, mtx)); + CHECK_HR(MediaGrabberCallback::CreateInstance(&sample_grabber_callback, this)); CHECK_HR(CreateTopology(media_source, sample_grabber_callback, &topology, &stream_info)); CHECK_HR(media_session->SetTopology(0, topology)); if (SUCCEEDED(hr)) { - IMFRateControl *m_pRate; - HRESULT hrTmp = MFGetService(media_session, MF_RATE_CONTROL_SERVICE, IID_PPV_ARGS(&m_pRate)); - + IMFRateControl *m_pRate = nullptr; BOOL bThin = false; float fRate = 0.f; CHECK_HR(m_pRate->GetRate(&bThin, &fRate)); @@ -523,13 +502,14 @@ int64_t VideoStreamPlaybackWMF::next_sample_time() { static int counter = 0; VideoStreamPlaybackWMF::VideoStreamPlaybackWMF() : - media_session(NULL), media_source(NULL), topology(NULL), presentation_clock(NULL), is_video_playing(false), is_video_paused(false), is_video_seekable(false), read_frame_idx(0), write_frame_idx(0) { - id = counter; - counter++; - - texture = Ref(memnew(ImageTexture)); - // Make sure cache_frames.size() is something more than 0. - cache_frames.resize(24); + media_session(NULL), media_source(NULL), topology(NULL), presentation_clock(NULL), + read_frame_idx(0), write_frame_idx(0), is_video_playing(false), + is_video_paused(false), is_video_seekable(false) { + id = counter; + counter++; + + texture = Ref(memnew(ImageTexture)); + cache_frames.resize(24); } VideoStreamPlaybackWMF::~VideoStreamPlaybackWMF() { diff --git a/modules/wmf/video_stream_wmf.h b/modules/wmf/video_stream_wmf.h index 3fd18450d0b0..829c5e42c82c 100644 --- a/modules/wmf/video_stream_wmf.h +++ b/modules/wmf/video_stream_wmf.h @@ -7,7 +7,7 @@ #include -class SampleGrabberCallback; +class MediaGrabberCallback; struct IMFMediaSession; struct IMFMediaSource; struct IMFTopology; @@ -25,7 +25,7 @@ class VideoStreamPlaybackWMF : public VideoStreamPlayback { IMFMediaSource *media_source; IMFTopology *topology; IMFPresentationClock *presentation_clock; - SampleGrabberCallback *sample_grabber_callback; + MediaGrabberCallback *sample_grabber_callback; Vector cache_frames; int read_frame_idx = 0; @@ -63,9 +63,6 @@ class VideoStreamPlaybackWMF : public VideoStreamPlayback { virtual void set_paused(bool p_paused) override; virtual bool is_paused() const override; - virtual void set_loop(bool p_enable) override; - virtual bool has_loop() const override; - virtual double get_length() const override; virtual String get_stream_name() const;