Skip to content

Commit

Permalink
Fixed some type conversion and other warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sskodje committed Feb 4, 2023
1 parent 10bd5a0 commit 1c425bc
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion ScreenRecorderLibNative/AudioManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ HRESULT AudioManager::InitializeAudioCapture()
return hr;
}

std::vector<BYTE> AudioManager::GrabAudioFrame(_In_ int durationHundredNanos)
std::vector<BYTE> AudioManager::GrabAudioFrame(_In_ UINT64 durationHundredNanos)
{
EnterCriticalSection(&m_CriticalSection);
LeaveCriticalSectionOnExit leaveOnExit(&m_CriticalSection);
Expand Down
2 changes: 1 addition & 1 deletion ScreenRecorderLibNative/AudioManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class AudioManager
~AudioManager();
HRESULT Initialize(_In_ std::shared_ptr<AUDIO_OPTIONS> &audioOptions);
void ClearRecordedBytes();
std::vector<BYTE> GrabAudioFrame(_In_ int durationHundredNanos);
std::vector<BYTE> GrabAudioFrame(_In_ UINT64 durationHundredNanos);
private:
CRITICAL_SECTION m_CriticalSection;
std::shared_ptr<AUDIO_OPTIONS> m_AudioOptions;
Expand Down
10 changes: 5 additions & 5 deletions ScreenRecorderLibNative/LoopbackCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ HRESULT LoopbackCapture::StartLoopbackCapture(
return E_FAIL;
}
// activate an IAudioClient
IAudioClient *pAudioClient;
IAudioClient *pAudioClient = nullptr;
hr = pMMDevice->Activate(
__uuidof(IAudioClient),
CLSCTX_ALL, NULL,
Expand Down Expand Up @@ -182,7 +182,7 @@ HRESULT LoopbackCapture::StartLoopbackCapture(
}

// activate an IAudioCaptureClient
IAudioCaptureClient *pAudioCaptureClient;
IAudioCaptureClient *pAudioCaptureClient = nullptr;
hr = pAudioClient->GetService(
__uuidof(IAudioCaptureClient),
(void **)&pAudioCaptureClient
Expand All @@ -204,7 +204,7 @@ HRESULT LoopbackCapture::StartLoopbackCapture(
AvRevertMmThreadCharacteristicsOnExit unregisterMmcss(hTask);

// set the waitable timer
LARGE_INTEGER liFirstFire;
LARGE_INTEGER liFirstFire{};
liFirstFire.QuadPart = -hnsDefaultDevicePeriod / 2; // negative means relative time
LONG lTimeBetweenFires = (LONG)hnsDefaultDevicePeriod / 2 / (10 * 1000); // convert to milliseconds
BOOL bOK = SetWaitableTimer(
Expand Down Expand Up @@ -351,10 +351,10 @@ std::vector<BYTE> LoopbackCapture::PeakRecordedBytes()
return m_RecordedBytes;
}

std::vector<BYTE> LoopbackCapture::GetRecordedBytes(int duration100Nanos)
std::vector<BYTE> LoopbackCapture::GetRecordedBytes(UINT64 duration100Nanos)
{
int frameCount = int(ceil(m_InputFormat.sampleRate * HundredNanosToSeconds(duration100Nanos)));
int byteCount = min((frameCount * m_InputFormat.FrameBytes()), m_RecordedBytes.size());
size_t byteCount = min((frameCount * m_InputFormat.FrameBytes()), m_RecordedBytes.size());
m_TaskWrapperImpl->m_Mutex.lock();
std::vector<BYTE> newvector(m_RecordedBytes.begin(), m_RecordedBytes.begin() + byteCount);
// convert audio
Expand Down
2 changes: 1 addition & 1 deletion ScreenRecorderLibNative/LoopbackCapture.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class LoopbackCapture
UINT32 channels
);
std::vector<BYTE> PeakRecordedBytes();
std::vector<BYTE> GetRecordedBytes(int duration100Nanos);
std::vector<BYTE> GetRecordedBytes(UINT64 duration100Nanos);
HRESULT StartCapture(UINT32 audioChannels, std::wstring device, EDataFlow flow) { return StartCapture(0, audioChannels, device, flow); }
HRESULT StartCapture(UINT32 sampleRate, UINT32 audioChannels, std::wstring device, EDataFlow flow);
HRESULT StopCapture();
Expand Down
12 changes: 6 additions & 6 deletions ScreenRecorderLibNative/RecordingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ REC_RESULT RecordingManager::StartRecorderLoop(_In_ const std::vector<RECORDING_
videoFrameDurationMillis = (double)1000 / GetEncoderOptions()->GetVideoFps();
}
else if (recorderMode == RecorderModeInternal::Slideshow) {
videoFrameDurationMillis = GetSnapshotOptions()->GetSnapshotsInterval().count();
videoFrameDurationMillis = (double)GetSnapshotOptions()->GetSnapshotsInterval().count();
}
INT64 videoFrameDuration100Nanos = MillisToHundredNanos(videoFrameDurationMillis);

Expand All @@ -446,9 +446,9 @@ REC_RESULT RecordingManager::StartRecorderLoop(_In_ const std::vector<RECORDING_
bool havePrematureFrame = false;
cancellation_token token = m_TaskWrapperImpl->m_RecordTaskCts.get_token();
INT64 minimumTimeForDelay100Nanons = 5000;//0.5ms
INT64 maxFrameLengthMillis = HundredNanosToMillis(m_MaxFrameLength100Nanos);
DWORD maxFrameLengthMillis = (DWORD)HundredNanosToMillis(m_MaxFrameLength100Nanos);
DynamicWait DynamicWait;
int totalDiff = 0;
INT64 totalDiff = 0;

auto IsTimeToTakeSnapshot([&]()
{
Expand Down Expand Up @@ -506,10 +506,10 @@ REC_RESULT RecordingManager::StartRecorderLoop(_In_ const std::vector<RECORDING_
}
}

int diff = 0;
INT64 diff = 0;
auto audioBytes = pAudioManager->GrabAudioFrame(duration100Nanos);
if (audioBytes.size() > 0) {
INT64 frameCount = audioBytes.size() / ((GetAudioOptions()->GetAudioBitsPerSample() / 8) * GetAudioOptions()->GetAudioChannels());
INT64 frameCount = audioBytes.size() / (INT64)((GetAudioOptions()->GetAudioBitsPerSample() / 8) * GetAudioOptions()->GetAudioChannels());
INT64 newDuration = (frameCount * 10 * 1000 * 1000) / GetAudioOptions()->GetAudioSamplesPerSecond();
diff = newDuration - duration100Nanos;
}
Expand Down Expand Up @@ -808,7 +808,7 @@ HRESULT RecordingManager::ProcessTextureTransforms(_In_ ID3D11Texture2D *pTextur
int leftMargin = (int)max(0, round(((double)videoOutputFrameSize.cx - (double)RectWidth(contentRect))) / 2);
int topMargin = (int)max(0, round(((double)videoOutputFrameSize.cy - (double)RectHeight(contentRect))) / 2);

D3D11_BOX Box;
D3D11_BOX Box{};
Box.front = 0;
Box.back = 1;
Box.left = 0;
Expand Down
2 changes: 0 additions & 2 deletions ScreenRecorderLibNative/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ inline double HundredNanosToSeconds(INT64 hundredNanos) {
/// <summary>
/// Forces the dimensions of rect to be even by adding 1*modifier pixel if odd.
/// </summary>
/// <param name="rect"></param>
inline RECT MakeRectEven(_In_ RECT &rect, _In_ int modifier = -1)
{
if ((rect.right - rect.left) % 2 != 0)
Expand All @@ -171,7 +170,6 @@ inline RECT MakeRectEven(_In_ RECT &rect, _In_ int modifier = -1)
/// <summary>
/// Forces the dimensions of n to be even by adding 1*modifier pixel if odd.
/// </summary>
/// <param name="rect"></param>
inline LONG MakeEven(_In_ LONG n, _In_ int modifier = -1) {
return n + (1 * modifier) * n % 2;
}
Expand Down
2 changes: 1 addition & 1 deletion TestConsoleAppCpp/TestConsoleAppCpp.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<RootNamespace>TestConsoleAppCpp</RootNamespace>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
<TargetFrameworkVersion>4.8</TargetFrameworkVersion>
<ProjectName>TestConsoleAppManagedCpp</ProjectName>
<ProjectName>TestConsoleAppCpp</ProjectName>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
Expand Down

0 comments on commit 1c425bc

Please sign in to comment.