Changeset 4825:4f866dedc5e6 in roaraudio
- Timestamp:
- 03/29/11 00:08:31 (13 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- roard
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
roard/driver_jack.c
r4708 r4825 3 3 /* 4 4 * Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2011 5 * Copyright (C) Nedko Arnaudov <nedko@arnaudov.name> - 2010 5 6 * 6 7 * This file is part of roard a part of RoarAudio, … … 27 28 28 29 #ifdef ROAR_HAVE_LIBJACK 30 31 static void unregister_ports(struct driver_jack * self) 32 { 33 while(self->channels--) 34 { 35 if ( self->ports_in != NULL ) 36 if ( self->ports_in [self->channels] != NULL ) 37 jack_port_unregister(self->client, self->ports_in [self->channels]); 38 if ( self->ports_out[self->channels] != NULL ) 39 jack_port_unregister(self->client, self->ports_out[self->channels]); 40 } 41 } 42 29 43 int driver_jack_open_vio (struct roar_vio_calls * inst, 30 44 char * device, … … 33 47 struct roar_stream_server * sstream) { 34 48 struct driver_jack * self; 49 char port_name[128]; 50 jack_nframes_t new_rate; 51 int autoconfig = 0; 52 int recsource = 0; 35 53 36 54 // we are not FH Safe, return error if fh != -1: 37 55 if ( fh != -1 ) 38 56 return -1; 57 58 if ( sstream != NULL ) { 59 autoconfig = streams_get_flag(ROAR_STREAM(sstream)->id, ROAR_FLAG_AUTOCONF); 60 recsource = streams_get_flag(ROAR_STREAM(sstream)->id, ROAR_FLAG_RECSOURCE); 61 } 39 62 40 63 // set up VIO: … … 57 80 inst->inst = self; 58 81 59 if ( (self->client = jack_client_ new("roard")) == NULL ) {82 if ( (self->client = jack_client_open("roard", JackNullOption, NULL)) == NULL ) { 60 83 roar_mm_free(self); 61 84 return -1; 62 85 } 63 86 64 // return -1 on error or 0 on no error. 87 new_rate = jack_get_sample_rate(self->client); 88 89 // need to check if we need to change stream's parameters: 90 if ( info->rate != new_rate || info->bits != 32 || info->codec != ROAR_CODEC_DEFAULT ) { 91 if ( autoconfig ) { 92 // we are allowed to change the parameters 93 info->rate = new_rate; 94 info->bits = 32; 95 info->codec = ROAR_CODEC_DEFAULT; 96 } else { 97 // we are not allowed to change the parameters 98 ROAR_WARN("driver_jack_open_vio(*): Can not open jack driver with given parameters, try -oO ...,autoconf"); 99 goto free_close; 100 } 101 } 102 103 if ( recsource ) 104 if ( (self->ports_in = roar_mm_malloc(sizeof(jack_port_t *) * info->channels)) == NULL ) 105 goto free_close; 106 107 if ( (self->ports_out = roar_mm_malloc(sizeof(jack_port_t *) * info->channels)) == NULL ) 108 goto free_ins; 109 110 // NULL ports so we do not segfaul if something goes wrong. 111 if ( self->ports_in != NULL ) 112 memset(self->ports_in, 0, sizeof(jack_port_t *) * info->channels); 113 memset(self->ports_in, 0, sizeof(jack_port_t *) * info->channels); 114 115 for (self->channels = 0; self->channels < info->channels; self->channels++) { 116 if ( recsource ) { 117 sprintf(port_name, "in_%03u", self->channels); 118 if ( (self->ports_in [self->channels] = jack_port_register(self->client, port_name, 119 JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0)) == NULL ) 120 goto unregister_ports; 121 } 122 123 sprintf(port_name, "out_%03u", self->channels); 124 if ( (self->ports_out[self->channels] = jack_port_register(self->client, port_name, 125 JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0)) == NULL ) { 126 jack_port_unregister(self->client, self->ports_in[self->channels]); 127 goto unregister_ports; 128 } 129 } 130 131 if (jack_activate(self->client) != 0) 132 goto unregister_ports; 133 65 134 return 0; 135 136 unregister_ports: 137 unregister_ports(self); 138 free_ins: 139 if ( self->ports_in != NULL ) 140 roar_mm_free(self->ports_in); 141 free_close: 142 jack_client_close(self->client); 143 roar_mm_free(self); 144 return -1; // error 66 145 } 67 146 … … 165 244 // close and free everything in here... 166 245 246 jack_deactivate(self->client); 247 unregister_ports(self); 167 248 jack_client_close(self->client); 168 249 -
roard/include/driver_jack.h
r4708 r4825 29 29 struct driver_jack { 30 30 jack_client_t * client; 31 jack_port_t * port_out; 31 unsigned int channels; 32 jack_port_t ** ports_in; 33 jack_port_t ** ports_out; 32 34 }; 33 35
Note: See TracChangeset
for help on using the changeset viewer.