Files
UnrealEngineUWP/Engine/Source/Runtime/AVEncoder/Public/IMFSampleWrapper.h
Bryan sefcik b4a6e947d8 Ran IWYU on Public headers under Engine/Source/Runtime/...
Headers are updated to contain any missing #includes needed to compile and #includes are sorted.  Nothing is removed.

#ushell-cherrypick of 21065896 by bryan.sefcik
#preflight 62d4b1a5a6141b6adfb0c892
#jira

#ROBOMERGE-OWNER: Bryan.sefcik
#ROBOMERGE-AUTHOR: bryan.sefcik
#ROBOMERGE-SOURCE: CL 21150156 via CL 21151754 via CL 21154719
#ROBOMERGE-BOT: UE5 (Release-Engine-Staging -> Main) (v972-20964824)
#ROBOMERGE-CONFLICT from-shelf

[CL 21181076 by Bryan sefcik in ue5-main branch]
2022-07-20 11:31:36 -04:00

106 lines
2.0 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "HAL/Platform.h"
#include "MediaPacket.h"
#include "Templates/RefCounting.h"
#include "VideoCommon.h"
#if PLATFORM_WINDOWS
namespace AVEncoder
{
//
// Wrapper for IMFSample, to make it easier to report errors
//
class AVENCODER_API FIMFSampleWrapper
{
public:
FIMFSampleWrapper(EPacketType InMediaType = EPacketType::Invalid, IMFSample* InSample = nullptr)
: MediaType(InMediaType)
, Sample(InSample)
{
}
const IMFSample* GetSample() const
{
return Sample;
}
IMFSample* GetSample()
{
return Sample;
}
bool CreateSample();
FTimespan GetTime() const;
void SetTime(FTimespan Time);
FTimespan GetDuration() const;
void SetDuration(FTimespan Duration);
bool IsVideoKeyFrame() const;
int GetBufferCount() const;
/**
*
* Calls the specified function for each buffer the sample contains
* Signature is "int (int BufferIndex, TArrayView<uint8> Data)
* The specified function should return true if iteration should continue, or false to finish
*
* The return value is what the specified function returned:
* true : Iterated through all the buffers
* false : Early termination
*/
template<typename T>
bool IterateBuffers(T&& Func)
{
int BufferCount = GetBufferCount();
for (int Idx = 0; Idx < BufferCount; ++Idx)
{
TRefCountPtr<IMFMediaBuffer> MediaBuffer = nullptr;
verify(SUCCEEDED(Sample->GetBufferByIndex(0, MediaBuffer.GetInitReference())));
BYTE* SrcData = nullptr;
DWORD MaxLength = 0;
DWORD CurrentLength = 0;
verify(SUCCEEDED(MediaBuffer->Lock(&SrcData, &MaxLength, &CurrentLength)));
bool res = Func(Idx, TArrayView<uint8>(SrcData, CurrentLength));
verify(SUCCEEDED(MediaBuffer->Unlock()));
if (!res)
{
return false;
}
}
return true;
}
bool IsValid() const
{
return Sample.IsValid();
}
void Reset()
{
Sample = nullptr;
}
FIMFSampleWrapper Clone() const;
private:
EPacketType MediaType;
TRefCountPtr<IMFSample> Sample;
};
}
#endif // PLATFORM_WINDOWS