summaryrefslogtreecommitdiff
path: root/tvapi/libtv/tv/CTvVchipCheck.cpp (plain)
blob: e83afcbca19041ad7523e1d367decddd4ab6d277
1#include "CTvVchipCheck.h"
2CTvVchipCheck:: CTvVchipCheck()
3{
4}
5
6CTvVchipCheck:: ~CTvVchipCheck()
7{
8}
9
10bool CTvVchipCheck::CheckProgramBlock(int id)
11{
12 bool lock = false;
13 CTvProgram prog;
14 CTvEvent ev;
15 int ret = 0;
16
17 ret = CTvProgram::selectByID(id, prog);
18 if (ret != 0) return false;
19
20 int type = prog.getProgType();
21
22 if (type == CTvProgram::TYPE_ATV) {
23 ret = ev.getATVProgEvent(prog.getSrc(), prog.getID(), ev);
24 } else {
25 //long epgtime = mDmTime.getTime();
26 //ret = ev.getProgPresentEvent(prog.getSrc(),prog.getSourceId(), epgtime, ev);
27 }
28 if (ret == 0) {
29 if (prog.isATSCMode()) {
30 // ATSC V-Chip
31 Vector<CTvDimension::VChipRating *> definedRatings = ev.getVChipRatings();
32 for (int i = 0; i < (int)definedRatings.size(); i++) {
33 CTvDimension dm;
34 if (dm.isBlocked(dm, definedRatings[i])) {
35 lock = true;
36 {
37 /*CurvchipDimension = dm.getName();
38 CurvchipAbbrev = dm.getAbbrev(definedRatings[i]->getValue());
39 CurvchipText= dm.getText(definedRatings[i]->getValue());
40 LOGD("%s, %d Dimension:%s, Abbrev: %s, idx:%d","TV",__LINE__,CurvchipDimension.string(),
41 CurvchipAbbrev.string(),definedRatings[i]->getValue());*/
42 }
43 break;
44 }
45 }
46 }
47 } else {
48 LOGD("Present event of playing program not received yet, will unblock this program.");
49 }
50
51 return lock;
52}
53
54void *CTvVchipCheck::VchipCheckingThread (void *arg __unused)
55{
56 /*CTv *pt = static_cast<CTv *> ( arg );
57
58 if ( !pt->IsVchipEnable() ) {
59 return NULL;
60 }
61
62 while ( pt->mvchip_running ) {
63 bool lock = 0;
64 String8 curdm;
65 String8 curabbrev;
66 tvin_info_t siginfo = pt->Tv_GetCurrentSignalInfo();
67
68 //if ( TVIN_SIG_STATUS_STABLE == siginfo.status ) {
69 lock = pt->mTvVchip.CheckProgramBlock ( pt->getDTVProgramID() );
70 curdm = pt->mTvVchip.getCurdimension();
71 curabbrev = pt->mTvVchip.getCurAbbr();
72
73 if ( ( lock != pt->mlastlockstatus ) || ( pt->mlastdm != curdm ) || ( pt->mlastabbrev != curabbrev ) ) {
74 pt->mlastlockstatus = lock;
75 pt->mlastdm = curdm;
76 pt->mlastabbrev = curabbrev;
77 BlockEvent evt;
78
79 if ( lock ) {
80 evt.programBlockType = 0;
81 evt.block_status = 1;
82 evt.vchipDimension = curdm;
83 evt.vchipAbbrev = curdm;
84 LOGD ( "%s, %d block the program by type %s, %s", "TV", __LINE__, curdm.string(), curabbrev.string() );
85 } else {
86 LOGD ( "unblock the program" );
87 evt.programBlockType = 0;
88 evt.block_status = 0;
89 }
90
91 pt->sendTvEvent ( evt );
92 pt->Programblock ( lock );
93 }
94
95 usleep ( 1000 * 1000 );
96 //} else {
97 //usleep ( 500 * 1000 );
98 //}
99 }*/
100
101 return NULL;
102}
103
104int CTvVchipCheck::stopVChipCheck()
105{
106 CMutex::Autolock _l ( mLock );
107 LOGD ( "stopVChipCheck() and exit thread" );
108 requestExit();
109 return 0;
110}
111
112int CTvVchipCheck::pauseVChipCheck()
113{
114 CMutex::Autolock _l ( mLock );
115 LOGD ( "pauseVChipCheck() set request pause flag, when flag true, thread loop go pause on condition" );
116 m_request_pause_detect = true;
117 return 0;
118}
119
120int CTvVchipCheck::requestAndWaitPauseVChipCheck()
121{
122 CMutex::Autolock _l ( mLock );
123 LOGD ( "requestAndWaitPauseVChipCheck(),first set pause flag to true, and wait when loop run to pause code segment" );
124 m_request_pause_detect = true;
125
126 if ( mDetectState == STATE_RUNNING ) {
127 mRequestPauseCondition.wait ( mLock );
128 }
129
130 return 0;
131}
132
133int CTvVchipCheck::resumeVChipCheck()
134{
135 CMutex::Autolock _l ( mLock );
136 LOGD ( "resumeVChipCheck() first set flag false, and signal to paused condition, let run loop" );
137 m_request_pause_detect = false;
138 mDetectPauseCondition.signal();
139 return 0;
140}
141
142bool CTvVchipCheck::threadLoop()
143{
144 while ( !exitPending() ) { //requietexit() or requietexitWait() not call
145 while ( m_request_pause_detect ) {
146 mRequestPauseCondition.broadcast();
147 mLock.lock();
148 mDetectState = STATE_PAUSE;
149 mDetectPauseCondition.wait ( mLock ); //first unlock,when return,lock again,so need,call unlock
150 mDetectState = STATE_RUNNING;
151 mLock.unlock();
152 }
153 //loop codes
154
155 if ( !m_request_pause_detect ) { //not request pause, sleep 1s which loop
156 usleep ( 1000 * 1000 );
157 }
158 }
159 //exit
160 mDetectState = STATE_STOPED;
161 //return true, run again, return false,not run.
162 return false;
163}
164