Skip to content

Commit

Permalink
Added debug messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
dchapyshev committed Nov 15, 2023
1 parent a9aea4b commit d977b40
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
8 changes: 7 additions & 1 deletion source/base/audio/audio_capturer_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,28 @@ AudioCapturerWin::AudioCapturerWin()
volume_filter_(kSilenceThreshold),
last_capture_error_(S_OK)
{
// Nothing
LOG(LS_INFO) << "Ctor";
}

//--------------------------------------------------------------------------------------------------
AudioCapturerWin::~AudioCapturerWin()
{
LOG(LS_INFO) << "Dtor";
DCHECK(thread_checker_.calledOnValidThread());
deinitialize();
}

//--------------------------------------------------------------------------------------------------
bool AudioCapturerWin::start(const PacketCapturedCallback& callback)
{
LOG(LS_INFO) << "Starting audio capturer";
callback_ = callback;

if (!initialize())
{
LOG(LS_ERROR) << "initialize failed";
return false;
}

// Initialize the capture timer and start capturing. Note, this timer won't be reset or
// restarted in resetAndInitialize() function. Which means we expect the audio_device_period_
Expand All @@ -100,6 +105,7 @@ bool AudioCapturerWin::resetAndInitialize()
deinitialize();
if (!initialize())
{
LOG(LS_ERROR) << "initialize failed";
deinitialize();
return false;
}
Expand Down
30 changes: 29 additions & 1 deletion source/base/audio/audio_output_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const char* sessionStateToString(AudioSessionState state)
AudioOutputWin::AudioOutputWin(const NeedMoreDataCB& need_more_data_cb)
: AudioOutput(need_more_data_cb)
{
LOG(LS_INFO) << "Ctor";

// Create the event which the audio engine will signal each time a buffer becomes ready to be
// processed by the client.
audio_samples_event_.reset(CreateEventW(nullptr, false, false, nullptr));
Expand All @@ -70,6 +72,7 @@ AudioOutputWin::AudioOutputWin(const NeedMoreDataCB& need_more_data_cb)
//--------------------------------------------------------------------------------------------------
AudioOutputWin::~AudioOutputWin()
{
LOG(LS_INFO) << "Dtor";
stop();
}

Expand Down Expand Up @@ -228,11 +231,17 @@ bool AudioOutputWin::init()
{
Microsoft::WRL::ComPtr<IMMDevice> device(createDevice());
if (!device.Get())
{
LOG(LS_ERROR) << "createDevice failed";
return false;
}

Microsoft::WRL::ComPtr<IAudioClient> audio_client = createClient(device.Get());
if (!audio_client.Get())
{
LOG(LS_ERROR) << "createClient failed";
return false;
}

// Define the output WAVEFORMATEXTENSIBLE format in |format_|.
WAVEFORMATEXTENSIBLE format_extensible;
Expand All @@ -253,7 +262,10 @@ bool AudioOutputWin::init()
format_extensible.SubFormat = KSDATAFORMAT_SUBTYPE_PCM;

if (!isFormatSupported(audio_client.Get(), AUDCLNT_SHAREMODE_SHARED, &format_extensible))
{
LOG(LS_ERROR) << "Format not supported";
return false;
}

// Initialize the audio stream between the client and the device in shared mode using
// event-driven buffer handling. Also, using 0 as requested buffer size results in a default
Expand All @@ -262,6 +274,7 @@ bool AudioOutputWin::init()
if (!sharedModeInitialize(audio_client.Get(), &format_extensible, audio_samples_event_,
requested_buffer_size, true, &endpoint_buffer_size_frames_))
{
LOG(LS_ERROR) << "sharedModeInitialize failed";
return false;
}

Expand All @@ -270,15 +283,21 @@ bool AudioOutputWin::init()
Microsoft::WRL::ComPtr<IAudioRenderClient> audio_render_client =
createRenderClient(audio_client.Get());
if (!audio_render_client.Get())
{
LOG(LS_ERROR) << "createRenderClient failed";
return false;
}

// Create an AudioSessionControl interface given the initialized client. The IAudioControl
// interface enables a client to configure the control parameters for an audio session and to
// monitor events in the session.
Microsoft::WRL::ComPtr<IAudioSessionControl> audio_session_control =
createAudioSessionControl(audio_client.Get());
if (!audio_session_control.Get())
{
LOG(LS_ERROR) << "createAudioSessionControl failed";
return false;
}

// The Sndvol program displays volume and mute controls for sessions that are in the active and
// inactive states.
Expand Down Expand Up @@ -372,13 +391,22 @@ bool AudioOutputWin::handleRestartEvent()
return true;

if (!stop())
{
LOG(LS_ERROR) << "stop failed";
return false;
}

if (!init())
{
LOG(LS_ERROR) << "init failed";
return false;
}

if (!start())
{
LOG(LS_ERROR) << "start failed";
return false;
}

return true;
}
Expand Down Expand Up @@ -458,7 +486,7 @@ HRESULT AudioOutputWin::OnSessionDisconnected(AudioSessionDisconnectReason disco
{
if (is_restarting_)
{
DLOG(LS_ERROR) << "Ignoring since restart is already active";
LOG(LS_ERROR) << "Ignoring since restart is already active";
return S_OK;
}

Expand Down

0 comments on commit d977b40

Please sign in to comment.