1 /* 2 * Copyright (C) 2011 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 ANDROID_FILTERFW_CORE_NATIVE_FRAME_H 18 #define ANDROID_FILTERFW_CORE_NATIVE_FRAME_H 19 20 #include "base/utilities.h" 21 22 namespace android { 23 namespace filterfw { 24 25 // A NativeFrame stores data in a memory buffer (on the heap). It is used for 26 // data processing on the CPU. 27 class NativeFrame { 28 public: 29 // Create an empty native frame. 30 explicit NativeFrame(int size); 31 32 ~NativeFrame(); 33 34 // Set the frame data and size in bytes. The NativeFrame object takes ownership of the data. 35 // To copy data into an existing frame, use WriteData(). 36 bool SetData(uint8_t* data, int size); 37 38 // Write the specified data of the given size to the frame at the specified offset. The 39 // receiver must be large enough to hold the data. 40 bool WriteData(const uint8_t* data, int offset, int size); 41 42 // Returns a pointer to the data, or NULL if no data was set. Data()43 const uint8_t* Data() const { 44 return data_; 45 } 46 47 // Returns a non-const pointer to the data, or NULL if no data was set. MutableData()48 uint8_t* MutableData() { 49 return data_; 50 } 51 52 // Resize the frame. You can only resize to a size that fits within the frame's capacity. 53 // Returns true if the resize was successful. 54 bool Resize(int newSize); 55 56 // Returns the size of the frame in bytes. Size()57 int Size() { 58 return size_; 59 } 60 61 // Returns the capacity of the frame in bytes. Capacity()62 int Capacity() { 63 return capacity_; 64 } 65 66 // Returns a new native frame 67 NativeFrame* Clone() const; 68 69 private: 70 // Pointer to the data. Owned by the frame. 71 uint8_t* data_; 72 73 // Size of data buffer in bytes. 74 int size_; 75 76 // Capacity of data buffer in bytes. 77 int capacity_; 78 79 NativeFrame(const NativeFrame&) = delete; 80 NativeFrame& operator=(const NativeFrame&) = delete; 81 }; 82 83 } // namespace filterfw 84 } // namespace android 85 86 #endif // ANDROID_FILTERFW_CORE_NATIVE_FRAME_H 87