-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #153 from jdibenes/realsense_test
Realsense test
- Loading branch information
Showing
167 changed files
with
8,224 additions
and
6,359 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.