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 //!
24 //! \file     media_pipeline.h
25 //! \brief    Defines the common interface for media pipeline
26 //! \details  The media pipeline interface is further sub-divided by component,
27 //!           this file is for the base interface which is shared by all components.
28 //!
29 
30 #ifndef __MEDIA_PIPELINE_H__
31 #define __MEDIA_PIPELINE_H__
32 #include <map>
33 #include "mos_defs.h"
34 #include "mos_os.h"
35 #include "media_task.h"
36 #include "media_context.h"
37 #include "codechal_debug.h"
38 #include "media_status_report.h"
39 #include "media_feature_manager.h"
40 #include "codechal_utilities.h"
41 
42 class MediaPacket;
43 class MediaPipeline
44 {
45 public:
46     //!
47     //! \brief  Media pipeline constructor
48     //! \param  [in] osInterface
49     //!         Pointer to MOS_INTERFACE
50     //!
51     MediaPipeline(PMOS_INTERFACE osInterface);
52 
53     //!
54     //! \brief  Media pipeline destructor
55     //!
56     virtual ~MediaPipeline();
57 
58     //!
59     //! \brief  Initialize the media pipeline
60     //! \param  [in] settings
61     //!         Pointer to the initialize settings
62     //! \return MOS_STATUS
63     //!         MOS_STATUS_SUCCESS if success, else fail reason
64     //!
65     virtual MOS_STATUS Init(void *settings) = 0;
66 
67     //!
68     //! \brief  Prepare interal parameters, should be invoked for each frame
69     //! \param  [in] params
70     //!         Pointer to the input parameters
71     //! \return MOS_STATUS
72     //!         MOS_STATUS_SUCCESS if success, else fail reason
73     //!
74     virtual MOS_STATUS Prepare(void *params) = 0;
75 
76     //!
77     //! \brief  Finish the execution for each frame
78     //! \return MOS_STATUS
79     //!         MOS_STATUS_SUCCESS if success, else fail reason
80     //!
81     virtual MOS_STATUS Execute() = 0;
82 
83     //!
84     //! \brief  Get media pipeline execution status
85     //! \param  [out] status
86     //!         The point to encode status
87     //! \param  [in] numStatus
88     //!         The requested number of status reports
89     //! \return MOS_STATUS
90     //!         MOS_STATUS_SUCCESS if success, else fail reason
91     //!
92     virtual MOS_STATUS GetStatusReport(void *status, uint16_t numStatus) = 0;
93 
94     //!
95     //! \brief  Destory the media pipeline and release internal resources
96     //! \return MOS_STATUS
97     //!         MOS_STATUS_SUCCESS if success, else fail reason
98     //!
99     virtual MOS_STATUS Destroy() = 0;
100 
101     //!
102     //! \brief  Delete the packet
103     //! \return MOS_STATUS
104     //!         MOS_STATUS_SUCCESS if success, else fail reason
105     //!
106     virtual MOS_STATUS DeletePackets();
107 
108     //!
109     //! \brief  Delete the tasks
110     //! \return MOS_STATUS
111     //!         MOS_STATUS_SUCCESS if success, else fail reason
112     //!
113     virtual MOS_STATUS DeleteTasks();
114 
GetStatusReportInstance()115     MediaStatusReport* GetStatusReportInstance() { return m_statusReport; }
116 
GetMediaContext()117     MediaContext *GetMediaContext() { return m_mediaContext; }
GetFeatureManager()118     virtual MediaFeatureManager *GetFeatureManager() { return m_featureManager; };
GetMediaScalability()119     MediaScalability* &GetMediaScalability() { return m_scalability; }
120     //!
121     //! \brief  Get if frame tracking is enabled from scalability
122     //! \return bool
123     //!         true if enabled, else false
124     //!
125     bool IsFrameTrackingEnabled();
126 
127 protected:
128     //!
129     //! \brief  User Feature Key Report
130     //! \return MOS_STATUS
131     //!         MOS_STATUS_SUCCESS if success, else fail reason
132     //!
133     virtual MOS_STATUS UserFeatureReport();
134 
135     //!
136     //! \brief  Initialize the platform infos
137     //! \return MOS_STATUS
138     //!         MOS_STATUS_SUCCESS if success, else fail reason
139     //!
140     virtual MOS_STATUS InitPlatform();
141 
142     //!
143     //! \brief  Register packets into packet pool
144     //! \param  [in] packetId
145     //!         Packet Id
146     //! \param  [in] packet
147     //!         Pointer to created packet
148     //! \return MOS_STATUS
149     //!         MOS_STATUS_SUCCESS if success, else fail reason
150     //!
151     MOS_STATUS RegisterPacket(uint32_t packetId, MediaPacket* packet);
152 
153     //!
154     //! \brief  Retrieve the task with given Id
155     //! \param  [in] taskId
156     //!         Task Id
157     //! \return MediaTask*
158     //!         Pointer to media task if success, else nullptr
159     //!
160     MediaTask* GetTask(MediaTask::TaskType type);
161 
162     //!
163     //! \brief  Activate packet and add it to active packet list
164     //! \param  [in] packetId
165     //!         Packet Id
166     //! \param  [in] immediateSubmit
167     //!         Indicate if this packet to activate is needed to submit immediately after been added to task
168     //! \param  [in] pass
169     //!         pass belongs to the Packet
170     //! \param  [in] pipe
171     //!         pipe belongs to the Packet
172     //! \param  [in] pipe numbers
173     //!         pipe numbers the Packet needs to use
174     //! \return MOS_STATUS
175     //!         MOS_STATUS_SUCCESS if success, else fail reason
176     //!
177     MOS_STATUS ActivatePacket(uint32_t packetId, bool immediateSubmit, uint8_t pass, uint8_t pipe, uint8_t pipeNum = 1, uint8_t subPass = 0, uint8_t rowNum = 0);
178 
179     //!
180     //! \brief  Finish the active packets execution
181     //! \return MOS_STATUS
182     //!         MOS_STATUS_SUCCESS if success, else fail reason
183     //!
184     virtual MOS_STATUS ExecuteActivePackets();
185 
186     //!
187     //! \brief  Create task and add into packet pool
188     //! \param  [in] type
189     //!         Task type
190     //! \return MediaTask*
191     //!         pointer to MediaTask
192     //!
193     MediaTask* CreateTask(MediaTask::TaskType type);
194 
195     //!
196     //! \brief  create media feature manager
197     //! \return MOS_STATUS
198     //!         MOS_STATUS_SUCCESS if success, else fail reason
199     //!
200     virtual MOS_STATUS CreateFeatureManager();
201 
202 protected:
203     PMOS_INTERFACE                   m_osInterface = nullptr;      //!< OS interface
204     CodechalDebugInterface           *m_debugInterface = nullptr;  //!< Interface used for debug dumps
205     PLATFORM                         m_platform = {};              //!< The platorm info
206     MEDIA_FEATURE_TABLE              *m_skuTable     = nullptr;    //!< SKU table
207     MEDIA_WA_TABLE                   *m_waTable      = nullptr;    //!< WA table
208     MEDIA_SYSTEM_INFO                *m_gtSystemInfo = nullptr;    //!< GT system infomation
209 
210     MediaScalability    *m_scalability = nullptr;
211     MediaContext        *m_mediaContext = nullptr;
212     MediaStatusReport   *m_statusReport = nullptr;
213     MediaFeatureManager *m_featureManager = nullptr;
214 
215     std::map<uint32_t, MediaPacket *>               m_packetList;        //!< Packets list
216     std::vector<PacketProperty>               m_activePacketList;  //!< Active packets property list
217     std::map<MediaTask::TaskType, MediaTask *>      m_taskList;          //!< Task list
218 
219 };
220 #endif // !__MEDIA_PIPELINE_H__
221