2022-06-11 23:01:27 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2022 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: IOPipeProcessor.hpp
|
|
|
|
Date: 2022-6-6
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#pragma once
|
|
|
|
|
2022-12-06 22:53:37 +00:00
|
|
|
#include <Aurora/Utility/ThroughputCalculator.hpp>
|
|
|
|
|
2022-06-11 23:01:27 +00:00
|
|
|
namespace Aurora::IO
|
|
|
|
{
|
2022-06-21 04:49:36 +00:00
|
|
|
struct IOProcessor;
|
2022-08-28 19:02:06 +00:00
|
|
|
struct IOPipeWork;
|
|
|
|
struct IOPipeProcessor;
|
|
|
|
|
|
|
|
struct IOWorkStart : IIOProcessorWorkUnit
|
|
|
|
{
|
|
|
|
IOWorkStart(IOPipeWork *parent);
|
|
|
|
|
|
|
|
void OnRun() override;
|
|
|
|
void OnCanceled() override;
|
|
|
|
|
|
|
|
IOPipeWork *parent {};
|
|
|
|
};
|
|
|
|
|
|
|
|
struct IOWorkEnd : IIOProcessorWorkUnit
|
|
|
|
{
|
|
|
|
IOWorkEnd(IOPipeWork *parent);
|
|
|
|
|
|
|
|
void OnRun() override;
|
|
|
|
void OnCanceled() override;
|
|
|
|
|
|
|
|
IOPipeWork *parent {};
|
|
|
|
};
|
|
|
|
|
2023-10-16 00:37:59 +00:00
|
|
|
struct IOPipeWork :
|
|
|
|
IIOPipeWork,
|
|
|
|
IIOEventListenerFunctional,
|
|
|
|
AuEnableSharedFromThis<IIOPipeWork>
|
2022-08-28 19:02:06 +00:00
|
|
|
{
|
2022-08-29 15:46:46 +00:00
|
|
|
IOPipeWork(const AuSPtr<IOPipeProcessor> &pParent, const IOPipeRequestAIO &request);
|
|
|
|
IOPipeWork(const AuSPtr<IOPipeProcessor> &pParent, const IOPipeRequestBasic &request);
|
2022-08-28 19:02:06 +00:00
|
|
|
|
2022-08-29 15:46:46 +00:00
|
|
|
AuSPtr<IIOProcessorItem> pWatch;
|
2022-08-28 19:02:06 +00:00
|
|
|
|
|
|
|
void Tick_FrameEpilogue() override;
|
|
|
|
void Tick_Any() override;
|
|
|
|
|
|
|
|
void OnFailureCompletion() override;
|
|
|
|
void OnNominalCompletion() override;
|
|
|
|
|
|
|
|
virtual bool Start() override;
|
|
|
|
|
|
|
|
virtual bool End() override;
|
|
|
|
|
2022-12-06 22:53:37 +00:00
|
|
|
virtual AuInt64 GetLastTickMS() override;
|
|
|
|
virtual AuInt64 GetStartTickMS() override;
|
|
|
|
|
|
|
|
virtual AuUInt64 GetBytesProcessed() override;
|
2023-04-25 05:36:31 +00:00
|
|
|
virtual AuUInt64 GetBytesProcessedInterframe() override;
|
2022-12-06 22:53:37 +00:00
|
|
|
|
|
|
|
virtual double GetPredictedThroughput() override;
|
|
|
|
|
2023-10-16 00:37:59 +00:00
|
|
|
virtual AuUInt SetNextFrameTargetLength(AuUInt uLength) override;
|
|
|
|
|
|
|
|
virtual AuUInt GetNextFrameTargetLength() override;
|
|
|
|
|
|
|
|
virtual bool ReallocateLater(AuUInt uLength) override;
|
|
|
|
|
|
|
|
virtual bool IsReallocationPending() override;
|
|
|
|
|
|
|
|
virtual bool DidLastReallocFail() override;
|
|
|
|
|
|
|
|
virtual AuUInt GetSuccessfulReallocations() override;
|
|
|
|
|
|
|
|
virtual AuUInt GetFailedReallocations() override;
|
|
|
|
|
|
|
|
virtual void RunOnThread();
|
|
|
|
virtual void TerminateOnThread(bool bError = false);
|
2022-08-28 19:02:06 +00:00
|
|
|
|
|
|
|
// INIT
|
|
|
|
void PrepareStream();
|
|
|
|
void PrepareAsync();
|
|
|
|
|
|
|
|
// PUMP
|
|
|
|
void AsyncPump();
|
|
|
|
void StreamPump();
|
|
|
|
|
|
|
|
// END/INIT
|
|
|
|
void ReadNext();
|
|
|
|
void ReadNextAsync();
|
|
|
|
|
|
|
|
AuUInt32 TryPump();
|
|
|
|
|
2023-10-16 00:37:59 +00:00
|
|
|
void DoReallocTick();
|
|
|
|
void FailRealloc();
|
2023-10-16 03:03:19 +00:00
|
|
|
void SuccessRealloc();
|
2023-10-16 00:37:59 +00:00
|
|
|
|
|
|
|
AuUInt GetNextFrameLength(AuUInt uBytesMax);
|
|
|
|
AuUInt GetNextFrameLength2();
|
|
|
|
|
2022-08-28 19:02:06 +00:00
|
|
|
AuMemoryViewWrite nextWriteAsync_;
|
|
|
|
IOPipeRequest request {};
|
2024-09-21 09:42:44 +00:00
|
|
|
bool bShouldReadNext { false };
|
|
|
|
bool bShouldBypassIOWatch { false };
|
2022-08-28 19:02:06 +00:00
|
|
|
|
|
|
|
bool IsAtRequestedEnd();
|
|
|
|
AuByteBuffer *GetBuffer();
|
|
|
|
|
2022-11-07 13:34:28 +00:00
|
|
|
AuSPtr<Protocol::IProtocolStack> pProtocolStack;
|
|
|
|
|
2022-08-28 19:02:06 +00:00
|
|
|
private:
|
|
|
|
AuSPtr<IOPipeProcessor> parent_;
|
|
|
|
|
|
|
|
struct /*not a union. the following members are mutex*/
|
|
|
|
{
|
|
|
|
IOPipeInputData input_;
|
2022-08-29 15:46:46 +00:00
|
|
|
AuSPtr<IAsyncTransaction> pAsyncTransaction_;
|
2023-09-23 15:40:13 +00:00
|
|
|
AuSPtr<Adapters::IAsyncStreamAdapter> pAsyncAdapter_;
|
|
|
|
AuSPtr<Adapters::IAsyncStreamReader> pAsyncStreamReader_;
|
2022-08-28 19:02:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
IOPipeCallback output;
|
|
|
|
IOWorkStart startCallback;
|
|
|
|
IOWorkEnd endCallback;
|
2022-12-06 22:53:37 +00:00
|
|
|
AuUInt64 iStartTickMS_ {};
|
2022-08-28 19:02:06 +00:00
|
|
|
bool bActive {true};
|
2022-08-29 15:46:46 +00:00
|
|
|
AuUInt32 uBufferSize_ {};
|
|
|
|
AuUInt32 uFrameCap_ {};
|
|
|
|
AuUInt uBytesWritten_ {};
|
|
|
|
AuUInt uBytesWrittenLimit_ {};
|
2022-11-20 10:31:13 +00:00
|
|
|
AuUInt uBytesWrittenTarget_ {};
|
2023-10-16 00:37:59 +00:00
|
|
|
AuUInt uBytesPerFrame_ {};
|
2024-09-17 17:23:49 +00:00
|
|
|
bool bReadEntireAllocation_ {};
|
2022-08-28 19:02:06 +00:00
|
|
|
AuByteBuffer buffer_;
|
2023-09-28 14:42:09 +00:00
|
|
|
Aurora::Utility::ThroughputCalculator throughput_;
|
2023-04-25 05:36:31 +00:00
|
|
|
AuUInt bytesProcessedInterframe_ {};
|
2023-05-11 15:05:00 +00:00
|
|
|
bool bWritingAheadLowLatency {};
|
|
|
|
bool bWritingAheadIOUOneTerminate {};
|
2023-10-16 00:37:59 +00:00
|
|
|
AuUInt uPendingRealloc_ {};
|
|
|
|
AuUInt uReallocs_[2] { 0, 0 };
|
|
|
|
bool bLastReallocFail { true };
|
2022-08-28 19:02:06 +00:00
|
|
|
};
|
|
|
|
|
2022-06-11 23:01:27 +00:00
|
|
|
|
2022-06-21 04:49:36 +00:00
|
|
|
struct IOPipeProcessor : IIOPipeProcessor
|
|
|
|
{
|
|
|
|
IOPipeProcessor(IOProcessor *parent);
|
|
|
|
|
|
|
|
virtual AuSPtr<IIOPipeWork> NewBasicPipe(const IOPipeRequestBasic &request) override;
|
|
|
|
|
|
|
|
virtual AuSPtr<IIOPipeWork> NewAIOPipe(const IOPipeRequestAIO &request) override;
|
|
|
|
|
|
|
|
IOProcessor *parent_;
|
|
|
|
};
|
2022-06-11 23:01:27 +00:00
|
|
|
}
|