1 /*
2  * Copyright (C) 2009 The Android Open Source Project
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 express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MEDIA_BUFFER_GROUP_H_
18 
19 #define MEDIA_BUFFER_GROUP_H_
20 
21 #include <media/stagefright/MediaBuffer.h>
22 #include <utils/Errors.h>
23 #include <utils/threads.h>
24 
25 namespace android {
26 
27 class MediaBuffer;
28 class MetaData;
29 
30 class MediaBufferGroup : public MediaBufferObserver {
31 public:
32     MediaBufferGroup();
33     ~MediaBufferGroup();
34 
35     void add_buffer(MediaBuffer *buffer);
36 
37     // If nonBlocking is false, it blocks until a buffer is available and
38     // passes it to the caller in *buffer, while returning OK.
39     // The returned buffer will have a reference count of 1.
40     // If nonBlocking is true and a buffer is not immediately available,
41     // buffer is set to NULL and it returns WOULD_BLOCK.
42     status_t acquire_buffer(MediaBuffer **buffer, bool nonBlocking = false);
43 
44 protected:
45     virtual void signalBufferReturned(MediaBuffer *buffer);
46 
47 private:
48     friend class MediaBuffer;
49 
50     Mutex mLock;
51     Condition mCondition;
52 
53     MediaBuffer *mFirstBuffer, *mLastBuffer;
54 
55     MediaBufferGroup(const MediaBufferGroup &);
56     MediaBufferGroup &operator=(const MediaBufferGroup &);
57 };
58 
59 }  // namespace android
60 
61 #endif  // MEDIA_BUFFER_GROUP_H_
62