~ubuntu-branches/ubuntu/wily/bluez/wily

« back to all changes in this revision

Viewing changes to audio/pcm_bluetooth.c

ImportĀ upstreamĀ versionĀ 4.81

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 *
3
3
 *  BlueZ - Bluetooth protocol stack for Linux
4
4
 *
5
 
 *  Copyright (C) 2006-2007  Nokia Corporation
6
 
 *  Copyright (C) 2004-2009  Marcel Holtmann <marcel@holtmann.org>
 
5
 *  Copyright (C) 2006-2010  Nokia Corporation
 
6
 *  Copyright (C) 2004-2010  Marcel Holtmann <marcel@holtmann.org>
7
7
 *
8
8
 *
9
9
 *  This library is free software; you can redistribute it and/or
146
146
 
147
147
static int audioservice_send(int sk, const bt_audio_msg_header_t *msg);
148
148
static int audioservice_expect(int sk, bt_audio_msg_header_t *outmsg,
149
 
                                int expected_type);
 
149
                                                        int expected_type);
150
150
 
151
151
static int bluetooth_start(snd_pcm_ioplug_t *io)
152
152
{
237
237
                ret = poll(fds, 2, poll_timeout);
238
238
 
239
239
                if (ret < 0) {
240
 
                        SNDERR("poll error: %s (%d)", strerror(errno), errno);
241
 
                        if (errno != EINTR)
 
240
                        if (errno != EINTR) {
 
241
                                SNDERR("poll error: %s (%d)", strerror(errno),
 
242
                                                                errno);
242
243
                                break;
 
244
                        }
243
245
                } else if (ret > 0) {
244
246
                        ret = (fds[0].revents) ? 0 : 1;
245
247
                        SNDERR("poll fd %d revents %d", ret, fds[ret].revents);
522
524
}
523
525
 
524
526
static int bluetooth_a2dp_init(struct bluetooth_data *data,
525
 
                                snd_pcm_hw_params_t *params)
 
527
                                        snd_pcm_hw_params_t *params)
526
528
{
527
529
        struct bluetooth_alsa_config *cfg = &data->alsa_config;
528
530
        sbc_capabilities_t *cap = &data->a2dp.sbc_capabilities;
958
960
 
959
961
static snd_pcm_sframes_t bluetooth_a2dp_read(snd_pcm_ioplug_t *io,
960
962
                                const snd_pcm_channel_area_t *areas,
961
 
                                snd_pcm_uframes_t offset,
962
 
                                snd_pcm_uframes_t size)
 
963
                                snd_pcm_uframes_t offset, snd_pcm_uframes_t size)
963
964
{
964
965
        snd_pcm_uframes_t ret = 0;
965
966
        return ret;
1007
1008
        struct bluetooth_a2dp *a2dp = &data->a2dp;
1008
1009
        snd_pcm_sframes_t ret = 0;
1009
1010
        unsigned int bytes_left;
1010
 
        int frame_size, encoded, written;
 
1011
        int frame_size, encoded;
 
1012
        ssize_t written;
1011
1013
        uint8_t *buff;
1012
1014
 
1013
1015
        DBG("areas->step=%u areas->first=%u offset=%lu size=%lu",
1050
1052
        }
1051
1053
 
1052
1054
        /* Check if we have any left over data from the last write */
1053
 
        if (data->count > 0 && (bytes_left - data->count) >= a2dp->codesize) {
1054
 
                int additional_bytes_needed = a2dp->codesize - data->count;
 
1055
        if (data->count > 0) {
 
1056
                unsigned int additional_bytes_needed =
 
1057
                                                a2dp->codesize - data->count;
 
1058
                if (additional_bytes_needed > bytes_left)
 
1059
                        goto out;
1055
1060
 
1056
1061
                memcpy(data->buffer + data->count, buff,
1057
1062
                                                additional_bytes_needed);
1122
1127
                }
1123
1128
        }
1124
1129
 
 
1130
out:
1125
1131
        /* Copy the extra to our temp buffer for the next write */
1126
1132
        if (bytes_left > 0) {
1127
1133
                memcpy(data->buffer + data->count, buff, bytes_left);
1584
1590
}
1585
1591
 
1586
1592
static int audioservice_expect(int sk, bt_audio_msg_header_t *rsp,
1587
 
                                int expected_name)
 
1593
                                                        int expected_name)
1588
1594
{
1589
1595
        bt_audio_error_t *error;
1590
1596
        int err = audioservice_recv(sk, rsp);
1640
1646
        return 0;
1641
1647
}
1642
1648
 
1643
 
static int bluetooth_init(struct bluetooth_data *data, snd_pcm_stream_t stream,
1644
 
                                snd_config_t *conf)
 
1649
static int bluetooth_init(struct bluetooth_data *data,
 
1650
                                snd_pcm_stream_t stream, snd_config_t *conf)
1645
1651
{
1646
1652
        int sk, err;
1647
1653
        struct bluetooth_alsa_config *alsa_conf = &data->alsa_config;
1769
1775
        return 0;
1770
1776
 
1771
1777
error:
1772
 
        bluetooth_exit(data);
 
1778
        if (data)
 
1779
                bluetooth_exit(data);
1773
1780
 
1774
1781
        return err;
1775
1782
}