*/
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;
}
+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;
/*.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,
};
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;
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,
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));
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;