mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-07-01 13:22:40 +00:00
make codec pointers more reliable
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8958 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
32b3a852db
commit
55399ddf61
@ -105,7 +105,9 @@ struct switch_core_session {
|
|||||||
|
|
||||||
switch_io_event_hooks_t event_hooks;
|
switch_io_event_hooks_t event_hooks;
|
||||||
switch_codec_t *read_codec;
|
switch_codec_t *read_codec;
|
||||||
|
switch_codec_t *real_read_codec;
|
||||||
switch_codec_t *write_codec;
|
switch_codec_t *write_codec;
|
||||||
|
switch_codec_t *real_write_codec;
|
||||||
switch_codec_t *video_read_codec;
|
switch_codec_t *video_read_codec;
|
||||||
switch_codec_t *video_write_codec;
|
switch_codec_t *video_write_codec;
|
||||||
|
|
||||||
|
@ -1129,6 +1129,13 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_codec(_In_ switch_c
|
|||||||
*/
|
*/
|
||||||
SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_read_codec(_In_ switch_core_session_t *session);
|
SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_read_codec(_In_ switch_core_session_t *session);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Retrieve the effevtive read codec from a given session
|
||||||
|
\param session session to retrieve from
|
||||||
|
\return a pointer to the codec
|
||||||
|
*/
|
||||||
|
SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_effective_read_codec(_In_ switch_core_session_t *session);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Assign the write codec to a given session
|
\brief Assign the write codec to a given session
|
||||||
\param session session to add the codec to
|
\param session session to add the codec to
|
||||||
@ -1144,6 +1151,13 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_write_codec(_In_ switch_
|
|||||||
*/
|
*/
|
||||||
SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_write_codec(_In_ switch_core_session_t *session);
|
SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_write_codec(_In_ switch_core_session_t *session);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Retrieve the effevtive write codec from a given session
|
||||||
|
\param session session to retrieve from
|
||||||
|
\return a pointer to the codec
|
||||||
|
*/
|
||||||
|
SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_effective_write_codec(_In_ switch_core_session_t *session);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Assign the video_read codec to a given session
|
\brief Assign the video_read codec to a given session
|
||||||
\param session session to add the codec to
|
\param session session to add the codec to
|
||||||
|
@ -49,7 +49,30 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_codec(switch_core_s
|
|||||||
switch_channel_t *channel = switch_core_session_get_channel(session);
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||||
char tmp[30];
|
char tmp[30];
|
||||||
|
|
||||||
switch_assert(codec->implementation);
|
if (!codec || !codec->implementation) {
|
||||||
|
if (session->real_read_codec) {
|
||||||
|
session->read_codec = session->real_read_codec;
|
||||||
|
session->real_read_codec = NULL;
|
||||||
|
} else {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot set NULL codec!\n");
|
||||||
|
return SWITCH_STATUS_FALSE;
|
||||||
|
}
|
||||||
|
} else if (session->read_codec) {
|
||||||
|
if (session->real_read_codec) {
|
||||||
|
if (codec == session->real_read_codec) {
|
||||||
|
session->read_codec = codec;
|
||||||
|
session->real_read_codec = NULL;
|
||||||
|
} else {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot double-set codec!\n");
|
||||||
|
return SWITCH_STATUS_FALSE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
session->real_read_codec = session->read_codec;
|
||||||
|
session->read_codec = codec;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
session->read_codec = codec;
|
||||||
|
}
|
||||||
|
|
||||||
if (switch_event_create(&event, SWITCH_EVENT_CODEC) == SWITCH_STATUS_SUCCESS) {
|
if (switch_event_create(&event, SWITCH_EVENT_CODEC) == SWITCH_STATUS_SUCCESS) {
|
||||||
switch_channel_event_set_data(session->channel, event);
|
switch_channel_event_set_data(session->channel, event);
|
||||||
@ -65,7 +88,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_codec(switch_core_s
|
|||||||
switch_snprintf(tmp, sizeof(tmp), "%d", codec->implementation->actual_samples_per_second);
|
switch_snprintf(tmp, sizeof(tmp), "%d", codec->implementation->actual_samples_per_second);
|
||||||
switch_channel_set_variable(channel, "read_rate", tmp);
|
switch_channel_set_variable(channel, "read_rate", tmp);
|
||||||
|
|
||||||
session->read_codec = codec;
|
|
||||||
session->raw_read_frame.codec = session->read_codec;
|
session->raw_read_frame.codec = session->read_codec;
|
||||||
session->raw_write_frame.codec = session->read_codec;
|
session->raw_write_frame.codec = session->read_codec;
|
||||||
session->enc_read_frame.codec = session->read_codec;
|
session->enc_read_frame.codec = session->read_codec;
|
||||||
@ -74,18 +97,46 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_read_codec(switch_core_s
|
|||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_read_codec(switch_core_session_t *session)
|
SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_effective_read_codec(switch_core_session_t *session)
|
||||||
{
|
{
|
||||||
return session->read_codec;
|
return session->read_codec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_read_codec(switch_core_session_t *session)
|
||||||
|
{
|
||||||
|
return session->real_read_codec ? session->real_read_codec : session->read_codec;
|
||||||
|
}
|
||||||
|
|
||||||
SWITCH_DECLARE(switch_status_t) switch_core_session_set_write_codec(switch_core_session_t *session, switch_codec_t *codec)
|
SWITCH_DECLARE(switch_status_t) switch_core_session_set_write_codec(switch_core_session_t *session, switch_codec_t *codec)
|
||||||
{
|
{
|
||||||
switch_event_t *event;
|
switch_event_t *event;
|
||||||
switch_channel_t *channel = switch_core_session_get_channel(session);
|
switch_channel_t *channel = switch_core_session_get_channel(session);
|
||||||
char tmp[30];
|
char tmp[30];
|
||||||
|
|
||||||
switch_assert(codec->implementation);
|
if (!codec || !codec->implementation) {
|
||||||
|
if (session->real_write_codec) {
|
||||||
|
session->write_codec = session->real_write_codec;
|
||||||
|
session->real_write_codec = NULL;
|
||||||
|
} else {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot set NULL codec!\n");
|
||||||
|
return SWITCH_STATUS_FALSE;
|
||||||
|
}
|
||||||
|
} else if (session->write_codec) {
|
||||||
|
if (session->real_write_codec) {
|
||||||
|
if (codec == session->real_write_codec) {
|
||||||
|
session->write_codec = codec;
|
||||||
|
session->real_write_codec = NULL;
|
||||||
|
} else {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot double-set codec!\n");
|
||||||
|
return SWITCH_STATUS_FALSE;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
session->real_write_codec = session->write_codec;
|
||||||
|
session->write_codec = codec;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
session->write_codec = codec;
|
||||||
|
}
|
||||||
|
|
||||||
if (switch_event_create(&event, SWITCH_EVENT_CODEC) == SWITCH_STATUS_SUCCESS) {
|
if (switch_event_create(&event, SWITCH_EVENT_CODEC) == SWITCH_STATUS_SUCCESS) {
|
||||||
switch_channel_event_set_data(session->channel, event);
|
switch_channel_event_set_data(session->channel, event);
|
||||||
@ -102,13 +153,18 @@ SWITCH_DECLARE(switch_status_t) switch_core_session_set_write_codec(switch_core_
|
|||||||
switch_snprintf(tmp, sizeof(tmp), "%d", codec->implementation->actual_samples_per_second);
|
switch_snprintf(tmp, sizeof(tmp), "%d", codec->implementation->actual_samples_per_second);
|
||||||
switch_channel_set_variable(channel, "write_rate", tmp);
|
switch_channel_set_variable(channel, "write_rate", tmp);
|
||||||
|
|
||||||
session->write_codec = codec;
|
|
||||||
return SWITCH_STATUS_SUCCESS;
|
return SWITCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_effective_write_codec(switch_core_session_t *session)
|
||||||
|
{
|
||||||
|
return session->write_codec;
|
||||||
|
}
|
||||||
|
|
||||||
SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_write_codec(switch_core_session_t *session)
|
SWITCH_DECLARE(switch_codec_t *) switch_core_session_get_write_codec(switch_core_session_t *session)
|
||||||
{
|
{
|
||||||
return session->write_codec;
|
return session->real_write_codec ? session->real_write_codec : session->write_codec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user