Skip to content
This repository was archived by the owner on Jul 19, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private async void bnListen_Click(object sender, RoutedEventArgs e)

private async void StartCapture()
{
captureEngine = await CaptureEngine.CreateAsync(false);
captureEngine = await CaptureEngine.CreateAsync(true);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change function signature to pass in the bool value for audio

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late response. Just got a chance to revisit this project. Added a checkbox in the UI and changed the signature of StartCapture. Please check the latest commit.

if (this.captureEngine != null)
{
await this.captureEngine.StartAsync(false, this.connection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,6 @@
<Capability Name="privateNetworkClientServer" />
<Capability Name="internetClient" />
<DeviceCapability Name="webcam" />
<DeviceCapability Name="microphone" />
</Capabilities>
</Package>
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ HRESULT CaptureEngineImpl::StartAsync(
ComPtr<MixedRemoteViewCompositor::Media::MrcAudioEffectDefinitionImpl> mrcAudioEffectDefinition;
MakeAndInitialize<MrcAudioEffectDefinitionImpl>(&mrcAudioEffectDefinition);

IFR(mrcAudioEffectDefinition->put_MixerMode(AudioMixerMode_Mic));
IFR(mrcAudioEffectDefinition->put_MixerMode(AudioMixerMode_MicAndLoopback));

ComPtr<ABI::Windows::Media::Effects::IAudioEffectDefinition> audioEffectDefinition;
IFR(mrcAudioEffectDefinition.As(&audioEffectDefinition));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ HRESULT NetworkMediaSinkStreamImpl::ProcessSamplesFromQueue(
if (nullptr != spDataBundle.Get())
{
ComPtr<IAsyncAction> spSendAction;
if (FAILED(_spConnection->SendBundleAsync(spDataBundle.Get(), &spSendAction)))
if (FAILED(_spConnection->SendBundleAsyncSequenced(spDataBundle.Get(), &spSendAction)))
{
fProcessingSample = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,8 @@ HRESULT PlaybackEngineImpl::StartPlayback()

NULL_CHK_HR(_sourceReader, E_NOT_SET);

IFR(RequestNextSampleAsync(MF_SOURCE_READER_FIRST_VIDEO_STREAM));
IFR(RequestNextSampleAsync(MF_SOURCE_READER_ANY_STREAM));
//IFR(RequestNextSampleAsync(MF_SOURCE_READER_FIRST_VIDEO_STREAM));

//IFR(RequestNextSampleAsync(MF_SOURCE_READER_FIRST_AUDIO_STREAM));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,9 @@ namespace MixedRemoteViewCompositor{ namespace Network {
HRESULT SendBundleAsync(
[in] MixedRemoteViewCompositor.Network.DataBundle* dataBundle,
[out, retval] Windows.Foundation.IAsyncAction** asyncAction);
HRESULT SendBundleAsyncSequenced(
[in] MixedRemoteViewCompositor.Network.DataBundle* dataBundle,
[out, retval] Windows.Foundation.IAsyncAction** asyncAction);
};

[exclusiveto(MixedRemoteViewCompositor.Network.Connection)]
Expand Down
115 changes: 115 additions & 0 deletions MixedRemoteViewCompositor/Source/Shared/Network/Connection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,121 @@ HRESULT ConnectionImpl::SendBundleAsync(
return spWriteAction.CopyTo(sendAction);
}

_Use_decl_annotations_
HRESULT ConnectionImpl::SendBundleAsyncSequenced(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can the single buffer/bundle be refactored to use SendBundleAsync function so there is only one function that is possibly writing to the output stream of the socket

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Removed the SendBundleAsyncSequenced function and refactor its code into the original function SendBundleAsync. Please check the latest commit.

IDataBundle *dataBundle,
IAsyncAction **sendAction)
{
Log(Log_Level_Info, L"ConnectionImpl::SendBundleAsyncSequenced\n");

NULL_CHK(dataBundle);
NULL_CHK(sendAction);

{
auto lock = _lock.Lock();

IFR(CheckClosed());
}

ComPtr<WriteCompleteImpl> spWriteAction;
IFR(MakeAndInitialize<WriteCompleteImpl>(&spWriteAction, 1));

// define workitem
ComPtr<IDataBundle> spDataBundle(dataBundle);
ComPtr<ConnectionImpl> spThis(this);
auto workItem =
Microsoft::WRL::Callback<ABI::Windows::System::Threading::IWorkItemHandler>(
[this, spThis, spDataBundle, spWriteAction](IAsyncAction* asyncAction) -> HRESULT
{
ComPtr<IOutputStream> spOutputStream;
DataBundleImpl::Container buffers;
DataBundleImpl::Iterator iter;

ComPtr<IStreamWriteOperation> writeOperation;
ComPtr<IBuffer> rawBuffer;
ComPtr<IDataBuffer> singleBuffer;

HRESULT hr = S_OK;

{
auto lock = _lock.Lock();

IFC(CheckClosed());

// get the output stream for socket
if (nullptr != _streamSocket)
{
IFC(_streamSocket->get_OutputStream(&spOutputStream));
}
else
{
IFC(E_UNEXPECTED);
}
}

DataBundleImpl* bundleImpl = static_cast<DataBundleImpl*>(spDataBundle.Get());
if (nullptr == bundleImpl)
{
IFC(E_INVALIDARG);
}

//make a single big buffer
ULONG totalSize;
IFC(bundleImpl->get_TotalSize(&totalSize));

IFC(MakeAndInitialize<DataBufferImpl>(&singleBuffer, totalSize));

DataBufferImpl * bufferImpl = static_cast<DataBufferImpl*>(singleBuffer.Get());

if (nullptr == bufferImpl)
{
IFC(E_INVALIDARG);
}

BYTE* rawSingleBuffer;
IFC(bufferImpl->get_Buffer(&rawSingleBuffer));

DWORD copied;
IFC(bundleImpl->CopyTo(0, totalSize, &rawSingleBuffer[0], &copied));

IFC(bufferImpl->put_CurrentLength(copied));

IFC(singleBuffer.As(&rawBuffer));

IFC(spOutputStream->WriteAsync(rawBuffer.Get(), &writeOperation));

hr = SyncWait<UINT32, UINT32>(writeOperation.Get(), 1);

spWriteAction->SignalCompleted(hr);

done:
if (FAILED(hr))
{
spWriteAction->SignalCompleted(hr);
}

return S_OK;
});

ComPtr<IAsyncAction> workerAsync;
IFR(_threadPoolStatics->RunAsync(workItem.Get(), &workerAsync));

IFR(StartAsyncThen(
workerAsync.Get(),
[this, spThis, spWriteAction](_In_ HRESULT hr, _In_ IAsyncAction *asyncResult, _In_ AsyncStatus asyncStatus) -> HRESULT
{
if (FAILED(hr))
{
spWriteAction->SignalCompleted(hr);
}

return S_OK;
}));

// hand off async op
return spWriteAction.CopyTo(sendAction);
}

// IConnectionInternal
_Use_decl_annotations_
HRESULT ConnectionImpl::WaitForHeader()
Expand Down
3 changes: 3 additions & 0 deletions MixedRemoteViewCompositor/Source/Shared/Network/Connection.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ namespace MixedRemoteViewCompositor
IFACEMETHOD(SendBundleAsync)(
_In_ ABI::MixedRemoteViewCompositor::Network::IDataBundle *dataBundle,
_Out_ ABI::Windows::Foundation::IAsyncAction **sendAction);
IFACEMETHOD(SendBundleAsyncSequenced)(
_In_ ABI::MixedRemoteViewCompositor::Network::IDataBundle *dataBundle,
_Out_ ABI::Windows::Foundation::IAsyncAction **sendAction);

protected:
// IConnectionInternal
Expand Down