FreeSWITCH API Documentation  1.7.0
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_codec_t* switch_core_session_get_effective_read_codec ( switch_core_session_t session)

Definition at line 303 of file switch_core_codec.c.

304 {
305  switch_codec_t *codec;
306  codec = session->read_codec;
307  return codec;
308 }
switch_codec_t * read_codec
switch_codec_t* switch_core_session_get_effective_write_codec ( switch_core_session_t session)

Definition at line 466 of file switch_core_codec.c.

467 {
468  switch_codec_t *codec;
469  codec = session->write_codec;
470 
471  return codec;
472 }
switch_codec_t * write_codec
switch_codec_t* switch_core_session_get_read_codec ( switch_core_session_t session)

Definition at line 310 of file switch_core_codec.c.

311 {
312  switch_codec_t *codec;
313  codec = session->real_read_codec ? session->real_read_codec : session->read_codec;
314  return codec;
315 }
switch_codec_t * read_codec
switch_codec_t * real_read_codec
switch_codec_t* switch_core_session_get_video_read_codec ( switch_core_session_t session)

Definition at line 524 of file switch_core_codec.c.

525 {
526  switch_codec_t *codec;
527  codec = session->video_read_codec;
528 
529  return codec;
530 
531 }
switch_codec_t * video_read_codec
switch_codec_t* switch_core_session_get_video_write_codec ( switch_core_session_t session)

Definition at line 569 of file switch_core_codec.c.

570 {
571  switch_codec_t *codec;
572  codec = session->video_write_codec;
573 
574  return codec;
575 
576 }
switch_codec_t * video_write_codec
switch_codec_t* switch_core_session_get_write_codec ( switch_core_session_t session)

Definition at line 474 of file switch_core_codec.c.

475 {
476  switch_codec_t *codec;
477  codec = session->real_write_codec ? session->real_write_codec : session->write_codec;
478 
479  return codec;
480 }
switch_codec_t * write_codec
switch_codec_t * real_write_codec
void switch_core_session_lock_codec_read ( switch_core_session_t session)

Definition at line 72 of file switch_core_codec.c.

References 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:285
void switch_core_session_lock_codec_write ( switch_core_session_t session)

Definition at line 62 of file switch_core_codec.c.

References 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:285
switch_status_t switch_core_session_set_read_codec ( switch_core_session_t session,
switch_codec_t codec 
)

Definition at line 195 of file switch_core_codec.c.

References CF_MEDIA_SET, switch_codec::implementation, memset(), switch_codec::next, 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.

196 {
197  switch_event_t *event;
199  char tmp[30];
201 
203 
204  if (codec && (!codec->implementation || !switch_core_codec_ready(codec))) {
205  codec = NULL;
206  }
207 
208  if (codec) {
209  if (!session->real_read_codec) {
210  session->read_codec = session->real_read_codec = codec;
211  if (codec->implementation) {
212  session->read_impl = *codec->implementation;
213  session->real_read_impl = *codec->implementation;
214  } else {
215  memset(&session->read_impl, 0, sizeof(session->read_impl));
216  }
217  } else {
218  if (codec == session->read_codec) {
219  goto end;
220  }
221  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Push codec %s:%d\n",
223  codec->next = session->read_codec;
224  session->read_codec = codec;
225  if (codec->implementation) {
226  session->read_impl = *codec->implementation;
227  } else {
228  memset(&session->read_impl, 0, sizeof(session->read_impl));
229  }
230  }
231  } else {
232  if (session->read_codec == session->real_read_codec) {
233  goto end;
234  }
235 
236  if (session->read_codec->next) {
237  switch_codec_t *old = session->read_codec;
238  session->read_codec = session->read_codec->next;
239  if (session->read_codec->implementation) {
240  session->read_impl = *session->read_codec->implementation;
241  } else {
242  memset(&session->read_impl, 0, sizeof(session->read_impl));
243  }
244  old->next = NULL;
245 
246  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Restore previous codec %s:%d.\n",
248  session->read_impl.iananame ? session->read_impl.iananame : "N/A", session->read_impl.ianacode);
249 
250 
251  } else if (session->real_read_codec) {
252  session->read_codec = session->real_read_codec;
253  if (session->real_read_codec->implementation) {
254  session->read_impl = *session->real_read_codec->implementation;
255  } else {
256  memset(&session->read_impl, 0, sizeof(session->read_impl));
257  }
258  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Restore original codec.\n");
259  } else {
260  status = SWITCH_STATUS_FALSE;
261  goto end;
262  }
263  }
264 
265  if (!session->read_codec) {
266  status = SWITCH_STATUS_FALSE;
267  goto end;
268  }
269 
270  if (session->read_codec && session->read_impl.decoded_bytes_per_packet) {
272  switch_channel_event_set_data(session->channel, event);
273  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-read-codec-name", session->read_impl.iananame);
274  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-read-codec-rate", "%d", session->read_impl.actual_samples_per_second);
275  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-read-codec-bit-rate", "%d", session->read_impl.bits_per_second);
277  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-reported-read-codec-rate", "%d", session->read_impl.samples_per_second);
278  }
279  switch_event_fire(&event);
280  }
281 
282  switch_channel_set_variable(channel, "read_codec", session->read_impl.iananame);
283  switch_snprintf(tmp, sizeof(tmp), "%d", session->read_impl.actual_samples_per_second);
284  switch_channel_set_variable(channel, "read_rate", tmp);
285 
286  session->raw_read_frame.codec = session->read_codec;
287  session->raw_write_frame.codec = session->read_codec;
288  session->enc_read_frame.codec = session->read_codec;
289  session->enc_write_frame.codec = session->read_codec;
290  }
291 
292  end:
293 
294  if (session->read_codec) {
296  }
297 
299  return status;
300 
301 }
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:412
#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:45
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
_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:285
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:383
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_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 CF_MEDIA_SET, switch_codec::implementation, memset(), switch_codec::next, 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  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "%s Original read codec replaced with %s:%d\n",
125  /* Set real_read_codec to front of the list of read_codecs */
126  cur_codec = session->read_codec;
127  while (cur_codec != NULL) {
128  if (cur_codec->next == session->real_read_codec) {
129  cur_codec->next = codec;
130  break;
131  }
132  cur_codec = cur_codec->next;
133  }
134  session->real_read_codec = codec;
135  /* set read_codec with real_read_codec if it no longer is ready */
136  if (!switch_core_codec_ready(session->read_codec)) {
137  session->read_codec = codec;
138  changed_read_codec = 1;
139  if (codec->implementation) {
140  session->read_impl = *codec->implementation;
141  session->real_read_impl = *codec->implementation;
142  } else {
143  memset(&session->read_impl, 0, sizeof(session->read_impl));
144  }
145  }
146  }
147 
148  /* force media bugs to copy the read codec from the next frame */
150  if (switch_core_codec_ready(&session->bug_codec)) {
151  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG, "Destroying BUG Codec %s:%d\n",
154  }
156  } else {
157  status = SWITCH_STATUS_FALSE;
158  goto end;
159  }
160 
161  if (changed_read_codec && session->read_codec && session->read_impl.decoded_bytes_per_packet) {
163  switch_channel_event_set_data(session->channel, event);
164  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-read-codec-name", session->read_impl.iananame);
165  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-read-codec-rate", "%d", session->read_impl.actual_samples_per_second);
166  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-read-codec-bit-rate", "%d", session->read_impl.bits_per_second);
168  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-reported-read-codec-rate", "%d", session->read_impl.samples_per_second);
169  }
170  switch_event_fire(&event);
171  }
172 
173  switch_channel_set_variable(channel, "read_codec", session->read_impl.iananame);
174  switch_channel_set_variable(channel, "original_read_codec", session->read_impl.iananame);
175  switch_snprintf(tmp, sizeof(tmp), "%d", session->read_impl.actual_samples_per_second);
176  switch_channel_set_variable(channel, "read_rate", tmp);
177  switch_channel_set_variable(channel, "original_read_rate", tmp);
178 
179  session->raw_read_frame.codec = session->read_codec;
180  session->raw_write_frame.codec = session->read_codec;
181  session->enc_read_frame.codec = session->read_codec;
182  session->enc_write_frame.codec = session->read_codec;
183  }
184 
185  end:
186 
187  if (session->read_codec) {
189  }
190 
192  return status;
193 }
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:412
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
Definition: switch_apr.c:263
#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:45
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
_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:237
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:285
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:383
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_status_t switch_core_session_set_video_read_codec ( switch_core_session_t session,
switch_codec_t codec 
)

Definition at line 484 of file switch_core_codec.c.

References 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, and SWITCH_STATUS_SUCCESS.

485 {
486  switch_event_t *event;
488  char tmp[30];
490 
491  if (!codec || !codec->implementation || !switch_core_codec_ready(codec)) {
492  if (session->video_read_codec) {
493  session->video_read_codec = NULL;
494  status = SWITCH_STATUS_SUCCESS;
495  goto end;
496  }
497  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot set NULL codec!\n");
498  status = SWITCH_STATUS_FALSE;
499  goto end;
500  }
501 
503  switch_channel_event_set_data(session->channel, event);
504  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-video-read-codec-name", codec->implementation->iananame);
505  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-video-read-codec-rate", "%d", codec->implementation->actual_samples_per_second);
506  switch_event_fire(&event);
507  }
508 
509  switch_channel_set_variable(channel, "video_read_codec", codec->implementation->iananame);
510  switch_snprintf(tmp, sizeof(tmp), "%d", codec->implementation->actual_samples_per_second);
511  switch_channel_set_variable(channel, "video_read_rate", tmp);
512 
513  session->video_read_codec = codec;
514  if (codec->implementation) {
515  session->video_read_impl = *codec->implementation;
516  } else {
517  memset(&session->video_read_impl, 0, sizeof(session->video_read_impl));
518  }
519  end:
520 
521  return status;
522 }
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:412
#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:383
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_status_t switch_core_session_set_video_write_codec ( switch_core_session_t session,
switch_codec_t codec 
)

Definition at line 533 of file switch_core_codec.c.

References 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, and SWITCH_STATUS_SUCCESS.

534 {
535  switch_event_t *event;
537  char tmp[30];
539  if (!codec || !codec->implementation || !switch_core_codec_ready(codec)) {
540  if (session->video_write_codec) {
541  session->video_write_codec = NULL;
542  status = SWITCH_STATUS_SUCCESS;
543  goto end;
544  }
545  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot set NULL codec!\n");
546  status = SWITCH_STATUS_FALSE;
547  goto end;
548  }
549 
551  switch_channel_event_set_data(session->channel, event);
552  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-video-write-codec-name", codec->implementation->iananame);
553  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "channel-video-write-codec-rate", "%d", codec->implementation->actual_samples_per_second);
554  switch_event_fire(&event);
555  }
556 
557  switch_channel_set_variable(channel, "video_write_codec", codec->implementation->iananame);
558  switch_snprintf(tmp, sizeof(tmp), "%d", codec->implementation->actual_samples_per_second);
559  switch_channel_set_variable(channel, "video_write_rate", tmp);
560 
561  session->video_write_codec = codec;
562  session->video_write_impl = *codec->implementation;
563 
564  end:
565 
566  return status;
567 }
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:412
#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:383
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_status_t switch_core_session_set_write_codec ( switch_core_session_t session,
switch_codec_t codec 
)

Definition at line 401 of file switch_core_codec.c.

References 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, and SWITCH_STATUS_SUCCESS.

402 {
403  switch_event_t *event;
405  char tmp[30];
407 
409 
410  if (!codec || !codec->implementation || !switch_core_codec_ready(codec)) {
411  if (session->real_write_codec) {
412  session->write_codec = session->real_write_codec;
413  session->write_impl = *session->real_write_codec->implementation;
414  session->real_write_codec = NULL;
415  } else {
416  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot set NULL codec!\n");
417  status = SWITCH_STATUS_FALSE;
418  goto end;
419  }
420  } else if (session->write_codec) {
421  if (session->real_write_codec) {
422  if (codec == session->real_write_codec) {
423  session->write_codec = codec;
424  session->write_impl = *codec->implementation;
425  session->real_write_codec = NULL;
426  } else {
427  switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Cannot double-set codec!\n");
428  status = SWITCH_STATUS_FALSE;
429  goto end;
430  }
431  } else {
432  session->real_write_codec = session->write_codec;
433  session->write_codec = codec;
434  session->write_impl = *codec->implementation;
435  }
436  } else {
437  session->write_codec = codec;
438  session->write_impl = *codec->implementation;
439  }
440 
441  if (session->write_codec && codec && session->write_impl.codec_id) {
443  switch_channel_event_set_data(session->channel, event);
444  switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "Channel-Write-Codec-Name", session->write_impl.iananame);
445  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Write-Codec-Rate", "%d", session->write_impl.actual_samples_per_second);
446  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Write-codec-bit-rate", "%d", session->write_impl.bits_per_second);
448  switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Channel-Reported-Write-Codec-Rate", "%d",
450  }
451  switch_event_fire(&event);
452  }
453 
454  switch_channel_set_variable(channel, "write_codec", session->write_impl.iananame);
455  switch_snprintf(tmp, sizeof(tmp), "%d", session->write_impl.actual_samples_per_second);
456  switch_channel_set_variable(channel, "write_rate", tmp);
457  }
458 
459  end:
461 
462  return status;
463 }
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
Definition: switch_event.h:412
#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:290
_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:285
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:383
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)
void switch_core_session_unlock_codec_read ( switch_core_session_t session)

Definition at line 77 of file switch_core_codec.c.

References 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:290
void switch_core_session_unlock_codec_write ( switch_core_session_t session)

Definition at line 67 of file switch_core_codec.c.

References 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:290
void switch_core_session_unset_read_codec ( switch_core_session_t session)

Definition at line 46 of file switch_core_codec.c.

References mutex, 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:45
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_mutex_t * mutex
switch_frame_t raw_read_frame
struct apr_thread_mutex_t switch_mutex_t
Definition: switch_apr.h:314
switch_frame_t enc_write_frame
switch_mutex_t * mutex
switch_frame_t raw_write_frame
void switch_core_session_unset_write_codec ( switch_core_session_t session)

Definition at line 82 of file switch_core_codec.c.

References mutex, switch_mutex_lock(), and switch_mutex_unlock().

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:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
switch_codec_t * write_codec
switch_mutex_t * mutex
struct apr_thread_mutex_t switch_mutex_t
Definition: switch_apr.h:314
switch_mutex_t * mutex
switch_codec_t * real_write_codec

Variable Documentation

uint32_t CODEC_ID = 1
static

Definition at line 39 of file switch_core_codec.c.

Referenced by switch_core_codec_next_id().