blob: 06233ea440721123fa5478bb29ed6c889d2ba0ea
1 | /* |
2 | * Copyright (c) 2014 Amlogic, Inc. All rights reserved. |
3 | * |
4 | * This source code is subject to the terms and conditions defined in the |
5 | * file 'LICENSE' which is part of this source code package. |
6 | * |
7 | * Description: |
8 | * AMLOGIC OMX IOCTL WRAPPER |
9 | */ |
10 | |
11 | |
12 | #define LOG_NDEBUG 0 |
13 | #define LOG_TAG "omxutil" |
14 | |
15 | #include <fcntl.h> |
16 | #include <sys/ioctl.h> |
17 | #include <media/stagefright/foundation/ADebug.h> |
18 | |
19 | #define AMSTREAM_IOC_MAGIC 'S' |
20 | |
21 | #define AMSTREAM_IOC_SET_OMX_VPTS _IOW(AMSTREAM_IOC_MAGIC, 0xaf, int) |
22 | #define AMSTREAM_IOC_SET_VIDEO_DISABLE _IOW(AMSTREAM_IOC_MAGIC, 0x49, int) |
23 | |
24 | static int amvideo_handle = 0; |
25 | |
26 | #define TVP_SECRET "amlogic_omx_decoder,pts=" |
27 | #define TVP_SECRET_RENDER "is rendered = true" |
28 | #define TVP_SECRET_VERSION "version=" |
29 | #define TVP_SECRET_FRAME_NUM "frame_num=" |
30 | |
31 | int openamvideo() { |
32 | amvideo_handle = open("/dev/amvideo",O_RDWR | O_NONBLOCK); |
33 | return amvideo_handle; |
34 | } |
35 | |
36 | void closeamvideo() { |
37 | if (amvideo_handle != 0) { |
38 | int ret = close(amvideo_handle); |
39 | amvideo_handle = 0; |
40 | if (ret < 0) |
41 | ALOGE("close Amvideo error"); |
42 | } |
43 | } |
44 | |
45 | int setomxdisplaymode() { |
46 | return ioctl(amvideo_handle, AMSTREAM_IOC_SET_VIDEO_DISABLE, 2); |
47 | |
48 | } |
49 | int setomxpts(int time_video) { |
50 | return ioctl(amvideo_handle, AMSTREAM_IOC_SET_OMX_VPTS, (unsigned long)&time_video); |
51 | } |
52 | |
53 | int setomxpts(uint32_t* omx_info) { |
54 | return ioctl(amvideo_handle, AMSTREAM_IOC_SET_OMX_VPTS, (unsigned long)omx_info); |
55 | } |
56 | |
57 | void set_omx_pts(char* data, int* handle) { |
58 | if (data == NULL) { |
59 | ALOGE("hnd->base is NULL!!!!"); |
60 | return; |
61 | } |
62 | if (strncmp(data, TVP_SECRET, strlen(TVP_SECRET)) == 0) { |
63 | if (*handle == 0 || amvideo_handle == 0) { |
64 | *handle = openamvideo(); |
65 | if (*handle == 0) |
66 | ALOGW("can not open amvideo"); |
67 | } |
68 | uint32_t omx_version = 0; |
69 | if (strncmp(data+sizeof(TVP_SECRET)+sizeof(signed long long), TVP_SECRET_RENDER, strlen(TVP_SECRET_RENDER)) != 0) { |
70 | signed long long time; |
71 | int offset = 0; |
72 | offset += sizeof(TVP_SECRET); |
73 | memcpy(&time, (char*)data+offset, sizeof(signed long long)); |
74 | offset += sizeof(signed long long); |
75 | int time_video = time * 9 / 100 + 1; |
76 | //ALOGW("render____time=%lld,time_video=%d",time,time_video); |
77 | uint32_t frame_num = 0; |
78 | if (strncmp(data+offset, TVP_SECRET_VERSION, strlen(TVP_SECRET_VERSION)) == 0) { |
79 | offset += sizeof(TVP_SECRET_VERSION); |
80 | memcpy(&omx_version, (char*)data+offset, sizeof(uint32_t)); |
81 | offset += sizeof(uint32_t); |
82 | } |
83 | int ret = 0; |
84 | if (omx_version >= 2) { |
85 | if (strncmp(data+offset, TVP_SECRET_FRAME_NUM, strlen(TVP_SECRET_FRAME_NUM)) == 0) { |
86 | offset += sizeof(TVP_SECRET_FRAME_NUM); |
87 | memcpy(&frame_num, (char*)data+offset, sizeof(uint32_t)); |
88 | offset += sizeof(uint32_t); |
89 | } |
90 | uint32_t omx_info[6]; |
91 | omx_info[0] = time_video; |
92 | omx_info[1] = omx_version; |
93 | omx_info[2] = 1; // set by hw |
94 | omx_info[3] = frame_num; |
95 | omx_info[4] = 0; // 0:need reset omx_pts;1:do not need reset omx_pts |
96 | omx_info[5] = 0; // Reserved |
97 | ret = setomxpts(omx_info); |
98 | } else |
99 | ret = setomxpts(time_video); |
100 | if (ret < 0) { |
101 | ALOGW("setomxpts error, ret =%d",ret); |
102 | } |
103 | } |
104 | memcpy((char*)data + sizeof(TVP_SECRET) + sizeof(signed long long), TVP_SECRET_RENDER, sizeof(TVP_SECRET_RENDER)); |
105 | } |
106 | } |
107 | |
108 |