Add FreeBSD support
[jack2.git] / common / JackAudioAdapterFactory.cpp
blobf121ed2b9badacdcf0b6f4813048dd4b8a5ab2b0
1 /*
2 Copyright (C) 2008-2012 Grame
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "JackAudioAdapter.h"
21 #include "JackPlatformPlug.h"
22 #include "JackArgParser.h"
24 #include <stdio.h>
25 #include <stdlib.h>
26 #include <assert.h>
28 #ifdef __APPLE__
29 #include "JackCoreAudioAdapter.h"
30 #define JackPlatformAdapter JackCoreAudioAdapter
31 #endif
33 #ifdef __linux__
34 #include "JackAlsaAdapter.h"
35 #define JackPlatformAdapter JackAlsaAdapter
36 #endif
38 #if defined(__sun__) || defined(sun) || defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
39 #include "JackOSSAdapter.h"
40 #define JackPlatformAdapter JackOSSAdapter
41 #endif
43 #ifdef WIN32
44 #include "JackPortAudioAdapter.h"
45 #define JackPlatformAdapter JackPortAudioAdapter
46 #endif
48 #ifdef __cplusplus
49 extern "C"
51 #endif
53 using namespace Jack;
55 SERVER_EXPORT int jack_internal_initialize(jack_client_t* jack_client, const JSList* params)
57 jack_log("Loading audioadapter");
59 Jack::JackAudioAdapter* adapter;
60 jack_nframes_t buffer_size = jack_get_buffer_size(jack_client);
61 jack_nframes_t sample_rate = jack_get_sample_rate(jack_client);
63 try {
65 adapter = new Jack::JackAudioAdapter(jack_client, new Jack::JackPlatformAdapter(buffer_size, sample_rate, params), params);
66 assert(adapter);
68 if (adapter->Open() == 0) {
69 return 0;
70 } else {
71 delete adapter;
72 return 1;
75 } catch (...) {
76 jack_info("audioadapter allocation error");
77 return 1;
81 SERVER_EXPORT int jack_initialize(jack_client_t* jack_client, const char* load_init)
83 JSList* params = NULL;
84 bool parse_params = true;
85 int res = 1;
86 jack_driver_desc_t* desc = jack_get_descriptor();
88 Jack::JackArgParser parser(load_init);
89 if (parser.GetArgc() > 0) {
90 parse_params = parser.ParseParams(desc, &params);
93 if (parse_params) {
94 res = jack_internal_initialize(jack_client, params);
95 parser.FreeParams(params);
97 return res;
100 SERVER_EXPORT void jack_finish(void* arg)
102 Jack::JackAudioAdapter* adapter = static_cast<Jack::JackAudioAdapter*>(arg);
104 if (adapter) {
105 jack_log("Unloading audioadapter");
106 adapter->Close();
107 delete adapter;
111 #ifdef __cplusplus
113 #endif