]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
added proper waiting (up to 10ms) for the DAHDI transcoder output frame
authorMoises Silva <moy@sangoma.com>
Fri, 8 May 2009 04:40:32 +0000 (04:40 +0000)
committerMoises Silva <moy@sangoma.com>
Fri, 8 May 2009 04:40:32 +0000 (04:40 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13262 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/codecs/mod_dahdi_codec/mod_dahdi_codec.c

index 8026ac70d00708821339f274bcda8680176bb68b..33dbe59d4c691208a0f6e686b9e826013c22389f 100644 (file)
 #include <fcntl.h>
 #include <errno.h>
 
+/*
+ * some rules to keep in mind for G729 (the frame size may be different for G723)
+ * we cannot write more than SFRAME_SIZE (320) - sizeof(struct rtp_packet) which 
+ * seems to be 266 bytes
+ * if we write less than 160 bytes (1 ulaw frame which is 20 bytes of G729 bytes, a read will block forever)
+ * TODO: do buffering ourselves to provide just the fixed amount of samples that the card expects
+ * */
+#define DAHDI_G729_INPUT_FRAME_SIZE 160
+#define DAHDI_G729_OUTPUT_FRAME_SIZE 20
+
 /*#define DEBUG_DAHDI_CODEC 1*/
 
 #define CODEC_G729_IANA_CODE 18
@@ -221,19 +231,22 @@ static switch_status_t switch_dahdi_init(switch_codec_t *codec, switch_codec_fla
        context->codec_r = (codec->implementation->ianacode == CODEC_G729_IANA_CODE) 
                ? 8 : 12;
 
+
        return SWITCH_STATUS_SUCCESS;
 }
 
 static int wait_for_transcoder(int fd)
 {
-       /* let's wait a bit for the transcoder, if in 20msthe driver does not notify us that its ready to accept more works
+       /* let's wait a bit for the transcoder, if in 20msthe driver does not notify us that its ready to give us something
        then just bail out with 0 bytes encoded/decoded as result, I'd expect the card to hold that buffer and return it later */
        int res = 0;
        struct pollfd readpoll;
        memset(&readpoll, 0, sizeof(readpoll));
        readpoll.fd = fd;
-       readpoll.events = POLLOUT;
-       res = poll(&readpoll, 1, 50);
+       readpoll.events = POLLIN;
+       /* my testing shows that it does not take more than 1ms to encode a 160 bytes frame ulaw to g729,
+          I dont think there is much difference decoding and for g723, waiting 10ms seems more than reasonable */
+       res = poll(&readpoll, 1, 10); 
        return res;
 }