2019-12-26 14:45:42 -05:00
|
|
|
// Copyright Epic Games, Inc. All Rights Reserved.
|
2019-11-26 17:28:51 -05:00
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
2021-04-29 19:32:06 -04:00
|
|
|
#include "MediaPacket.h"
|
2019-11-26 17:28:51 -05:00
|
|
|
#include "Templates/RefCounting.h"
|
2021-05-27 13:40:37 -04:00
|
|
|
#include "VideoCommon.h"
|
2019-11-26 17:28:51 -05:00
|
|
|
|
2022-05-18 11:45:55 -04:00
|
|
|
#if PLATFORM_WINDOWS
|
2019-11-26 17:28:51 -05:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-18 11:45:55 -04:00
|
|
|
#endif // PLATFORM_WINDOWS
|
2019-11-28 08:44:18 -05:00
|
|
|
|