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#ifndef PV_GAU_H_
20#define PV_GAU_H_
21#include "oscl_media_data.h"
22#include "oscl_mem.h"
23
24#define MAX_NUM_FRAGMENTS  10
25const uint32 MAX_GAU_BUNDLE = 40;
26
27struct SimpleBufferFragGroup
28{
29    int32 num_fragments;  //number of buffer fragments in this buffer frag group
30    BufferFragment fragments[MAX_NUM_FRAGMENTS];  //buffer fragments within this group
31    BufferState * buf_states[MAX_NUM_FRAGMENTS];  //buffer state for each buffer fragment
32
33    SimpleBufferFragGroup()
34            : num_fragments(0)
35    {
36    }
37};
38
39struct MediaMetaInfo
40{
41    uint32  len;  //size of the frame
42    uint32  ts;   //time stamp
43    uint32  ts_delta; // timestamp delta from the previous timestamp
44    uint32  sample_info;  //4 uint8 information together
45    bool  dropFlag;
46    uint8 layer;
47
48    //overload < operator for sorting later
49    bool operator < (const struct MediaMetaInfo b) const
50    {
51        if (ts < b.ts)
52            return true;
53        else
54            return false;
55    }
56
57    bool  operator  <= (const struct  MediaMetaInfo  b) const
58    {
59        if (ts <= b.ts)
60            return true;
61        else
62            return false;
63    }
64};
65
66
67
68struct GAU
69{
70
71    uint32  numMediaSamples;  //number of media samples within this GAU
72    SimpleBufferFragGroup buf;
73    MediaMetaInfo    info[MAX_GAU_BUNDLE];
74    bool free_buffer_states_when_done;
75    uint64 SampleOffset;
76    OSCL_IMPORT_REF uint32  getSamplesTotalSize(uint32 number, MediaMetaInfo *metaInfo);  //return the sum of total sample size
77
78    OSCL_IMPORT_REF GAU();
79
80    OSCL_IMPORT_REF GAU(GAU & gauElement);
81
82    OSCL_IMPORT_REF ~GAU();
83
84    void SetFreeBufferStatesWhenDone()
85    {
86        free_buffer_states_when_done = true;
87    }
88
89    /*
90      Return info pointer
91    */
92    MediaMetaInfo *getInfo(uint32 i)
93    {
94        if (i < MAX_GAU_BUNDLE)
95            return info + i;
96        else
97            return NULL;
98
99    }
100
101
102    int32 AddBufFrag(uint8 *ptr, uint32 len, BufferFreeFuncPtr freeFunc)
103    {
104        if (buf.num_fragments >= MAX_NUM_FRAGMENTS) return 0;
105
106        buf.fragments[buf.num_fragments].ptr = ptr;
107        buf.fragments[buf.num_fragments].len = len;
108        if (buf.buf_states[buf.num_fragments]) OSCL_DELETE(buf.buf_states[buf.num_fragments]);
109        buf.buf_states[buf.num_fragments] = OSCL_NEW(BufferState, ());
110        buf.buf_states[buf.num_fragments]->bind(ptr, freeFunc);
111        buf.num_fragments ++;
112        return 1;
113    }
114};
115
116
117#endif  // PV_GAU_H_
118