mirror of
https://github.com/morgan9e/FreeRDP
synced 2026-04-15 00:44:19 +09:00
[channel,audin] move common code to server channel
* manage channel related callbacks with default implementations * use dynamic logger for server audin channel
This commit is contained in:
@@ -33,109 +33,6 @@
|
||||
#define TAG SERVER_TAG("sample")
|
||||
|
||||
#if defined(CHANNEL_AUDIN_SERVER)
|
||||
static UINT sf_peer_audin_receive_version(audin_server_context* audin, const SNDIN_VERSION* version)
|
||||
{
|
||||
testPeerContext* context;
|
||||
SNDIN_FORMATS formats = { 0 };
|
||||
|
||||
WINPR_ASSERT(audin);
|
||||
WINPR_ASSERT(version);
|
||||
|
||||
context = audin->userdata;
|
||||
WINPR_ASSERT(context);
|
||||
|
||||
if (version->Version == 0)
|
||||
{
|
||||
WLog_ERR(TAG, "Received invalid AUDIO_INPUT version from client");
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
WLog_DBG(TAG, "AUDIO_INPUT version of client: %u", version->Version);
|
||||
|
||||
formats.NumFormats = context->audin_n_server_formats;
|
||||
formats.SoundFormats = context->audin_server_formats;
|
||||
|
||||
return audin->SendFormats(audin, &formats);
|
||||
}
|
||||
|
||||
static UINT send_open(audin_server_context* audin)
|
||||
{
|
||||
testPeerContext* context;
|
||||
SNDIN_OPEN open = { 0 };
|
||||
|
||||
WINPR_ASSERT(audin);
|
||||
|
||||
context = audin->userdata;
|
||||
WINPR_ASSERT(context);
|
||||
|
||||
open.FramesPerPacket = 441;
|
||||
open.initialFormat = context->audin_client_format_idx;
|
||||
open.captureFormat.wFormatTag = WAVE_FORMAT_PCM;
|
||||
open.captureFormat.nChannels = 2;
|
||||
open.captureFormat.nSamplesPerSec = 44100;
|
||||
open.captureFormat.nAvgBytesPerSec = 44100 * 2 * 2;
|
||||
open.captureFormat.nBlockAlign = 4;
|
||||
open.captureFormat.wBitsPerSample = 16;
|
||||
|
||||
return audin->SendOpen(audin, &open);
|
||||
}
|
||||
|
||||
static UINT sf_peer_audin_receive_formats(audin_server_context* audin, const SNDIN_FORMATS* formats)
|
||||
{
|
||||
testPeerContext* context;
|
||||
|
||||
WINPR_ASSERT(audin);
|
||||
WINPR_ASSERT(formats);
|
||||
|
||||
context = audin->userdata;
|
||||
WINPR_ASSERT(context);
|
||||
|
||||
if (context->audin_negotiated_format)
|
||||
{
|
||||
WLog_ERR(TAG, "Received client formats, but negotiation was already done");
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < context->audin_n_server_formats; ++i)
|
||||
{
|
||||
for (UINT32 j = 0; j < formats->NumFormats; ++j)
|
||||
{
|
||||
if (audio_format_compatible(&context->audin_server_formats[i],
|
||||
&formats->SoundFormats[j]))
|
||||
{
|
||||
context->audin_negotiated_format = &context->audin_server_formats[i];
|
||||
context->audin_client_format_idx = i;
|
||||
return send_open(audin);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WLog_ERR(TAG, "Could not agree on a audio format with the server");
|
||||
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
static UINT sf_peer_audin_open_reply(audin_server_context* audin,
|
||||
const SNDIN_OPEN_REPLY* open_reply)
|
||||
{
|
||||
WINPR_ASSERT(audin);
|
||||
WINPR_ASSERT(open_reply);
|
||||
|
||||
/* TODO: Implement failure handling */
|
||||
WLog_DBG(TAG, "Open Reply PDU: Result: %i", open_reply->Result);
|
||||
return CHANNEL_RC_OK;
|
||||
}
|
||||
|
||||
static UINT sf_peer_audin_incoming_data(audin_server_context* audin,
|
||||
const SNDIN_DATA_INCOMING* data_incoming)
|
||||
{
|
||||
WINPR_ASSERT(audin);
|
||||
WINPR_ASSERT(data_incoming);
|
||||
|
||||
/* TODO: Implement bandwidth measure of clients uplink */
|
||||
WLog_DBG(TAG, "Received Incoming Data PDU");
|
||||
return CHANNEL_RC_OK;
|
||||
}
|
||||
|
||||
static UINT sf_peer_audin_data(audin_server_context* audin, const SNDIN_DATA* data)
|
||||
{
|
||||
@@ -148,30 +45,9 @@ static UINT sf_peer_audin_data(audin_server_context* audin, const SNDIN_DATA* da
|
||||
return CHANNEL_RC_OK;
|
||||
}
|
||||
|
||||
static UINT sf_peer_audin_receive_format_change(audin_server_context* audin,
|
||||
const SNDIN_FORMATCHANGE* format_change)
|
||||
{
|
||||
testPeerContext* context;
|
||||
|
||||
WINPR_ASSERT(audin);
|
||||
WINPR_ASSERT(format_change);
|
||||
|
||||
context = audin->userdata;
|
||||
WINPR_ASSERT(context);
|
||||
|
||||
if (format_change->NewFormat != context->audin_client_format_idx)
|
||||
{
|
||||
WLog_ERR(TAG, "NewFormat in FormatChange differs from requested format");
|
||||
return ERROR_INVALID_DATA;
|
||||
}
|
||||
|
||||
WLog_DBG(TAG, "Received Format Change PDU: %u", format_change->NewFormat);
|
||||
|
||||
return CHANNEL_RC_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
void sf_peer_audin_init(testPeerContext* context)
|
||||
BOOL sf_peer_audin_init(testPeerContext* context)
|
||||
{
|
||||
WINPR_ASSERT(context);
|
||||
#if defined(CHANNEL_AUDIN_SERVER)
|
||||
@@ -181,14 +57,11 @@ void sf_peer_audin_init(testPeerContext* context)
|
||||
context->audin->rdpcontext = &context->_p;
|
||||
context->audin->userdata = context;
|
||||
|
||||
context->audin->ReceiveVersion = sf_peer_audin_receive_version;
|
||||
context->audin->ReceiveFormats = sf_peer_audin_receive_formats;
|
||||
context->audin->OpenReply = sf_peer_audin_open_reply;
|
||||
context->audin->IncomingData = sf_peer_audin_incoming_data;
|
||||
context->audin->Data = sf_peer_audin_data;
|
||||
context->audin->ReceiveFormatChange = sf_peer_audin_receive_format_change;
|
||||
|
||||
context->audin_n_server_formats = server_audin_get_formats(&context->audin_server_formats);
|
||||
return audin_server_set_formats(context->audin, -1, NULL);
|
||||
#else
|
||||
return TRUE;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -233,12 +106,7 @@ void sf_peer_audin_uninit(testPeerContext* context)
|
||||
WINPR_ASSERT(context);
|
||||
|
||||
#if defined(CHANNEL_AUDIN_SERVER)
|
||||
if (context->audin)
|
||||
{
|
||||
audio_formats_free(context->audin_server_formats, context->audin_n_server_formats);
|
||||
context->audin_server_formats = NULL;
|
||||
audin_server_context_free(context->audin);
|
||||
context->audin = NULL;
|
||||
}
|
||||
audin_server_context_free(context->audin);
|
||||
context->audin = NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#include "sfreerdp.h"
|
||||
|
||||
void sf_peer_audin_init(testPeerContext* context);
|
||||
BOOL sf_peer_audin_init(testPeerContext* context);
|
||||
void sf_peer_audin_uninit(testPeerContext* context);
|
||||
|
||||
BOOL sf_peer_audin_running(testPeerContext* context);
|
||||
|
||||
@@ -60,10 +60,6 @@ struct test_peer_context
|
||||
HANDLE debug_channel_thread;
|
||||
#if defined(CHANNEL_AUDIN_SERVER)
|
||||
audin_server_context* audin;
|
||||
AUDIO_FORMAT* audin_server_formats;
|
||||
size_t audin_n_server_formats;
|
||||
AUDIO_FORMAT* audin_negotiated_format;
|
||||
UINT32 audin_client_format_idx;
|
||||
#endif
|
||||
BOOL audin_open;
|
||||
#if defined(CHANNEL_AINPUT_SERVER)
|
||||
|
||||
Reference in New Issue
Block a user