blob: 31ffcd25850c28c0047db312866d95759590b066
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 | |
22 | static int amvideo_handle = 0; |
23 | |
24 | #define TVP_SECRET "amlogic_omx_decoder,pts=" |
25 | #define TVP_SECRET_RENDER "is rendered = true" |
26 | |
27 | int openamvideo() { |
28 | amvideo_handle = open("/dev/amvideo",O_RDWR | O_NONBLOCK); |
29 | return amvideo_handle; |
30 | } |
31 | |
32 | void 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 | |
41 | int setomxdisplaymode() { |
42 | return ioctl(amvideo_handle, AMSTREAM_IOC_SET_VIDEO_DISABLE, 2); |
43 | |
44 | } |
45 | int setomxpts(int time_video) { |
46 | return ioctl(amvideo_handle, AMSTREAM_IOC_SET_OMX_VPTS, (unsigned long)&time_video); |
47 | } |
48 | |
49 | void set_omx_pts(char* data, int* handle) { |
50 | if (data == NULL) { |
51 | ALOGE("hnd->base is NULL!!!!"); |
52 | return; |
53 | } |
54 | if (strncmp(data, TVP_SECRET, strlen(TVP_SECRET)) == 0) { |
55 | if (*handle == 0 || amvideo_handle == 0) { |
56 | *handle = openamvideo(); |
57 | if (*handle == 0) |
58 | ALOGW("can not open amvideo"); |
59 | } |
60 | if (strncmp(data+sizeof(TVP_SECRET)+sizeof(signed long long), TVP_SECRET_RENDER, strlen(TVP_SECRET_RENDER)) != 0) { |
61 | signed long long time; |
62 | memcpy(&time, (char*)data+sizeof(TVP_SECRET), sizeof(signed long long)); |
63 | int time_video = time * 9 / 100 + 1; |
64 | //ALOGW("render____time=%lld,time_video=%d",time,time_video); |
65 | int ret = setomxpts(time_video); |
66 | if (ret < 0) { |
67 | ALOGW("setomxpts error, ret =%d",ret); |
68 | } |
69 | } |
70 | memcpy((char*)data + sizeof(TVP_SECRET) + sizeof(signed long long), TVP_SECRET_RENDER, sizeof(TVP_SECRET_RENDER)); |
71 | } |
72 | } |
73 | |
74 |