Home | History | Annotate | Download | only in stagefright
      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 <list>
     22 
     23 #include <media/stagefright/MediaBufferBase.h>
     24 #include <utils/Errors.h>
     25 #include <utils/threads.h>
     26 
     27 namespace android {
     28 
     29 class MediaBufferBase;
     30 
     31 class MediaBufferGroup : public MediaBufferObserver {
     32 public:
     33     MediaBufferGroup(size_t growthLimit = 0);
     34 
     35     // create a media buffer group with preallocated buffers
     36     MediaBufferGroup(size_t buffers, size_t buffer_size, size_t growthLimit = 0);
     37 
     38     ~MediaBufferGroup();
     39 
     40     void add_buffer(MediaBufferBase *buffer);
     41 
     42     bool has_buffers();
     43 
     44     // If nonBlocking is false, it blocks until a buffer is available and
     45     // passes it to the caller in *buffer, while returning OK.
     46     // The returned buffer will have a reference count of 1.
     47     // If nonBlocking is true and a buffer is not immediately available,
     48     // buffer is set to NULL and it returns WOULD_BLOCK.
     49     // If requestedSize is 0, any free MediaBuffer will be returned.
     50     // If requestedSize is > 0, the returned MediaBuffer should have buffer
     51     // size of at least requstedSize.
     52     status_t acquire_buffer(
     53             MediaBufferBase **buffer, bool nonBlocking = false, size_t requestedSize = 0);
     54 
     55     size_t buffers() const;
     56 
     57     // If buffer is nullptr, have acquire_buffer() check for remote release.
     58     virtual void signalBufferReturned(MediaBufferBase *buffer);
     59 
     60 private:
     61     struct InternalData;
     62     InternalData *mInternal;
     63 
     64     MediaBufferGroup(const MediaBufferGroup &);
     65     MediaBufferGroup &operator=(const MediaBufferGroup &);
     66 };
     67 
     68 }  // namespace android
     69 
     70 #endif  // MEDIA_BUFFER_GROUP_H_
     71