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