diff options
author | Benny Prijono <bennylp@teluu.com> | 2007-01-21 23:12:40 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2007-01-21 23:12:40 +0000 |
commit | 5d7fc1ab44dd43d9170119bafbd2fc54c0829a8c (patch) | |
tree | 6346052cb13e5befcac417bef305c97f58ab1f30 /pjsip | |
parent | d5979b2e6027ad0eb652e87cf24580f84559b50c (diff) |
Implement ticket #67: added WAV playlist feature to PJMEDIA
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@895 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip')
-rw-r--r-- | pjsip/include/pjsua-lib/pjsua.h | 35 | ||||
-rw-r--r-- | pjsip/include/pjsua-lib/pjsua_internal.h | 1 | ||||
-rw-r--r-- | pjsip/src/pjsua-lib/pjsua_media.c | 73 |
3 files changed, 100 insertions, 9 deletions
diff --git a/pjsip/include/pjsua-lib/pjsua.h b/pjsip/include/pjsua-lib/pjsua.h index f0bf5775..0d7a6454 100644 --- a/pjsip/include/pjsua-lib/pjsua.h +++ b/pjsip/include/pjsua-lib/pjsua.h @@ -2893,11 +2893,11 @@ PJ_DECL(pj_status_t) pjsua_conf_get_signal_level(pjsua_conf_port_id slot, /***************************************************************************** - * File player. + * File player and playlist. */ /** - * Create a file player, and automatically connect this player to + * Create a file player, and automatically add this player to * the conference bridge. * * @param filename The filename to be played. Currently only @@ -2915,7 +2915,28 @@ PJ_DECL(pj_status_t) pjsua_player_create(const pj_str_t *filename, /** - * Get conference port ID associated with player. + * Create a file playlist media port, and automatically add the port + * to the conference bridge. + * + * @param file_names Array of file names to be added to the play list. + * Note that the files must have the same clock rate, + * number of channels, and number of bits per sample. + * @param file_count Number of files in the array. + * @param label Optional label to be set for the media port. + * @param options Optional option flag. Application may specify + * PJMEDIA_FILE_NO_LOOP to prevent looping. + * @param p_id Optional pointer to receive player ID. + * + * @return PJ_SUCCESS on success, or the appropriate error code. + */ +PJ_DECL(pj_status_t) pjsua_playlist_create(const pj_str_t file_names[], + unsigned file_count, + const pj_str_t *label, + unsigned options, + pjsua_player_id *p_id); + +/** + * Get conference port ID associated with player or playlist. * * @param id The file player ID. * @@ -2925,7 +2946,7 @@ PJ_DECL(pjsua_conf_port_id) pjsua_player_get_conf_port(pjsua_player_id id); /** - * Get the media port for the player. + * Get the media port for the player or playlist. * * @param id The player ID. * @param p_port The media port associated with the player. @@ -2936,7 +2957,7 @@ PJ_DECL(pj_status_t) pjsua_player_get_port(pjsua_recorder_id id, pjmedia_port **p_port); /** - * Set playback position. + * Set playback position. This operation is not valid for playlist. * * @param id The file player ID. * @param samples The playback position, in samples. Application can @@ -2949,8 +2970,8 @@ PJ_DECL(pj_status_t) pjsua_player_set_pos(pjsua_player_id id, /** - * Close the file, remove the player from the bridge, and free - * resources associated with the file player. + * Close the file of playlist, remove the player from the bridge, and free + * resources associated with the file player or playlist. * * @param id The file player ID. * diff --git a/pjsip/include/pjsua-lib/pjsua_internal.h b/pjsip/include/pjsua-lib/pjsua_internal.h index 43d28591..42344ec8 100644 --- a/pjsip/include/pjsua-lib/pjsua_internal.h +++ b/pjsip/include/pjsua-lib/pjsua_internal.h @@ -145,6 +145,7 @@ typedef struct pjsua_buddy */ typedef struct pjsua_file_data { + pj_bool_t type; /* 0=player, 1=playlist */ pjmedia_port *port; unsigned slot; } pjsua_file_data; diff --git a/pjsip/src/pjsua-lib/pjsua_media.c b/pjsip/src/pjsua-lib/pjsua_media.c index 46d99a2b..0cf1d1de 100644 --- a/pjsip/src/pjsua-lib/pjsua_media.c +++ b/pjsip/src/pjsua-lib/pjsua_media.c @@ -720,7 +720,7 @@ PJ_DEF(pj_status_t) pjsua_player_create( const pj_str_t *filename, pjsua_player_id *p_id) { unsigned slot, file_id; - char path[128]; + char path[PJ_MAXPATH]; pjmedia_port *port; pj_status_t status; @@ -761,6 +761,7 @@ PJ_DEF(pj_status_t) pjsua_player_create( const pj_str_t *filename, return status; } + pjsua_var.player[file_id].type = 0; pjsua_var.player[file_id].port = port; pjsua_var.player[file_id].slot = slot; @@ -774,6 +775,73 @@ PJ_DEF(pj_status_t) pjsua_player_create( const pj_str_t *filename, /* + * Create a file playlist media port, and automatically add the port + * to the conference bridge. + */ +PJ_DEF(pj_status_t) pjsua_playlist_create( const pj_str_t file_names[], + unsigned file_count, + const pj_str_t *label, + unsigned options, + pjsua_player_id *p_id) +{ + unsigned slot, file_id, ptime; + pjmedia_port *port; + pj_status_t status; + + if (pjsua_var.player_cnt >= PJ_ARRAY_SIZE(pjsua_var.player)) + return PJ_ETOOMANY; + + PJSUA_LOCK(); + + for (file_id=0; file_id<PJ_ARRAY_SIZE(pjsua_var.player); ++file_id) { + if (pjsua_var.player[file_id].port == NULL) + break; + } + + if (file_id == PJ_ARRAY_SIZE(pjsua_var.player)) { + /* This is unexpected */ + PJSUA_UNLOCK(); + pj_assert(0); + return PJ_EBUG; + } + + + ptime = pjsua_var.mconf_cfg.samples_per_frame * 1000 / + pjsua_var.media_cfg.clock_rate; + + status = pjmedia_wav_playlist_create(pjsua_var.pool, label, + file_names, file_count, + ptime, options, 0, &port); + if (status != PJ_SUCCESS) { + PJSUA_UNLOCK(); + pjsua_perror(THIS_FILE, "Unable to create playlist", status); + return status; + } + + status = pjmedia_conf_add_port(pjsua_var.mconf, pjsua_var.pool, + port, &port->info.name, &slot); + if (status != PJ_SUCCESS) { + pjmedia_port_destroy(port); + PJSUA_UNLOCK(); + pjsua_perror(THIS_FILE, "Unable to add port", status); + return status; + } + + pjsua_var.player[file_id].type = 1; + pjsua_var.player[file_id].port = port; + pjsua_var.player[file_id].slot = slot; + + if (p_id) *p_id = file_id; + + ++pjsua_var.player_cnt; + + PJSUA_UNLOCK(); + return PJ_SUCCESS; + +} + + +/* * Get conference port ID associated with player. */ PJ_DEF(pjsua_conf_port_id) pjsua_player_get_conf_port(pjsua_player_id id) @@ -807,6 +875,7 @@ PJ_DEF(pj_status_t) pjsua_player_set_pos( pjsua_player_id id, { PJ_ASSERT_RETURN(id>=0 && id<PJ_ARRAY_SIZE(pjsua_var.player), PJ_EINVAL); PJ_ASSERT_RETURN(pjsua_var.player[id].port != NULL, PJ_EINVAL); + PJ_ASSERT_RETURN(pjsua_var.player[id].type == 0, PJ_EINVAL); return pjmedia_wav_player_port_set_pos(pjsua_var.player[id].port, samples); } @@ -860,7 +929,7 @@ PJ_DEF(pj_status_t) pjsua_recorder_create( const pj_str_t *filename, FMT_MP3, }; unsigned slot, file_id; - char path[128]; + char path[PJ_MAXPATH]; pj_str_t ext; int file_format; pjmedia_port *port; |