Changeset 4825:4f866dedc5e6 in roaraudio


Ignore:
Timestamp:
03/29/11 00:08:31 (13 years ago)
Author:
phi
Branch:
default
Phase:
public
Message:

merged some code by Nedko Arnaudov and updated it to current interface, fixed some possible segfaults (uninited pointers)

Location:
roard
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • roard/driver_jack.c

    r4708 r4825  
    33/* 
    44 *      Copyright (C) Philipp 'ph3-der-loewe' Schafft - 2009-2011 
     5 *      Copyright (C) Nedko Arnaudov <nedko@arnaudov.name> - 2010 
    56 * 
    67 *  This file is part of roard a part of RoarAudio, 
     
    2728 
    2829#ifdef ROAR_HAVE_LIBJACK 
     30 
     31static 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 
    2943int driver_jack_open_vio  (struct roar_vio_calls * inst, 
    3044                           char * device, 
     
    3347                           struct roar_stream_server * sstream) { 
    3448 struct driver_jack * self; 
     49 char port_name[128]; 
     50 jack_nframes_t new_rate; 
     51 int autoconfig            = 0; 
     52 int recsource             = 0; 
    3553 
    3654 // we are not FH Safe, return error if fh != -1: 
    3755 if ( fh != -1 ) 
    3856  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 } 
    3962 
    4063 // set up VIO: 
     
    5780 inst->inst     = self; 
    5881 
    59  if ( (self->client = jack_client_new("roard")) == NULL ) { 
     82 if ( (self->client = jack_client_open("roard", JackNullOption, NULL)) == NULL ) { 
    6083  roar_mm_free(self); 
    6184  return -1; 
    6285 } 
    6386 
    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 
    65134 return 0; 
     135 
     136unregister_ports: 
     137 unregister_ports(self); 
     138free_ins: 
     139 if ( self->ports_in != NULL ) 
     140  roar_mm_free(self->ports_in); 
     141free_close: 
     142 jack_client_close(self->client); 
     143 roar_mm_free(self); 
     144 return -1; // error 
    66145} 
    67146 
     
    165244 // close and free everything in here... 
    166245 
     246 jack_deactivate(self->client); 
     247 unregister_ports(self); 
    167248 jack_client_close(self->client); 
    168249 
  • roard/include/driver_jack.h

    r4708 r4825  
    2929struct driver_jack { 
    3030 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; 
    3234}; 
    3335 
Note: See TracChangeset for help on using the changeset viewer.