circularbufferresidentobject.h
来自「C++封装的视频采集代码」· C头文件 代码 · 共 132 行
H
132 行
#ifndef CIRCULARBUFFERRESIDENTOBJECT_H#define CIRCULARBUFFERRESIDENTOBJECT_H#include "CircularBufferPosition.h"#include "CircularBufferSpaceInfo.h"#include "Misc/ObjectPool.h"#include "Misc/PoolableObject.h"namespace oxsemi{ namespace circular_buffer { class CircularBufferResidentObject : public PoolableObject { public: typedef unsigned long Id; class DecodeResult { public: DecodeResult( bool successful, unsigned long bytesConsumed); unsigned long GetBytesConsumed() const { return bytesConsumed_; } bool GetSuccessful() const { return successful_; } private: bool successful_; unsigned long bytesConsumed_; }; class EncodeResult { public: EncodeResult( bool successful, bool skippedFirstSection, unsigned long bytesConsumed); bool GetSkippedFirstSection() const { return skippedFirstSection_; } unsigned long GetBytesConsumed() const { return bytesConsumed_; } bool GetSuccessful() const { return successful_; } private: bool successful_; bool skippedFirstSection_; unsigned long bytesConsumed_; }; /** * Make the association between the passed object and its in-buffer repre- * sentation * * @param writePositionInfo A const CircularBufferSpaceInfo& giving infor- * mation on the write position of the CircularBuffer object into which * this object is to be encoded * @return A EncodeResult indicating how much of the circular * buffer to reserve for this object. */ virtual EncodeResult AssociateWithBuffer(const CircularBufferSpaceInfo& writePositionInfo) = 0; /** * Store the completed object into the circular buffer and make it * available to the readers. Must store the object ID as the first * element written to buffer * * @return A EncodeResult indicating the how much of the circular * buffer to commit to this object */ virtual EncodeResult CommitToBuffer() const = 0; /** * Create an object from its in-buffer representation * * @param readPositionInfo A const CircularBufferSpaceInfo& giving infor- * mation on the read position of the CircularBuffer object from which this * object is to be decoded * @return A DecodeResult indicating the result of the decode operation */ virtual DecodeResult DecodeFromBuffer(const CircularBufferSpaceInfo& readPositionInfo) = 0; virtual unsigned long GetEncodedSize() const = 0; const Id& GetId() const { return id_; } void SetId(const Id& id) { id_ = id; } protected: CircularBufferResidentObject(); private: friend class CircularBuffer; Id id_; ObjectPool* pool_; CircularBufferPosition afterPosition_; CircularBufferResidentObject(const CircularBufferResidentObject&); CircularBufferResidentObject& operator=(const CircularBufferResidentObject&); const CircularBufferPosition& GetAfterPosition() const; ObjectPool* GetPool() const; void SetAfterPosition(const CircularBufferPosition& afterPosition); void SetPool(ObjectPool* pool); /** * The object should not write any data into it's buffer space within * the circular buffer, but should do any calculations required to * return an EncodeResult which contains the same data that it would * if a CommitToBuffer() call had been made. The object should also * update its internal record of how much circular buffer space it's * allocated to reflect the data returned in the EncodeResult * * @return A EncodeResult indicating the how much of the circular * buffer is required by the trimmed object */ virtual EncodeResult TrimBufferUsage() = 0; }; }}#endif // #if !defined(__CIRCULARBUFFERRESIDENTOBJECT_H__)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?