Skip to content

Meson build system proof-of-concept #8137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions libs/openFrameworks/app/ofAppEGLWindow.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef __unix__

#include "ofAppEGLWindow.h"

#include "ofGraphics.h" // used in runAppViaInfiniteLoop()
Expand Down Expand Up @@ -28,6 +30,13 @@

#include <string.h> // strlen

using std::string;
using std::map;
using std::make_shared;
using std::shared_ptr;
using std::endl;
using std::queue;

// native events
struct udev* udev;
struct udev_monitor* mon;
Expand Down Expand Up @@ -412,7 +421,7 @@ void ofAppEGLWindow::setup(const ofAppEGLWindowSettings & _settings) {
// pDisplay = ofGetEnv("DISPLAY");
// bool bIsX11Available = (pDisplay != NULL);

bool bIsX11Available = ofGetEnv("DISPLAY") != NULL;
bool bIsX11Available = !ofGetEnv("DISPLAY").empty();

if(settings.eglWindowPreference == OF_APP_WINDOW_AUTO) {
if(bIsX11Available) {
Expand Down Expand Up @@ -1427,7 +1436,7 @@ void ofAppEGLWindow::setupNativeInput(){
tc.c_lflag &= ~ECHO;
tc.c_lflag |= ECHONL;
tcsetattr(STDIN_FILENO, TCSAFLUSH, &tc);

mb.mouseButtonState = 0;

kb.shiftPressed = false;
Expand Down Expand Up @@ -1495,7 +1504,7 @@ void ofAppEGLWindow::printInput(){

void ofAppEGLWindow::destroyNativeInput(){
ofLogNotice("ofAppEGLWindow") << "destroyNativeInput()";

for(device::iterator iter = inputDevices.begin(); iter != inputDevices.end(); iter++){
if(iter->second >= 0){
::close(iter->second);
Expand All @@ -1517,7 +1526,7 @@ void ofAppEGLWindow::processInput(int fd, const char * node){
static ofMouseEventArgs mouseEvent;
struct input_event ev;
char key = 0;

bool pushKeyEvent = false;
bool pushMouseEvent = false;
bool pushTouchEvent = false;
Expand Down Expand Up @@ -1567,7 +1576,7 @@ void ofAppEGLWindow::processInput(int fd, const char * node){
pushMouseEvent = true;
}
}else if(ev.code == BTN_TOUCH){
if(ev.value == 0){ // release
if(ev.value == 0){ // release
touchEvent.type = ofTouchEventArgs::up;
touchEvent.id = 0;
mt[touchEvent.id] = 0;
Expand Down Expand Up @@ -1731,7 +1740,7 @@ void ofAppEGLWindow::processInput(int fd, const char * node){
}else{
ofLogNotice("ofAppEGLWindow") << "readKeyboardEvents(): input_event.code is outside of our small range";
}
}
}
}
}else if (ev.type == EV_REL){
int axis = ev.code;
Expand Down Expand Up @@ -1782,7 +1791,7 @@ void ofAppEGLWindow::processInput(int fd, const char * node){
pushTouchEvent = true;
}
}
else
else
{
if (mt[touchEvent.id] == 0){
touchEvent.type = ofTouchEventArgs::down;
Expand Down Expand Up @@ -1840,16 +1849,16 @@ void ofAppEGLWindow::processInput(int fd, const char * node){
}
}




if(pushKeyEvent){
lock();
keyEvents.push(keyEvent);
unlock();
pushKeyEvent = false;
}

if(pushMouseEvent){
// lock the thread for a moment while we copy the data
lock();
Expand Down Expand Up @@ -1925,7 +1934,7 @@ void ofAppEGLWindow::readNativeUDevEvents() {
removeInput(devnode);
}
}

udev_device_unref(dev);
}else{
ofLogNotice("ofAppEGLWindow") << "readNativeUDevEvents(): device returned by receive_device() is NULL";
Expand Down Expand Up @@ -2304,3 +2313,5 @@ void ofAppEGLWindow::handleX11Event(const XEvent& event){
}*/
}
}

#endif
8 changes: 7 additions & 1 deletion libs/openFrameworks/app/ofAppEGLWindow.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#ifdef __unix__

#pragma once

#include "ofAppBaseWindow.h"
Expand All @@ -10,6 +12,8 @@

#include <queue>
#include <map>

#include <EGL/eglplatform.h>
#include <X11/Xlib.h>

enum ofAppEGLWindowType {
Expand Down Expand Up @@ -268,7 +272,7 @@ class ofAppEGLWindow : public ofAppBaseGLESWindow, public ofThread {
void readNativeUDevEvents();
void readNativeInputEvents();

void processInput(int fd, const char * node);
void processInput(int fd, const char * node);
void addInput(const char * node, bool isMouse);
void removeInput(const char * node);
void printInput();
Expand All @@ -285,3 +289,5 @@ class ofAppEGLWindow : public ofAppBaseGLESWindow, public ofThread {
std::shared_ptr<ofBaseRenderer> currentRenderer;
static ofAppEGLWindow * instance;
};

#endif
2 changes: 1 addition & 1 deletion libs/openFrameworks/graphics/ofCairoRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class ofCairoRenderer: public ofBaseRenderer{
std::stack<glm::mat4> projectionStack;
std::stack<glm::mat4> modelViewStack;
std::stack<ofRectangle> viewportStack;

ofMatrixMode currentMatrixMode;

std::vector<glm::vec3> sphereVerts;
Expand Down
55 changes: 29 additions & 26 deletions libs/openFrameworks/sound/ofMediaFoundationSoundPlayer.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef _WIN32

#include "ofMediaFoundationSoundPlayer.h"
#include "ofLog.h"
Expand Down Expand Up @@ -168,7 +169,7 @@ void ofMediaFoundationSoundPlayer::sCloseAudioSystems() {
sNumInstances--;
if (sNumInstances <= 0) {
ofLogVerbose("ofMediaFoundationSoundPlayer") << " closing XAudio2.";
sCloseXAudio2();
sCloseXAudio2();
}
ofMediaFoundationUtils::CloseMediaFoundation();
if (sNumInstances < 0) {
Expand All @@ -189,7 +190,7 @@ ofMediaFoundationSoundPlayer::~ofMediaFoundationSoundPlayer() {
//--------------------
bool ofMediaFoundationSoundPlayer::load(const of::filesystem::path & fileName, bool stream) {
unload();

auto filePath = fileName;
std::string fileStr = ofPathToString(fileName);
bool bStream = false;
Expand Down Expand Up @@ -223,7 +224,7 @@ bool ofMediaFoundationSoundPlayer::load(const of::filesystem::path & fileName, b


LPCWSTR path = filePath.c_str();


hr = MFCreateSourceReaderFromURL(
path,
Expand Down Expand Up @@ -255,14 +256,14 @@ bool ofMediaFoundationSoundPlayer::load(const of::filesystem::path & fileName, b
hr = mSrcReader->GetNativeMediaType(MF_SOURCE_READER_FIRST_AUDIO_STREAM, 0, &nativeType);

auto nativeTypePtr = std::unique_ptr<IMFMediaType, MyComDeleterFunctor>(nativeType);
// get a wave format
// get a wave format
hr = MFCreateWaveFormatExFromMFMediaType(nativeType, &nativeFormat, &formatSize);

mNumChannels = nativeFormat->nChannels;
mSampleRate = nativeFormat->nSamplesPerSec;

CoTaskMemFree(nativeFormat);


ComPtr<IMFMediaType> mediaType;
hr = MFCreateMediaType(mediaType.GetAddressOf());
Expand Down Expand Up @@ -335,19 +336,19 @@ bool ofMediaFoundationSoundPlayer::load(const of::filesystem::path & fileName, b
}

ofLogVerbose("ofMediaFoundationSoundPlayer::load") << "made it all the way to the end.";

if (!mBStreaming) {
mSrcReader.Reset();
mSrcReader = nullptr;
}

{

// create stream context for listening to voice
// create stream context for listening to voice
mVoiceContext = std::make_shared<StreamingVoiceContext>();
// Create the source voice
IXAudio2SourceVoice* pSourceVoice = nullptr;
// setting max freq ratio to 3, though it may need to be higher to play at a
// setting max freq ratio to 3, though it may need to be higher to play at a
// faster pitch
if (mBStreaming) {
hr = sXAudio2->CreateSourceVoice(
Expand Down Expand Up @@ -430,7 +431,7 @@ void ofMediaFoundationSoundPlayer::unload() {
mTotalNumFrames = 0;
mNumSamplesAlreadyPlayed = 0;
mBRequestNewReaderSample = false;

LeaveCriticalSection(&m_critSec);
};

Expand Down Expand Up @@ -467,7 +468,7 @@ void ofMediaFoundationSoundPlayer::update(ofEventArgs& args) {
} else {
bRequestStop = true;
// we need to request stop outside of the scope of the lock
// since stop() also locks to set vars
// since stop() also locks to set vars
}
}
}
Expand Down Expand Up @@ -497,7 +498,7 @@ void ofMediaFoundationSoundPlayer::update(ofEventArgs& args) {
if (!xstate.BuffersQueued && mExtraVoices.size() < 1) {
// we have reached the end //
if (mBLoop) {
// set isPlaying to false, so that it will create a new instance
// set isPlaying to false, so that it will create a new instance
// for mVoice and not an Extra Voice
mPosPct = 0.0f;
mBIsPlaying = false;
Expand Down Expand Up @@ -530,7 +531,7 @@ void ofMediaFoundationSoundPlayer::play() {
return;
}

// don't want a ton of loops going on here
// don't want a ton of loops going on here
if (mBLoop) {
stop();
}
Expand All @@ -539,7 +540,7 @@ void ofMediaFoundationSoundPlayer::play() {
}

if (mBStreaming) {
// just in case, multiplay is not supported for streams
// just in case, multiplay is not supported for streams
_clearExtraVoices();
}

Expand Down Expand Up @@ -583,7 +584,7 @@ void ofMediaFoundationSoundPlayer::play() {
XAUDIO2_BUFFER buffer = {};
buffer.pAudioData = mBuffer.data();
// tell the source voice not to expect any data after this buffer
buffer.Flags = XAUDIO2_END_OF_STREAM;
buffer.Flags = XAUDIO2_END_OF_STREAM;
buffer.AudioBytes = mBuffer.size();

hr = pSourceVoice->SubmitSourceBuffer(&buffer);
Expand All @@ -605,7 +606,7 @@ void ofMediaFoundationSoundPlayer::play() {
buffer.AudioBytes = mBuffer.size();

mVoice->SubmitSourceBuffer(&buffer);

}

mVoice->SetVolume(mVolume);
Expand Down Expand Up @@ -711,7 +712,7 @@ void ofMediaFoundationSoundPlayer::setPaused(bool bP) {
//--------------------
void ofMediaFoundationSoundPlayer::setLoop(bool bLp) {
if (bLp) {
// we don't want a lot of looping iterations
// we don't want a lot of looping iterations
_clearExtraVoices();
}
mBLoop = bLp;
Expand Down Expand Up @@ -740,7 +741,7 @@ void ofMediaFoundationSoundPlayer::setPosition(float pct) {
ofLogWarning("ofMediaFoundationSoundPlayer::setPosition") << " unable to seek.";
return;
}

// ok we need to kill buffers and resubmit a buffer
if (mVoice) {
std::ignore = mVoice->Stop();
Expand Down Expand Up @@ -785,7 +786,7 @@ void ofMediaFoundationSoundPlayer::setPositionMS(int ms) {
};

//--------------------
float ofMediaFoundationSoundPlayer::getPosition() const {
float ofMediaFoundationSoundPlayer::getPosition() const {
return mPosPct;
};

Expand Down Expand Up @@ -880,7 +881,7 @@ void ofMediaFoundationSoundPlayer::OnSourceReaderEvent(HRESULT hrStatus, DWORD d
}

hr = mediaBuffer->Unlock();

if (mVoice && mVoiceContext) {
XAUDIO2_VOICE_STATE state;

Expand Down Expand Up @@ -909,7 +910,7 @@ void ofMediaFoundationSoundPlayer::OnSourceReaderEvent(HRESULT hrStatus, DWORD d
std::unique_lock<std::mutex> lk(mSrcReaderMutex);
mBRequestNewReaderSample = true;
}

}
}

Expand Down Expand Up @@ -953,7 +954,7 @@ void ofMediaFoundationSoundPlayer::_setPan(IXAudio2SourceVoice* avoice, float ap
float outputMatrix[8];
for (int i = 0; i < 8; i++) outputMatrix[i] = 0;

// pan of -1.0 indicates all left speaker,
// pan of -1.0 indicates all left speaker,
// 1.0 is all right speaker, 0.0 is split between left and right
float left = 0.5f - apan / 2;
float right = 0.5f + apan / 2;
Expand Down Expand Up @@ -990,7 +991,7 @@ void ofMediaFoundationSoundPlayer::_setPan(IXAudio2SourceVoice* avoice, float ap

// Assuming pVoice sends to pMasteringVoice

// TODO: Cache this
// TODO: Cache this
XAUDIO2_VOICE_DETAILS MasterVoiceDetails;
sXAudioMasteringVoice->GetVoiceDetails(&MasterVoiceDetails);

Expand Down Expand Up @@ -1019,7 +1020,7 @@ bool ofMediaFoundationSoundPlayer::_readToBuffer(IMFSourceReader* areader) {
HRESULT hr = areader->ReadSample(
MF_SOURCE_READER_FIRST_AUDIO_STREAM,
0, // Flags.
&streamIndex, // Receives the actual stream index.
&streamIndex, // Receives the actual stream index.
&flags, // Receives status flags.
&llAudioTimeStamp, // Receives the time stamp.
&audioSample // Receives the sample or NULL.
Expand Down Expand Up @@ -1049,14 +1050,14 @@ bool ofMediaFoundationSoundPlayer::_readToBuffer(IMFSourceReader* areader) {
if (hr != S_OK) {
continue;
}

size_t numFramesRead = uint64_t(sampleBufferLength) / (bytes64 * numChannels64);
ofLogVerbose("ofMediaFoundationSoundPlayer::_readToBuffer") << "sampleBufferLength : " << sampleBufferLength << " num frames: " << numFramesRead << std::endl;
totalFrames += numFramesRead;
std::vector<BYTE> tempBuffer;
tempBuffer.resize(sampleBufferLength, 0);
memcpy_s(tempBuffer.data(), sampleBufferLength, audioData, sampleBufferLength);
// add into the main buffer?
// add into the main buffer?
mBuffer.insert(mBuffer.end(), tempBuffer.begin(), tempBuffer.end());

hr = mediaBuffer->Unlock();
Expand All @@ -1073,3 +1074,5 @@ bool ofMediaFoundationSoundPlayer::_readToBuffer(IMFSourceReader* areader) {
ofLogVerbose("ofMediaFoundationSoundPlayer::_readToBuffer") << "Total frames read: " << (totalFrames) << " mTotalNumFrames: " << mTotalNumFrames << " dur millis: " << durMillis << " dur seconds: " << durSeconds << std::endl;
return mBuffer.size() > 0;
}

#endif
Loading
Loading