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