[Freeswitch-svn] [commit] r8958 - in freeswitch/trunk/src: . include include/private

Freeswitch SVN anthm at freeswitch.org
Wed Jul 9 12:44:19 EDT 2008


Author: anthm
Date: Wed Jul  9 12:44:19 2008
New Revision: 8958

Modified:
   freeswitch/trunk/src/include/private/switch_core_pvt.h
   freeswitch/trunk/src/include/switch_core.h
   freeswitch/trunk/src/switch_core_codec.c

Log:
make codec pointers more reliable

Modified: freeswitch/trunk/src/include/private/switch_core_pvt.h
==============================================================================
--- freeswitch/trunk/src/include/private/switch_core_pvt.h	(original)
+++ freeswitch/trunk/src/include/private/switch_core_pvt.h	Wed Jul  9 12:44:19 2008
@@ -105,7 +105,9 @@
 
 	switch_io_event_hooks_t event_hooks;
 	switch_codec_t *read_codec;
+	switch_codec_t *real_read_codec;
 	switch_codec_t *write_codec;
+	switch_codec_t *real_write_codec;
 	switch_codec_t *video_read_codec;
 	switch_codec_t *video_write_codec;
 

Modified: freeswitch/trunk/src/include/switch_core.h
==============================================================================
--- freeswitch/trunk/src/include/switch_core.h	(original)
+++ freeswitch/trunk/src/include/switch_core.h	Wed Jul  9 12:44:19 2008
@@ -1130,6 +1130,13 @@
 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
   \param session session to add the codec to
   \param codec the codec to add
@@ -1145,6 +1152,13 @@
 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
   \param session session to add the codec to
   \param codec the codec to add

Modified: freeswitch/trunk/src/switch_core_codec.c
==============================================================================
--- freeswitch/trunk/src/switch_core_codec.c	(original)
+++ freeswitch/trunk/src/switch_core_codec.c	Wed Jul  9 12:44:19 2008
@@ -49,7 +49,30 @@
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	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) {
 		switch_channel_event_set_data(session->channel, event);
@@ -65,7 +88,7 @@
 	switch_snprintf(tmp, sizeof(tmp), "%d", codec->implementation->actual_samples_per_second);
 	switch_channel_set_variable(channel, "read_rate", tmp);
 
-	session->read_codec = codec;
+
 	session->raw_read_frame.codec = session->read_codec;
 	session->raw_write_frame.codec = session->read_codec;
 	session->enc_read_frame.codec = session->read_codec;
@@ -74,18 +97,46 @@
 	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;
 }
 
+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_event_t *event;
 	switch_channel_t *channel = switch_core_session_get_channel(session);
 	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) {
 		switch_channel_event_set_data(session->channel, event);
@@ -102,15 +153,20 @@
 	switch_snprintf(tmp, sizeof(tmp), "%d", codec->implementation->actual_samples_per_second);
 	switch_channel_set_variable(channel, "write_rate", tmp);
 
-	session->write_codec = codec;
 	return SWITCH_STATUS_SUCCESS;
 }
 
-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_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)
+{
+	return session->real_write_codec ? session->real_write_codec : session->write_codec;
+}
+
 
 
 SWITCH_DECLARE(switch_status_t) switch_core_session_set_video_read_codec(switch_core_session_t *session, switch_codec_t *codec)



More information about the Freeswitch-svn mailing list