MediaBufferGroup.h revision 20111aa043c5f404472bc63b90bc5aad906b1101
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 <utils/Errors.h>
22#include <utils/threads.h>
23
24namespace android {
25
26class MediaBuffer;
27class MetaData;
28
29class MediaBufferGroup : public MediaBufferObserver {
30public:
31    MediaBufferGroup();
32    ~MediaBufferGroup();
33
34    void add_buffer(MediaBuffer *buffer);
35
36    // Blocks until a buffer is available and returns it to the caller,
37    // the returned buffer will have a reference count of 1.
38    status_t acquire_buffer(MediaBuffer **buffer);
39
40protected:
41    virtual void signalBufferReturned(MediaBuffer *buffer);
42
43private:
44    friend class MediaBuffer;
45
46    Mutex mLock;
47    Condition mCondition;
48
49    MediaBuffer *mFirstBuffer, *mLastBuffer;
50
51    MediaBufferGroup(const MediaBufferGroup &);
52    MediaBufferGroup &operator=(const MediaBufferGroup &);
53};
54
55}  // namespace android
56
57#endif  // MEDIA_BUFFER_GROUP_H_
58