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_BASE_H_ 18 19 #define MEDIA_BUFFER_BASE_H_ 20 21 namespace android { 22 23 class MediaBufferBase; 24 class MetaDataBase; 25 26 class MediaBufferObserver { 27 public: 28 MediaBufferObserver() {} 29 virtual ~MediaBufferObserver() {} 30 31 virtual void signalBufferReturned(MediaBufferBase *buffer) = 0; 32 33 private: 34 MediaBufferObserver(const MediaBufferObserver &); 35 MediaBufferObserver &operator=(const MediaBufferObserver &); 36 }; 37 38 class MediaBufferBase { 39 public: 40 static MediaBufferBase *Create(size_t size); 41 42 // If MediaBufferGroup is set, decrement the local reference count; 43 // if the local reference count drops to 0, return the buffer to the 44 // associated MediaBufferGroup. 45 // 46 // If no MediaBufferGroup is set, the local reference count must be zero 47 // when called, whereupon the MediaBuffer is deleted. 48 virtual void release() = 0; 49 50 // Increments the local reference count. 51 // Use only when MediaBufferGroup is set. 52 virtual void add_ref() = 0; 53 54 virtual void *data() const = 0; 55 virtual size_t size() const = 0; 56 57 virtual size_t range_offset() const = 0; 58 virtual size_t range_length() const = 0; 59 60 virtual void set_range(size_t offset, size_t length) = 0; 61 62 virtual MetaDataBase& meta_data() = 0; 63 64 // Clears meta data and resets the range to the full extent. 65 virtual void reset() = 0; 66 67 virtual void setObserver(MediaBufferObserver *group) = 0; 68 69 // Returns a clone of this MediaBufferBase increasing its reference 70 // count. The clone references the same data but has its own range and 71 // MetaData. 72 virtual MediaBufferBase *clone() = 0; 73 74 virtual int refcount() const = 0; 75 76 virtual int localRefcount() const = 0; 77 virtual int remoteRefcount() const = 0; 78 79 virtual ~MediaBufferBase() {}; 80 }; 81 82 } // namespace android 83 84 #endif // MEDIA_BUFFER_BASE_H_ 85