FreeSWITCH API Documentation  1.7.0
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_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

#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 1865 of file switch_core.h.

Referenced by main(), setup_ringback(), switch_ivr_displace_session(), switch_ivr_insert_file(), switch_ivr_play_file(), switch_ivr_record_file(), switch_ivr_record_session(), switch_ivr_wait_for_answer(), and switch_ivr_wait_for_silence().

Function Documentation

switch_status_t switch_core_file_close ( _In_ switch_file_handle_t fh)
switch_status_t switch_core_file_command ( switch_file_handle_t fh,
switch_file_command_t  command 
)

Definition at line 743 of file switch_core_file.c.

References 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().

744 {
746 
747  switch_assert(fh != NULL);
748  switch_assert(fh->file_interface != NULL);
749 
751  return SWITCH_STATUS_FALSE;
752  }
753 
754  switch(command) {
755  case SCFC_FLUSH_AUDIO:
756  if (fh->pre_buffer) {
758  }
759  break;
760  default:
761  break;
762  }
763 
764  if (fh->file_interface->file_command) {
766  status = fh->file_interface->file_command(fh, command);
768  }
769 
770  return status;
771 }
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:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
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:624
#define switch_assert(expr)
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 switch_ivr_play_file().

switch_bool_t switch_core_file_has_video ( switch_file_handle_t fh,
switch_bool_t  CHECK_OPEN 
)
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_insert_file(), switch_ivr_originate(), switch_ivr_play_file(), switch_ivr_record_file(), switch_ivr_wait_for_answer(), switch_ivr_wait_for_silence(), and write_displace_callback().

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 606 of file switch_core_file.c.

References switch_assert, switch_cond_next(), SWITCH_FILE_OPEN, SWITCH_STATUS_FALSE, SWITCH_STATUS_GENERR, and switch_test_flag.

Referenced by video_write_thread().

607 {
608  switch_status_t status;
609 
610  switch_assert(fh != NULL);
611  switch_assert(fh->file_interface != NULL);
612 
614  return SWITCH_STATUS_GENERR;
615  }
616 
617  if (!fh->file_interface->file_read_video) {
618  return SWITCH_STATUS_FALSE;
619  }
620 
621  status = fh->file_interface->file_read_video(fh, frame, flags);
622 
623  if (status == SWITCH_STATUS_FALSE) {
625  }
626 
627  return status;
628 }
switch_file_interface_t * file_interface
void switch_cond_next(void)
Definition: switch_time.c:638
switch_status_t(* file_read_video)(switch_file_handle_t *, switch_frame_t *frame, switch_video_read_flag_t flags)
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:624
#define switch_assert(expr)
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(), switch_ivr_wait_for_answer(), and write_displace_callback().

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(), and switch_ivr_record_session().

switch_status_t switch_core_file_truncate ( switch_file_handle_t fh,
int64_t  offset 
)

Definition at line 713 of file switch_core_file.c.

References 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().

714 {
715  switch_status_t status;
716 
717  switch_assert(fh != NULL);
718  switch_assert(fh->file_interface != NULL);
719 
721  return SWITCH_STATUS_FALSE;
722  }
723 
724  if (!fh->file_interface->file_truncate) {
725  return SWITCH_STATUS_FALSE;
726  }
727 
728  if ((status = fh->file_interface->file_truncate(fh, offset)) == SWITCH_STATUS_SUCCESS) {
729  if (fh->buffer) {
731  }
732  if (fh->pre_buffer) {
734  }
735  fh->samples_out = 0;
736  fh->pos = 0;
737  }
738 
739  return status;
740 
741 }
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.
switch_status_t(* file_truncate)(switch_file_handle_t *, int64_t offset)
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:624
#define switch_assert(expr)
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(), and teletone_handler().

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_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 
)