summaryrefslogtreecommitdiff
path: root/tvp/OmxUtil.cpp (plain)
blob: ae57fdb2f36067f111eb1d329ddf5037a8c22320
1/*
2 * AMLOGIC IOCTL WRAPPER
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the BSD Licence, GNU General Public License
6 * as published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version
8 */
9
10#define LOG_NDEBUG 0
11#define LOG_TAG "omxutil"
12
13#include <fcntl.h>
14#include <sys/ioctl.h>
15#include <media/stagefright/foundation/ADebug.h>
16
17#define AMSTREAM_IOC_MAGIC 'S'
18
19#define AMSTREAM_IOC_SET_OMX_VPTS _IOW(AMSTREAM_IOC_MAGIC, 0xaf, int)
20#define AMSTREAM_IOC_SET_VIDEO_DISABLE _IOW(AMSTREAM_IOC_MAGIC, 0x49, int)
21
22static int amvideo_handle = 0;
23
24#define TVP_SECRET "amlogic_omx_decoder,pts="
25#define TVP_SECRET_RENDER "is rendered = true"
26
27int openamvideo() {
28 amvideo_handle = open("/dev/amvideo",O_RDWR | O_NONBLOCK);
29 return amvideo_handle;
30}
31
32void closeamvideo() {
33 if (amvideo_handle != 0) {
34 int ret = close(amvideo_handle);
35 amvideo_handle = 0;
36 if (ret < 0)
37 ALOGE("close Amvideo error");
38 }
39}
40
41int setomxdisplaymode() {
42 return ioctl(amvideo_handle, AMSTREAM_IOC_SET_VIDEO_DISABLE, 2);
43
44}
45int setomxpts(int time_video) {
46 return ioctl(amvideo_handle, AMSTREAM_IOC_SET_OMX_VPTS, (unsigned long)&time_video);
47}
48
49void set_omx_pts(char* data, int* handle) {
50 if (strncmp(data, TVP_SECRET, strlen(TVP_SECRET)) == 0) {
51 if (*handle == 0 || amvideo_handle == 0) {
52 *handle = openamvideo();
53 if (*handle == 0)
54 ALOGW("can not open amvideo");
55 }
56 if (strncmp(data+sizeof(TVP_SECRET)+sizeof(signed long long), TVP_SECRET_RENDER, strlen(TVP_SECRET_RENDER)) != 0) {
57 signed long long time;
58 memcpy(&time, (char*)data+sizeof(TVP_SECRET), sizeof(signed long long));
59 int time_video = time * 9 / 100 + 1;
60 //ALOGW("render____time=%lld,time_video=%d",time,time_video);
61 int ret = setomxpts(time_video);
62 if (ret < 0) {
63 ALOGW("setomxpts error, ret =%d",ret);
64 }
65 }
66 memcpy((char*)data + sizeof(TVP_SECRET) + sizeof(signed long long), TVP_SECRET_RENDER, sizeof(TVP_SECRET_RENDER));
67 }
68}
69
70