]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add metadata functions to sound file api
authorAnthony Minessale <anthony.minessale@gmail.com>
Tue, 25 Jul 2006 22:37:52 +0000 (22:37 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Tue, 25 Jul 2006 22:37:52 +0000 (22:37 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@2139 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_core.h
src/include/switch_module_interfaces.h
src/include/switch_types.h
src/mod/formats/mod_sndfile/mod_sndfile.c
src/switch_core.c
src/switch_ivr.c

index 4183bde96cc302326e6d515dcda76bea9aaa48fe..4fec3650243ac0b376ef879669a921b6173c49f9 100644 (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
index 10f88e45c82ded2b8a0e7dff67c6af0d5552cd0e..69a672f749e9d70b1c77084392994ec78ce6a5f4 100644 (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;
index 727bf4e9d817609a0da8240d6386704da75771c1..864519ce56aa4ae510a46681a80d17bb092dcf25 100644 (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),
index 9096cbd60a9de061ad76dd2f3800fa39e54d4c61..9b579205a44f850ce6c62fbec082e77d4b036b5b 100644 (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,
 };
index 886a4af3442f68f51ba7e1494bd0b17361d39d38..894e66ee7017e780df1e264505f274def1fc92d4 100644 (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);
index a2fec657586a5205bd68b9775b0dced9b96a2128..142d55af66b40bf0cf8a06aa17e73e59dc891504 100644 (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;