예제 #1
0
static int _applemidi_disconnect( struct MIDIDriverAppleMIDI * driver, int fd ) {
  struct RTPPeer * peer = NULL;
  RTPSessionNextPeer( driver->rtp_session, &peer );
  while( peer != NULL ) {
    _applemidi_disconnect_peer( driver, peer );
    peer = NULL; /* peer was removed, find the new first */
    RTPSessionNextPeer( driver->rtp_session, &peer );
  }
  if( fd == driver->control_socket || fd == 0 ) {
    MIDIRunloopSourceClearRead( driver->base.rls, driver->control_socket );
    MIDIRunloopSourceClearWrite( driver->base.rls, driver->control_socket );
    if( driver->control_socket > 0 ) {
      if( close( driver->control_socket ) ) {
        return 1;
      }
      driver->control_socket = 0;
    }
  }

  if( fd == driver->rtp_socket || fd == 0 ) {
    MIDIRunloopSourceClearRead( driver->base.rls, driver->rtp_socket );
    MIDIRunloopSourceClearWrite( driver->base.rls, driver->rtp_socket );
    if( driver->rtp_socket > 0 ) {
      if( close( driver->rtp_socket ) ) {
        return 1;
      }
      driver->rtp_socket = 0;
    }
  }

  return 0;
}
예제 #2
0
static int _applemidi_disconnect(struct MIDIDriverAppleMIDI *driver,
				 struct socket *sock)
{
	struct RTPPeer *peer = NULL;
	RTPSessionNextPeer(driver->rtp_session, &peer);
	while (peer != NULL) {
		_applemidi_disconnect_peer(driver, peer);
		peer = NULL;
		/* peer was removed, find the new first*/
		RTPSessionNextPeer(driver->rtp_session, &peer);
	}

	if (sock == driver->control_socket || sock == NULL) {
		if (driver->control_socket != NULL) {
			sock_release(driver->control_socket);
			driver->control_socket = NULL;
			pr_debug("control released\n");
		}
	}
	if (sock == driver->rtp_socket || sock == NULL) {
		if (driver->rtp_socket != NULL) {
			sock_release(driver->rtp_socket);
			driver->rtp_socket = NULL;
			pr_debug("rtp released\n");
		}
	}
	return 0;
}
예제 #3
0
static int _applemidi_idle_timeout( void * drv, struct timespec * ts ) {
  struct MIDIDriverAppleMIDI * driver = drv;
  struct sockaddr * addr;
  socklen_t size;

  _applemidi_update_runloop_source( driver );

  RTPSessionNextPeer( driver->rtp_session, &(driver->peer) );
  if( driver->peer != NULL ) {
    /* check if receiver feedback needs to be sent */
    if( driver->sync == 0 ) {
      /* no sync packets active. start new sync */
      RTPPeerGetAddress( driver->peer, &size, &addr );
      return _applemidi_start_sync( driver, driver->rtp_socket, size, addr );
    }
  }

  /* check for messages in dispatch (incoming) queue:
   *   if message needs to be dispatched (timestamp >= now+latency)
   *   call MIDIDriverAppleMIDIReceiveMessage
   * send receiver feedback
   * if the last synchronization happened a certain time ago, synchronize again */

  return 0;
}
예제 #4
0
void _applemidi_idle_timeout(unsigned long data)
{
	struct sockaddr_in *addr;
	int size;

	struct MIDIDriverAppleMIDI *driver = (struct MIDIDriverAppleMIDI *)data;
	mod_timer(&driver->timer, jiffies + msecs_to_jiffies(1500));

	pr_debug("====called timeout (%ld) dat: %lx ====\n", jiffies, data);

	if (spin_trylock(&(driver->lock))) {
		RTPSessionNextPeer(driver->rtp_session, &(driver->peer));
		if (driver->peer != NULL) {
			/* check if receiver feedback needs to be sent */
			if (driver->sync == 0) {
				/* no sync packets active. start new sync */
				RTPPeerGetAddress(driver->peer, &size, &addr);

				pr_debug("start sync with client: %pI4\n",
					 &addr->sin_addr.s_addr);
				_applemidi_start_sync(
				    driver, driver->rtp_socket->sk, size, addr);
				// no return
			}
		}
		spin_unlock(&(driver->lock));
	} else {
		pr_warn("could not so sync timeout because of midi event\n");
	}
	//
	// /* check for messages in dispatch (incoming) queue:
	//  *   if message needs to be dispatched (timestamp >= now+latency)
	//  *   call MIDIDriverAppleMIDIReceiveMessage
	//  * send receiver feedback
	//  * if the last synchronization happened a certain time ago,
	// synchronize again */
	//
	// return 0;
}