From 1e47fd78f11dab4b2f6cffa766417f111434f734 Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Fri, 14 Mar 2014 04:09:50 +0000 Subject: Closed #1748: enhancements to WAV player API git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@4793 74dad513-b988-da41-8d7b-12977e46ad98 --- pjmedia/include/pjmedia/wav_port.h | 48 ++++++++++++++++++++++++++++++++++---- pjmedia/src/pjmedia/wav_player.c | 40 ++++++++++++++++++++++++++++++- 2 files changed, 83 insertions(+), 5 deletions(-) (limited to 'pjmedia') diff --git a/pjmedia/include/pjmedia/wav_port.h b/pjmedia/include/pjmedia/wav_port.h index 29467836..bd6037f0 100644 --- a/pjmedia/include/pjmedia/wav_port.h +++ b/pjmedia/include/pjmedia/wav_port.h @@ -51,6 +51,35 @@ enum pjmedia_file_player_option }; +/** + * Additional information about the WAV player. + */ +typedef struct pjmedia_wav_player_info +{ + /** + * Format ID of the payload. + */ + pjmedia_format_id fmt_id; + + /** + * The number of bits per sample of the file payload. For example, + * the value is 16 for PCM WAV and 8 for Alaw/Ulas WAV files. + */ + unsigned payload_bits_per_sample; + + /** + * The WAV payload size in bytes. + */ + pj_uint32_t size_bytes; + + /** + * The WAV payload size in samples. + */ + pj_uint32_t size_samples; + +} pjmedia_wav_player_info; + + /** * Create a media port to play streams from a WAV file. WAV player port * supports for reading WAV file with uncompressed 16 bit PCM format or @@ -76,14 +105,24 @@ PJ_DECL(pj_status_t) pjmedia_wav_player_port_create( pj_pool_t *pool, pj_ssize_t buff_size, pjmedia_port **p_port ); +/** + * Get additional info about the file player. + * + * @param port The file port. + * @param i The info. + * + * @return PJ_SUCCESS on success or the appropriate error code. + */ +PJ_DECL(pj_status_t) pjmedia_wav_player_get_info(pjmedia_port *port, + pjmedia_wav_player_info *i); /** * Get the data length, in bytes. * * @param port The file player port. * - * @return The length of the data, in bytes. Upon error it will - * return negative value. + * @return The length of the data, in bytes. On error, the + * error code is given as negative value. */ PJ_DECL(pj_ssize_t) pjmedia_wav_player_get_len(pjmedia_port *port); @@ -102,11 +141,12 @@ PJ_DECL(pj_status_t) pjmedia_wav_player_port_set_pos( pjmedia_port *port, /** - * Get the file play position of WAV player. + * Get the file play position of WAV player, in bytes. * * @param port The file player port. * - * @return PJ_SUCCESS on success. + * @return The current play position, in bytes. On error, the + * error code is given as negative value. */ PJ_DECL(pj_ssize_t) pjmedia_wav_player_port_get_pos( pjmedia_port *port ); diff --git a/pjmedia/src/pjmedia/wav_player.c b/pjmedia/src/pjmedia/wav_player.c index 78a02e04..1e9a92ca 100644 --- a/pjmedia/src/pjmedia/wav_player.c +++ b/pjmedia/src/pjmedia/wav_player.c @@ -424,6 +424,44 @@ PJ_DEF(pj_status_t) pjmedia_wav_player_port_create( pj_pool_t *pool, } +/* + * Get additional info about the file player. + */ +PJ_DEF(pj_status_t) pjmedia_wav_player_get_info( + pjmedia_port *port, + pjmedia_wav_player_info *info) +{ + struct file_reader_port *fport; + PJ_ASSERT_RETURN(port && info, PJ_EINVAL); + + pj_bzero(info, sizeof(*info)); + + /* Check that this is really a player port */ + PJ_ASSERT_RETURN(port->info.signature == SIGNATURE, PJ_EINVALIDOP); + + fport = (struct file_reader_port*) port; + + if (fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_PCM) { + info->fmt_id = PJMEDIA_FORMAT_PCM; + info->payload_bits_per_sample = 16; + } else if (fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_ULAW) { + info->fmt_id = PJMEDIA_FORMAT_ULAW; + info->payload_bits_per_sample = 8; + } else if (fport->fmt_tag == PJMEDIA_WAVE_FMT_TAG_ALAW) { + info->fmt_id = PJMEDIA_FORMAT_ALAW; + info->payload_bits_per_sample = 8; + } else { + pj_assert(!"Unsupported format"); + return PJ_ENOTSUP; + } + + info->size_bytes = pjmedia_wav_player_get_len(port); + info->size_samples = info->size_bytes / + (info->payload_bits_per_sample / 8); + + return PJ_SUCCESS; +} + /* * Get the data length, in bytes. */ @@ -484,7 +522,7 @@ PJ_DEF(pj_status_t) pjmedia_wav_player_port_set_pos(pjmedia_port *port, /* - * Get the file play position of WAV player. + * Get the file play position of WAV player (in bytes). */ PJ_DEF(pj_ssize_t) pjmedia_wav_player_port_get_pos( pjmedia_port *port ) { -- cgit v1.2.3