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

Macros

#define switch_core_codec_init(_codec, _codec_name, _modname, _fmtp, _rate, _ms, _channels, _flags, _codec_settings, _pool)   switch_core_codec_init_with_bitrate(_codec, _codec_name, _modname, _fmtp, _rate, _ms, _channels, 0, _flags, _codec_settings, _pool)
 Initialize a codec handle. More...
 

Functions

switch_status_t switch_core_codec_init_with_bitrate (switch_codec_t *codec, const char *codec_name, const char *fmtp, const char *modname, uint32_t rate, int ms, int channels, uint32_t bitrate, uint32_t flags, const switch_codec_settings_t *codec_settings, switch_memory_pool_t *pool)
 
switch_status_t switch_core_codec_copy (switch_codec_t *codec, switch_codec_t *new_codec, const switch_codec_settings_t *codec_settings, switch_memory_pool_t *pool)
 
switch_status_t switch_core_codec_parse_fmtp (const char *codec_name, const char *fmtp, uint32_t rate, switch_codec_fmtp_t *codec_fmtp)
 
switch_status_t switch_core_codec_reset (switch_codec_t *codec)
 
switch_status_t switch_core_codec_encode (switch_codec_t *codec, switch_codec_t *other_codec, void *decoded_data, uint32_t decoded_data_len, uint32_t decoded_rate, void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate, unsigned int *flag)
 Encode data using a codec handle. More...
 
switch_status_t switch_core_codec_decode (switch_codec_t *codec, switch_codec_t *other_codec, void *encoded_data, uint32_t encoded_data_len, uint32_t encoded_rate, void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate, unsigned int *flag)
 Decode data using a codec handle. More...
 
switch_status_t switch_core_codec_encode_video (switch_codec_t *codec, switch_frame_t *frame)
 Encode video data using a codec handle. More...
 
switch_status_t switch_core_codec_control (switch_codec_t *codec, switch_codec_control_command_t cmd, switch_codec_control_type_t ctype, void *cmd_data, switch_codec_control_type_t atype, void *cmd_arg, switch_codec_control_type_t *rtype, void **ret_data)
 send control data using a codec handle More...
 
switch_status_t switch_core_codec_decode_video (switch_codec_t *codec, switch_frame_t *frame)
 Decode video data using a codec handle. More...
 
switch_status_t switch_core_codec_destroy (switch_codec_t *codec)
 Destroy an initalized codec handle. More...
 
switch_status_t switch_core_session_set_read_codec (_In_ switch_core_session_t *session, switch_codec_t *codec)
 Assign the read codec to a given session. More...
 
switch_status_t switch_core_session_set_real_read_codec (_In_ switch_core_session_t *session, switch_codec_t *codec)
 Assign the original read codec to a given session. This is the read codec used by an endpoint. More...
 
void switch_core_session_unset_read_codec (_In_ switch_core_session_t *session)
 
void switch_core_session_unset_write_codec (_In_ switch_core_session_t *session)
 
void switch_core_session_lock_codec_write (_In_ switch_core_session_t *session)
 
void switch_core_session_unlock_codec_write (_In_ switch_core_session_t *session)
 
void switch_core_session_lock_codec_read (_In_ switch_core_session_t *session)
 
void switch_core_session_unlock_codec_read (_In_ switch_core_session_t *session)
 
switch_status_t switch_core_session_get_read_impl (switch_core_session_t *session, switch_codec_implementation_t *impp)
 
switch_status_t switch_core_session_get_real_read_impl (switch_core_session_t *session, switch_codec_implementation_t *impp)
 
switch_status_t switch_core_session_get_write_impl (switch_core_session_t *session, switch_codec_implementation_t *impp)
 
switch_status_t switch_core_session_get_video_read_impl (switch_core_session_t *session, switch_codec_implementation_t *impp)
 
switch_status_t switch_core_session_get_video_write_impl (switch_core_session_t *session, switch_codec_implementation_t *impp)
 
switch_codec_tswitch_core_session_get_read_codec (_In_ switch_core_session_t *session)
 Retrieve the read codec from a given session. More...
 
switch_codec_tswitch_core_session_get_effective_read_codec (_In_ switch_core_session_t *session)
 Retrieve the effevtive read codec from a given session. More...
 
switch_status_t switch_core_session_set_write_codec (_In_ switch_core_session_t *session, switch_codec_t *codec)
 Assign the write codec to a given session. More...
 
switch_codec_tswitch_core_session_get_write_codec (_In_ switch_core_session_t *session)
 Retrieve the write codec from a given session. More...
 
switch_codec_tswitch_core_session_get_effective_write_codec (_In_ switch_core_session_t *session)
 Retrieve the effevtive write codec from a given session. More...
 
switch_status_t switch_core_session_set_video_read_codec (_In_ switch_core_session_t *session, switch_codec_t *codec)
 Assign the video_read codec to a given session. More...
 
switch_codec_tswitch_core_session_get_video_read_codec (_In_ switch_core_session_t *session)
 Retrieve the video_read codec from a given session. More...
 
switch_status_t switch_core_session_set_video_write_codec (_In_ switch_core_session_t *session, switch_codec_t *codec)
 Assign the video_write codec to a given session. More...
 
switch_codec_tswitch_core_session_get_video_write_codec (_In_ switch_core_session_t *session)
 Retrieve the video_write codec from a given session. More...
 

Detailed Description

Macro Definition Documentation

◆ switch_core_codec_init

#define switch_core_codec_init (   _codec,
  _codec_name,
  _modname,
  _fmtp,
  _rate,
  _ms,
  _channels,
  _flags,
  _codec_settings,
  _pool 
)    switch_core_codec_init_with_bitrate(_codec, _codec_name, _modname, _fmtp, _rate, _ms, _channels, 0, _flags, _codec_settings, _pool)

Initialize a codec handle.

Parameters
codecthe handle to initilize
codec_namethe name of the codec module to use
fmtpcodec parameters to send
ratethe desired rate (0 for any)
msthe desired number of milliseconds (0 for any)
channelsthe desired number of channels (0 for any)
flagsflags to alter behaviour
codec_settingsdesired codec settings
poolthe memory pool to use
Returns
SWITCH_STATUS_SUCCESS if the handle is allocated

Definition at line 1693 of file switch_core.h.

Referenced by audio_bridge_thread(), early_thread_run(), setup_ringback(), switch_core_codec_copy(), switch_core_media_set_video_codec(), switch_core_session_set_codec_slin(), switch_ivr_activate_unicast(), switch_ivr_collect_digits_count(), switch_ivr_detect_audio(), switch_ivr_detect_silence(), switch_ivr_eavesdrop_session(), switch_ivr_gentones(), switch_ivr_park(), switch_ivr_play_file(), switch_ivr_record_file_event(), switch_ivr_sleep(), switch_ivr_sound_test(), switch_ivr_speak_text(), switch_ivr_wait_for_answer(), switch_ivr_wait_for_silence(), and switch_rtp_enable_vad().

Function Documentation

◆ switch_core_codec_control()

switch_status_t switch_core_codec_control ( switch_codec_t codec,
switch_codec_control_command_t  cmd,
switch_codec_control_type_t  ctype,
void *  cmd_data,
switch_codec_control_type_t  atype,
void *  cmd_arg,
switch_codec_control_type_t rtype,
void **  ret_data 
)

send control data using a codec handle

Parameters
codecthe codec handle to use
cmdthe command to send
ctypethe type of the arguement
cmd_dataa void pointer to the data matching the passed type
atypethe type of the extra arguement
cmd_arga void pointer to the data matching the passed type
rtypethe type of the response if any
ret_dataa void pointer to a pointer of return data
Returns
SWITCH_STATUS_SUCCESS if the command was received

Definition at line 882 of file switch_core_codec.c.

References switch_codec_implementation::codec_control, switch_codec::implementation, switch_codec::mutex, switch_assert, SWITCH_CHANNEL_LOG, switch_core_codec_ready(), SWITCH_LOG_ERROR, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), and SWITCH_STATUS_FALSE.

Referenced by switch_core_media_codec_control(), switch_core_media_receive_message(), switch_core_media_set_outgoing_bitrate(), and switch_core_session_stop_media().

890 {
891 
893 
894 
895  switch_assert(codec != NULL);
896 
897 
898  if (!codec->implementation || !switch_core_codec_ready(codec)) {
899  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec is not initialized!\n");
900  abort();
901  //return SWITCH_STATUS_NOT_INITALIZED;
902  }
903 
904 
905  if (codec->mutex) switch_mutex_lock(codec->mutex);
906 
907  if (codec->implementation->codec_control) {
908  status = codec->implementation->codec_control(codec, cmd, ctype, cmd_data, atype, cmd_arg, rtype, ret_data);
909  }
910 
911  if (codec->mutex) switch_mutex_unlock(codec->mutex);
912 
913 
914  return status;
915 }
#define SWITCH_CHANNEL_LOG
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
const switch_codec_implementation_t * implementation
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_status_t
Common return values.
static switch_bool_t switch_core_codec_ready(switch_codec_t *codec)
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_mutex_t * mutex
#define switch_assert(expr)
switch_core_codec_control_func_t codec_control

◆ switch_core_codec_copy()

switch_status_t switch_core_codec_copy ( switch_codec_t codec,
switch_codec_t new_codec,
const switch_codec_settings_t codec_settings,
switch_memory_pool_t pool 
)

Definition at line 620 of file switch_core_codec.c.

References switch_codec_implementation::actual_samples_per_second, switch_codec::flags, switch_codec::fmtp_in, switch_codec_implementation::iananame, switch_codec::implementation, switch_codec_implementation::microseconds_per_packet, switch_codec_implementation::modname, switch_codec_implementation::number_of_channels, switch_codec_implementation::samples_per_second, switch_assert, and switch_core_codec_init.

Referenced by switch_core_session_read_frame().

622 {
623  uint32_t codec_rate;
624  switch_assert(codec != NULL);
625  switch_assert(new_codec != NULL);
626 
627  codec_rate = !strcasecmp(codec->implementation->iananame, "g722")
629 
630  return switch_core_codec_init(new_codec,
631  codec->implementation->iananame,
632  codec->implementation->modname,
633  codec->fmtp_in,
634  codec_rate,
637  codec->flags,
638  codec_settings,
639  pool);
640 
641 }
switch_memory_pool_t * pool
const switch_codec_implementation_t * implementation
#define switch_core_codec_init(_codec, _codec_name, _modname, _fmtp, _rate, _ms, _channels, _flags, _codec_settings, _pool)
Initialize a codec handle.
Definition: switch_core.h:1693
#define switch_assert(expr)

◆ switch_core_codec_decode()

switch_status_t switch_core_codec_decode ( switch_codec_t codec,
switch_codec_t other_codec,
void *  encoded_data,
uint32_t  encoded_data_len,
uint32_t  encoded_rate,
void *  decoded_data,
uint32_t *  decoded_data_len,
uint32_t *  decoded_rate,
unsigned int *  flag 
)

Decode data using a codec handle.

Parameters
codecthe codec handle to use
other_codecthe codec handle of the last codec used
encoded_datathe buffer to read the encoded data from
encoded_data_lenthe size of the encoded_data buffer
encoded_ratethe rate of the encoded data
decoded_datathe raw data buffer
decoded_data_lenthen length of the raw buffer
decoded_ratethe new rate of the decoded data
flagflags to exchange
Returns
SWITCH_STATUS_SUCCESS if the data was decoded
Note
decoded_data_len will be rewritten to the in-use size of decoded_data

Definition at line 775 of file switch_core_codec.c.

References switch_codec_implementation::decode, switch_codec_implementation::decoded_bytes_per_packet, switch_codec_implementation::encoded_bytes_per_packet, switch_codec::implementation, memset(), switch_codec::mutex, switch_codec_implementation::number_of_channels, switch_assert, SWITCH_CHANNEL_LOG, SWITCH_CODEC_FLAG_DECODE, switch_core_codec_ready(), SWITCH_LOG_CRIT, SWITCH_LOG_ERROR, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_NOT_INITALIZED, SWITCH_STATUS_SUCCESS, and switch_test_flag.

Referenced by main(), rtp_common_write(), switch_core_session_read_frame(), switch_core_session_write_frame(), and switch_ivr_park().

781 {
782  switch_status_t status;
783 
784  switch_assert(codec != NULL);
785  switch_assert(encoded_data != NULL);
786  switch_assert(decoded_data != NULL);
787 
788  if (!codec->implementation || !switch_core_codec_ready(codec)) {
789  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Decode Codec is not initialized!\n");
791  }
792 
794  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec decoder is not initialized!\n");
796  }
797 
799  uint32_t frames = encoded_data_len / codec->implementation->encoded_bytes_per_packet / codec->implementation->number_of_channels;
800 
801  if (frames && codec->implementation->decoded_bytes_per_packet * frames > *decoded_data_len) {
802  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Buffer size sanity check failed! edl:%u ebpp:%u fr:%u ddl:%u\n",
803  encoded_data_len, codec->implementation->encoded_bytes_per_packet, frames, *decoded_data_len);
804  *decoded_data_len = codec->implementation->decoded_bytes_per_packet;
805  memset(decoded_data, 255, *decoded_data_len);
806  return SWITCH_STATUS_SUCCESS;
807  }
808  }
809 
810  if (codec->mutex) switch_mutex_lock(codec->mutex);
811  status = codec->implementation->decode(codec, other_codec, encoded_data, encoded_data_len, encoded_rate,
812  decoded_data, decoded_data_len, decoded_rate, flag);
813  if (codec->mutex) switch_mutex_unlock(codec->mutex);
814 
815  return status;
816 }
#define SWITCH_CHANNEL_LOG
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
const switch_codec_implementation_t * implementation
switch_core_codec_decode_func_t decode
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
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
static switch_bool_t switch_core_codec_ready(switch_codec_t *codec)
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_mutex_t * mutex
#define switch_assert(expr)
memset(buf, 0, buflen)

◆ switch_core_codec_decode_video()

switch_status_t switch_core_codec_decode_video ( switch_codec_t codec,
switch_frame_t frame 
)

Decode video data using a codec handle.

Parameters
codecthe codec handle to use
framethe frame to be decoded
imgthe new image in I420 format, allocated by the codec
flagflags to exchange
Returns
SWITCH_STATUS_SUCCESS if the data was decoded, and a non-NULL img

Definition at line 854 of file switch_core_codec.c.

References switch_codec_implementation::decode_video, switch_codec::implementation, switch_codec::mutex, switch_assert, SWITCH_CHANNEL_LOG, SWITCH_CODEC_FLAG_DECODE, switch_core_codec_ready(), SWITCH_LOG_ERROR, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, SWITCH_STATUS_NOT_INITALIZED, and switch_test_flag.

Referenced by switch_core_session_read_video_frame().

855 {
857 
858  switch_assert(codec != NULL);
859  switch_assert(frame != NULL);
860 
861  if (!codec->implementation || !switch_core_codec_ready(codec)) {
862  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Decode Codec is not initialized!\n");
864  }
865 
867  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec decoder is not initialized!\n");
869  }
870 
871  if (codec->mutex) switch_mutex_lock(codec->mutex);
872 
873  if (codec->implementation->decode_video) {
874  status = codec->implementation->decode_video(codec, frame);
875  }
876  if (codec->mutex) switch_mutex_unlock(codec->mutex);
877 
878  return status;
879 }
#define SWITCH_CHANNEL_LOG
switch_core_codec_video_decode_func_t decode_video
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
const switch_codec_implementation_t * implementation
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
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
static switch_bool_t switch_core_codec_ready(switch_codec_t *codec)
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_mutex_t * mutex
#define switch_assert(expr)

◆ switch_core_codec_destroy()

switch_status_t switch_core_codec_destroy ( switch_codec_t codec)

Destroy an initalized codec handle.

Parameters
codecthe codec handle to destroy
Returns
SWITCH_STATUS_SUCCESS if the codec was destroyed

Definition at line 917 of file switch_core_codec.c.

References switch_codec::codec_interface, switch_codec_implementation::destroy, switch_codec::implementation, switch_codec::memory_pool, memset(), switch_codec::mutex, mutex, pool, switch_assert, SWITCH_CHANNEL_LOG, switch_clear_flag, SWITCH_CODEC_FLAG_FREE_POOL, SWITCH_CODEC_FLAG_READY, switch_core_codec_ready(), switch_core_destroy_memory_pool, switch_log_printf(), SWITCH_LOG_WARNING, switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_NOT_INITALIZED, SWITCH_STATUS_SUCCESS, switch_test_flag, and UNPROTECT_INTERFACE.

Referenced by audio_bridge_thread(), early_thread_run(), main(), switch_core_media_bug_prune(), switch_core_media_bug_remove(), switch_core_media_bug_remove_all_function(), switch_core_media_bug_remove_callback(), switch_core_media_bug_transfer_callback(), switch_core_media_set_codec(), switch_core_media_set_video_codec(), switch_core_session_raw_read(), switch_core_session_reset(), switch_core_session_set_real_read_codec(), switch_ivr_clear_speech_cache(), switch_ivr_collect_digits_count(), switch_ivr_deactivate_unicast(), switch_ivr_detect_audio(), switch_ivr_detect_silence(), switch_ivr_eavesdrop_session(), switch_ivr_gentones(), switch_ivr_originate(), switch_ivr_park(), switch_ivr_play_file(), switch_ivr_record_file_event(), switch_ivr_sleep(), switch_ivr_sound_test(), switch_ivr_speak_text(), switch_ivr_wait_for_answer(), switch_ivr_wait_for_silence(), switch_media_handle_destroy(), and switch_rtp_disable_vad().

918 {
919  switch_mutex_t *mutex = NULL;
920  switch_memory_pool_t *pool = NULL;
921  int free_pool = 0;
922 
923  switch_assert(codec != NULL);
924  mutex = codec->mutex;
925  pool = codec->memory_pool;
926 
927  if (mutex) switch_mutex_lock(mutex);
928 
929  if (switch_core_codec_ready(codec)) {
931  } else {
932  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Codec is not initialized!\n");
933  if (mutex) switch_mutex_unlock(mutex);
935  }
936 
938  free_pool = 1;
939  }
940 
941  codec->implementation->destroy(codec);
942 
944 
945  if (mutex) switch_mutex_unlock(mutex);
946 
947  if (free_pool) {
949  }
950 
951  memset(codec, 0, sizeof(*codec));
952 
953  return SWITCH_STATUS_SUCCESS;
954 }
#define SWITCH_CHANNEL_LOG
switch_core_codec_destroy_func_t destroy
#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_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
#define UNPROTECT_INTERFACE(_it)
#define switch_clear_flag(obj, flag)
Clear a flag on an arbitrary object while locked.
Definition: switch_utils.h:724
const switch_codec_implementation_t * implementation
switch_codec_interface_t * codec_interface
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_memory_pool_t * memory_pool
switch_mutex_t * mutex
struct fspr_thread_mutex_t switch_mutex_t
Definition: switch_apr.h:314
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693
static switch_bool_t switch_core_codec_ready(switch_codec_t *codec)
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_mutex_t * mutex
struct fspr_pool_t switch_memory_pool_t
#define switch_assert(expr)
memset(buf, 0, buflen)

◆ switch_core_codec_encode()

switch_status_t switch_core_codec_encode ( switch_codec_t codec,
switch_codec_t other_codec,
void *  decoded_data,
uint32_t  decoded_data_len,
uint32_t  decoded_rate,
void *  encoded_data,
uint32_t *  encoded_data_len,
uint32_t *  encoded_rate,
unsigned int *  flag 
)

Encode data using a codec handle.

Parameters
codecthe codec handle to use
other_codecthe codec handle of the last codec used
decoded_datathe raw data
decoded_data_lenthen length of the raw buffer
decoded_ratethe rate of the decoded data
encoded_datathe buffer to write the encoded data to
encoded_data_lenthe size of the encoded_data buffer
encoded_ratethe new rate of the encoded data
flagflags to exchange
Returns
SWITCH_STATUS_SUCCESS if the data was encoded
Note
encoded_data_len will be rewritten to the in-use size of encoded_data

Definition at line 743 of file switch_core_codec.c.

References switch_codec_implementation::encode, switch_codec::implementation, switch_codec::mutex, switch_assert, SWITCH_CHANNEL_LOG, SWITCH_CODEC_FLAG_ENCODE, switch_core_codec_ready(), SWITCH_LOG_ERROR, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_NOT_INITALIZED, and switch_test_flag.

Referenced by main(), switch_core_session_read_frame(), and switch_core_session_write_frame().

749 {
750  switch_status_t status;
751 
752  switch_assert(codec != NULL);
753  switch_assert(encoded_data != NULL);
754  switch_assert(decoded_data != NULL);
755 
756  if (!codec->implementation || !switch_core_codec_ready(codec)) {
757  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec is not initialized!\n");
759  }
760 
762  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec encoder is not initialized!\n");
764  }
765 
766  if (codec->mutex) switch_mutex_lock(codec->mutex);
767  status = codec->implementation->encode(codec, other_codec, decoded_data, decoded_data_len,
768  decoded_rate, encoded_data, encoded_data_len, encoded_rate, flag);
769  if (codec->mutex) switch_mutex_unlock(codec->mutex);
770 
771  return status;
772 
773 }
#define SWITCH_CHANNEL_LOG
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
const switch_codec_implementation_t * implementation
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_status_t
Common return values.
switch_core_codec_encode_func_t encode
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:693
static switch_bool_t switch_core_codec_ready(switch_codec_t *codec)
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_mutex_t * mutex
#define switch_assert(expr)

◆ switch_core_codec_encode_video()

switch_status_t switch_core_codec_encode_video ( switch_codec_t codec,
switch_frame_t frame 
)

Encode video data using a codec handle.

Parameters
codecthe codec handle to use
framethe frame to encode

Definition at line 818 of file switch_core_codec.c.

References switch_frame::datalen, switch_codec_implementation::encode_video, switch_frame::flags, switch_codec::implementation, switch_codec::mutex, switch_frame::packetlen, SFF_SAME_IMAGE, switch_assert, SWITCH_CHANNEL_LOG, SWITCH_CODEC_FLAG_ENCODE, switch_core_codec_ready(), SWITCH_LOG_ERROR, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, SWITCH_STATUS_MORE_DATA, SWITCH_STATUS_NOT_INITALIZED, and switch_test_flag.

Referenced by switch_core_session_write_video_frame().

819 {
821 
822  switch_assert(codec != NULL);
823 
824  if (!codec->implementation || !switch_core_codec_ready(codec)) {
825  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec is not initialized!\n");
827  }
828 
830  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec encoder is not initialized!\n");
832  }
833 
834  if (codec->mutex) switch_mutex_lock(codec->mutex);
835 
836  if (codec->implementation->encode_video) {
837  status = codec->implementation->encode_video(codec, frame);
838 
839  if (status == SWITCH_STATUS_MORE_DATA) {
840  frame->flags |= SFF_SAME_IMAGE;
841  } else {
842  frame->flags &= ~SFF_SAME_IMAGE;
843  }
844 
845  frame->packetlen = frame->datalen + 12;
846  }
847 
848  if (codec->mutex) switch_mutex_unlock(codec->mutex);
849 
850  return status;
851 
852 }
#define SWITCH_CHANNEL_LOG
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
const switch_codec_implementation_t * implementation
uint32_t datalen
Definition: switch_frame.h:68
uint32_t packetlen
Definition: switch_frame.h:62
switch_frame_flag_t flags
Definition: switch_frame.h:85
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
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
static switch_bool_t switch_core_codec_ready(switch_codec_t *codec)
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_mutex_t * mutex
switch_core_codec_video_encode_func_t encode_video
#define switch_assert(expr)

◆ switch_core_codec_init_with_bitrate()

switch_status_t switch_core_codec_init_with_bitrate ( switch_codec_t codec,
const char *  codec_name,
const char *  fmtp,
const char *  modname,
uint32_t  rate,
int  ms,
int  channels,
uint32_t  bitrate,
uint32_t  flags,
const switch_codec_settings_t codec_settings,
switch_memory_pool_t pool 
)

Definition at line 643 of file switch_core_codec.c.

References switch_codec_implementation::actual_samples_per_second, switch_codec_implementation::bits_per_second, switch_codec::codec_interface, switch_cache_db_handle::flags, switch_codec::flags, switch_codec::fmtp_in, switch_codec::implementation, switch_codec_interface::implementations, switch_codec_implementation::init, switch_codec::memory_pool, memset(), switch_codec_implementation::microseconds_per_packet, switch_codec::mutex, switch_codec_implementation::next, switch_codec_implementation::number_of_channels, pool, switch_codec_implementation::samples_per_second, switch_codec::session, switch_assert, SWITCH_CHANNEL_LOG, SWITCH_CODEC_FLAG_FREE_POOL, SWITCH_CODEC_FLAG_READY, switch_core_memory_pool_get_data(), switch_core_new_memory_pool, switch_core_strdup, switch_loadable_module_get_codec_interface(), SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_LOG_WARNING, switch_mutex_init(), SWITCH_MUTEX_NESTED, switch_set_flag, SWITCH_STATUS_GENERR, SWITCH_STATUS_NOTIMPL, SWITCH_STATUS_SUCCESS, and UNPROTECT_INTERFACE.

Referenced by main(), and switch_core_media_set_codec().

646 {
647  switch_codec_interface_t *codec_interface;
648  const switch_codec_implementation_t *iptr, *implementation = NULL;
649 
650  switch_assert(codec != NULL);
651  switch_assert(codec_name != NULL);
652 
653  memset(codec, 0, sizeof(*codec));
654 
655  if (pool) {
656  codec->session = switch_core_memory_pool_get_data(pool, "__session");
657  }
658 
659  if (strchr(codec_name, '.')) {
660  char *p = NULL;
661  codec_name = switch_core_strdup(pool, codec_name);
662  if ((p = strchr(codec_name, '.'))) {
663  *p++ = '\0';
664  modname = codec_name;
665  codec_name = p;
666  }
667  }
668 
669  if ((codec_interface = switch_loadable_module_get_codec_interface(codec_name, modname)) == 0) {
670  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid codec %s!\n", codec_name);
671  return SWITCH_STATUS_GENERR;
672  }
673 
674  if (!strncasecmp(codec_name, "PROXY", 5)) {
675  for (iptr = codec_interface->implementations; iptr; iptr = iptr->next) {
676  if (!channels || channels == iptr->number_of_channels) {
677  implementation = iptr;
678  break;
679  }
680  }
681 
682  goto found;
683  }
684 
685  /* If no specific codec interval is requested opt for 20ms above all else because lots of stuff assumes it */
686  if (!ms) {
687  for (iptr = codec_interface->implementations; iptr; iptr = iptr->next) {
688  uint32_t crate = !strcasecmp(codec_name, "g722") ? iptr->samples_per_second : iptr->actual_samples_per_second;
689  if ((!rate || rate == crate) && (!bitrate || bitrate == (uint32_t)iptr->bits_per_second) &&
690  (20 == (iptr->microseconds_per_packet / 1000)) && (!channels || channels == iptr->number_of_channels)) {
691  implementation = iptr;
692  goto found;
693  }
694  }
695  }
696 
697  /* Either looking for a specific interval or there was no interval specified and there wasn't one @20ms available */
698  for (iptr = codec_interface->implementations; iptr; iptr = iptr->next) {
699  uint32_t crate = !strcasecmp(codec_name, "g722") ? iptr->samples_per_second : iptr->actual_samples_per_second;
700  if ((!rate || rate == crate) && (!bitrate || bitrate == (uint32_t)iptr->bits_per_second) &&
701  (!ms || ms == (iptr->microseconds_per_packet / 1000)) && (!channels || channels == iptr->number_of_channels)) {
702  implementation = iptr;
703  break;
704  }
705  }
706 
707  found:
708 
709  if (implementation) {
710  switch_status_t status;
711  codec->codec_interface = codec_interface;
712  codec->implementation = implementation;
713  codec->flags = flags;
714 
715  if (pool) {
716  codec->memory_pool = pool;
717  } else {
719  return status;
720  }
722  }
723 
724  if (fmtp) {
725  codec->fmtp_in = switch_core_strdup(codec->memory_pool, fmtp);
726  }
727 
728  implementation->init(codec, flags, codec_settings);
731  return SWITCH_STATUS_SUCCESS;
732  } else {
733  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Codec %s Exists but not at the desired implementation. %dhz %dms %dch\n",
734  codec_name, rate, ms, channels);
735 
736  }
737 
738  UNPROTECT_INTERFACE(codec_interface);
739 
740  return SWITCH_STATUS_NOTIMPL;
741 }
switch_core_session_t * session
#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_CHANNEL_LOG
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:733
switch_memory_pool_t * pool
switch_codec_implementation_t * implementations
void * switch_core_memory_pool_get_data(switch_memory_pool_t *pool, const char *key)
#define UNPROTECT_INTERFACE(_it)
#define SWITCH_MUTEX_NESTED
Definition: switch_apr.h:318
const switch_codec_implementation_t * implementation
switch_codec_interface_t * codec_interface
switch_memory_pool_t * memory_pool
Top level module interface to implement a series of codec implementations.
switch_status_t switch_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
Definition: switch_apr.c:293
switch_codec_interface_t * switch_loadable_module_get_codec_interface(const char *name, const char *modname)
Retrieve the codec interface by it's registered name.
switch_status_t
Common return values.
switch_core_codec_init_func_t init
struct switch_codec_implementation * next
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
A table of settings and callbacks that define a paticular implementation of a codec.
switch_mutex_t * mutex
#define switch_assert(expr)
memset(buf, 0, buflen)

◆ switch_core_codec_parse_fmtp()

switch_status_t switch_core_codec_parse_fmtp ( const char *  codec_name,
const char *  fmtp,
uint32_t  rate,
switch_codec_fmtp_t codec_fmtp 
)

Definition at line 586 of file switch_core_codec.c.

References switch_codec_fmtp::actual_samples_per_second, memset(), switch_codec_interface::parse_fmtp, switch_loadable_module_get_codec_interface(), SWITCH_STATUS_FALSE, UNPROTECT_INTERFACE, and zstr.

Referenced by add_audio_codec(), and switch_core_media_negotiate_sdp().

587 {
588  switch_codec_interface_t *codec_interface;
590 
591  if (zstr(codec_name) || zstr(fmtp) || !codec_fmtp) {
592  return SWITCH_STATUS_FALSE;
593  }
594 
595  memset(codec_fmtp, 0, sizeof(*codec_fmtp));
596 
597  if ((codec_interface = switch_loadable_module_get_codec_interface(codec_name, NULL))) {
598  if (codec_interface->parse_fmtp) {
599  codec_fmtp->actual_samples_per_second = rate;
600  status = codec_interface->parse_fmtp(fmtp, codec_fmtp);
601  }
602 
603  UNPROTECT_INTERFACE(codec_interface);
604  }
605 
606  return status;
607 }
#define zstr(x)
Definition: switch_utils.h:314
#define UNPROTECT_INTERFACE(_it)
Top level module interface to implement a series of codec implementations.
switch_codec_interface_t * switch_loadable_module_get_codec_interface(const char *name, const char *modname)
Retrieve the codec interface by it's registered name.
switch_status_t
Common return values.
switch_core_codec_fmtp_parse_func_t parse_fmtp
memset(buf, 0, buflen)

◆ switch_core_codec_reset()

switch_status_t switch_core_codec_reset ( switch_codec_t codec)

Definition at line 609 of file switch_core_codec.c.

References switch_codec_implementation::destroy, switch_codec::flags, switch_codec::implementation, switch_codec_implementation::init, switch_assert, and SWITCH_STATUS_SUCCESS.

Referenced by switch_core_session_read_frame(), and switch_core_session_write_frame().

610 {
611  switch_assert(codec != NULL);
612 
613  codec->implementation->destroy(codec);
614  codec->implementation->init(codec, codec->flags, NULL);
615 
616  return SWITCH_STATUS_SUCCESS;
617 }
switch_core_codec_destroy_func_t destroy
const switch_codec_implementation_t * implementation
switch_core_codec_init_func_t init
#define switch_assert(expr)

◆ switch_core_session_get_effective_read_codec()

switch_codec_t* switch_core_session_get_effective_read_codec ( _In_ switch_core_session_t session)

Retrieve the effevtive read codec from a given session.

Parameters
sessionsession to retrieve from
Returns
a pointer to the codec

◆ switch_core_session_get_effective_write_codec()

switch_codec_t* switch_core_session_get_effective_write_codec ( _In_ switch_core_session_t session)

Retrieve the effevtive write codec from a given session.

Parameters
sessionsession to retrieve from
Returns
a pointer to the codec

◆ switch_core_session_get_read_codec()

switch_codec_t* switch_core_session_get_read_codec ( _In_ switch_core_session_t session)

◆ switch_core_session_get_read_impl()

switch_status_t switch_core_session_get_read_impl ( switch_core_session_t session,
switch_codec_implementation_t impp 
)

Definition at line 325 of file switch_core_codec.c.

References switch_codec_implementation::codec_id, memset(), switch_codec_implementation::number_of_channels, switch_core_session::read_impl, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by audio_bridge_thread(), early_thread_run(), inband_dtmf_generate_callback(), inherit_codec(), preprocess_callback(), record_callback(), recording_thread(), session_audio_callback(), setup_ringback(), switch_channel_event_set_basic_data(), switch_core_media_bug_add(), switch_core_media_bug_read(), switch_core_session_get_real_read_impl(), switch_core_session_set_codec_slin(), switch_core_session_transcoding(), switch_core_session_wait_for_video_input_params(), switch_ivr_collect_digits_count(), switch_ivr_delay_echo(), switch_ivr_detect_audio(), switch_ivr_detect_silence(), switch_ivr_detect_speech_init(), switch_ivr_displace_session(), switch_ivr_eavesdrop_session(), switch_ivr_gentones(), switch_ivr_inband_dtmf_session(), switch_ivr_insert_file(), switch_ivr_originate(), switch_ivr_park(), switch_ivr_play_file(), switch_ivr_preprocess_session(), switch_ivr_record_file_event(), switch_ivr_record_session_event(), switch_ivr_session_audio(), switch_ivr_sleep(), switch_ivr_sound_test(), switch_ivr_speak_text(), switch_ivr_tone_detect_session(), and switch_ivr_wait_for_silence().

326 {
327  if (session->read_impl.codec_id) {
328  *impp = session->read_impl;
329  return SWITCH_STATUS_SUCCESS;
330  }
331 
332  memset(impp, 0, sizeof(*impp));
333  impp->number_of_channels = 1;
334  return SWITCH_STATUS_FALSE;
335 }
switch_codec_implementation_t read_impl
memset(buf, 0, buflen)

◆ switch_core_session_get_real_read_impl()

switch_status_t switch_core_session_get_real_read_impl ( switch_core_session_t session,
switch_codec_implementation_t impp 
)

Definition at line 337 of file switch_core_codec.c.

References switch_codec_implementation::codec_id, switch_core_session::real_read_impl, switch_core_session_get_read_impl(), and SWITCH_STATUS_SUCCESS.

Referenced by switch_ivr_eavesdrop_session().

338 {
339  if (session->real_read_impl.codec_id) {
340  *impp = session->real_read_impl;
341  return SWITCH_STATUS_SUCCESS;
342  }
343 
344  return switch_core_session_get_read_impl(session, impp);
345 }
switch_status_t switch_core_session_get_read_impl(switch_core_session_t *session, switch_codec_implementation_t *impp)
switch_codec_implementation_t real_read_impl

◆ switch_core_session_get_video_read_codec()

switch_codec_t* switch_core_session_get_video_read_codec ( _In_ switch_core_session_t session)

Retrieve the video_read codec from a given session.

Parameters
sessionsession to retrieve from
Returns
a pointer to the codec

Referenced by switch_core_session_outgoing_channel().

◆ switch_core_session_get_video_read_impl()

switch_status_t switch_core_session_get_video_read_impl ( switch_core_session_t session,
switch_codec_implementation_t impp 
)

Definition at line 359 of file switch_core_codec.c.

References switch_codec_implementation::codec_id, memset(), switch_codec_implementation::number_of_channels, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_core_session::video_read_impl.

Referenced by inherit_codec(), and text_bridge_thread().

360 {
361  if (session->video_read_impl.codec_id) {
362  *impp = session->video_read_impl;
363  return SWITCH_STATUS_SUCCESS;
364  }
365 
366  memset(impp, 0, sizeof(*impp));
367  impp->number_of_channels = 1;
368  return SWITCH_STATUS_FALSE;
369 }
switch_codec_implementation_t video_read_impl
memset(buf, 0, buflen)

◆ switch_core_session_get_video_write_codec()

switch_codec_t* switch_core_session_get_video_write_codec ( _In_ switch_core_session_t session)

Retrieve the video_write codec from a given session.

Parameters
sessionsession to retrieve from
Returns
a pointer to the codec

Referenced by switch_core_session_write_video_frame().

◆ switch_core_session_get_video_write_impl()

switch_status_t switch_core_session_get_video_write_impl ( switch_core_session_t session,
switch_codec_implementation_t impp 
)

Definition at line 371 of file switch_core_codec.c.

References switch_codec_implementation::codec_id, memset(), switch_codec_implementation::number_of_channels, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, and switch_core_session::video_write_impl.

Referenced by text_bridge_thread().

372 {
373  if (session->video_write_impl.codec_id) {
374  *impp = session->video_write_impl;
375  return SWITCH_STATUS_SUCCESS;
376  }
377 
378  memset(impp, 0, sizeof(*impp));
379  impp->number_of_channels = 1;
380  return SWITCH_STATUS_FALSE;
381 }
switch_codec_implementation_t video_write_impl
memset(buf, 0, buflen)

◆ switch_core_session_get_write_codec()

switch_codec_t* switch_core_session_get_write_codec ( _In_ switch_core_session_t session)

Retrieve the write codec from a given session.

Parameters
sessionsession to retrieve from
Returns
a pointer to the codec

Referenced by setup_ringback(), and switch_channel_test_ready().

◆ switch_core_session_get_write_impl()

switch_status_t switch_core_session_get_write_impl ( switch_core_session_t session,
switch_codec_implementation_t impp 
)

◆ switch_core_session_lock_codec_read()

void switch_core_session_lock_codec_read ( _In_ switch_core_session_t session)

◆ switch_core_session_lock_codec_write()

void switch_core_session_lock_codec_write ( _In_ switch_core_session_t session)

◆ switch_core_session_set_read_codec()

switch_status_t switch_core_session_set_read_codec ( _In_ switch_core_session_t session,
switch_codec_t codec 
)

Assign the read codec to a given session.

Parameters
sessionsession to add the codec to
codecthe codec to add
Returns
SWITCH_STATUS_SUCCESS if successful

Referenced by early_thread_run(), setup_ringback(), switch_core_session_reset(), switch_core_session_set_codec_slin(), switch_ivr_detect_audio(), switch_ivr_detect_silence(), switch_ivr_eavesdrop_session(), switch_ivr_record_file_event(), switch_ivr_wait_for_answer(), and switch_ivr_wait_for_silence().

◆ switch_core_session_set_real_read_codec()

switch_status_t switch_core_session_set_real_read_codec ( _In_ switch_core_session_t session,
switch_codec_t codec 
)

Assign the original read codec to a given session. This is the read codec used by an endpoint.

Parameters
sessionsession to add the codec to
codecthe codec to add
Returns
SWITCH_STATUS_SUCCESS if successful

Referenced by switch_core_media_set_codec().

◆ switch_core_session_set_video_read_codec()

switch_status_t switch_core_session_set_video_read_codec ( _In_ switch_core_session_t session,
switch_codec_t codec 
)

Assign the video_read codec to a given session.

Parameters
sessionsession to add the codec to
codecthe codec to add
Returns
SWITCH_STATUS_SUCCESS if successful

Referenced by switch_core_media_set_video_codec().

◆ switch_core_session_set_video_write_codec()

switch_status_t switch_core_session_set_video_write_codec ( _In_ switch_core_session_t session,
switch_codec_t codec 
)

Assign the video_write codec to a given session.

Parameters
sessionsession to add the codec to
codecthe codec to add
Returns
SWITCH_STATUS_SUCCESS if successful

Referenced by switch_core_media_set_video_codec().

◆ switch_core_session_set_write_codec()

switch_status_t switch_core_session_set_write_codec ( _In_ switch_core_session_t session,
switch_codec_t codec 
)

Assign the write codec to a given session.

Parameters
sessionsession to add the codec to
codecthe codec to add
Returns
SWITCH_STATUS_SUCCESS if successful

Referenced by switch_core_media_set_codec().

◆ switch_core_session_unlock_codec_read()

void switch_core_session_unlock_codec_read ( _In_ switch_core_session_t session)

◆ switch_core_session_unlock_codec_write()

void switch_core_session_unlock_codec_write ( _In_ switch_core_session_t session)

◆ switch_core_session_unset_read_codec()

void switch_core_session_unset_read_codec ( _In_ switch_core_session_t session)

◆ switch_core_session_unset_write_codec()

void switch_core_session_unset_write_codec ( _In_ switch_core_session_t session)