summaryrefslogtreecommitdiffstats
path: root/audio/gsta2dpsink.c
diff options
context:
space:
mode:
authorLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2007-10-25 21:07:50 +0000
committerLuiz Augusto von Dentz <luiz.dentz@openbossa.org>2007-10-25 21:07:50 +0000
commit6a7bdf306c26ac5663ecd9f1637839a7dd0141d4 (patch)
tree24791de0c431b1c3ae6c04d1fa689925d3a77f7e /audio/gsta2dpsink.c
parent4c6834afabcef620f1f5aff0c56b8994171d57d2 (diff)
Fix buffer usage.
Diffstat (limited to 'audio/gsta2dpsink.c')
-rw-r--r--audio/gsta2dpsink.c49
1 files changed, 22 insertions, 27 deletions
diff --git a/audio/gsta2dpsink.c b/audio/gsta2dpsink.c
index 2066496f..a80fd790 100644
--- a/audio/gsta2dpsink.c
+++ b/audio/gsta2dpsink.c
@@ -41,6 +41,14 @@
#include "gsta2dpsink.h"
+enum {
+ NOT_CONFIGURED,
+ CONFIGURING_INIT,
+ CONFIGURING_SENT_CONF,
+ CONFIGURING_RCVD_DEV_CONF,
+ CONFIGURED
+};
+
GST_DEBUG_CATEGORY_STATIC(a2dp_sink_debug);
#define GST_CAT_DEFAULT a2dp_sink_debug
@@ -128,8 +136,9 @@ static gboolean gst_a2dp_sink_stop(GstBaseSink *basesink)
{
GstA2dpSink *self = GST_A2DP_SINK(basesink);
+ GST_INFO_OBJECT(self, "stop");
+
self->con_state = NOT_CONFIGURED;
- self->total = 0;
if (self->watch_id != 0) {
g_source_remove(self->watch_id);
@@ -357,8 +366,10 @@ static gboolean gst_a2dp_sink_conf_resp(GstA2dpSink *sink)
gchar buf[IPC_MTU];
GIOError io_error;
gsize ret;
+ gint total;
struct ipc_packet *pkt = (void *) buf;
struct ipc_data_cfg *cfg = (void *) pkt->data;
+ struct ipc_codec_sbc *sbc = (void *) cfg->data;
memset(buf, 0, sizeof(buf));
@@ -370,7 +381,7 @@ static gboolean gst_a2dp_sink_conf_resp(GstA2dpSink *sink)
return FALSE;
}
- sink->total = ret;
+ total = ret;
if (pkt->type != PKT_TYPE_CFG_RSP) {
GST_ERROR_OBJECT(sink, "Unexpected packet type %d "
"received", pkt->type);
@@ -388,18 +399,6 @@ static gboolean gst_a2dp_sink_conf_resp(GstA2dpSink *sink)
return FALSE;
}
- return TRUE;
-}
-
-static gboolean gst_a2dp_sink_conf_recv_dev_conf(GstA2dpSink *sink)
-{
- gchar buf[IPC_MTU];
- GIOError io_error;
- gsize ret;
- struct ipc_packet *pkt = (void *) buf;
- struct ipc_data_cfg *cfg = (void *) pkt->data;
- struct ipc_codec_sbc *sbc = (void *) cfg->data;
-
io_error = g_io_channel_read(sink->server, (gchar *) sbc,
sizeof(*sbc), &ret);
if (io_error != G_IO_ERROR_NONE) {
@@ -411,15 +410,15 @@ static gboolean gst_a2dp_sink_conf_recv_dev_conf(GstA2dpSink *sink)
return FALSE;
}
- sink->total += ret;
- GST_DEBUG_OBJECT(sink, "OK - %d bytes received", sink->total);
-#if 0
- if (pkt->length != (sink->total - sizeof(struct ipc_packet))) {
+ total += ret;
+ GST_DEBUG_OBJECT(sink, "OK - %d bytes received", total);
+
+ if (pkt->length != (total - sizeof(struct ipc_packet))) {
GST_ERROR_OBJECT(sink, "Error while configuring device: "
"packet size doesn't match");
return FALSE;
}
-#endif
+
memcpy(&sink->data->cfg, cfg, sizeof(*cfg));
GST_DEBUG_OBJECT(sink, "Device configuration:\n\tchannel=%p\n\t"
@@ -516,15 +515,10 @@ static void gst_a2dp_sink_conf_recv_data(GstA2dpSink *sink)
switch (sink->con_state) {
case CONFIGURING_SENT_CONF:
if (gst_a2dp_sink_conf_resp(sink))
- sink->con_state = CONFIGURING_RCVD_CONF_RSP;
- else
- GST_A2DP_SINK_CONFIGURATION_FAIL(sink);
- break;
- case CONFIGURING_RCVD_CONF_RSP:
- if (gst_a2dp_sink_conf_recv_dev_conf(sink))
sink->con_state = CONFIGURING_RCVD_DEV_CONF;
else
GST_A2DP_SINK_CONFIGURATION_FAIL(sink);
+ break;
case CONFIGURING_RCVD_DEV_CONF:
if (gst_a2dp_sink_conf_recv_stream_fd(sink))
GST_A2DP_SINK_CONFIGURATION_SUCCESS(sink);
@@ -569,6 +563,8 @@ static gboolean gst_a2dp_sink_start(GstBaseSink *basesink)
gint sk;
gint err;
+ GST_INFO_OBJECT(self, "start");
+
self->watch_id = 0;
sk = socket(PF_LOCAL, SOCK_STREAM, 0);
@@ -593,10 +589,10 @@ static gboolean gst_a2dp_sink_start(GstBaseSink *basesink)
G_IO_ERR | G_IO_NVAL, server_callback, self);
self->data = g_new0(struct bluetooth_data, 1);
+ memset(self->data, 0, sizeof(struct bluetooth_data));
self->stream = NULL;
self->con_state = NOT_CONFIGURED;
- self->total = 0;
self->waiting_con_conf = FALSE;
@@ -789,7 +785,6 @@ static void gst_a2dp_sink_init(GstA2dpSink *self, GstA2dpSinkClass *klass)
self->stream = NULL;
self->con_state = NOT_CONFIGURED;
- self->total = 0;
self->con_conf_end = g_cond_new();
self->waiting_con_conf = FALSE;