]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
fix FSCORE-210
authorBrian West <brian@freeswitch.org>
Wed, 29 Oct 2008 00:04:20 +0000 (00:04 +0000)
committerBrian West <brian@freeswitch.org>
Wed, 29 Oct 2008 00:04:20 +0000 (00:04 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10182 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_types.h
src/switch_core_codec.c
src/switch_core_io.c
src/switch_core_media_bug.c
src/switch_core_session.c

index aacb66f798fb066410f7f4fe27202101b16b6b48..1390605901e6d43abc42d43abcfbc82288098a6c 100644 (file)
@@ -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;
 
 
index d5095d63afd0d5fad70c584eb1cbe0d66c32bac3..1c4d7c19cafdc62e3750b6a2f8b26bd2082ea873 100644 (file)
@@ -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);
index 4fcdd269026cf19ed42bc994a4d5648082bbc2e9..b2b25e1e3f78ad63067fe6bfbba0a880904e4007 100644 (file)
@@ -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);
index d7afe95ef8f3f0c8edf15c50cd001c1298362d5a..d2121c214594df80d0b178fbd5d6618697f7bff2 100644 (file)
@@ -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;
index 609093be746d15388da4b051db507f87d202eb8e..e9d21c244f931e0bed99b8c185f3e9dfaa255d5b 100644 (file)
@@ -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);