Ticket #988: jack-use-more-ports.patch

File jack-use-more-ports.patch, 2.3 KB (added by jannis_achstetter@…, 18 years ago)

Patch to make ao_jack connect to all ports found

  • libao2/ao_jack.

    old new  
    229229    {NULL}
    230230  };
    231231  int port_flags = JackPortIsInput;
    232   int i;
     232  int i, j;
    233233  estimate = 1;
    234234  if (subopt_parse(ao_subdevice, subopts) != 0) {
    235235    print_help();
     
    252252  jack_set_process_callback(client, outputaudio, 0);
    253253
    254254  // list matching ports
     255  mp_msg(MSGT_AO, MSGL_V, "[JACK] searching for ports named \"%s\" to connect to\n", port_name);
     256
    255257  if (!port_name)
    256258    port_flags |= JackPortIsPhysical;
    257259  matching_ports = jack_get_ports(client, port_name, NULL, port_flags);
     
    260262    mp_msg(MSGT_AO, MSGL_FATAL, "[JACK] no physical ports available\n");
    261263    goto err_out;
    262264  }
     265
     266  mp_msg(MSGT_AO, MSGL_V, "[JACK] We have %d channels and found %d ports\n", channels, num_ports);
     267
     268  // originally, port-connections were limited here
     269  // num_ports will be set to channels futher down, after connecting the ports
     270/*
    263271  if (channels > num_ports) channels = num_ports;
    264272  num_ports = channels;
     273*/
    265274
    266   // create out output ports
    267   for (i = 0; i < num_ports; i++) {
     275  // create output ports
     276  for (i = 0; i < channels; i++) {
    268277    char pname[30];
    269278    snprintf(pname, 30, "out_%d", i);
    270279    ports[i] = jack_port_register(client, pname, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
     
    278287    goto err_out;
    279288  }
    280289  for (i = 0; i < num_ports; i++) {
    281     if (jack_connect(client, jack_port_name(ports[i]), matching_ports[i])) {
     290    // this is quite a hack since it assumes that we only found ports that
     291    // "fit well" with our number of channels
     292    j = i % channels;
     293    /* printf("Connecting our port %d to matching port %d (%s) ... ", j, i, matching_ports[i]); */
     294    if (jack_connect(client, jack_port_name(ports[j]), matching_ports[i])) {
    282295      mp_msg(MSGT_AO, MSGL_FATAL, "[JACK] connecting failed\n");
    283296      goto err_out;
     297    } else {
     298      /* printf("connection ok!\n"); */
    284299    }
    285300  }
     301
     302  // moved here; mplayer crashes if we don't set this, used again at outputaudio
     303  // (wouldn't it be better to use channels instead of num_ports in the callback-functions?)
     304  num_ports = channels;
     305
    286306  rate = jack_get_sample_rate(client);
    287307  jack_latency = (float)(jack_port_get_total_latency(client, ports[0]) +
    288308                         jack_get_buffer_size(client)) / (float)rate;