1 // Copyright (c) 2017 Intel Corporation 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in all 11 // copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 // SOFTWARE. 20 21 #ifndef __UMC_FRAME_ALLOCATOR_H__ 22 #define __UMC_FRAME_ALLOCATOR_H__ 23 24 #include "umc_defs.h" 25 #include "umc_structures.h" 26 #include "umc_dynamic_cast.h" 27 #include "umc_mutex.h" 28 29 #define FMID_INVALID 0 30 31 namespace UMC 32 { 33 34 class VideoDataInfo; 35 class FrameData; 36 37 typedef int32_t FrameMemID; 38 39 enum 40 { 41 FRAME_MID_INVALID = -1 42 }; 43 44 /*enum UMC_ALLOC_FLAGS 45 { 46 UMC_ALLOC_PERSISTENT = 0x01, 47 UMC_ALLOC_FUNCLOCAL = 0x02 48 };*/ 49 50 class FrameAllocatorParams 51 { DYNAMIC_CAST_DECL_BASE(FrameAllocatorParams)52 DYNAMIC_CAST_DECL_BASE(FrameAllocatorParams) 53 54 public: 55 FrameAllocatorParams(){} ~FrameAllocatorParams()56 virtual ~FrameAllocatorParams(){} 57 }; 58 59 class FrameAllocator 60 { DYNAMIC_CAST_DECL_BASE(FrameAllocator)61 DYNAMIC_CAST_DECL_BASE(FrameAllocator) 62 63 public: 64 FrameAllocator(void){} ~FrameAllocator(void)65 virtual ~FrameAllocator(void){} 66 67 // Initiates object Init(FrameAllocatorParams *)68 virtual Status Init(FrameAllocatorParams *) { return UMC_OK;} 69 70 // Closes object and releases all allocated memory 71 virtual Status Close() = 0; 72 73 virtual Status Reset() = 0; 74 75 // Allocates or reserves physical memory and returns unique ID 76 // Sets lock counter to 0 77 virtual Status Alloc(FrameMemID *pNewMemID, const VideoDataInfo * info, uint32_t Flags) = 0; 78 79 virtual Status GetFrameHandle(UMC::FrameMemID MID, void * handle) = 0; 80 81 // Lock() provides pointer from ID. If data is not in memory (swapped) 82 // prepares (restores) it. Increases lock counter 83 virtual const FrameData* Lock(FrameMemID MID) = 0; 84 85 // Unlock() decreases lock counter 86 virtual Status Unlock(FrameMemID MID) = 0; 87 88 // Notifies that the data won't be used anymore. Memory can be freed. 89 virtual Status IncreaseReference(FrameMemID MID) = 0; 90 91 // Notifies that the data won't be used anymore. Memory can be freed. 92 virtual Status DecreaseReference(FrameMemID MID) = 0; 93 94 protected: 95 Mutex m_guard; 96 97 private: 98 // Declare private copy constructor to avoid accidental assignment 99 // and klocwork complaining. 100 FrameAllocator(const FrameAllocator &); 101 FrameAllocator & operator = (const FrameAllocator &); 102 }; 103 104 } //namespace UMC 105 106 #endif //__UMC_FRAME_ALLOCATOR_H__ 107