Home | History | Annotate | Download | only in src
      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 // -*- c++ -*-
     19 #ifndef ACCESS_UNIT_H
     20 #define ACCESS_UNIT_H
     21 
     22 #include "oscl_media_data.h"
     23 
     24 // Constants controlling the size of the AU container
     25 const int AU_MAX_FRAGMENTS = 30;
     26 const int AU_IMMEDIATE_DATA = 1500;
     27 
     28 const int DEF_AU_FRAGS = 10;
     29 const int DEF_AU_IMMEDIATE_DATA = 100;
     30 
     31 class AccessUnitImplementation;
     32 
     33 typedef MemAllocator<AccessUnitImplementation> AUImplAllocator;
     34 
     35 class AccessUnit
     36 {
     37     public:
     38 
     39         OSCL_IMPORT_REF AccessUnit(AUImplAllocator* in_alloc, void *hint = 0, const int num_reserved_frags = 1);
     40         OSCL_IMPORT_REF ~AccessUnit();
     41 
     42 
     43         OSCL_IMPORT_REF MediaStatusClass::status_t AddAUFrag(const BufferFragment& frag, BufferState* buffer_state,
     44                 int32 location_offset = APPEND_MEDIA_AT_END);
     45 
     46         OSCL_IMPORT_REF MediaStatusClass::status_t AddCodecInfo(BufferFragment& fragment);
     47         OSCL_IMPORT_REF MediaStatusClass::status_t AddCodecInfo(void *ptr, int len);
     48 
     49         OSCL_IMPORT_REF void Clear();
     50 
     51         // void reset();
     52 
     53 
     54         OSCL_IMPORT_REF BufferFragment * GetCodecInfo() const;
     55 
     56         MediaStatusClass::status_t GetLocalFragment(BufferFragment& fragment);
     57 
     58         MediaStatusClass::status_t AddLocalAUFrag(BufferFragment& fragment, int32 location_offset = APPEND_MEDIA_AT_END);
     59 
     60         uint32 GetAvailableBufferSize() const;
     61         uint32 GetLocalBufsize() const;
     62 
     63         OSCL_IMPORT_REF MediaTimestamp GetTimestamp() const;
     64 
     65         OSCL_IMPORT_REF void SetTimestamp(const MediaTimestamp& timestamp);
     66 
     67         OSCL_IMPORT_REF const BufferFragment* GetMediaFragments() const;
     68 
     69         OSCL_IMPORT_REF BufferState * GetBufferState(const uint32 idx)const;
     70 
     71         OSCL_IMPORT_REF void GetMediaFragment(uint32 index, BufferFragment& frag, BufferState*& buffer_state) const;
     72         OSCL_IMPORT_REF BufferFragment * GetMediaFragment(const uint32 idx)const;
     73 
     74         OSCL_IMPORT_REF int32 GetNumFrags() const;
     75         // int32 GetNumMediaFrags() const;
     76         OSCL_IMPORT_REF int32 GetMaxFrags() const;
     77         OSCL_IMPORT_REF uint32 GetLength() const;
     78         //  uint32 GetSize() const { return GetLength(); };
     79 
     80         //
     81         // The following method emphasize the fact that MediaSize does not count reserved stuff
     82         //
     83         uint32 GetMediaSize() const
     84         {
     85             return GetLength();
     86         };
     87 
     88         void AppendNext(AccessUnit *next_ptr);
     89 
     90         OSCL_IMPORT_REF bool IsLocalData(const OsclMemoryFragment& frag) const;
     91 
     92         OSCL_IMPORT_REF AccessUnit* GetNext() const;
     93 
     94         //
     95         // Function match_bit_pattern_with_state() returns 0 if matched,
     96         // else it returns the number of bytes counting from the head that are yet to be matched.
     97         //
     98         OSCL_IMPORT_REF
     99         int32 match_bit_pattern_with_state(const int32 idx, const int32 offset, const uint8 * pattern,
    100                                            const uint8 pattern_size_in_bits, const int32 state) const;
    101 
    102 
    103         //
    104         // Function seek() moves the current position forward (if positive) or backward (if negative) by
    105         // "delta_in_bytes". It returns false if error is encountered,
    106         // else return true and change idx, offset and ptr to the new position.
    107         // If boundary is reached, boundaryReached is set to true.
    108         //
    109         OSCL_IMPORT_REF bool seek(int & idx, int & offset, uint8 * & ptr, bool & boundaryReached,
    110                                   const int delta_in_bytes) const;
    111 
    112         //
    113         // Function match_bit_pattern_with_state()
    114         // returns true if matched,
    115         // else return false;
    116         //
    117         OSCL_IMPORT_REF bool match_bit_pattern_no_state(const int idx, const int offset, const uint8 * pattern,
    118                 const uint8 pattern_size_in_bits) const;
    119 
    120     private:
    121         AUImplAllocator* alloc;
    122         AccessUnitImplementation* rep;
    123         void *impl_hint;
    124 
    125 };
    126 
    127 typedef MemAllocator<AccessUnit> AccessUnitAlloc;
    128 
    129 #endif
    130