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 //
20 // rtppp_media_frag_group.cpp
21 //
22 // Overloaded version of PVMFMediaFragGroupCombinedAlloc that allows
23 // notification on a given number of free chunks, opposed to only one.
24 //
25 ///////////////////////////////////////////////////////////////////////////////
26
27 #ifndef RTPPP_MEDIA_FRAG_GROUP_H
28 #define RTPPP_MEDIA_FRAG_GROUP_H
29
30 #include "pvmf_media_frag_group.h"
31
32 ///////////////////////////////////////////////////////////////////////////////
33 //
34 // class RTPPPMediaFragGroupCombinedAlloc
35 //
36 ///////////////////////////////////////////////////////////////////////////////
37
38 template<class Alloc>
39 class RTPPPMediaFragGroupCombinedAlloc: public PVMFMediaFragGroupCombinedAlloc<Alloc>
40 {
41 public:
42
43 // constructor
44 RTPPPMediaFragGroupCombinedAlloc<Alloc>(
45 uint in_capacity,
46 uint in_fragment_capacity,
47 Oscl_DefAlloc* opt_gen_alloc = 0)
48 : PVMFMediaFragGroupCombinedAlloc<Alloc>(
49 in_capacity, in_fragment_capacity, opt_gen_alloc)
50 {
51 iGroupSize = 1;
52 };
53
54 // notification style of the base class
55 void notifyfreechunkavailable(OsclMemPoolFixedChunkAllocatorObserver& obs,
56 OsclAny* aContextData = NULL);
57
58 // notification of multiple frag groups
59 void notifyfreechunkgroupavailable(OsclMemPoolFixedChunkAllocatorObserver& obs,
60 int groupSize, OsclAny* aContextData = NULL);
61
62 // frag group free
63 void destruct_and_dealloc(OsclAny* ptr);
64
65 // check if number messages asked for is available
IsMsgAvailable(int count)66 bool IsMsgAvailable(int count)
67 {
68 return count <= this->num_available_mfgs;
69 }
70
71 //number of free msgs
getNumAvailableMsgs()72 unsigned getNumAvailableMsgs()
73 {
74 return this->num_available_mfgs;
75 }
76
77 private:
78
79 // number of free frags for when we will notify
80 int iGroupSize;
81 };
82
83 ///////////////////////////////////////////////////////////////////////////////
84 //
85 // method RTPPPMediaFragGroupCombinedAlloc::notifyfreechunkavailable
86 //
87 ///////////////////////////////////////////////////////////////////////////////
88
89 template<class Alloc>
notifyfreechunkavailable(OsclMemPoolFixedChunkAllocatorObserver & obs,OsclAny * aContextData)90 void RTPPPMediaFragGroupCombinedAlloc<Alloc>::notifyfreechunkavailable(
91 OsclMemPoolFixedChunkAllocatorObserver& obs,
92 OsclAny* aContextData)
93 {
94 notifyfreechunkgroupavailable(obs, 1, aContextData);
95 }
96
97 ///////////////////////////////////////////////////////////////////////////////
98 //
99 // method RTPPPMediaFragGroupCombinedAlloc::notifyfreechunkgroupavailable
100 //
101 ///////////////////////////////////////////////////////////////////////////////
102
103 template<class Alloc>
notifyfreechunkgroupavailable(OsclMemPoolFixedChunkAllocatorObserver & obs,int groupSize,OsclAny * aContextData)104 void RTPPPMediaFragGroupCombinedAlloc<Alloc>::notifyfreechunkgroupavailable(
105 OsclMemPoolFixedChunkAllocatorObserver& obs, int groupSize,
106 OsclAny* aContextData)
107 {
108 this->iGroupSize = groupSize;
109 this->PVMFMediaFragGroupCombinedAlloc<Alloc>::notifyfreechunkavailable(obs, aContextData);
110 }
111
112 ///////////////////////////////////////////////////////////////////////////////
113 //
114 // method RTPPPMediaFragGroupCombinedAlloc::destruct_and_dealloc
115 //
116 ///////////////////////////////////////////////////////////////////////////////
117
118 template<class Alloc>
destruct_and_dealloc(OsclAny * ptr)119 void RTPPPMediaFragGroupCombinedAlloc<Alloc>::destruct_and_dealloc(OsclAny* ptr)
120 {
121 uint8* my_ptr = (uint8*)ptr;
122 uint aligned_refcnt_size = oscl_mem_aligned_size(sizeof(OsclRefCounterDA));
123 PVMFMediaDataImpl* media_data_ptr = (PVMFMediaDataImpl*)(my_ptr + aligned_refcnt_size);
124 media_data_ptr->clearMediaFragments();
125
126 if (! this->iDestroy)
127 {
128 OsclRefCounter* my_refcnt = OSCL_PLACEMENT_NEW(my_ptr, OsclRefCounterDA(my_ptr, this));
129 OsclSharedPtr<PVMFMediaDataImpl> shared_media_data(media_data_ptr, my_refcnt);
130 this->append(shared_media_data);
131
132 // if we've reached the quoata of empties, perform the notify
133 if ((this->num_available_mfgs >= this->iGroupSize) && (this->iObserver != NULL))
134 {
135 this->iObserver->freechunkavailable(this->iNextAvailableContextData);
136 this->iObserver = NULL;
137 }
138 }
139 else
140 {
141 media_data_ptr->~PVMFMediaDataImpl();
142 this->gen_alloc->deallocate(ptr);
143 }
144 }
145
146
147 #endif // RTPPP_MEDIA_FRAG_GROUP_H
148