2 Copyright (C) 2014 Samsung Electronics
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include "JackSapaProxy.h"
21 #include "JackServerGlobals.h"
22 #include "JackEngineControl.h"
23 #include "JackLockedEngine.h"
24 #include "JackArgParser.h"
31 // sapaproxy:__system_capture_1 -->| |--> sapaproxy:capture_1
32 // sapaproxy:__system_capture_2 -->| |--> sapaproxy:capture_2
35 // sapaproxy:playback_1 ---------->| |--> sapaproxy:__system_playback_1
36 // sapaproxy:playback_2 ---------->| |--> sapaproxy:__system_playback_2
37 // sapaproxy:playback_3 ---------->| |--> sapaproxy:__system_playback_3
38 // sapaproxy:playback_4 ---------->| |--> sapaproxy:__system_playback_4
45 JackSapaProxy::JackSapaProxy(jack_client_t
* client
, const JSList
* params
)
48 jack_log("JackSapaProxy::JackSapaProxy");
50 fCapturePorts
= fPlaybackPorts
= 0;
53 const jack_driver_param_t
* param
;
54 for (node
= params
; node
; node
= jack_slist_next(node
)) {
55 param
= (const jack_driver_param_t
*)node
->data
;
57 switch (param
->character
) {
59 fCapturePorts
= (param
->value
.ui
> SAPAPROXY_PORT_NUM_FOR_CLIENT
)? SAPAPROXY_PORT_NUM_FOR_CLIENT
: param
->value
.ui
;
63 fPlaybackPorts
= (param
->value
.ui
> SAPAPROXY_PORT_NUM_FOR_CLIENT
)? SAPAPROXY_PORT_NUM_FOR_CLIENT
: param
->value
.ui
;
69 JackSapaProxy::~JackSapaProxy()
71 jack_log("JackSapaProxy::~JackSapaProxy");
74 int JackSapaProxy::Setup(jack_client_t
* client
)
76 jack_log("JackSapaProxy::Setup");
78 //refer to system ports and create sapaproxy ports
79 unsigned int i
= 0, j
= 0;
80 const char **ports_system_capture
;
81 const char **ports_system_playback
;
82 unsigned int ports_system_capture_cnt
= 0;
83 unsigned int ports_system_playback_cnt
= 0;
84 char port_name
[JACK_PORT_NAME_SIZE
] = {0,};
85 ports_system_capture
= jack_get_ports(client
, "system:.*", NULL
, JackPortIsPhysical
| JackPortIsOutput
);
86 if (ports_system_capture
!= NULL
) {
87 for (i
= 0; i
< fCapturePorts
&& ports_system_capture
[i
]; i
++) {
88 sprintf(port_name
, "__system_capture_%d", i
+ 1);
89 fInputPorts
[i
] = jack_port_register(client
, port_name
, JACK_DEFAULT_AUDIO_TYPE
, JackPortIsInput
, 0);
90 sprintf(port_name
, "capture_%d", i
+ 1);
91 fOutputPorts
[i
] = jack_port_register(client
, port_name
, JACK_DEFAULT_AUDIO_TYPE
, JackPortIsOutput
, 0);
92 ports_system_capture_cnt
++;
94 jack_free(ports_system_capture
);
97 ports_system_playback
= jack_get_ports(client
, "system:.*", NULL
, JackPortIsPhysical
| JackPortIsInput
);
98 if (ports_system_playback
!= NULL
) {
99 for (j
= 0; j
< fPlaybackPorts
&& ports_system_playback
[j
]; j
++, i
++) {
100 sprintf(port_name
, "playback_%d", j
+ 1);
101 fInputPorts
[i
] = jack_port_register(client
, port_name
, JACK_DEFAULT_AUDIO_TYPE
, JackPortIsInput
, 0);
102 sprintf(port_name
, "__system_playback_%d", j
+ 1);
103 fOutputPorts
[i
] = jack_port_register(client
, port_name
, JACK_DEFAULT_AUDIO_TYPE
, JackPortIsOutput
, 0);
104 ports_system_playback_cnt
++;
106 jack_free(ports_system_playback
);
109 //store actual number of system ports
110 fCapturePorts
= ports_system_capture_cnt
;
111 fPlaybackPorts
= ports_system_playback_cnt
;
113 jack_set_process_callback(client
, Process
, this);
114 jack_activate(client
);
116 //conenct between sapaproxy and system ports
117 for (unsigned int i
= 0; i
< ports_system_capture_cnt
; i
++) {
118 sprintf(port_name
, "system:capture_%d", i
+ 1);
119 jack_connect(client
, port_name
, jack_port_name(fInputPorts
[i
]));
122 for (unsigned int i
= 0; i
< ports_system_playback_cnt
; i
++) {
123 sprintf(port_name
, "system:playback_%d", i
+ 1);
124 jack_connect(client
, jack_port_name(fOutputPorts
[ports_system_capture_cnt
+ i
]), port_name
);
130 int JackSapaProxy::Process(jack_nframes_t nframes
, void* arg
)
132 JackSapaProxy
* sapaproxy
= static_cast<JackSapaProxy
*>(arg
);
133 jack_default_audio_sample_t
*in
, *out
;
136 for (unsigned int i
= 0; i
< sapaproxy
->fCapturePorts
; i
++) {
137 in
= (jack_default_audio_sample_t
*)jack_port_get_buffer(sapaproxy
->fInputPorts
[i
] , nframes
);
138 out
= (jack_default_audio_sample_t
*)jack_port_get_buffer(sapaproxy
->fOutputPorts
[i
], nframes
);
140 // TODO: adjust pcm gain each platform here
142 memcpy(out
, in
, sizeof(jack_default_audio_sample_t
) * nframes
);
146 for (unsigned int i
= sapaproxy
->fCapturePorts
; i
< (sapaproxy
->fCapturePorts
+ sapaproxy
->fPlaybackPorts
); i
++) {
147 in
= (jack_default_audio_sample_t
*)jack_port_get_buffer(sapaproxy
->fInputPorts
[i
] , nframes
);
148 out
= (jack_default_audio_sample_t
*)jack_port_get_buffer(sapaproxy
->fOutputPorts
[i
], nframes
);
150 // TODO: adjust pcm gain each platform here
152 memcpy(out
, in
, sizeof(jack_default_audio_sample_t
) * nframes
);