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