fix FSCORE-210
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10182 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
3a4993d3dc
commit
585eaeb551
|
@ -623,7 +623,8 @@ typedef enum {
|
|||
SWITCH_STATUS_NOTFOUND,
|
||||
SWITCH_STATUS_UNLOAD,
|
||||
SWITCH_STATUS_NOUNLOAD,
|
||||
SWITCH_STATUS_IGNORE
|
||||
SWITCH_STATUS_IGNORE,
|
||||
SWITCH_STATUS_NOT_INITALIZED
|
||||
} switch_status_t;
|
||||
|
||||
|
||||
|
|
|
@ -60,45 +60,34 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_codec(switch_core_s
|
|||
char tmp[30];
|
||||
switch_status_t status = SWITCH_STATUS_SUCCESS;
|
||||
|
||||
if (codec && !codec->implementation) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot set UNINITIALIZED codec!\n");
|
||||
status = SWITCH_STATUS_FALSE;
|
||||
goto end;
|
||||
}
|
||||
|
||||
if (!codec || codec == session->real_read_codec) {
|
||||
|
||||
if (!codec || !codec->implementation) {
|
||||
if (session->real_read_codec) {
|
||||
if (session->real_read_codec->implementation) {
|
||||
session->read_codec = session->real_read_codec;
|
||||
session->read_impl = *session->real_read_codec->implementation;
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "resetting to uninitilized codec, setting to NULL\n");
|
||||
session->read_codec = session->real_read_codec = NULL;
|
||||
status = SWITCH_STATUS_FALSE;
|
||||
goto end;
|
||||
}
|
||||
session->read_codec = session->real_read_codec;
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Restore original codec.\n");
|
||||
} else {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot set UNINITIALIZED codec!\n");
|
||||
status = SWITCH_STATUS_FALSE;
|
||||
goto end;
|
||||
}
|
||||
|
||||
} else if (codec) {
|
||||
if (session->read_codec != session->real_read_codec) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot double-set codec!\n");
|
||||
status = SWITCH_STATUS_FALSE;
|
||||
goto end;
|
||||
}
|
||||
|
||||
session->read_codec = codec;
|
||||
session->read_impl = *codec->implementation;
|
||||
} else {
|
||||
|
||||
if (!session->real_read_codec) {
|
||||
session->real_read_codec = session->read_codec;
|
||||
session->read_codec = session->real_read_codec = codec;
|
||||
} else {
|
||||
session->read_codec = codec;
|
||||
}
|
||||
}
|
||||
|
||||
if (session->read_codec && codec && session->read_impl.decoded_bytes_per_packet) {
|
||||
if (!session->read_codec) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No READ codec!\n");
|
||||
status = SWITCH_STATUS_FALSE;
|
||||
goto end;
|
||||
}
|
||||
|
||||
session->read_impl = *session->read_codec->implementation;
|
||||
|
||||
|
||||
if (session->read_codec && session->read_impl.decoded_bytes_per_packet) {
|
||||
if (switch_event_create(&event, SWITCH_EVENT_CODEC) == SWITCH_STATUS_SUCCESS) {
|
||||
switch_channel_event_set_data(session->channel, event);
|
||||
switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "channel-read-codec-name", session->read_impl.iananame);
|
||||
|
@ -477,12 +466,12 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_encode(switch_codec_t *codec,
|
|||
|
||||
if (!codec->implementation) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec is not initialized!\n");
|
||||
return SWITCH_STATUS_GENERR;
|
||||
return SWITCH_STATUS_NOT_INITALIZED;
|
||||
}
|
||||
|
||||
if (!switch_test_flag(codec, SWITCH_CODEC_FLAG_ENCODE)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec encoder is not initialized!\n");
|
||||
return SWITCH_STATUS_GENERR;
|
||||
return SWITCH_STATUS_NOT_INITALIZED;
|
||||
}
|
||||
|
||||
return codec->implementation->encode(codec, other_codec, decoded_data, decoded_data_len, decoded_rate, encoded_data, encoded_data_len, encoded_rate,
|
||||
|
@ -502,12 +491,12 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_decode(switch_codec_t *codec,
|
|||
|
||||
if (!codec->implementation) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec is not initialized!\n");
|
||||
return SWITCH_STATUS_GENERR;
|
||||
return SWITCH_STATUS_NOT_INITALIZED;
|
||||
}
|
||||
|
||||
if (!switch_test_flag(codec, SWITCH_CODEC_FLAG_DECODE)) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec decoder is not initialized!\n");
|
||||
return SWITCH_STATUS_GENERR;
|
||||
return SWITCH_STATUS_NOT_INITALIZED;
|
||||
}
|
||||
|
||||
return codec->implementation->decode(codec, other_codec, encoded_data, encoded_data_len, encoded_rate, decoded_data, decoded_data_len, decoded_rate,
|
||||
|
@ -520,7 +509,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_codec_destroy(switch_codec_t *codec)
|
|||
|
||||
if (!codec->implementation) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Codec is not initialized!\n");
|
||||
return SWITCH_STATUS_GENERR;
|
||||
return SWITCH_STATUS_NOT_INITALIZED;
|
||||
}
|
||||
|
||||
codec->implementation->destroy(codec);
|
||||
|
|
|
@ -296,6 +296,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
|
|||
read_frame = &session->raw_read_frame;
|
||||
status = SWITCH_STATUS_SUCCESS;
|
||||
break;
|
||||
case SWITCH_STATUS_NOT_INITALIZED:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec init error!\n");
|
||||
goto done;
|
||||
default:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec %s decoder error!\n", session->read_codec->codec_interface->interface_name);
|
||||
goto done;
|
||||
|
@ -437,6 +440,11 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_read_frame(switch_core_sessi
|
|||
*frame = &session->raw_read_frame;
|
||||
status = SWITCH_STATUS_SUCCESS;
|
||||
break;
|
||||
case SWITCH_STATUS_NOT_INITALIZED:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec init error!\n");
|
||||
*frame = NULL;
|
||||
status = SWITCH_STATUS_GENERR;
|
||||
break;
|
||||
default:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec %s encoder error!\n",
|
||||
session->read_codec->codec_interface->interface_name);
|
||||
|
@ -650,11 +658,15 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
|
|||
status = SWITCH_STATUS_SUCCESS;
|
||||
break;
|
||||
default:
|
||||
if (status == SWITCH_STATUS_NOT_INITALIZED) {
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec init error!\n");
|
||||
return status;
|
||||
}
|
||||
if (ptime_mismatch) {
|
||||
status = perform_write(session, frame, flags, stream_id);
|
||||
return SWITCH_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec %s decoder error!\n", frame->codec->codec_interface->interface_name);
|
||||
return status;
|
||||
}
|
||||
|
@ -799,6 +811,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
|
|||
write_frame = enc_frame;
|
||||
status = SWITCH_STATUS_SUCCESS;
|
||||
break;
|
||||
case SWITCH_STATUS_NOT_INITALIZED:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec init error!\n");
|
||||
write_frame = NULL;
|
||||
return status;
|
||||
default:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec %s encoder error!\n",
|
||||
session->read_codec->codec_interface->interface_name);
|
||||
|
@ -886,6 +902,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_write_frame(switch_core_sess
|
|||
write_frame = enc_frame;
|
||||
status = SWITCH_STATUS_SUCCESS;
|
||||
break;
|
||||
case SWITCH_STATUS_NOT_INITALIZED:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec init error!\n");
|
||||
write_frame = NULL;
|
||||
return status;
|
||||
default:
|
||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Codec %s encoder error %d!\n",
|
||||
session->read_codec->codec_interface->interface_name, status);
|
||||
|
|
|
@ -290,6 +290,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove_all(switch_core_ses
|
|||
|
||||
if (session->bug_codec.implementation) {
|
||||
switch_core_codec_destroy(&session->bug_codec);
|
||||
memset(&session->bug_codec, 0, sizeof(session->bug_codec));
|
||||
}
|
||||
|
||||
return SWITCH_STATUS_FALSE;
|
||||
|
@ -346,9 +347,10 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_remove(switch_core_session
|
|||
switch_thread_rwlock_unlock(session->bug_rwlock);
|
||||
status = switch_core_media_bug_close(&bp);
|
||||
}
|
||||
|
||||
|
||||
if (!session->bugs && session->bug_codec.implementation) {
|
||||
switch_core_codec_destroy(&session->bug_codec);
|
||||
memset(&session->bug_codec, 0, sizeof(session->bug_codec));
|
||||
}
|
||||
|
||||
return status;
|
||||
|
|
|
@ -672,7 +672,7 @@ SWITCH_DECLARE(void) switch_core_session_reset(switch_core_session_t *session, s
|
|||
switch_size_t has;
|
||||
|
||||
switch_core_session_set_read_codec(session, NULL);
|
||||
|
||||
|
||||
/* clear resamplers */
|
||||
switch_mutex_lock(session->resample_mutex);
|
||||
switch_resample_destroy(&session->read_resampler);
|
||||
|
|
Loading…
Reference in New Issue