Skip to content
This repository was archived by the owner on Feb 3, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions tinywrap/ActionConfig.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*/

#include "ActionConfig.h"

ActionConfig::ActionConfig()
{
m_pHandle = tsip_action_create(tsip_atype_config,
TSIP_ACTION_SET_NULL());
}

ActionConfig::~ActionConfig()
{
TSK_OBJECT_SAFE_FREE(m_pHandle);
}

bool ActionConfig::addHeader(const char* name, const char* value)
{
return (tsip_action_set(m_pHandle,
TSIP_ACTION_SET_HEADER(name, value),
TSIP_ACTION_SET_NULL()) == 0);
}

bool ActionConfig::addPayload(const void* payload, unsigned len)
{
return (tsip_action_set(m_pHandle,
TSIP_ACTION_SET_PAYLOAD(payload, len),
TSIP_ACTION_SET_NULL()) == 0);
}

bool ActionConfig::setActiveMedia(twrap_media_type_t type)
{
tmedia_type_t media_type = twrap_get_native_media_type(type);
return (tsip_action_set(m_pHandle,
TSIP_ACTION_SET_MEDIA_TYPE(media_type),
TSIP_ACTION_SET_NULL()) == 0);
}

ActionConfig* ActionConfig::setResponseLine(short code, const char* phrase)
{
int32_t _code = code;
tsip_action_set(m_pHandle,
TSIP_ACTION_SET_RESP_LINE(_code, phrase),
TSIP_ACTION_SET_NULL());
return this;
}

ActionConfig* ActionConfig::setMediaString(twrap_media_type_t type, const char* key, const char* value)
{
tmedia_type_t media_type = twrap_get_native_media_type(type);
tsip_action_set(m_pHandle,
TSIP_ACTION_SET_MEDIA(
TMEDIA_SESSION_SET_STR(media_type, key, value),
TMEDIA_SESSION_SET_NULL()),
TSIP_ACTION_SET_NULL());

return this;
}

ActionConfig* ActionConfig::setMediaInt(twrap_media_type_t type, const char* key, int value)
{
tmedia_type_t media_type = twrap_get_native_media_type(type);
tsip_action_set(m_pHandle,
TSIP_ACTION_SET_MEDIA(
TMEDIA_SESSION_SET_INT32(media_type, key, value),
TMEDIA_SESSION_SET_NULL()),
TSIP_ACTION_SET_NULL());

return this;
}
52 changes: 52 additions & 0 deletions tinywrap/ActionConfig.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* Copyright (C) 2010-2011 Mamadou Diop.
*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*/
#ifndef TINYWRAP_ACTIONCONFIG_H
#define TINYWRAP_ACTIONCONFIG_H

#include "tinyWRAP_config.h"

#include "tinysip.h"
#include "Common.h"

class TINYWRAP_API ActionConfig
{
public:
ActionConfig();
virtual ~ActionConfig();

bool addHeader(const char* name, const char* value);
bool addPayload(const void* payload, unsigned len);
bool setActiveMedia(twrap_media_type_t type);

ActionConfig* setResponseLine(short code, const char* phrase);
ActionConfig* setMediaString(twrap_media_type_t type, const char* key, const char* value);
ActionConfig* setMediaInt(twrap_media_type_t type, const char* key, int value);

private:
tsip_action_handle_t* m_pHandle;

#if !defined(SWIG)
public:
const inline tsip_action_handle_t* getHandle()const{
return m_pHandle;
}
#endif
};


#endif /* TINYWRAP_ACTIONCONFIG_H */
73 changes: 73 additions & 0 deletions tinywrap/AudioResampler.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
*/

/**@file AudioResampler.cxx
* @brief Audio resampler
*
* @author Mamadou Diop <diopmamadou(at)doubango.org>
*/
#include "AudioResampler.h"

#include "tinymedia/tmedia_resampler.h"

#include "tsk_debug.h"

AudioResampler::AudioResampler(uint32_t nInFreq, uint32_t nOutFreq, uint32_t nFrameDuration, uint32_t nChannels, uint32_t nQuality):
m_nOutFreq(nOutFreq),
m_nInFreq(nInFreq),
m_nFrameDuration(nFrameDuration),
m_nChannels(nChannels),
m_nQuality(nQuality)
{
if ((m_pWrappedResampler = tmedia_resampler_create())) {
int ret;
if ((ret = tmedia_resampler_open(m_pWrappedResampler, nInFreq, nOutFreq, nFrameDuration, nChannels, nChannels, m_nQuality, 16))){
TSK_DEBUG_ERROR("Failed to open audio resampler (%d)", ret);
TSK_OBJECT_SAFE_FREE(m_pWrappedResampler);
}
}
else {
TSK_DEBUG_ERROR("No audio resampler could be found. Did you forget to call tdav_init()?");
}
}

AudioResampler::~AudioResampler()
{
TSK_OBJECT_SAFE_FREE(m_pWrappedResampler);
}

uint32_t AudioResampler::process(const void* pInData, uint32_t nInSizeInBytes, void* pOutData, uint32_t nOutSizeInBytes)
{
if(!m_pWrappedResampler){
TSK_DEBUG_ERROR("Embedded resampler is invalid");
return 0;
}
if(nInSizeInBytes < getInputRequiredSizeInShort()/2){
TSK_DEBUG_ERROR("Input buffer is too short");
return 0;
}
if(nOutSizeInBytes < getOutputRequiredSizeInShort()/2){
TSK_DEBUG_ERROR("Output buffer is too short");
return 0;
}
return 2*tmedia_resampler_process(m_pWrappedResampler, (uint16_t*)pInData, nInSizeInBytes/2, (uint16_t*)pOutData, nOutSizeInBytes/2);
}
56 changes: 56 additions & 0 deletions tinywrap/AudioResampler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
*/

/**@file AudioResampler.h
* @brief Audio resampler
*
* @author Mamadou Diop <diopmamadou(at)doubango.org>
*/
#ifndef TINYWRAP_AUDIO_RESAMPLER_H
#define TINYWRAP_AUDIO_RESAMPLER_H

#include "tinyWRAP_config.h"
#include "tsk_common.h"

class AudioResampler
{
public:
AudioResampler(uint32_t nInFreq, uint32_t nOutFreq, uint32_t nFrameDuration, uint32_t nChannels, uint32_t nQuality);
~AudioResampler();

public:
inline bool isValid(){ return (m_pWrappedResampler != tsk_null); }
inline uint32_t getOutputRequiredSizeInShort(){ return (m_nOutFreq * m_nFrameDuration)/1000; }
inline uint32_t getInputRequiredSizeInShort(){ return (m_nInFreq * m_nFrameDuration)/1000; }
uint32_t process(const void* pInData, uint32_t nInSizeInBytes, void* pOutData, uint32_t nOutSizeInBytes);

private:
struct tmedia_resampler_s* m_pWrappedResampler;
uint32_t m_nOutFreq;
uint32_t m_nInFreq;
uint32_t m_nFrameDuration;
uint32_t m_nChannels;
uint32_t m_nQuality;
};


#endif /* TINYWRAP_AUDIO_RESAMPLER_H */
98 changes: 98 additions & 0 deletions tinywrap/Common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* Copyright (C) 2010-2011 Mamadou Diop.
*
* Contact: Mamadou Diop <diopmamadou(at)doubango.org>
*
* This file is part of Open Source Doubango Framework.
*
* DOUBANGO is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* DOUBANGO is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with DOUBANGO.
*
*/
#ifndef TINYWRAP_COMMON_H
#define TINYWRAP_COMMON_H

#include "tinyWRAP_config.h"

#if ANDROID
# define dyn_cast static_cast
# define __JNIENV JNIEnv
#else
# define dyn_cast dynamic_cast
# define __JNIENV void
#endif

typedef enum twrap_media_type_e
{
// because of Java don't use OR
twrap_media_none = 0x00,

twrap_media_audio = 0x01, // (0x01 << 0)
twrap_media_video = 0x02, // (0x01 << 1)
twrap_media_msrp = 0x04, // (0x01 << 2)
twrap_media_t140 = 0x08, // (0x01 << 3)
twrap_media_bfcp = 0x10, // (0x01 << 4)
twrap_media_bfcp_audio = 0x30, // (0x01 << 5) | twrap_media_bfcp;
twrap_media_bfcp_video = 0x50, // (0x01 << 6) | twrap_media_bfcp;

twrap_media_audiovideo = 0x03, /* @deprecated */
twrap_media_audio_video = twrap_media_audiovideo,
}
twrap_media_type_t;

#if !defined(SWIG)
#include "tinymedia/tmedia_common.h"

struct media_type_bind_s
{
twrap_media_type_t twrap;
tmedia_type_t tnative;
};
static const struct media_type_bind_s __media_type_binds[] =
{
{ twrap_media_msrp, tmedia_msrp },
{ twrap_media_audio , tmedia_audio },
{ twrap_media_video, tmedia_video },
{ twrap_media_audio_video, (tmedia_type_t)(tmedia_audio | tmedia_video) },
{ twrap_media_t140, tmedia_t140 },
{ twrap_media_bfcp, tmedia_bfcp },
{ twrap_media_bfcp_audio, tmedia_bfcp_audio },
{ twrap_media_bfcp_video, tmedia_bfcp_video },
};
static const tsk_size_t __media_type_binds_count = sizeof(__media_type_binds)/sizeof(__media_type_binds[0]);
static tmedia_type_t twrap_get_native_media_type(twrap_media_type_t type)
{
tsk_size_t u;
tmedia_type_t t = tmedia_none;
for (u = 0; u < __media_type_binds_count; ++u) {
if ((__media_type_binds[u].twrap & type) == __media_type_binds[u].twrap) {
t = (tmedia_type_t)(t | __media_type_binds[u].tnative);
}
}
return t;
}
static twrap_media_type_t twrap_get_wrapped_media_type(tmedia_type_t type)
{
twrap_media_type_t t = twrap_media_none;
tsk_size_t u;
for (u = 0; u < __media_type_binds_count; ++u) {
if ((__media_type_binds[u].tnative & type) == __media_type_binds[u].tnative) {
t = (twrap_media_type_t)(t | __media_type_binds[u].twrap);
}
}
return t;
}
#endif

#endif /* TINYWRAP_COMMON_H */

Loading