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

#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 1602 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_eavesdrop_session(), switch_ivr_gentones(), switch_ivr_park(), switch_ivr_play_file(), switch_ivr_record_file(), 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_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 870 of file switch_core_codec.c.

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

878 {
879 
881 
882 
883  switch_assert(codec != NULL);
884 
885 
886  if (!codec->implementation || !switch_core_codec_ready(codec)) {
887  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec is not initialized!\n");
888  abort();
889  //return SWITCH_STATUS_NOT_INITALIZED;
890  }
891 
892 
893  if (codec->mutex) switch_mutex_lock(codec->mutex);
894 
895  if (codec->implementation->codec_control) {
896  status = codec->implementation->codec_control(codec, cmd, ctype, cmd_data, atype, cmd_arg, rtype, ret_data);
897  }
898 
899  if (codec->mutex) switch_mutex_unlock(codec->mutex);
900 
901 
902  return status;
903 }
#define SWITCH_CHANNEL_LOG
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
const switch_codec_implementation_t * implementation
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
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_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 612 of file switch_core_codec.c.

References switch_assert, and switch_core_codec_init.

Referenced by switch_core_session_read_frame().

614 {
615  switch_assert(codec != NULL);
616  switch_assert(new_codec != NULL);
617 
618  return switch_core_codec_init(new_codec,
619  codec->implementation->iananame,
620  codec->implementation->modname,
621  codec->fmtp_in,
625  codec->flags,
626  codec_settings,
627  pool);
628 
629 }
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:1602
#define switch_assert(expr)
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 763 of file switch_core_codec.c.

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

769 {
770  switch_status_t status;
771 
772  switch_assert(codec != NULL);
773  switch_assert(encoded_data != NULL);
774  switch_assert(decoded_data != NULL);
775 
776  if (!codec->implementation || !switch_core_codec_ready(codec)) {
777  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Decode Codec is not initialized!\n");
779  }
780 
782  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec decoder is not initialized!\n");
784  }
785 
787  uint32_t frames = encoded_data_len / codec->implementation->encoded_bytes_per_packet / codec->implementation->number_of_channels;
788 
789  if (frames && codec->implementation->decoded_bytes_per_packet * frames > *decoded_data_len) {
790  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Buffer size sanity check failed! edl:%u ebpp:%u fr:%u ddl:%u\n",
791  encoded_data_len, codec->implementation->encoded_bytes_per_packet, frames, *decoded_data_len);
792  *decoded_data_len = codec->implementation->decoded_bytes_per_packet;
793  memset(decoded_data, 255, *decoded_data_len);
794  return SWITCH_STATUS_SUCCESS;
795  }
796  }
797 
798  if (codec->mutex) switch_mutex_lock(codec->mutex);
799  status = codec->implementation->decode(codec, other_codec, encoded_data, encoded_data_len, encoded_rate,
800  decoded_data, decoded_data_len, decoded_rate, flag);
801  if (codec->mutex) switch_mutex_unlock(codec->mutex);
802 
803  return status;
804 }
#define SWITCH_CHANNEL_LOG
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
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:285
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
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_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 842 of file switch_core_codec.c.

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

843 {
845 
846  switch_assert(codec != NULL);
847  switch_assert(frame != NULL);
848 
849  if (!codec->implementation || !switch_core_codec_ready(codec)) {
850  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Decode Codec is not initialized!\n");
852  }
853 
855  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec decoder is not initialized!\n");
857  }
858 
859  if (codec->mutex) switch_mutex_lock(codec->mutex);
860 
861  if (codec->implementation->decode_video) {
862  status = codec->implementation->decode_video(codec, frame);
863  }
864  if (codec->mutex) switch_mutex_unlock(codec->mutex);
865 
866  return status;
867 }
#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:290
const switch_codec_implementation_t * implementation
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
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
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_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 905 of file switch_core_codec.c.

References memset(), 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_eavesdrop_session(), switch_ivr_gentones(), switch_ivr_originate(), switch_ivr_park(), switch_ivr_play_file(), switch_ivr_record_file(), 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().

906 {
907  switch_mutex_t *mutex = codec->mutex;
909  int free_pool = 0;
910 
911  switch_assert(codec != NULL);
912 
913  if (mutex) switch_mutex_lock(mutex);
914 
915  if (switch_core_codec_ready(codec)) {
917  } else {
918  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Codec is not initialized!\n");
919  if (mutex) switch_mutex_unlock(mutex);
921  }
922 
924  free_pool = 1;
925  }
926 
927  codec->implementation->destroy(codec);
928 
930 
931  if (mutex) switch_mutex_unlock(mutex);
932 
933  if (free_pool) {
935  }
936 
937  memset(codec, 0, sizeof(*codec));
938 
939  return SWITCH_STATUS_SUCCESS;
940 }
#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:640
switch_memory_pool_t * pool
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
#define UNPROTECT_INTERFACE(_it)
#define switch_clear_flag(obj, flag)
Clear a flag on an arbitrary object while locked.
Definition: switch_utils.h:655
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:285
switch_memory_pool_t * memory_pool
switch_mutex_t * mutex
struct apr_thread_mutex_t switch_mutex_t
Definition: switch_apr.h:314
struct apr_pool_t switch_memory_pool_t
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
Definition: switch_utils.h:624
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_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 731 of file switch_core_codec.c.

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

737 {
738  switch_status_t status;
739 
740  switch_assert(codec != NULL);
741  switch_assert(encoded_data != NULL);
742  switch_assert(decoded_data != NULL);
743 
744  if (!codec->implementation || !switch_core_codec_ready(codec)) {
745  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec is not initialized!\n");
747  }
748 
750  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec encoder is not initialized!\n");
752  }
753 
754  if (codec->mutex) switch_mutex_lock(codec->mutex);
755  status = codec->implementation->encode(codec, other_codec, decoded_data, decoded_data_len,
756  decoded_rate, encoded_data, encoded_data_len, encoded_rate, flag);
757  if (codec->mutex) switch_mutex_unlock(codec->mutex);
758 
759  return status;
760 
761 }
#define SWITCH_CHANNEL_LOG
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
const switch_codec_implementation_t * implementation
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
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:624
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_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 806 of file switch_core_codec.c.

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

807 {
809 
810  switch_assert(codec != NULL);
811 
812  if (!codec->implementation || !switch_core_codec_ready(codec)) {
813  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec is not initialized!\n");
815  }
816 
818  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec encoder is not initialized!\n");
820  }
821 
822  if (codec->mutex) switch_mutex_lock(codec->mutex);
823 
824  if (codec->implementation->encode_video) {
825  status = codec->implementation->encode_video(codec, frame);
826 
827  if (status == SWITCH_STATUS_MORE_DATA) {
828  frame->flags |= SFF_SAME_IMAGE;
829  } else {
830  frame->flags &= ~SFF_SAME_IMAGE;
831  }
832 
833  frame->packetlen = frame->datalen + 12;
834  }
835 
836  if (codec->mutex) switch_mutex_unlock(codec->mutex);
837 
838  return status;
839 
840 }
#define SWITCH_CHANNEL_LOG
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
const switch_codec_implementation_t * implementation
uint32_t datalen
Definition: switch_frame.h:57
uint32_t packetlen
Definition: switch_frame.h:51
switch_frame_flag_t flags
Definition: switch_frame.h:74
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
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
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_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 631 of file switch_core_codec.c.

References switch_codec_implementation::actual_samples_per_second, switch_codec_implementation::bits_per_second, switch_cache_db_handle::flags, switch_codec_interface::implementations, switch_codec_implementation::init, memset(), switch_codec_implementation::microseconds_per_packet, switch_codec_implementation::next, switch_codec_implementation::number_of_channels, pool, switch_codec_implementation::samples_per_second, 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().

634 {
635  switch_codec_interface_t *codec_interface;
636  const switch_codec_implementation_t *iptr, *implementation = NULL;
637 
638  switch_assert(codec != NULL);
639  switch_assert(codec_name != NULL);
640 
641  memset(codec, 0, sizeof(*codec));
642 
643  if (pool) {
644  codec->session = switch_core_memory_pool_get_data(pool, "__session");
645  }
646 
647  if (strchr(codec_name, '.')) {
648  char *p = NULL;
649  codec_name = switch_core_strdup(pool, codec_name);
650  if ((p = strchr(codec_name, '.'))) {
651  *p++ = '\0';
652  modname = codec_name;
653  codec_name = p;
654  }
655  }
656 
657  if ((codec_interface = switch_loadable_module_get_codec_interface(codec_name, modname)) == 0) {
658  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid codec %s!\n", codec_name);
659  return SWITCH_STATUS_GENERR;
660  }
661 
662  if (!strncasecmp(codec_name, "PROXY", 5)) {
663  for (iptr = codec_interface->implementations; iptr; iptr = iptr->next) {
664  if ((!channels || channels == iptr->number_of_channels)) {
665  implementation = iptr;
666  break;
667  }
668  }
669 
670  goto found;
671  }
672 
673  /* If no specific codec interval is requested opt for 20ms above all else because lots of stuff assumes it */
674  if (!ms) {
675  for (iptr = codec_interface->implementations; iptr; iptr = iptr->next) {
676  uint32_t crate = !strcasecmp(codec_name, "g722") ? iptr->samples_per_second : iptr->actual_samples_per_second;
677  if ((!rate || rate == crate) && (!bitrate || bitrate == (uint32_t)iptr->bits_per_second) &&
678  (20 == (iptr->microseconds_per_packet / 1000)) && (!channels || channels == iptr->number_of_channels)) {
679  implementation = iptr;
680  goto found;
681  }
682  }
683  }
684 
685  /* Either looking for a specific interval or there was no interval specified and there wasn't one @20ms available */
686  for (iptr = codec_interface->implementations; iptr; iptr = iptr->next) {
687  uint32_t crate = !strcasecmp(codec_name, "g722") ? iptr->samples_per_second : iptr->actual_samples_per_second;
688  if ((!rate || rate == crate) && (!bitrate || bitrate == (uint32_t)iptr->bits_per_second) &&
689  (!ms || ms == (iptr->microseconds_per_packet / 1000)) && (!channels || channels == iptr->number_of_channels)) {
690  implementation = iptr;
691  break;
692  }
693  }
694 
695  found:
696 
697  if (implementation) {
698  switch_status_t status;
699  codec->codec_interface = codec_interface;
700  codec->implementation = implementation;
701  codec->flags = flags;
702 
703  if (pool) {
704  codec->memory_pool = pool;
705  } else {
707  return status;
708  }
710  }
711 
712  if (fmtp) {
713  codec->fmtp_in = switch_core_strdup(codec->memory_pool, fmtp);
714  }
715 
716  implementation->init(codec, flags, codec_settings);
719  return SWITCH_STATUS_SUCCESS;
720  } else {
721  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Codec %s Exists but not at the desired implementation. %dhz %dms %dch\n",
722  codec_name, rate, ms, channels);
723 
724  }
725 
726  UNPROTECT_INTERFACE(codec_interface);
727 
728  return SWITCH_STATUS_NOTIMPL;
729 }
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:631
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
Definition: switch_utils.h:631
#define SWITCH_CHANNEL_LOG
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given pool.
Definition: switch_core.h:729
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:270
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_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 578 of file switch_core_codec.c.

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

579 {
580  switch_codec_interface_t *codec_interface;
582 
583  if (zstr(codec_name) || zstr(fmtp) || !codec_fmtp) {
584  return SWITCH_STATUS_FALSE;
585  }
586 
587  memset(codec_fmtp, 0, sizeof(*codec_fmtp));
588 
589  if ((codec_interface = switch_loadable_module_get_codec_interface(codec_name, NULL))) {
590  if (codec_interface->parse_fmtp) {
591  codec_fmtp->actual_samples_per_second = rate;
592  status = codec_interface->parse_fmtp(fmtp, codec_fmtp);
593  }
594 
595  UNPROTECT_INTERFACE(codec_interface);
596  }
597 
598  return status;
599 }
#define zstr(x)
Definition: switch_utils.h:281
#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_status_t switch_core_codec_reset ( switch_codec_t codec)

Definition at line 601 of file switch_core_codec.c.

References switch_assert, and SWITCH_STATUS_SUCCESS.

Referenced by switch_core_session_read_frame(), and switch_core_session_write_frame().

602 {
603  switch_assert(codec != NULL);
604 
605  codec->implementation->destroy(codec);
606  codec->implementation->init(codec, codec->flags, NULL);
607 
608  return SWITCH_STATUS_SUCCESS;
609 }
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_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_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_codec_t* switch_core_session_get_read_codec ( _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 
)

Definition at line 317 of file switch_core_codec.c.

References memset(), 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_wait_for_video_input_params(), switch_ivr_collect_digits_count(), switch_ivr_delay_echo(), 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(), switch_ivr_record_session(), 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().

318 {
319  if (session->read_impl.codec_id) {
320  *impp = session->read_impl;
321  return SWITCH_STATUS_SUCCESS;
322  }
323 
324  memset(impp, 0, sizeof(*impp));
325  impp->number_of_channels = 1;
326  return SWITCH_STATUS_FALSE;
327 }
switch_codec_implementation_t read_impl
memset(buf, 0, buflen)
switch_status_t switch_core_session_get_real_read_impl ( switch_core_session_t session,
switch_codec_implementation_t impp 
)

Definition at line 329 of file switch_core_codec.c.

References switch_core_session_get_read_impl(), and SWITCH_STATUS_SUCCESS.

330 {
331  if (session->real_read_impl.codec_id) {
332  *impp = session->real_read_impl;
333  return SWITCH_STATUS_SUCCESS;
334  }
335 
336  return switch_core_session_get_read_impl(session, impp);
337 }
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_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_status_t switch_core_session_get_video_read_impl ( switch_core_session_t session,
switch_codec_implementation_t impp 
)

Definition at line 351 of file switch_core_codec.c.

References memset(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by inherit_codec().

352 {
353  if (session->video_read_impl.codec_id) {
354  *impp = session->video_read_impl;
355  return SWITCH_STATUS_SUCCESS;
356  }
357 
358  memset(impp, 0, sizeof(*impp));
359  impp->number_of_channels = 1;
360  return SWITCH_STATUS_FALSE;
361 }
switch_codec_implementation_t video_read_impl
memset(buf, 0, buflen)
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_status_t switch_core_session_get_video_write_impl ( switch_core_session_t session,
switch_codec_implementation_t impp 
)

Definition at line 363 of file switch_core_codec.c.

References memset(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

364 {
365  if (session->video_write_impl.codec_id) {
366  *impp = session->video_write_impl;
367  return SWITCH_STATUS_SUCCESS;
368  }
369 
370  memset(impp, 0, sizeof(*impp));
371  impp->number_of_channels = 1;
372  return SWITCH_STATUS_FALSE;
373 }
switch_codec_implementation_t video_write_impl
memset(buf, 0, buflen)
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_status_t switch_core_session_get_write_impl ( switch_core_session_t session,
switch_codec_implementation_t impp 
)

Definition at line 339 of file switch_core_codec.c.

References memset(), SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

Referenced by setup_ringback(), switch_channel_event_set_basic_data(), and switch_core_media_bug_add().

340 {
341  if (session->write_impl.codec_id) {
342  *impp = session->write_impl;
343  return SWITCH_STATUS_SUCCESS;
344  }
345 
346  memset(impp, 0, sizeof(*impp));
347  impp->number_of_channels = 1;
348  return SWITCH_STATUS_FALSE;
349 }
switch_codec_implementation_t write_impl
memset(buf, 0, buflen)
void switch_core_session_lock_codec_read ( _In_ switch_core_session_t session)
void switch_core_session_lock_codec_write ( _In_ switch_core_session_t session)
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_eavesdrop_session(), switch_ivr_record_file(), switch_ivr_wait_for_answer(), and switch_ivr_wait_for_silence().

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

void switch_core_session_unlock_codec_read ( _In_ switch_core_session_t session)
void switch_core_session_unlock_codec_write ( _In_ switch_core_session_t session)
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)