Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix crash #240

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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
27 changes: 18 additions & 9 deletions src/audio-capture-helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,17 @@ void AudioCaptureHelper::InitClient()
auto propvariant = GetPropvariant(&params);

wil::com_ptr<IActivateAudioInterfaceAsyncOperation> async_op;
CompletionHandler completion_handler;

Microsoft::WRL::ComPtr<CompletionHandler> completion_handler = Microsoft::WRL::Make<CompletionHandler>();

THROW_IF_FAILED(ActivateAudioInterfaceAsync(VIRTUAL_AUDIO_DEVICE_PROCESS_LOOPBACK,
__uuidof(IAudioClient), &propvariant,
&completion_handler, &async_op));
completion_handler.Get(), &async_op));

completion_handler.event_finished.wait();
THROW_IF_FAILED(completion_handler.activate_hr);
completion_handler->event_finished.wait();
THROW_IF_FAILED(completion_handler->activate_hr);

client = completion_handler.client;
client = completion_handler->client;

THROW_IF_FAILED(
client->Initialize(AUDCLNT_SHAREMODE_SHARED,
Expand Down Expand Up @@ -102,12 +103,20 @@ void AudioCaptureHelper::ForwardPacket()
THROW_IF_FAILED(capture_client->GetNextPacketSize(&num_frames));

while (num_frames > 0) {
BYTE *new_data;
BYTE *new_data = nullptr;
DWORD flags;
UINT64 qpc_position;

THROW_IF_FAILED(capture_client->GetBuffer(&new_data, &num_frames, &flags, NULL,
&qpc_position));
HRESULT hr = capture_client->GetBuffer(&new_data, &num_frames, &flags, NULL,
&qpc_position);

THROW_IF_FAILED(hr);
if (hr == AUDCLNT_S_BUFFER_EMPTY || new_data == nullptr)
{
THROW_IF_FAILED(capture_client->ReleaseBuffer(num_frames));
THROW_IF_FAILED(capture_client->GetNextPacketSize(&num_frames));
continue;
}

if (!(flags & AUDCLNT_BUFFERFLAGS_SILENT))
ForwardToMixers(qpc_position, new_data, num_frames);
Expand Down Expand Up @@ -164,7 +173,7 @@ void AudioCaptureHelper::CaptureSafe()
AudioCaptureHelper::AudioCaptureHelper(Mixer *mixer, WAVEFORMATEX format, DWORD pid)
: mixers{mixer}, format{format}, pid{pid}
{
for (auto &event : events)
for (auto &event : events)
event.create();

capture_thread = std::thread(&AudioCaptureHelper::CaptureSafe, this);
Expand Down
13 changes: 8 additions & 5 deletions src/audio-capture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,15 @@ AudioCapture::DeDuplicateCaptureList(const std::set<DWORD> &pids,
for (auto pid : explicitly_captured_pids)
uncaptured_pids.erase(pid);

for (auto pid : uncaptured_pids) {
if (!explicitly_captured_pids.contains(parents[pid]))
auto iter = uncaptured_pids.begin();
while (iter != uncaptured_pids.end()) {
if (!explicitly_captured_pids.contains(parents[*iter]))
{
++iter;
continue;

implicitly_captured_pids.insert(pid);
uncaptured_pids.erase(pid);
}
implicitly_captured_pids.insert(*iter);
iter = uncaptured_pids.erase(iter);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/session-monitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <wrl/implements.h>

#include "common.hpp"
#include <optional>

using namespace Microsoft::WRL;

Expand Down