blob: 7cdb23f7f7103b0f8e7811b68309c7d69e88796d
1 | #include "CAutoPQparam.h" |
2 | #include "../tvsetting/CTvSetting.h" |
3 | #include "../tvconfig/tvconfig.h" |
4 | #include "../tvutils/tvutils.h" |
5 | #include <stdio.h> |
6 | #include <unistd.h> |
7 | #include <sys/types.h> |
8 | #include <sys/stat.h> |
9 | #include <sys/ioctl.h> |
10 | #include <fcntl.h> |
11 | #include <string.h> |
12 | #include <errno.h> |
13 | #include <dlfcn.h> |
14 | #include <linux/fb.h> |
15 | #include <stdlib.h> |
16 | #include <cutils/properties.h> |
17 | |
18 | #include <xxxconfig.h> |
19 | |
20 | #ifdef LOG_TAG |
21 | #undef LOG_TAG |
22 | #define LOG_TAG "CAutoPQ" |
23 | #endif |
24 | |
25 | CAutoPQparam::CAutoPQparam( CVpp *mVpp, CTvin *pTvin, CAv *mAv) |
26 | { |
27 | myVpp = mVpp; |
28 | myTvin = pTvin; |
29 | myAv = mAv; |
30 | preFmtType = 0; |
31 | curFmtType = 0; |
32 | autofreq_checkcount = 0; |
33 | autofreq_checkflag = 0; |
34 | mAutoPQ_OnOff_Flag = false; |
35 | } |
36 | |
37 | CAutoPQparam::~CAutoPQparam() |
38 | { |
39 | mAutoPQ_OnOff_Flag = false; |
40 | } |
41 | |
42 | bool CAutoPQparam::isAutoPQing() |
43 | { |
44 | return mAutoPQ_OnOff_Flag; |
45 | } |
46 | |
47 | void CAutoPQparam::startAutoPQ( tv_source_input_type_t source_type ) |
48 | { |
49 | #ifndef CC_PROJECT_DISABLE_AUTO_PQ |
50 | mAutoPQSource = source_type; |
51 | |
52 | LOGD("---------startAutoPQParameters --------mAutoPQ_OnOff_Flag = %d", mAutoPQ_OnOff_Flag); |
53 | if (!mAutoPQ_OnOff_Flag) { |
54 | mAutoPQ_OnOff_Flag = true; |
55 | this->run(); |
56 | } |
57 | #else |
58 | LOGD("AutoPQparam disable.\n"); |
59 | #endif |
60 | } |
61 | |
62 | void CAutoPQparam::stopAutoPQ() |
63 | { |
64 | #ifndef CC_PROJECT_DISABLE_AUTO_PQ |
65 | LOGD("---------stopAutoPQParameters -------- mAutoPQ_OnOff_Flag = %d", mAutoPQ_OnOff_Flag); |
66 | if (mAutoPQ_OnOff_Flag) { |
67 | mAutoPQ_OnOff_Flag = false; |
68 | } |
69 | #else |
70 | LOGD("AutoPQparam disable.\n"); |
71 | #endif |
72 | } |
73 | |
74 | /** |
75 | TVIN_SIG_FMT_HDMI_720X480P_60HZ = 0x402 nodeVal<900 |
76 | TVIN_SIG_FMT_HDMI_1920X1080P_60HZ = 0x40a 900<nodeVal<2000 |
77 | TVIN_SIG_FMT_HDMI_3840_2160_00HZ = 0x445 nodeVal>2000 |
78 | */ |
79 | int CAutoPQparam::adjustPQparameters() |
80 | { |
81 | int fd = -1; |
82 | int nodeVal = 0, ret = 0; |
83 | int new_frame_count = 0; |
84 | float frame_rate = 0; |
85 | float frame_rate_ave = 0; |
86 | char s[21]; |
87 | char str[10]; |
88 | tvin_sig_fmt_e sig_fmt; |
89 | is_3d_type_t _3d_type = INDEX_2D; |
90 | tvin_trans_fmt trans_fmt = TVIN_TFMT_2D; |
91 | |
92 | fd = open("/sys/module/amvideo/parameters/new_frame_count", O_RDONLY); |
93 | if (fd <= 0) { |
94 | LOGE("open /sys/module/amvideo/parameters/new_frame_count ERROR!!error = -%s- \n", strerror ( errno )); |
95 | return -1; |
96 | } |
97 | memset(s, 0, sizeof(s)); |
98 | read(fd, s, sizeof(s)); |
99 | close(fd); |
100 | new_frame_count = atoi(s); |
101 | |
102 | if (new_frame_count != 0) { |
103 | |
104 | fd = open("/sys/class/video/frame_height", O_RDONLY); |
105 | if (fd <= 0) { |
106 | LOGE("open /sys/class/video/frame_height ERROR!!error = -%s- \n", strerror ( errno )); |
107 | return -1; |
108 | } |
109 | memset(s, 0, sizeof(s)); |
110 | read(fd, s, sizeof(s)); |
111 | close(fd); |
112 | nodeVal = atoi(s); |
113 | |
114 | if (nodeVal <= 576) { |
115 | curFmtType = 1; |
116 | sig_fmt = TVIN_SIG_FMT_HDMI_720X480P_60HZ; |
117 | } else if (nodeVal > 567 && nodeVal <= 1088) { |
118 | curFmtType = 2; |
119 | sig_fmt = TVIN_SIG_FMT_HDMI_1920X1080P_60HZ; |
120 | } else { |
121 | curFmtType = 3; |
122 | sig_fmt = TVIN_SIG_FMT_HDMI_3840_2160_00HZ; |
123 | } |
124 | |
125 | if (curFmtType != preFmtType) { |
126 | LOGD("adjustPQparameters: nodeVal = %d, sig_fmt = %d.", nodeVal, sig_fmt); |
127 | ret = myVpp->LoadVppSettings (mAutoPQSource, sig_fmt, _3d_type, trans_fmt); |
128 | } |
129 | |
130 | preFmtType = curFmtType; |
131 | |
132 | } else { |
133 | if (preFmtType != 0 || curFmtType != 0) { |
134 | preFmtType = 0; |
135 | curFmtType = 0; |
136 | } |
137 | } |
138 | return ret; |
139 | } |
140 | |
141 | bool CAutoPQparam::threadLoop() |
142 | { |
143 | int sleeptime = 1000;//ms |
144 | while ( mAutoPQ_OnOff_Flag ) { |
145 | usleep ( sleeptime * 1000 ); |
146 | adjustPQparameters(); |
147 | } |
148 | |
149 | return false;//return true, run again, return false,not run. |
150 | } |
151 |