• 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 #if !defined(PDU_PARCOM_H)
19 #define PDU_PARCOM_H
20 #include "oscl_base.h"
21 #include "oscl_mem.h"
22 #include "media_fragment.h"
23 #include "media_packet.h"
24 #include "golay.h"
25 #include "oscl_time.h"
26 #include "oscl_rand.h"
27 #include "h324utils.h"
28 #include "h223types.h"
29 
30 #ifndef PVMF_MEDIA_FRAG_GROUP_H_INCLUDED
31 #include "pvmf_media_frag_group.h"
32 #endif
33 
34 #ifndef PVMF_POOL_BUFFER_ALLOCATOR_H_INCLUDED
35 #include "pvmf_pool_buffer_allocator.h"
36 #endif
37 
38 #ifndef PVLOGGER_H_INCLUDED
39 #include "pvlogger.h"
40 #endif
41 
42 typedef enum
43 {
44     EHeaderErr = 0,
45     ESizeErr
46 } EMuxPduError;
47 
48 class H223PduParcomObserver
49 {
50     public:
~H223PduParcomObserver()51         virtual ~H223PduParcomObserver() {}
52         virtual uint32 MuxPduIndicate(uint8* pPdu, uint32 pduSz, int32 fClosing, int32 muxCode) = 0;
53         virtual void MuxPduErrIndicate(EMuxPduError err) = 0;
54         virtual void MuxSetupComplete(PVMFStatus status, TPVH223Level level) = 0;
55 };
56 
57 class H223PduParcom
58 {
59     public:
~H223PduParcom()60         virtual ~H223PduParcom() {}
61 
62         /**
63          * Returns the level associated with this parcom.
64          **/
65         virtual TPVH223Level GetLevel() = 0;
66 
67         /**
68          * Constructs the parcom based on max_outstanding_pdus.
69          **/
70         virtual void Construct(uint16 max_outstanding_pdus) = 0;
71         /**
72          * Sets the base parcom observer.
73          **/
74         virtual void SetObserver(H223PduParcomObserver* observer) = 0;
75         /**
76          * Copies one stuffing sequence into the provided buffer.
77          * @param buf The buffer to be used.
78          * @param buf_size The maximum size of the buffer.
79          * @param mux_code The multiplex code to be used in the stuffing header (may not apply for some parcoms)
80          * @return The number of bytes copied.
81          **/
82         virtual uint32 GetStuffing(uint8* buf, uint32 buf_size, uint8 mux_code = 0) = 0;
83 
84         /**
85          * @return The size of the header field.
86          **/
87         virtual uint32 GetHeaderSz() = 0;
88 
89         /**
90          * Returns the stuffing size.
91          * @return The size of the stuffing sequence.
92          **/
93         virtual uint32 GetStuffingSz() = 0;
94 
95         /**
96          * Parses the bitstream and returns pdus using the MuxPduIndicate observer callback.
97          * @param buf The buffer to be used.
98          * @param buf_size The maximum size of the buffer.
99          * @param mux_code The multiplex code to be used in the stuffing header (may not apply for some parcoms)
100          * @return The number of bytes copied.
101          **/
102         virtual uint32 Parse(uint8* buffer, uint32 buffer_size) = 0;
103 
104         /**
105          * Returns a header fragment.
106          * @param frag The buffer to be used.
107          * @param buf_size The maximum size of the buffer.
108          * @param mux_code The multiplex code to be used in the stuffing header (may not apply for some parcoms)
109          * @return The number of bytes copied.
110          **/
111         virtual void GetHdrFragment(OsclRefCounterMemFrag& frag) = 0;
112 
113         /**
114          * Completes a pdu (sets the header and trailer info if any).
115          * @param pdu The pdu to be completed.
116          * @param mux_code The multiplex code for this pdu.
117          * @param packet_marker The packet marker field.
118          * @return The return status.
119          **/
120         virtual PVMFStatus CompletePdu(OsclSharedPtr<PVMFMediaDataImpl>& pdu, int8 mux_code, uint8 packet_marker) = 0;
121 
122         virtual void ResetStats() = 0;
123         virtual void LogStats(TPVDirection dir) = 0;
124 };
125 
126 typedef OsclSharedPtr<H223PduParcom> H223PduParcomSharedPtr;
127 
128 /** Base implementation with some common features to Level0,1,2. **/
129 class H223PduParcomBase : public H223PduParcom
130 {
131     public:
H223PduParcomBase()132         H223PduParcomBase():
133                 iObserver(NULL),
134                 iLogger(NULL),
135                 iPduEndPos(NULL)
136         {
137             iPduPos = iPdu;
138             iPduEndPos = &iPdu[H223_MAX_DEMUX_PDU_SIZE-1];
139         }
140 
SetObserver(H223PduParcomObserver * observer)141         void SetObserver(H223PduParcomObserver* observer)
142         {
143             iObserver = observer;
144         }
145 
146         void ResetStats();
147         void LogStats(TPVDirection dir);
148     protected:
149         H223PduParcomObserver* iObserver;
150         PVLogger* iLogger;
151 
152         uint8 iPdu[H223_MAX_DEMUX_PDU_SIZE];
153         uint8* iPduPos;
154         uint8* iPduEndPos;
155 
156         // Outgoing
157         uint32 iNumFlagsTx;
158         uint32 iNumStuffingTx;
159         uint32 iNumPdusTx;
160 
161         // Incoming
162         uint32 iNumFlagsRx;
163         uint32 iNumStuffingRx;
164         uint32 iNumPdusRx;
165         uint32 iNumPmRx;
166 
167         uint32 iNumFlagErrorsRx;
168         uint32 iCumFlagErrorsRx;
169         uint32 iNumSyncLossRx;
170         uint32 iNumBytesLossRx;
171         uint32 iNumPduHdrErrorRx;
172         uint32 iCumPduHdrErrorRx;
173 };
174 
175 class PduParcomRefCounter: public OsclRefCounter
176 {
177     public:
PduParcomRefCounter(H223PduParcom * p)178         PduParcomRefCounter(H223PduParcom* p): ptr(p), refcnt(1) {}
179 
addRef()180         void addRef()
181         {
182             ++refcnt;
183         }
184 
removeRef()185         void removeRef()
186         {
187             --refcnt;
188             if (refcnt == 0)
189             {
190                 if (ptr)
191                 {
192                     delete ptr;
193                 }
194                 delete this;
195             }
196         }
197 
getCount()198         uint32 getCount()
199         {
200             return refcnt;
201         }
202     private:
203         H223PduParcom* ptr;
204         uint32 refcnt;
205 };
206 
207 #endif
208