• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2015 Rockchip Electronics Co. LTD
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 __MPP_TASK_H__
18 #define __MPP_TASK_H__
19 
20 #include "mpp_meta.h"
21 
22 /*
23  * Advanced task flow
24  * Advanced task flow introduces three concepts: port, task and item
25  *
26  * Port is from OpenMAX
27  * Port has two type: input port and output port which are all for data transaction.
28  * Port work like a queue. task will be dequeue from or enqueue to one port.
29  * On input side user will dequeue task from input port, setup task and enqueue task
30  * back to input port.
31  * On output side user will dequeue task from output port, get the information from
32  * and then enqueue task back to output port.
33  *
34  * Task indicates one transaction on the port.
35  * Task has two working mode: async mode and sync mode
36  * If mpp is work in sync mode on task enqueue function return the task has been done
37  * If mpp is work in async mode on task enqueue function return the task is just put
38  * on the task queue for process.
39  * Task can carry different items. Task just like a container of items
40  *
41  * Item indicates MppPacket or MppFrame which is contained in one task
42  */
43 
44 /*
45  * One mpp task queue has two ports: input and output
46  *
47  * The whole picture is:
48  * Top layer mpp has two ports: mpp_input_port and mpp_output_port
49  * But internally these two ports belongs to two task queue.
50  * The mpp_input_port is the mpp_input_task_queue's input port.
51  * The mpp_output_port is the mpp_output_task_queue's output port.
52  *
53  * Each port uses its task queue to communication
54  */
55 typedef enum {
56     MPP_PORT_INPUT,
57     MPP_PORT_OUTPUT,
58     MPP_PORT_BUTT,
59 } MppPortType;
60 
61 /*
62  * Advance task work flow mode:
63  ******************************************************************************
64  * 1. async mode (default_val)
65  *
66  * mpp_init(type, coding, MPP_WORK_ASYNC)
67  *
68  * input thread
69  * a - poll(input)
70  * b - dequeue(input, *task)
71  * c - task_set_item(packet/frame)
72  * d - enqueue(input, task)     // when enqueue return the task is not done yet
73  *
74  * output thread
75  * a - poll(output)
76  * b - dequeue(output, *task)
77  * c - task_get_item(frame/packet)
78  * d - enqueue(output, task)
79  ******************************************************************************
80  * 2. sync mode
81  *
82  * mpp_init(type, coding, MPP_WORK_SYNC)
83  *
84  * a - poll(input)
85  * b - dequeue(input, *task)
86  * c - task_set_item(packet/frame)
87  * d - enqueue(task)            // when enqueue return the task is finished
88  ******************************************************************************
89  */
90 typedef enum {
91     MPP_TASK_ASYNC,
92     MPP_TASK_SYNC,
93     MPP_TASK_WORK_MODE_BUTT,
94 } MppTaskWorkMode;
95 
96 /*
97  * Mpp port poll type
98  *
99  * MPP_POLL_BLOCK           - for block poll
100  * MPP_POLL_NON_BLOCK       - for non-block poll
101  * small than MPP_POLL_MAX  - for poll with timeout in ms
102  * small than MPP_POLL_BUTT or larger than MPP_POLL_MAX is invalid value
103  */
104 typedef enum {
105     MPP_POLL_BUTT       = -2,
106     MPP_POLL_BLOCK      = -1,
107     MPP_POLL_NON_BLOCK  = 0,
108     MPP_POLL_MAX        = 8000,
109 } MppPollType;
110 
111 /*
112  * Mpp timeout define
113  * MPP_TIMEOUT_BLOCK            - for block poll
114  * MPP_TIMEOUT_NON_BLOCK        - for non-block poll
115  * small than MPP_TIMEOUT_MAX   - for poll with timeout in ms
116  * small than MPP_TIMEOUT_BUTT or larger than MPP_TIMEOUT_MAX is invalid value
117  */
118 #define MPP_TIMEOUT_BUTT        (-2L)
119 #define MPP_TIMEOUT_BLOCK       (-1L)
120 #define MPP_TIMEOUT_NON_BLOCK   (0L)
121 #define MPP_TIMEOUT_MAX         (8000L)
122 
123 /*
124  * MppTask is descriptor of a task which send to mpp for process
125  * mpp can support different type of work mode, for example:
126  *
127  * decoder:
128  *
129  * 1. typical decoder mode:
130  * input    - MppPacket     (normal cpu buffer, need cpu copy)
131  * output   - MppFrame      (ion/drm buffer in external/internal mode)
132  * 2. secure decoder mode:
133  * input    - MppPacket     (externel ion/drm buffer, cpu can not access)
134  * output   - MppFrame      (ion/drm buffer in external/internal mode, cpu can not access)
135  *
136  * interface usage:
137  *
138  * typical flow
139  * input side:
140  * task_dequeue(ctx, PORT_INPUT, &task);
141  * task_put_item(task, MODE_INPUT, packet)
142  * task_enqueue(ctx, PORT_INPUT, task);
143  * output side:
144  * task_dequeue(ctx, PORT_OUTPUT, &task);
145  * task_get_item(task, MODE_OUTPUT, &frame)
146  * task_enqueue(ctx, PORT_OUTPUT, task);
147  *
148  * secure flow
149  * input side:
150  * task_dequeue(ctx, PORT_INPUT, &task);
151  * task_put_item(task, MODE_INPUT, packet)
152  * task_put_item(task, MODE_OUTPUT, frame)  // buffer will be specified here
153  * task_enqueue(ctx, PORT_INPUT, task);
154  * output side:
155  * task_dequeue(ctx, PORT_OUTPUT, &task);
156  * task_get_item(task, MODE_OUTPUT, &frame)
157  * task_enqueue(ctx, PORT_OUTPUT, task);
158  *
159  * encoder:
160  *
161  * 1. typical encoder mode:
162  * input    - MppFrame      (ion/drm buffer in external mode)
163  * output   - MppPacket     (normal cpu buffer, need cpu copy)
164  * 2. user input encoder mode:
165  * input    - MppFrame      (normal cpu buffer, need to build hardware table for this buffer)
166  * output   - MppPacket     (normal cpu buffer, need cpu copy)
167  * 3. secure encoder mode:
168  * input    - MppFrame      (ion/drm buffer in external mode, cpu can not access)
169  * output   - MppPacket     (externel ion/drm buffer, cpu can not access)
170  *
171  * typical / user input flow
172  * input side:
173  * task_dequeue(ctx, PORT_INPUT, &task);
174  * task_put_item(task, MODE_INPUT, frame)
175  * task_enqueue(ctx, PORT_INPUT, task);
176  * output side:
177  * task_dequeue(ctx, PORT_OUTPUT, &task);
178  * task_get_item(task, MODE_OUTPUT, &packet)
179  * task_enqueue(ctx, PORT_OUTPUT, task);
180  *
181  * secure flow
182  * input side:
183  * task_dequeue(ctx, PORT_INPUT, &task);
184  * task_put_item(task, MODE_OUTPUT, packet)  // buffer will be specified here
185  * task_put_item(task, MODE_INPUT, frame)
186  * task_enqueue(ctx, PORT_INPUT, task);
187  * output side:
188  * task_dequeue(ctx, PORT_OUTPUT, &task);
189  * task_get_item(task, MODE_OUTPUT, &packet)
190  * task_get_item(task, MODE_OUTPUT, &frame)
191  * task_enqueue(ctx, PORT_OUTPUT, task);
192  *
193  * NOTE: this flow can specify the output frame. User will setup both intput frame and output packet
194  * buffer at the input side. Then at output side when user gets a finished task user can get the output
195  * packet and corresponding released input frame.
196  *
197  * image processing
198  *
199  * 1. typical image process mode:
200  * input    - MppFrame      (ion/drm buffer in external mode)
201  * output   - MppFrame      (ion/drm buffer in external mode)
202  *
203  * typical / user input flow
204  * input side:
205  * task_dequeue(ctx, PORT_INPUT, &task);
206  * task_put_item(task, MODE_INPUT, frame)
207  * task_enqueue(ctx, PORT_INPUT, task);
208  * output side:
209  * task_dequeue(ctx, PORT_OUTPUT, &task);
210  * task_get_item(task, MODE_OUTPUT, &frame)
211  * task_enqueue(ctx, PORT_OUTPUT, task);
212  */
213 /* NOTE: use index rather then handle to descripbe task */
214 
215 #ifdef __cplusplus
216 extern "C" {
217 #endif
218 
219 MPP_RET mpp_task_meta_set_s32(MppTask task, MppMetaKey key, RK_S32 val);
220 MPP_RET mpp_task_meta_set_s64(MppTask task, MppMetaKey key, RK_S64 val);
221 MPP_RET mpp_task_meta_set_ptr(MppTask task, MppMetaKey key, void  *val);
222 MPP_RET mpp_task_meta_set_frame (MppTask task, MppMetaKey key, MppFrame  frame);
223 MPP_RET mpp_task_meta_set_packet(MppTask task, MppMetaKey key, MppPacket packet);
224 MPP_RET mpp_task_meta_set_buffer(MppTask task, MppMetaKey key, MppBuffer buffer);
225 
226 MPP_RET mpp_task_meta_get_s32(MppTask task, MppMetaKey key, RK_S32 *val, RK_S32 default_val);
227 MPP_RET mpp_task_meta_get_s64(MppTask task, MppMetaKey key, RK_S64 *val, RK_S64 default_val);
228 MPP_RET mpp_task_meta_get_ptr(MppTask task, MppMetaKey key, void  **val, void  *default_val);
229 MPP_RET mpp_task_meta_get_frame (MppTask task, MppMetaKey key, MppFrame  *frame);
230 MPP_RET mpp_task_meta_get_packet(MppTask task, MppMetaKey key, MppPacket *packet);
231 MPP_RET mpp_task_meta_get_buffer(MppTask task, MppMetaKey key, MppBuffer *buffer);
232 
233 #ifdef __cplusplus
234 }
235 #endif
236 
237 #endif /*__MPP_QUEUE_H__*/
238