[Freeswitch-svn] [commit] r2139 - in freeswitch/trunk/src: . include mod/formats/mod_sndfile

Freeswitch SVN anthm at freeswitch.org
Tue Jul 25 18:37:53 EDT 2006


Author: anthm
Date: Tue Jul 25 18:37:52 2006
New Revision: 2139

Modified:
   freeswitch/trunk/src/include/switch_core.h
   freeswitch/trunk/src/include/switch_module_interfaces.h
   freeswitch/trunk/src/include/switch_types.h
   freeswitch/trunk/src/mod/formats/mod_sndfile/mod_sndfile.c
   freeswitch/trunk/src/switch_core.c
   freeswitch/trunk/src/switch_ivr.c

Log:
add metadata functions to sound file api

Modified: freeswitch/trunk/src/include/switch_core.h
==============================================================================
--- freeswitch/trunk/src/include/switch_core.h	(original)
+++ freeswitch/trunk/src/include/switch_core.h	Tue Jul 25 18:37:52 2006
@@ -867,6 +867,25 @@
 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
   \return SWITCH_STATUS_SUCCESS if the file handle was closed

Modified: freeswitch/trunk/src/include/switch_module_interfaces.h
==============================================================================
--- freeswitch/trunk/src/include/switch_module_interfaces.h	(original)
+++ freeswitch/trunk/src/include/switch_module_interfaces.h	Tue Jul 25 18:37:52 2006
@@ -266,6 +266,10 @@
 	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;

Modified: freeswitch/trunk/src/include/switch_types.h
==============================================================================
--- freeswitch/trunk/src/include/switch_types.h	(original)
+++ freeswitch/trunk/src/include/switch_types.h	Tue Jul 25 18:37:52 2006
@@ -94,6 +94,16 @@
 #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),

Modified: freeswitch/trunk/src/mod/formats/mod_sndfile/mod_sndfile.c
==============================================================================
--- freeswitch/trunk/src/mod/formats/mod_sndfile/mod_sndfile.c	(original)
+++ freeswitch/trunk/src/mod/formats/mod_sndfile/mod_sndfile.c	Tue Jul 25 18:37:52 2006
@@ -213,6 +213,26 @@
 	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 @@
 	/*.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,
 };

Modified: freeswitch/trunk/src/switch_core.c
==============================================================================
--- freeswitch/trunk/src/switch_core.c	(original)
+++ freeswitch/trunk/src/switch_core.c	Tue Jul 25 18:37:52 2006
@@ -543,8 +543,25 @@
 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)
 {

Modified: freeswitch/trunk/src/switch_ivr.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr.c	(original)
+++ freeswitch/trunk/src/switch_ivr.c	Tue Jul 25 18:37:52 2006
@@ -214,6 +214,8 @@
 	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_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_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 @@
 	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;
 



More information about the Freeswitch-svn mailing list