2012-12-18 10:50:43 -06:00
|
|
|
/*
|
|
|
|
* FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
|
|
|
* Copyright (C) 2005-2012, Anthony Minessale II <anthm@freeswitch.org>
|
|
|
|
*
|
|
|
|
* Version: MPL 1.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is FreeSWITCH Modular Media Switching Software Library / Soft-Switch Application
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Anthony Minessale II <anthm@freeswitch.org>
|
|
|
|
* Portions created by the Initial Developer are Copyright (C)
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Anthony Minessale II <anthm@freeswitch.org>
|
|
|
|
*
|
|
|
|
* switch_core_media.c -- Core Media
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <switch.h>
|
|
|
|
#include <switch_ssl.h>
|
|
|
|
#include <switch_stun.h>
|
|
|
|
#include <switch_nat.h>
|
|
|
|
#include <switch_version.h>
|
|
|
|
#include "private/switch_core_pvt.h"
|
|
|
|
#include <switch_curl.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2012-12-18 16:06:29 -06:00
|
|
|
typedef enum {
|
|
|
|
SMH_INIT = (1 << 0),
|
|
|
|
SMH_READY = (1 << 1)
|
|
|
|
} smh_flag_t;
|
2012-12-18 10:50:43 -06:00
|
|
|
|
|
|
|
|
2012-12-18 16:06:29 -06:00
|
|
|
struct switch_media_handle_s {
|
|
|
|
switch_core_session_t *session;
|
|
|
|
switch_core_media_NDLB_t ndlb;
|
|
|
|
smh_flag_t flags;
|
|
|
|
};
|
2012-12-18 10:50:43 -06:00
|
|
|
|
|
|
|
|
2012-12-18 16:06:29 -06:00
|
|
|
SWITCH_DECLARE(switch_status_t) switch_media_handle_create(switch_media_handle_t **smhp, switch_core_session_t *session)
|
|
|
|
{
|
|
|
|
switch_status_t status = SWITCH_STATUS_FALSE;
|
|
|
|
switch_media_handle_t *smh = NULL;
|
|
|
|
|
|
|
|
*smhp = NULL;
|
|
|
|
|
|
|
|
if ((session->media_handle = switch_core_session_alloc(session, (sizeof(*smh))))) {
|
|
|
|
|
|
|
|
*smhp = session->media_handle;
|
|
|
|
switch_set_flag(session->media_handle, SMH_INIT);
|
|
|
|
status = SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return status;
|
|
|
|
}
|
|
|
|
|
|
|
|
SWITCH_DECLARE(void) switch_media_handle_set_ndlb(switch_media_handle_t *smh, switch_core_media_NDLB_t flag)
|
|
|
|
{
|
|
|
|
switch_assert(smh);
|
|
|
|
|
|
|
|
smh->flags |= flag;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
SWITCH_DECLARE(void) switch_media_handle_clear_ndlb(switch_media_handle_t *smh, switch_core_media_NDLB_t flag)
|
|
|
|
{
|
|
|
|
switch_assert(smh);
|
|
|
|
|
|
|
|
smh->flags &= ~flag;
|
|
|
|
}
|
|
|
|
|
|
|
|
SWITCH_DECLARE(int32_t) switch_media_handle_test_ndlb(switch_media_handle_t *smh, switch_core_media_NDLB_t flag)
|
|
|
|
{
|
|
|
|
switch_assert(smh);
|
|
|
|
return (smh->flags & flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
SWITCH_DECLARE(switch_status_t) switch_core_session_media_handle_ready(switch_core_session_t *session)
|
|
|
|
{
|
|
|
|
if (session->media_handle && switch_test_flag(session->media_handle, SMH_INIT)) {
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SWITCH_DECLARE(switch_media_handle_t *) switch_core_session_get_media_handle(switch_core_session_t *session)
|
|
|
|
{
|
|
|
|
if (switch_core_session_media_handle_ready(session)) {
|
|
|
|
return session->media_handle;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
SWITCH_DECLARE(switch_status_t) switch_core_session_clear_media_handle(switch_core_session_t *session)
|
|
|
|
{
|
|
|
|
if (!session->media_handle) {
|
|
|
|
return SWITCH_STATUS_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return SWITCH_STATUS_SUCCESS;
|
|
|
|
}
|
2012-12-18 10:50:43 -06:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* For Emacs:
|
|
|
|
* Local Variables:
|
|
|
|
* mode:c
|
|
|
|
* indent-tabs-mode:t
|
|
|
|
* tab-width:4
|
|
|
|
* c-basic-offset:4
|
|
|
|
* End:
|
|
|
|
* For VIM:
|
|
|
|
* vim:set softtabstop=4 shiftwidth=4 tabstop=4:
|
|
|
|
*/
|