• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 TSC_SRP_BUFFER_H
19 #define TSC_SRP_BUFFER_H
20 
21 #include "oscl_stdstring.h"
22 #include "oscl_types.h"
23 #include "oscl_timer.h"
24 #include "oscl_mem.h"
25 
26 #ifndef OSCL_MEM_MEMPOOL_H_INCLUDED
27 #include "oscl_mem_mempool.h"
28 #endif
29 
30 #ifndef PVMF_PORT_INTERFACE_H_INCLUDED
31 #include "pvmf_port_interface.h"
32 #endif
33 
34 #ifndef PVMF_PORT_BASE_IMPL_H_INCLUDED
35 #include "pvmf_port_base_impl.h"
36 #endif
37 
38 #ifndef PVMF_SIMPLE_MEDIA_BUFFER_H_INCLUDED
39 #include "pvmf_simple_media_buffer.h"
40 #endif
41 
42 #ifndef PVMF_POOL_BUFFER_ALLOCATOR_H_INCLUDED
43 #include "pvmf_pool_buffer_allocator.h"
44 #endif
45 
46 #include "layer.h"
47 #include "pvt_params.h"
48 
49 #include "media_packet.h"
50 
51 #ifndef PVLOGGER_H_INCLUDED
52 #include "pvlogger.h"
53 #endif
54 
55 
56 #define TSCSRPBUFFER_INPUT_PORT_TAG 0
57 #define TSCSRPBUFFER_OUTPUT_PORT_TAG 1
58 
59 class TscSrpBuffer;
60 
61 class TscSrpBufferLLPortOut : public PvmfPortBaseImpl
62 {
63     public:
TscSrpBufferLLPortOut()64         TscSrpBufferLLPortOut() : PvmfPortBaseImpl(TSCSRPBUFFER_OUTPUT_PORT_TAG, NULL) {};
65 
~TscSrpBufferLLPortOut()66         ~TscSrpBufferLLPortOut() {};
67 };
68 
69 class TscSrpBufferLLPortIn : public PvmfPortBaseImpl
70 {
71     public:
72         static TscSrpBufferLLPortIn* NewL(TscSrpBuffer* aTscSrpBuffer);
73 
74         virtual ~TscSrpBufferLLPortIn();
75 
76         virtual PVMFStatus Receive(PVMFSharedMediaMsgPtr aMsg);
77 
78     private:
TscSrpBufferLLPortIn(TscSrpBuffer * aTscSrpBuffer)79         TscSrpBufferLLPortIn(TscSrpBuffer* aTscSrpBuffer) : PvmfPortBaseImpl(TSCSRPBUFFER_INPUT_PORT_TAG, NULL),
80                 iCurSize(0),
81                 iPkt(NULL),
82                 iFrag(NULL),
83                 iMediaFragAlloc(NULL),
84                 iTscSrpBuffer(aTscSrpBuffer)
85         {};
86         static void ConstructSelf(TscSrpBufferLLPortIn* self);
87 
88         void ConstructL();
89 
90         uint32 iCurSize;
91         MediaPacket* iPkt;
92         MediaFragment* iFrag;
93         MediaPacketAllocator iMediaPktAlloc;
94         PoolFragmentAllocator* iMediaFragAlloc;
95         TscSrpBuffer* iTscSrpBuffer;
96 };
97 
98 class TscSrpBuffer : /*public SimpleStackElement, */public OsclTimerObserver
99 {
100     public:
101         typedef enum
102         {
103             TscSrpBufferStopped,
104             TscSrpBufferStarted
105         } TscSrpBufferState;
106 
107         static TscSrpBuffer* NewL();
108 
109         virtual ~TscSrpBuffer();
110 
GetUpperLayer()111         Layer* GetUpperLayer()
112         {
113             return &iH245Interface;
114         }
115 
GetLLPort(const int32 aPortTag)116         PVMFPortInterface* GetLLPort(const int32 aPortTag)
117         {
118             if (aPortTag == TSCSRPBUFFER_INPUT_PORT_TAG)
119             {
120                 return iLLPortIn;
121             }
122             if (aPortTag == TSCSRPBUFFER_OUTPUT_PORT_TAG)
123             {
124                 return iLLPortOut;
125             }
126 
127             return NULL;
128         }
129 
130         void Start();
131         void Stop();
132 
133         void Reset();
134         void EnableBuffering(bool enable);
135 
136         // Receive packet from H245
137         void ProcessOutgoingH245Packet(MediaPacket* pPkt);
138         // Receive packet from SRP
139         void ProcessIncomingSrpPacket(MediaPacket* pPkt);
140 
141         void TimeoutOccurred(int32 timerID, int32 timeoutInfo);
142 
143     private:
144 
145         static void ConstructSelf(TscSrpBuffer* self);
TscSrpBuffer()146         TscSrpBuffer() : iNumMsgs(0),
147                 iTxMediaMsgPoolAlloc(NULL),
148                 iTxMediaDataImplMemAlloc(NULL),
149                 iTxPacketAlloc(NULL),
150                 iTimer(NULL),
151                 iH245Interface(NULL),
152                 iLLPortOut(NULL),
153                 iLLPortIn(NULL),
154                 iLogger(NULL),
155                 iState(TscSrpBufferStarted),
156                 iEnableBuffering(true)
157         {};
158 
159         void ConstructL();
160 
161         uint32 iNumMsgs;
162         OsclMemAllocator iMemAllocator;
163         OsclMemPoolFixedChunkAllocator* iTxMediaMsgPoolAlloc;
164         OsclMemPoolFixedChunkAllocator* iTxMediaDataImplMemAlloc;
165         PVMFSimpleMediaBufferCombinedAlloc* iTxPacketAlloc;
166         OsclTimer<OsclMemAllocator>* iTimer;
167 
168         // Interface with H245
169         class UpperLayer : public Layer, public PacketInput, public PacketOutput
170         {
171             public:
UpperLayer(TscSrpBuffer * parent)172                 UpperLayer(TscSrpBuffer* parent)
173                 {
174                     iParent = parent;
175                 }
GetPacketInput()176                 PacketInput* GetPacketInput()
177                 {
178                     return this;
179                 }
GetPacketOutput()180                 PacketOutput* GetPacketOutput()
181                 {
182                     return this;
183                 }
184 
185                 // Implement PAcketInput: process incoming packet
PacketIn(Packet * pack)186                 void PacketIn(Packet* pack)
187                 {
188                     if (iParent)
189                     {
190                         iParent->ProcessOutgoingH245Packet((MediaPacket*) pack);
191                     }
192                 }
Dispatch(Packet * pack)193                 void Dispatch(Packet* pack)
194                 {
195                     if (pPktOutput) pPktOutput->PacketIn(pack);
196                 }
197 
198             private:
199                 TscSrpBuffer* iParent;
200         };
201 
202         // Interface with SRP
203         class LowerLayer : public Layer, public PacketInput, public PacketOutput
204         {
205             public:
LowerLayer(TscSrpBuffer * parent)206                 LowerLayer(TscSrpBuffer* parent)
207                 {
208                     iParent = parent;
209                 }
GetPacketInput()210                 PacketInput* GetPacketInput()
211                 {
212                     return this;
213                 }
GetPacketOutput()214                 PacketOutput* GetPacketOutput()
215                 {
216                     return this;
217                 }
218 
219                 // Implement PAcketInput: process incoming packet
PacketIn(Packet * pack)220                 void PacketIn(Packet* pack)
221                 {
222                     if (iParent)
223                     {
224                         iParent->ProcessIncomingSrpPacket((MediaPacket*) pack);
225                     }
226                 }
Dispatch(Packet * pack)227                 void Dispatch(Packet* pack)
228                 {
229                     if (pPktOutput) pPktOutput->PacketIn(pack);
230                 }
231             private:
232                 TscSrpBuffer* iParent;
233         };
234 
235 
236         // Data sendto interfaces.
237         // When sending to a lower layer, you are calling that object's upper layer rx,
238         // when sending to an upper layer, you are calling that object's lower layer rx, got it?
239         UpperLayer iH245Interface;
240         PVMFPortInterface* iLLPortOut;
241         PVMFPortInterface* iLLPortIn;
242         PVLogger* iLogger;
243         PVMFSharedMediaDataPtr iTxData;
244         TscSrpBufferState iState;
245         bool iEnableBuffering;
246         friend class TscSrpBufferLLPortIn;
247 };
248 #endif
249