51 if (session->read_codec) mutex = session->read_codec->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;
87 if (session->write_codec) mutex = session->write_codec->mutex;
89 session->real_write_codec = session->write_codec = NULL;
100 int changed_read_codec = 0;
110 if (!session->real_read_codec) {
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;
119 memset(&session->read_impl, 0,
sizeof(session->read_impl));
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;
132 cur_codec = cur_codec->
next;
134 session->real_read_codec = codec;
137 session->read_codec = codec;
138 changed_read_codec = 1;
139 if (codec->implementation) {
141 session->real_read_impl = *codec->implementation;
143 memset(&session->read_impl, 0,
sizeof(session->read_impl));
152 session->bug_codec.implementation->iananame, session->bug_codec.implementation->ianacode);
161 if (changed_read_codec && session->read_codec && session->read_impl.decoded_bytes_per_packet) {
167 if (session->read_impl.actual_samples_per_second != session->read_impl.samples_per_second) {
175 switch_snprintf(tmp,
sizeof(tmp),
"%d", session->read_impl.actual_samples_per_second);
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;
187 if (session->read_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;
215 memset(&session->read_impl, 0,
sizeof(session->read_impl));
218 if (codec == session->read_codec) {
223 codec->next = session->read_codec;
224 session->read_codec = codec;
225 if (codec->implementation) {
226 session->read_impl = *codec->implementation;
228 memset(&session->read_impl, 0,
sizeof(session->read_impl));
232 if (session->read_codec == session->real_read_codec) {
236 if (session->read_codec->next) {
238 session->read_codec = session->read_codec->
next;
239 if (session->read_codec->implementation) {
242 memset(&session->read_impl, 0,
sizeof(session->read_impl));
248 session->read_impl.iananame ? session->read_impl.iananame :
"N/A", session->read_impl.ianacode);
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;
256 memset(&session->read_impl, 0,
sizeof(session->read_impl));
265 if (!session->read_codec) {
270 if (session->read_codec && session->read_impl.decoded_bytes_per_packet) {
276 if (session->read_impl.actual_samples_per_second != session->read_impl.samples_per_second) {
283 switch_snprintf(tmp,
sizeof(tmp),
"%d", session->read_impl.actual_samples_per_second);
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;
294 if (session->read_codec) {
306 codec = session->read_codec;
313 codec = session->real_read_codec ? session->real_read_codec : session->read_codec;
319 if (session->read_impl.codec_id) {
320 *impp = session->read_impl;
324 memset(impp, 0,
sizeof(*impp));
325 impp->number_of_channels = 1;
331 if (session->real_read_impl.codec_id) {
332 *impp = session->real_read_impl;
341 if (session->write_impl.codec_id) {
342 *impp = session->write_impl;
346 memset(impp, 0,
sizeof(*impp));
347 impp->number_of_channels = 1;
353 if (session->video_read_impl.codec_id) {
354 *impp = session->video_read_impl;
358 memset(impp, 0,
sizeof(*impp));
359 impp->number_of_channels = 1;
365 if (session->video_write_impl.codec_id) {
366 *impp = session->video_write_impl;
370 memset(impp, 0,
sizeof(*impp));
371 impp->number_of_channels = 1;
378 session->read_impl = *impp;
384 session->write_impl = *impp;
390 session->video_read_impl = *impp;
396 session->video_write_impl = *impp;
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;
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;
432 session->real_write_codec = session->write_codec;
433 session->write_codec = codec;
434 session->write_impl = *codec->implementation;
437 session->write_codec = codec;
438 session->write_impl = *codec->implementation;
441 if (session->write_codec && codec && session->write_impl.codec_id) {
447 if (session->write_impl.actual_samples_per_second != session->write_impl.samples_per_second) {
449 session->write_impl.actual_samples_per_second);
455 switch_snprintf(tmp,
sizeof(tmp),
"%d", session->write_impl.actual_samples_per_second);
469 codec = session->write_codec;
477 codec = session->real_write_codec ? session->real_write_codec : session->write_codec;
492 if (session->video_read_codec) {
493 session->video_read_codec = NULL;
510 switch_snprintf(tmp,
sizeof(tmp),
"%d", codec->implementation->actual_samples_per_second);
513 session->video_read_codec = codec;
514 if (codec->implementation) {
515 session->video_read_impl = *codec->implementation;
517 memset(&session->video_read_impl, 0,
sizeof(session->video_read_impl));
527 codec = session->video_read_codec;
540 if (session->video_write_codec) {
541 session->video_write_codec = NULL;
558 switch_snprintf(tmp,
sizeof(tmp),
"%d", codec->implementation->actual_samples_per_second);
561 session->video_write_codec = codec;
562 session->video_write_impl = *codec->implementation;
572 codec = session->video_write_codec;
583 if (
zstr(codec_name) ||
zstr(fmtp) || !codec_fmtp) {
587 memset(codec_fmtp, 0,
sizeof(*codec_fmtp));
591 codec_fmtp->actual_samples_per_second = rate;
592 status = codec_interface->
parse_fmtp(fmtp, codec_fmtp);
605 codec->implementation->destroy(codec);
606 codec->implementation->init(codec, codec->flags, NULL);
619 codec->implementation->iananame,
620 codec->implementation->modname,
622 codec->implementation->samples_per_second,
623 codec->implementation->microseconds_per_packet / 1000,
624 codec->implementation->number_of_channels,
632 uint32_t rate,
int ms,
int channels, uint32_t bitrate, uint32_t
flags,
641 memset(codec, 0,
sizeof(*codec));
647 if (strchr(codec_name,
'.')) {
650 if ((p = strchr(codec_name,
'.'))) {
652 modname = codec_name;
662 if (!strncasecmp(codec_name,
"PROXY", 5)) {
665 implementation = iptr;
677 if ((!rate || rate == crate) && (!bitrate || bitrate == (uint32_t)iptr->
bits_per_second) &&
679 implementation = iptr;
688 if ((!rate || rate == crate) && (!bitrate || bitrate == (uint32_t)iptr->
bits_per_second) &&
690 implementation = iptr;
697 if (implementation) {
699 codec->codec_interface = codec_interface;
700 codec->implementation = implementation;
701 codec->flags =
flags;
704 codec->memory_pool =
pool;
716 implementation->
init(codec, flags, codec_settings);
722 codec_name, rate, ms, channels);
734 uint32_t decoded_data_len,
735 uint32_t decoded_rate,
736 void *encoded_data, uint32_t *encoded_data_len, uint32_t *encoded_rate,
unsigned int *flag)
755 status = codec->implementation->encode(codec, other_codec, decoded_data, decoded_data_len,
756 decoded_rate, encoded_data, encoded_data_len, encoded_rate, flag);
766 uint32_t encoded_data_len,
767 uint32_t encoded_rate,
768 void *decoded_data, uint32_t *decoded_data_len, uint32_t *decoded_rate,
unsigned int *flag)
786 if (codec->implementation->encoded_bytes_per_packet) {
787 uint32_t frames = encoded_data_len / codec->implementation->encoded_bytes_per_packet / codec->implementation->number_of_channels;
789 if (frames && codec->implementation->decoded_bytes_per_packet * frames > *decoded_data_len) {
791 encoded_data_len, codec->implementation->encoded_bytes_per_packet, frames, *decoded_data_len);
792 *decoded_data_len = codec->implementation->decoded_bytes_per_packet;
793 memset(decoded_data, 255, *decoded_data_len);
799 status = codec->implementation->decode(codec, other_codec, encoded_data, encoded_data_len, encoded_rate,
800 decoded_data, decoded_data_len, decoded_rate, flag);
824 if (codec->implementation->encode_video) {
825 status = codec->implementation->encode_video(codec, frame);
833 frame->packetlen = frame->datalen + 12;
861 if (codec->implementation->decode_video) {
862 status = codec->implementation->decode_video(codec, frame);
895 if (codec->implementation->codec_control) {
896 status = codec->implementation->codec_control(codec, cmd, ctype, cmd_data, atype, cmd_arg, rtype, ret_data);
927 codec->implementation->destroy(codec);
937 memset(codec, 0,
sizeof(*codec));
switch_status_t switch_core_codec_decode_video(switch_codec_t *codec, switch_frame_t *frame)
Decode video data using a codec handle.
#define switch_event_fire(event)
Fire an event filling in most of the arguements with obvious values.
#define switch_core_new_memory_pool(p)
Create a new sub memory pool from the core's master pool.
switch_status_t switch_thread_rwlock_unlock(switch_thread_rwlock_t *rwlock)
switch_status_t switch_core_session_set_video_write_codec(switch_core_session_t *session, switch_codec_t *codec)
#define SWITCH_CHANNEL_SESSION_LOG(x)
switch_status_t switch_core_codec_parse_fmtp(const char *codec_name, const char *fmtp, uint32_t rate, switch_codec_fmtp_t *codec_fmtp)
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
#define SWITCH_CHANNEL_LOG
void switch_core_session_unset_write_codec(switch_core_session_t *session)
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.
#define switch_core_strdup(_pool, _todup)
Copy a string using memory allocation from a given 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.
switch_status_t switch_core_session_set_read_impl(switch_core_session_t *session, const switch_codec_implementation_t *impp)
#define switch_core_destroy_memory_pool(p)
Returns a subpool back to the main pool.
switch_memory_pool_t * pool
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.
switch_codec_implementation_t * implementations
void * switch_core_memory_pool_get_data(switch_memory_pool_t *pool, const char *key)
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_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.
switch_status_t switch_core_codec_destroy(switch_codec_t *codec)
Destroy an initalized codec handle.
switch_status_t switch_core_session_set_read_codec(switch_core_session_t *session, switch_codec_t *codec)
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_core_session_set_write_codec(switch_core_session_t *session, switch_codec_t *codec)
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_codec_reset(switch_codec_t *codec)
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
switch_codec_t * switch_core_session_get_effective_write_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)
_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_control_command_t
#define UNPROTECT_INTERFACE(_it)
#define switch_clear_flag(obj, flag)
Clear a flag on an arbitrary object while locked.
#define SWITCH_MUTEX_NESTED
switch_status_t switch_thread_rwlock_wrlock(switch_thread_rwlock_t *rwlock)
switch_codec_control_type_t
const switch_codec_implementation_t * implementation
void switch_core_session_lock_codec_write(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_status_t switch_mutex_lock(switch_mutex_t *lock)
switch_status_t switch_core_session_set_video_read_impl(switch_core_session_t *session, const switch_codec_implementation_t *impp)
uint32_t actual_samples_per_second
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_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.
Top level module interface to implement a series of codec implementations.
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_mutex_init(switch_mutex_t **lock, unsigned int flags, switch_memory_pool_t *pool)
An abstraction of a data frame.
struct switch_codec * next
#define switch_core_codec_init(_codec, _codec_name, _modname, _fmtp, _rate, _ms, _channels, _flags, _codec_settings, _pool)
Initialize a codec handle.
uint32_t switch_core_codec_next_id(void)
switch_status_t switch_core_session_get_write_impl(switch_core_session_t *session, switch_codec_implementation_t *impp)
int microseconds_per_packet
switch_codec_t * switch_core_session_get_effective_read_codec(switch_core_session_t *session)
switch_codec_interface_t * switch_loadable_module_get_codec_interface(const char *name, const char *modname)
Retrieve the codec interface by it's registered name.
switch_status_t switch_core_codec_encode_video(switch_codec_t *codec, switch_frame_t *frame)
Encode video data using a codec handle.
void switch_core_session_lock_codec_read(switch_core_session_t *session)
switch_codec_t * switch_core_session_get_video_read_codec(switch_core_session_t *session)
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)
uint8_t number_of_channels
struct apr_thread_mutex_t switch_mutex_t
uint32_t samples_per_second
switch_status_t
Common return values.
switch_core_codec_fmtp_parse_func_t parse_fmtp
#define switch_event_create(event, id)
Create a new event assuming it will not be custom event and therefore hiding the unused parameters...
#define switch_channel_set_flag(_c, _f)
switch_core_codec_init_func_t init
void switch_core_session_unlock_codec_read(switch_core_session_t *session)
struct switch_codec_implementation * next
struct apr_pool_t switch_memory_pool_t
#define switch_test_flag(obj, flag)
Test for the existance of a flag on an arbitary object.
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.
A table of settings and callbacks that define a paticular implementation of a codec.
switch_status_t switch_core_session_set_real_read_codec(switch_core_session_t *session, switch_codec_t *codec)
switch_codec_t * switch_core_session_get_read_codec(switch_core_session_t *session)
switch_status_t switch_core_session_get_video_read_impl(switch_core_session_t *session, switch_codec_implementation_t *impp)
#define switch_channel_set_variable(_channel, _var, _val)
char * switch_channel_get_name(switch_channel_t *channel)
Retrieve the name of a given channel.
void switch_core_session_unset_read_codec(switch_core_session_t *session)
switch_status_t switch_core_session_set_write_impl(switch_core_session_t *session, const switch_codec_implementation_t *impp)
void switch_core_session_unlock_codec_write(switch_core_session_t *session)
switch_codec_t * switch_core_session_get_video_write_codec(switch_core_session_t *session)
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
switch_codec_t * switch_core_session_get_write_codec(switch_core_session_t *session)