Skip to content

Commit

Permalink
[VCM] add debug ability to overwrite frames with files
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyoyuppe committed Apr 13, 2021
1 parent e0160fd commit e540e7a
Showing 1 changed file with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <mfidl.h>
#include <Shlwapi.h>
#include <mfapi.h>
#include <fstream>

constexpr static inline wchar_t FILTER_NAME[] = L"PowerToysVCMProxyFilter";
constexpr static inline wchar_t PIN_NAME[] = L"PowerToysVCMProxyPIN";
Expand Down Expand Up @@ -437,10 +438,40 @@ bool OverwriteFrame(IMediaSample* frame, wil::com_ptr_nothrow<IMFSample>& image)
}

//#define DEBUG_FRAME_DATA
//#define DEBUG_OVERWRITE_FRAME

#if defined(DEBUG_OVERWRITE_FRAME)
void DebugOverwriteFrame(IMediaSample* frame, std::string_view filepath)
{
std::ifstream file{ filepath.data(), std::ios::binary };
std::streampos fileSize = 0;
fileSize = file.tellg();
file.seekg(0, std::ios::end);
fileSize = file.tellg() - fileSize;

BYTE* frameData = nullptr;
if (!frame)
{
LOG("null frame provided");
return;
}
frame->GetPointer(&frameData);
const DWORD frameSize = frame->GetSize();

if (fileSize > frameSize || !frameData)
{
LOG("frame can't be filled with data");
return;
}
file.read((char*)frameData, fileSize);
frame->SetActualDataLength((long)fileSize);
LOG("DebugOverwriteFrame success");
}

#endif

#if defined(DEBUG_FRAME_DATA)
#include <filesystem>
#include <fstream>

namespace fs = std::filesystem;

Expand Down Expand Up @@ -500,6 +531,7 @@ VideoCaptureProxyFilter::VideoCaptureProxyFilter() :
auto newSettings = SyncCurrentSettings();
if (newSettings.webcamDisabled)
{
#if !defined(DEBUG_OVERWRITE_FRAME)
bool overwritten = OverwriteFrame(_pending_frame, _overlayImage ? _overlayImage : _blankImage);
while (!overwritten && _overlayImage)
{
Expand Down Expand Up @@ -532,6 +564,9 @@ VideoCaptureProxyFilter::VideoCaptureProxyFilter() :
{
OverwriteFrame(_pending_frame, _blankImage);
}
#else
DebugOverwriteFrame(_pending_frame, "R:\\frame.data");
#endif
}

_pending_frame = nullptr;
Expand Down

1 comment on commit e540e7a

@github-actions
Copy link

Choose a reason for hiding this comment

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

Misspellings found, please review:

  • filepath
  • seekg
  • streampos
  • tellg
To accept these changes, run the following commands from this repository on this branch
pushd $(git rev-parse --show-toplevel)
perl -e '
my $new_expect_file=".github/actions/spell-check/expect.txt";
use File::Path qw(make_path);
make_path ".github/actions/spell-check";
open FILE, q{<}, $new_expect_file; chomp(my @words = <FILE>); close FILE;
my @add=qw('"filepath seekg streampos tellg "');
my %items; @items{@words} = @words x (1); @items{@add} = @add x (1);
@words = sort {lc($a) cmp lc($b)} keys %items;
open FILE, q{>}, $new_expect_file; for my $word (@words) { print FILE "$word\n" if $word =~ /\w/; };
close FILE;'
popd

Please sign in to comment.