120111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber/* 220111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * Copyright (C) 2009 The Android Open Source Project 320111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * 420111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * Licensed under the Apache License, Version 2.0 (the "License"); 520111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * you may not use this file except in compliance with the License. 620111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * You may obtain a copy of the License at 720111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * 820111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * http://www.apache.org/licenses/LICENSE-2.0 920111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * 1020111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * Unless required by applicable law or agreed to in writing, software 1120111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * distributed under the License is distributed on an "AS IS" BASIS, 1220111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1320111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * See the License for the specific language governing permissions and 1420111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber * limitations under the License. 1520111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber */ 1620111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber 1720111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber#ifndef MEDIA_BUFFER_GROUP_H_ 1820111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber 1920111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber#define MEDIA_BUFFER_GROUP_H_ 2020111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber 212d7d46fb2d7f5f80afbf060f25ed049079fb0fc9Andreas Huber#include <media/stagefright/MediaBuffer.h> 2220111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber#include <utils/Errors.h> 2320111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber#include <utils/threads.h> 2420111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber 2520111aa043c5f404472bc63b90bc5aad906b1101Andreas Hubernamespace android { 2620111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber 2720111aa043c5f404472bc63b90bc5aad906b1101Andreas Huberclass MediaBuffer; 2820111aa043c5f404472bc63b90bc5aad906b1101Andreas Huberclass MetaData; 2920111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber 3020111aa043c5f404472bc63b90bc5aad906b1101Andreas Huberclass MediaBufferGroup : public MediaBufferObserver { 3120111aa043c5f404472bc63b90bc5aad906b1101Andreas Huberpublic: 3220111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber MediaBufferGroup(); 3320111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber ~MediaBufferGroup(); 3420111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber 3520111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber void add_buffer(MediaBuffer *buffer); 3620111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber 37c9a11abbb6b48604ea063daedd6118024cfbfa92Lajos Molnar // If nonBlocking is false, it blocks until a buffer is available and 38c9a11abbb6b48604ea063daedd6118024cfbfa92Lajos Molnar // passes it to the caller in *buffer, while returning OK. 39c9a11abbb6b48604ea063daedd6118024cfbfa92Lajos Molnar // The returned buffer will have a reference count of 1. 40c9a11abbb6b48604ea063daedd6118024cfbfa92Lajos Molnar // If nonBlocking is true and a buffer is not immediately available, 41c9a11abbb6b48604ea063daedd6118024cfbfa92Lajos Molnar // buffer is set to NULL and it returns WOULD_BLOCK. 42e9a5b96e7927fd4e38623e17ac73e8e4e25877eeWei Jia // If requestedSize is 0, any free MediaBuffer will be returned. 43e9a5b96e7927fd4e38623e17ac73e8e4e25877eeWei Jia // If requestedSize is > 0, the returned MediaBuffer should have buffer 44e9a5b96e7927fd4e38623e17ac73e8e4e25877eeWei Jia // size of at least requstedSize. 45e9a5b96e7927fd4e38623e17ac73e8e4e25877eeWei Jia status_t acquire_buffer( 46e9a5b96e7927fd4e38623e17ac73e8e4e25877eeWei Jia MediaBuffer **buffer, bool nonBlocking = false, size_t requestedSize = 0); 4720111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber 4820111aa043c5f404472bc63b90bc5aad906b1101Andreas Huberprotected: 4920111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber virtual void signalBufferReturned(MediaBuffer *buffer); 5020111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber 5120111aa043c5f404472bc63b90bc5aad906b1101Andreas Huberprivate: 5220111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber friend class MediaBuffer; 5320111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber 5420111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber Mutex mLock; 5520111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber Condition mCondition; 5620111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber 5720111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber MediaBuffer *mFirstBuffer, *mLastBuffer; 5820111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber 5920111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber MediaBufferGroup(const MediaBufferGroup &); 6020111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber MediaBufferGroup &operator=(const MediaBufferGroup &); 6120111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber}; 6220111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber 6320111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber} // namespace android 6420111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber 6520111aa043c5f404472bc63b90bc5aad906b1101Andreas Huber#endif // MEDIA_BUFFER_GROUP_H_ 66