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_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 311 of file switch_core_codec.c.

References switch_core_session::read_codec.

312 {
313  switch_codec_t *codec;
314  codec = session->read_codec;
315  return codec;
316 }
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 474 of file switch_core_codec.c.

References switch_core_session::write_codec.

475 {
476  switch_codec_t *codec;
477  codec = session->write_codec;
478 
479  return codec;
480 }
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 318 of file switch_core_codec.c.

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

319 {
320  switch_codec_t *codec;
321  codec = session->real_read_codec ? session->real_read_codec : session->read_codec;
322  return codec;
323 }
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 532 of file switch_core_codec.c.

References switch_core_session::video_read_codec.

533 {
534  switch_codec_t *codec;
535  codec = session->video_read_codec;
536 
537  return codec;
538 
539 }
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 577 of file switch_core_codec.c.

References switch_core_session::video_write_codec.

578 {
579  switch_codec_t *codec;
580  codec = session->video_write_codec;
581 
582  return codec;
583 
584 }
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 482 of file switch_core_codec.c.

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

483 {
484  switch_codec_t *codec;
485  codec = session->real_write_codec ? session->real_write_codec : session->write_codec;
486 
487  return codec;
488 }
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 72 of file switch_core_codec.c.

References switch_core_session::codec_read_mutex, and switch_mutex_lock().

73 {
75 }
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 62 of file switch_core_codec.c.

References switch_core_session::codec_write_mutex, and switch_mutex_lock().

63 {
65 }
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 203 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.

204 {
205  switch_event_t *event;
207  char tmp[30];
209 
211 
212  if (codec && (!codec->implementation || !switch_core_codec_ready(codec))) {
213  codec = NULL;
214  }
215 
216  if (codec) {
217  if (!session->real_read_codec) {
218  session->read_codec = session->real_read_codec = codec;
219  if (codec->implementation) {
220  session->read_impl = *codec->implementation;
221  session->real_read_impl = *codec->implementation;
222  } else {
223  memset(&session->read_impl, 0, sizeof(session->read_impl));
224  }
225  } else {
226  if (codec == session->read_codec) {
227  goto end;
228  }
229  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Push codec %s:%d\n",
230  switch_channel_get_name(session->channel), codec->implementation ? codec->implementation->iananame : "undefined", codec->implementation ? codec->implementation->ianacode : -1);
231  codec->next = session->read_codec;
232  session->read_codec = codec;
233  if (codec->implementation) {
234  session->read_impl = *codec->implementation;
235  } else {
236  memset(&session->read_impl, 0, sizeof(session->read_impl));
237  }
238  }
239  } else {
240  if (session->read_codec == session->real_read_codec) {
241  goto end;
242  }
243 
244  if (session->read_codec->next && switch_core_codec_ready(session->read_codec->next)) {
245  switch_codec_t *old = session->read_codec;
246  session->read_codec = session->read_codec->next;
247  if (session->read_codec->implementation) {
248  session->read_impl = *session->read_codec->implementation;
249  } else {
250  memset(&session->read_impl, 0, sizeof(session->read_impl));
251  }
252  old->next = NULL;
253 
254  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Restore previous codec %s:%d.\n",
256  session->read_impl.iananame ? session->read_impl.iananame : "N/A", session->read_impl.ianacode);
257 
258 
259  } else if (session->real_read_codec) {
260  session->read_codec = session->real_read_codec;
261  if (session->real_read_codec->implementation) {
262  session->read_impl = *session->real_read_codec->implementation;
263  } else {
264  memset(&session->read_impl, 0, sizeof(session->read_impl));
265  }
266  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Restore original codec.\n");
267  } else {
268  status = SWITCH_STATUS_FALSE;
269  goto end;
270  }
271  }
272 
273  if (!session->read_codec) {
274  status = SWITCH_STATUS_FALSE;
275  goto end;
276  }
277 
278  if (session->read_impl.decoded_bytes_per_packet) {
280  switch_channel_event_set_data(session->channel, event);
281  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-read-codec-name", session->read_impl.iananame);
282  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-read-codec-rate", "%d", session->read_impl.actual_samples_per_second);
283  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-read-codec-bit-rate", "%d", session->read_impl.bits_per_second);
285  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-reported-read-codec-rate", "%d", session->read_impl.samples_per_second);
286  }
287  switch_event_fire(&event);
288  }
289 
290  switch_channel_set_variable(channel, "read_codec", session->read_impl.iananame);
291  switch_snprintf(tmp, sizeof(tmp), "%d", session->read_impl.actual_samples_per_second);
292  switch_channel_set_variable(channel, "read_rate", tmp);
293 
294  session->raw_read_frame.codec = session->read_codec;
295  session->raw_write_frame.codec = session->read_codec;
296  session->enc_read_frame.codec = session->read_codec;
297  session->enc_write_frame.codec = session->read_codec;
298  }
299 
300  end:
301 
302  if (session->read_codec) {
304  }
305 
307  return status;
308 
309 }
#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 94 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().

95 {
96  switch_event_t *event;
98  char tmp[30];
100  int changed_read_codec = 0;
101 
103 
104  if (codec && (!codec->implementation || !switch_core_codec_ready(codec))) {
105  codec = NULL;
106  }
107 
108  if (codec) {
109  /* set real_read_codec and read_codec */
110  if (!session->real_read_codec) {
111  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Original read codec set to %s:%d\n",
113  session->read_codec = session->real_read_codec = codec;
114  changed_read_codec = 1;
115  if (codec->implementation) {
116  session->read_impl = *codec->implementation;
117  session->real_read_impl = *codec->implementation;
118  } else {
119  memset(&session->read_impl, 0, sizeof(session->read_impl));
120  }
121  } else { /* replace real_read_codec */
122  switch_codec_t *cur_codec;
123 
124  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Original read codec replaced with %s:%d\n",
125  switch_channel_get_name(session->channel), codec->implementation ? codec->implementation->iananame : "undefined", codec->implementation ? codec->implementation->ianacode : -1);
126  /* Set real_read_codec to front of the list of read_codecs */
127  cur_codec = session->read_codec;
128  while (cur_codec != NULL) {
129  if (cur_codec->next == session->real_read_codec) {
130  cur_codec->next = codec;
131  break;
132  }
133 
134  cur_codec = cur_codec->next;
135  }
136 
137  session->real_read_codec = codec;
138  session->real_read_impl = *codec->implementation;
139 
140  /* set read_codec with real_read_codec if it no longer is ready */
141  if (!switch_core_codec_ready(session->read_codec)) {
142  session->read_codec = codec;
143  changed_read_codec = 1;
144  if (codec->implementation) {
145  session->read_impl = *codec->implementation;
146  session->real_read_impl = *codec->implementation;
147  } else {
148  memset(&session->read_impl, 0, sizeof(session->read_impl));
149  }
150  }
151  }
152 
153  /* force media bugs to copy the read codec from the next frame */
155  if (switch_core_codec_ready(&session->bug_codec)) {
156  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Destroying BUG Codec %s:%d\n",
159  }
160 
162  } else {
163  status = SWITCH_STATUS_FALSE;
164  goto end;
165  }
166 
167  if (changed_read_codec && session->read_codec && session->read_impl.decoded_bytes_per_packet) {
169  switch_channel_event_set_data(session->channel, event);
170  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-read-codec-name", session->read_impl.iananame);
171  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-read-codec-rate", "%d", session->read_impl.actual_samples_per_second);
172  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-read-codec-bit-rate", "%d", session->read_impl.bits_per_second);
174  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-reported-read-codec-rate", "%d", session->read_impl.samples_per_second);
175  }
176 
177  switch_event_fire(&event);
178  }
179 
180  switch_channel_set_variable(channel, "read_codec", session->read_impl.iananame);
181  switch_channel_set_variable(channel, "original_read_codec", session->read_impl.iananame);
182  switch_snprintf(tmp, sizeof(tmp), "%d", session->read_impl.actual_samples_per_second);
183  switch_channel_set_variable(channel, "read_rate", tmp);
184  switch_channel_set_variable(channel, "original_read_rate", tmp);
185 
186  session->raw_read_frame.codec = session->read_codec;
187  session->raw_write_frame.codec = session->read_codec;
188  session->enc_read_frame.codec = session->read_codec;
189  session->enc_write_frame.codec = session->read_codec;
190  }
191 
192  end:
193 
194  if (session->read_codec) {
196  }
197 
199 
200  return status;
201 }
#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 492 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.

493 {
494  switch_event_t *event;
496  char tmp[30];
498 
499  if (!codec || !codec->implementation || !switch_core_codec_ready(codec)) {
500  if (session->video_read_codec) {
501  session->video_read_codec = NULL;
502  status = SWITCH_STATUS_SUCCESS;
503  goto end;
504  }
505  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot set NULL codec!\n");
506  status = SWITCH_STATUS_FALSE;
507  goto end;
508  }
509 
511  switch_channel_event_set_data(session->channel, event);
512  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-video-read-codec-name", codec->implementation->iananame);
513  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-video-read-codec-rate", "%d", codec->implementation->actual_samples_per_second);
514  switch_event_fire(&event);
515  }
516 
517  switch_channel_set_variable(channel, "video_read_codec", codec->implementation->iananame);
518  switch_snprintf(tmp, sizeof(tmp), "%d", codec->implementation->actual_samples_per_second);
519  switch_channel_set_variable(channel, "video_read_rate", tmp);
520 
521  session->video_read_codec = codec;
522  if (codec->implementation) {
523  session->video_read_impl = *codec->implementation;
524  } else {
525  memset(&session->video_read_impl, 0, sizeof(session->video_read_impl));
526  }
527  end:
528 
529  return status;
530 }
#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 541 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.

542 {
543  switch_event_t *event;
545  char tmp[30];
547  if (!codec || !codec->implementation || !switch_core_codec_ready(codec)) {
548  if (session->video_write_codec) {
549  session->video_write_codec = NULL;
550  status = SWITCH_STATUS_SUCCESS;
551  goto end;
552  }
553  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot set NULL codec!\n");
554  status = SWITCH_STATUS_FALSE;
555  goto end;
556  }
557 
559  switch_channel_event_set_data(session->channel, event);
560  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-video-write-codec-name", codec->implementation->iananame);
561  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-video-write-codec-rate", "%d", codec->implementation->actual_samples_per_second);
562  switch_event_fire(&event);
563  }
564 
565  switch_channel_set_variable(channel, "video_write_codec", codec->implementation->iananame);
566  switch_snprintf(tmp, sizeof(tmp), "%d", codec->implementation->actual_samples_per_second);
567  switch_channel_set_variable(channel, "video_write_rate", tmp);
568 
569  session->video_write_codec = codec;
570  session->video_write_impl = *codec->implementation;
571 
572  end:
573 
574  return status;
575 }
#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 409 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.

410 {
411  switch_event_t *event;
413  char tmp[30];
415 
417 
418  if (!codec || !codec->implementation || !switch_core_codec_ready(codec)) {
419  if (session->real_write_codec) {
420  session->write_codec = session->real_write_codec;
421  session->write_impl = *session->real_write_codec->implementation;
422  session->real_write_codec = NULL;
423  } else {
424  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot set NULL codec!\n");
425  status = SWITCH_STATUS_FALSE;
426  goto end;
427  }
428  } else if (session->write_codec) {
429  if (session->real_write_codec) {
430  if (codec == session->real_write_codec) {
431  session->write_codec = codec;
432  session->write_impl = *codec->implementation;
433  session->real_write_codec = NULL;
434  } else {
435  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot double-set codec!\n");
436  status = SWITCH_STATUS_FALSE;
437  goto end;
438  }
439  } else {
440  session->real_write_codec = session->write_codec;
441  session->write_codec = codec;
442  session->write_impl = *codec->implementation;
443  }
444  } else {
445  session->write_codec = codec;
446  session->write_impl = *codec->implementation;
447  }
448 
449  if (codec && session->write_impl.codec_id) {
451  switch_channel_event_set_data(session->channel, event);
452  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Write-Codec-Name", session->write_impl.iananame);
453  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Write-Codec-Rate", "%d", session->write_impl.actual_samples_per_second);
454  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Write-codec-bit-rate", "%d", session->write_impl.bits_per_second);
456  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Reported-Write-Codec-Rate", "%d",
458  }
459  switch_event_fire(&event);
460  }
461 
462  switch_channel_set_variable(channel, "write_codec", session->write_impl.iananame);
463  switch_snprintf(tmp, sizeof(tmp), "%d", session->write_impl.actual_samples_per_second);
464  switch_channel_set_variable(channel, "write_rate", tmp);
465  }
466 
467  end:
469 
470  return status;
471 }
#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 77 of file switch_core_codec.c.

References switch_core_session::codec_read_mutex, and switch_mutex_unlock().

78 {
80 }
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 67 of file switch_core_codec.c.

References switch_core_session::codec_write_mutex, and switch_mutex_unlock().

68 {
70 }
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 82 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.

83 {
84  switch_mutex_t *mutex = NULL;
85 
87  if (session->write_codec) mutex = session->write_codec->mutex;
88  if (mutex) switch_mutex_lock(mutex);
89  session->real_write_codec = session->write_codec = NULL;
90  if (mutex) switch_mutex_unlock(mutex);
92 }
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().