1 /* 2 * Copyright (c) 2018, Intel Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included 12 * in all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 */ 22 //! 23 //! \file encode_buffer_slot.h 24 //! \brief Defines the interface for buffer slot 25 //! \details The slot manages the buffers with the same type 26 //! 27 #ifndef __ENCODE_TRACKED_BUFFER_SLOT_H__ 28 #define __ENCODE_TRACKED_BUFFER_SLOT_H__ 29 30 #include "encode_tracked_buffer.h" 31 #include "media_class_trace.h" 32 #include "mos_defs.h" 33 #include <stdint.h> 34 #include <map> 35 #include <memory> 36 37 namespace encode { 38 39 class BufferQueue; 40 class BufferSlot 41 { 42 public: 43 //! 44 //! \brief Constructor 45 //! \param [in] tracker 46 //! pointer to BufferTracker 47 //! 48 BufferSlot(TrackedBuffer* tracker); 49 50 //! 51 //! \brief Destructor 52 //! 53 ~BufferSlot(); 54 55 //! 56 //! \brief Set the busy flag to show that the slot is been using 57 //! \return None 58 //! SetBusy()59 void SetBusy() 60 { 61 m_isBusy = true; 62 } 63 64 //! 65 //! \brief Check whether the slot is free to reuse 66 //! \return bool 67 //! true if the slot is free to reuse, otherwise false 68 //! IsFree()69 bool IsFree() const 70 { 71 return !m_isBusy; 72 } 73 74 //! 75 //! \brief Reset the slot status and return all buffers to allocator 76 //! \return MOS_SURFACE * 77 //! MOS_SURFACE * if success, else nullptr if the pool is empty 78 //! 79 MOS_STATUS Reset(); 80 81 //! 82 //! \brief Set the frame index value for current slot 83 //! \param [in] frameIdx 84 //! Frame index from application 85 //! \return void 86 //! SetFrameIdx(uint8_t frameIdx)87 inline void SetFrameIdx(uint8_t frameIdx) { m_frameIndex = frameIdx; } 88 89 //! 90 //! \brief Get associated frame index 91 //! \return uint8_t 92 //! Frame index 93 //! GetFrameIdx()94 inline uint8_t GetFrameIdx() const { return m_frameIndex; } 95 96 //! 97 //! \brief Get resource from current slot 98 //! \param [in]type 99 //! BufferType 100 //! \return Pointer of resource 101 //! Pointer of resource if success, else nullptr if the pool is empty 102 //! 103 void *GetResource(BufferType type); 104 105 protected: 106 uint8_t m_frameIndex = 0; //!< frame index associated with current slot 107 TrackedBuffer *m_tracker = nullptr; //!< pointer to TrackedBuffer 108 bool m_isBusy = false; //!< whether the slot is been using 109 110 std::map<BufferType, void *> m_buffers = {}; //!< buffers attached with current slot 111 std::map<BufferType, std::shared_ptr<BufferQueue> > m_bufferQueues = {}; //!< buffer queue for all types 112 113 MEDIA_CLASS_DEFINE_END(encode__BufferSlot) 114 }; 115 } 116 #endif // !__ENCODE_TRACKED_BUFFER_SLOT_H__ 117