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 __MFX_TASK_H
22 #define __MFX_TASK_H
23 
24 #include <mfxplugin.h>
25 #include <mfx_thread_task.h>
26 #include <mfx_task_threading_policy.h>
27 
28 enum
29 {
30     // Declare the maximum number of source or destination dependencies
31     MFX_TASK_NUM_DEPENDENCIES   = 4
32 };
33 
34 enum
35 {
36     // Declare overall number of priorities
37     MFX_PRIORITY_NUMBER = MFX_PRIORITY_HIGH + 1
38 
39 };
40 
41 // Declare implementation types
42 enum
43 {
44     MFX_TYPE_HARDWARE = 0,
45     MFX_TYPE_SOFTWARE = 1,
46     MFX_TYPE_NUMBER
47 };
48 
49 #define MFX_TASK_NEED_CONTINUE MFX_TASK_WORKING
50 
51 enum
52 {
53     MFX_TRACE_ID_DECODE  = 0x10000000,
54     MFX_TRACE_ID_VPP     = 0x20000000,
55     MFX_TRACE_ID_VPP2    = 0x30000000,
56     MFX_TRACE_ID_ENCODE  = 0x40000000,
57     MFX_TRACE_ID_ENCODE2 = 0x50000000,
58     MFX_TRACE_ID_USER    = 0x60000000,
59 };
60 
61 inline
isFailed(mfxStatus mfxRes)62 bool isFailed(mfxStatus mfxRes)
63 {
64     return (MFX_ERR_NONE > mfxRes);
65 
66 } // bool isFailed(mfxStatus mfxRes)
67 
68 /* declare type for MFX task callbacks.
69 Usually, most thread API involve a single parameter.
70 MFX callback function require 3 parameters to make developers' life.
71 pState - is a pointer to the performing object or something like this.
72 pParam - is an addition parameter to destingush one task from the another inside
73     the entry point. It is possible to start different threads with the same
74     object (pState), but different task (pParam). Usually, it is a handle or some
75     internal pointer.
76 threadNumber - number of the current additional thread. It can be any number
77     not exceeding the maximum required threads for given task. */
78 typedef mfxStatus (*mfxTaskRoutine) (void *pState, void *pParam, mfxU32 threadNumber, mfxU32 callNumber);
79 typedef mfxStatus (*mfxTaskCompleteProc) (void *pState, void *pParam, mfxStatus taskRes);
80 typedef mfxStatus (*mfxGetSubTaskProc) (void *pState, void *pParam, void **ppSubTask);
81 typedef mfxStatus (*mfxCompleteSubTaskProc) (void *pState, void *pParam, void *pSubTask, mfxStatus taskRes);
82 
83 typedef
84 struct MFX_ENTRY_POINT
85 {
86     // pointer to the task processing object
87     void *pState;
88     // pointer to the task's parameter
89     void *pParam;
90 
91     // pointer to the task processing routine
92     mfxTaskRoutine pRoutine;
93     // pointer to the task completing procedure
94     mfxTaskCompleteProc pCompleteProc;
95 
96     // pointer to get a sub-task from the component (NON-OBLIGATORY)
97     mfxGetSubTaskProc pGetSubTaskProc;
98     // sub-task is complete. Update the status of it (NON-OBLIGATORY)
99     mfxCompleteSubTaskProc pCompleteSubTaskProc;
100 
101     // number of simultaneously allowed threads for the task
102     mfxU32 requiredNumThreads;
103 
104     // name of routine - for debug and tracing purpose
105     const char *pRoutineName;
106 } MFX_ENTRY_POINT;
107 
108 struct MFX_TASK
109 {
110     // Pointer to task owning object
111     void *pOwner;
112 
113     // Task parameters provided by the component
114     MFX_ENTRY_POINT entryPoint;
115 
116     // legacy parameters should be eliminated
117     bool bObsoleteTask;
118     MFX_THREAD_TASK_PARAMETERS obsolete_params;
119 
120     // these are not a source/destination parameters,
121     // these are only in/out dependencies.
122 
123     // Array of source dependencies
124     const void *pSrc[MFX_TASK_NUM_DEPENDENCIES];
125     // Array of destination dependencies
126     void *pDst[MFX_TASK_NUM_DEPENDENCIES];
127 
128     // Task's priority
129     mfxPriority priority;
130     // how the object processes the tasks
131     mfxTaskThreadingPolicy threadingPolicy;
132 
133     unsigned int nTaskId;
134     unsigned int nParentId;
135 };
136 
137 #endif // __MFX_TASK_H
138