Beispiel #1
0
static int headset_button(struct s_headset *headset)
{
	uint16_t sco_handle, sco_mtu;

	if (headset == NULL)
		return 0;
	if (headset->sco_fd != -1) {
		/* close bt_sco audio handle */
		bt_sco_set_fd(headset->handle, -1);
		/* disconnect SCO stream */
		close(headset->sco_fd);
		headset->sco_fd = -1;
		fprintf(stderr, "disconnected SCO channel\n");
		return 1;
	}
	fprintf(stderr, "opened hwdep\n");
	/* connect sco stream */
	if ((headset->sco_fd = sco_connect(&headset->local, &headset->bdaddr, &sco_handle, &sco_mtu)) < 0) {
		perror("Can't connect SCO audio channel");
		return 1;
	}
	fprintf(stderr, "connected SCO channel\n");
	//      write(rd, "RING\r\n", 6);
	fprintf(stderr, "Setting sco fd\n"); 
	bt_sco_set_fd (headset->handle, headset->sco_fd);
	fprintf(stderr, "Done setting sco fd\n"); 
	return 1;
}
/*!
    \internal
*/
void QBluetoothHeadsetService::scoStateChanged(QBluetoothAbstractSocket::SocketState socketState)
{
    switch (socketState) {
        case QBluetoothAbstractSocket::ConnectingState:
            break;
        case QBluetoothAbstractSocket::ConnectedState:
            // This is gonna be ugly...
            m_data->m_scofd = dup(m_data->m_scoSocket->socketDescriptor());
            ::fcntl(m_data->m_scofd, F_SETFD, FD_CLOEXEC);

            delete m_data->m_scoSocket;
            m_data->m_scoSocket = 0;

            if (m_data->m_audioDev)
                bt_sco_set_fd(m_data->m_audioDev, m_data->m_scofd);
            m_data->m_interface->setValue("AudioEnabled", true);
            emit audioStateChanged();
            break;
        case QBluetoothAbstractSocket::ClosingState:
            break;
        case QBluetoothAbstractSocket::UnconnectedState:
            // This happens on a failed connect
            if (m_data->m_scoSocket) {
                m_data->m_scoSocket->deleteLater();
                m_data->m_scoSocket = 0;
            }

            break;
        default:
            break;
    };
}
/*!
    This method is the concrete implementation of the
    QBluetoothAudioGateway interface method of the same name.
    It is called from the QBluetoothHandsfreeAudioGatewayServer
    class, which acts as a forwarding agent.

    \sa QBluetoothHandsfreeAudioGatewayServer
*/
void QBluetoothHeadsetService::releaseAudio()
{
    if (m_data->m_scoSocket) {
        delete m_data->m_scoSocket;
        m_data->m_scoSocket = 0;
    }

    if (m_data->m_scofd == -1)
        return;

    if (m_data->m_audioDev)
        bt_sco_set_fd(m_data->m_audioDev, -1);
    ::close(m_data->m_scofd);
    m_data->m_scofd = -1;

    m_data->m_interface->setValue("AudioEnabled", false);
    emit audioStateChanged();
}
Beispiel #4
0
static void headset_destroy(struct s_headset *headset)
{
	if (headset == NULL)
		return;
	if (headset->sco_fd != -1) {
		bt_sco_set_fd(headset->handle, -1);
		close(headset->sco_fd);
	}

	sleep(1);
	if (headset->rfcomm_fd != -1) 
		close(headset->rfcomm_fd);
	if (headset->handle != NULL) 
		snd_hwdep_close(headset->handle);
	headset->sco_fd = -1;
	headset->rfcomm_fd = -1;
	headset->handle = NULL;
}