RTS API Documentation  1.10.11
Macros | Functions
File Functions
+ Collaboration diagram for File Functions:

Macros

#define switch_core_file_open(_fh, _file_path, _channels, _rate, _flags, _pool)   switch_core_perform_file_open(__FILE__, __SWITCH_FUNC__, __LINE__, _fh, _file_path, _channels, _rate, _flags, _pool)
 Open a media file using file format modules. More...
 

Functions

switch_status_t switch_core_perform_file_open (const char *file, const char *func, int line, _In_ switch_file_handle_t *fh, _In_opt_z_ const char *file_path, _In_ uint32_t channels, _In_ uint32_t rate, _In_ unsigned int flags, _In_opt_ switch_memory_pool_t *pool)
 
switch_status_t switch_core_file_read (_In_ switch_file_handle_t *fh, void *data, switch_size_t *len)
 Read media from a file handle. More...
 
switch_status_t switch_core_file_write (_In_ switch_file_handle_t *fh, void *data, switch_size_t *len)
 Write media to a file handle. More...
 
switch_status_t switch_core_file_write_video (_In_ switch_file_handle_t *fh, switch_frame_t *frame)
 Write media to a file handle. More...
 
switch_status_t switch_core_file_read_video (switch_file_handle_t *fh, switch_frame_t *frame, switch_video_read_flag_t flags)
 
switch_status_t switch_core_file_seek (_In_ switch_file_handle_t *fh, unsigned int *cur_pos, int64_t samples, int whence)
 Seek a position in a file. More...
 
switch_status_t switch_core_file_set_string (_In_ switch_file_handle_t *fh, switch_audio_col_t col, const char *string)
 Set metadata to the desired string. More...
 
switch_status_t switch_core_file_get_string (_In_ switch_file_handle_t *fh, switch_audio_col_t col, const char **string)
 get metadata of the desired string More...
 
switch_status_t switch_core_file_pre_close (_In_ switch_file_handle_t *fh)
 Pre close an open file handle, then can get file size etc., no more wirte to the file. More...
 
switch_status_t switch_core_file_handle_dup (switch_file_handle_t *oldfh, switch_file_handle_t **newfh, switch_memory_pool_t *pool)
 Duplicates a file handle using another pool. More...
 
switch_status_t switch_core_file_close (_In_ switch_file_handle_t *fh)
 Close an open file handle. More...
 
switch_status_t switch_core_file_command (switch_file_handle_t *fh, switch_file_command_t command)
 
switch_status_t switch_core_file_truncate (switch_file_handle_t *fh, int64_t offset)
 
switch_bool_t switch_core_file_has_video (switch_file_handle_t *fh, switch_bool_t CHECK_OPEN)
 

Detailed Description

Macro Definition Documentation

◆ switch_core_file_open

#define switch_core_file_open (   _fh,
  _file_path,
  _channels,
  _rate,
  _flags,
  _pool 
)    switch_core_perform_file_open(__FILE__, __SWITCH_FUNC__, __LINE__, _fh, _file_path, _channels, _rate, _flags, _pool)

Open a media file using file format modules.

Parameters
_fha file handle to use
_file_paththe path to the file
_channelsthe number of channels
_ratethe sample rate
_flagsread/write flags
_poolthe pool to use (NULL for new pool)
Returns
SWITCH_STATUS_SUCCESS if the file is opened
Note
the loadable module used is chosen based on the file extension

Definition at line 1963 of file switch_core.h.

Referenced by main(), setup_ringback(), switch_ivr_detect_audio(), switch_ivr_detect_silence(), switch_ivr_displace_session(), switch_ivr_insert_file(), switch_ivr_play_file(), switch_ivr_record_file_event(), switch_ivr_record_session_event(), switch_ivr_wait_for_answer(), and switch_ivr_wait_for_silence().

Function Documentation

◆ switch_core_file_close()

switch_status_t switch_core_file_close ( _In_ switch_file_handle_t fh)

◆ switch_core_file_command()

switch_status_t switch_core_file_command ( switch_file_handle_t fh,
switch_file_command_t  command 
)

Definition at line 906 of file switch_core_file.c.

References switch_file_interface::file_command, switch_file_handle::file_interface, switch_file_handle::flag_mutex, switch_file_handle::pre_buffer, SCFC_FLUSH_AUDIO, switch_assert, switch_buffer_zero(), SWITCH_FILE_OPEN, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, and switch_test_flag.

Referenced by switch_ivr_process_fh(), and switch_ivr_record_file_event().

907 {
909 
910  switch_assert(fh != NULL);
911  switch_assert(fh->file_interface != NULL);
912 
914  return SWITCH_STATUS_FALSE;
915  }
916 
917  switch(command) {
918  case SCFC_FLUSH_AUDIO:
919  if (fh->pre_buffer) {
921  }
922  break;
923  default:
924  break;
925  }
926 
927  if (fh->file_interface->file_command) {
929  status = fh->file_interface->file_command(fh, command);
931  }
932 
933  return status;
934 }
switch_file_interface_t * file_interface
switch_status_t(* file_command)(switch_file_handle_t *fh, switch_file_command_t command)
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_buffer_t * pre_buffer
void switch_buffer_zero(_In_ switch_buffer_t *buffer)
Remove all data from the buffer.
switch_status_t
Common return values.
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693
#define switch_assert(expr)

◆ switch_core_file_get_string()

switch_status_t switch_core_file_get_string ( _In_ switch_file_handle_t fh,
switch_audio_col_t  col,
const char **  string 
)

get metadata of the desired string

Parameters
fhthe file handle to get data from
colthe enum of the col name
stringpointer to the string to fetch
Returns
SWITCH_STATUS_SUCCESS with cur_pos adjusted to new position

Referenced by record_callback(), switch_ivr_play_file(), and switch_ivr_record_file_event().

◆ switch_core_file_handle_dup()

switch_status_t switch_core_file_handle_dup ( switch_file_handle_t oldfh,
switch_file_handle_t **  newfh,
switch_memory_pool_t pool 
)

Duplicates a file handle using another pool.

Parameters
oldfhthe file handle to duplicate
newfhpointer to assign new file handle to
poolthe pool to use (NULL for new pool)
Returns
SWITCH_STATUS_SUCCESS if the file handle was duplicated

Definition at line 982 of file switch_core_file.c.

References switch_file_handle::channels, DUP_CHECK, switch_file_handle::flag_mutex, switch_file_handle::memory_pool, pool, switch_file_handle::pre_buffer_data, switch_file_handle::pre_buffer_datalen, switch_assert, switch_clear_flag, switch_core_alloc, switch_core_destroy_memory_pool, switch_core_new_memory_pool, SWITCH_FILE_FLAG_FREE_POOL, switch_goto_status, switch_mutex_init(), SWITCH_MUTEX_NESTED, switch_set_flag, SWITCH_STATUS_MEMERR, and SWITCH_STATUS_SUCCESS.

Referenced by switch_ivr_record_session_event().

983 {
984  switch_status_t status;
986  uint8_t destroy_pool = 0;
987 
988  switch_assert(oldfh != NULL);
989  switch_assert(newfh != NULL);
990 
991  if (!pool) {
993  return status;
994  }
995 
996  destroy_pool = 1;
997  }
998 
999  if (!(fh = switch_core_alloc(pool, sizeof(switch_file_handle_t)))) {
1001  }
1002 
1003  memcpy(fh, oldfh, sizeof(switch_file_handle_t));
1004 
1005  if (!destroy_pool) {
1007  } else {
1008  fh->memory_pool = pool;
1010  }
1011 
1013  switch_goto_status(status, err);
1014  }
1015 
1016 #define DUP_CHECK(dup) if (oldfh->dup && !(fh->dup = switch_core_strdup(pool, oldfh->dup))) {switch_goto_status(SWITCH_STATUS_MEMERR, err);}
1017 
1018  DUP_CHECK(prefix);
1019  DUP_CHECK(modname);
1020  DUP_CHECK(mm.auth_username);
1021  DUP_CHECK(mm.auth_password);
1022  DUP_CHECK(stream_name);
1023  DUP_CHECK(file_path);
1024  DUP_CHECK(handler);
1025  DUP_CHECK(spool_path);
1026 
1027  fh->pre_buffer_data = NULL;
1028  if (oldfh->pre_buffer_data) {
1029  switch_size_t pre_buffer_data_size = oldfh->pre_buffer_datalen * oldfh->channels;
1030  if (pre_buffer_data_size) {
1031  if (!(fh->pre_buffer_data = switch_core_alloc(pool, pre_buffer_data_size))) {
1033  }
1034 
1035  memcpy(fh->pre_buffer_data, oldfh->pre_buffer_data, pre_buffer_data_size);
1036  }
1037  }
1038 
1039  *newfh = fh;
1040 
1041  return SWITCH_STATUS_SUCCESS;
1042 
1043 err:
1044  if (destroy_pool) {
1046  }
1047 
1048  return status;
1049 }
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core's master pool.
Definition: switch_core.h:633
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
Definition: switch_utils.h:700
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
Definition: switch_core.h:642
switch_memory_pool_t * pool
switch_memory_pool_t * memory_pool
#define switch_clear_flag(obj, flag)
Clear a flag on an arbitrary object while locked.
Definition: switch_utils.h:724
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
#define switch_core_alloc(_pool, _mem)
Allocate memory directly from a memory pool.
Definition: switch_core.h:684
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:293
uintptr_t switch_size_t
switch_status_t
Common return values.
#define switch_goto_status(_status, _label)
Definition: switch_utils.h:287
#define switch_assert(expr)
#define DUP_CHECK(dup)

◆ switch_core_file_has_video()

switch_bool_t switch_core_file_has_video ( switch_file_handle_t fh,
switch_bool_t  CHECK_OPEN 
)

◆ switch_core_file_pre_close()

switch_status_t switch_core_file_pre_close ( _In_ switch_file_handle_t fh)

Pre close an open file handle, then can get file size etc., no more wirte to the file.

Parameters
fhthe file handle to close
Returns
SWITCH_STATUS_SUCCESS if the file handle was pre closed

Referenced by record_callback(), and switch_ivr_record_file_event().

◆ switch_core_file_read()

switch_status_t switch_core_file_read ( _In_ switch_file_handle_t fh,
void *  data,
switch_size_t len 
)

Read media from a file handle.

Parameters
fhthe file handle to read from (must be initilized by you memset all 0 for read, fill in channels and rate for write)
datathe buffer to read the data to
lenthe max size of the buffer
Returns
SWITCH_STATUS_SUCCESS with len adjusted to the bytes read if successful

Referenced by main(), read_displace_callback(), switch_ivr_detect_audio(), switch_ivr_detect_silence(), switch_ivr_insert_file(), switch_ivr_originate(), switch_ivr_play_file(), switch_ivr_record_file_event(), switch_ivr_wait_for_answer(), switch_ivr_wait_for_silence(), and write_displace_callback().

◆ switch_core_file_read_video()

switch_status_t switch_core_file_read_video ( switch_file_handle_t fh,
switch_frame_t frame,
switch_video_read_flag_t  flags 
)

Definition at line 755 of file switch_core_file.c.

References switch_file_handle::file_interface, switch_file_interface::file_read_video, switch_assert, switch_cond_next(), SWITCH_FILE_OPEN, SWITCH_STATUS_FALSE, SWITCH_STATUS_GENERR, and switch_test_flag.

Referenced by video_write_thread().

756 {
757  switch_status_t status;
758 
759  switch_assert(fh != NULL);
760  switch_assert(fh->file_interface != NULL);
761 
763  return SWITCH_STATUS_GENERR;
764  }
765 
766  if (!fh->file_interface->file_read_video) {
767  return SWITCH_STATUS_FALSE;
768  }
769 
770  status = fh->file_interface->file_read_video(fh, frame, flags);
771 
772  if (status == SWITCH_STATUS_FALSE) {
774  }
775 
776  return status;
777 }
switch_file_interface_t * file_interface
switch_status_t(* file_read_video)(switch_file_handle_t *, switch_frame_t *frame, switch_video_read_flag_t flags)
void switch_cond_next(void)
Definition: switch_time.c:658
switch_status_t
Common return values.
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693
#define switch_assert(expr)

◆ switch_core_file_seek()

switch_status_t switch_core_file_seek ( _In_ switch_file_handle_t fh,
unsigned int *  cur_pos,
int64_t  samples,
int  whence 
)

Seek a position in a file.

Parameters
fhthe file handle to seek
cur_posthe current position in the file
samplesthe amount of samples to seek from the beginning of the file
whencethe indicator (see traditional seek)
Returns
SWITCH_STATUS_SUCCESS with cur_pos adjusted to new position

Referenced by read_displace_callback(), switch_ivr_insert_file(), switch_ivr_originate(), switch_ivr_play_file(), switch_ivr_process_fh(), switch_ivr_record_file_event(), switch_ivr_wait_for_answer(), and write_displace_callback().

◆ switch_core_file_set_string()

switch_status_t switch_core_file_set_string ( _In_ switch_file_handle_t fh,
switch_audio_col_t  col,
const char *  string 
)

Set metadata to the desired string.

Parameters
fhthe file handle to set data to
colthe enum of the col name
stringthe string to add
Returns
SWITCH_STATUS_SUCCESS with cur_pos adjusted to new position

Referenced by switch_ivr_record_file_event(), and switch_ivr_record_session_event().

◆ switch_core_file_truncate()

switch_status_t switch_core_file_truncate ( switch_file_handle_t fh,
int64_t  offset 
)

Definition at line 876 of file switch_core_file.c.

References switch_file_handle::buffer, switch_file_handle::file_interface, switch_file_interface::file_truncate, switch_file_handle::pos, switch_file_handle::pre_buffer, switch_file_handle::samples_out, switch_assert, switch_buffer_zero(), SWITCH_FILE_FLAG_WRITE, SWITCH_FILE_OPEN, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_test_flag.

Referenced by switch_ivr_process_fh().

877 {
878  switch_status_t status;
879 
880  switch_assert(fh != NULL);
881  switch_assert(fh->file_interface != NULL);
882 
884  return SWITCH_STATUS_FALSE;
885  }
886 
887  if (!fh->file_interface->file_truncate) {
888  return SWITCH_STATUS_FALSE;
889  }
890 
891  if ((status = fh->file_interface->file_truncate(fh, offset)) == SWITCH_STATUS_SUCCESS) {
892  if (fh->buffer) {
894  }
895  if (fh->pre_buffer) {
897  }
898  fh->samples_out = 0;
899  fh->pos = 0;
900  }
901 
902  return status;
903 
904 }
switch_status_t(* file_truncate)(switch_file_handle_t *, int64_t offset)
switch_file_interface_t * file_interface
switch_buffer_t * pre_buffer
void switch_buffer_zero(_In_ switch_buffer_t *buffer)
Remove all data from the buffer.
switch_status_t
Common return values.
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693
#define switch_assert(expr)

◆ switch_core_file_write()

switch_status_t switch_core_file_write ( _In_ switch_file_handle_t fh,
void *  data,
switch_size_t len 
)

Write media to a file handle.

Parameters
fhthe file handle to write to
datathe buffer to write
lenthe amount of data to write from the buffer
Returns
SWITCH_STATUS_SUCCESS with len adjusted to the bytes written if successful

Referenced by main(), record_callback(), recording_thread(), switch_ivr_insert_file(), switch_ivr_record_file_event(), and teletone_handler().

◆ switch_core_file_write_video()

switch_status_t switch_core_file_write_video ( _In_ switch_file_handle_t fh,
switch_frame_t frame 
)

Write media to a file handle.

Parameters
fhthe file handle to write to
datathe buffer to write
lenthe amount of data to write from the buffer
Returns
SWITCH_STATUS_SUCCESS with len adjusted to the bytes written if successful

Referenced by record_callback(), and video_helper_thread().

◆ switch_core_perform_file_open()

switch_status_t switch_core_perform_file_open ( const char *  file,
const char *  func,
int  line,
_In_ switch_file_handle_t fh,
_In_opt_z_ const char *  file_path,
_In_ uint32_t  channels,
_In_ uint32_t  rate,
_In_ unsigned int  flags,
_In_opt_ switch_memory_pool_t pool 
)