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 #if !defined(ADAPTATION_LAYER_H)
     19 #define ADAPTATION_LAYER_H
     20 #include "oscl_types.h"
     21 #include "oscl_error_codes.h"
     22 #include "pvt_params.h"
     23 #include "h245def.h"
     24 #include "crccheck_cpp.h"
     25 #include "h324utils.h"
     26 
     27 #ifndef PVMF_MEDIA_FRAG_GROUP_H_INCLUDED
     28 #include "pvmf_media_frag_group.h"
     29 #endif
     30 
     31 #ifndef PVMF_POOL_BUFFER_ALLOCATOR_H_INCLUDED
     32 #include "pvmf_pool_buffer_allocator.h"
     33 #endif
     34 
     35 #define DEF_AL2_SN_POS 1
     36 #define DEF_AL3_SN_POS 2
     37 
     38 class IncomingALPduInfo
     39 {
     40     public:
     41         IncomingALPduInfo() : sdu_size(0), crc_error(0), seq_num_error(0) {}
     42         int16 sdu_size;
     43         bool crc_error;
     44         int32 seq_num_error;
     45 };
     46 
     47 class AdaptationLayer
     48 {
     49     public:
     50         AdaptationLayer(TPVDirection dir, uint32 sdu_size, uint32 max_num_sdus): iLogger(NULL)
     51         {
     52             OSCL_UNUSED_ARG(dir);
     53             PVLOGGER_LOGMSG(PVLOGMSG_INST_HLDBG, iLogger, PVLOGMSG_STACK_TRACE, (0, "AdaptationLayer::AdaptationLayer Dir=%d, Sdu Size=%d, Max num sdus=%d", dir, sdu_size, max_num_sdus));
     54             iSduSize = sdu_size;
     55             iMaxNumSdus = max_num_sdus;
     56             iPktNum = 0;
     57         }
     58         virtual ~AdaptationLayer() {}
     59         virtual unsigned GetHdrSz() = 0;
     60         virtual unsigned GetTrlrSz() = 0;
     61         virtual PVMFStatus StartPacket(OsclSharedPtr<PVMFMediaDataImpl>& pkt) = 0;
     62         virtual PVMFStatus CompletePacket(OsclSharedPtr<PVMFMediaDataImpl>& pkt) = 0;
     63         virtual void ParsePacket(OsclSharedPtr<PVMFMediaDataImpl>& pkt, IncomingALPduInfo& info) = 0;
     64         unsigned GetSduSize()
     65         {
     66             return iSduSize;
     67         }
     68         unsigned GetPduSize()
     69         {
     70             return iSduSize + GetHdrSz() + GetTrlrSz();
     71         }
     72         virtual void Construct() = 0;
     73     protected:
     74         uint32 iSduSize;
     75         uint32 iMaxNumSdus;
     76         int32 iPktNum;
     77         PVLogger* iLogger;
     78 };
     79 
     80 class AdaptationLayer1 : public AdaptationLayer
     81 {
     82     public:
     83         AdaptationLayer1(TPVDirection dir, uint32 sdu_size, uint32 max_num_sdus) : AdaptationLayer(dir, sdu_size, max_num_sdus)
     84         {
     85         }
     86         void Construct();
     87 
     88         unsigned GetHdrSz()
     89         {
     90             return 0;
     91         }
     92         unsigned GetTrlrSz()
     93         {
     94             return 0;
     95         }
     96         PVMFStatus StartPacket(OsclSharedPtr<PVMFMediaDataImpl>& /*pkt*/)
     97         {
     98             return PVMFSuccess;
     99         }
    100 
    101         PVMFStatus CompletePacket(OsclSharedPtr<PVMFMediaDataImpl>& pkt);
    102         void ParsePacket(OsclSharedPtr<PVMFMediaDataImpl>& pkt, IncomingALPduInfo& info);
    103 };
    104 
    105 class AdaptationLayer2 : public AdaptationLayer
    106 {
    107     public:
    108         AdaptationLayer2(TPVDirection dir, uint32 sdu_size, uint32 max_num_sdus, bool seqno = false)
    109                 : AdaptationLayer(dir, sdu_size, max_num_sdus),
    110                 iSNPos(0),
    111                 iHdrSz(0),
    112                 iTrlrSz(1)
    113         {
    114             SetSeqnum(seqno);
    115             iSeqNum = 0;
    116         }
    117         void Construct();
    118 
    119         ~AdaptationLayer2()
    120         {
    121         }
    122         inline unsigned GetHdrSz()
    123         {
    124             return iHdrSz;
    125         }
    126         inline unsigned GetTrlrSz()
    127         {
    128             return iTrlrSz;
    129         }
    130         PVMFStatus StartPacket(OsclSharedPtr<PVMFMediaDataImpl>& pkt);
    131         PVMFStatus CompletePacket(OsclSharedPtr<PVMFMediaDataImpl>& pkt);
    132 
    133         void ParsePacket(OsclSharedPtr<PVMFMediaDataImpl>& pkt, IncomingALPduInfo& info);
    134 
    135         void SetSeqnum(bool on_off);
    136     private:
    137         unsigned iSNPos;
    138         unsigned iHdrSz;
    139         unsigned iTrlrSz;
    140         unsigned iSeqNum;
    141         PVMFBufferPoolAllocator iMemFragmentAlloc;
    142         CRC crc;
    143 
    144 };
    145 
    146 class AdaptationLayer3 : public AdaptationLayer
    147 {
    148     public:
    149         AdaptationLayer3(TPVDirection dir, uint32 sdu_size, uint32 max_num_sdus, uint16 snpos)
    150                 : AdaptationLayer(dir, sdu_size, max_num_sdus),
    151                 iSNPos(snpos),
    152                 iHdrSz(snpos),
    153                 iTrlrSz(2)
    154         {
    155             iSeqNum = 0;
    156         }
    157 
    158         ~AdaptationLayer3()
    159         {
    160         }
    161 
    162         void Construct();
    163 
    164         inline unsigned GetHdrSz()
    165         {
    166             return iHdrSz;
    167         }
    168         inline unsigned GetTrlrSz()
    169         {
    170             return iTrlrSz;
    171         }
    172         void SetSeqnumSz(uint16 sz);
    173         PVMFStatus StartPacket(OsclSharedPtr<PVMFMediaDataImpl>& pkt);
    174         PVMFStatus CompletePacket(OsclSharedPtr<PVMFMediaDataImpl>& pkt);
    175 
    176         void ParsePacket(OsclSharedPtr<PVMFMediaDataImpl>& pkt, IncomingALPduInfo& info);
    177     private:
    178         void DRTXSend(int , uint16)
    179         {
    180         }
    181 
    182         void AlDrtxInd()
    183         {
    184         }
    185 
    186         unsigned iSNPos;
    187         unsigned iHdrSz;
    188         unsigned iTrlrSz;
    189         unsigned iSeqNum;
    190         PVMFBufferPoolAllocator iMemFragmentAlloc;
    191 
    192         CRC crc;
    193 };
    194 
    195 
    196 
    197 class AdaptationLayerAlloc
    198 {
    199     public:
    200         static int GetAlIndex(ErrorProtectionLevel_t epl)
    201         {
    202             switch (epl)
    203             {
    204                 case E_EP_LOW:
    205                     return 1;
    206                 case E_EP_MEDIUM:
    207                     return 2;
    208                 case E_EP_HIGH:
    209                     return 3;
    210             }
    211             return 0;
    212         }
    213 
    214         static OsclSharedPtr<AdaptationLayer> GetAdaptationLayer(TPVDirection dir,
    215                 PS_H223LogicalChannelParameters lcnParams,
    216                 uint32 sdu_size,
    217                 uint32 max_num_sdus)
    218         {
    219             uint16 al_index = 0;
    220             uint16 hint = 0;
    221             switch (lcnParams->adaptationLayerType.index)
    222             {
    223                 case 1:
    224                     al_index = 1;
    225                     break;
    226                 case 2:
    227                     al_index = 1;
    228                     break;
    229                 case 3:
    230                     al_index = 2;
    231                     hint = 0;
    232                     break;
    233                 case 4:
    234                     al_index = 2;
    235                     hint = 1;
    236                     break;
    237                 case 5:
    238                     al_index = 3;
    239                     hint = lcnParams->adaptationLayerType.al3->controlFieldOctets;
    240                     break;
    241             }
    242             return GetAdaptationLayer(dir, al_index, sdu_size, max_num_sdus, hint);
    243         }
    244 
    245         static OsclSharedPtr<AdaptationLayer> GetAdaptationLayer(TPVDirection dir,
    246                 uint16 index,
    247                 uint32 sdu_size,
    248                 uint32 max_num_sdus,
    249                 uint16 hint)
    250         {
    251             AdaptationLayer* al = NULL;
    252             void* ptr = NULL;
    253             switch (index)
    254             {
    255                 case 1:
    256                     ptr = OSCL_DEFAULT_MALLOC(sizeof(AdaptationLayer1));
    257                     al = new(ptr)AdaptationLayer1(dir, sdu_size, max_num_sdus);
    258                     break;
    259                 case 2:
    260                     ptr = OSCL_DEFAULT_MALLOC(sizeof(AdaptationLayer2));
    261                     al = new(ptr)AdaptationLayer2(dir, sdu_size, max_num_sdus, (hint ? true : false));
    262                     break;
    263                 case 3:
    264                     ptr = OSCL_DEFAULT_MALLOC(sizeof(AdaptationLayer3));
    265                     al = new(ptr)AdaptationLayer3(dir, sdu_size, max_num_sdus, hint);
    266                     break;
    267                 default:
    268                     OSCL_LEAVE(OsclFailure);
    269             }
    270             al->Construct();
    271             OsclRefCounterSA<Oscl_TAlloc<AdaptationLayer, BasicAlloc> > *alRefCounter =
    272                 new OsclRefCounterSA<Oscl_TAlloc<AdaptationLayer, BasicAlloc> >(ptr);
    273 
    274             OsclSharedPtr<AdaptationLayer> alPtr(al, alRefCounter);
    275 
    276             return alPtr;
    277         }
    278 
    279         static uint16 GetHdrSz(int index)
    280         {
    281             switch (index)
    282             {
    283                 case 0:
    284                 case 1:
    285                 case 2:
    286                 case 3:
    287                     return 0;
    288                 case 4:
    289                     return 1;
    290                 case 5:
    291                     return 2;
    292             }
    293             return 0;
    294         }
    295         static int GetTrlrSz(int index)
    296         {
    297             switch (index)
    298             {
    299                 case 0:
    300                 case 1:
    301                 case 2:
    302                     return 0;
    303                 case 3:
    304                 case 4:
    305                     return 1;
    306                 case 5:
    307                     return 2;
    308             }
    309             return 0;
    310         }
    311 };
    312 
    313 #endif
    314