switch_bool_t m;
/*! frame flags */
switch_frame_flag_t flags;
- switch_core_session_t *session;
};
SWITCH_END_EXTERN_C
impl->destroy = destroy;
impl->codec_id = codec_interface->codec_id;
impl->next = codec_interface->implementations;
+ impl->impl_id = switch_core_codec_next_id();
codec_interface->implementations = impl;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Rejected codec name: %s rate: %u ptime: %u\n",
}
+static inline switch_bool_t switch_core_codec_ready(switch_codec_t *codec)
+{
+ return (codec->flags & SWITCH_CODEC_FLAG_READY) ? SWITCH_TRUE : SWITCH_FALSE;
+}
+
/*! deinitalize a codec handle using this implementation */
switch_core_codec_destroy_func_t destroy;
uint32_t codec_id;
+ uint32_t impl_id;
struct switch_codec_implementation *next;
};
SWITCH_CODEC_FLAG_SILENCE = (1 << 4),
SWITCH_CODEC_FLAG_FREE_POOL = (1 << 5),
SWITCH_CODEC_FLAG_AAL2 = (1 << 6),
- SWITCH_CODEC_FLAG_PASSTHROUGH = (1 << 7)
+ SWITCH_CODEC_FLAG_PASSTHROUGH = (1 << 7),
+ SWITCH_CODEC_FLAG_READY = (1 << 8)
} switch_codec_flag_enum_t;
typedef uint32_t switch_codec_flag_t;
switch_core_session_reset(member->session, SWITCH_TRUE, SWITCH_FALSE);
- if (member->read_codec.implementation) {
+ if (switch_core_codec_ready(&member->read_codec)) {
switch_core_codec_destroy(&member->read_codec);
}
fail:
switch_core_session_set_read_codec(session, NULL);
- if (codec.implementation) {
+ if (switch_core_codec_ready(&codec)) {
switch_core_codec_destroy(&codec);
}
switch_core_session_set_read_codec(session, NULL);
- if (read_codec.implementation) {
+ if (switch_core_codec_ready(&read_codec)) {
switch_core_codec_destroy(&read_codec);
}
- if (write_codec.implementation) {
+ if (switch_core_codec_ready(&write_codec)) {
switch_core_codec_destroy(&write_codec);
}
switch_core_session_set_read_codec(session, read_codec);
}
- if (codec.implementation) {
+ if (switch_core_codec_ready(&codec)) {
switch_core_codec_destroy(&codec);
}
- if (vid_codec.implementation) {
+ if (switch_core_codec_ready(&vid_codec)) {
switch_core_codec_destroy(&vid_codec);
}
{
deactivate_audio_device();
- if (globals.read_codec.implementation) {
+ if (switch_core_codec_ready(&globals.read_codec)) {
switch_core_codec_destroy(&globals.read_codec);
}
- if (globals.write_codec.implementation) {
+ if (switch_core_codec_ready(&globals.write_codec)) {
switch_core_codec_destroy(&globals.write_codec);
}
switch_core_hash_destroy(&globals.call_hash);
tech_pvt->rtp_session = NULL;
}
- if (tech_pvt->read_codec.implementation) {
+ if (switch_core_codec_ready(&tech_pvt->read_codec)) {
switch_core_codec_destroy(&tech_pvt->read_codec);
}
- if (tech_pvt->write_codec.implementation) {
+ if (switch_core_codec_ready(&tech_pvt->write_codec)) {
switch_core_codec_destroy(&tech_pvt->write_codec);
}
}
}
- if (!tech_pvt->read_codec.implementation) {
+ if (!switch_core_codec_ready(&tech_pvt->read_codec) || !tech_pvt->read_codec.implementation) {
return SWITCH_STATUS_GENERR;
}
switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
switch_clear_flag_locked(tech_pvt, TFLAG_CODEC);
- if (tech_pvt->read_codec.implementation) {
+ if (switch_core_codec_ready(&tech_pvt->read_codec)) {
switch_core_codec_destroy(&tech_pvt->read_codec);
}
- if (tech_pvt->write_codec.implementation) {
+ if (!switch_core_codec_ready(&tech_pvt->write_codec)) {
switch_core_codec_destroy(&tech_pvt->write_codec);
}
if (channel && switch_channel_up(channel)) {
int bytes = 0, frames = 1;
- if (!switch_test_flag(tech_pvt, TFLAG_CODEC) || !tech_pvt->read_codec.implementation) {
+ if (!switch_test_flag(tech_pvt, TFLAG_CODEC) || !tech_pvt->read_codec.implementation ||
+ !switch_core_codec_ready(&tech_pvt->read_codec)) {
switch_channel_hangup(channel, SWITCH_CAUSE_NORMAL_CLEARING);
break;
}
interval = codec->implementation->microseconds_per_packet / 1000;
}
- if (tech_pvt->read_codec.implementation) {
+ if (switch_core_codec_ready(&tech_pvt->read_codec)) {
switch_core_codec_destroy(&tech_pvt->read_codec);
}
- if (tech_pvt->write_codec.implementation) {
+ if (switch_core_codec_ready(&tech_pvt->write_codec)) {
switch_core_codec_destroy(&tech_pvt->write_codec);
}
NULL,
switch_core_session_get_pool(session));
- if (status != SWITCH_STATUS_SUCCESS || !tech_pvt->read_codec.implementation) {
+ if (status != SWITCH_STATUS_SUCCESS || !tech_pvt->read_codec.implementation || !switch_core_codec_ready(&tech_pvt->read_codec)) {
goto end;
}
switch_core_timer_destroy(&tech_pvt->timer);
- if (tech_pvt->read_codec.implementation) {
+ if (switch_core_codec_ready(&tech_pvt->read_codec)) {
switch_core_codec_destroy(&tech_pvt->read_codec);
}
- if (tech_pvt->write_codec.implementation) {
+ if (switch_core_codec_ready(&tech_pvt->write_codec)) {
switch_core_codec_destroy(&tech_pvt->write_codec);
}
static void destroy_codecs(void)
{
- if (globals.read_codec.implementation) {
+ if (switch_core_codec_ready(&globals.read_codec)) {
switch_core_codec_destroy(&globals.read_codec);
}
- if (globals.write_codec.implementation) {
+ if (switch_core_codec_ready(&globals.write_codec)) {
switch_core_codec_destroy(&globals.write_codec);
}
return SWITCH_STATUS_SUCCESS;
}
- if (!globals.read_codec.implementation) {
+ if (!switch_core_codec_ready(&globals.read_codec))) {
if (switch_core_codec_init(&globals.read_codec,
"L16",
NULL, sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
switch_assert(globals.read_codec.implementation);
- if (!globals.write_codec.implementation) {
+ if (!switch_core_codec_ready(&globals.write_codec)) {
if (switch_core_codec_init(&globals.write_codec,
"L16",
NULL,
switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
//switch_thread_cond_signal(tech_pvt->cond);
- if (tech_pvt->read_codec.implementation) {
+ if (switch_core_codec_ready(&tech_pvt->read_codec)) {
switch_core_codec_destroy(&tech_pvt->read_codec);
}
- if (tech_pvt->write_codec.implementation) {
+ if (switch_core_codec_ready(&tech_pvt->write_codec)) {
switch_core_codec_destroy(&tech_pvt->write_codec);
}
skypiax_signaling_write(tech_pvt, msg_to_skype);
}
- if (tech_pvt->read_codec.implementation) {
- switch_core_codec_destroy(&tech_pvt->read_codec);
+ if (switch_core_codec_ready(&tech_pvt->read_codec)) {
+ switch_core_codec_destroy(&tech_pvt->read_codec);
}
- if (tech_pvt->write_codec.implementation) {
- switch_core_codec_destroy(&tech_pvt->write_codec);
+ if (switch_core_codec_ready(&tech_pvt->write_codec)) {
+ switch_core_codec_destroy(&tech_pvt->write_codec);
}
memset(tech_pvt->session_uuid_str, '\0', sizeof(tech_pvt->session_uuid_str));
sofia_clear_flag(tech_pvt, TFLAG_IO);
- if (tech_pvt->read_codec.implementation) {
+ if (switch_core_codec_ready(&tech_pvt->read_codec)) {
switch_core_codec_destroy(&tech_pvt->read_codec);
}
- if (tech_pvt->write_codec.implementation) {
+ if (switch_core_codec_ready(&tech_pvt->write_codec)) {
switch_core_codec_destroy(&tech_pvt->write_codec);
}
tech_pvt->read_frame.datalen = 0;
sofia_set_flag_locked(tech_pvt, TFLAG_READING);
- if (sofia_test_flag(tech_pvt, TFLAG_HUP) || sofia_test_flag(tech_pvt, TFLAG_BYE) || !tech_pvt->read_codec.implementation) {
+ if (sofia_test_flag(tech_pvt, TFLAG_HUP) || sofia_test_flag(tech_pvt, TFLAG_BYE) || !tech_pvt->read_codec.implementation ||
+ !switch_core_codec_ready(&tech_pvt->read_codec)) {
return SWITCH_STATUS_FALSE;
}
int frames = 1;
if (!switch_test_flag((&tech_pvt->read_frame), SFF_CNG)) {
- if (!tech_pvt->read_codec.implementation) {
+ if (!tech_pvt->read_codec.implementation || !switch_core_codec_ready(&tech_pvt->read_codec)) {
*frame = NULL;
return SWITCH_STATUS_GENERR;
}
}
}
- if (!tech_pvt->read_codec.implementation) {
+ if (!tech_pvt->read_codec.implementation || !switch_core_codec_ready(&tech_pvt->read_codec)) {
return SWITCH_STATUS_GENERR;
}
return SWITCH_STATUS_SUCCESS;
}
- if (sofia_test_flag(tech_pvt, TFLAG_BYE) || !tech_pvt->read_codec.implementation) {
+ if (sofia_test_flag(tech_pvt, TFLAG_BYE) || !tech_pvt->read_codec.implementation || !switch_core_codec_ready(&tech_pvt->read_codec)) {
return SWITCH_STATUS_FALSE;
}
switch_status_t sofia_glue_tech_set_video_codec(private_object_t *tech_pvt, int force)
{
- if (tech_pvt->video_read_codec.implementation) {
+ if (tech_pvt->video_read_codec.implementation && switch_core_codec_ready(&tech_pvt->video_read_codec)) {
if (!force) {
return SWITCH_STATUS_SUCCESS;
}
switch_goto_status(SWITCH_STATUS_FALSE, end);
}
- if (tech_pvt->read_codec.implementation) {
+ if (tech_pvt->read_codec.implementation && switch_core_codec_ready(&tech_pvt->read_codec)) {
if (!force) {
switch_goto_status(SWITCH_STATUS_SUCCESS, end);
}
tech_pvt->read_frame.rate = tech_pvt->rm_rate;
ms = tech_pvt->write_codec.implementation->microseconds_per_packet / 1000;
- if (!tech_pvt->read_codec.implementation) {
+ if (!switch_core_codec_ready(&tech_pvt->read_codec)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't load codec?\n");
switch_goto_status(SWITCH_STATUS_FALSE, end);
}
switch_clear_flag_locked(tech_pvt, TFLAG_VOICE);
//switch_thread_cond_signal(tech_pvt->cond);
- if (tech_pvt->read_codec.implementation)
+ if (switch_core_codec_ready(&tech_pvt->read_codec))
switch_core_codec_destroy(&tech_pvt->read_codec);
- if (tech_pvt->write_codec.implementation)
+ if (switch_core_codec_ready(&tech_pvt->write_codec)
switch_core_codec_destroy(&tech_pvt->write_codec);
-
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s channel hangup\n", switch_channel_get_name(channel));
#if 0
return SWITCH_STATUS_SUCCESS;\r
}\r
\r
- if (!source->read_codec.implementation) {\r
+ if (!switch_core_codec_ready(&source->read_codec)) {\r
if (switch_core_codec_init(&source->read_codec,\r
"L16",\r
NULL, sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,\r
\r
switch_assert(source->read_codec.implementation);\r
\r
- if (!source->write_codec.implementation) {\r
+ if (!switch_core_codec_ready(&source->write_codec) {\r
if (switch_core_codec_init(&source->write_codec,\r
"L16",\r
NULL,\r
\r
switch_mutex_lock(source->device_lock);\r
CloseAudioStream(source->audio_stream);\r
- if (source->read_codec.implementation) {\r
+ if (switch_core_codec_ready(&source->read_codec)) {\r
switch_core_codec_destroy(&source->read_codec);\r
switch_core_codec_destroy(&source->write_codec);\r
}\r
- if (source->write_codec.implementation) {\r
+ if (switch_core_codec_ready(&source->write_codec) {\r
switch_core_codec_destroy(&source->write_codec);\r
}\r
switch_mutex_unlock(source->device_lock);\r
switch_mutex_lock(session->codec_read_mutex);
- if (codec && !codec->implementation) {
+ if (codec && (!codec->implementation || !switch_core_codec_ready(codec))) {
codec = NULL;
}
switch_mutex_lock(session->codec_write_mutex);
- if (!codec || !codec->implementation) {
+ if (!codec || !codec->implementation || !switch_core_codec_ready(codec)) {
if (session->real_write_codec) {
session->write_codec = session->real_write_codec;
session->write_impl = *session->real_write_codec->implementation;
char tmp[30];
switch_status_t status = SWITCH_STATUS_SUCCESS;
- if (!codec || !codec->implementation) {
+ if (!codec || !codec->implementation || !switch_core_codec_ready(codec)) {
if (session->video_read_codec) {
session->video_read_codec = NULL;
status = SWITCH_STATUS_SUCCESS;
switch_channel_t *channel = switch_core_session_get_channel(session);
char tmp[30];
switch_status_t status = SWITCH_STATUS_SUCCESS;
- if (!codec || !codec->implementation) {
+ if (!codec || !codec->implementation || !switch_core_codec_ready(codec)) {
if (session->video_write_codec) {
session->video_write_codec = NULL;
status = SWITCH_STATUS_SUCCESS;
implementation->init(codec, flags, codec_settings);
switch_mutex_init(&codec->mutex, SWITCH_MUTEX_NESTED, codec->memory_pool);
-
+ switch_set_flag(codec, SWITCH_CODEC_FLAG_READY);
return SWITCH_STATUS_SUCCESS;
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Codec %s Exists but not at the desired implementation. %dhz %dms\n", codec_name, rate,
switch_assert(encoded_data != NULL);
switch_assert(decoded_data != NULL);
- if (!codec->implementation) {
+ if (!codec->implementation || !switch_core_codec_ready(codec)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec is not initialized!\n");
return SWITCH_STATUS_NOT_INITALIZED;
}
switch_assert(encoded_data != NULL);
switch_assert(decoded_data != NULL);
- if (!codec->implementation) {
+ if (!codec->implementation || !switch_core_codec_ready(codec)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec is not initialized!\n");
return SWITCH_STATUS_NOT_INITALIZED;
}
switch_assert(codec != NULL);
- if (!codec->implementation) {
+ if (!codec->implementation || !switch_core_codec_ready(codec)) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Codec is not initialized!\n");
return SWITCH_STATUS_NOT_INITALIZED;
}
if (mutex) switch_mutex_lock(mutex);
codec->implementation->destroy(codec);
+ switch_clear_flag(codec, SWITCH_CODEC_FLAG_READY);
UNPROTECT_INTERFACE(codec->codec_interface);
- memset(codec, 0, sizeof(*codec));
-
if (mutex) switch_mutex_unlock(mutex);
if (free_pool) {
switch_status_t status = SWITCH_STATUS_FALSE;
int need_codec, perfect, do_bugs = 0, do_resample = 0, is_cng = 0;
unsigned int flag = 0;
+ switch_codec_implementation_t codec_impl;
switch_assert(session != NULL);
- if (!(session->read_codec && session->read_codec->implementation)) {
+ if (!(session->read_codec && session->read_codec->implementation && switch_core_codec_ready(session->read_codec))) {
if (switch_channel_test_flag(session->channel, CF_PROXY_MODE) || switch_channel_get_state(session->channel) == CS_HIBERNATE) {
*frame = &runtime.dummy_cng_frame;
return SWITCH_STATUS_SUCCESS;
switch_assert((*frame)->codec != NULL);
- if (((*frame)->codec && session->read_codec->implementation != (*frame)->codec->implementation)) {
- need_codec = TRUE;
- }
-
- if (!(session->read_codec && (*frame)->codec && (*frame)->codec->implementation)) {
+ switch_mutex_lock((*frame)->codec->mutex);
+ if (!(session->read_codec && (*frame)->codec && (*frame)->codec->implementation) && switch_core_codec_ready((*frame)->codec)) {
status = SWITCH_STATUS_FALSE;
+ switch_mutex_unlock((*frame)->codec->mutex);
goto done;
}
- if ((*frame)->codec->implementation->actual_samples_per_second != session->read_impl.actual_samples_per_second) {
+ codec_impl = *(*frame)->codec->implementation;
+ switch_mutex_unlock((*frame)->codec->mutex);
+
+ if (session->read_codec->implementation->impl_id != codec_impl.impl_id) {
+ need_codec = TRUE;
+ }
+
+ if (codec_impl.actual_samples_per_second != session->read_impl.actual_samples_per_second) {
do_resample = 1;
}
} else {
switch_codec_t *use_codec = read_frame->codec;
if (do_bugs) {
- if (!session->bug_codec.implementation) {
+ if (!switch_core_codec_ready(&session->bug_codec)) {
switch_core_codec_copy(read_frame->codec, &session->bug_codec, switch_core_session_get_pool(session));
}
use_codec = &session->bug_codec;
even_more_done:
- if (!*frame || !(*frame)->codec || !(*frame)->codec->implementation) {
+ if (!*frame || !(*frame)->codec || !(*frame)->codec->implementation || !switch_core_codec_ready((*frame)->codec)) {
*frame = &runtime.dummy_cng_frame;
}
- (*frame)->session = session;
-
switch_mutex_unlock(session->read_codec->mutex);
switch_mutex_unlock(session->codec_read_mutex);
return SWITCH_STATUS_SUCCESS;
}
- if (!(session->write_codec && session->write_codec->implementation) && !pass_cng) {
+ if (!(session->write_codec && switch_core_codec_ready(session->write_codec)) && !pass_cng) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s has no write codec.\n", switch_channel_get_name(session->channel));
return SWITCH_STATUS_FALSE;
}
- if (frame->codec && frame->codec->implementation) {
+ if (frame->codec && frame->codec->implementation && switch_core_codec_ready(frame->codec)) {
rate = frame->codec->implementation->actual_samples_per_second;
} else {
rate = session->write_impl.actual_samples_per_second;
status = SWITCH_STATUS_SUCCESS;
}
- if (session->bug_codec.implementation) {
+ if (switch_core_codec_ready(&session->bug_codec)) {
switch_core_codec_destroy(&session->bug_codec);
memset(&session->bug_codec, 0, sizeof(session->bug_codec));
}
}
}
- if (!session->bugs && session->bug_codec.implementation) {
+ if (!session->bugs && switch_core_codec_ready(&session->bug_codec)) {
switch_core_codec_destroy(&session->bug_codec);
memset(&session->bug_codec, 0, sizeof(session->bug_codec));
}
switch_thread_rwlock_unlock(session->bug_rwlock);
}
- if (!session->bugs && session->bug_codec.implementation) {
+ if (!session->bugs && switch_core_codec_ready(&session->bug_codec)) {
switch_core_codec_destroy(&session->bug_codec);
memset(&session->bug_codec, 0, sizeof(session->bug_codec));
}
vid_read_codec = switch_core_session_get_video_read_codec(session);
- if (read_codec && read_codec->implementation) {
+ if (read_codec && read_codec->implementation && switch_core_codec_ready(read_codec)) {
char rc[80] = "", vrc[80] = "", tmp[160] = "";
switch_codec2str(read_codec, rc, sizeof(rc));
- if (vid_read_codec && vid_read_codec->implementation) {
+ if (vid_read_codec && vid_read_codec->implementation && switch_core_codec_ready(vid_read_codec)) {
vrc[0] = ',';
switch_codec2str(read_codec, vrc+1, sizeof(vrc) - 1);
switch_channel_set_variable(peer_channel, SWITCH_ORIGINATOR_VIDEO_CODEC_VARIABLE, vrc+1);
break;
}
}
- if (conninfo->read_codec.implementation) {
+ if (switch_core_codec_ready(&conninfo->read_codec)) {
switch_core_codec_destroy(&conninfo->read_codec);
}
switch_socket_close(conninfo->socket);
switch_core_session_reset(session, SWITCH_TRUE, SWITCH_TRUE);
- if (write_codec.implementation) {
+ if (switch_core_codec_ready(&write_codec)) {
switch_core_codec_destroy(&write_codec);
}
switch_core_session_reset(oglobals.session, SWITCH_FALSE, SWITCH_TRUE);
}
- if (write_codec.implementation) {
+ if (switch_core_codec_ready(&write_codec)) {
switch_core_codec_destroy(&write_codec);
}