diff options
Diffstat (limited to 'pjsip')
-rw-r--r-- | pjsip/include/pjsua-lib/pjsua.h | 15 | ||||
-rw-r--r-- | pjsip/src/pjsua-lib/pjsua_media.c | 53 |
2 files changed, 55 insertions, 13 deletions
diff --git a/pjsip/include/pjsua-lib/pjsua.h b/pjsip/include/pjsua-lib/pjsua.h index 39d5caf3..8eeceed8 100644 --- a/pjsip/include/pjsua-lib/pjsua.h +++ b/pjsip/include/pjsua-lib/pjsua.h @@ -2531,12 +2531,15 @@ PJ_DECL(pj_status_t) pjsua_player_destroy(pjsua_player_id id); * Create a file recorder, and automatically connect this recorder to * the conference bridge. * - * @param filename Output file name. - * @param file_format Specify the file format (currently only WAV is - * supported, so the value MUST be zero). - * @param encoding Specify the encoding to be applied to the file. - * Currently only 16bit raw PCM is supported, so - * the value must be NULL. + * @param filename Output file name. The function will determine the + * default format to be used based on the file extension. + * Currently ".wav" is supported on all platforms, and + * also ".mp3" is support on Windows. + * @param file_format This option is obsolete. + * @param encoding Optionally specify the encoding to be applied to the + * file. By default (if NULL is specified), the encoding + * is determined from the file extension (i.e. 16bit PCM + * is used for the WAV files). * @param max_size Maximum file size. Specify -1 to remove size * limitation. * @param options Optional options. diff --git a/pjsip/src/pjsua-lib/pjsua_media.c b/pjsip/src/pjsua-lib/pjsua_media.c index 63527f71..c94265d0 100644 --- a/pjsip/src/pjsua-lib/pjsua_media.c +++ b/pjsip/src/pjsua-lib/pjsua_media.c @@ -802,13 +802,23 @@ PJ_DEF(pj_status_t) pjsua_recorder_create( const pj_str_t *filename, unsigned options, pjsua_recorder_id *p_id) { + enum Format + { + FMT_UNKNOWN, + FMT_WAV, + FMT_MP3, + }; unsigned slot, file_id; char path[128]; + pj_str_t ext; pjmedia_port *port; pj_status_t status; + /* Filename must present */ + PJ_ASSERT_RETURN(filename != NULL, PJ_EINVAL); + /* Don't support max_size at present */ - PJ_ASSERT_RETURN(max_size == 0, PJ_EINVAL); + PJ_ASSERT_RETURN(max_size == 0 || max_size == -1, PJ_EINVAL); /* Don't support file format at present */ PJ_ASSERT_RETURN(file_format == 0, PJ_EINVAL); @@ -819,6 +829,21 @@ PJ_DEF(pj_status_t) pjsua_recorder_create( const pj_str_t *filename, if (pjsua_var.rec_cnt >= PJ_ARRAY_SIZE(pjsua_var.recorder)) return PJ_ETOOMANY; + /* Determine the file format */ + ext.ptr = filename->ptr + filename->slen - 4; + ext.slen = 4; + + if (pj_stricmp2(&ext, ".wav") == 0) + file_format = FMT_WAV; + else if (pj_stricmp2(&ext, ".mp3") == 0) + file_format = FMT_MP3; + else { + PJ_LOG(1,(THIS_FILE, "pjsua_recorder_create() error: unable to " + "determine file format for %.*s", + (int)filename->slen, filename->ptr)); + return PJ_ENOTSUP; + } + PJSUA_LOCK(); for (file_id=0; file_id<PJ_ARRAY_SIZE(pjsua_var.recorder); ++file_id) { @@ -835,12 +860,26 @@ PJ_DEF(pj_status_t) pjsua_recorder_create( const pj_str_t *filename, pj_memcpy(path, filename->ptr, filename->slen); path[filename->slen] = '\0'; - status = pjmedia_wav_writer_port_create(pjsua_var.pool, path, - pjsua_var.media_cfg.clock_rate, - pjsua_var.mconf_cfg.channel_count, - pjsua_var.mconf_cfg.samples_per_frame, - pjsua_var.mconf_cfg.bits_per_sample, - options, 0, &port); + + if (file_format == FMT_WAV) { + status = pjmedia_wav_writer_port_create(pjsua_var.pool, path, + pjsua_var.media_cfg.clock_rate, + pjsua_var.mconf_cfg.channel_count, + pjsua_var.mconf_cfg.samples_per_frame, + pjsua_var.mconf_cfg.bits_per_sample, + options, 0, &port); + } else if (file_format == FMT_MP3) { + status = pjmedia_mp3_writer_port_create(pjsua_var.pool, path, + pjsua_var.media_cfg.clock_rate, + pjsua_var.mconf_cfg.channel_count, + pjsua_var.mconf_cfg.samples_per_frame, + pjsua_var.mconf_cfg.bits_per_sample, + NULL, &port); + } else { + port = NULL; + status = PJ_ENOTSUP; + } + if (status != PJ_SUCCESS) { PJSUA_UNLOCK(); pjsua_perror(THIS_FILE, "Unable to open file for recording", status); |