add metadata functions to sound file api

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@2139 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Anthony Minessale 2006-07-25 22:37:52 +00:00
parent a4a82896b3
commit da4ae7be4c
6 changed files with 157 additions and 2 deletions

View File

@ -866,6 +866,25 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_write(switch_file_handle_t *fh,
*/
SWITCH_DECLARE(switch_status_t) switch_core_file_seek(switch_file_handle_t *fh, unsigned int *cur_pos, int64_t samples, int whence);
/*!
\brief Set metadata to the desired string
\param fh the file handle to set data to
\param col the enum of the col name
\param string the string to add
\return SWITCH_STATUS_SUCCESS with cur_pos adjusted to new position
*/
SWITCH_DECLARE(switch_status_t) switch_core_file_set_string(switch_file_handle_t *fh, switch_audio_col_t col, const char *string);
/*!
\brief get metadata of the desired string
\param fh the file handle to get data from
\param col the enum of the col name
\param string pointer to the string to fetch
\return SWITCH_STATUS_SUCCESS with cur_pos adjusted to new position
*/
SWITCH_DECLARE(switch_status_t) switch_core_file_get_string(switch_file_handle_t *fh, switch_audio_col_t col, const char **string);
/*!
\brief Close an open file handle
\param fh the file handle to close

View File

@ -266,6 +266,10 @@ struct switch_file_interface {
switch_status_t (*file_write)(switch_file_handle_t *, void *data, switch_size_t *len);
/*! function to seek to a certian position in the file */
switch_status_t (*file_seek)(switch_file_handle_t *, unsigned int *cur_pos, int64_t samples, int whence);
/*! function to set meta data */
switch_status_t (*file_set_string)(switch_file_handle_t *fh, switch_audio_col_t col, const char *string);
/*! function to get meta data */
switch_status_t (*file_get_string)(switch_file_handle_t *fh, switch_audio_col_t col, const char **string);
/*! list of supported file extensions */
char **extens;
const struct switch_file_interface *next;

View File

@ -94,6 +94,16 @@ SWITCH_DECLARE_DATA extern switch_directories SWITCH_GLOBAL_dirs;
#define SWITCH_FALSE 0
#define SWITCH_CORE_QUEUE_LEN 100000
typedef enum {
SWITCH_AUDIO_COL_STR_TITLE = 0x01,
SWITCH_AUDIO_COL_STR_COPYRIGHT = 0x02,
SWITCH_AUDIO_COL_STR_SOFTWARE = 0x03,
SWITCH_AUDIO_COL_STR_ARTIST = 0x04,
SWITCH_AUDIO_COL_STR_COMMENT = 0x05,
SWITCH_AUDIO_COL_STR_DATE = 0x06
} switch_audio_col_t;
typedef enum {
SWITCH_XML_SECTION_RESULT = 0,
SWITCH_XML_SECTION_CONFIG = (1 << 0),

View File

@ -213,6 +213,26 @@ static switch_status_t sndfile_file_write(switch_file_handle_t *handle, void *da
return SWITCH_STATUS_SUCCESS;
}
static switch_status_t sndfile_file_set_string(switch_file_handle_t *handle, switch_audio_col_t col, const char *string)
{
sndfile_context *context = handle->private_info;
return sf_set_string(context->handle, (int)col, string) ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS;
}
static switch_status_t sndfile_file_get_string(switch_file_handle_t *handle, switch_audio_col_t col, const char **string)
{
sndfile_context *context = handle->private_info;
const char *s;
if ((s = sf_get_string(context->handle, (int)col))) {
*string = s;
return SWITCH_STATUS_SUCCESS;
}
return SWITCH_STATUS_FALSE;
}
/* Registration */
static char **supported_formats;
@ -224,6 +244,8 @@ static switch_file_interface_t sndfile_file_interface = {
/*.file_read */ sndfile_file_read,
/*.file_write */ sndfile_file_write,
/*.file_seek */ sndfile_file_seek,
/*.file_set_string */ sndfile_file_set_string,
/*.file_get_string */ sndfile_file_get_string,
/*.extens */ NULL,
/*.next */ NULL,
};

View File

@ -543,9 +543,26 @@ SWITCH_DECLARE(switch_status_t) switch_core_file_write(switch_file_handle_t *fh,
SWITCH_DECLARE(switch_status_t) switch_core_file_seek(switch_file_handle_t *fh, unsigned int *cur_pos, int64_t samples,
int whence)
{
assert(fh != NULL);
return fh->file_interface->file_seek(fh, cur_pos, samples, whence);
}
SWITCH_DECLARE(switch_status_t) switch_core_file_set_string(switch_file_handle_t *fh, switch_audio_col_t col, const char *string)
{
assert(fh != NULL);
return fh->file_interface->file_set_string(fh, col, string);
}
SWITCH_DECLARE(switch_status_t) switch_core_file_get_string(switch_file_handle_t *fh, switch_audio_col_t col, const char **string)
{
assert(fh != NULL);
return fh->file_interface->file_get_string(fh, col, string);
}
SWITCH_DECLARE(switch_status_t) switch_core_file_close(switch_file_handle_t *fh)
{
return fh->file_interface->file_close(fh);

View File

@ -214,6 +214,8 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se
switch_codec_t codec, *read_codec;
char *codec_name;
switch_status_t status = SWITCH_STATUS_SUCCESS;
char *p;
const char *vval;
if (!fh) {
fh = &lfh;
@ -241,6 +243,41 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_record_file(switch_core_session_t *se
switch_channel_answer(channel);
if ((p = switch_channel_get_variable(channel, "RECORD_TITLE"))) {
vval = (const char *) switch_core_session_strdup(session, p);
switch_core_file_set_string(fh, SWITCH_AUDIO_COL_STR_TITLE, vval);
switch_channel_set_variable(channel, "RECORD_TITLE", NULL);
}
if ((p = switch_channel_get_variable(channel, "RECORD_COPYRIGHT"))) {
vval = (const char *) switch_core_session_strdup(session, p);
switch_core_file_set_string(fh, SWITCH_AUDIO_COL_STR_COPYRIGHT, vval);
switch_channel_set_variable(channel, "RECORD_COPYRIGHT", NULL);
}
if ((p = switch_channel_get_variable(channel, "RECORD_SOFTWARE"))) {
vval = (const char *) switch_core_session_strdup(session, p);
switch_core_file_set_string(fh, SWITCH_AUDIO_COL_STR_SOFTWARE, vval);
switch_channel_set_variable(channel, "RECORD_SOFTWARE", NULL);
}
if ((p = switch_channel_get_variable(channel, "RECORD_ARTIST"))) {
vval = (const char *) switch_core_session_strdup(session, p);
switch_core_file_set_string(fh, SWITCH_AUDIO_COL_STR_ARTIST, vval);
switch_channel_set_variable(channel, "RECORD_ARTIST", NULL);
}
if ((p = switch_channel_get_variable(channel, "RECORD_COMMENT"))) {
vval = (const char *) switch_core_session_strdup(session, p);
switch_core_file_set_string(fh, SWITCH_AUDIO_COL_STR_COMMENT, vval);
switch_channel_set_variable(channel, "RECORD_COMMENT", NULL);
}
if ((p = switch_channel_get_variable(channel, "RECORD_DATE"))) {
vval = (const char *) switch_core_session_strdup(session, p);
switch_core_file_set_string(fh, SWITCH_AUDIO_COL_STR_DATE, vval);
switch_channel_set_variable(channel, "RECORD_DATE", NULL);
}
codec_name = "L16";
if (switch_core_codec_init(&codec,
@ -333,7 +370,9 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_file_handle_t lfh;
switch_codec_t *read_codec = switch_core_session_get_read_codec(session);
const char *p;
char *title = "", *copyright = "", *software = "", *artist = "", *comment = "", *date = "";
if (!fh) {
fh = &lfh;
memset(fh, 0, sizeof(lfh));
@ -354,8 +393,52 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_play_file(switch_core_session_t *sess
write_frame.data = abuf;
write_frame.buflen = sizeof(abuf);
if (switch_core_file_get_string(fh, SWITCH_AUDIO_COL_STR_TITLE, &p) == SWITCH_STATUS_SUCCESS) {
title = (char *) switch_core_session_strdup(session, (char *)p);
switch_channel_set_variable(channel, "RECORD_TITLE", (char *)p);
}
if (switch_core_file_get_string(fh, SWITCH_AUDIO_COL_STR_COPYRIGHT, &p) == SWITCH_STATUS_SUCCESS) {
copyright = (char *) switch_core_session_strdup(session, (char *)p);
switch_channel_set_variable(channel, "RECORD_COPYRIGHT", (char *)p);
}
if (switch_core_file_get_string(fh, SWITCH_AUDIO_COL_STR_SOFTWARE, &p) == SWITCH_STATUS_SUCCESS) {
software = (char *) switch_core_session_strdup(session, (char *)p);
switch_channel_set_variable(channel, "RECORD_SOFTWARE", (char *)p);
}
if (switch_core_file_get_string(fh, SWITCH_AUDIO_COL_STR_ARTIST, &p) == SWITCH_STATUS_SUCCESS) {
artist = (char *) switch_core_session_strdup(session, (char *)p);
switch_channel_set_variable(channel, "RECORD_ARTIST", (char *)p);
}
if (switch_core_file_get_string(fh, SWITCH_AUDIO_COL_STR_COMMENT, &p) == SWITCH_STATUS_SUCCESS) {
comment = (char *) switch_core_session_strdup(session, (char *)p);
switch_channel_set_variable(channel, "RECORD_COMMENT", (char *)p);
}
if (switch_core_file_get_string(fh, SWITCH_AUDIO_COL_STR_DATE, &p) == SWITCH_STATUS_SUCCESS) {
date = (char *) switch_core_session_strdup(session, (char *)p);
switch_channel_set_variable(channel, "RECORD_DATE", (char *)p);
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG,
"OPEN FILE %s %uhz %u channels\n"
"TITLE=%s\n"
"COPYRIGHT=%s\n"
"SOFTWARE=%s\n"
"ARTIST=%s\n"
"COMMENT=%s\n"
"DATE=%s\n", file, fh->samplerate, fh->channels,
title,
copyright,
software,
artist,
comment,
date);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "OPEN FILE %s %uhz %u channels\n", file, fh->samplerate, fh->channels);
interval = read_codec->implementation->microseconds_per_frame / 1000;