From fd3b25d28208341cbb31f81abf88a98fc45514d0 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 11 Jul 2017 12:45:57 -0500 Subject: [PATCH] add some params to control rate and channels --- src/mod/applications/mod_av/avformat.c | 25 +++++++++++++++++++++++-- src/switch_core_file.c | 2 +- src/switch_event.c | 3 ++- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/mod/applications/mod_av/avformat.c b/src/mod/applications/mod_av/avformat.c index f35b03e336..4fd2e1b655 100644 --- a/src/mod/applications/mod_av/avformat.c +++ b/src/mod/applications/mod_av/avformat.c @@ -1957,6 +1957,19 @@ static switch_status_t av_file_open(switch_file_handle_t *handle, const char *pa fmt->audio_codec = context->audio_codec->id; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "specified audio codec %s %s [%s]\n", tmp, context->audio_codec->name, context->audio_codec->long_name); + + if (!strcasecmp(tmp, "pcm_mulaw")) { + handle->mm.samplerate = 8000; + handle->mm.ab = 64; + } + } + } + + if (handle->params && (tmp = switch_event_get_header(handle->params, "av_video_codec"))) { + if ((context->video_codec = avcodec_find_encoder_by_name(tmp))) { + fmt->video_codec = context->video_codec->id; + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "specified video codec %s %s [%s]\n", + tmp, context->video_codec->name, context->video_codec->long_name); } } @@ -1977,9 +1990,17 @@ static switch_status_t av_file_open(switch_file_handle_t *handle, const char *pa } if (handle->mm.samplerate) { + handle->samplerate = handle->mm.samplerate; + } else { handle->mm.samplerate = handle->samplerate; } + if (handle->mm.channels) { + handle->channels = handle->mm.channels; + } else { + handle->mm.channels = handle->channels; + } + if (!handle->mm.ab) { handle->mm.ab = 128; } @@ -1988,10 +2009,10 @@ static switch_status_t av_file_open(switch_file_handle_t *handle, const char *pa handle->mm.vb = switch_calc_bitrate(handle->mm.vw, handle->mm.vh, 1, handle->mm.fps); } - if (fmt->video_codec != AV_CODEC_ID_NONE) { + if (switch_test_flag(handle, SWITCH_FILE_FLAG_VIDEO) && fmt->video_codec != AV_CODEC_ID_NONE) { const AVCodecDescriptor *desc; - if ((handle->stream_name && (!strcasecmp(handle->stream_name, "rtmp") || !strcasecmp(handle->stream_name, "rtsp") || !strcasecmp(handle->stream_name, "youtube")))) { + if ((handle->stream_name && (!strcasecmp(handle->stream_name, "rtmp") || !strcasecmp(handle->stream_name, "youtube")))) { if (fmt->video_codec != AV_CODEC_ID_H264 ) { fmt->video_codec = AV_CODEC_ID_H264; // force H264 diff --git a/src/switch_core_file.c b/src/switch_core_file.c index 834d8c88ca..a0a80e1dd4 100644 --- a/src/switch_core_file.c +++ b/src/switch_core_file.c @@ -123,7 +123,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_perform_file_open(const char *file, if ((val = switch_event_get_header(fh->params, "samplerate"))) { tmp = atoi(val); - if (tmp > 8000) { + if (tmp >= 8000) { fh->mm.samplerate = tmp; } } diff --git a/src/switch_event.c b/src/switch_event.c index f3b0566ac0..7911d155d4 100644 --- a/src/switch_event.c +++ b/src/switch_event.c @@ -1663,6 +1663,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_create_brackets(char *data, char a, if (!e) { switch_event_create_plain(&e, SWITCH_EVENT_CHANNEL_DATA); + e->flags |= EF_UNIQ_HEADERS; } @@ -1696,7 +1697,7 @@ SWITCH_DECLARE(switch_status_t) switch_event_create_brackets(char *data, char a, if ((inner_var_count = switch_separate_string(var_array[x], '=', inner_var_array, (sizeof(inner_var_array) / sizeof(inner_var_array[0])))) == 2) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, "Parsing variable [%s]=[%s]\n", inner_var_array[0], inner_var_array[1]); + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Parsing variable [%s]=[%s]\n", inner_var_array[0], inner_var_array[1]); switch_event_add_header_string(e, SWITCH_STACK_BOTTOM, inner_var_array[0], inner_var_array[1]); } }