mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-06 12:36:58 +00:00
Fix transcoding performance issue
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@41318 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -75,6 +75,10 @@ static AST_LIST_HEAD_STATIC(translators, translator);
|
|||||||
struct pvt {
|
struct pvt {
|
||||||
int fd;
|
int fd;
|
||||||
int fake;
|
int fake;
|
||||||
|
#ifdef DEBUG_TRANSCODE
|
||||||
|
int totalms;
|
||||||
|
int lasttotalms;
|
||||||
|
#endif
|
||||||
struct zt_transcode_header *hdr;
|
struct zt_transcode_header *hdr;
|
||||||
struct ast_frame f;
|
struct ast_frame f;
|
||||||
};
|
};
|
||||||
@@ -106,7 +110,7 @@ static int zap_framein(struct ast_trans_pvt *pvt, struct ast_frame *f)
|
|||||||
hdr->srcoffset = 0;
|
hdr->srcoffset = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(hdr->srcdata + hdr->srcoffset, f->data, f->datalen);
|
memcpy(hdr->srcdata + hdr->srcoffset + hdr->srclen, f->data, f->datalen);
|
||||||
hdr->srclen += f->datalen;
|
hdr->srclen += f->datalen;
|
||||||
pvt->samples += f->samples;
|
pvt->samples += f->samples;
|
||||||
|
|
||||||
@@ -131,16 +135,15 @@ static struct ast_frame *zap_frameout(struct ast_trans_pvt *pvt)
|
|||||||
pvt->samples = 0;
|
pvt->samples = 0;
|
||||||
} else if (ztp->fake == 1) {
|
} else if (ztp->fake == 1) {
|
||||||
return NULL;
|
return NULL;
|
||||||
} else if (!hdr->srclen) {
|
|
||||||
return NULL;
|
|
||||||
} else {
|
} else {
|
||||||
hdr->dstoffset = 0;
|
if (hdr->dstlen) {
|
||||||
hdr->dstlen = 0;
|
#ifdef DEBUG_TRANSCODE
|
||||||
x = ZT_TCOP_TRANSCODE;
|
ztp->totalms += hdr->dstsamples;
|
||||||
if (ioctl(ztp->fd, ZT_TRANSCODE_OP, &x))
|
if ((ztp->totalms - ztp->lasttotalms) > 8000) {
|
||||||
ast_log(LOG_WARNING, "Failed to transcode: %s\n", strerror(errno));
|
printf("Whee %p, %d (%d to %d)\n", ztp, hdr->dstlen, ztp->lasttotalms, ztp->totalms);
|
||||||
if (!hdr->dstlen)
|
ztp->lasttotalms = ztp->totalms;
|
||||||
return NULL;
|
}
|
||||||
|
#endif
|
||||||
ztp->f.frametype = AST_FRAME_VOICE;
|
ztp->f.frametype = AST_FRAME_VOICE;
|
||||||
ztp->f.subclass = hdr->dstfmt;
|
ztp->f.subclass = hdr->dstfmt;
|
||||||
ztp->f.samples = hdr->dstsamples;
|
ztp->f.samples = hdr->dstsamples;
|
||||||
@@ -149,6 +152,17 @@ static struct ast_frame *zap_frameout(struct ast_trans_pvt *pvt)
|
|||||||
ztp->f.datalen = hdr->dstlen;
|
ztp->f.datalen = hdr->dstlen;
|
||||||
ztp->f.mallocd = 0;
|
ztp->f.mallocd = 0;
|
||||||
pvt->samples -= ztp->f.samples;
|
pvt->samples -= ztp->f.samples;
|
||||||
|
hdr->dstlen = 0;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
if (hdr->srclen) {
|
||||||
|
hdr->dstoffset = AST_FRIENDLY_OFFSET;
|
||||||
|
x = ZT_TCOP_TRANSCODE;
|
||||||
|
if (ioctl(ztp->fd, ZT_TRANSCODE_OP, &x))
|
||||||
|
ast_log(LOG_WARNING, "Failed to transcode: %s\n", strerror(errno));
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &ztp->f;
|
return &ztp->f;
|
||||||
@@ -169,9 +183,16 @@ static int zap_translate(struct ast_trans_pvt *pvt, int dest, int source)
|
|||||||
unsigned int x = ZT_TCOP_RESET;
|
unsigned int x = ZT_TCOP_RESET;
|
||||||
struct pvt *ztp = pvt->pvt;
|
struct pvt *ztp = pvt->pvt;
|
||||||
struct zt_transcode_header *hdr;
|
struct zt_transcode_header *hdr;
|
||||||
|
int flags;
|
||||||
|
|
||||||
if ((fd = open("/dev/zap/transcode", O_RDWR)) < 0)
|
if ((fd = open("/dev/zap/transcode", O_RDWR)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
flags = fcntl(fd, F_GETFL);
|
||||||
|
if (flags > - 1) {
|
||||||
|
if (fcntl(fd, F_SETFL, flags | O_NONBLOCK))
|
||||||
|
ast_log(LOG_WARNING, "Could not set non-block mode!\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if ((hdr = mmap(NULL, sizeof(*hdr), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) {
|
if ((hdr = mmap(NULL, sizeof(*hdr), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) {
|
||||||
ast_log(LOG_ERROR, "Memory Map failed for transcoding (%s)\n", strerror(errno));
|
ast_log(LOG_ERROR, "Memory Map failed for transcoding (%s)\n", strerror(errno));
|
||||||
|
Reference in New Issue
Block a user