Review Board 1.7.16


wideband streaming with res_musiconhold

Review Request #3112 - Created Jan. 9, 2014 and submitted

wdoekes
trunk
Reviewers
asterisk-dev
Asterisk
When streaming mp3s or using a custom musiconhold app, selecting format=sln16 wasn't possible. The audio would become choppy and unbearable.

The cause is that the reader only feeds 8kHz of info to asterisk per second, while we require 16kHz.
The basic class->format calculation worked on Asterisk 11 with the following scenario. I added a bit of documentation and it still compiles.


[default]
mode=custom
;application=/etc/asterisk/musiconhold.sh 8000
;format=slin
application=/etc/asterisk/musiconhold.sh 16000
format=slin16


#!/bin/sh
hz="$1"
test -z "$hz" && hz=8000
mp3toraw="/usr/bin/madplay -Q -o raw:- --mono -b 16 -R $hz -a -12 -"
cat my_audio_file.mp3 | $mp3toraw

Diff revision 1 (Latest)

  1. /trunk/res/res_musiconhold.c: Loading...
/trunk/res/res_musiconhold.c
Revision 405210 New Change
[20] 701 lines
[+20] [+] static void *monmp3thread(void *data)
702
			if (ast_poll(&pfd, 1, -1) > 0) {
702
			if (ast_poll(&pfd, 1, -1) > 0) {
703
				if (ast_timer_ack(class->timer, 1) < 0) {
703
				if (ast_timer_ack(class->timer, 1) < 0) {
704
					ast_log(LOG_ERROR, "Failed to acknowledge timer for mp3player\n");
704
					ast_log(LOG_ERROR, "Failed to acknowledge timer for mp3player\n");
705
					return NULL;
705
					return NULL;
706
				}
706
				}
707
				res = 320;
707
				/* 25 samples per second => 40ms framerate => 320 samples */

    
   
708
				res = 320; /* 320/40 = 8 samples/ms */
708
			} else {
709
			} else {
709
				ast_log(LOG_WARNING, "poll() failed: %s\n", strerror(errno));
710
				ast_log(LOG_WARNING, "poll() failed: %s\n", strerror(errno));
710
				res = 0;
711
				res = 0;
711
			}
712
			}
712
			pthread_testcancel();
713
			pthread_testcancel();
[+20] [20] 10 lines
[+20] static void *monmp3thread(void *data)
723
				pthread_testcancel();
724
				pthread_testcancel();
724
			} else {
725
			} else {
725
				ast_log(LOG_NOTICE, "Request to schedule in the past?!?!\n");
726
				ast_log(LOG_NOTICE, "Request to schedule in the past?!?!\n");
726
				deadline = tv_tmp;
727
				deadline = tv_tmp;
727
			}
728
			}
728
			res = 8 * MOH_MS_INTERVAL;	/* 8 samples per millisecond */
729
			/* 10 samples per second (MOH_MS_INTERVAL) => 100ms framerate => 800 samples */

    
   
730
			res = 8 * MOH_MS_INTERVAL; /* 800/100 = 8 samples/ms */
729
		}
731
		}

    
   
732
		/* For non-8000Hz formats, we need to alter the resolution */

    
   
733
		res = res * ast_format_rate(&class->format) / 8000;

    
   
734

   
730
		if ((strncasecmp(class->dir, "http://", 7) && strcasecmp(class->dir, "nodir")) && AST_LIST_EMPTY(&class->members))
735
		if ((strncasecmp(class->dir, "http://", 7) && strcasecmp(class->dir, "nodir")) && AST_LIST_EMPTY(&class->members))
731
			continue;
736
			continue;
732
		/* Read mp3 audio */
737
		/* Read mp3 audio */
733
		len = ast_codec_get_len(&class->format, res);
738
		len = ast_codec_get_len(&class->format, res);
734

    
   
739

   
[+20] [20] 1334 lines
  1. /trunk/res/res_musiconhold.c: Loading...

https://reviewboard.asterisk.org/ runs on a server provided by Digium, Inc. and uses bandwidth donated to the open source Asterisk community by API Digital Communications in Huntsville, AL USA.
Please report problems with this site to asteriskteam@digium.com.