Skip to content

Commit

Permalink
Merge pull request #153 from jdibenes/realsense_test
Browse files Browse the repository at this point in the history
Realsense test
  • Loading branch information
jdibenes authored Dec 20, 2024
2 parents 4a77f07 + 540a9ab commit 51daf7a
Show file tree
Hide file tree
Showing 167 changed files with 8,224 additions and 6,359 deletions.
2 changes: 1 addition & 1 deletion hl2ss/hl2ss/Package.appxmanifest
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Identity
Name="eaaf3af3-1402-4e5b-b6a1-5d0fbb7c1ba8"
Publisher="CN=jcds"
Version="1.0.33.0" />
Version="1.0.34.0" />
<mp:PhoneIdentity PhoneProductId="eaaf3af3-1402-4e5b-b6a1-5d0fbb7c1ba8" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
<Properties>
<DisplayName>hl2ss</DisplayName>
Expand Down
7 changes: 7 additions & 0 deletions hl2ss/hl2ss/custom_audio_effect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,25 @@
using namespace winrt::Windows::Foundation::Collections;
using namespace winrt::Windows::Media::Effects;

//-----------------------------------------------------------------------------
// Functions
//-----------------------------------------------------------------------------

// OK
MRCAudioEffect::MRCAudioEffect(MRCAudioOptions const& options)
{
m_propertySet.Insert(L"MixerMode", winrt::box_value<uint32_t>((options.mixer_mode & 3) % 3));
m_propertySet.Insert(L"LoopbackGain", winrt::box_value<float>(options.loopback_gain));
m_propertySet.Insert(L"MicrophoneGain", winrt::box_value<float>(options.microphone_gain));
}

// OK
IPropertySet MRCAudioEffect::Properties()
{
return m_propertySet;
}

// OK
winrt::hstring MRCAudioEffect::ActivatableClassId()
{
return L"Windows.Media.MixedRealityCapture.MixedRealityCaptureAudioEffect";
Expand Down
112 changes: 112 additions & 0 deletions hl2ss/hl2ss/custom_encoder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@

#include <mfapi.h>
#include "custom_encoder.h"

//-----------------------------------------------------------------------------
// Functions
//-----------------------------------------------------------------------------

// OK
CustomEncoder::CustomEncoder(HOOK_ENCODER_PROC pHookCallback, void* pHookParam, HOOK_METADATA_PROC pMetadataFree, uint32_t metadata_size, bool shift)
{
m_metadata = std::make_unique<uint8_t[]>(metadata_size);
m_metadata_size = metadata_size;
m_shift = shift;
m_pHookCallback = pHookCallback;
m_pHookParam = pHookParam;
m_pMetadataFree = pMetadataFree;

memset(m_metadata.get(), 0, metadata_size);
}

// OK
CustomEncoder::CustomEncoder(HOOK_ENCODER_PROC pHookCallback, void* pHookParam, HOOK_METADATA_PROC pMetadataFree, uint32_t metadata_size, AudioSubtype input_subtype, AACFormat const& format) :
CustomEncoder(pHookCallback, pHookParam, pMetadataFree, metadata_size, false)
{
m_pSinkWriter = CustomSinkWriter::CreateForAudio(Thunk_Sink, this, input_subtype, format);
}

// OK
CustomEncoder::CustomEncoder(HOOK_ENCODER_PROC pHookCallback, void* pHookParam, HOOK_METADATA_PROC pMetadataFree, uint32_t metadata_size, VideoSubtype input_subtype, H26xFormat const& format, uint32_t stride, std::vector<uint64_t> const& encoder_options) :
CustomEncoder(pHookCallback, pHookParam, pMetadataFree, metadata_size, format.profile != H26xProfile::H26xProfile_None)
{
m_pSinkWriter = CustomSinkWriter::CreateForVideo(Thunk_Sink, this, input_subtype, format, stride, encoder_options);
}

// OK
CustomEncoder::~CustomEncoder()
{
if (!m_shift) { return; }
if (m_pMetadataFree) { m_pMetadataFree(m_metadata.get(), m_metadata_size); }
}

// OK
void CustomEncoder::ProcessSample(IMFSample* pSample)
{
UINT32 bCleanPoint = TRUE;
IMFMediaBuffer* pBuffer; // Release
LONGLONG hnsSampleTime;
BYTE* pFrame;
DWORD cbFrameBytes;

pSample->GetUINT32(MFSampleExtension_CleanPoint, &bCleanPoint);

pSample->ConvertToContiguousBuffer(&pBuffer);
pSample->GetSampleTime(&hnsSampleTime);

if (!m_shift) { pSample->GetBlob(MF_USER_DATA_PAYLOAD, m_metadata.get(), m_metadata_size, NULL); }

pBuffer->Lock(&pFrame, NULL, &cbFrameBytes);

m_pHookCallback(pFrame, cbFrameBytes, bCleanPoint, hnsSampleTime, m_metadata.get(), m_metadata_size, m_pHookParam);

pBuffer->Unlock();
pBuffer->Release();

if (m_pMetadataFree) { m_pMetadataFree(m_metadata.get(), m_metadata_size); }

if ( m_shift) { pSample->GetBlob(MF_USER_DATA_PAYLOAD, m_metadata.get(), m_metadata_size, NULL); }
}

// OK
void CustomEncoder::Thunk_Sink(IMFSample* pSample, void* param)
{
static_cast<CustomEncoder*>(param)->ProcessSample(pSample);
}

// OK
void CustomEncoder::CreateBuffer(IMFMediaBuffer** ppBuffer, DWORD size)
{
MFCreateMemoryBuffer(size, ppBuffer);

(*ppBuffer)->SetCurrentLength(size);
}

// OK
void CustomEncoder::WriteBuffer(IMFMediaBuffer* pBuffer, LONGLONG timestamp, LONGLONG duration, void* metadata)
{
IMFSample* pSample; // Release

MFCreateSample(&pSample);

pSample->AddBuffer(pBuffer);
pSample->SetSampleDuration(duration);
pSample->SetSampleTime(timestamp);
pSample->SetBlob(MF_USER_DATA_PAYLOAD, static_cast<UINT8*>(metadata), m_metadata_size);

m_pSinkWriter->WriteSample(pSample);

pSample->Release();
}

// OK
void CustomEncoder_Startup()
{
MFStartup(MF_VERSION);
}

// OK
void CustomEncoder_Cleanup()
{
MFShutdown();
}
40 changes: 40 additions & 0 deletions hl2ss/hl2ss/custom_encoder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

#pragma once

#include "custom_sink_writers.h"

uint8_t const NV12_ZERO_CHROMA = 0x80;

typedef void(*HOOK_ENCODER_PROC)(void*, DWORD, UINT32, LONGLONG, void*, UINT32, void*);
typedef void(*HOOK_METADATA_PROC)(void*, uint32_t);

class CustomEncoder
{
private:
std::unique_ptr<CustomSinkWriter> m_pSinkWriter;
std::unique_ptr<uint8_t[]> m_metadata;
uint32_t m_metadata_size;
bool m_shift;
HOOK_ENCODER_PROC m_pHookCallback;
void* m_pHookParam;
HOOK_METADATA_PROC m_pMetadataFree;

CustomEncoder(HOOK_ENCODER_PROC pHookCallback, void* pHookParam, HOOK_METADATA_PROC pMetadataFree, uint32_t metadata_size, bool shift);

void ProcessSample(IMFSample* pSample);

static void Thunk_Sink(IMFSample* pSample, void* param);

protected:
CustomEncoder(HOOK_ENCODER_PROC pHookCallback, void* pHookParam, HOOK_METADATA_PROC pMetadataFree, uint32_t metadata_size, AudioSubtype input_subtype, AACFormat const& format);
CustomEncoder(HOOK_ENCODER_PROC pHookCallback, void* pHookParam, HOOK_METADATA_PROC pMetadataFree, uint32_t metadata_size, VideoSubtype input_subtype, H26xFormat const& format, uint32_t stride, std::vector<uint64_t> const& encoder_options);

virtual ~CustomEncoder();

void WriteBuffer(IMFMediaBuffer* pBuffer, LONGLONG timestamp, LONGLONG duration, void* metadata);

static void CreateBuffer(IMFMediaBuffer** ppBuffer, DWORD size);
};

void CustomEncoder_Startup();
void CustomEncoder_Cleanup();
131 changes: 0 additions & 131 deletions hl2ss/hl2ss/custom_hook_callback.cpp

This file was deleted.

53 changes: 0 additions & 53 deletions hl2ss/hl2ss/custom_hook_callback.h

This file was deleted.

Loading

0 comments on commit 51daf7a

Please sign in to comment.