Commit c284e58b authored by sletz's avatar sletz
Browse files

Clock source setting on Linux (in progress).

git-svn-id: http://subversion.jackaudio.org/jack/jack2/trunk/jackmp@3508 0c269be4-1314-0410-8aa9-9f06e86f4224
parent 8e6fa87b
......@@ -27,7 +27,8 @@ Paul Davis
2009-04-20 Stephane Letz <letz@grame.fr>
* In ALSA audio card reservation code, tries to open the card even if reservation fails.
* In ALSA audio card reservation code, tries to open the card even if reservation fails.
* Clock source setting on Linux (in progress).
2009-04-08 Stephane Letz <letz@grame.fr>
......
......@@ -81,6 +81,10 @@ struct jackctl_server
/* uint32_t, ports of the loopback driver */
union jackctl_parameter_value loopback_ports;
union jackctl_parameter_value default_loopback_ports;
/* uint32_t, clock source type */
union jackctl_parameter_value clock_source;
union jackctl_parameter_value default_clock_source;
/* bool */
union jackctl_parameter_value replace_registry;
......@@ -733,6 +737,20 @@ EXPORT jackctl_server_t * jackctl_server_create()
{
goto fail_free_parameters;
}
value.ui = 0;
if (jackctl_add_parameter(
&server_ptr->parameters,
"clock-source",
"Clocksource type : c(ycle) | h(pet) | s(ystem)",
"",
JackParamUInt,
&server_ptr->clock_source,
&server_ptr->default_clock_source,
value) == NULL)
{
goto fail_free_parameters;
}
value.b = false;
if (jackctl_add_parameter(
......@@ -864,6 +882,7 @@ jackctl_server_start(
server_ptr->realtime_priority.i,
server_ptr->loopback_ports.ui,
server_ptr->verbose.b,
(jack_timer_type_t)server_ptr->clock_source.ui,
server_ptr->name.str);
if (server_ptr->engine == NULL)
{
......
......@@ -63,6 +63,7 @@ struct SERVER_EXPORT JackEngineControl : public JackShmMem
int fMaxClientPriority;
char fServerName[64];
JackTransportEngine fTransport;
jack_timer_type_t fClockSource;
bool fVerbose;
// CPU Load
......@@ -88,7 +89,7 @@ struct SERVER_EXPORT JackEngineControl : public JackShmMem
JackEngineProfiling fProfiler;
#endif
JackEngineControl(bool sync, bool temporary, long timeout, bool rt, long priority, bool verbose, const char* server_name)
JackEngineControl(bool sync, bool temporary, long timeout, bool rt, long priority, bool verbose, jack_timer_type_t clock, const char* server_name)
{
fBufferSize = 512;
fSampleRate = 48000;
......@@ -113,6 +114,7 @@ struct SERVER_EXPORT JackEngineControl : public JackShmMem
fConstraint = 0;
fMaxDelayedUsecs = 0.f;
fXrunDelayedUsecs = 0.f;
fClockSource = clock;
}
~JackEngineControl()
......
......@@ -115,6 +115,7 @@ int JackLibClient::Open(const char* server_name, const char* name, jack_options_
JackGlobals::fClientTable[GetClientControl()->fRefNum] = this;
JackGlobals::fServerRunning = true;
SetClockSource(GetEngineControl()->fClockSource);
jack_log("JackLibClient::Open name = %s refnum = %ld", name_res, GetClientControl()->fRefNum);
return 0;
......
......@@ -38,7 +38,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
namespace Jack
{
JackServer::JackServer(bool sync, bool temporary, long timeout, bool rt, long priority, long loopback, bool verbose, const char* server_name)
JackServer::JackServer(bool sync, bool temporary, long timeout, bool rt, long priority, long loopback, bool verbose, jack_timer_type_t clock, const char* server_name)
{
if (rt) {
jack_info("JACK server starting in realtime mode with priority %ld", priority);
......@@ -47,7 +47,7 @@ JackServer::JackServer(bool sync, bool temporary, long timeout, bool rt, long pr
}
fGraphManager = new JackGraphManager();
fEngineControl = new JackEngineControl(sync, temporary, timeout, rt, priority, verbose, server_name);
fEngineControl = new JackEngineControl(sync, temporary, timeout, rt, priority, verbose, clock, server_name);
fEngine = new JackLockedEngine(fGraphManager, GetSynchroTable(), fEngineControl);
fFreewheelDriver = new JackThreadedDriver(new JackFreewheelDriver(fEngine, GetSynchroTable()));
fLoopbackDriver = new JackLoopbackDriver(fEngine, GetSynchroTable());
......@@ -115,6 +115,7 @@ int JackServer::Open(jack_driver_desc_t* driver_desc, JSList* driver_params)
fAudioDriver->AddSlave(fLoopbackDriver);
fAudioDriver->AddSlave(fFreewheelDriver); // After ???
InitTime();
SetClockSource(fEngineControl->fClockSource);
return 0;
fail_close7:
......
......@@ -64,7 +64,7 @@ class SERVER_EXPORT JackServer
public:
JackServer(bool sync, bool temporary, long timeout, bool rt, long priority, long loopback, bool verbose, const char* server_name);
JackServer(bool sync, bool temporary, long timeout, bool rt, long priority, long loopback, bool verbose, jack_timer_type_t clock, const char* server_name);
~JackServer();
int Open(jack_driver_desc_t* driver_desc, JSList* driver_params);
......
......@@ -40,10 +40,11 @@ int JackServerGlobals::Start(const char* server_name,
int rt,
int priority,
int loopback,
int verbose)
int verbose,
jack_timer_type_t clock)
{
jack_log("Jackdmp: sync = %ld timeout = %ld rt = %ld priority = %ld verbose = %ld ", sync, time_out_ms, rt, priority, verbose);
new JackServer(sync, temporary, time_out_ms, rt, priority, loopback, verbose, server_name); // Will setup fInstance and fUserCount globals
new JackServer(sync, temporary, time_out_ms, rt, priority, loopback, verbose, clock, server_name); // Will setup fInstance and fUserCount globals
int res = fInstance->Open(driver_desc, driver_params);
return (res < 0) ? res : fInstance->Start();
}
......@@ -92,6 +93,7 @@ bool JackServerGlobals::Init()
char buffer[255];
int argc = 0;
char* argv[32];
jack_timer_type_t clock_source = JACK_TIMER_SYSTEM_CLOCK;
// First user starts the server
if (fUserCount++ == 0) {
......@@ -99,8 +101,9 @@ bool JackServerGlobals::Init()
jack_log("JackServerGlobals Init");
jack_driver_desc_t* driver_desc;
const char *options = "-ad:P:uvshVRL:STFl:t:mn:p:";
const char *options = "-ad:P:uvshVRL:STFl:t:mn:p:c:";
static struct option long_options[] = {
{ "clock-source", 1, 0, 'c' },
{ "driver", 1, 0, 'd' },
{ "verbose", 0, 0, 'v' },
{ "help", 0, 0, 'h' },
......@@ -155,6 +158,18 @@ bool JackServerGlobals::Init()
(opt = getopt_long(argc, argv, options, long_options, &option_index)) != EOF) {
switch (opt) {
case 'c':
if (tolower (optarg[0]) == 'h') {
clock_source = JACK_TIMER_HPET;
} else if (tolower (optarg[0]) == 'c') {
clock_source = JACK_TIMER_CYCLE_COUNTER;
} else if (tolower (optarg[0]) == 's') {
clock_source = JACK_TIMER_SYSTEM_CLOCK;
} else {
jack_error("unknown option character %c", optopt);
}
break;
case 'd':
seen_driver = 1;
......@@ -281,7 +296,7 @@ bool JackServerGlobals::Init()
free(argv[i]);
}
int res = Start(server_name, driver_desc, driver_params, sync, temporary, client_timeout, realtime, realtime_priority, loopback, verbose_aux);
int res = Start(server_name, driver_desc, driver_params, sync, temporary, client_timeout, realtime, realtime_priority, loopback, verbose_aux, clock_source);
if (res < 0) {
jack_error("Cannot start server... exit");
Delete();
......
......@@ -44,7 +44,7 @@ struct SERVER_EXPORT JackServerGlobals
static bool Init();
static void Destroy();
static int Start(const char* server_name,
static int Start (const char* server_name,
jack_driver_desc_t* driver_desc,
JSList* driver_params,
int sync,
......@@ -53,7 +53,8 @@ struct SERVER_EXPORT JackServerGlobals
int rt,
int priority,
int loopback,
int verbose);
int verbose,
jack_timer_type_t clock);
static void Stop();
static void Delete();
};
......
......@@ -21,6 +21,8 @@
#ifndef __JackTypes__
#define __JackTypes__
#include "JackCompilerDeps.h"
typedef unsigned short UInt16;
#if __LP64__
typedef unsigned int UInt32;
......@@ -34,8 +36,11 @@ typedef signed long SInt32;
typedef uint16_t jack_int_t; // Internal type for ports and refnum
namespace Jack
{
typedef enum {
JACK_TIMER_SYSTEM_CLOCK,
JACK_TIMER_CYCLE_COUNTER,
JACK_TIMER_HPET,
} jack_timer_type_t;
typedef enum {
NotTriggered,
......@@ -44,6 +49,16 @@ typedef enum {
Finished,
} jack_client_state_t;
#ifdef __cplusplus
extern "C"
{
#endif
SERVER_EXPORT void SetClockSource(jack_timer_type_t source);
SERVER_EXPORT const char* ClockSourceName(jack_timer_type_t source);
#ifdef __cplusplus
}
#endif
#endif
......@@ -97,6 +97,9 @@ static void usage(FILE* file)
" [ --timeout OR -t client-timeout-in-msecs ]\n"
" [ --midi OR -X midi-driver ]\n"
" [ --verbose OR -v ]\n"
#ifdef __linux__
" [ --clocksource OR -c [ c(ycle) | h(pet) | s(ystem) ]\n"
#endif
" [ --replace-registry OR -r ]\n"
" [ --silent OR -s ]\n"
" [ --sync OR -S ]\n"
......@@ -156,8 +159,17 @@ int main(int argc, char* argv[])
const char* server_name = "default";
jackctl_driver_t * audio_driver_ctl;
jackctl_driver_t * midi_driver_ctl;
#ifdef __linux__
const char *options = "-ad:X:P:uvrshVRL:STFl:t:mn:p:c:";
#else
const char *options = "-ad:X:P:uvrshVRL:STFl:t:mn:p:";
#endif
struct option long_options[] = {
#ifdef __linux__
{ "clock-source", 1, 0, 'c' },
#endif
{ "audio-driver", 1, 0, 'd' },
{ "midi-driver", 1, 0, 'X' },
{ "verbose", 0, 0, 'v' },
......@@ -177,6 +189,7 @@ int main(int argc, char* argv[])
{ "sync", 0, 0, 'S' },
{ 0, 0, 0, 0 }
};
int i,opt = 0;
int option_index = 0;
bool seen_audio_driver = false;
......@@ -211,6 +224,27 @@ int main(int argc, char* argv[])
long_options, &option_index)) != EOF) {
switch (opt) {
#ifdef __linux__
case 'c':
param = jackctl_get_parameter(server_parameters, "clock-source");
if (param != NULL) {
if (tolower (optarg[0]) == 'h') {
value.ui = JACK_TIMER_HPET;
jackctl_parameter_set_value(param, &value);
} else if (tolower (optarg[0]) == 'c') {
value.ui = JACK_TIMER_CYCLE_COUNTER;
jackctl_parameter_set_value(param, &value);
} else if (tolower (optarg[0]) == 's') {
value.ui = JACK_TIMER_SYSTEM_CLOCK;
jackctl_parameter_set_value(param, &value);
} else {
usage(stdout);
goto fail_free;
}
}
break;
#endif
case 'd':
seen_audio_driver = true;
audio_driver_name = optarg;
......
......@@ -99,3 +99,11 @@ SERVER_EXPORT void JackSleep(long usec)
}
#endif
SERVER_EXPORT void SetClockSource(jack_timer_type_t source)
{}
SERVER_EXPORT const char* ClockSourceName(jack_timer_type_t source)
{
return "";
}
......@@ -20,6 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "JackTime.h"
#include "JackError.h"
#include "JackTypes.h"
#include <mach/mach_time.h>
#include <unistd.h>
......@@ -42,3 +43,11 @@ SERVER_EXPORT jack_time_t GetMicroSeconds(void)
{
return (jack_time_t) (mach_absolute_time () * __jack_time_ratio);
}
SERVER_EXPORT void SetClockSource(jack_timer_type_t source)
{}
SERVER_EXPORT const char* ClockSourceName(jack_timer_type_t source)
{
return "";
}
......@@ -568,7 +568,7 @@ OSStatus JackCoreAudioDriver::CreateAggregateDevice(AudioDeviceID captureDeviceI
CFRelease(captureDeviceUID);
CFRelease(playbackDeviceUID);
jack_log("New aggregate device %ld\n", *outAggregateDevice);
jack_log("New aggregate device %ld", *outAggregateDevice);
return noErr;
}
......
......@@ -35,3 +35,10 @@ SERVER_EXPORT jack_time_t GetMicroSeconds(void)
return (jack_time_t)(gethrtime() / 1000);
}
SERVER_EXPORT void SetClockSource(jack_timer_type_t source)
{}
SERVER_EXPORT const char* ClockSourceName(jack_timer_type_t source)
{
return "";
}
......@@ -41,3 +41,11 @@ SERVER_EXPORT jack_time_t GetMicroSeconds(void)
QueryPerformanceCounter(&t1);
return (jack_time_t)(((double)t1.QuadPart) / ((double)_jack_freq.QuadPart));
}
SERVER_EXPORT void SetClockSource(jack_timer_type_t source)
{}
SERVER_EXPORT const char* ClockSourceName(jack_timer_type_t source)
{
return "";
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment