[asterisk-commits] sruffell: branch sruffell/asterisk-1.4-transcoder r114868 - /team/sruffell/as...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Apr 29 18:54:11 CDT 2008


Author: sruffell
Date: Tue Apr 29 18:54:10 2008
New Revision: 114868

URL: http://svn.digium.com/view/asterisk?view=rev&rev=114868
Log:
Switched back to using framein / frameout.

Modified:
    team/sruffell/asterisk-1.4-transcoder/codecs/codec_zap.c

Modified: team/sruffell/asterisk-1.4-transcoder/codecs/codec_zap.c
URL: http://svn.digium.com/view/asterisk/team/sruffell/asterisk-1.4-transcoder/codecs/codec_zap.c?view=diff&rev=114868&r1=114867&r2=114868
==============================================================================
--- team/sruffell/asterisk-1.4-transcoder/codecs/codec_zap.c (original)
+++ team/sruffell/asterisk-1.4-transcoder/codecs/codec_zap.c Tue Apr 29 18:54:10 2008
@@ -133,41 +133,81 @@
 static int zap_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
 {
 	int res;
-	unsigned char *dst = (unsigned char *)pvt->outbuf + pvt->datalen;
 	struct pvt *ztp = pvt->pvt;
 
-	if (!f->subclass) {
+	if (f->subclass) {
+		/* Give the frame to the hardware transcoder... */
+		res = write(ztp->fd, f->data, f->datalen); 
+		if (-1 == res) {
+			ast_log(LOG_ERROR, "Failed to write to /dev/transcode: %s\n", strerror(errno));
+		}
+		if (f->datalen != res) {
+			ast_log(LOG_ERROR, "Requested write of %d bytes, but only wrote %d bytes.\n", f->datalen, res);
+		}
+		res = -1;
+		pvt->samples += f->samples;
+	} else {
 		/* Fake a return frame for calculation purposes */
 		ztp->fake = 2;
 		pvt->samples = f->samples;
-		return 0;
-	}
-
-	/* Give the frame to the hardware transcoder... */
-	res = write(ztp->fd,f->data, f->datalen); 
-	if (-1 == res) {
-		ast_log(LOG_ERROR, "Failed to write to /dev/transcode: %s\n", strerror(errno));
-		return -1;
-	}
-	if (f->datalen != res) {
-		ast_log(LOG_ERROR, "Requested write of %d bytes, but only wrote %d bytes.\n", f->datalen, res);
-	}
-
-	/* Wait for the results.... */
-	res = read(ztp->fd, dst, pvt->t->buf_size - pvt->datalen);
-	if (-1 == res) {
-		ast_log(LOG_ERROR, "Failed to read from /dev/transcode: %s\n", strerror(errno));
-		return -1;
-	}
-	if (0 == res) {
-		ast_log(LOG_NOTICE, "Timeout waiting for transcoder.\n");
-		return -1;
-	}
-
-	pvt->samples += res;
-	pvt->datalen += res;
-
-	return 0;
+		res = 0;
+	}
+	return res;
+}
+
+static struct ast_frame *zap_frameout(struct ast_trans_pvt *pvt)
+{
+	struct pvt *ztp = pvt->pvt;
+
+	if (0 == ztp->fake) {
+		int res;
+		/* Let's check to see if there is a new frame for us.... */
+		res = read(ztp->fd, pvt->outbuf + pvt->datalen, pvt->t->buf_size - pvt->datalen);
+		if (-1 == res) {
+			if (EWOULDBLOCK == errno) {
+				/* Nothing waiting... */
+				return NULL;
+			} else {
+				ast_log(LOG_ERROR, "Failed to read from /dev/transcode: %s\n", strerror(errno));
+				return NULL;
+			}
+		} else {
+			pvt->f.samples = res;
+			pvt->f.datalen = res;
+			pvt->datalen = 0;
+			pvt->f.frametype = AST_FRAME_VOICE;
+			pvt->f.subclass = 1 <<  (pvt->t->dstfmt);
+			pvt->f.mallocd = 0;
+			pvt->f.offset = AST_FRIENDLY_OFFSET;
+			pvt->f.src = pvt->t->name;
+			pvt->f.data = pvt->outbuf;
+			ast_set_flag(&pvt->f, AST_FRFLAG_FROM_TRANSLATOR);
+
+			return &pvt->f;
+		}
+
+	} else if (2 == ztp->fake) {
+
+		ztp->fake = 1;
+		pvt->f.frametype = AST_FRAME_VOICE;
+		pvt->f.subclass = 0;
+		pvt->f.samples = 160;
+		pvt->f.data = NULL;
+		pvt->f.offset = 0;
+		pvt->f.datalen = 0;
+		pvt->f.mallocd = 0;
+		ast_set_flag(&pvt->f, AST_FRFLAG_FROM_TRANSLATOR);
+		pvt->samples = 0;
+
+		return &pvt->f;
+
+	} else if (1 == ztp->fake) {
+
+		return NULL;
+
+	}
+	/* Shouldn't get here... */
+	return NULL;
 }
 
 static void zap_destroy(struct ast_trans_pvt *pvt)
@@ -254,6 +294,7 @@
 	zt->t.dstfmt = (1 << dst);
 	zt->t.newpvt = zap_new;
 	zt->t.framein = zap_framein;
+	zt->t.frameout = zap_frameout;
 	zt->t.destroy = zap_destroy;
 	zt->t.sample = fakesrc_sample;
 	zt->t.useplc = global_useplc;




More information about the asterisk-commits mailing list