//// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF //// ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO //// THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A //// PARTICULAR PURPOSE. //// //// Copyright (c) Microsoft Corporation. All rights reserved #include #include "FactoryCache.h" #if TV_API namespace Microsoft { namespace Xbox { namespace GameChat { enum JitterBufferState { NeedPackets = 0, Draining }; class IJitterBuffer { public: virtual HRESULT Push( _In_reads_(sourceBufferLengthInBytes) BYTE* sourceBuffer, _In_ UINT sourceBufferLengthInBytes ) = 0; virtual HRESULT GetFront( _Out_ Windows::Storage::Streams::IBuffer^* buffer ) = 0; virtual HRESULT Pop() = 0; virtual UINT GetCurrentPacketCount() = 0; virtual UINT GetLowestNeededPacketCount() = 0; virtual UINT GetMaxPacketsInRingBuffer() = 0; virtual UINT GetDynamicNeededPacketCount() = 0; }; class JitterBuffer : public IJitterBuffer { public: JitterBuffer( _In_ UINT maxBytesInPeriod, _In_ UINT maxPacketsInRingBuffer, _In_ UINT lowestNeededPacketCount, _In_ UINT packetsBeforeRelaxingNeeded, _In_ std::shared_ptr factoryCache ); virtual ~JitterBuffer(); // IJitterBuffer /// /// Title is pushing the next buffer of data. /// virtual HRESULT Push( _In_reads_(sourceBufferLengthInBytes) BYTE* sourceBuffer, _In_ UINT sourceBufferLengthInBytes ); /// /// Title is asking for a reference to the next IBuffer that needs to be rendered. /// virtual HRESULT GetFront( _Out_ Windows::Storage::Streams::IBuffer^* buffer ); /// /// Title is telling the JitterBuffer that it is ok to reuse the last IBuffer that was /// handed down by the Jitter Buffer, essentially advancing the JB ring buffer. /// virtual HRESULT Pop(); /// /// Title can use this property to query the current size/latency, expressed in periods/packets. /// virtual UINT GetCurrentPacketCount(); /// /// Title can use this property to query the min needed packet count, expressed in periods. /// virtual UINT GetLowestNeededPacketCount(); /// /// Title can use this property to query the max packets in the ring buffer, expressed in periods. /// virtual UINT GetMaxPacketsInRingBuffer(); /// /// Title can use this property to query the current dynamic needed packets, expressed in periods. /// virtual UINT GetDynamicNeededPacketCount(); private: // Ring buffer UINT m_maxPacketsInRingBuffer; UINT m_maxBytesInPeriod; std::vector m_ringBuffer; UINT m_readIndex; UINT m_writeIndex; UINT m_currentPacketCount; std::shared_ptr m_factoryCache; // Heuristics UINT m_dynamicNeededPacketCount; UINT m_lowestNeededPacketCount; UINT m_packetsBeforeRelaxingNeeded; UINT m_numberOfPacketsAboveNeededWhileDraining; JitterBufferState m_state; }; }}} #endif