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 /**
     19  * @file pvmf_jitter_buffer_port.h
     20  */
     21 #ifndef PVMF_JITTER_BUFFER_PORT_H_INCLUDED
     22 #define PVMF_JITTER_BUFFER_PORT_H_INCLUDED
     23 
     24 #ifndef OSCL_BASE_H_INCLUDED
     25 #include "oscl_base.h"
     26 #endif
     27 #ifndef OSCL_STRING_CONTAINERS_H_INCLUDED
     28 #include "oscl_string_containers.h"
     29 #endif
     30 #ifndef PVLOGGER_H_INCLUDED
     31 #include "pvlogger.h"
     32 #endif
     33 #ifndef PVMF_PORT_BASE_IMPL_H_INCLUDED
     34 #include "pvmf_port_base_impl.h"
     35 #endif
     36 #ifndef PVMI_CONFIG_AND_CAPABILITY_H_INCLUDED
     37 #include "pvmi_config_and_capability.h"
     38 #endif
     39 #ifndef __MEDIA_CLOCK_CONVERTER_H
     40 #include "media_clock_converter.h"
     41 #endif
     42 #ifndef PVMI_PORT_CONFIG_KVP_H_INCLUDED
     43 #include "pvmi_port_config_kvp.h"
     44 #endif
     45 
     46 #define PVMF_JB_PORT_OVERRIDE 1
     47 
     48 class PVMFJitterBuffer;
     49 
     50 //Default vector reserve size
     51 #define PVMF_JITTER_BUFFER_NODE_PORT_VECTOR_RESERVE 10
     52 
     53 // Capability mime strings
     54 #define PVMF_JITTER_BUFFER_PORT_SPECIFIC_ALLOCATOR          "x-pvmf/pvmfstreaming/socketmemallocator"
     55 #define PVMF_JITTER_BUFFER_PORT_SPECIFIC_ALLOCATOR_VALTYPE  "x-pvmf/pvmfstreaming/socketmemallocator;valtype=ksv"
     56 
     57 /** Enumerated list of port tags supported by this port */
     58 typedef enum
     59 {
     60     PVMF_JITTER_BUFFER_PORT_TYPE_UNKNOWN = -1,
     61     PVMF_JITTER_BUFFER_PORT_TYPE_INPUT = 0,
     62     PVMF_JITTER_BUFFER_PORT_TYPE_OUTPUT = 1,
     63     //Feedback Port: Only used in case of RTSP based streaming to send feedback
     64     //reports (RTCP reports) for the RTP session going on at the input port
     65     PVMF_JITTER_BUFFER_PORT_TYPE_FEEDBACK = 2
     66 } PVMFJitterBufferNodePortTag;
     67 
     68 class PVMFJitterBufferNode;
     69 class PVMFJitterBufferPort;
     70 class PVMFJitterBufferPortParams
     71 {
     72     public:
     73         void ResetParams()
     74         {
     75             iJitterBufferEmpty = false;
     76             iProcessIncomingMessages = true;
     77             iProcessOutgoingMessages = true;
     78             iMonitorForRemoteActivity = true;
     79         };
     80 
     81         PVMFJitterBufferPortParams(PVMFJitterBufferPort& aPort): irPort(aPort)
     82         {
     83             iId = -1;
     84             iTag = PVMF_JITTER_BUFFER_PORT_TYPE_UNKNOWN;
     85 
     86             ipJitterBuffer = NULL;              //Only Input ports will have the jitter buffer associated with them
     87             iTimeScale = 0;
     88             iBitrate = 0;
     89             iLastMsgTimeStamp = 0;
     90             iNumMediaMsgsRecvd = 0;
     91             iNumMediaMsgsSent = 0;
     92             iJitterBufferEmpty = true;
     93             iProcessIncomingMessages = true;
     94             iProcessOutgoingMessages = true;
     95             iCanReceivePktFromJB = false;
     96             iMonitorForRemoteActivity = false;
     97         }
     98 
     99         int32                       iId;
    100         PVMFJitterBufferNodePortTag iTag;
    101         PVMFJitterBufferPort&       irPort;
    102         PVMFJitterBuffer*           ipJitterBuffer;             //Only Input ports will have the jitter buffer associated with them
    103         uint32                      iTimeScale;
    104         uint32                      iBitrate;
    105         MediaClockConverter         iMediaClockConverter;
    106         PVMFTimestamp               iLastMsgTimeStamp;
    107         uint32                      iNumMediaMsgsRecvd;
    108         uint32                      iNumMediaMsgsSent;
    109         bool                        iJitterBufferEmpty;
    110         bool                        iProcessIncomingMessages;
    111         bool                        iProcessOutgoingMessages;
    112         bool                        iCanReceivePktFromJB;
    113         bool                        iMonitorForRemoteActivity;
    114         OSCL_HeapString<OsclMemAllocator> iMimeType;
    115 };
    116 
    117 /**
    118  * Input (sink) ports have a simple flow control scheme.
    119  * Ports report "busy" when their queue is full, then when the
    120  * queue goes to half-empty they issue a "get data" to the connected
    121  * port.  The media message in the "get data" is empty and is
    122  * meant to be discarded.
    123  * Output (source) ports assume the connected port uses the
    124  * same flow-control scheme.
    125  */
    126 class PVMFJitterBufferPort : public PvmfPortBaseImpl,
    127         public PvmiCapabilityAndConfig
    128 {
    129     public:
    130         /**
    131          * Default constructor. Default settings will be used for the data queues.
    132          * @param aId ID assigned to this port
    133          * @param aTag Port tag
    134          * @param aNode Container node
    135          */
    136         PVMFJitterBufferPort(int32 aTag, PVMFJitterBufferNode& aNode, const char*);
    137 
    138         /**
    139          * Constructor that allows the node to configure the data queues of this port.
    140          * @param aTag Port tag
    141          * @param aNode Container node
    142          * @param aSize Data queue capacity. The data queue size will not grow beyond this capacity.
    143          * @param aReserve Size of data queue for which memory is reserved. This must be
    144          * less than or equal to the capacity. If this is less than capacity, memory will be
    145          * allocated when the queue grows beyond the reserve size, but will stop growing at
    146          * capacity.
    147          * @param aThreshold Ready-to-receive threshold, in terms of percentage of the data queue capacity.
    148          * This value should be between 0 - 100.
    149          */
    150         PVMFJitterBufferPort(int32 aTag,
    151                              PVMFJitterBufferNode& aNode,
    152                              uint32 aInCapacity,
    153                              uint32 aInReserve,
    154                              uint32 aInThreshold,
    155                              uint32 aOutCapacity,
    156                              uint32 aOutReserve,
    157                              uint32 aOutThreshold, const char*);
    158 
    159         /** Destructor */
    160         ~PVMFJitterBufferPort();
    161 
    162         /* Over ride Connect() */
    163         PVMFStatus Connect(PVMFPortInterface* aPort);
    164 
    165         /* Over ride QueryInterface - this port supports config interface */
    166         void QueryInterface(const PVUuid &aUuid, OsclAny*&aPtr)
    167         {
    168             if (aUuid == PVMI_CAPABILITY_AND_CONFIG_PVUUID)
    169                 aPtr = (PvmiCapabilityAndConfig*)this;
    170             else
    171                 aPtr = NULL;
    172         }
    173 
    174         // Implement pure virtuals from PvmiCapabilityAndConfig interface
    175         PVMFStatus getParametersSync(PvmiMIOSession aSession, PvmiKeyType aIdentifier,
    176                                      PvmiKvp*& aParameters, int& num_parameter_elements,    PvmiCapabilityContext aContext);
    177         PVMFStatus releaseParameters(PvmiMIOSession aSession, PvmiKvp* aParameters, int num_elements);
    178         void setParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters,
    179                                int num_elements, PvmiKvp * & aRet_kvp);
    180         PVMFStatus verifyParametersSync(PvmiMIOSession aSession, PvmiKvp* aParameters, int num_elements);
    181 
    182         // Unsupported PvmiCapabilityAndConfig methods
    183         void setObserver(PvmiConfigAndCapabilityCmdObserver* aObserver)
    184         {
    185             OSCL_UNUSED_ARG(aObserver);
    186         };
    187         void createContext(PvmiMIOSession aSession, PvmiCapabilityContext& aContext)
    188         {
    189             OSCL_UNUSED_ARG(aSession);
    190             OSCL_UNUSED_ARG(aContext);
    191         };
    192         void setContextParameters(PvmiMIOSession aSession, PvmiCapabilityContext& aContext,
    193                                   PvmiKvp* aParameters, int num_parameter_elements)
    194         {
    195             OSCL_UNUSED_ARG(aSession);
    196             OSCL_UNUSED_ARG(aContext);
    197             OSCL_UNUSED_ARG(aParameters);
    198             OSCL_UNUSED_ARG(num_parameter_elements);
    199         };
    200         void DeleteContext(PvmiMIOSession aSession, PvmiCapabilityContext& aContext)
    201         {
    202             OSCL_UNUSED_ARG(aSession);
    203             OSCL_UNUSED_ARG(aContext);
    204         };
    205         PVMFCommandId setParametersAsync(PvmiMIOSession aSession, PvmiKvp* aParameters,
    206                                          int num_elements, PvmiKvp*& aRet_kvp, OsclAny* context = NULL)
    207         {
    208             OSCL_UNUSED_ARG(aSession);
    209             OSCL_UNUSED_ARG(aParameters);
    210             OSCL_UNUSED_ARG(num_elements);
    211             OSCL_UNUSED_ARG(aRet_kvp);
    212             OSCL_UNUSED_ARG(context);
    213             return -1;
    214         }
    215         uint32 getCapabilityMetric(PvmiMIOSession aSession)
    216         {
    217             OSCL_UNUSED_ARG(aSession);
    218             return 0;
    219         }
    220 
    221 
    222 
    223         PVMFJitterBufferPortParams* GetPortParams()
    224         {
    225             return iPortParams;
    226         }
    227         //overrides from PVMFPortInterface
    228         PVMFStatus QueueOutgoingMsg(PVMFSharedMediaMsgPtr aMsg);
    229         bool IsOutgoingQueueBusy();
    230     private:
    231         void Construct();
    232 
    233         PVMFFormatType                      iFormat;
    234         PVMFJitterBufferNodePortTag         iPortType;
    235         PVMFJitterBufferPortParams*         iPortParams;
    236         // Corresponding port paired with current port
    237         PVMFJitterBufferPort*               iPortCounterpart;
    238         // Parameters of port paired with current port
    239         PVMFJitterBufferPortParams*         iCounterpartPortParams;
    240 
    241         PVMFJitterBufferNode&               irJitterBufferNode;
    242         PVLogger*                           ipLogger;
    243 
    244         friend class PVMFJitterBufferNode;
    245         friend class PVMFJitterBufferExtensionInterfaceImpl;
    246 };
    247 
    248 #endif // PVMF_JITTER_BUFFER_PORT_H_INCLUDED
    249