From c1c3fa057bfa597a4e7a0d05a15aae676eed444d Mon Sep 17 00:00:00 2001 From: sletz Date: Wed, 2 Jul 2008 12:46:58 +0000 Subject: [PATCH] New JackBlockingNetIOAdapter and JackCallbackNetIOAdapter classes git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@2582 0c269be4-1314-0410-8aa9-9f06e86f4224 --- common/JackBlockingNetIOAdapter.h | 47 ++++++++++ common/JackCallbackNetIOAdapter.cpp | 109 +++++++++++++++++++++++ common/JackCallbackNetIOAdapter.h | 49 ++++++++++ common/JackNetIOAdapter.cpp | 68 +------------- common/JackNetIOAdapter.h | 11 +-- common/wscript | 2 +- macosx/Jackdmp.xcodeproj/project.pbxproj | 14 +-- 7 files changed, 220 insertions(+), 80 deletions(-) create mode 100644 common/JackBlockingNetIOAdapter.h create mode 100644 common/JackCallbackNetIOAdapter.cpp create mode 100644 common/JackCallbackNetIOAdapter.h diff --git a/common/JackBlockingNetIOAdapter.h b/common/JackBlockingNetIOAdapter.h new file mode 100644 index 00000000..d4ab02c9 --- /dev/null +++ b/common/JackBlockingNetIOAdapter.h @@ -0,0 +1,47 @@ +/* +Copyright (C) 2008 Grame + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#ifndef __JackBlockingNetIOAdapter__ +#define __JackBlockingNetIOAdapter__ + +#include "JackNetIOAdapter.h" + +namespace Jack +{ + + class JackBlockingNetIOAdapter : public JackNetIOAdapter + { + private: + + static int Process(jack_nframes_t, void* arg) {return 0;} + + public: + + JackBlockingNetIOAdapter(jack_client_t* jack_client, + JackIOAdapterInterface* audio_io, + int input, + int output) + : JackNetIOAdapter(jack_client, audio_io, input, output) + ~JackBlockingNetIOAdapter() + {} + + }; +} + +#endif diff --git a/common/JackCallbackNetIOAdapter.cpp b/common/JackCallbackNetIOAdapter.cpp new file mode 100644 index 00000000..09815c53 --- /dev/null +++ b/common/JackCallbackNetIOAdapter.cpp @@ -0,0 +1,109 @@ +/* +Copyright (C) 2008 Grame + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "JackCallbackNetIOAdapter.h" +#include "JackError.h" +#include "JackExports.h" +#include +#include + +using namespace std; + +namespace Jack +{ + +#define DEFAULT_RB_SIZE 16384 + +int JackCallbackNetIOAdapter::Process(jack_nframes_t frames, void* arg) +{ + JackCallbackNetIOAdapter* adapter = static_cast(arg); + char* buffer; + int i; + + if (!adapter->fIOAdapter->IsRunning()) + return 0; + + for (i = 0; i < adapter->fCaptureChannels; i++) { + + buffer = static_cast(jack_port_get_buffer(adapter->fCapturePortList[i], frames)); + size_t len = jack_ringbuffer_read_space(adapter->fCaptureRingBuffer); + + if (len < frames * sizeof(float)) { + jack_error("JackCallbackNetIOAdapter::Process : consumer too slow, skip frames = %d", (frames * sizeof(float)) - len); + jack_ringbuffer_read(adapter->fCaptureRingBuffer, buffer, len); + } else { + jack_ringbuffer_read(adapter->fCaptureRingBuffer, buffer, frames * sizeof(float)); + } + } + + for (i = 0; i < adapter->fPlaybackChannels; i++) { + + buffer = static_cast(jack_port_get_buffer(adapter->fPlaybackPortList[i], frames)); + size_t len = jack_ringbuffer_write_space(adapter->fPlaybackRingBuffer); + + if (len < frames * sizeof(float)) { + jack_error("JackCallbackNetIOAdapter::Process : producer too slow, missing frames = %d", (frames * sizeof(float)) - len); + jack_ringbuffer_write(adapter->fPlaybackRingBuffer, buffer, len); + } else { + jack_ringbuffer_write(adapter->fPlaybackRingBuffer, buffer, frames * sizeof(float)); + } + } + + return 0; +} + +JackCallbackNetIOAdapter::JackCallbackNetIOAdapter(jack_client_t* jack_client, + JackIOAdapterInterface* audio_io, + int input, + int output) + : JackNetIOAdapter(jack_client, audio_io, input, output) +{ + + fCaptureRingBuffer = jack_ringbuffer_create(fCaptureChannels * sizeof(float) * DEFAULT_RB_SIZE); + if (fCaptureRingBuffer == NULL) + goto fail; + + fPlaybackRingBuffer = jack_ringbuffer_create(fPlaybackChannels * sizeof(float) * DEFAULT_RB_SIZE); + if (fPlaybackRingBuffer == NULL) + goto fail; + + fIOAdapter->SetRingBuffers(fCaptureRingBuffer, fPlaybackRingBuffer); + + if (jack_set_process_callback(fJackClient, Process, this) < 0) + goto fail; + + if (jack_activate(fJackClient) < 0) + goto fail; + + return; + +fail: + FreePorts(); +} + +JackCallbackNetIOAdapter::~JackCallbackNetIOAdapter() +{ + if (fCaptureRingBuffer) + jack_ringbuffer_free(fCaptureRingBuffer); + + if (fPlaybackRingBuffer) + jack_ringbuffer_free(fPlaybackRingBuffer); +} + +} //namespace diff --git a/common/JackCallbackNetIOAdapter.h b/common/JackCallbackNetIOAdapter.h new file mode 100644 index 00000000..52494ad4 --- /dev/null +++ b/common/JackCallbackNetIOAdapter.h @@ -0,0 +1,49 @@ +/* +Copyright (C) 2008 Grame + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#ifndef __JackCallbackNetIOAdapter__ +#define __JackCallbackNetIOAdapter__ + +#include "JackNetIOAdapter.h" +#include "ringbuffer.h" + +namespace Jack +{ + + class JackCallbackNetIOAdapter : public JackNetIOAdapter + { + private: + + jack_ringbuffer_t* fCaptureRingBuffer; + jack_ringbuffer_t* fPlaybackRingBuffer; + + static int Process(jack_nframes_t, void* arg); + + public: + + JackCallbackNetIOAdapter(jack_client_t* jack_client, + JackIOAdapterInterface* audio_io, + int input, + int output); + ~JackCallbackNetIOAdapter(); + + }; +} + +#endif diff --git a/common/JackNetIOAdapter.cpp b/common/JackNetIOAdapter.cpp index 902c0ba4..3289ee5c 100644 --- a/common/JackNetIOAdapter.cpp +++ b/common/JackNetIOAdapter.cpp @@ -28,45 +28,6 @@ using namespace std; namespace Jack { -#define DEFAULT_RB_SIZE 16384 - -int JackNetIOAdapter::Process(jack_nframes_t frames, void* arg) -{ - JackNetIOAdapter* adapter = static_cast(arg); - char* buffer; - int i; - - if (!adapter->fIOAdapter->IsRunning()) - return 0; - - for (i = 0; i < adapter->fCaptureChannels; i++) { - - buffer = static_cast(jack_port_get_buffer(adapter->fCapturePortList[i], frames)); - size_t len = jack_ringbuffer_read_space(adapter->fCaptureRingBuffer); - - if (len < frames * sizeof(float)) { - jack_error("JackNetIOAdapter::Process : consumer too slow, skip frames = %d", (frames * sizeof(float)) - len); - jack_ringbuffer_read(adapter->fCaptureRingBuffer, buffer, len); - } else { - jack_ringbuffer_read(adapter->fCaptureRingBuffer, buffer, frames * sizeof(float)); - } - } - - for (i = 0; i < adapter->fPlaybackChannels; i++) { - - buffer = static_cast(jack_port_get_buffer(adapter->fPlaybackPortList[i], frames)); - size_t len = jack_ringbuffer_write_space(adapter->fPlaybackRingBuffer); - - if (len < frames * sizeof(float)) { - jack_error("JackNetIOAdapter::Process : producer too slow, missing frames = %d", (frames * sizeof(float)) - len); - jack_ringbuffer_write(adapter->fPlaybackRingBuffer, buffer, len); - } else { - jack_ringbuffer_write(adapter->fPlaybackRingBuffer, buffer, frames * sizeof(float)); - } - } - - return 0; -} JackNetIOAdapter::JackNetIOAdapter(jack_client_t* jack_client, JackIOAdapterInterface* audio_io, @@ -82,17 +43,7 @@ JackNetIOAdapter::JackNetIOAdapter(jack_client_t* jack_client, fCapturePortList = new jack_port_t* [fCaptureChannels]; fPlaybackPortList = new jack_port_t* [fPlaybackChannels]; - - fCaptureRingBuffer = jack_ringbuffer_create(fCaptureChannels * sizeof(float) * DEFAULT_RB_SIZE); - if (fCaptureRingBuffer == NULL) - goto fail; - - fPlaybackRingBuffer = jack_ringbuffer_create(fPlaybackChannels * sizeof(float) * DEFAULT_RB_SIZE); - if (fPlaybackRingBuffer == NULL) - goto fail; - - fIOAdapter->SetRingBuffers(fCaptureRingBuffer, fPlaybackRingBuffer); - + for (i = 0; i < fCaptureChannels; i++) { sprintf(name, "capture_%d", i+1); if ((fCapturePortList[i] = jack_port_register(fJackClient, name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0)) == NULL) @@ -105,12 +56,6 @@ JackNetIOAdapter::JackNetIOAdapter(jack_client_t* jack_client, goto fail; } - if (jack_set_process_callback(fJackClient, Process, this) < 0) - goto fail; - - if (jack_activate(fJackClient) < 0) - goto fail; - return; fail: @@ -127,13 +72,7 @@ void JackNetIOAdapter::FreePorts() { int i; - if (fCaptureRingBuffer) - jack_ringbuffer_free(fCaptureRingBuffer); - - if (fPlaybackRingBuffer) - jack_ringbuffer_free(fPlaybackRingBuffer); - - for (i = 0; i < fCaptureChannels; i++) { + for (i = 0; i < fCaptureChannels; i++) { if (fCapturePortList[i]) jack_port_unregister(fJackClient, fCapturePortList[i]); } @@ -168,6 +107,7 @@ extern "C" #include "JackCoreAudioIOAdapter.h" #include "JackPortAudioIOAdapter.h" +#include "JackCallbackNetIOAdapter.h" EXPORT int jack_initialize(jack_client_t* jack_client, const char* load_init) { @@ -177,7 +117,7 @@ extern "C" } else { jack_log("Loading NetAudio Adapter"); // adapter = new Jack::JackNetIOAdapter(jack_client, new Jack::JackCoreAudioIOAdapter(2, 2, 512, 44100.f), 2, 2); - adapter = new Jack::JackNetIOAdapter(jack_client, + adapter = new Jack::JackCallbackNetIOAdapter(jack_client, new Jack::JackPortAudioIOAdapter(2, 2, jack_get_buffer_size(jack_client), jack_get_sample_rate(jack_client)), 2, 2); assert(adapter); diff --git a/common/JackNetIOAdapter.h b/common/JackNetIOAdapter.h index 5a4464f3..2c362acd 100644 --- a/common/JackNetIOAdapter.h +++ b/common/JackNetIOAdapter.h @@ -21,7 +21,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #define __JackNetIOAdapter__ #include "jack.h" -#include "ringbuffer.h" #include "JackIOAdapter.h" namespace Jack @@ -29,22 +28,18 @@ namespace Jack class JackNetIOAdapter { - private: + protected: int fCaptureChannels; int fPlaybackChannels; jack_port_t** fCapturePortList; jack_port_t** fPlaybackPortList; - - jack_ringbuffer_t* fCaptureRingBuffer; - jack_ringbuffer_t* fPlaybackRingBuffer; jack_client_t* fJackClient; JackIOAdapterInterface* fIOAdapter; - static int Process(jack_nframes_t, void* arg); - void FreePorts(); + void FreePorts(); public: @@ -52,7 +47,7 @@ namespace Jack JackIOAdapterInterface* audio_io, int input, int output); - ~JackNetIOAdapter(); + virtual ~JackNetIOAdapter(); int Open(); int Close(); diff --git a/common/wscript b/common/wscript index 94ed3c51..fb67b5f3 100644 --- a/common/wscript +++ b/common/wscript @@ -196,7 +196,7 @@ def build(bld): #create_jack_process_obj(bld, 'netioadapter', 'JackNetIOAdapter.cpp ../macosx/JackCoreAudioIOAdapter.cpp', serverlib) - process = create_jack_process_obj(bld, 'netioadapter', 'JackNetIOAdapter.cpp ../windows/JackPortAudioIOAdapter.cpp', serverlib) + process = create_jack_process_obj(bld, 'netioadapter', 'JackNetIOAdapter.cpp JackCallbackNetIOAdapter.cpp ../windows/JackPortAudioIOAdapter.cpp', serverlib) if bld.env()['IS_MACOSX']: process.env.append_value("LINKFLAGS", "../macosx/libportaudio.a -framework CoreAudio -framework AudioUnit -framework AudioToolbox -framework CoreServices ") diff --git a/macosx/Jackdmp.xcodeproj/project.pbxproj b/macosx/Jackdmp.xcodeproj/project.pbxproj index 290427ca..853336d3 100644 --- a/macosx/Jackdmp.xcodeproj/project.pbxproj +++ b/macosx/Jackdmp.xcodeproj/project.pbxproj @@ -1207,9 +1207,9 @@ 4B5F253D0DEE9B8F0041E486 /* JackLockedEngine.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = JackLockedEngine.h; path = ../common/JackLockedEngine.h; sourceTree = SOURCE_ROOT; }; 4B60CE480AAABA31004956AA /* connect.c */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.c; name = connect.c; path = "../example-clients/connect.c"; sourceTree = SOURCE_ROOT; }; 4B66A8580934964500A89560 /* JackConstants.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = JackConstants.h; path = ../common/JackConstants.h; sourceTree = SOURCE_ROOT; }; - 4B699BB1097D421600A18468 /* jackdmp */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = jackdmp; sourceTree = BUILT_PRODUCTS_DIR; }; + 4B699BB1097D421600A18468 /* jackdmp */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = jackdmp; sourceTree = BUILT_PRODUCTS_DIR; }; 4B699C47097D421600A18468 /* Jackmp.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Jackmp.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - 4B699CAC097D421600A18468 /* Jackdmp.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Jackdmp.framework; sourceTree = BUILT_PRODUCTS_DIR; }; + 4B699CAC097D421600A18468 /* Jackservermp.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Jackservermp.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 4B699CBB097D421600A18468 /* jack_metro */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = jack_metro; sourceTree = BUILT_PRODUCTS_DIR; }; 4B699CCB097D421600A18468 /* jack_lsp */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = jack_lsp; sourceTree = BUILT_PRODUCTS_DIR; }; 4B699CDB097D421600A18468 /* jack_connect */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = jack_connect; sourceTree = BUILT_PRODUCTS_DIR; }; @@ -1395,7 +1395,7 @@ 4BFB73F608AD291A00DB99B8 /* JackGlobals.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = JackGlobals.h; path = ../common/JackGlobals.h; sourceTree = SOURCE_ROOT; }; 4BFB741E08AD2B9900DB99B8 /* JackMachThread.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = JackMachThread.cpp; sourceTree = SOURCE_ROOT; }; 4BFB741F08AD2B9900DB99B8 /* JackMachThread.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = JackMachThread.h; sourceTree = SOURCE_ROOT; }; - BA222ACF0DC88132001A17F4 /* jack_dummy.so */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = jack_dummy.so; sourceTree = BUILT_PRODUCTS_DIR; }; + BA222ACF0DC88132001A17F4 /* jack_net.so */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = jack_net.so; sourceTree = BUILT_PRODUCTS_DIR; }; BA222AD60DC88268001A17F4 /* JackNetTool.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = JackNetTool.cpp; path = ../common/JackNetTool.cpp; sourceTree = SOURCE_ROOT; }; BA222AD70DC88268001A17F4 /* JackNetTool.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; name = JackNetTool.h; path = ../common/JackNetTool.h; sourceTree = SOURCE_ROOT; }; BA222ADC0DC882A5001A17F4 /* JackNetDriver.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; name = JackNetDriver.cpp; path = ../common/JackNetDriver.cpp; sourceTree = SOURCE_ROOT; }; @@ -1974,7 +1974,7 @@ children = ( 4B699BB1097D421600A18468 /* jackdmp */, 4B699C47097D421600A18468 /* Jackmp.framework */, - 4B699CAC097D421600A18468 /* Jackdmp.framework */, + 4B699CAC097D421600A18468 /* Jackservermp.framework */, 4B699CBB097D421600A18468 /* jack_metro */, 4B699CCB097D421600A18468 /* jack_lsp */, 4B699CDB097D421600A18468 /* jack_connect */, @@ -2028,7 +2028,7 @@ 4B0A292D0D52108E002EFF74 /* jack_thread_wait */, 4B57F5950D72C27900B4E719 /* jack_thread_wait */, 4BA7FEC30D8E76270017FF73 /* jack_lsp */, - BA222ACF0DC88132001A17F4 /* jack_dummy.so */, + BA222ACF0DC88132001A17F4 /* jack_net.so */, BA222AE90DC882DB001A17F4 /* netmanager.so */, 4BA7FEC30D8E76270017FF73 /* jack_lsp */, 4B363DD80DEB02F6001F72D9 /* jack_midiseq */, @@ -4019,7 +4019,7 @@ ); name = "Jackservermp.framework Universal"; productName = Jack; - productReference = 4B699CAC097D421600A18468 /* Jackdmp.framework */; + productReference = 4B699CAC097D421600A18468 /* Jackservermp.framework */; productType = "com.apple.product-type.framework"; }; 4B699CB1097D421600A18468 /* jack_metro Universal */ = { @@ -4580,7 +4580,7 @@ ); name = "jack_net Universal"; productName = jack_coreaudio; - productReference = BA222ACF0DC88132001A17F4 /* jack_dummy.so */; + productReference = BA222ACF0DC88132001A17F4 /* jack_net.so */; productType = "com.apple.product-type.library.dynamic"; }; BA222AE00DC882DB001A17F4 /* netmanager */ = {