Skip to content

Commit 8f4993d

Browse files
authored
Set width and height immediately if loading sync (#7675)
#changelog #video
1 parent 04bd781 commit 8f4993d

2 files changed

Lines changed: 27 additions & 7 deletions

File tree

libs/openFrameworks/video/ofMediaFoundationPlayer.cpp

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,9 @@ bool SharedDXGLTexture::isLocked() {
335335
//----------------------------------------------
336336
bool SharedDXGLTexture::draw(ofPixels& apix) {
337337
if (lock()) {
338-
mOfTex->draw(0, 0);
338+
if (mOfTex->isAllocated()) {
339+
mOfTex->draw(0, 0);
340+
}
339341
unlock();
340342
return true;
341343
}
@@ -825,8 +827,11 @@ bool ofMediaFoundationPlayer::isInitialized() const {
825827

826828
//----------------------------------------------
827829
void ofMediaFoundationPlayer::OnMediaEngineEvent(DWORD aEvent, DWORD_PTR param1, DWORD param2) {
830+
828831
if (aEvent == MF_MEDIA_ENGINE_EVENT_LOADEDMETADATA) {
829832
if (!mBLoadAsync) {
833+
updateDuration();
834+
updateDimensions();
830835
mBIsDoneAtomic.store(true);
831836
mWaitCondition.notify_one();
832837
}
@@ -1218,12 +1223,13 @@ void ofMediaFoundationPlayer::handleMEEvent(DWORD aevent) {
12181223
}
12191224
}
12201225
mBDone = false;
1221-
mWidth = 0.f;
1222-
mHeight = 0.f;
1223-
DWORD w, h;
1224-
if (SUCCEEDED(m_spMediaEngine->GetNativeVideoSize(&w, &h))) {
1225-
mWidth = w;
1226-
mHeight = h;
1226+
//mWidth = 0.f;
1227+
//mHeight = 0.f;
1228+
//DWORD w, h;
1229+
//if (SUCCEEDED(m_spMediaEngine->GetNativeVideoSize(&w, &h))) {
1230+
//mWidth = w;
1231+
//mHeight = h;
1232+
if(updateDimensions()) {
12271233

12281234
if (mMeTexture) {
12291235
if (mMeTexture->getWidth() != mWidth || mMeTexture->getHeight() != mHeight) {
@@ -1384,3 +1390,16 @@ void ofMediaFoundationPlayer::updateDuration() {
13841390
}
13851391
}
13861392

1393+
//-----------------------------------------
1394+
bool ofMediaFoundationPlayer::updateDimensions() {
1395+
mWidth = 0.f;
1396+
mHeight = 0.f;
1397+
DWORD w, h;
1398+
if (SUCCEEDED(m_spMediaEngine->GetNativeVideoSize(&w, &h))) {
1399+
mWidth = w;
1400+
mHeight = h;
1401+
return true;
1402+
}
1403+
return false;
1404+
}
1405+

libs/openFrameworks/video/ofMediaFoundationPlayer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ class ofMediaFoundationPlayer : public ofBaseVideoPlayer, public of::MediaEngine
189189

190190
void handleMEEvent(DWORD aevent);
191191
void updateDuration();
192+
bool updateDimensions();
192193

193194
std::shared_ptr<METexture> mMeTexture;
194195

0 commit comments

Comments
 (0)