RTS API Documentation  1.10.11
Functions | Variables
switch_core_codec.c File Reference
#include <switch.h>
#include "private/switch_core_pvt.h"
+ Include dependency graph for switch_core_codec.c:

Go to the source code of this file.

Functions

uint32_t switch_core_codec_next_id (void)
 
void switch_core_session_unset_read_codec (switch_core_session_t *session)
 
void switch_core_codec_lock_full (switch_core_session_t *session)
 Lock codec read mutex and codec write mutex using trylock in an infinite loop. More...
 
void switch_core_codec_unlock_full (switch_core_session_t *session)
 Unlock codec read mutex and codec write mutex. More...
 
void switch_core_session_lock_codec_write (switch_core_session_t *session)
 
void switch_core_session_unlock_codec_write (switch_core_session_t *session)
 
void switch_core_session_lock_codec_read (switch_core_session_t *session)
 
void switch_core_session_unlock_codec_read (switch_core_session_t *session)
 
void switch_core_session_unset_write_codec (switch_core_session_t *session)
 
switch_status_t switch_core_session_set_real_read_codec (switch_core_session_t *session, switch_codec_t *codec)
 
switch_status_t switch_core_session_set_read_codec (switch_core_session_t *session, switch_codec_t *codec)
 
switch_codec_tswitch_core_session_get_effective_read_codec (switch_core_session_t *session)
 
switch_codec_tswitch_core_session_get_read_codec (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_status_t switch_core_session_set_read_impl (switch_core_session_t *session, const switch_codec_implementation_t *impp)
 
switch_status_t switch_core_session_set_write_impl (switch_core_session_t *session, const switch_codec_implementation_t *impp)
 
switch_status_t switch_core_session_set_video_read_impl (switch_core_session_t *session, const switch_codec_implementation_t *impp)
 
switch_status_t switch_core_session_set_video_write_impl (switch_core_session_t *session, const switch_codec_implementation_t *impp)
 
switch_status_t switch_core_session_set_write_codec (switch_core_session_t *session, switch_codec_t *codec)
 
switch_codec_tswitch_core_session_get_effective_write_codec (switch_core_session_t *session)
 
switch_codec_tswitch_core_session_get_write_codec (switch_core_session_t *session)
 
switch_status_t switch_core_session_set_video_read_codec (switch_core_session_t *session, switch_codec_t *codec)
 
switch_codec_tswitch_core_session_get_video_read_codec (switch_core_session_t *session)
 
switch_status_t switch_core_session_set_video_write_codec (switch_core_session_t *session, switch_codec_t *codec)
 
switch_codec_tswitch_core_session_get_video_write_codec (switch_core_session_t *session)
 
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_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_init_with_bitrate (switch_codec_t *codec, const char *codec_name, const char *modname, const char *fmtp, 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_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_decode_video (switch_codec_t *codec, switch_frame_t *frame)
 Decode 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_destroy (switch_codec_t *codec)
 Destroy an initalized codec handle. More...
 

Variables

static uint32_t CODEC_ID = 1
 

Function Documentation

◆ switch_core_session_get_effective_read_codec()

switch_codec_t* switch_core_session_get_effective_read_codec ( switch_core_session_t session)

Definition at line 332 of file switch_core_codec.c.

References switch_core_session::read_codec.

333 {
334  switch_codec_t *codec;
335  codec = session->read_codec;
336  return codec;
337 }
switch_codec_t * read_codec

◆ switch_core_session_get_effective_write_codec()

switch_codec_t* switch_core_session_get_effective_write_codec ( switch_core_session_t session)

Definition at line 495 of file switch_core_codec.c.

References switch_core_session::write_codec.

496 {
497  switch_codec_t *codec;
498  codec = session->write_codec;
499 
500  return codec;
501 }
switch_codec_t * write_codec

◆ switch_core_session_get_read_codec()

switch_codec_t* switch_core_session_get_read_codec ( switch_core_session_t session)

Definition at line 339 of file switch_core_codec.c.

References switch_core_session::read_codec, and switch_core_session::real_read_codec.

340 {
341  switch_codec_t *codec;
342  codec = session->real_read_codec ? session->real_read_codec : session->read_codec;
343  return codec;
344 }
switch_codec_t * read_codec
switch_codec_t * real_read_codec

◆ switch_core_session_get_video_read_codec()

switch_codec_t* switch_core_session_get_video_read_codec ( switch_core_session_t session)

Definition at line 553 of file switch_core_codec.c.

References switch_core_session::video_read_codec.

554 {
555  switch_codec_t *codec;
556  codec = session->video_read_codec;
557 
558  return codec;
559 
560 }
switch_codec_t * video_read_codec

◆ switch_core_session_get_video_write_codec()

switch_codec_t* switch_core_session_get_video_write_codec ( switch_core_session_t session)

Definition at line 598 of file switch_core_codec.c.

References switch_core_session::video_write_codec.

599 {
600  switch_codec_t *codec;
601  codec = session->video_write_codec;
602 
603  return codec;
604 
605 }
switch_codec_t * video_write_codec

◆ switch_core_session_get_write_codec()

switch_codec_t* switch_core_session_get_write_codec ( switch_core_session_t session)

Definition at line 503 of file switch_core_codec.c.

References switch_core_session::real_write_codec, and switch_core_session::write_codec.

504 {
505  switch_codec_t *codec;
506  codec = session->real_write_codec ? session->real_write_codec : session->write_codec;
507 
508  return codec;
509 }
switch_codec_t * write_codec
switch_codec_t * real_write_codec

◆ switch_core_session_lock_codec_read()

void switch_core_session_lock_codec_read ( switch_core_session_t session)

Definition at line 93 of file switch_core_codec.c.

References switch_core_session::codec_read_mutex, and switch_mutex_lock().

94 {
96 }
switch_mutex_t * codec_read_mutex
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308

◆ switch_core_session_lock_codec_write()

void switch_core_session_lock_codec_write ( switch_core_session_t session)

Definition at line 83 of file switch_core_codec.c.

References switch_core_session::codec_write_mutex, and switch_mutex_lock().

84 {
86 }
switch_mutex_t * codec_write_mutex
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308

◆ switch_core_session_set_read_codec()

switch_status_t switch_core_session_set_read_codec ( switch_core_session_t session,
switch_codec_t codec 
)

Definition at line 224 of file switch_core_codec.c.

References switch_codec_implementation::actual_samples_per_second, switch_codec_implementation::bits_per_second, CF_MEDIA_SET, switch_core_session::channel, switch_frame::codec, switch_core_session::codec_read_mutex, switch_codec_implementation::decoded_bytes_per_packet, switch_core_session::enc_read_frame, switch_core_session::enc_write_frame, switch_codec_implementation::ianacode, switch_codec_implementation::iananame, switch_codec::implementation, memset(), switch_codec::next, switch_core_session::raw_read_frame, switch_core_session::raw_write_frame, switch_core_session::read_codec, switch_core_session::read_impl, switch_core_session::real_read_codec, switch_core_session::real_read_impl, switch_codec_implementation::samples_per_second, switch_channel_event_set_data(), switch_channel_get_name(), SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_flag, switch_channel_set_variable, switch_core_codec_ready(), switch_core_session_get_channel(), switch_event_add_header(), switch_event_add_header_string(), SWITCH_EVENT_CODEC, switch_event_create, switch_event_fire, SWITCH_LOG_DEBUG, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), switch_snprintf(), SWITCH_STACK_BOTTOM, SWITCH_STATUS_FALSE, and SWITCH_STATUS_SUCCESS.

225 {
226  switch_event_t *event;
228  char tmp[30];
230 
232 
233  if (codec && (!codec->implementation || !switch_core_codec_ready(codec))) {
234  codec = NULL;
235  }
236 
237  if (codec) {
238  if (!session->real_read_codec) {
239  session->read_codec = session->real_read_codec = codec;
240  if (codec->implementation) {
241  session->read_impl = *codec->implementation;
242  session->real_read_impl = *codec->implementation;
243  } else {
244  memset(&session->read_impl, 0, sizeof(session->read_impl));
245  }
246  } else {
247  if (codec == session->read_codec) {
248  goto end;
249  }
250  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Push codec %s:%d\n",
251  switch_channel_get_name(session->channel), codec->implementation ? codec->implementation->iananame : "undefined", codec->implementation ? codec->implementation->ianacode : -1);
252  codec->next = session->read_codec;
253  session->read_codec = codec;
254  if (codec->implementation) {
255  session->read_impl = *codec->implementation;
256  } else {
257  memset(&session->read_impl, 0, sizeof(session->read_impl));
258  }
259  }
260  } else {
261  if (session->read_codec == session->real_read_codec) {
262  goto end;
263  }
264 
265  if (session->read_codec->next && switch_core_codec_ready(session->read_codec->next)) {
266  switch_codec_t *old = session->read_codec;
267  session->read_codec = session->read_codec->next;
268  if (session->read_codec->implementation) {
269  session->read_impl = *session->read_codec->implementation;
270  } else {
271  memset(&session->read_impl, 0, sizeof(session->read_impl));
272  }
273  old->next = NULL;
274 
275  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Restore previous codec %s:%d.\n",
277  session->read_impl.iananame ? session->read_impl.iananame : "N/A", session->read_impl.ianacode);
278 
279 
280  } else if (session->real_read_codec) {
281  session->read_codec = session->real_read_codec;
282  if (session->real_read_codec->implementation) {
283  session->read_impl = *session->real_read_codec->implementation;
284  } else {
285  memset(&session->read_impl, 0, sizeof(session->read_impl));
286  }
287  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Restore original codec.\n");
288  } else {
289  status = SWITCH_STATUS_FALSE;
290  goto end;
291  }
292  }
293 
294  if (!session->read_codec) {
295  status = SWITCH_STATUS_FALSE;
296  goto end;
297  }
298 
299  if (session->read_impl.decoded_bytes_per_packet) {
301  switch_channel_event_set_data(session->channel, event);
302  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-read-codec-name", session->read_impl.iananame);
303  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-read-codec-rate", "%d", session->read_impl.actual_samples_per_second);
304  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-read-codec-bit-rate", "%d", session->read_impl.bits_per_second);
306  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-reported-read-codec-rate", "%d", session->read_impl.samples_per_second);
307  }
308  switch_event_fire(&event);
309  }
310 
311  switch_channel_set_variable(channel, "read_codec", session->read_impl.iananame);
312  switch_snprintf(tmp, sizeof(tmp), "%d", session->read_impl.actual_samples_per_second);
313  switch_channel_set_variable(channel, "read_rate", tmp);
314 
315  session->raw_read_frame.codec = session->read_codec;
316  session->raw_write_frame.codec = session->read_codec;
317  session->enc_read_frame.codec = session->read_codec;
318  session->enc_write_frame.codec = session->read_codec;
319  }
320 
321  end:
322 
323  if (session->read_codec) {
325  }
326 
328  return status;
329 
330 }
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:413
#define SWITCH_CHANNEL_SESSION_LOG(x)
switch_frame_t enc_read_frame
switch_mutex_t * codec_read_mutex
void switch_channel_event_set_data(_In_ switch_channel_t *channel, _In_ switch_event_t *event)
Add information about a given channel to an event object.
switch_codec_t * read_codec
switch_status_t switch_event_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *fmt,...) PRINTF_FUNCTION(4
Add a header to an event.
Representation of an event.
Definition: switch_event.h:80
switch_codec_t * real_read_codec
switch_codec_implementation_t read_impl
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
switch_codec_t * codec
Definition: switch_frame.h:56
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
const switch_codec_implementation_t * implementation
switch_codec_implementation_t real_read_impl
switch_channel_t * channel
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_status_t switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
Add a string header to an event.
struct switch_codec * next
switch_frame_t raw_read_frame
switch_status_t
Common return values.
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
Definition: switch_event.h:384
switch_frame_t enc_write_frame
#define switch_channel_set_flag(_c, _f)
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.
#define switch_channel_set_variable(_channel, _var, _val)
switch_frame_t raw_write_frame
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
memset(buf, 0, buflen)

◆ switch_core_session_set_real_read_codec()

switch_status_t switch_core_session_set_real_read_codec ( switch_core_session_t session,
switch_codec_t codec 
)

Definition at line 115 of file switch_core_codec.c.

References switch_codec_implementation::actual_samples_per_second, switch_codec_implementation::bits_per_second, switch_core_session::bug_codec, switch_core_session::bug_rwlock, CF_MEDIA_SET, switch_core_session::channel, switch_frame::codec, switch_core_session::codec_read_mutex, switch_codec_implementation::decoded_bytes_per_packet, switch_core_session::enc_read_frame, switch_core_session::enc_write_frame, switch_codec_implementation::ianacode, switch_codec_implementation::iananame, switch_codec::implementation, memset(), switch_codec::next, switch_core_session::raw_read_frame, switch_core_session::raw_write_frame, switch_core_session::read_codec, switch_core_session::read_impl, switch_core_session::real_read_codec, switch_core_session::real_read_impl, switch_codec_implementation::samples_per_second, switch_channel_event_set_data(), switch_channel_get_name(), SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_flag, switch_channel_set_variable, switch_core_codec_destroy(), switch_core_codec_ready(), switch_core_session_get_channel(), switch_event_add_header(), switch_event_add_header_string(), SWITCH_EVENT_CODEC, switch_event_create, switch_event_fire, SWITCH_LOG_DEBUG, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), switch_snprintf(), SWITCH_STACK_BOTTOM, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_thread_rwlock_unlock(), and switch_thread_rwlock_wrlock().

116 {
117  switch_event_t *event;
119  char tmp[30];
121  int changed_read_codec = 0;
122 
124 
125  if (codec && (!codec->implementation || !switch_core_codec_ready(codec))) {
126  codec = NULL;
127  }
128 
129  if (codec) {
130  /* set real_read_codec and read_codec */
131  if (!session->real_read_codec) {
132  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Original read codec set to %s:%d\n",
134  session->read_codec = session->real_read_codec = codec;
135  changed_read_codec = 1;
136  if (codec->implementation) {
137  session->read_impl = *codec->implementation;
138  session->real_read_impl = *codec->implementation;
139  } else {
140  memset(&session->read_impl, 0, sizeof(session->read_impl));
141  }
142  } else { /* replace real_read_codec */
143  switch_codec_t *cur_codec;
144 
145  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Original read codec replaced with %s:%d\n",
146  switch_channel_get_name(session->channel), codec->implementation ? codec->implementation->iananame : "undefined", codec->implementation ? codec->implementation->ianacode : -1);
147  /* Set real_read_codec to front of the list of read_codecs */
148  cur_codec = session->read_codec;
149  while (cur_codec != NULL) {
150  if (cur_codec->next == session->real_read_codec) {
151  cur_codec->next = codec;
152  break;
153  }
154 
155  cur_codec = cur_codec->next;
156  }
157 
158  session->real_read_codec = codec;
159  session->real_read_impl = *codec->implementation;
160 
161  /* set read_codec with real_read_codec if it no longer is ready */
162  if (!switch_core_codec_ready(session->read_codec)) {
163  session->read_codec = codec;
164  changed_read_codec = 1;
165  if (codec->implementation) {
166  session->read_impl = *codec->implementation;
167  session->real_read_impl = *codec->implementation;
168  } else {
169  memset(&session->read_impl, 0, sizeof(session->read_impl));
170  }
171  }
172  }
173 
174  /* force media bugs to copy the read codec from the next frame */
176  if (switch_core_codec_ready(&session->bug_codec)) {
177  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Destroying BUG Codec %s:%d\n",
180  }
181 
183  } else {
184  status = SWITCH_STATUS_FALSE;
185  goto end;
186  }
187 
188  if (changed_read_codec && session->read_codec && session->read_impl.decoded_bytes_per_packet) {
190  switch_channel_event_set_data(session->channel, event);
191  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-read-codec-name", session->read_impl.iananame);
192  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-read-codec-rate", "%d", session->read_impl.actual_samples_per_second);
193  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-read-codec-bit-rate", "%d", session->read_impl.bits_per_second);
195  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-reported-read-codec-rate", "%d", session->read_impl.samples_per_second);
196  }
197 
198  switch_event_fire(&event);
199  }
200 
201  switch_channel_set_variable(channel, "read_codec", session->read_impl.iananame);
202  switch_channel_set_variable(channel, "original_read_codec", session->read_impl.iananame);
203  switch_snprintf(tmp, sizeof(tmp), "%d", session->read_impl.actual_samples_per_second);
204  switch_channel_set_variable(channel, "read_rate", tmp);
205  switch_channel_set_variable(channel, "original_read_rate", tmp);
206 
207  session->raw_read_frame.codec = session->read_codec;
208  session->raw_write_frame.codec = session->read_codec;
209  session->enc_read_frame.codec = session->read_codec;
210  session->enc_write_frame.codec = session->read_codec;
211  }
212 
213  end:
214 
215  if (session->read_codec) {
217  }
218 
220 
221  return status;
222 }
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:413
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:286
#define SWITCH_CHANNEL_SESSION_LOG(x)
switch_thread_rwlock_t * bug_rwlock
switch_frame_t enc_read_frame
switch_mutex_t * codec_read_mutex
void switch_channel_event_set_data(_In_ switch_channel_t *channel, _In_ switch_event_t *event)
Add information about a given channel to an event object.
switch_codec_t * read_codec
switch_status_t switch_event_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *fmt,...) PRINTF_FUNCTION(4
Add a header to an event.
Representation of an event.
Definition: switch_event.h:80
switch_codec_t * real_read_codec
switch_codec_implementation_t read_impl
switch_status_t switch_core_codec_destroy(switch_codec_t *codec)
Destroy an initalized codec handle.
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
switch_codec_t * codec
Definition: switch_frame.h:56
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
switch_status_t switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:260
const switch_codec_implementation_t * implementation
switch_codec_implementation_t real_read_impl
switch_channel_t * channel
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_status_t switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
Add a string header to an event.
struct switch_codec * next
switch_codec_t bug_codec
switch_frame_t raw_read_frame
switch_status_t
Common return values.
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
Definition: switch_event.h:384
switch_frame_t enc_write_frame
#define switch_channel_set_flag(_c, _f)
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.
#define switch_channel_set_variable(_channel, _var, _val)
switch_frame_t raw_write_frame
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
memset(buf, 0, buflen)

◆ switch_core_session_set_video_read_codec()

switch_status_t switch_core_session_set_video_read_codec ( switch_core_session_t session,
switch_codec_t codec 
)

Definition at line 513 of file switch_core_codec.c.

References switch_codec_implementation::actual_samples_per_second, switch_core_session::channel, switch_codec_implementation::iananame, switch_codec::implementation, memset(), switch_channel_event_set_data(), SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_variable, switch_core_codec_ready(), switch_core_session_get_channel(), switch_event_add_header(), switch_event_add_header_string(), SWITCH_EVENT_CODEC, switch_event_create, switch_event_fire, SWITCH_LOG_ERROR, switch_log_printf(), switch_snprintf(), SWITCH_STACK_BOTTOM, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_core_session::video_read_codec, and switch_core_session::video_read_impl.

514 {
515  switch_event_t *event;
517  char tmp[30];
519 
520  if (!codec || !codec->implementation || !switch_core_codec_ready(codec)) {
521  if (session->video_read_codec) {
522  session->video_read_codec = NULL;
523  status = SWITCH_STATUS_SUCCESS;
524  goto end;
525  }
526  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot set NULL codec!\n");
527  status = SWITCH_STATUS_FALSE;
528  goto end;
529  }
530 
532  switch_channel_event_set_data(session->channel, event);
533  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-video-read-codec-name", codec->implementation->iananame);
534  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-video-read-codec-rate", "%d", codec->implementation->actual_samples_per_second);
535  switch_event_fire(&event);
536  }
537 
538  switch_channel_set_variable(channel, "video_read_codec", codec->implementation->iananame);
539  switch_snprintf(tmp, sizeof(tmp), "%d", codec->implementation->actual_samples_per_second);
540  switch_channel_set_variable(channel, "video_read_rate", tmp);
541 
542  session->video_read_codec = codec;
543  if (codec->implementation) {
544  session->video_read_impl = *codec->implementation;
545  } else {
546  memset(&session->video_read_impl, 0, sizeof(session->video_read_impl));
547  }
548  end:
549 
550  return status;
551 }
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:413
#define SWITCH_CHANNEL_SESSION_LOG(x)
void switch_channel_event_set_data(_In_ switch_channel_t *channel, _In_ switch_event_t *event)
Add information about a given channel to an event object.
switch_codec_t * video_read_codec
switch_status_t switch_event_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *fmt,...) PRINTF_FUNCTION(4
Add a header to an event.
Representation of an event.
Definition: switch_event.h:80
switch_codec_implementation_t video_read_impl
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
const switch_codec_implementation_t * implementation
switch_channel_t * channel
switch_status_t switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
Add a string header to an event.
switch_status_t
Common return values.
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
Definition: switch_event.h:384
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.
#define switch_channel_set_variable(_channel, _var, _val)
memset(buf, 0, buflen)

◆ switch_core_session_set_video_write_codec()

switch_status_t switch_core_session_set_video_write_codec ( switch_core_session_t session,
switch_codec_t codec 
)

Definition at line 562 of file switch_core_codec.c.

References switch_codec_implementation::actual_samples_per_second, switch_core_session::channel, switch_codec_implementation::iananame, switch_codec::implementation, switch_channel_event_set_data(), SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_variable, switch_core_codec_ready(), switch_core_session_get_channel(), switch_event_add_header(), switch_event_add_header_string(), SWITCH_EVENT_CODEC, switch_event_create, switch_event_fire, SWITCH_LOG_ERROR, switch_log_printf(), switch_snprintf(), SWITCH_STACK_BOTTOM, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_core_session::video_write_codec, and switch_core_session::video_write_impl.

563 {
564  switch_event_t *event;
566  char tmp[30];
568  if (!codec || !codec->implementation || !switch_core_codec_ready(codec)) {
569  if (session->video_write_codec) {
570  session->video_write_codec = NULL;
571  status = SWITCH_STATUS_SUCCESS;
572  goto end;
573  }
574  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot set NULL codec!\n");
575  status = SWITCH_STATUS_FALSE;
576  goto end;
577  }
578 
580  switch_channel_event_set_data(session->channel, event);
581  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-video-write-codec-name", codec->implementation->iananame);
582  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-video-write-codec-rate", "%d", codec->implementation->actual_samples_per_second);
583  switch_event_fire(&event);
584  }
585 
586  switch_channel_set_variable(channel, "video_write_codec", codec->implementation->iananame);
587  switch_snprintf(tmp, sizeof(tmp), "%d", codec->implementation->actual_samples_per_second);
588  switch_channel_set_variable(channel, "video_write_rate", tmp);
589 
590  session->video_write_codec = codec;
591  session->video_write_impl = *codec->implementation;
592 
593  end:
594 
595  return status;
596 }
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:413
#define SWITCH_CHANNEL_SESSION_LOG(x)
void switch_channel_event_set_data(_In_ switch_channel_t *channel, _In_ switch_event_t *event)
Add information about a given channel to an event object.
switch_status_t switch_event_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *fmt,...) PRINTF_FUNCTION(4
Add a header to an event.
Representation of an event.
Definition: switch_event.h:80
switch_codec_t * video_write_codec
switch_codec_implementation_t video_write_impl
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
const switch_codec_implementation_t * implementation
switch_channel_t * channel
switch_status_t switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
Add a string header to an event.
switch_status_t
Common return values.
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
Definition: switch_event.h:384
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.
#define switch_channel_set_variable(_channel, _var, _val)

◆ switch_core_session_set_write_codec()

switch_status_t switch_core_session_set_write_codec ( switch_core_session_t session,
switch_codec_t codec 
)

Definition at line 430 of file switch_core_codec.c.

References switch_codec_implementation::actual_samples_per_second, switch_codec_implementation::bits_per_second, switch_core_session::channel, switch_codec_implementation::codec_id, switch_core_session::codec_write_mutex, switch_codec_implementation::iananame, switch_codec::implementation, switch_core_session::real_write_codec, switch_codec_implementation::samples_per_second, switch_channel_event_set_data(), SWITCH_CHANNEL_SESSION_LOG, switch_channel_set_variable, switch_core_codec_ready(), switch_core_session_get_channel(), switch_event_add_header(), switch_event_add_header_string(), SWITCH_EVENT_CODEC, switch_event_create, switch_event_fire, SWITCH_LOG_ERROR, switch_log_printf(), switch_mutex_lock(), switch_mutex_unlock(), switch_snprintf(), SWITCH_STACK_BOTTOM, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_core_session::write_codec, and switch_core_session::write_impl.

431 {
432  switch_event_t *event;
434  char tmp[30];
436 
438 
439  if (!codec || !codec->implementation || !switch_core_codec_ready(codec)) {
440  if (session->real_write_codec) {
441  session->write_codec = session->real_write_codec;
442  session->write_impl = *session->real_write_codec->implementation;
443  session->real_write_codec = NULL;
444  } else {
445  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot set NULL codec!\n");
446  status = SWITCH_STATUS_FALSE;
447  goto end;
448  }
449  } else if (session->write_codec) {
450  if (session->real_write_codec) {
451  if (codec == session->real_write_codec) {
452  session->write_codec = codec;
453  session->write_impl = *codec->implementation;
454  session->real_write_codec = NULL;
455  } else {
456  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot double-set codec!\n");
457  status = SWITCH_STATUS_FALSE;
458  goto end;
459  }
460  } else {
461  session->real_write_codec = session->write_codec;
462  session->write_codec = codec;
463  session->write_impl = *codec->implementation;
464  }
465  } else {
466  session->write_codec = codec;
467  session->write_impl = *codec->implementation;
468  }
469 
470  if (codec && session->write_impl.codec_id) {
472  switch_channel_event_set_data(session->channel, event);
473  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Write-Codec-Name", session->write_impl.iananame);
474  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Write-Codec-Rate", "%d", session->write_impl.actual_samples_per_second);
475  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Write-codec-bit-rate", "%d", session->write_impl.bits_per_second);
477  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Reported-Write-Codec-Rate", "%d",
479  }
480  switch_event_fire(&event);
481  }
482 
483  switch_channel_set_variable(channel, "write_codec", session->write_impl.iananame);
484  switch_snprintf(tmp, sizeof(tmp), "%d", session->write_impl.actual_samples_per_second);
485  switch_channel_set_variable(channel, "write_rate", tmp);
486  }
487 
488  end:
490 
491  return status;
492 }
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:413
#define SWITCH_CHANNEL_SESSION_LOG(x)
switch_mutex_t * codec_write_mutex
void switch_channel_event_set_data(_In_ switch_channel_t *channel, _In_ switch_event_t *event)
Add information about a given channel to an event object.
switch_status_t switch_event_add_header(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *fmt,...) PRINTF_FUNCTION(4
Add a header to an event.
Representation of an event.
Definition: switch_event.h:80
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
_Ret_ switch_channel_t * switch_core_session_get_channel(_In_ switch_core_session_t *session)
Retrieve a pointer to the channel object associated with a given session.
switch_codec_implementation_t write_impl
const switch_codec_implementation_t * implementation
switch_channel_t * channel
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_status_t switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
Add a string header to an event.
switch_codec_t * write_codec
switch_status_t
Common return values.
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
Definition: switch_event.h:384
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_codec_t * real_write_codec
#define switch_channel_set_variable(_channel, _var, _val)

◆ switch_core_session_unlock_codec_read()

void switch_core_session_unlock_codec_read ( switch_core_session_t session)

Definition at line 98 of file switch_core_codec.c.

References switch_core_session::codec_read_mutex, and switch_mutex_unlock().

99 {
101 }
switch_mutex_t * codec_read_mutex
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313

◆ switch_core_session_unlock_codec_write()

void switch_core_session_unlock_codec_write ( switch_core_session_t session)

Definition at line 88 of file switch_core_codec.c.

References switch_core_session::codec_write_mutex, and switch_mutex_unlock().

89 {
91 }
switch_mutex_t * codec_write_mutex
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313

◆ switch_core_session_unset_read_codec()

void switch_core_session_unset_read_codec ( switch_core_session_t session)

Definition at line 46 of file switch_core_codec.c.

References switch_frame::codec, switch_core_session::codec_read_mutex, switch_core_session::enc_read_frame, switch_core_session::enc_write_frame, switch_codec::mutex, mutex, switch_core_session::raw_read_frame, switch_core_session::raw_write_frame, switch_core_session::read_codec, switch_core_session::real_read_codec, switch_mutex_lock(), and switch_mutex_unlock().

47 {
48  switch_mutex_t *mutex = NULL;
49 
51  if (session->read_codec) mutex = session->read_codec->mutex;
52  if (mutex) switch_mutex_lock(mutex);
53  session->real_read_codec = session->read_codec = NULL;
54  session->raw_read_frame.codec = session->read_codec;
55  session->raw_write_frame.codec = session->read_codec;
56  session->enc_read_frame.codec = session->read_codec;
57  session->enc_write_frame.codec = session->read_codec;
58  if (mutex) switch_mutex_unlock(mutex);
60 }
switch_frame_t enc_read_frame
switch_mutex_t * codec_read_mutex
switch_codec_t * read_codec
switch_codec_t * real_read_codec
switch_codec_t * codec
Definition: switch_frame.h:56
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_mutex_t * mutex
struct fspr_thread_mutex_t switch_mutex_t
Definition: switch_apr.h:314
switch_frame_t raw_read_frame
switch_frame_t enc_write_frame
switch_mutex_t * mutex
switch_frame_t raw_write_frame

◆ switch_core_session_unset_write_codec()

void switch_core_session_unset_write_codec ( switch_core_session_t session)

Definition at line 103 of file switch_core_codec.c.

References switch_core_session::codec_write_mutex, switch_codec::mutex, mutex, switch_core_session::real_write_codec, switch_mutex_lock(), switch_mutex_unlock(), and switch_core_session::write_codec.

104 {
105  switch_mutex_t *mutex = NULL;
106 
108  if (session->write_codec) mutex = session->write_codec->mutex;
109  if (mutex) switch_mutex_lock(mutex);
110  session->real_write_codec = session->write_codec = NULL;
111  if (mutex) switch_mutex_unlock(mutex);
113 }
switch_mutex_t * codec_write_mutex
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
switch_codec_t * write_codec
switch_mutex_t * mutex
struct fspr_thread_mutex_t switch_mutex_t
Definition: switch_apr.h:314
switch_mutex_t * mutex
switch_codec_t * real_write_codec

Variable Documentation

◆ CODEC_ID

uint32_t CODEC_ID = 1
static

Definition at line 39 of file switch_core_codec.c.

Referenced by switch_core_codec_next_id().