FSCORE-349 add flag to denote if a codec is init or not
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@12961 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
2840f826f0
commit
68b0359cfb
|
@ -68,7 +68,6 @@ SWITCH_BEGIN_EXTERN_C
|
|||
switch_bool_t m;
|
||||
/*! frame flags */
|
||||
switch_frame_flag_t flags;
|
||||
switch_core_session_t *session;
|
||||
};
|
||||
|
||||
SWITCH_END_EXTERN_C
|
||||
|
|
|
@ -413,6 +413,7 @@ static inline void switch_core_codec_add_implementation(switch_memory_pool_t *po
|
|||
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",
|
||||
|
@ -427,6 +428,11 @@ static inline void switch_core_codec_add_implementation(switch_memory_pool_t *po
|
|||
}
|
||||
|
||||
|
||||
static inline switch_bool_t switch_core_codec_ready(switch_codec_t *codec)
|
||||
{
|
||||
return (codec->flags & SWITCH_CODEC_FLAG_READY) ? SWITCH_TRUE : SWITCH_FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -609,6 +609,7 @@ struct switch_codec_implementation {
|
|||
/*! 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;
|
||||
};
|
||||
|
||||
|
|
|
@ -954,7 +954,8 @@ typedef enum {
|
|||
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;
|
||||
|
||||
|
|
|
@ -4489,7 +4489,7 @@ static int setup_media(conference_member_t *member, conference_obj_t *conference
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -242,7 +242,7 @@ SWITCH_STANDARD_APP(bcast_function)
|
|||
fail:
|
||||
|
||||
switch_core_session_set_read_codec(session, NULL);
|
||||
if (codec.implementation) {
|
||||
if (switch_core_codec_ready(&codec)) {
|
||||
switch_core_codec_destroy(&codec);
|
||||
}
|
||||
|
||||
|
|
|
@ -678,11 +678,11 @@ void process_fax(switch_core_session_t *session, const char *data, application_m
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -346,11 +346,11 @@ SWITCH_STANDARD_APP(play_fsv_function)
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -931,11 +931,11 @@ SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_alsa_shutdown)
|
|||
{
|
||||
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);
|
||||
|
|
|
@ -1244,11 +1244,11 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
|
|||
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);
|
||||
}
|
||||
|
||||
|
@ -1440,7 +1440,7 @@ static switch_status_t channel_write_frame(switch_core_session_t *session, switc
|
|||
}
|
||||
}
|
||||
|
||||
if (!tech_pvt->read_codec.implementation) {
|
||||
if (!switch_core_codec_ready(&tech_pvt->read_codec) || !tech_pvt->read_codec.implementation) {
|
||||
return SWITCH_STATUS_GENERR;
|
||||
}
|
||||
|
||||
|
|
|
@ -498,11 +498,11 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
|
|||
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);
|
||||
}
|
||||
|
||||
|
@ -1084,7 +1084,8 @@ SWITCH_MODULE_RUNTIME_FUNCTION(mod_iax_runtime)
|
|||
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;
|
||||
}
|
||||
|
|
|
@ -113,11 +113,11 @@ static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *ses
|
|||
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);
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ static switch_status_t tech_init(private_t *tech_pvt, switch_core_session_t *ses
|
|||
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;
|
||||
}
|
||||
|
||||
|
@ -373,11 +373,11 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -348,11 +348,11 @@ static void deactivate_audio_device(void)
|
|||
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);
|
||||
}
|
||||
|
||||
|
@ -1294,7 +1294,7 @@ static switch_status_t engage_device(int restart)
|
|||
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,
|
||||
|
@ -1306,7 +1306,7 @@ static switch_status_t engage_device(int restart)
|
|||
|
||||
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,
|
||||
|
|
|
@ -200,11 +200,11 @@ static switch_status_t channel_on_hangup(switch_core_session_t *session)
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -205,11 +205,11 @@ static switch_status_t channel_on_hangup(switch_core_session_t * session)
|
|||
skypiax_signaling_write(tech_pvt, msg_to_skype);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -379,11 +379,11 @@ switch_status_t sofia_on_hangup(switch_core_session_t *session)
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -665,7 +665,8 @@ static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_f
|
|||
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;
|
||||
}
|
||||
|
||||
|
@ -711,7 +712,7 @@ static switch_status_t sofia_read_frame(switch_core_session_t *session, switch_f
|
|||
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;
|
||||
}
|
||||
|
@ -872,7 +873,7 @@ static switch_status_t sofia_write_frame(switch_core_session_t *session, switch_
|
|||
}
|
||||
}
|
||||
|
||||
if (!tech_pvt->read_codec.implementation) {
|
||||
if (!tech_pvt->read_codec.implementation || !switch_core_codec_ready(&tech_pvt->read_codec)) {
|
||||
return SWITCH_STATUS_GENERR;
|
||||
}
|
||||
|
||||
|
@ -888,7 +889,7 @@ static switch_status_t sofia_write_frame(switch_core_session_t *session, switch_
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -1752,7 +1752,7 @@ void sofia_glue_deactivate_rtp(private_object_t *tech_pvt)
|
|||
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;
|
||||
}
|
||||
|
@ -1825,7 +1825,7 @@ switch_status_t sofia_glue_tech_set_codec(private_object_t *tech_pvt, int force)
|
|||
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);
|
||||
}
|
||||
|
@ -1885,7 +1885,7 @@ switch_status_t sofia_glue_tech_set_codec(private_object_t *tech_pvt, int force)
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -948,9 +948,9 @@ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "unicall_on_hangup(%p)\n"
|
|||
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));
|
||||
|
|
|
@ -171,7 +171,7 @@ static switch_status_t engage_device(portaudio_stream_source_t *source,int resta
|
|||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
if (!source->read_codec.implementation) {
|
||||
if (!switch_core_codec_ready(&source->read_codec)) {
|
||||
if (switch_core_codec_init(&source->read_codec,
|
||||
"L16",
|
||||
NULL, sample_rate, codec_ms, 1, SWITCH_CODEC_FLAG_ENCODE | SWITCH_CODEC_FLAG_DECODE, NULL,
|
||||
|
@ -183,7 +183,7 @@ static switch_status_t engage_device(portaudio_stream_source_t *source,int resta
|
|||
|
||||
switch_assert(source->read_codec.implementation);
|
||||
|
||||
if (!source->write_codec.implementation) {
|
||||
if (!switch_core_codec_ready(&source->write_codec) {
|
||||
if (switch_core_codec_init(&source->write_codec,
|
||||
"L16",
|
||||
NULL,
|
||||
|
@ -340,11 +340,11 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
|
|||
|
||||
switch_mutex_lock(source->device_lock);
|
||||
CloseAudioStream(source->audio_stream);
|
||||
if (source->read_codec.implementation) {
|
||||
if (switch_core_codec_ready(&source->read_codec)) {
|
||||
switch_core_codec_destroy(&source->read_codec);
|
||||
switch_core_codec_destroy(&source->write_codec);
|
||||
}
|
||||
if (source->write_codec.implementation) {
|
||||
if (switch_core_codec_ready(&source->write_codec) {
|
||||
switch_core_codec_destroy(&source->write_codec);
|
||||
}
|
||||
switch_mutex_unlock(source->device_lock);
|
||||
|
|
|
@ -100,7 +100,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_codec(switch_core_s
|
|||
|
||||
switch_mutex_lock(session->codec_read_mutex);
|
||||
|
||||
if (codec && !codec->implementation) {
|
||||
if (codec && (!codec->implementation || !switch_core_codec_ready(codec))) {
|
||||
codec = NULL;
|
||||
}
|
||||
|
||||
|
@ -221,7 +221,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_write_codec(switch_core_
|
|||
|
||||
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;
|
||||
|
@ -301,7 +301,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_video_read_codec(switch_
|
|||
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;
|
||||
|
@ -345,7 +345,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_video_write_codec(switch
|
|||
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;
|
||||
|
@ -493,7 +493,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_init(switch_codec_t *codec, co
|
|||
|
||||
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,
|
||||
|
@ -518,7 +518,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_encode(switch_codec_t *codec,
|
|||
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;
|
||||
}
|
||||
|
@ -550,7 +550,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_decode(switch_codec_t *codec,
|
|||
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;
|
||||
}
|
||||
|
@ -576,7 +576,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_destroy(switch_codec_t *codec)
|
|||
|
||||
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;
|
||||
}
|
||||
|
@ -591,11 +591,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_destroy(switch_codec_t *codec)
|
|||
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) {
|
||||
|
|
|
@ -106,10 +106,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
|
|||
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;
|
||||
|
@ -202,16 +203,21 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
|
|||
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;
|
||||
}
|
||||
|
||||
|
@ -243,7 +249,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
|
|||
} 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;
|
||||
|
@ -525,12 +531,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
|
|||
|
||||
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);
|
||||
|
||||
|
@ -579,7 +583,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
|
|||
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;
|
||||
}
|
||||
|
@ -924,7 +928,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
|
|||
|
||||
|
||||
|
||||
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;
|
||||
|
|
|
@ -334,7 +334,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_all(switch_core_ses
|
|||
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));
|
||||
}
|
||||
|
@ -389,7 +389,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove(switch_core_session
|
|||
}
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
@ -427,7 +427,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_callback(switch_cor
|
|||
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));
|
||||
}
|
||||
|
|
|
@ -399,11 +399,11 @@ SWITCH_DECLARE(switch_call_cause_t) switch_core_session_outgoing_channel(switch_
|
|||
|
||||
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);
|
||||
|
|
|
@ -342,7 +342,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_deactivate_unicast(switch_core_sessio
|
|||
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);
|
||||
|
|
|
@ -833,7 +833,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_wait_for_answer(switch_core_session_t
|
|||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -2102,7 +2102,7 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_originate(switch_core_session_t *sess
|
|||
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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue