Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/bta2dpd/bta2dpd RTP timestamp is now set correctly....



details:   https://anonhg.NetBSD.org/src/rev/a54d3cce02f5
branches:  trunk
changeset: 821654:a54d3cce02f5
user:      nat <nat%NetBSD.org@localhost>
date:      Sun Feb 12 08:25:31 2017 +0000

description:
RTP timestamp is now set correctly.  The streaming socket is set to non
block blocking and connection state machinre improvement.

diffstat:

 usr.sbin/bta2dpd/bta2dpd/bta2dpd.c    |  34 ++++++++++++++++++-----------
 usr.sbin/bta2dpd/bta2dpd/sbc_encode.c |  39 ++++++++++++++++++++++++++++------
 2 files changed, 53 insertions(+), 20 deletions(-)

diffs (185 lines):

diff -r 0fa10f722072 -r a54d3cce02f5 usr.sbin/bta2dpd/bta2dpd/bta2dpd.c
--- a/usr.sbin/bta2dpd/bta2dpd/bta2dpd.c        Sun Feb 12 06:16:33 2017 +0000
+++ b/usr.sbin/bta2dpd/bta2dpd/bta2dpd.c        Sun Feb 12 08:25:31 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bta2dpd.c,v 1.1 2017/01/28 16:55:54 nat Exp $ */
+/* $NetBSD: bta2dpd.c,v 1.2 2017/02/12 08:25:31 nat Exp $ */
 
 /*-
  * Copyright (c) 2015 - 2016 Nathanial Sloss <nathanialsloss%yahoo.com.au@localhost>
@@ -615,7 +615,7 @@
        static uint8_t trans;
        uint8_t buff[1024];
        static size_t offset = 0;
-       int result;
+       int result, flags;
 
        if(avdtpCheckResponse(fd, &isCommand, &trans, &signal, NULL, buff,
            &bufflen, &sep) == ENOMEM) {
@@ -674,6 +674,7 @@
                case AVDTP_SUSPEND:
                case AVDTP_START:
                        avdtpSendAccept(fd, fd, trans, signal);
+                       state = 6;
                        break;
                default:
                        avdtpSendReject(fd, fd, trans, signal);
@@ -703,17 +704,20 @@
 
                        if (!result && verbose)
                                fprintf(stderr, "Bitpool value = %d\n",bitpool);
+                       state = 3;
                        break;
                case AVDTP_SET_CONFIGURATION:
-                       if (state < 5 && !asSpeaker)
+                       if (state == 3 && !asSpeaker)
                                avdtpOpen(fd, fd, mySepInfo.sep);
+                       state = 4;
                        break;
                case AVDTP_OPEN:
-                       if (state < 5)
+                       if (state == 4)
                                state = 5;
                        break;
                case AVDTP_SUSPEND:
                case AVDTP_START:
+                       state = 6;
                        break;
                default:
                        avdtpSendReject(fd, fd, trans, signal);
@@ -723,7 +727,7 @@
        }
 
 
-       if (state != 5)
+       if (state < 5 || state > 7)
                return;
 
        if (asSpeaker) {
@@ -731,8 +735,9 @@
                if ((sc = accept(orighc,(struct sockaddr*)&addr, &len)) < 0)
                        err(EXIT_FAILURE, "stream accept");
 
+       }
+       if (state == 6)
                goto opened_connection;
-       }
 
        memset(&addr, 0, sizeof(addr));
 
@@ -758,31 +763,34 @@
        if (connect(sc,(struct sockaddr*)&addr, sizeof(addr)) < 0)
                return;
 
+       if (!asSpeaker)
+               avdtpStart(fd, fd, mySepInfo.sep); 
+
+       return;
+
 opened_connection:
        if (asSpeaker) {
                event_set(&recv_ev, sc, EV_READ | EV_PERSIST, do_recv, NULL);
                if (event_add(&recv_ev, NULL) < 0)
                        err(EXIT_FAILURE, "recv_ev");
+               state = 7;
        } else {
+               flags = fcntl(sc, F_GETFL, 0);
+               fcntl(sc, F_SETFL, flags | O_NONBLOCK);
                event_set(&interrupt_ev, audfile, EV_READ | EV_PERSIST,
                    do_interrupt, NULL);
                if (event_add(&interrupt_ev, NULL) < 0)
                        err(EXIT_FAILURE, "interrupt_ev");
+               state = 7;
        }
 
-       mtusize = sizeof(uint16_t);
        getsockopt(sc, BTPROTO_L2CAP, SO_L2CAP_OMTU, &mtu, &mtusize);
-
        if (userset_mtu != 0 && userset_mtu > 100 && userset_mtu < mtu)
                mtu = userset_mtu;
        else if (userset_mtu == 0 && mtu >= 500)
                mtu /= 2;
 
-       if (!asSpeaker)
-               avdtpStart(fd, fd, mySepInfo.sep); 
-
-       state = 6;
-
+       mtusize = sizeof(uint16_t);
 }
 
 static void
diff -r 0fa10f722072 -r a54d3cce02f5 usr.sbin/bta2dpd/bta2dpd/sbc_encode.c
--- a/usr.sbin/bta2dpd/bta2dpd/sbc_encode.c     Sun Feb 12 06:16:33 2017 +0000
+++ b/usr.sbin/bta2dpd/bta2dpd/sbc_encode.c     Sun Feb 12 08:25:31 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sbc_encode.c,v 1.1 2017/01/28 16:55:54 nat Exp $ */
+/* $NetBSD: sbc_encode.c,v 1.2 2017/02/12 08:25:31 nat Exp $ */
 
 /*-
  * Copyright (c) 2015 - 2016 Nathanial Sloss <nathanialsloss%yahoo.com.au@localhost>
@@ -822,9 +822,10 @@
        ssize_t len, mySize[16], offset, next_pkt;
        ssize_t pkt_len;
        size_t readsize, totalSize;
+       size_t frequency;
        static size_t ts = 0;
        static uint16_t seqnumber = 0;
-       int numpkts;
+       int numpkts, tries;
 
        global_mode = mode;
        global_bitpool = bitpool;
@@ -855,6 +856,15 @@
        if (global_mode == MODE_MONO)
                global_chan = 1;
 
+       if (global_freq == FREQ_16K)
+               frequency = 16000;
+       else if (global_freq == FREQ_32K)
+               frequency = 32000;
+       else if (global_freq == FREQ_48K)
+               frequency = 48000;
+       else
+               frequency = 44100;
+
        memset(&myHeader, 0, sizeof(myHeader));
        myHeader.id = 0x80;     /* RTP v2 */
        myHeader.id2 = 0x60;    /* payload type 96. */
@@ -911,16 +921,31 @@
        memcpy(whole + offset, frameData, (size_t)next_pkt);
        free(frameData);
 
+       tries = 1;
 send_again:
        len = write(outfd, whole, totalSize);
 
-       if (len == -1 && errno == EAGAIN)
-               goto send_again;
+       if (len == -1 && errno == EAGAIN) {
+               tries --;
+               if (tries >= 0) {
+                       usleep(1);
+                       goto send_again;
+               } else
+                       len = (ssize_t)totalSize;
+       } else if (len == -1 && (errno == EINPROGRESS ||
+           errno == EWOULDBLOCK)) {
+               usleep(1);
+                       len = (ssize_t)totalSize;
+       }
+
+       seqnumber++;
+       ts += (1000000 * (size_t)(global_blocks * global_bands)
+           / frequency) * (size_t)numpkts;
+
        free(whole);
 
-       seqnumber++;
-       ts += (readsize / ((size_t)global_chan * sizeof(int16_t)))  *
-           (size_t)numpkts;
+       if (seqnumber % 96 == 95)
+               usleep(1);
 
        return len;
 }



Home | Main Index | Thread Index | Old Index