static int bluetooth_init(struct bluetooth_data *data) { int sk, err; struct timeval tv = {.tv_sec = RECV_TIMEOUT}; DBG("bluetooth_init"); sk = bt_audio_service_open(); if (sk < 0) { ERR("bt_audio_service_open failed\n"); return -errno; } err = setsockopt(sk, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv)); if (err < 0) { ERR("bluetooth_init setsockopt(SO_RCVTIMEO) failed %d", err); return err; } data->server.fd = sk; data->server.events = POLLIN; data->state = A2DP_STATE_INITIALIZED; return 0; }
static gboolean gst_avdtp_sink_start(GstBaseSink *basesink) { GstAvdtpSink *self = GST_AVDTP_SINK(basesink); gint sk; gint err; GST_INFO_OBJECT(self, "start"); self->watch_id = 0; sk = bt_audio_service_open(); if (sk <= 0) { err = errno; GST_ERROR_OBJECT(self, "Cannot open connection to bt " "audio service: %s %d", strerror(err), err); goto failed; } self->server = g_io_channel_unix_new(sk); self->watch_id = g_io_add_watch(self->server, G_IO_HUP | G_IO_ERR | G_IO_NVAL, server_callback, self); self->data = g_new0(struct bluetooth_data, 1); self->stream = NULL; self->stream_caps = NULL; self->mp3_using_crc = -1; self->channel_mode = -1; if (!gst_avdtp_sink_get_capabilities(self)) { GST_ERROR_OBJECT(self, "failed to get capabilities " "from device"); goto failed; } return TRUE; failed: bt_audio_service_close(sk); return FALSE; }