Home | History | Annotate | Download | only in include
      1 /* ------------------------------------------------------------------
      2  * Copyright (C) 1998-2009 PacketVideo
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
     13  * express or implied.
     14  * See the License for the specific language governing permissions
     15  * and limitations under the License.
     16  * -------------------------------------------------------------------
     17  */
     18 #ifndef PVMF_JB_JITTERBUFFERMISC_H_INCLUDED
     19 #define PVMF_JB_JITTERBUFFERMISC_H_INCLUDED
     20 
     21 #ifndef PVMF_MEDIA_CLOCK_H_INCLUDED
     22 #include "pvmf_media_clock.h"
     23 #endif
     24 
     25 #ifndef PVMF_JB_EVENT_NOTIFIER_H
     26 #include "pvmf_jb_event_notifier.h"
     27 #endif
     28 
     29 #ifndef PVMF_JB_SESSION_DURATION_TIMER_H_INCLUDED
     30 #include "pvmf_jb_session_duration_timer.h"
     31 #endif
     32 
     33 #ifndef OSCL_MEM_H_INCLUDED
     34 #include "oscl_mem.h"
     35 #endif
     36 
     37 #ifndef PVMF_RTCP_PROTO_IMPL_H_INCLUDED
     38 #include "pvmf_rtcp_proto_impl.h"
     39 #endif
     40 
     41 #ifndef PVMFFIREWALLPKTS_H_INCLUDED
     42 #include "pvmf_jb_firewall_pkts_impl.h"
     43 #endif
     44 
     45 #ifndef PVMF_JITTER_BUFFER_PORT_H_INCLUDED
     46 #include "pvmf_jitter_buffer_port.h"
     47 #endif
     48 
     49 #ifndef RTSP_TIME_FORMAT_H
     50 #include "rtsp_time_formats.h"
     51 #endif
     52 
     53 class PVLogger;
     54 
     55 class PVMFJitterBufferMiscObserver
     56 {
     57     public:
     58         virtual void MessageReadyToSend(PVMFPortInterface*& aPort, PVMFSharedMediaMsgPtr& aMessage) = 0;
     59         virtual void MediaReceivingChannelPrepared(bool aStatus) = 0;
     60         virtual void ProcessRTCPControllerEvent(PVMFAsyncEvent& aEvent) = 0;
     61         virtual void SessionSessionExpired() = 0;
     62 };
     63 
     64 class PVMFJitterBufferMisc: public PVRTCPProtoImplementorObserver
     65         , public PVMFJBEventNotifierObserver
     66         , public PvmfJBSessionDurationTimerObserver
     67 {
     68     public:
     69         OSCL_IMPORT_REF static PVMFJitterBufferMisc* New(PVMFJitterBufferMiscObserver* aObserver, PVMFMediaClock& aClientPlaybackClock, Oscl_Vector<PVMFJitterBufferPortParams*, OsclMemAllocator>& aPortParamsQueue);
     70         OSCL_IMPORT_REF virtual ~PVMFJitterBufferMisc();
     71         OSCL_IMPORT_REF void StreamingSessionStarted();
     72         OSCL_IMPORT_REF void StreamingSessionStopped();
     73         OSCL_IMPORT_REF void StreamingSessionPaused();
     74         OSCL_IMPORT_REF void StreamingSessionBufferingStart();
     75         OSCL_IMPORT_REF void StreamingSessionBufferingEnd();
     76 
     77         OSCL_IMPORT_REF void SetBroadcastSession();
     78 
     79         OSCL_IMPORT_REF void ResetEstimatedServerClock();
     80 
     81         OSCL_IMPORT_REF bool PrepareForRepositioning(bool oUseExpectedClientClockVal, uint32 aExpectedClientClockVal);
     82         OSCL_IMPORT_REF bool PurgeElementsWithNPTLessThan(NptTimeFormat &aNPTTime);
     83 
     84         OSCL_IMPORT_REF bool IsSessionExpired();
     85 
     86         OSCL_IMPORT_REF void Prepare();
     87         OSCL_IMPORT_REF void Reset();
     88 
     89         OSCL_IMPORT_REF PVMFStatus PrepareMediaReceivingChannel();
     90         OSCL_IMPORT_REF PVMFStatus CancelMediaReceivingChannelPreparation();
     91 
     92         OSCL_IMPORT_REF PVMFStatus ProcessFeedbackMessage(PVMFJitterBufferPortParams& aParam, PVMFSharedMediaMsgPtr aMsg);
     93         OSCL_IMPORT_REF void SetRateAdaptationInfo(PVMFPortInterface* aPort, bool aRateAdaptation, uint32 aRateAdaptationFeedBackFrequency, uint32 aRateAdaptationFreeBufferSpaceInBytes = 0);
     94         OSCL_IMPORT_REF void SetRTCPIntervalInMicroSecs(uint32 aRTCPInterval);
     95         OSCL_IMPORT_REF bool SetPortRTCPParams(PVMFPortInterface* aPort, int aNumSenders, uint32 aRR, uint32 aRS);
     96         OSCL_IMPORT_REF bool ResetSession();
     97         OSCL_IMPORT_REF bool SetSessionDurationExpired();
     98 
     99         OSCL_IMPORT_REF void MediaReceivingChannelPreparationRequired(bool aRequired);
    100         OSCL_IMPORT_REF PVMFMediaClock& GetEstimatedServerClock();
    101         OSCL_IMPORT_REF PVMFJBEventNotifier* GetEventNotifier();
    102 
    103         OSCL_IMPORT_REF bool SetPlayRange(int32 aStartTimeInMS,
    104                                           int32 aStopTimeInMS,
    105                                           bool aPlayAfterASeek,
    106                                           bool aStopTimeAvailable);
    107 
    108         OSCL_IMPORT_REF void SetPortSSRC(PVMFPortInterface* aPort, uint32 aSSRC);
    109 
    110         OSCL_IMPORT_REF uint32 GetEstimatedServerClockValue();
    111 
    112         OSCL_IMPORT_REF bool PlayStopTimeAvailable() const;
    113 
    114         OSCL_IMPORT_REF void SetServerInfo(PVMFJitterBufferFireWallPacketInfo& aServerInfo);
    115 
    116         OSCL_IMPORT_REF PVMFTimestamp GetMaxMediaDataTS();
    117         OSCL_IMPORT_REF PVMFTimestamp GetActualMediaDataTSAfterSeek();
    118 
    119         OSCL_IMPORT_REF void SetMediaClockConverter(PVMFPortInterface* apPort, MediaClockConverter* apMediaClockConverter);
    120         OSCL_IMPORT_REF void ProcessFirstPacketAfterSeek();
    121 
    122         void ProcessCallback(CLOCK_NOTIFICATION_INTF_TYPE aClockNotificationInterfaceType, uint32 aCallBkId, const OsclAny* aContext, PVMFStatus aStatus);
    123         virtual void PVMFJBSessionDurationTimerEvent();
    124         PVMFStatus RTCPPacketReceived(RTCPPacketType aPacketType, PVRTCPChannelController* aController);
    125         PVMFStatus RTCPReportReadyToSend(PVMFPortInterface*& aPort, PVMFSharedMediaMsgPtr& aMessage);
    126         PVMFStatus ProcessInfoEvent(PVMFAsyncEvent& aEvent);
    127         void LogClientAndEstimatedServerClock(PVLogger* aLogger);
    128 
    129     private:
    130         PVMFJitterBufferMisc(PVMFJitterBufferMiscObserver* aObserver, PVMFMediaClock& aClientPlaybackClock, Oscl_Vector<PVMFJitterBufferPortParams*, OsclMemAllocator>& aPortParamsQueue):
    131                 irClientPlaybackClock(aClientPlaybackClock)
    132                 , ipObserver(aObserver)
    133                 , irPortParamsQueue(aPortParamsQueue)
    134                 , ipSessionDurationTimer(NULL)
    135                 , ipEventNotifier(NULL)
    136                 , ipRTCPProtoImplementator(NULL)
    137                 , ipFireWallPacketExchangerImpl(NULL)
    138                 , ipEstimatedServerClock(NULL)
    139                 , ipWallClock(NULL)
    140                 , ipNonDecreasingClock(NULL)
    141                 , ipJBEventsClockLogger(NULL)
    142                 , ipClockLoggerSessionDuration(NULL)
    143                 , ipClockLogger(NULL)
    144                 , ipDataPathLoggerIn(NULL)
    145                 , ipDataPathLoggerOut(NULL)
    146                 , ipDataPathLoggerRTCP(NULL)
    147                 , ipLogger(NULL)
    148         {
    149             ResetParams(false);
    150         }
    151 
    152         void Construct();
    153         bool CreateProtocolObjects();
    154         bool LookupRTCPChannelParams(PVMFPortInterface* rtpPort, PVMFPortInterface*& rtcpPort, PVMFJitterBuffer*& rtpPktJitterBuffer);
    155         bool LocateFeedBackPort(PVMFJitterBufferPortParams*& aInputPortParamsPtr, PVMFJitterBufferPortParams*& aFeedBackPortParamsPtr);
    156         bool FirewallPacketExchangerRequired() const;
    157         bool RTCPProtocolImplementorRequired() const;
    158 
    159         void ResetParams(bool aReleaseMemory = true);
    160         void ComputeCurrentSessionDurationMonitoringInterval()
    161         {
    162             /* Restart the session duration timer after accounting for any elapsed time */
    163             uint64 elapsedTime = ipSessionDurationTimer->GetMonitoringIntervalElapsed();
    164             uint32 elapsedTime32 = Oscl_Int64_Utils::get_uint64_lower32(elapsedTime);
    165             ipSessionDurationTimer->UpdateElapsedSessionDuration(elapsedTime32);
    166             uint32 totalSessionDuration = ipSessionDurationTimer->getSessionDurationInMS();
    167             uint32 elapsedSessionDuration = ipSessionDurationTimer->GetElapsedSessionDurationInMS();
    168             uint32 interval = (totalSessionDuration - elapsedSessionDuration);
    169             if (interval > PVMF_JITTER_BUFFER_NODE_SESSION_DURATION_MONITORING_INTERVAL_MAX_IN_MS)
    170             {
    171                 interval = PVMF_JITTER_BUFFER_NODE_SESSION_DURATION_MONITORING_INTERVAL_MAX_IN_MS;
    172             }
    173             ipSessionDurationTimer->setCurrentMonitoringIntervalInMS(interval);
    174             PVMF_JB_LOGCLOCK_SESSION_DURATION((0, "PVMFJBN::ComputeCurrentSessionDurationMonitoringInterval - TotalDuration=%d, ElapsedDuration=%d, CurrMonitoringInterval=%d", totalSessionDuration, elapsedSessionDuration, interval));
    175         }
    176 
    177         PVMFMediaClock&     irClientPlaybackClock;      //Reference to the client playback clock passed on by its observer.
    178         PVMFJitterBufferMiscObserver*   ipObserver;
    179         Oscl_Vector<PVMFJitterBufferPortParams*, OsclMemAllocator>& irPortParamsQueue;
    180 
    181         Oscl_Vector<RTPSessionInfoForFirewallExchange, OsclMemAllocator> iRTPExchangeInfosForFirewallExchange;
    182         struct RateAdapatationInfo
    183         {
    184             RateAdapatationInfo(): iPort(NULL) {}
    185             PVMFPortInterface* iPort;
    186             RTPRateAdaptationInfo iRateAdapatationInfo;
    187         };
    188         Oscl_Vector<RateAdapatationInfo, OsclMemAllocator> iRateAdaptationInfos;
    189 
    190         struct RTCPParams
    191         {
    192             RTCPParams(): iFeedbackPort(NULL), iNumSenders(0), iRR(0), iRS(0) {}
    193             PVMFPortInterface* iFeedbackPort;
    194             int iNumSenders;
    195             uint32 iRR;
    196             uint32 iRS;
    197         };
    198         Oscl_Vector<RTCPParams, OsclMemAllocator> iRTCPParamsVect;
    199 
    200         //Sesion Info
    201         uint32  iSessionDuration;
    202         bool    iStreamingSessionExpired;
    203         bool    iPlayDurationAvailable;
    204         bool    iBroadcastSession;
    205 
    206         bool UseSessionDurationTimerForEOS();
    207         bool iUseSessionDurationTimerForEOS;
    208 
    209         uint32  iPlayStartTimeInMS;
    210         uint32  iPlayStopTimeInMS;
    211         bool    iPlayStopTimeAvailable;
    212 
    213         bool    iFireWallPacketsExchangeEnabled;
    214 
    215         bool   iEstimatedServerClockUpdateCallbackPending;
    216         uint32 iEstimatedServerClockUpdateCallbackId;
    217 
    218         PvmfJBSessionDurationTimer*     ipSessionDurationTimer;
    219         PVMFJBEventNotifier*            ipEventNotifier;
    220         PVRTCPProtoImplementor*         ipRTCPProtoImplementator;
    221         PVFirewallPacketExchangeImpl*   ipFireWallPacketExchangerImpl;
    222 
    223         PVMFMediaClock*     ipEstimatedServerClock;     //Estimation of the estimated server clock.
    224         PVMFMediaClock*     ipWallClock;                //A continously increasing clock.
    225         PVMFMediaClock*     ipNonDecreasingClock;       //Always increasing clock but may not be continous (may get pasued in between depending on the state of the streaming session)
    226         PVMFTimebase_Tickcount iEstimatedServerClockTimeBase;
    227         PVMFTimebase_Tickcount iWallClockTimeBase;
    228         PVMFTimebase_Tickcount iNonDecreasingTimeBase;
    229 
    230         PVLogger* ipJBEventsClockLogger;
    231         PVLogger* ipRTCPDataPathLoggerIn;
    232         PVLogger* ipClockLoggerSessionDuration;
    233         PVLogger* ipClockLoggerRebuff;
    234         PVLogger* ipClockLogger;
    235         PVLogger* ipDataPathLoggerIn;
    236         PVLogger* ipDataPathLoggerOut;
    237         PVLogger* ipDataPathLoggerRTCP;
    238         PVLogger* ipLogger;
    239 };
    240 
    241 #endif
    242