Lines Matching refs:ctx
67 static void kmpp_release_venc_packet(void *ctx, void *arg) in kmpp_release_venc_packet() argument
71 if (!ctx || !pkt) { in kmpp_release_venc_packet()
72 mpp_err_f("invalid input ctx %p pkt %p\n", ctx, pkt); in kmpp_release_venc_packet()
79 static MPP_RET init(Kmpp *ctx, MppCtxType type, MppCodingType coding) in init() argument
86 if (!ctx) in init()
95 if (ctx->mClientFd < 0) { in init()
96 ctx->mClientFd = mpp_vcodec_open(); in init()
97 if (ctx->mClientFd < 0) { in init()
103 hnd = kmpp_obj_to_shm(ctx->mVencInitKcfg); in init()
104 size = kmpp_obj_to_shm_size(ctx->mVencInitKcfg); in init()
105 kmpp_obj_get_u32(ctx->mVencInitKcfg, "chan_dup", &ctx->mChanDup); in init()
106 kmpp_obj_set_s32(ctx->mVencInitKcfg, "chan_fd", ctx->mClientFd); in init()
108 ret = mpp_vcodec_ioctl(ctx->mClientFd, VCODEC_CHAN_CREATE, 0, size, hnd); in init()
110 mpp_err("chan %d VCODEC_CHAN_CREATE failed\n", ctx->mChanId); in init()
114 if (!ctx->mChanDup) { in init()
115 ret = mpp_vcodec_ioctl(ctx->mClientFd, VCODEC_CHAN_START, 0, 0, 0); in init()
117 mpp_err("chan %d VCODEC_CHAN_START failed\n", ctx->mChanId); in init()
122 if (ctx->mPacketGroup == NULL) in init()
123 mpp_buffer_group_get_internal(&ctx->mPacketGroup, MPP_BUFFER_TYPE_ION); in init()
125 kmpp_obj_get_u32(ctx->mVencInitKcfg, "chan_id", &chan_id); in init()
126 mpp_log("client %d open chan_id %d ok", ctx->mClientFd, chan_id); in init()
127 ctx->mInitDone = 1; in init()
128 ctx->mChanId = chan_id; in init()
129 ctx->mType = type; in init()
130 ctx->mOutputTimeout = MPP_POLL_BLOCK; in init()
131 ctx->mTimeout.tv_sec = 2; in init()
132 ctx->mTimeout.tv_usec = 100000; in init()
137 static MPP_RET open_client(Kmpp *ctx) in open_client() argument
139 if (!ctx) in open_client()
142 ctx->mClientFd = mpp_vcodec_open(); in open_client()
143 if (ctx->mClientFd < 0) { in open_client()
150 static void clear(Kmpp *ctx) in clear() argument
152 if (!ctx) in clear()
155 if (!ctx->mChanDup) { in clear()
158 ret = mpp_vcodec_ioctl(ctx->mClientFd, VCODEC_CHAN_DESTROY, 0, 0, 0); in clear()
160 mpp_err("chan %d VCODEC_CHAN_DESTROY failed\n", ctx->mChanId); in clear()
163 if (ctx->mClientFd >= 0) in clear()
164 mpp_vcodec_close(ctx->mClientFd); in clear()
165 ctx->mClientFd = -1; in clear()
167 if (ctx->mPacketGroup) { in clear()
168 mpp_buffer_group_put(ctx->mPacketGroup); in clear()
169 ctx->mPacketGroup = NULL; in clear()
172 if (ctx->mKframe) { in clear()
173 kmpp_frame_put(ctx->mKframe); in clear()
174 ctx->mKframe = NULL; in clear()
178 static MPP_RET start(Kmpp *ctx) in start() argument
182 if (!ctx) in start()
185 if (ctx->mChanDup) in start()
188 ret = mpp_vcodec_ioctl(ctx->mClientFd, VCODEC_CHAN_START, 0, 0, 0); in start()
190 mpp_err("chan %d VCODEC_CHAN_START failed\n", ctx->mChanId); in start()
195 static MPP_RET stop(Kmpp *ctx) in stop() argument
199 if (!ctx) in stop()
202 if (ctx->mChanDup) in stop()
205 ret = mpp_vcodec_ioctl(ctx->mClientFd, VCODEC_CHAN_START, 0, 0, 0); in stop()
207 mpp_err("chan %d VCODEC_CHAN_START failed\n", ctx->mChanId); in stop()
212 static MPP_RET mpp_pause(Kmpp *ctx) in mpp_pause() argument
216 if (!ctx) in mpp_pause()
219 if (ctx->mChanDup) in mpp_pause()
222 ret = mpp_vcodec_ioctl(ctx->mClientFd, VCODEC_CHAN_PAUSE, 0, 0, 0); in mpp_pause()
224 mpp_err("chan %d VCODEC_CHAN_PAUSE failed\n", ctx->mChanId); in mpp_pause()
229 static MPP_RET resume(Kmpp *ctx) in resume() argument
233 if (!ctx) in resume()
236 if (ctx->mChanDup) in resume()
239 ret = mpp_vcodec_ioctl(ctx->mClientFd, VCODEC_CHAN_RESUME, 0, 0, 0); in resume()
241 mpp_err("chan %d VCODEC_CHAN_RESUME failed\n", ctx->mChanId); in resume()
246 static MPP_RET put_packet(Kmpp *ctx, MppPacket packet) in put_packet() argument
251 if (!ctx->mInitDone) in put_packet()
257 static MPP_RET get_frame(Kmpp *ctx, MppFrame *frame) in get_frame() argument
260 if (!ctx->mInitDone) in get_frame()
266 static MPP_RET put_frame(Kmpp *ctx, MppFrame frame) in put_frame() argument
272 if (!ctx) in put_frame()
275 if (!ctx->mInitDone) in put_frame()
281 if (ctx->mKframe == NULL) in put_frame()
282 kmpp_frame_get(&ctx->mKframe); in put_frame()
284 kmpp_frame_set_width(ctx->mKframe, impl->width); in put_frame()
285 kmpp_frame_set_height(ctx->mKframe, impl->height); in put_frame()
286 kmpp_frame_set_hor_stride(ctx->mKframe, impl->hor_stride); in put_frame()
287 kmpp_frame_set_ver_stride(ctx->mKframe, impl->ver_stride); in put_frame()
288 kmpp_frame_set_fmt(ctx->mKframe, impl->fmt); in put_frame()
289 kmpp_frame_set_eos(ctx->mKframe, impl->eos); in put_frame()
290 kmpp_frame_set_pts(ctx->mKframe, impl->pts); in put_frame()
291 kmpp_frame_set_dts(ctx->mKframe, impl->dts); in put_frame()
292 kmpp_frame_set_offset_x(ctx->mKframe, impl->offset_x); in put_frame()
293 kmpp_frame_set_offset_y(ctx->mKframe, impl->offset_y); in put_frame()
294 kmpp_frame_set_hor_stride_pixel(ctx->mKframe, impl->hor_stride_pixel); in put_frame()
297 kmpp_frame_set_buf_fd(ctx->mKframe, mpp_buffer_get_fd(impl->buffer)); in put_frame()
308 ctx->mPacket = packet; in put_frame()
320 ctx->mApi->control(ctx, MPP_ENC_SET_ROI_CFG, &roi_data0); in put_frame()
331 ctx->mApi->control(ctx, MPP_ENC_SET_OSD_DATA_CFG, osd_data3); in put_frame()
336 ptr = kmpp_obj_to_shm(ctx->mKframe); in put_frame()
337 size = kmpp_obj_to_shm_size(ctx->mKframe); in put_frame()
343 ret = mpp_vcodec_ioctl(ctx->mClientFd, VCODEC_CHAN_IN_FRM_RDY, 0, size, ptr); in put_frame()
345 mpp_err("chan %d VCODEC_CHAN_IN_FRM_RDY failed\n", ctx->mChanId); in put_frame()
350 static MPP_RET get_packet(Kmpp *ctx, MppPacket *packet) in get_packet() argument
354 if (!ctx) in get_packet()
357 if (!ctx->mInitDone) in get_packet()
364 FD_SET(ctx->mClientFd, &read_fds); in get_packet()
366 memcpy(&timeout, &ctx->mTimeout, sizeof(timeout)); in get_packet()
367 ret = select(ctx->mClientFd + 1, &read_fds, NULL, NULL, &timeout); in get_packet()
371 if (FD_ISSET(ctx->mClientFd, &read_fds)) { in get_packet()
381 ret = mpp_vcodec_ioctl(ctx->mClientFd, VCODEC_CHAN_OUT_PKT_RDY, in get_packet()
384 mpp_err("chan %d VCODEC_CHAN_OUT_PKT_RDY failed\n", ctx->mChanId); in get_packet()
395 if (ctx->mPacket) { in get_packet()
398 pkt = ctx->mPacket; in get_packet()
399 ctx->mPacket = NULL; in get_packet()
409 mpp_packet_set_release(pkt, kmpp_release_venc_packet, ctx, kmpp_pkt); in get_packet()
426 static MPP_RET release_packet(Kmpp *ctx, MppPacket *packet) in release_packet() argument
430 if (!ctx) in release_packet()
433 if (!ctx->mInitDone) in release_packet()
439 if (ctx->mClientFd < 0) in release_packet()
447 static MPP_RET poll(Kmpp *ctx, MppPortType type, MppPollType timeout) in poll() argument
453 if (!ctx->mInitDone) in poll()
459 static MPP_RET dequeue(Kmpp *ctx, MppPortType type, MppTask *task) in dequeue() argument
465 if (!ctx->mInitDone) in dequeue()
471 static MPP_RET enqueue(Kmpp *ctx, MppPortType type, MppTask task) in enqueue() argument
477 if (!ctx->mInitDone) in enqueue()
483 static MPP_RET control(Kmpp *ctx, MpiCmd cmd, MppParam param) in control() argument
489 if (!ctx) in control()
535 ctx->mTimeout.tv_sec = p->tv_sec; in control()
536 ctx->mTimeout.tv_usec = p->tv_usec; in control()
547 ret = mpp_vcodec_ioctl(ctx->mClientFd, VCODEC_CHAN_CONTROL, cmd, size, arg); in control()
549 mpp_err("chan %d VCODEC_CHAN_CONTROL failed\n", ctx->mChanId); in control()
554 static MPP_RET reset(Kmpp *ctx) in reset() argument
558 if (!ctx) in reset()
560 if (ctx->mChanDup) in reset()
562 if (!ctx->mInitDone) in reset()
565 ret = mpp_vcodec_ioctl(ctx->mClientFd, VCODEC_CHAN_RESET, 0, 0, 0); in reset()
567 mpp_err("chan %d VCODEC_CHAN_RESET failed\n", ctx->mChanId); in reset()
572 static MPP_RET notify_flag(Kmpp *ctx, RK_U32 flag) in notify_flag() argument
575 (void)ctx; in notify_flag()
580 static MPP_RET notify(Kmpp *ctx, MppBufferGroup group) in notify() argument
585 switch (ctx->mType) { in notify()
595 static MPP_RET get_fd(Kmpp *ctx, RK_S32 *fd) in get_fd() argument
599 if (!ctx) in get_fd()
602 if (ctx->mClientFd >= 0) in get_fd()
603 *fd = fcntl(ctx->mClientFd, F_DUPFD_CLOEXEC, 3); in get_fd()
613 static MPP_RET close_fd(Kmpp *ctx, RK_S32 fd) in close_fd() argument
617 (void)ctx; in close_fd()
645 void mpp_get_api(Kmpp *ctx) in mpp_get_api() argument
647 if (!ctx) in mpp_get_api()
650 ctx->mApi = &ops; in mpp_get_api()