Skip to content

Commit

Permalink
refactor: rename sample_grabber_callback to media_grabber_callback
Browse files Browse the repository at this point in the history
This commit renames the file and class `sample_grabber_callback` to `media_grabber_callback`. The changes include renaming the header file, updating include statements, and changing class names throughout the codebase. This change improves clarity and consistency in naming conventions.
  • Loading branch information
fire committed Jul 4, 2023
1 parent c234917 commit e9a75a3
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 82 deletions.
Original file line number Diff line number Diff line change
@@ -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 <Shlwapi.h>
Expand All @@ -16,40 +16,40 @@
} \
}

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;
}
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"

Check failure on line 37 in modules/wmf/media_grabber_callback.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

the following warning is treated as an error

Check warning on line 37 in modules/wmf/media_grabber_callback.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

unknown pragma 'clang'

Check failure on line 37 in modules/wmf/media_grabber_callback.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release)

the following warning is treated as an error

Check warning on line 37 in modules/wmf/media_grabber_callback.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release)

unknown pragma 'clang'
QITABENT(SampleGrabberCallback, IMFSampleGrabberSinkCallback),
QITABENT(MediaGrabberCallback, IMFSampleGrabberSinkCallback),
#pragma clang diagnostic ignored "-Wc++11-narrowing"

Check warning on line 39 in modules/wmf/media_grabber_callback.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Editor (target=editor, tests=yes)

unknown pragma 'clang'

Check warning on line 39 in modules/wmf/media_grabber_callback.cpp

View workflow job for this annotation

GitHub Actions / 🏁 Windows / Template (target=template_release)

unknown pragma 'clang'
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;
Expand All @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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);
Expand All @@ -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,
Expand All @@ -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; }
};
Expand Down
20 changes: 10 additions & 10 deletions modules/wmf/resource_importer_wmf_video.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> *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<String> *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<ImportOption> *r_options, int p_preset = 0) const;
virtual bool get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &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<ImportOption> *r_options, int p_preset = 0) const override;
virtual bool get_option_visibility(const String &p_path, const String &p_option, const HashMap<StringName, Variant> &p_options) const override;

virtual Error import(const String &p_source_file, const String &p_save_path, const HashMap<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = NULL, Variant *r_metadata = NULL);
virtual Error import(const String &p_source_file, const String &p_save_path, const HashMap<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files, Variant *r_metadata) override;

ResourceImporterWMFVideo();
};
Expand Down
46 changes: 13 additions & 33 deletions modules/wmf/video_stream_wmf.cpp
Original file line number Diff line number Diff line change
@@ -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 <mfapi.h>
#include <mferror.h>
#include <mfidl.h>
#include <thirdparty/misc/yuv2rgb.h>
#include <wmcodecdsp.h>

#define CHECK_HR(func) \
Expand Down Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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<ImageTexture>(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<ImageTexture>(memnew(ImageTexture));
cache_frames.resize(24);
}

VideoStreamPlaybackWMF::~VideoStreamPlaybackWMF() {
Expand Down
7 changes: 2 additions & 5 deletions modules/wmf/video_stream_wmf.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <deque>

class SampleGrabberCallback;
class MediaGrabberCallback;
struct IMFMediaSession;
struct IMFMediaSource;
struct IMFTopology;
Expand All @@ -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<FrameData> cache_frames;
int read_frame_idx = 0;
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit e9a75a3

Please sign in to comment.