This commit is contained in:
watrabi
2025-09-18 17:55:52 -04:00
commit 977f1ff4b8
15030 changed files with 17324420 additions and 0 deletions
@@ -0,0 +1,103 @@
//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved
#include "pch.h"
#include "AudioDeviceInfo.h"
#if TV_API
namespace Microsoft {
namespace Xbox {
namespace GameChat {
ComStyleRemoteAudioDeviceInfo::ComStyleRemoteAudioDeviceInfo() :
m_type( Awxs::AudioDeviceType_Capture ),
m_sharing( Awxs::AudioDeviceSharing_Exclusive )
{
}
ComStyleRemoteAudioDeviceInfo::~ComStyleRemoteAudioDeviceInfo()
{
}
HRESULT ComStyleRemoteAudioDeviceInfo::RuntimeClassInitialize(
const HSTRING id,
const Awxs::AudioDeviceType type,
const Awxs::AudioDeviceSharing sharing,
const Awxs::AudioDeviceCategory category
)
{
HRESULT hr = E_UNEXPECTED;
CHECKHR_EXIT( m_id.Set( id ) );
m_type = type;
m_sharing = sharing;
m_category = category;
exit:
return hr;
}
HRESULT ComStyleRemoteAudioDeviceInfo::get_Id( _Out_ HSTRING* pOut )
{
if ( pOut == nullptr )
{
return E_POINTER;
}
return WindowsDuplicateString( m_id.Get(), pOut );
}
HRESULT ComStyleRemoteAudioDeviceInfo::get_DeviceType( _Out_ Awxs::AudioDeviceType* pOut )
{
if ( pOut == nullptr )
{
return E_POINTER;
}
*pOut = m_type;
return S_OK;
}
HRESULT ComStyleRemoteAudioDeviceInfo::get_Sharing( _Out_ Awxs::AudioDeviceSharing* pOut )
{
if ( pOut == nullptr )
{
return E_POINTER;
}
*pOut = m_sharing;
return S_OK;
}
HRESULT ComStyleRemoteAudioDeviceInfo::get_DeviceCategory( _Out_ Awxs::AudioDeviceCategory* pOut )
{
if ( pOut == nullptr )
{
return E_POINTER;
}
*pOut = m_category;
return S_OK;
}
HRESULT ComStyleRemoteAudioDeviceInfo::get_Volume( _Out_ float* /* pOut */ )
{
return E_UNEXPECTED;
}
HRESULT ComStyleRemoteAudioDeviceInfo::get_Muted( _Out_ boolean* /* pOut */ )
{
return E_UNEXPECTED;
}
HRESULT ComStyleRemoteAudioDeviceInfo::get_IsMicrophoneMuted( _Out_ boolean* /* pOut */ )
{
return E_NOTIMPL;
}
}}}
#endif
@@ -0,0 +1,55 @@
//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved
#pragma once
#include "ChatUserSerializationCommon.h"
#if TV_API
namespace Microsoft {
namespace Xbox {
namespace GameChat {
/*
===============================================================================
This class is used to represent a remote audio device
IMPORTANT
1. Implements IAudioDevice
2. We create remote audio device for remote user, based on network data
===============================================================================
*/
class ComStyleRemoteAudioDeviceInfo : public Mwrl::RuntimeClass<Awxs::IAudioDeviceInfo, Mwrl::FtmBase>
{
public:
ComStyleRemoteAudioDeviceInfo();
virtual ~ComStyleRemoteAudioDeviceInfo();
HRESULT RuntimeClassInitialize( const HSTRING id,
const Awxs::AudioDeviceType type,
const Awxs::AudioDeviceSharing sharing,
const Awxs::AudioDeviceCategory category );
// IAudioDevice
HRESULT get_Id( _Out_ HSTRING* pOut );
HRESULT get_DeviceType( _Out_ Awxs::AudioDeviceType* pOut );
HRESULT get_Sharing( _Out_ Awxs::AudioDeviceSharing* pOut );
HRESULT get_DeviceCategory( _Out_ Awxs::AudioDeviceCategory* pOut );
HRESULT get_Volume( _Out_ float* /* pOut */ );
HRESULT get_Muted( _Out_ boolean* /* pOut */ );
HRESULT get_IsMicrophoneMuted( _Out_ boolean* /* pOut */ );
private:
Mwrlw::HString m_id;
Awxs::AudioDeviceType m_type;
Awxs::AudioDeviceSharing m_sharing;
Awxs::AudioDeviceCategory m_category;
};
}}}
#endif
@@ -0,0 +1,59 @@
//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved
#include "pch.h"
#include "AudioDevices.h"
#if TV_API
namespace Microsoft {
namespace Xbox {
namespace GameChat {
ComStyleRemoteAudioDeviceInfos::ComStyleRemoteAudioDeviceInfos()
{
}
ComStyleRemoteAudioDeviceInfos::~ComStyleRemoteAudioDeviceInfos()
{
}
void ComStyleRemoteAudioDeviceInfos::PushBack(
const Mwrl::ComPtr<Awxs::IAudioDeviceInfo>& spIAudioDevice
)
{
m_vector.push_back( spIAudioDevice );
}
HRESULT ComStyleRemoteAudioDeviceInfos::GetAt( UINT index, Awxs::IAudioDeviceInfo** ppOut )
{
if ( ppOut == nullptr )
{
return E_POINTER;
}
return m_vector.at( index ).CopyTo( ppOut );
}
HRESULT ComStyleRemoteAudioDeviceInfos::get_Size( UINT* pOut )
{
if ( pOut == nullptr )
{
return E_POINTER;
}
*pOut = ( UINT )m_vector.size();
return S_OK;
}
HRESULT ComStyleRemoteAudioDeviceInfos::IndexOf( Awxs::IAudioDeviceInfo* /* pIAudioDevice */, UINT* /* pOutIndex */, boolean* /* pOutFound */ )
{
return E_UNEXPECTED;
}
}}}
#endif
@@ -0,0 +1,43 @@
//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved
#pragma once
#include "ChatUserSerializationCommon.h"
#if TV_API
namespace Microsoft {
namespace Xbox {
namespace GameChat {
/*
====================================================================
This class is used to represent a vector of Mwrl::ComPtr<Awxs::IAudioDeviceInfo>
IMPORTANT
Implements IAudioDevices
====================================================================
*/
class ComStyleRemoteAudioDeviceInfos : public Mwrl::RuntimeClass<Awfc::IVectorView<Awxs::IAudioDeviceInfo*>,Mwrl::FtmBase>
{
public:
ComStyleRemoteAudioDeviceInfos();
virtual ~ComStyleRemoteAudioDeviceInfos();
void PushBack( const Mwrl::ComPtr<Awxs::IAudioDeviceInfo>& spIAudioDevice );
// IAudioDevices
HRESULT GetAt( UINT index, Awxs::IAudioDeviceInfo** ppOut );
HRESULT get_Size( UINT* pOut );
HRESULT IndexOf( Awxs::IAudioDeviceInfo* /* pIAudioDevice */, UINT* /* pOutIndex */, boolean* /* pOutFound */ );
private:
std::vector<Mwrl::ComPtr<Awxs::IAudioDeviceInfo>> m_vector;
};
}}}
#endif
@@ -0,0 +1,332 @@
//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved
#include "pch.h"
#include "ChatPacker.h"
#if TV_API
namespace Microsoft {
namespace Xbox {
namespace GameChat {
Packer::Packer()
{
}
Packer::~Packer()
{
}
HRESULT Packer::PackBegin()
{
HRESULT hr = E_UNEXPECTED;
CHECKHR_EXIT( m_buffer.Cleanup() );
exit:
return hr;
}
// Returns the packed data, if there is no packed data, the behavior is E_UNEXPECTED
HRESULT Packer::PackEnd(
_Outptr_ BYTE** ppOut,
_Out_ UINT* pOut
)
{
HRESULT hr = E_UNEXPECTED;
CHECKHR_EXIT( m_buffer.Length( pOut ) );
CHECKHR_EXIT( m_buffer.ReadFast( ppOut, *pOut ) );
exit:
return hr;
}
//----------------------------------------------------------------------------------------
// Pack functions
// 1. Pack primitive types
// a. No input data validation
// b. Input data validation
// 2. Pack complex types
// a. Input data validation( Not handled in sub-pack functions )
// b. Group of sub-pack functions
//----------------------------------------------------------------------------------------
HRESULT Packer::PackBYTE(
_In_ const BYTE data
)
{
HRESULT hr = E_UNEXPECTED;
// No input data validation
CHECKHR_EXIT( m_buffer.Write( &data, sizeof( BYTE ) ) );
exit:
return hr;
}
HRESULT Packer::PackUSHORT(
_In_ const USHORT data
)
{
HRESULT hr = E_UNEXPECTED;
// No input data validation
CHECKHR_EXIT( m_buffer.Write( (BYTE*)&data, sizeof( USHORT ) ) );
exit:
return hr;
}
HRESULT Packer::PackUINT(
_In_ const UINT data
)
{
HRESULT hr = E_UNEXPECTED;
// No input data validation
CHECKHR_EXIT( m_buffer.Write( ( BYTE* )&data, sizeof( UINT ) ) );
exit:
return hr;
}
HRESULT Packer::PackBytes(
_In_reads_bytes_(size) const BYTE* const pData,
_In_ const UINT size
)
{
HRESULT hr = S_FALSE; // if size if 0 or no data
// Input data validation
if ( pData && size ) {
CHECKHR_EXIT( m_buffer.Write( pData, size ) );
}
exit:
return hr;
}
HRESULT Packer::PackString(
_In_ const Mwrlw::HString& data
)
{
HRESULT hr = E_UNEXPECTED;
UINT strLen = 0;
UINT size = 0;
// Input data validation
if ( data != nullptr )
{
const wchar_t* pStr = data.GetRawBuffer( &strLen );
size = strLen * sizeof( wchar_t );
std::string pUtf8Str;
ConvertWideToUtf8(pStr, &pUtf8Str);
CHECKHR_EXIT( PackUINT( (UINT)pUtf8Str.size() ) );
CHECKHR_EXIT( PackBytes( ( BYTE* )pUtf8Str.data(), (UINT)pUtf8Str.size() ) );
}
exit:
return hr;
}
HRESULT Packer::PackBuffer(
_In_ const Mwrl::ComPtr<Awss::IBuffer>& spData )
{
HRESULT hr = E_UNEXPECTED;
UINT size = 0;
Mwrl::ComPtr<Wss::IBufferByteAccess> spIBufferByteAccess;
BYTE* pBytes = nullptr;
// Input data validation
if ( spData ) {
CHECKHR_EXIT( spData->get_Length( &size ) );
CHECKHR_EXIT( spData.As( &spIBufferByteAccess ) );
CHECKHR_EXIT( spIBufferByteAccess->Buffer( &pBytes ) );
CHECKHR_EXIT( PackUINT( size ) );
CHECKHR_EXIT( PackBytes( pBytes, size ) );
}
exit:
return hr;
}
//----------------------------------------------------------------------------------------
// IMPORTANT
// 1. When we pack an audio device, it is a "local" audio device from a "local" user
// 2. Id, type and sharing, use BYTE to represent enum
//----------------------------------------------------------------------------------------
HRESULT Packer::PackAudioDevice(
_In_ const Mwrl::ComPtr<Awxs::IAudioDeviceInfo>& spData,
_In_ AudioDeviceIDMapper^ audioDeviceIDMapper
)
{
HRESULT hr = E_UNEXPECTED;
Mwrlw::HString id;
Awxs::AudioDeviceType type;
Awxs::AudioDeviceSharing sharing;
Awxs::AudioDeviceCategory category;
// Input data validation
if ( spData )
{
CHECKHR_EXIT( spData->get_Id( id.GetAddressOf() ) );
CHECKHR_EXIT( spData->get_DeviceType( &type ) );
CHECKHR_EXIT( spData->get_Sharing( &sharing ) );
CHECKHR_EXIT( spData->get_DeviceCategory( &category ) );
// Save and send a deviceId
UINT length = 0;
Platform::String^ strId = ref new Platform::String( id.GetRawBuffer(&length) );
DEVICE_ID deviceId = audioDeviceIDMapper->GetLocalDeviceID(strId);
CHECKHR_EXIT( PackBYTE( deviceId ) );
uint8 isKinect = (wcsstr(strId->Data(), L"postmec") != nullptr);
CHECKHR_EXIT( PackBYTE( ( BYTE )isKinect ) );
CHECKHR_EXIT( PackBYTE( ( BYTE )type ) );
CHECKHR_EXIT( PackBYTE( ( BYTE )sharing ) );
CHECKHR_EXIT( PackBYTE( ( BYTE )category ) );
#ifdef DEBUG_REMOTE_AUDIO_DEVICES
WCHAR text[1024] = {0};
swprintf_s(
text, ARRAYSIZE(text),
L"Packer::PackAudioDevice: strId = %s, deviceId = %d, isKinect = %d\r\n",
strId->Data(),
deviceId,
isKinect
);
OutputDebugString( text );
#endif
}
exit:
return hr;
}
//----------------------------------------------------------------------------------------
// IMPORTANT
// 1. When we pack audio devices, it is "local" audio devices from a "local" user
//----------------------------------------------------------------------------------------
HRESULT Packer::PackAudioDevices(
_In_ const Mwrl::ComPtr<Awfc::IVectorView<Awxs::IAudioDeviceInfo*>>& spData,
_In_ AudioDeviceIDMapper^ audioDeviceIDMapper
)
{
HRESULT hr = E_UNEXPECTED;
UINT size = 0;
// Input data validation
if ( spData ) {
// Pack size
CHECKHR_EXIT( spData->get_Size( &size ) );
CHECKHR_EXIT( PackUINT( size ) );
// Pack each Mwrl::ComPtr<Awxs::IAudioDeviceInfo>
for ( UINT i = 0; i < size; i++ ) {
Mwrl::ComPtr<Awxs::IAudioDeviceInfo> spIAudioDevice;
CHECKHR_EXIT( spData->GetAt( i, &spIAudioDevice ) );
CHECKHR_EXIT( PackAudioDevice( spIAudioDevice, audioDeviceIDMapper ) );
}
}
exit:
return hr;
}
//----------------------------------------------------------------------------------------
// IMPORTANT
// 1. When we pack an user, it is "local" user
//----------------------------------------------------------------------------------------
HRESULT Packer::PackUser(
_In_ const Mwrl::ComPtr<Awxs::IUser>& spData,
_In_ AudioDeviceIDMapper^ audioDeviceIDMapper
)
{
HRESULT hr = E_UNEXPECTED;
boolean isGuest = false;
Mwrlw::HString xuid;
Mwrl::ComPtr<Awfc::IVectorView<Awxs::IAudioDeviceInfo*>> spIAudioDevices;
// Input data validation
if ( spData ) {
CHECKHR_EXIT( spData->get_IsGuest( &isGuest ) );
CHECKHR_EXIT( spData->get_XboxUserId( xuid.GetAddressOf() ) );
CHECKHR_EXIT( spData->get_AudioDevices( &spIAudioDevices ) );
CHECKHR_EXIT( PackBYTE( isGuest ) );
CHECKHR_EXIT( PackString( xuid ) );
CHECKHR_EXIT( PackAudioDevices( spIAudioDevices, audioDeviceIDMapper ) );
}
exit:
return hr;
}
HRESULT Packer::ConvertWideToUtf8(
_In_ PCWSTR wideStr,
_Inout_ std::string* pUtf8Str
)
{
if ( !pUtf8Str )
{
return E_POINTER;
}
HRESULT hr = S_OK;
try
{
pUtf8Str->clear();
if (wideStr == nullptr || wideStr[0] == L'\0')
return S_OK;
int wideStrLen = (int)wcslen(wideStr) + 1; // WideCharToMultiByte expects the NULL terminator to be counted
// calculate the required size
int nBytes = WideCharToMultiByte(
CP_UTF8,
0,
wideStr,
wideStrLen,
nullptr,
0,
nullptr,
nullptr);
if(nBytes == 0)
{
hr = HRESULT_FROM_WIN32(GetLastError());
goto Exit;
}
std::unique_ptr<char[]> utf8Buffer(new char[nBytes]);
if(WideCharToMultiByte(
CP_UTF8,
0,
wideStr,
wideStrLen,
utf8Buffer.get(),
nBytes,
nullptr,
nullptr) == 0)
{
hr = HRESULT_FROM_WIN32(GetLastError());
goto Exit;
}
pUtf8Str->assign(utf8Buffer.get());
hr = S_OK;
goto Exit;
}
catch (std::bad_alloc)
{
hr = E_OUTOFMEMORY;
goto Exit;
}
Exit:
return hr;
}
}}}
#endif
@@ -0,0 +1,81 @@
//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved
#pragma once
#include "ChatUserSerializationCommon.h"
#include "ChatReadWriteBuffer.h"
#include "AudioDeviceIDMapper.h"
#if TV_API
namespace Microsoft {
namespace Xbox {
namespace GameChat {
// Class that used to perform data serialization
class Packer
{
public:
Packer();
~Packer();
HRESULT PackBegin();
HRESULT PackEnd(
_Outptr_ BYTE** ppOut,
_Out_ UINT* pOut
);
HRESULT PackBYTE(
_In_ const BYTE data
);
HRESULT PackUSHORT(
_In_ const USHORT data
);
HRESULT PackUINT(
_In_ const UINT data
);
HRESULT PackBytes(
_In_reads_bytes_(size) const BYTE* const pData,
_In_ const UINT size
);
HRESULT PackString(
_In_ const Mwrlw::HString& data
);
HRESULT PackBuffer(
_In_ const Mwrl::ComPtr<Awss::IBuffer>& spData
);
HRESULT PackAudioDevice(
_In_ const Mwrl::ComPtr<Awxs::IAudioDeviceInfo>& spData,
_In_ AudioDeviceIDMapper^ audioDeviceIDMapper
);
HRESULT PackAudioDevices(
_In_ const Mwrl::ComPtr<Awfc::IVectorView<Awxs::IAudioDeviceInfo*>>& spData,
_In_ AudioDeviceIDMapper^ audioDeviceIDMapper
);
HRESULT PackUser(
_In_ const Mwrl::ComPtr<Awxs::IUser>& spData,
_In_ AudioDeviceIDMapper^ audioDeviceIDMapper
);
private:
ReadWriteBuffer m_buffer;
static HRESULT ConvertWideToUtf8( _In_ PCWSTR wideStr, _Inout_ std::string* pUtf8Str);
};
}}}
#endif
@@ -0,0 +1,107 @@
//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved
#include "pch.h"
#include "ChatReadWriteBuffer.h"
#if TV_API
namespace Microsoft {
namespace Xbox {
namespace GameChat {
ReadWriteBuffer::ReadWriteBuffer( const unsigned int capa ) :
m_pData( nullptr ),
m_capacity( 0 ),
m_isCreated( false ),
m_pR( nullptr ),
m_pW( nullptr )
{
if ( capa )
{
m_pData.reset(new BYTE[capa]);
if ( m_pData )
{
m_capacity = capa;
m_isCreated = true;
Cleanup();
}
}
}
ReadWriteBuffer::~ReadWriteBuffer()
{
}
HRESULT ReadWriteBuffer::Cleanup()
{
if ( m_isCreated )
{
m_pR = m_pW = m_pData.get();
return S_OK;
}
return E_UNEXPECTED;
}
HRESULT ReadWriteBuffer::Length( unsigned int* pOut ) const
{
if ( m_isCreated )
{
*pOut = ( unsigned int )( m_pW - m_pR );
return S_OK;
}
return E_UNEXPECTED;
}
// IMPORTANT
// 1. When m_pR == m_pW, m_pR is pointing to garbage data, or it is out of boundary
// 2. When m_pW == ( m_pData + m_capacity ), m_pW is out of boundary
// We treat size zero as unexpected behaviors when performing read and write
// ReadFast does not copy memory out, just return the start address
HRESULT ReadWriteBuffer::ReadFast( BYTE** ppOut, const unsigned int size )
{
if ( size != 0 && IsAbleToRead( size ) )
{
*ppOut = m_pR;
m_pR += size;
return S_OK;
}
return E_UNEXPECTED;
}
HRESULT ReadWriteBuffer::Write( const BYTE* const pData, const unsigned int size )
{
if ( size != 0 && IsAbleToWrite( size ) )
{
if ( !memcpy_s( m_pW, size, pData, size ) )
{
m_pW += size;
return S_OK;
}
}
return E_UNEXPECTED;
}
bool ReadWriteBuffer::IsAbleToRead( const unsigned int size ) const {
if ( m_isCreated ) {
return ( m_pR + size ) <= ( m_pW );
}
return false;
}
bool ReadWriteBuffer::IsAbleToWrite( const unsigned int size ) const
{
if ( m_isCreated )
{
return ( m_pW + size ) <= ( m_pData.get() + m_capacity );
}
return false;
}
}}}
#endif
@@ -0,0 +1,43 @@
//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved
#pragma once
#include "ChatUserSerializationCommon.h"
#if TV_API
namespace Microsoft {
namespace Xbox {
namespace GameChat {
#define DEFAULT_CAPACITY 8192
// Fixed capacity buffer with a read and a write pointer
class ReadWriteBuffer
{
public:
ReadWriteBuffer( const unsigned int capa = DEFAULT_CAPACITY );
~ReadWriteBuffer();
HRESULT Cleanup();
HRESULT Length( unsigned int* pOut ) const;
HRESULT ReadFast( BYTE** ppOut, const unsigned int size );
HRESULT Write( const BYTE* const pData, const unsigned int size );
private:
std::unique_ptr<BYTE[]> m_pData;
unsigned int m_capacity;
bool m_isCreated;
BYTE* m_pR;
BYTE* m_pW;
bool IsAbleToRead( const unsigned int size ) const;
bool IsAbleToWrite( const unsigned int size ) const;
};
}}}
#endif
@@ -0,0 +1,279 @@
//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved
#include "pch.h"
#include "AudioDeviceIDMapper.h"
#include "AudioDeviceInfo.h"
#include "AudioDevices.h"
#include "RemoteUser.h"
#include "ChatUnpacker.h"
#if TV_API
namespace Microsoft {
namespace Xbox {
namespace GameChat {
Unpacker::Unpacker()
{
}
Unpacker::~Unpacker()
{
}
// Cleanup buffer and feed it with data
HRESULT Unpacker::UnpackBegin(
_In_reads_bytes_(size) const BYTE* const pData,
_In_ const UINT size )
{
HRESULT hr = E_UNEXPECTED;
CHECKHR_EXIT( m_buffer.Cleanup() );
CHECKHR_EXIT( m_buffer.Write( pData, size ) );
exit:
return hr;
}
HRESULT Unpacker::UnpackEnd() const
{
return S_OK;
}
//----------------------------------------------------------------------------------------
// Unpack functions
// 1. Unpack primitive types
// a. No input data validation
// b. Input data validation
// 2. Unpack complex types
// a. Group of sub-unpack functions
//----------------------------------------------------------------------------------------
HRESULT Unpacker::UnpackBYTE(
_Out_ BYTE* pOut
)
{
HRESULT hr = E_UNEXPECTED;
BYTE* pR = nullptr;
// No input data validation
CHECKHR_EXIT( m_buffer.ReadFast( &pR, sizeof( BYTE ) ) );
*pOut = *pR;
exit:
return hr;
}
HRESULT Unpacker::UnpackUSHORT(
_Out_ USHORT* pOut
)
{
HRESULT hr = E_UNEXPECTED;
BYTE* pR = nullptr;
// No input data validation
CHECKHR_EXIT( m_buffer.ReadFast( &pR, sizeof( USHORT ) ) );
*pOut = *( USHORT* )pR;
exit:
return hr;
}
HRESULT Unpacker::UnpackUINT(
_Out_ UINT* pOut
)
{
HRESULT hr = E_UNEXPECTED;
BYTE* pR = nullptr;
// No input data validation
CHECKHR_EXIT( m_buffer.ReadFast( &pR, sizeof( UINT ) ) );
*pOut = *( UINT* )pR;
exit:
return hr;
}
// Returns pointer, no memory copy
HRESULT Unpacker::UnpackBytesFast(
_Outptr_result_maybenull_ BYTE** ppOut,
_In_ const UINT size
)
{
if ( !ppOut )
{
return E_POINTER;
}
*ppOut = nullptr;
HRESULT hr = S_FALSE;
BYTE* pR = nullptr;
// Input data validation
if ( size )
{
CHECKHR_EXIT( m_buffer.ReadFast( &pR, size ) );
*ppOut = pR;
return hr;
}
exit:
return hr;
}
HRESULT Unpacker::UnpackString(
_Out_ Mwrlw::HString& out
)
{
HRESULT hr = E_UNEXPECTED;
UINT size = 0;
BYTE* pBytes = nullptr;
CHECKHR_EXIT( UnpackUINT( &size ) );
CHECKHR_EXIT( UnpackBytesFast( &pBytes, size ) );
{
std::string byteString ((char*)pBytes, size);
std::unique_ptr<WCHAR[]> pConverted( new WCHAR[size] );
::MultiByteToWideChar( CP_UTF8,
0,
&byteString[0],
-1,
pConverted.get(),
size );
CHECKHR_EXIT( WindowsCreateString( pConverted.get(), size , out.GetAddressOf() ) );
}
exit:
return hr;
}
// Returns pointer and size, no memory copy
HRESULT Unpacker::UnpackBufferFast(
_Outptr_result_maybenull_ BYTE** ppOut,
_Out_ UINT* pOut
)
{
HRESULT hr = E_UNEXPECTED;
UINT size = 0;
BYTE* pBytes = nullptr;
CHECKHR_EXIT( UnpackUINT( &size ) );
CHECKHR_EXIT( UnpackBytesFast( &pBytes, size ) );
*ppOut = pBytes;
*pOut = size;
exit:
return hr;
}
//----------------------------------------------------------------------------------------
// IMPORTANT
// 1. When we unpack an audio device, it is a "remote" audio device for a "remote" user
// 2. Id, type, sharing, use BYTE to represent enum
//----------------------------------------------------------------------------------------
HRESULT Unpacker::UnpackAudioDevice(
_Out_ Mwrl::ComPtr<Awxs::IAudioDeviceInfo>& spOut,
_In_ AudioDeviceIDMapper^ audioDeviceIDMapper,
_In_ uint8 localNameOfRemoteConsole
)
{
HRESULT hr = E_UNEXPECTED;
Mwrlw::HString id;
BYTE type = 0;
BYTE sharing = 0;
BYTE category = 0;
BYTE isKinect;
DEVICE_ID deviceId;
Platform::String^ strId;
CHECKHR_EXIT( UnpackBYTE( &deviceId ) );
CHECKHR_EXIT( UnpackBYTE( &isKinect ) );
CHECKHR_EXIT( UnpackBYTE( &type ) );
CHECKHR_EXIT( UnpackBYTE( &sharing ) );
CHECKHR_EXIT( UnpackBYTE( &category ) );
// Store the lookupID and strId correlation for later use
LOOKUP_ID lookUpId = audioDeviceIDMapper->ConstructLookupID( localNameOfRemoteConsole, deviceId );
strId = lookUpId.ToString();
if (isKinect)
{
strId += L"postmec";
}
audioDeviceIDMapper->AddRemoteAudioDevice( lookUpId, strId );
id.Set(strId->Data());
// RemoteAudioDevice
CHECKHR_EXIT( Mwrl::MakeAndInitialize<ComStyleRemoteAudioDeviceInfo>( &spOut,
id.Get(),
( Awxs::AudioDeviceType )type,
( Awxs::AudioDeviceSharing )sharing,
( Awxs::AudioDeviceCategory )category ) );
exit:
return hr;
}
//----------------------------------------------------------------------------------------
// IMPORTANT
// 1. When we unpack audio devices, it is "remote" audio devices for a "remote user"
//----------------------------------------------------------------------------------------
HRESULT Unpacker::UnpackAudioDevices(
_Out_ Mwrl::ComPtr<Awfc::IVectorView<Awxs::IAudioDeviceInfo*>>& spOut,
_In_ AudioDeviceIDMapper^ audioDeviceIDMapper,
_In_ uint8 localNameOfRemoteConsole
)
{
HRESULT hr = E_UNEXPECTED;
Mwrl::ComPtr<ComStyleRemoteAudioDeviceInfos> spTemp;
UINT size = 0;
// RemoteAudioDevices
CHECKHR_EXIT( Mwrl::MakeAndInitialize<ComStyleRemoteAudioDeviceInfos>( &spTemp ) );
CHECKHR_EXIT( UnpackUINT( &size ) );
for ( UINT i = 0; i < size; i++ )
{
Mwrl::ComPtr<Awxs::IAudioDeviceInfo> spIAudioDevice;
CHECKHR_EXIT( UnpackAudioDevice( spIAudioDevice, audioDeviceIDMapper, localNameOfRemoteConsole ) );
spTemp->PushBack( spIAudioDevice );
}
CHECKHR_EXIT( spTemp.As( &spOut ) );
exit:
return hr;
}
//----------------------------------------------------------------------------------------
// IMPORTANT
// 1. When we unpack an user, it is a "remote" user
//----------------------------------------------------------------------------------------
HRESULT Unpacker::UnpackUser(
_Out_ Mwrl::ComPtr<Awxs::IUser>& spOut,
_In_ AudioDeviceIDMapper^ audioDeviceIDMapper,
_In_ uint8 localNameOfRemoteConsole
)
{
HRESULT hr = E_UNEXPECTED;
BYTE isGuest = 0;
Mwrlw::HString xuid;
Mwrl::ComPtr<Awfc::IVectorView<Awxs::IAudioDeviceInfo*>> spIAudioDevices;
CHECKHR_EXIT( UnpackBYTE( &isGuest ) );
CHECKHR_EXIT( UnpackString( xuid ) );
CHECKHR_EXIT( UnpackAudioDevices( spIAudioDevices, audioDeviceIDMapper, localNameOfRemoteConsole ) );
// RemoteUser
CHECKHR_EXIT( Mwrl::MakeAndInitialize<ComStyleRemoteUser>( &spOut,
isGuest,
xuid.Get(),
spIAudioDevices.Get() ) );
exit:
return hr;
}
}}}
#endif
@@ -0,0 +1,82 @@
//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved
#pragma once
#include "ChatUserSerializationCommon.h"
#include "ChatReadWriteBuffer.h"
#if TV_API
namespace Microsoft {
namespace Xbox {
namespace GameChat {
// Class that used to perform data deserialization
class Unpacker
{
public:
Unpacker();
~Unpacker();
HRESULT UnpackBegin(
_In_reads_bytes_(size) const BYTE* const pData,
_In_ const UINT size
);
HRESULT UnpackEnd() const;
HRESULT UnpackBYTE(
_Out_ BYTE* pOut
);
HRESULT UnpackUSHORT(
_Out_ USHORT* pOut
);
HRESULT UnpackUINT(
_Out_ UINT* pOut
);
HRESULT UnpackBytesFast(
_Outptr_result_maybenull_ BYTE** ppOut,
_In_ const UINT size
);
HRESULT UnpackString(
_Out_ Mwrlw::HString& out
);
HRESULT UnpackBufferFast(
_Outptr_result_maybenull_ BYTE** ppOut,
_Out_ UINT* pOut
);
HRESULT UnpackAudioDevice(
_Out_ Mwrl::ComPtr<Awxs::IAudioDeviceInfo>& spOut,
_In_ AudioDeviceIDMapper^ audioDeviceIDMapper,
_In_ uint8 localNameOfRemoteConsole
);
HRESULT UnpackAudioDevices(
_Out_ Mwrl::ComPtr<Awfc::IVectorView<Awxs::IAudioDeviceInfo*>>& spOut,
_In_ AudioDeviceIDMapper^ audioDeviceIDMapper,
_In_ uint8 localNameOfRemoteConsole
);
HRESULT UnpackUser(
_Out_ Mwrl::ComPtr<Awxs::IUser>& spOut,
_In_ AudioDeviceIDMapper^ audioDeviceIDMapper,
_In_ uint8 localNameOfRemoteConsole
);
private:
ReadWriteBuffer m_buffer;
};
}}}
#endif
@@ -0,0 +1,30 @@
//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved
#pragma once
#if TV_API
namespace Microsoft {
namespace Xbox {
namespace GameChat {
//----------------------------------------------------------------------------------------------
// Namespaces
//----------------------------------------------------------------------------------------------
namespace Mwrl = Microsoft::WRL;
namespace Mwrlw = Microsoft::WRL::Wrappers;
namespace Wf = Windows::Foundation;
namespace Awf = ABI::Windows::Foundation;
namespace Awfc = ABI::Windows::Foundation::Collections;
namespace Wss = Windows::Storage::Streams;
namespace Awss = ABI::Windows::Storage::Streams;
namespace Wxs = Windows::Xbox::System;
namespace Awxs = ABI::Windows::Xbox::System;
namespace Awxi = ABI::Windows::Xbox::Input;
}}}
#endif
@@ -0,0 +1,201 @@
//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved
#include "pch.h"
#include "RemoteUser.h"
#if TV_API
namespace Microsoft {
namespace Xbox {
namespace GameChat {
#define REMOTEUSERSTART 0x01000000
#define REMOTEUSEREND 0x01100000
unsigned ComStyleRemoteUser::s_id = REMOTEUSERSTART;
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
ComStyleRemoteUser::ComStyleRemoteUser() :
m_id( s_id < REMOTEUSEREND ? s_id++ : (s_id = REMOTEUSERSTART, s_id++) ), // using the , operator, returns last expression
m_isGuest( false )
{
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
ComStyleRemoteUser::~ComStyleRemoteUser()
{
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
HRESULT ComStyleRemoteUser::RuntimeClassInitialize(
const boolean isGuest,
const HSTRING xuid,
Awfc::IVectorView<Awxs::IAudioDeviceInfo*>* const pIAudioDevices )
{
HRESULT hr = E_UNEXPECTED;
m_isGuest = isGuest;
CHECKHR_EXIT( m_xuid.Set( xuid ) );
m_spIAudioDevices = pIAudioDevices;
exit:
return hr;
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
HRESULT ComStyleRemoteUser::get_Id( UINT32* id )
{
if ( id == nullptr )
{
return E_POINTER;
}
*id = m_id;
return S_OK;
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
HRESULT ComStyleRemoteUser::get_AudioDevices( Awfc::IVectorView<Awxs::IAudioDeviceInfo*>** audioDevices )
{
if ( audioDevices == nullptr )
{
return E_POINTER;
}
return m_spIAudioDevices.CopyTo( audioDevices );
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
HRESULT ComStyleRemoteUser::get_Controllers( Awfc::IVectorView<Awxi::IController*>** /* controllers */ )
{
return E_NOTIMPL;
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
HRESULT ComStyleRemoteUser::get_DisplayInfo( Awxs::IUserDisplayInfo** /* displayInfo */ )
{
return E_NOTIMPL;
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
HRESULT ComStyleRemoteUser::get_IsGuest( boolean* isGuest )
{
if ( isGuest == nullptr )
{
return E_POINTER;
}
*isGuest = m_isGuest;
return S_OK;
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
HRESULT ComStyleRemoteUser::get_IsSignedIn( boolean* isSignedIn )
{
if ( isSignedIn == nullptr )
{
return E_POINTER;
}
*isSignedIn = true;
return S_OK;
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
HRESULT ComStyleRemoteUser::get_Location( Awxs::UserLocation* location )
{
if ( location == nullptr )
{
return E_POINTER;
}
*location = Awxs::UserLocation_Remote;
return S_OK;
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
HRESULT ComStyleRemoteUser::get_Sponsor( IUser** /* sponsor */ )
{
return E_NOTIMPL;
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
HRESULT ComStyleRemoteUser::get_XboxUserHash( HSTRING* /* userhash */ )
{
return E_NOTIMPL;
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
HRESULT ComStyleRemoteUser::get_XboxUserId( _Out_ HSTRING* xuid )
{
if ( !xuid )
{
return E_POINTER;
}
HRESULT hr = WindowsDuplicateString( m_xuid.Get(), xuid );
#ifdef __PREFAST__
if ( FAILED(hr) )
{
*xuid = nullptr;
}
#endif
return hr;
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
HRESULT ComStyleRemoteUser::GetTokenAndSignatureAsync(
HSTRING /* httpMethod */,
HSTRING /* url */,
HSTRING /* headers */,
Awf::IAsyncOperation<Awxs::GetTokenAndSignatureResult*>** /* operation */ )
{
return E_NOTIMPL;
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
HRESULT ComStyleRemoteUser::GetTokenAndSignatureWithBodyAsync(
HSTRING /* httpMethod */,
HSTRING /* url */,
HSTRING /* headers */,
UINT32 /* __bodySize */,
BYTE* /* body */,
Awf::IAsyncOperation<Awxs::GetTokenAndSignatureResult*>** /* operation */ )
{
return E_NOTIMPL;
}
//----------------------------------------------------------------------------------------
//----------------------------------------------------------------------------------------
HRESULT ComStyleRemoteUser::GetTokenAndSignatureWithStringBodyAsync(
HSTRING /* httpMethod */,
HSTRING /* url */,
HSTRING /* headers */,
HSTRING /* body */,
Awf::IAsyncOperation<Awxs::GetTokenAndSignatureResult*>** /* operation */ )
{
return E_NOTIMPL;
}
}}}
#endif
@@ -0,0 +1,73 @@
//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
//// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
//// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
//// PARTICULAR PURPOSE.
////
//// Copyright (c) Microsoft Corporation. All rights reserved
#pragma once
#include "ChatUserSerializationCommon.h"
#if TV_API
namespace Microsoft {
namespace Xbox {
namespace GameChat {
/*
=====================================================================
This class is used to represent a remote user, remote user is
not created by user manager
IMPORTANT
1. Implements IUser
=====================================================================
*/
class ComStyleRemoteUser : public Mwrl::RuntimeClass<ABI::Windows::Xbox::System::IUser, Mwrl::FtmBase>
{
public:
ComStyleRemoteUser();
virtual ~ComStyleRemoteUser();
HRESULT RuntimeClassInitialize( const boolean isGuest,
const HSTRING xuid,
Awfc::IVectorView<Awxs::IAudioDeviceInfo*>* const pIAudioDevices );
HRESULT get_Id( UINT32* id );
HRESULT get_AudioDevices( Awfc::IVectorView<Awxs::IAudioDeviceInfo*>** audioDevices );
HRESULT get_Controllers( Awfc::IVectorView<Awxi::IController*>** controllers );
HRESULT get_DisplayInfo( Awxs::IUserDisplayInfo** displayInfo );
HRESULT get_IsGuest( boolean* isGuest );
HRESULT get_IsSignedIn( boolean* isSignedIn );
HRESULT get_Location( Awxs::UserLocation* location );
HRESULT get_Sponsor( ABI::Windows::Xbox::System::IUser** sponsor );
HRESULT get_XboxUserHash( HSTRING* userhash );
HRESULT get_XboxUserId( _Out_ HSTRING* xuid );
HRESULT GetTokenAndSignatureAsync( HSTRING httpMethod,
HSTRING url,
HSTRING headers,
Awf::IAsyncOperation<Awxs::GetTokenAndSignatureResult*>** operation );
HRESULT GetTokenAndSignatureWithBodyAsync( HSTRING httpMethod,
HSTRING url,
HSTRING headers,
UINT32 __bodySize,
BYTE* body,
Awf::IAsyncOperation<Awxs::GetTokenAndSignatureResult*>** operation );
HRESULT GetTokenAndSignatureWithStringBodyAsync( HSTRING httpMethod,
HSTRING url,
HSTRING headers,
HSTRING body,
Awf::IAsyncOperation<Awxs::GetTokenAndSignatureResult*>** operation );
private:
UINT m_id;
boolean m_isGuest;
Mwrlw::HString m_xuid;
Mwrl::ComPtr<Awfc::IVectorView<Awxs::IAudioDeviceInfo*>> m_spIAudioDevices;
static UINT s_id;
};
}}}
#endif