summaryrefslogtreecommitdiff
path: root/tvapi/libtv/tv/CTv.cpp (plain)
blob: 8a6aa0f718976bfbf9e01a355ec1767493fcc81b
1//
2//
3// amlogic 2013
4//
5// @ Project : tv
6// @ File Name : CTv.cpp
7// @ Date : 2013-11
8// @ Author :
9#include <stdio.h>
10#include <unistd.h>
11#include <fcntl.h>
12#include <dirent.h>
13#include <am_epg.h>
14#include <am_mem.h>
15#include "CTvDatabase.h"
16#include <stdlib.h>
17#include <string.h>
18#include <malloc.h>
19#include <pthread.h>
20#include <sys/types.h>
21#include <errno.h>
22#include <dlfcn.h>
23#include <cutils/properties.h>
24#include <cutils/log.h>
25#include <cutils/android_reboot.h>
26#include <utils/threads.h>
27#include <time.h>
28#include <sys/prctl.h>
29#include <getopt.h>
30#include <errno.h>
31#include <sys/types.h>
32#include <sys/stat.h>
33#include <fcntl.h>
34#include <stdlib.h>
35#ifdef ANDROID
36#include <termios.h>
37#endif
38#include <string.h>
39#include <signal.h>
40
41#include "../version/version.h"
42#include "../tvsetting/CTvSetting.h"
43#include "../tvutils/tvutils.h"
44#include "../tvconfig/tvconfig.h"
45#include "../tvutils/CFile.h"
46#include <hardware_legacy/power.h>
47#include "../tvutils/serial_operate.h"
48#include <xxxconfig.h>
49
50extern "C" {
51#include "am_ver.h"
52#include "am_misc.h"
53#include "am_debug.h"
54#include "am_fend.h"
55}
56
57#include <math.h>
58#include <sys/ioctl.h>
59
60#include "CTv.h"
61
62#define LOG_TAG "CTv"
63
64
65using namespace android;
66
67// Called each time a message is logged.
68static void sqliteLogCallback(void *data, int iErrCode, const char *zMsg) {
69 data = data;
70 LOGD( "showbo sqlite (%d) %s\n", iErrCode, zMsg);
71}
72
73CTv::CTv() :
74 mSigDetectThread ( &mTvin ),
75 mSourceConnectDetectThread(&mTvin),
76 mHDMIRxCEC ( &mTvin ),
77 mTvScanner ( &mTvin ),
78 mTvMsgQueue(this),
79 mAutoBackLight( &mVpp, &mTvin ),
80 mTvScannerDetectObserver(this),
81 mAutoPQparam( &mVpp, &mTvin, &mAv ) {
82 mAudioMuteStatusForTv = CC_AUDIO_UNMUTE;
83 mAudioMuteStatusForSystem = CC_AUDIO_UNMUTE;
84 //mpClient = pClient;
85 //copy file to param
86 if (Tv_Utils_IsFileExist ( TV_CONFIG_FILE_SYSTEM_PATH )) {
87 if (!Tv_Utils_IsFileExist ( TV_CONFIG_FILE_PARAM_PATH )) {
88 CFile file ( TV_CONFIG_FILE_SYSTEM_PATH );
89
90 if ( file.copyTo ( TV_CONFIG_FILE_PARAM_PATH ) != 0 ) {
91 LOGE ( "%s, copy file = %s , error", __FUNCTION__, TV_CONFIG_FILE_PARAM_PATH );
92 }
93 }
94 }
95
96 if (Tv_Utils_IsFileExist ( TV_CHANNEL_LIST_SYSTEM_PATH )) {
97 if (!Tv_Utils_IsFileExist ( TV_CHANNEL_LIST_PARAM_PATH )) {
98 CFile file ( TV_CHANNEL_LIST_SYSTEM_PATH );
99
100 if ( file.copyTo ( TV_CHANNEL_LIST_PARAM_PATH ) != 0 ) {
101 LOGE ( "%s, copy file = %s , error", __FUNCTION__, TV_CHANNEL_LIST_PARAM_PATH );
102 }
103 }
104 }
105
106 //ssm
107 if (Tv_Utils_IsFileExist ( TV_SSM_DATA_SYSTEM_PATH )) {
108 if (!Tv_Utils_IsFileExist ( TV_SSM_DATA_PARAM_PATH )) {
109 CFile file ( TV_SSM_DATA_SYSTEM_PATH );
110
111 if ( file.copyTo ( TV_SSM_DATA_PARAM_PATH ) != 0 ) {
112 LOGE ( "%s, copy file = %s , error", __FUNCTION__, TV_SSM_DATA_PARAM_PATH );
113 }
114 }
115 }
116
117 AM_EVT_Init();
118 mTvEpg.setObserver ( &mTvMsgQueue );
119 mpObserver = NULL;
120 fbcIns = NULL;
121 dtv_auto_3d_flag = 0;
122 m_autoset_displayfreq = false;
123
124 tv_config_load ( TV_CONFIG_FILE_PATH );
125 sqlite3_config (SQLITE_CONFIG_SERIALIZED);
126 //sqlite3_config(SQLITE_CONFIG_LOG, &sqliteLogCallback, (void*)1);
127 sqlite3_soft_heap_limit(8 * 1024 * 1024);
128 // Initialize SQLite.
129 sqlite3_initialize();
130 CTvDatabase::GetTvDb()->InitTvDb ( TV_DB_PATH );
131
132 if ( CTvDimension::isDimensionTblExist() == false ) {
133 CTvDimension::builtinAtscDimensions();
134 }
135
136 CTvSettingLoad();
137
138 mDtvScanRunningStatus = DTV_SCAN_RUNNING_NORMAL;
139 if (hdmiOutWithFbc()) {
140 mHdmiOutFbc = true;
141 } else {
142 mHdmiOutFbc = false;
143 }
144
145 m_sig_stable_nums = 0;
146 m_is_set_hdmi_edid = false;
147 m_cur_playing_prog_id = -1;
148
149 m_hdmi_audio_data = 0;
150 mSigDetectThread.setObserver ( this );
151 mSourceConnectDetectThread.setObserver ( this );
152 mHDMIRxCEC.setObserver(this);
153 mFrontDev.setObserver ( &mTvMsgQueue );
154 mpUpgradeFBC = NULL;
155 if (mHdmiOutFbc) {
156 fbcIns = GetSingletonFBC();
157
158 mpUpgradeFBC = new CUpgradeFBC();
159 mpUpgradeFBC->setObserver(this);
160 }
161 mSerialA.setObserver(this);
162 mSerialB.setObserver(this);
163 mSerialC.setObserver(this);
164 mSubtitle.setObserver(this);
165 mHeadSet.setObserver(this);
166 mTvScanner.setGlobalScanerObject(&mTvScanner);
167 mAv.setObserver(&mTvMsgQueue);
168 mMainVolLutTableExtraName[0] = '\0';
169 //-----------------------------------------------------------
170 mCurAudioMasterVolume = CC_DEF_SOUND_VOL;
171 mCurAudioBalance = CC_DEF_SOUND_BALANCE_VAL;
172 mCurAudioSupperBassVolume = CC_DEF_SUPPERBASS_VOL;
173 mCurAudioSupperBassSwitch = CC_SWITCH_OFF;
174 mCurAudioSRSSurround = CC_SWITCH_OFF;
175 mCurAudioSrsDialogClarity = CC_SWITCH_OFF;
176 mCurAudioSrsTruBass = CC_SWITCH_OFF;
177 mCurAudioSPDIFSwitch = CC_SWITCH_ON;
178 mCurAudioSPDIFMode = CC_SPDIF_MODE_PCM;
179 mCurAudioBassVolume = CC_DEF_BASS_TREBLE_VOL;
180 mCurAudioTrebleVolume = CC_DEF_BASS_TREBLE_VOL;
181 mCurAudioSoundMode = CC_SOUND_MODE_END;
182 mCurAudioWallEffect = CC_SWITCH_OFF;
183 mCurAudioEQMode = CC_EQ_MODE_START;
184 mCustomAudioMasterVolume = CC_DEF_SOUND_VOL;
185 mCustomAudioBalance = CC_DEF_SOUND_BALANCE_VAL;
186 mCustomAudioSupperBassVolume = CC_DEF_SUPPERBASS_VOL;
187 mCustomAudioSupperBassSwitch = CC_SWITCH_OFF;
188 mCustomAudioSRSSurround = CC_SWITCH_OFF;
189 mCustomAudioSrsDialogClarity = CC_SWITCH_OFF;
190 mCustomAudioSrsTruBass = CC_SWITCH_OFF;
191 mCustomAudioBassVolume = CC_DEF_BASS_TREBLE_VOL;
192 mCustomAudioTrebleVolume = CC_DEF_BASS_TREBLE_VOL;
193 mCustomAudioSoundMode = CC_SOUND_MODE_END;
194 mCustomAudioWallEffect = CC_SWITCH_OFF;
195 mCustomAudioEQMode = CC_EQ_MODE_START;
196 mCustomAudioSoundEnhancementSwitch = CC_SWITCH_OFF;
197 mVolumeCompensationVal = 0;
198
199 mMainVolumeBalanceVal = 0;
200 for (int i = 0; i < CC_BAND_ITEM_CNT; i++) {
201 mCustomEQGainBuf[i] = 0;
202 mCurEQGainBuf[i] = 0;
203 mCurEQGainChBuf[i] = 0;
204 }
205 static const int WALL_EFFECT_VALUE[CC_BAND_ITEM_CNT] = { 0, 0, 1, 2, 2, 0 };
206 for (int i = 0; i < CC_BAND_ITEM_CNT; i++) {
207 mWallEffectValueBuf[i] = WALL_EFFECT_VALUE[i];
208 }
209 mTvAction &= TV_ACTION_NULL;
210 mTvStatus = TV_INIT_ED;
211 print_version_info();
212};
213
214CTv::~CTv() {
215 int iRet;
216 mpObserver = NULL;
217 CTvSettingunLoad();
218 CTvDatabase::deleteTvDb();
219 tv_config_unload();
220 mAv.Close();
221 mTvStatus = TV_INIT_ED;
222 mFrontDev.Close();
223
224 if (mpUpgradeFBC != NULL) {
225 delete mpUpgradeFBC;
226 mpUpgradeFBC = NULL;
227 }
228}
229
230void CTv::onEvent ( const CTvScanner::ScannerEvent &ev ) {
231 LOGD ( "%s, CTv::onEvent lockStatus = %d type = %d\n", __FUNCTION__, ev.mLockedStatus, ev.mType );
232
233 if ( mDtvScanRunningStatus == DTV_SCAN_RUNNING_ANALYZE_CHANNEL ) {
234 if ( ev.mType == CTvScanner::ScannerEvent::EVENT_SCAN_END ) {
235 CMessage msg;
236 msg.mType = CTvMsgQueue::TV_MSG_STOP_ANALYZE_TS;
237 msg.mpData = this;
238 mTvMsgQueue.sendMsg ( msg );
239 } else if ( ev.mType == CTvScanner::ScannerEvent::EVENT_STORE_END ) {
240 CTvEpg::EpgEvent epgev;
241 epgev.type = CTvEpg::EpgEvent::EVENT_CHANNEL_UPDATE_END;
242 mDtvScanRunningStatus = DTV_SCAN_RUNNING_NORMAL;
243 sendTvEvent ( epgev );
244 }
245 } else {
246 sendTvEvent ( ev );
247 }
248}
249
250void CTv::onEvent ( const CFrontEnd::FEEvent &ev ) {
251 const char *config_value = NULL;
252 LOGD ( "%s, FE event type = %d tvaction=%x", __FUNCTION__, ev.mCurSigStaus, mTvAction);
253 if (mTvAction & TV_ACTION_SCANNING) return;
254
255 //前端事件响应处理
256 if ( ev.mCurSigStaus == CFrontEnd::FEEvent::EVENT_FE_HAS_SIG ) { //作为信号稳定
257 if (/*m_source_input == SOURCE_TV || */m_source_input == SOURCE_DTV && (mTvAction & TV_ACTION_PLAYING)) { //atv and other tvin source not to use it, and if not playing, not use have sig
258 if ( m_win_mode == PREVIEW_WONDOW ) {
259 //mAv.setVideoAxis(m_win_pos.x1, m_win_pos.y1, m_win_pos.x2, m_win_pos.y2);
260 mAv.setVideoScreenMode ( CAv::VIDEO_WIDEOPTION_FULL_STRETCH );
261 }
262
263 if ( m_autoset_displayfreq) {
264 mTvin.VDIN_SetDisplayVFreq ( 50, mAv.getVideoDisplayResolution() , mHdmiOutFbc);
265 }
266 TvEvent::SignalInfoEvent ev;
267 ev.mStatus = TVIN_SIG_STATUS_STABLE;
268 ev.mTrans_fmt = TVIN_TFMT_2D;
269 ev.mFmt = TVIN_SIG_FMT_NULL;
270 ev.mReserved = 0;
271 sendTvEvent ( ev );
272 //if (mAv.WaittingVideoPlaying() == 0) {
273 SetDisplayMode ( mVpp.GetDisplayMode ( CTvin::Tvin_SourceInputToSourceInputType(m_source_input) ), CTvin::Tvin_SourceInputToSourceInputType(m_source_input), mAv.getVideoResolutionToFmt());
274 usleep(50 * 1000);
275 mAv.EnableVideoNow();
276 SetAudioMuteForTv ( CC_AUDIO_UNMUTE );
277 //}
278 Tv_SetAudioInSource(SOURCE_DTV);
279 }
280 } else if ( ev.mCurSigStaus == CFrontEnd::FEEvent::EVENT_FE_NO_SIG ) { //作为信号消失
281 if (/*m_source_input == SOURCE_TV || */m_source_input == SOURCE_DTV && (mTvAction & TV_ACTION_PLAYING)) { //just playing
282 config_value = config_get_str ( CFG_SECTION_TV, CFG_BLUE_SCREEN_COLOR, "null" );
283 if ( strcmp ( config_value, "black" ) == 0 ) {
284 mAv.DisableVideoWithBlackColor();
285 } else {
286 mAv.DisableVideoWithBlueColor();
287 }
288 SetAudioMuteForTv ( CC_AUDIO_MUTE );
289
290 TvEvent::SignalInfoEvent ev;
291 ev.mStatus = TVIN_SIG_STATUS_NOSIG;
292 ev.mTrans_fmt = TVIN_TFMT_2D;
293 ev.mFmt = TVIN_SIG_FMT_NULL;
294 ev.mReserved = 0;
295 sendTvEvent ( ev );
296 }
297 }
298}
299
300void CTv::onEvent ( const CTvEpg::EpgEvent &ev ) {
301 switch ( ev.type ) {
302 case CTvEpg::EpgEvent::EVENT_TDT_END:
303 LOGD ( "%s, CTv::onEvent epg time = %ld", __FUNCTION__, ev.time );
304 mTvTime.setTime ( ev.time );
305 break;
306
307 case CTvEpg::EpgEvent::EVENT_CHANNEL_UPDATE: {
308 LOGD ( "%s, CTv:: onEvent channel update", __FUNCTION__ );
309 CMessage msg;
310 msg.mType = CTvMsgQueue::TV_MSG_START_ANALYZE_TS;
311 msg.mpData = this;
312 mCurAnalyzeTsChannelID = ev.channelID;
313 mTvMsgQueue.sendMsg ( msg );
314 break;
315 }
316
317 default:
318 break;
319 }
320
321 sendTvEvent ( ev );
322}
323
324void CTv::onEvent(const CAv::AVEvent &ev) {
325 const char *config_value = NULL;
326 LOGD("AVEvent = %d", ev.type);
327 switch ( ev.type ) {
328 case CAv::AVEvent::EVENT_AV_STOP: {
329 config_value = config_get_str ( CFG_SECTION_TV, CFG_BLUE_SCREEN_COLOR, "null" );
330 if ( strcmp ( config_value, "black" ) == 0 ) {
331 mAv.DisableVideoWithBlackColor();
332 } else {
333 mAv.DisableVideoWithBlueColor();
334 }
335 SetAudioMuteForTv ( CC_AUDIO_MUTE );
336
337 TvEvent::SignalInfoEvent ev;
338 ev.mStatus = TVIN_SIG_STATUS_NOSIG;
339 ev.mTrans_fmt = TVIN_TFMT_2D;
340 ev.mFmt = TVIN_SIG_FMT_NULL;
341 ev.mReserved = 0;
342 sendTvEvent ( ev );
343 break;
344 }
345
346 case CAv::AVEvent::EVENT_AV_RESUEM: {
347 //if (mAv.WaittingVideoPlaying() == 0) {
348 SetDisplayMode ( mVpp.GetDisplayMode ( CTvin::Tvin_SourceInputToSourceInputType(m_source_input) ),
349 CTvin::Tvin_SourceInputToSourceInputType(m_source_input),
350 mAv.getVideoResolutionToFmt());
351 usleep(50 * 1000);
352 mAv.EnableVideoNow();
353 SetAudioMuteForTv ( CC_AUDIO_UNMUTE );
354 //}
355 TvEvent::AVPlaybackEvent AvPlayBackEvt;
356 AvPlayBackEvt.mMsgType = TvEvent::AVPlaybackEvent::EVENT_AV_PLAYBACK_RESUME;
357 AvPlayBackEvt.mProgramId = ( int ) ev.param;
358 sendTvEvent(AvPlayBackEvt );
359 break;
360 }
361
362 case CAv::AVEvent::EVENT_AV_SCAMBLED: {
363 config_value = config_get_str ( CFG_SECTION_TV, CFG_BLUE_SCREEN_COLOR, "null" );
364 if ( strcmp ( config_value, "black" ) == 0 ) {
365 mAv.DisableVideoWithBlackColor();
366 } else {
367 mAv.DisableVideoWithBlueColor();
368 }
369 TvEvent::AVPlaybackEvent AvPlayBackEvt;
370 AvPlayBackEvt.mMsgType = TvEvent::AVPlaybackEvent::EVENT_AV_SCAMBLED;
371 AvPlayBackEvt.mProgramId = ( int ) ev.param;
372 sendTvEvent(AvPlayBackEvt );
373 break;
374 }
375
376 case CAv::AVEvent::EVENT_AV_UNSUPPORT: {
377 LOGD("To AVS or AVS+ format");//just avs format, not unsupport, and avs avs+
378 break;
379 }
380
381 default:
382 break;
383 }
384}
385
386CTv::CTvMsgQueue::CTvMsgQueue(CTv *tv) {
387 mpTv = tv;
388}
389
390CTv::CTvMsgQueue::~CTvMsgQueue() {
391}
392
393void CTv::CTvMsgQueue::handleMessage ( CMessage &msg ) {
394 LOGD ("%s, CTv::CTvMsgQueue::handleMessage type = %d", __FUNCTION__, msg.mType);
395
396 switch ( msg.mType ) {
397 case TV_MSG_COMMON:
398 break;
399
400 case TV_MSG_STOP_ANALYZE_TS:
401 //mpTv->Tv_Stop_Analyze_Ts();
402 break;
403
404 case TV_MSG_START_ANALYZE_TS:
405 //mpTv->Tv_Start_Analyze_Ts ( pTv->mCurAnalyzeTsChannelID );
406 break;
407
408 case TV_MSG_CHECK_FE_DELAY: {
409 mpTv->mFrontDev.checkStatusOnce();
410 break;
411 }
412
413 case TV_MSG_AV_EVENT: {
414 mpTv->onEvent(*((CAv::AVEvent *)(msg.mpPara)));
415 break;
416 }
417
418 case TV_MSG_FE_EVENT: {
419 mpTv->onEvent(*((CFrontEnd::FEEvent *)(msg.mpPara)));
420 break;
421 }
422
423 case TV_MSG_SCAN_EVENT: {
424 mpTv->onEvent(*((CTvScanner::ScannerEvent *)(msg.mpPara)));
425 break;
426 }
427
428 case TV_MSG_EPG_EVENT: {
429 mpTv->onEvent(*((CTvEpg::EpgEvent *)(msg.mpPara)));
430 break;
431 }
432
433 case TV_MSG_HDMI_SR_CHANGED: {
434 int sr = ((int *)(msg.mpPara))[0];
435 mpTv->onHdmiSrChanged(sr, (((int *)(msg.mpPara))[1] == 0) ? true : false);
436 break;
437 }
438
439 case TV_MSG_ENABLE_VIDEO_LATER: {
440 int fc = msg.mpPara[0];
441 mpTv->onEnableVideoLater(fc);
442 break;
443 }
444
445 default:
446 break;
447 }
448}
449
450void CTv::onHdmiSrChanged(int sr, bool bInit) {
451 if (bInit) {
452 LOGD ( "%s, Init HDMI audio, sampling rate:%d", __FUNCTION__, sr );
453 sr = HanldeAudioInputSr(sr);
454 InitTvAudio (sr, CC_IN_USE_SPDIF_DEVICE);
455 } else {
456 LOGD ( "%s, Reset HDMI sampling rate to %d", __FUNCTION__, sr );
457 AudioChangeSampleRate ( sr );
458 }
459}
460
461void CTv::onHMDIAudioStatusChanged(int status) {
462 if (status == 0) {//change to no audio data
463 SetAudioMuteForTv ( CC_AUDIO_MUTE );
464 } else if (status == 1) {//change to audio data come
465 Tv_SetAudioInSource(m_source_input);
466 usleep(200 * 1000);
467 SetAudioMuteForTv ( CC_AUDIO_UNMUTE );
468 }
469}
470
471void CTv::CTvMsgQueue::onEvent ( const CTvScanner::ScannerEvent &ev ) {
472 CMessage msg;
473 msg.mDelayMs = 0;
474 msg.mType = CTvMsgQueue::TV_MSG_SCAN_EVENT;
475 memcpy(msg.mpPara, &ev, sizeof(ev));
476 this->sendMsg ( msg );
477}
478
479void CTv::CTvMsgQueue::onEvent ( const CFrontEnd::FEEvent &ev ) {
480 CMessage msg;
481 msg.mDelayMs = 0;
482 msg.mType = CTvMsgQueue::TV_MSG_FE_EVENT;
483 memcpy(msg.mpPara, &ev, sizeof(ev));
484 this->sendMsg ( msg );
485}
486
487void CTv::CTvMsgQueue::onEvent ( const CTvEpg::EpgEvent &ev ) {
488 CMessage msg;
489 msg.mDelayMs = 0;
490 msg.mType = CTvMsgQueue::TV_MSG_EPG_EVENT;
491 memcpy(msg.mpPara, &ev, sizeof(ev));
492 this->sendMsg ( msg );
493}
494
495void CTv::CTvMsgQueue::onEvent(const CAv::AVEvent &ev) {
496 CMessage msg;
497 msg.mDelayMs = 0;
498 msg.mType = CTvMsgQueue::TV_MSG_AV_EVENT;
499 memcpy(msg.mpPara, &ev, sizeof(ev));
500 this->sendMsg ( msg );
501}
502
503int CTv::setTvObserver ( TvIObserver *ob ) {
504 mpObserver = ob;
505 return 0;
506}
507
508void CTv::sendTvEvent ( const CTvEv &ev ) {
509 //AutoMutex lock(mLock);
510 /* send sigstate to AutoBackLight */
511 if (ev.getEvType() == CTvEv::TV_EVENT_SIGLE_DETECT) {
512 TvEvent::SignalInfoEvent *pEv = (TvEvent::SignalInfoEvent *)(&ev);
513 if (pEv->mStatus == TVIN_SIG_STATUS_STABLE) {
514 mAutoBackLight.updateSigState(mAutoBackLight.SIG_STATE_STABLE);
515 } else {
516 mAutoBackLight.updateSigState(mAutoBackLight.SIG_STATE_NOSIG);
517 }
518 }
519
520 LOGD ( "%s, tvaction=%x", __FUNCTION__, mTvAction);
521 if ((mTvAction & TV_ACTION_SCANNING) && (ev.getEvType() == CTvEv::TV_EVENT_SIGLE_DETECT)) {
522 LOGD("%s, when scanning, not send sig detect event", __FUNCTION__);
523 return;
524 }
525 if ( mpObserver != NULL ) {
526 mpObserver->onTvEvent ( ev );
527 }
528}
529
530int CTv::ClearAnalogFrontEnd() {
531 return mFrontDev.ClearAnalogFrontEnd ();
532}
533
534int CTv::dtvAutoScan() {
535 AutoMutex lock ( mLock );
536 mTvAction |= TV_ACTION_SCANNING;
537 mTvEpg.leaveChannel();
538 mAv.StopTS ();
539 mAv.DisableVideoWithBlueColor();
540 CTvProgram::CleanAllProgramBySrvType ( CTvProgram::TYPE_DTV );
541 CTvProgram::CleanAllProgramBySrvType ( CTvProgram::TYPE_RADIO );
542 CTvEvent::CleanAllEvent();
543 mTvScanner.setObserver ( &mTvMsgQueue );
544 mDtvScanRunningStatus = DTV_SCAN_RUNNING_NORMAL;
545 mFrontDev.Open(FE_DTMB);
546 mTvScanner.autoDtmbScan();//dtmb
547 return 0;
548}
549
550int CTv::dtvCleanProgramByFreq ( int freq ) {
551 int iOutRet = 0;
552 CTvChannel channel;
553 iOutRet = CTvChannel::SelectByFreq ( freq, channel );
554 if ( -1 == iOutRet ) {
555 LOGD ( "%s, Warnning: Current Freq not have program info in the ts_table\n", __FUNCTION__ );
556 }
557
558 iOutRet == CTvProgram::deleteChannelsProgram ( channel );
559 return iOutRet;
560}
561
562int CTv::dtvManualScan (int beginFreq, int endFreq, int modulation) {
563 AutoMutex lock ( mLock );
564 mTvAction |= TV_ACTION_SCANNING;
565 mTvEpg.leaveChannel();
566 mAv.StopTS ();
567 mAv.DisableVideoWithBlueColor();
568 CTvChannel::DeleteBetweenFreq(beginFreq, endFreq);
569 mTvScanner.setObserver ( &mTvMsgQueue );
570 mDtvScanRunningStatus = DTV_SCAN_RUNNING_NORMAL;
571 mFrontDev.Open(FE_DTMB);
572 int iOutRet = mTvScanner.manualDtmbScan (beginFreq, endFreq, modulation); //dtmb
573 return iOutRet;
574}
575
576int CTv::dtvAutoScanAtscLock(int attenna, int videoStd, int audioStd) {
577 //for warning
578 attenna = attenna;
579 videoStd = videoStd;
580 audioStd= audioStd;
581 //showboz
582 /* int minScanFreq, maxScanFreq, vStd, aStd;
583 vStd = CC_ATV_VIDEO_STD_PAL;
584 aStd = CC_ATV_AUDIO_STD_DK;
585 v4l2_std_id stdAndColor = mFrontDev.enumToStdAndColor(vStd, aStd);
586
587 AutoMutex lock ( mLock );
588 mTvAction |= TV_ACTION_SCANNING;
589 mTvEpg.leaveChannel();
590 mAv.StopTS ();
591 mAv.DisableVideoWithBlueColor();
592 CTvProgram::CleanAllProgramBySrvType ( CTvProgram::TYPE_DTV );
593 CTvProgram::CleanAllProgramBySrvType ( CTvProgram::TYPE_RADIO );
594 CTvEvent::CleanAllEvent();
595 mTvScanner.setObserver ( &mTvMsgQueue );
596 mDtvScanRunningStatus = DTV_SCAN_RUNNING_NORMAL;
597 mFrontDev.Open(FE_ATSC);
598 mTvScanner.autoAtscScan(CTvScanner::AM_ATSC_ATTENNA_TYPE_AIR, stdAndColor);//dtmb*/
599 return 0;
600}
601
602//searchType 0:not 256 1:is 256 Program
603int CTv::atvAutoScan(int videoStd, int audioStd, int searchType) {
604 int minScanFreq, maxScanFreq, vStd, aStd;
605 AutoMutex lock ( mLock );
606 mAv.DisableVideoWithBlueColor();
607 mTvAction |= TV_ACTION_SCANNING;
608 stopPlaying();
609 mTvScanner.setObserver ( &mTvMsgQueue );
610 SetAudioMuteForTv ( CC_AUDIO_MUTE );
611 getATVMinMaxFreq (&minScanFreq, &maxScanFreq );
612 if ( minScanFreq == 0 || maxScanFreq == 0 || minScanFreq > maxScanFreq ) {
613 LOGE ( "%s, auto scan freq set is error min=%d, max=%d", __FUNCTION__, minScanFreq, maxScanFreq );
614 return -1;
615 }
616 mSigDetectThread.setVdinNoSigCheckKeepTimes(1000, false);
617 mSigDetectThread.requestAndWaitPauseDetect();
618 mSigDetectThread.setObserver(&mTvScannerDetectObserver);
619 mTvin.Tvin_StopDecoder();
620 //if set std null AUTO, use default PAL/DK
621 //if(videoStd == CC_ATV_VIDEO_STD_AUTO) {
622 // vStd = CC_ATV_VIDEO_STD_PAL;
623 // aStd = CC_ATV_AUDIO_STD_DK;
624 //} else {
625 vStd = CC_ATV_VIDEO_STD_PAL;
626 aStd = CC_ATV_AUDIO_STD_DK;
627 //}
628 tvin_port_t source_port = mTvin.Tvin_GetSourcePortBySourceInput(SOURCE_TV);
629 mTvin.VDIN_OpenPort ( source_port );
630 v4l2_std_id stdAndColor = mFrontDev.enumToStdAndColor(vStd, aStd);
631
632 int fmt = CFrontEnd::stdEnumToCvbsFmt (vStd, aStd);
633 mTvin.AFE_SetCVBSStd ( ( tvin_sig_fmt_t ) TVIN_SIG_FMT_NULL );
634
635 if (searchType == 0) {
636 CTvProgram::CleanAllProgramBySrvType ( CTvProgram::TYPE_ATV );
637 } else if (searchType == 1) { //type for skyworth, and insert 256 prog, and just update ts table
638 }
639 minScanFreq = mFrontDev.formatATVFreq ( minScanFreq );
640 maxScanFreq = mFrontDev.formatATVFreq ( maxScanFreq );
641 LOGD("%s, atv auto scan vstd=%d, astd=%d stdandcolor=%lld", __FUNCTION__, vStd, aStd, stdAndColor);
642 mFrontDev.Open(FE_ANALOG);
643 mSigDetectThread.initSigState();
644 mSigDetectThread.resumeDetect();
645 mTvScanner.autoAtvScan ( minScanFreq, maxScanFreq, stdAndColor, searchType);
646 return 0;
647}
648
649int CTv::clearAllProgram(int arg0) {
650 CTvProgram::CleanAllProgramBySrvType ( CTvProgram::TYPE_ATV );
651 CTvProgram::CleanAllProgramBySrvType ( CTvProgram::TYPE_TV );
652 CTvProgram::CleanAllProgramBySrvType ( CTvProgram::TYPE_DTV );
653 CTvProgram::CleanAllProgramBySrvType ( CTvProgram::TYPE_RADIO);
654 return 0;
655}
656
657int CTv::atvMunualScan ( int startFreq, int endFreq, int videoStd, int audioStd,
658 int store_Type , int channel_num ) {
659 int minScanFreq, maxScanFreq, vStd, aStd;
660
661 minScanFreq = mFrontDev.formatATVFreq ( startFreq );
662 maxScanFreq = mFrontDev.formatATVFreq ( endFreq );
663 if ( minScanFreq == 0 || maxScanFreq == 0 ) {
664 LOGE ( "%s, munual scan freq set is error min=%d, max=%d", __FUNCTION__, minScanFreq, maxScanFreq );
665 return -1;
666 }
667
668 //if set std null AUTO, use default PAL/DK
669 //if(videoStd == CC_ATV_VIDEO_STD_AUTO) {
670 // vStd = CC_ATV_VIDEO_STD_PAL;
671 // aStd = CC_ATV_AUDIO_STD_DK;
672 // } else {
673 vStd = videoStd;
674 aStd = audioStd;
675 // }
676
677 AutoMutex lock ( mLock );
678 mAv.DisableVideoWithBlueColor();
679 mTvAction |= TV_ACTION_SCANNING;
680 mTvScanner.setObserver ( &mTvMsgQueue );
681
682 SetAudioMuteForTv ( CC_AUDIO_MUTE );
683 v4l2_std_id stdAndColor = mFrontDev.enumToStdAndColor(vStd, aStd);
684
685
686 tvin_port_t source_port = mTvin.Tvin_GetSourcePortBySourceInput(SOURCE_TV);
687 mTvin.VDIN_OpenPort ( source_port );
688
689 int fmt = CFrontEnd::stdEnumToCvbsFmt (vStd, aStd);
690 mTvin.AFE_SetCVBSStd ( ( tvin_sig_fmt_t ) TVIN_SIG_FMT_NULL );
691 LOGD("%s, atv manual scan vstd=%d, astd=%d stdandcolor=%lld", __FUNCTION__, vStd, aStd, stdAndColor);
692 mFrontDev.Open(FE_ANALOG);
693 return mTvScanner.ATVManualScan ( minScanFreq, maxScanFreq, stdAndColor, store_Type, channel_num);
694}
695
696int CTv::getVideoFormatInfo ( int *pWidth, int *pHeight, int *pFPS, int *pInterlace ) {
697 int iOutRet = -1;
698 AM_AV_VideoStatus_t video_status;
699
700 do {
701 if ( NULL == pWidth || NULL == pHeight || NULL == pFPS || NULL == pInterlace ) {
702 break;
703 }
704
705 iOutRet = mAv.GetVideoStatus (&video_status );
706
707 if ( AM_SUCCESS != iOutRet ) {
708 LOGD ( "%s, ERROR: Cann't Get video format info\n", __FUNCTION__);
709 break;
710 }
711
712 *pWidth = video_status.src_w;
713 *pHeight = video_status.src_h;
714 *pFPS = video_status.fps;
715 *pInterlace = video_status.interlaced;
716 //LOGD("%s, w : %d h : %d fps : %d interlaced: %d\n", __FUNCTION__, video_status.src_w,video_status.src_h,video_status.fps,video_status.interlaced);
717 } while ( false );
718
719 return iOutRet;
720}
721
722int CTv::stopScanLock() {
723 AutoMutex lock ( mLock );
724 return stopScan();
725}
726
727int CTv::stopScan() {
728 const char *config_value = NULL;
729 if (!(mTvAction & TV_ACTION_SCANNING)) {
730 LOGD("%s, tv not scanning ,return\n", __FUNCTION__);
731 return 0;
732 }
733
734 LOGD("%s, tv scanning , stop it\n", __FUNCTION__);
735 config_value = config_get_str ( CFG_SECTION_TV, CFG_BLUE_SCREEN_COLOR, "null" );
736 if ( strcmp ( config_value, "black" ) == 0 ) {
737 mAv.DisableVideoWithBlackColor();
738 } else {
739 mAv.DisableVideoWithBlueColor();
740 }
741 mSigDetectThread.requestAndWaitPauseDetect();
742 mSigDetectThread.setObserver(this);
743 mTvEpg.leaveChannel();
744 mTvScanner.stopScan();
745 mFrontDev.Close();
746 mTvAction &= ~TV_ACTION_SCANNING;
747 return 0;
748}
749
750int CTv::playProgramLock ( int progId ) {
751 /*AutoMutex lock ( mLock );
752 CTvProgram prog;
753 int ret = CTvProgram::selectByID ( progId, prog );
754
755 if ( ret != 0 ) {
756 return -1;
757 }
758 int type = prog.getProgType();
759 LOGD ( "%s, blackout = %dprog type = %d id = %d name = %s\n", __FUNCTION__, m_blackout_enable, type, progId, prog.getName().string() );
760 if (m_blackout_enable == 1) {
761 mAv.EnableVideoBlackout();
762 }else if (m_blackout_enable == 0){
763 mAv.DisableVideoBlackout();
764 }
765
766 mTvAction |= TV_ACTION_PLAYING;
767 m_cur_playing_prog_id = progId;
768 mFrontDev.Open(FE_ANALOG);
769 if ( m_source_input == SOURCE_TV && type == CTvProgram::TYPE_ATV ) {
770 playAtvProgram ( progId );
771 } else if ( m_source_input == SOURCE_DTV && ( type == CTvProgram::TYPE_DTV || type == CTvProgram::TYPE_RADIO ) ) {
772 playDtmbProgram ( progId );
773 } else {
774 LOGD ( "%s, source(%d) != type(%d),not play\n", __FUNCTION__, m_source_input, type );
775 }
776 //just for ui,left/right/stereo
777 int audio_ch = prog.getAudioChannel();
778 AM_AOUT_OutputMode_t channel = AM_AOUT_OUTPUT_STEREO;
779 if (audio_ch == 1) {
780 channel = AM_AOUT_OUTPUT_STEREO;
781 } else if (audio_ch == 2) {
782 channel = AM_AOUT_OUTPUT_DUAL_LEFT;
783 } else if (audio_ch == 3) {
784 channel = AM_AOUT_OUTPUT_DUAL_RIGHT;
785 }
786 setAudioChannel((int)channel);*/
787 return 0;
788}
789
790int CTv::playDvbcProgram ( int progId ) {
791 LOGD ( "%s, progId = %d\n", __FUNCTION__, progId );
792
793 CTvProgram prog;
794 int ret = CTvProgram::selectByID ( progId, prog );
795
796 if ( ret != 0 ) {
797 return -1;
798 }
799
800 LOGD ( "%s, prog name = %s\n", __FUNCTION__, prog.getName().string() );
801 CTvChannel channel;
802 prog.getChannel ( channel );
803
804 mFrontDev.setPara ( channel.getMode(), channel.getFrequency(), channel.getSymbolRate(), channel.getModulation() );
805
806 int vpid = 0x1fff, apid = 0x1fff, vfmt = -1, afmt = -1;
807
808 CTvProgram::Video *pV = prog.getVideo();
809 CTvProgram::Audio *pA;
810
811 if ( pV != NULL ) {
812 vpid = pV->getPID();
813 vfmt = pV->getFormat();
814 }
815
816 int aindex = prog.getCurrentAudio ( String8 ( "eng" ) );
817
818 if ( aindex >= 0 ) {
819 pA = prog.getAudio ( aindex );
820
821 if ( pA != NULL ) {
822 apid = pA->getPID();
823 afmt = pA->getFormat();
824 }
825 }
826 mTvEpg.leaveProgram();
827 mTvEpg.leaveChannel();
828 startPlayTv ( SOURCE_DTV, vpid, apid, vfmt, afmt );
829
830 mTvEpg.enterChannel ( channel.getID() );
831 mTvEpg.enterProgram ( prog.getID() );
832 return 0;
833}
834
835int CTv::getAudioTrackNum ( int progId ) {
836 int iRet, iOutCnt = 0;
837 CTvProgram prog;
838
839 do {
840 if ( 0 > progId ) {
841 break;
842 }
843
844 iRet = CTvProgram::selectByID ( progId, prog );
845 if ( 0 != iRet ) {
846 break;
847 }
848
849 iOutCnt = prog.getAudioTrackSize();
850 } while ( false );
851
852 return iOutCnt;
853}
854
855int CTv::getAudioInfoByIndex ( int progId, int idx, int *pAFmt, String8 &lang ) {
856 int iRet, iOutRet = -1;
857 CTvProgram prog;
858 CTvProgram::Audio *pA = NULL;
859
860 do {
861 if ( NULL == pAFmt || idx < 0 ) {
862 break;
863 }
864
865 iRet = CTvProgram::selectByID ( progId, prog );
866
867 if ( 0 != iRet ) {
868 break;
869 }
870
871 if ( idx >= prog.getAudioTrackSize() ) {
872 break;
873 }
874
875 pA = prog.getAudio ( idx );
876
877 if ( NULL == pA ) {
878 break;
879 }
880
881 *pAFmt = pA->getFormat();
882 lang = pA->getLang();
883 } while ( false );
884
885 return iOutRet;
886}
887
888int CTv::switchAudioTrack ( int aPid, int aFmt, int aParam ) {
889 int iOutRet = 0;
890
891 do {
892 if ( aPid < 0 || aFmt < 0 ) {
893 break;
894 }
895
896 iOutRet = mAv.SwitchTSAudio (( uint16_t ) aPid, ( AM_AV_AFormat_t ) aFmt );
897 LOGD ( "%s, iOutRet = %d AM_AV_SwitchTSAudio\n", __FUNCTION__, iOutRet );
898 } while ( false );
899
900 return iOutRet;
901}
902
903int CTv::switchAudioTrack ( int progId, int idx ) {
904 int iOutRet = 0;
905 CTvProgram prog;
906 CTvProgram::Audio *pAudio = NULL;
907 int aPid = -1;
908 int aFmt = -1;
909
910 do {
911 if ( idx < 0 ) {
912 break;
913 }
914
915 iOutRet = CTvProgram::selectByID ( progId, prog );
916
917 if ( 0 != iOutRet ) {
918 break;
919 }
920 if (prog.getAudioTrackSize() <= 1) {
921 LOGD("%s, just one audio track, not to switch", __FUNCTION__);
922 break;
923 }
924 if ( idx >= prog.getAudioTrackSize() ) {
925 break;
926 }
927
928 pAudio = prog.getAudio ( idx );
929 if ( NULL == pAudio ) {
930 break;
931 }
932
933 aPid = pAudio->getPID();
934 aFmt = pAudio->getFormat();
935 if ( aPid < 0 || aFmt < 0 ) {
936 break;
937 }
938
939 iOutRet = mAv.SwitchTSAudio (( uint16_t ) aPid, ( AM_AV_AFormat_t ) aFmt );
940 LOGD ( "%s, iOutRet = %d AM_AV_SwitchTSAudio\n", __FUNCTION__, iOutRet );
941 } while ( false );
942
943 return iOutRet;
944}
945
946int CTv::ResetAudioDecoderForPCMOutput() {
947 int iOutRet = 0;
948
949 iOutRet = mAv.ResetAudioDecoder ();
950 LOGD ( "%s, iOutRet = %d AM_AV_ResetAudioDecoder\n", __FUNCTION__, iOutRet );
951 return iOutRet;
952}
953
954int CTv::playDtvProgram ( int mode, int freq, int para1, int para2,
955 int vpid, int vfmt, int apid, int afmt, int pcr, int audioCompetation) {
956 AutoMutex lock ( mLock );
957 mTvAction |= TV_ACTION_PLAYING;
958 if ( m_blackout_enable == 1 ) {
959 mAv.EnableVideoBlackout();
960 } else if ( m_blackout_enable == 0 ) {
961 mAv.DisableVideoBlackout();
962 }
963 mFrontDev.Open(FE_ANALOG);
964 mFrontDev.setPara ( mode, freq, para1, para2);
965 mTvAction |= TV_ACTION_PLAYING;
966 startPlayTv ( SOURCE_DTV, vpid, apid, vfmt, afmt );
967 //
968 CMessage msg;
969 msg.mDelayMs = 2000;
970 msg.mType = CTvMsgQueue::TV_MSG_CHECK_FE_DELAY;
971 mTvMsgQueue.sendMsg ( msg );
972 SetCurProgramAudioVolumeCompensationVal ( audioCompetation );
973 return 0;
974}
975
976
977int CTv::playDtmbProgram ( int progId ) {
978 CTvProgram prog;
979 CTvChannel channel;
980 int vpid = 0x1fff, apid = 0x1fff, vfmt = -1, afmt = -1;
981 int aindex;
982 CTvProgram::Audio *pA;
983 CTvProgram::Video *pV;
984 int ret = CTvProgram::selectByID ( progId, prog );
985
986 SetAudioMuteForTv ( CC_AUDIO_MUTE );
987 saveDTVProgramID ( progId );
988 prog.getChannel ( channel );
989 //音量补偿
990 int chanVolCompValue = 0;
991 chanVolCompValue = GetAudioVolumeCompensationVal(progId);
992 SetCurProgramAudioVolumeCompensationVal ( chanVolCompValue );
993
994 mFrontDev.setPara ( channel.getMode(), channel.getFrequency(), channel.getBandwidth(), 0 );
995
996 pV = prog.getVideo();
997
998 if ( pV != NULL ) {
999 vpid = pV->getPID();
1000 vfmt = pV->getFormat();
1001 }
1002
1003 aindex = prog.getCurrAudioTrackIndex();
1004 if ( -1 == aindex ) { //db is default
1005 aindex = prog.getCurrentAudio ( String8 ( "eng" ) );
1006 if ( aindex >= 0 ) {
1007 prog.setCurrAudioTrackIndex ( progId, aindex );
1008 }
1009 }
1010
1011 if ( aindex >= 0 ) {
1012 pA = prog.getAudio ( aindex );
1013 if ( pA != NULL ) {
1014 apid = pA->getPID();
1015 afmt = pA->getFormat();
1016 }
1017 }
1018
1019 mTvEpg.leaveProgram();
1020 mTvEpg.leaveChannel();
1021 startPlayTv ( SOURCE_DTV, vpid, apid, vfmt, afmt );
1022 mTvEpg.enterChannel ( channel.getID() );
1023 mTvEpg.enterProgram ( prog.getID() );
1024 return 0;
1025}
1026
1027int CTv::playAtvProgram (int freq, int videoStd, int audioStd, int fineTune, int audioCompetation) {
1028 mTvAction |= TV_ACTION_PLAYING;
1029 if ( m_blackout_enable == 1 ) {
1030 mAv.EnableVideoBlackout();
1031 } else if ( m_blackout_enable == 0 ) {
1032 mAv.DisableVideoBlackout();
1033 }
1034 SetAudioMuteForTv ( CC_AUDIO_MUTE );
1035 //image selecting channel
1036 mSigDetectThread.requestAndWaitPauseDetect();
1037 mTvin.Tvin_StopDecoder();
1038 mFrontDev.Open(FE_ANALOG);
1039 //set CVBS
1040 int fmt = CFrontEnd::stdEnumToCvbsFmt (videoStd, audioStd);
1041 mTvin.AFE_SetCVBSStd ( ( tvin_sig_fmt_t ) fmt );
1042
1043 v4l2_std_id stdAndColor = mFrontDev.enumToStdAndColor (videoStd, audioStd);
1044 //set TUNER
1045 mFrontDev.setPara (FE_ANALOG, freq, stdAndColor, 1);
1046
1047 mSigDetectThread.setObserver ( this );
1048 mSigDetectThread.initSigState();
1049 mSigDetectThread.resumeDetect(1000);
1050
1051 SetCurProgramAudioVolumeCompensationVal ( audioCompetation );
1052 return 0;
1053}
1054
1055int CTv::resetFrontEndPara ( frontend_para_set_t feParms ) {
1056 if ( feParms.mode == FE_ANALOG ) {
1057 int progID = -1;
1058 int tmpFreq = feParms.freq;
1059 int tmpfineFreq = feParms.para2;
1060 int mode = feParms.mode;
1061
1062 //get tunerStd from videoStd and audioStd
1063 v4l2_std_id stdAndColor = mFrontDev.enumToStdAndColor (feParms.videoStd, feParms.audioStd);
1064
1065 LOGD("%s, resetFrontEndPara- vstd=%d astd=%d stdandcolor=%lld", __FUNCTION__, feParms.videoStd, feParms.audioStd, stdAndColor);
1066
1067 //set frontend parameters to tuner dev
1068 mSigDetectThread.requestAndWaitPauseDetect();
1069 mTvin.Tvin_StopDecoder();
1070
1071 //set CVBS
1072 int fmt = CFrontEnd::stdEnumToCvbsFmt (feParms.videoStd, feParms.audioStd );
1073 mTvin.AFE_SetCVBSStd ( ( tvin_sig_fmt_t ) fmt );
1074
1075 //set TUNER
1076 usleep(400 * 1000);
1077 mFrontDev.setPara ( FE_ANALOG, tmpFreq, stdAndColor, 1 );
1078 usleep(400 * 1000);
1079 if ( tmpfineFreq != 0 ) {
1080 mFrontDev.fineTune ( tmpfineFreq / 1000 );
1081 }
1082
1083 mSigDetectThread.initSigState();
1084 mSigDetectThread.resumeDetect();
1085 } else if ( feParms.mode == FE_DTMB ) {
1086 mFrontDev.setPara ( FE_DTMB, feParms.freq, feParms.para1, feParms.para2 );
1087 }
1088
1089 return 0;
1090}
1091
1092int CTv::resetDmxAndAvSource() {
1093 AM_DMX_Source_t curdmxSource;
1094 mFrontDev.GetTSSource ( &curdmxSource );
1095 LOGD ( "%s, AM_FEND_GetTSSource %d", __FUNCTION__, curdmxSource );
1096 mTvDmx.Close();
1097 AM_DMX_OpenPara_t para;
1098 memset ( &para, 0, sizeof ( para ) );
1099 mTvDmx.Open (para);
1100 mTvDmx.SetSource(curdmxSource );
1101 AM_AV_TSSource_t ts_source = ( AM_AV_TSSource_t ) curdmxSource;
1102 mAv.SetTSSource (ts_source );
1103 return 0;
1104}
1105
1106int CTv::SetCurProgramAudioVolumeCompensationVal ( int tmpVal ) {
1107 SetAudioVolumeCompensationVal ( tmpVal );
1108 SetAudioMasterVolume (GetAudioMasterVolume() );
1109
1110 LOGD ( "%s, VolumeCompensationVal = %d, id = %d\n", __FUNCTION__, tmpVal, m_cur_playing_prog_id );
1111 CTvProgram prog;
1112 if ( CTvProgram::selectByID ( m_cur_playing_prog_id, prog ) != 0 ) {
1113 LOGE ( "%s, atv progID is not matching the db's ret = 0\n", __FUNCTION__ );
1114 return -1;
1115 }
1116
1117 if (prog.updateVolComp ( m_cur_playing_prog_id, tmpVal ) != 0 ) {
1118 LOGE ( "%s, atv progID is not matching the db's\n", __FUNCTION__);
1119 return -1;
1120 }
1121 return 0;
1122}
1123
1124int CTv::GetAudioVolumeCompensationVal(int progxxId) {
1125 int tmpVolValue = 0;
1126 CTvProgram prog;
1127 if ( CTvProgram::selectByID ( m_cur_playing_prog_id, prog ) != 0 ) {
1128 LOGE ( "%s, atv progID is not matching the db's ret = 0\n", __FUNCTION__ );
1129 return tmpVolValue;
1130 }
1131 tmpVolValue = prog.getChanVolume ();
1132 LOGD ( "%s,progid = %d CompensationVal = %d\n", __FUNCTION__, m_cur_playing_prog_id, tmpVolValue );
1133 if (tmpVolValue > 20 || tmpVolValue < -20) tmpVolValue = 0;
1134 return tmpVolValue;
1135}
1136
1137int CTv::startPlayTv ( int source, int vid, int aid, int vfat, int afat ) {
1138 if ( source == SOURCE_DTV ) {
1139 AM_FileEcho ( DEVICE_CLASS_TSYNC_AV_THRESHOLD_MIN, AV_THRESHOLD_MIN_MS );
1140 LOGD ( "%s, startPlayTv", __FUNCTION__);
1141 mAv.StartTS (vid, aid, ( AM_AV_VFormat_t ) vfat, ( AM_AV_AFormat_t ) afat );
1142 }
1143 return 0;
1144}
1145
1146int CTv::stopPlayingLock() {
1147 AutoMutex lock ( mLock );
1148 if (getSubSwitchStatus() == 1)
1149 stopSubtitle();
1150 return stopPlaying();
1151}
1152
1153int CTv::stopPlaying() {
1154 const char *config_value = NULL;
1155 if (!(mTvAction & TV_ACTION_PLAYING)) {
1156 LOGD("%s, stopplay cur action = %x not playing , return", __FUNCTION__, mTvAction);
1157 return 0;
1158 }
1159 mSigDetectThread.requestAndWaitPauseDetect();
1160 mAv.EnableVideoBlackout();
1161 if (m_source_input == SOURCE_TV) {
1162 //first mute
1163 SetAudioMuteForTv(CC_AUDIO_MUTE);
1164 ClearAnalogFrontEnd();
1165 } else if (m_source_input == SOURCE_DTV) {
1166 //mFrontDev.setPara(FE_DTMB, 51000000, 0, 0);
1167 mAv.StopTS ();
1168 mTvEpg.leaveChannel();
1169 mTvEpg.leaveProgram();
1170 }
1171 config_value = config_get_str ( CFG_SECTION_TV, CFG_BLUE_SCREEN_COLOR, "null" );
1172 if ( strcmp ( config_value, "black" ) == 0 ) {
1173 mAv.DisableVideoWithBlackColor();
1174 } else {
1175 mAv.DisableVideoWithBlueColor();
1176 }
1177 mTvAction &= ~TV_ACTION_PLAYING;
1178 return 0;
1179}
1180
1181int CTv::GetATVAFCType() {
1182 return 1;
1183}
1184
1185int CTv::GetATVSourceTimerSwitch() {
1186 return 1;
1187}
1188
1189int CTv::getAudioChannel() {
1190 int iRet = -1;
1191 AM_AOUT_OutputMode_t audioChanneleMod;
1192 do {
1193 iRet = mAv.AudioGetOutputMode (&audioChanneleMod );
1194 if ( AM_SUCCESS != iRet ) {
1195 LOGD ( "%s, jianfei.lan GetOutputMode is FAILED %d\n", __FUNCTION__, iRet );
1196 break;
1197 }
1198 LOGD ( "%s, jianfei.lan getAudioChannel iRet : %d audioChanneleMod %d\n", __FUNCTION__, iRet, audioChanneleMod );
1199 } while ( 0 );
1200 return audioChanneleMod;
1201}
1202
1203int CTv::setAudioChannel ( int channelIdx ) {
1204 int iOutRet = 0;
1205 AM_AOUT_OutputMode_t audioChanneleMod;
1206 LOGD ( "%s, channelIdx : %d\n", __FUNCTION__, channelIdx );
1207 audioChanneleMod = ( AM_AOUT_OutputMode_t ) channelIdx;
1208 iOutRet = mAv.AudioSetOutputMode (audioChanneleMod );
1209 int aud_ch = 1;
1210 if (audioChanneleMod == AM_AOUT_OUTPUT_STEREO) {
1211 aud_ch = 1;
1212 } else if (audioChanneleMod == AM_AOUT_OUTPUT_DUAL_LEFT) {
1213 aud_ch = 2;
1214 } else if (audioChanneleMod == AM_AOUT_OUTPUT_DUAL_RIGHT) {
1215 aud_ch = 3;
1216 }
1217 CTvProgram::updateAudioChannel(m_cur_playing_prog_id, aud_ch);
1218 if ( AM_SUCCESS != iOutRet) {
1219 LOGD ( "%s, jianfei.lan TV AM_AOUT_SetOutputMode device is FAILED %d\n", __FUNCTION__, iOutRet );
1220 }
1221 return 0;
1222}
1223
1224int CTv::getFrontendSignalStrength() {
1225 int Strength = 0;
1226 Strength = mFrontDev.getStrength();
1227 return Strength;
1228}
1229
1230int CTv::getFrontendSNR() {
1231 int snr = 0;
1232 snr = mFrontDev.getSNR();
1233 return snr;
1234}
1235
1236int CTv::getFrontendBER() {
1237 int ber = 0;
1238 ber = mFrontDev.getBER();
1239 return ber;
1240}
1241
1242int CTv::getChannelInfoBydbID ( int dbID, channel_info_t &chan_info ) {
1243 CTvProgram prog;
1244 CTvChannel channel;
1245 Vector<sp<CTvProgram> > out;
1246 memset ( &chan_info, sizeof ( chan_info ), 0 );
1247 chan_info.freq = 44250000;
1248 chan_info.uInfo.atvChanInfo.videoStd = CC_ATV_VIDEO_STD_PAL;
1249 chan_info.uInfo.atvChanInfo.audioStd = CC_ATV_AUDIO_STD_DK;
1250 static const int CVBS_ID = -1;
1251 if (dbID == CVBS_ID) {
1252 unsigned char std;
1253 SSMReadCVBSStd(&std);
1254 chan_info.uInfo.atvChanInfo.videoStd = (atv_video_std_t)std;
1255 chan_info.uInfo.atvChanInfo.audioStd = CC_ATV_AUDIO_STD_DK;
1256 chan_info.uInfo.atvChanInfo.isAutoStd = (std == CC_ATV_VIDEO_STD_AUTO) ? 1 : 0;
1257 return 0;
1258 }
1259
1260 int ret = CTvProgram::selectByID ( dbID, prog );
1261 if ( ret != 0 ) {
1262 LOGD ( "getChannelinfo , select dbid=%d,is not exist", dbID);
1263 return -1;
1264 }
1265 prog.getChannel ( channel );
1266
1267 if ( CTvProgram::TYPE_ATV == prog.getProgType() ) {
1268 chan_info.freq = channel.getFrequency();
1269 chan_info.uInfo.atvChanInfo.finefreq = channel.getAfcData();
1270 LOGD("%s, get channel std = %lld", __FUNCTION__, channel.getStd());
1271 chan_info.uInfo.atvChanInfo.videoStd =
1272 ( atv_video_std_t ) CFrontEnd::stdAndColorToVideoEnum ( channel.getStd() );
1273 chan_info.uInfo.atvChanInfo.audioStd =
1274 ( atv_audio_std_t ) CFrontEnd::stdAndColorToAudioEnum ( channel.getStd() );
1275 chan_info.uInfo.atvChanInfo.isAutoStd = ((channel.getStd() & V4L2_COLOR_STD_AUTO) == V4L2_COLOR_STD_AUTO) ? 1 : 0;
1276 } else if ( CTvProgram::TYPE_DTV == prog.getProgType() || CTvProgram::TYPE_RADIO == prog.getProgType()) {
1277 chan_info.freq = channel.getFrequency();
1278 chan_info.uInfo.dtvChanInfo.strength = getFrontendSignalStrength();
1279 chan_info.uInfo.dtvChanInfo.quality = getFrontendSNR();
1280 chan_info.uInfo.dtvChanInfo.ber = getFrontendBER();
1281 }
1282
1283 return 0;
1284}
1285
1286bool CTv::Tv_Start_Analyze_Ts ( int channelID ) {
1287 int freq, ret;
1288 CTvChannel channel;
1289
1290 AutoMutex lock ( mLock );
1291 mAv.StopTS ();
1292 mAv.DisableVideoWithBlueColor();
1293 ret = CTvChannel::selectByID ( channelID, channel );
1294 if ( ret != 0 ) {
1295 LOGD ( "%s, CTv tv_updatats can not get freq by channel ID", __FUNCTION__ );
1296 return false;
1297 }
1298
1299 mTvAction |= TV_ACTION_SCANNING;
1300 freq = channel.getFrequency();
1301 LOGD ( "%s, the freq = %d", __FUNCTION__, freq );
1302 mDtvScanRunningStatus = DTV_SCAN_RUNNING_ANALYZE_CHANNEL;
1303 mTvScanner.setObserver ( &mTvMsgQueue );
1304 mTvScanner.manualDtmbScan ( freq, freq ); //dtmb
1305 return true;
1306}
1307
1308bool CTv::Tv_Stop_Analyze_Ts() {
1309 stopScanLock();
1310 return true;
1311}
1312
1313int CTv::saveATVProgramID ( int dbID ) {
1314 config_set_int ( CFG_SECTION_TV, "atv.get.program.id", dbID );
1315 return 0;
1316}
1317
1318int CTv::getATVProgramID ( void ) {
1319 return config_get_int ( CFG_SECTION_TV, "atv.get.program.id", -1 );
1320}
1321
1322int CTv::saveDTVProgramID ( int dbID ) {
1323 config_set_int ( CFG_SECTION_TV, "dtv.get.program.id", dbID );
1324 return 0;
1325}
1326
1327int CTv::getDTVProgramID ( void ) {
1328 return config_get_int ( CFG_SECTION_TV, "dtv.get.program.id", -1 );
1329}
1330
1331int CTv::getATVMinMaxFreq ( int *scanMinFreq, int *scanMaxFreq ) {
1332 int tmpVal, i = 0;
1333 const char *config_value;
1334 const char *strDelimit = ",";
1335 char *token = NULL;
1336
1337 *scanMinFreq = 44250000;
1338 *scanMaxFreq = 868250000;
1339
1340 config_value = config_get_str ( CFG_SECTION_ATV, "atv.get.min.max.freq", "null" );
1341
1342 if ( strcmp ( config_value, "null" ) == 0 ) {
1343 LOGD ( "%s, atv.get.min.max.freq not set config\n", __FUNCTION__ );
1344 return -1;
1345 }
1346
1347 char data_str[512];
1348 memset ( ( void * ) data_str, 0, sizeof ( data_str ) );
1349 strncpy ( data_str, config_value, sizeof ( data_str ) - 1 );
1350
1351 char *pSave;
1352 token = strtok_r ( data_str, strDelimit, &pSave);
1353 sscanf ( token, "%d", scanMinFreq );
1354 token = strtok_r ( NULL, strDelimit , &pSave);
1355
1356 if ( token != NULL ) {
1357 sscanf ( token, "%d", scanMaxFreq );
1358 }
1359 return 0;
1360}
1361
1362int CTv::IsDVISignal() {
1363 return ( ( TVIN_SIG_FMT_NULL != mSigDetectThread.getCurSigInfo().fmt ) && ( mSigDetectThread.getCurSigInfo().reserved & 0x1 ) );
1364}
1365
1366int CTv::getHDMIFrameRate() {
1367 int ConstRate[5] = {24, 25, 30, 50, 60};
1368 float ConstRateDiffHz[5] = {0.5, 0.5, 0.5, 2, 2}; //偏差便
1369 int fps = mSigDetectThread.getCurSigInfo().fps;
1370 int i = 0;
1371 for (; i < 5; i++) {
1372 if (abs(ConstRate[i] - fps) < ConstRateDiffHz[i])
1373 fps = ConstRate[i];
1374 }
1375 return fps;
1376}
1377
1378tv_source_input_t CTv::GetLastSourceInput ( void ) {
1379 return m_last_source_input;
1380}
1381
1382int CTv::isVgaFmtInHdmi ( void ) {
1383 tvin_sig_fmt_t fmt = mSigDetectThread.getCurSigInfo().fmt;
1384
1385 if ( CTvin::Tvin_SourceInputToSourceInputType(m_source_input) != SOURCE_TYPE_HDMI ) {
1386 return -1;
1387 }
1388 return CTvin::isVgaFmtInHdmi ( fmt );
1389}
1390
1391int CTv::isSDFmtInHdmi ( void ) {
1392 tvin_sig_fmt_t fmt = mSigDetectThread.getCurSigInfo().fmt;
1393
1394 if ( CTvin::Tvin_SourceInputToSourceInputType(m_source_input) != SOURCE_TYPE_HDMI ) {
1395 return -1;
1396 }
1397 return CTvin::isSDFmtInHdmi ( fmt );
1398}
1399
1400void CTv::print_version_info ( void ) {
1401 // print tvapi version info
1402 LOGD ( "libtvservice git branch:%s\n", tvservice_get_git_branch_info() );
1403 LOGD ( "libtvservice git version:%s\n", tvservice_get_git_version_info() );
1404 LOGD ( "libtvservice Last Changed:%s\n", tvservice_get_last_chaned_time_info() );
1405 LOGD ( "libtvservice Last Build:%s\n", tvservice_get_build_time_info() );
1406 LOGD ( "libtvservice Builer Name:%s\n", tvservice_get_build_name_info() );
1407 LOGD ( "libtvservice board version:%s\n", tvservice_get_board_version_info() );
1408 LOGD ( "\n\n");
1409 // print dvb version info
1410 LOGD ( "libdvb git branch:%s\n", dvb_get_git_branch_info() );
1411 LOGD ( "libdvb git version:%s\n", dvb_get_git_version_info() );
1412 LOGD ( "libdvb Last Changed:%s\n", dvb_get_last_chaned_time_info() );
1413 LOGD ( "libdvb Last Build:%s\n", dvb_get_build_time_info() );
1414 LOGD ( "libdvb Builer Name:%s\n", dvb_get_build_name_info() );
1415}
1416
1417int CTv::Tvin_GetTvinConfig ( void ) {
1418 const char *config_value;
1419 int i = 0;
1420
1421 config_value = config_get_str ( CFG_SECTION_TV, "tvin.kernelpet_disable", "null" );
1422 if ( strcmp ( config_value, "disable" ) == 0 ) {
1423 gTvinConfig.kernelpet_disable = true;
1424 } else {
1425 gTvinConfig.kernelpet_disable = false;
1426 }
1427
1428 config_value = config_get_str ( CFG_SECTION_TV, "tvin.kernelpet.timeout", "null" );
1429 gTvinConfig.userpet_timeout = ( unsigned int ) strtol ( config_value, NULL, 10 );
1430
1431 if ( gTvinConfig.kernelpet_timeout <= 0 || gTvinConfig.kernelpet_timeout > 40 ) {
1432 gTvinConfig.kernelpet_timeout = 10;
1433 }
1434
1435 config_value = config_get_str ( CFG_SECTION_TV, "tvin.userpet", "null" );
1436 if ( strcmp ( config_value, "enable" ) == 0 ) {
1437 gTvinConfig.userpet = true;
1438 } else {
1439 gTvinConfig.userpet = false;
1440 }
1441
1442 config_value = config_get_str ( CFG_SECTION_TV, "tvin.userpet.timeout", "null" );
1443 gTvinConfig.userpet_timeout = ( unsigned int ) strtol ( config_value, NULL, 10 );
1444
1445 if ( gTvinConfig.userpet_timeout <= 0 || gTvinConfig.userpet_timeout > 100 ) {
1446 gTvinConfig.userpet_timeout = 10;
1447 }
1448
1449 config_value = config_get_str ( CFG_SECTION_TV, "tvin.userpet.reset", "null" );
1450 if ( strcmp ( config_value, "disable" ) == 0 ) {
1451 gTvinConfig.userpet_reset = 0;
1452 } else {
1453 gTvinConfig.userpet_reset = 1;
1454 }
1455 return 0;
1456}
1457
1458TvRunStatus_t CTv::GetTvStatus() {
1459 Mutex::Autolock _l ( mLock );
1460 return mTvStatus;
1461}
1462
1463int CTv::OpenTv ( void ) {
1464 int tmp_val = 0;
1465 const char *value;
1466 Tv_Spread_Spectrum();
1467 //reboot system by fbc setting.
1468 value = config_get_str ( CFG_SECTION_TV, "fbc.get.panelinfo", "null" );
1469 LOGD("%s fbc-------------------\n", value);
1470 if ( strcmp ( value, "edid" ) == 0 ) {
1471 reboot_sys_by_fbc_edid_info();
1472 } else if ( strcmp ( value, "uart" ) == 0 ) {
1473 reboot_sys_by_fbc_uart_panel_info(fbcIns);
1474 }
1475
1476 LOGD ( "%s, tv open\n", __FUNCTION__);
1477 char prop_value[PROPERTY_VALUE_MAX] = {0};
1478
1479 mTvin.Tvin_LoadSourceInputToPortMap();
1480
1481 SSMHandlePreCopying();
1482 if ( SSMDeviceMarkCheck() < 0 ) {
1483 SSMRestoreDeviceMarkValues();
1484 Tv_SSMRestoreDefaultSetting();
1485 }
1486 mTvin.OpenTvin();
1487 mTvin.init_vdin();
1488 mTvin.Tv_init_afe();
1489 mVpp.Vpp_Init(getPqDbPath());
1490 TvAudioOpen();
1491 SetAudioVolDigitLUTTable(SOURCE_MPEG);
1492
1493 SSMSetHDCPKey();
1494 system ( "/system/bin/dec" );
1495
1496 //set color filter
1497 // SetFileAttrValue ( "/sys/module/amvideo/parameters/filt_mode", "0x2100" );
1498 value = config_get_str ( CFG_SECTION_TV, "ssm.hdmi_av.hotplug.detect.en", "null" );
1499 if ( strtoul(value, NULL, 10) == 1 ) {
1500 m_hdmiav_hotplugdetect_en = 1;
1501 } else {
1502 m_hdmiav_hotplugdetect_en = 0;
1503 }
1504
1505 value = config_get_str ( CFG_SECTION_TV, "tvin.autoset.displayfreq", "null" );
1506
1507 if ( strcmp ( value, "enable" ) == 0 ) {
1508 m_autoset_displayfreq = true;
1509 } else {
1510 m_autoset_displayfreq = false;
1511 }
1512
1513 if (mTvin.VDIN_GetDisplayVFreq() == 30) {
1514 m_autoset_displayfreq = false;
1515 }
1516
1517 Tv_HandeHDMIEDIDFilePathConfig();
1518
1519 value = config_get_str ( CFG_SECTION_TV, "ssm.handle.hdmi.edid.en", "null" );
1520
1521 if ( strtoul(value, NULL, 10) == 1 ) {
1522 LOGD( "%s, get config \"%s\" is \"%s\".\n", __FUNCTION__, "ssm.handle.hdmi.edid.en", value );
1523 //get hdmi edid use mode
1524 char prop_value[256] = {0};
1525 property_get( "ubootenv.var.outputmode", prop_value, "null" );
1526 LOGD( "%s, get property \"%s\" is \"%s\".\n", __FUNCTION__, "ubootenv.var.outputmode", prop_value );
1527 if ( strcmp ( prop_value, "null" ) != 0 ) {
1528 config_set_str ( CFG_SECTION_TV, CS_HDMI_EDID_USE_CFG, prop_value );
1529 char edid_path[256];
1530 char edid_path_cfg[256];
1531 //set file's path for hdmi edid of each port
1532 for (int i = 1; i <= SSM_HDMI_PORT_MAX; i++ ) {
1533 memset( edid_path, '\0', 256 );
1534 memset( edid_path_cfg, '\0', 256 );
1535 sprintf ( edid_path, "/system/etc/%s_port%d.bin", prop_value, i );
1536 sprintf ( edid_path_cfg, "ssm.handle.hdmi.port%d.edid.file.path", i );
1537 config_set_str ( CFG_SECTION_TV, edid_path_cfg, edid_path );
1538 }
1539 } else {
1540 //set default hdmi edid
1541 config_set_str ( CFG_SECTION_TV, CS_HDMI_EDID_USE_CFG, "hdmi_edid" );
1542 char edid_path[256];
1543 char edid_path_cfg[256];
1544 //set file's path for hdmi edid of each port
1545 for ( int i = 1; i <= SSM_HDMI_PORT_MAX; i++ ) {
1546 memset( edid_path, '\0', 256 );
1547 memset( edid_path_cfg, '\0', 256 );
1548 sprintf ( edid_path, "/system/etc/%s_port%d.bin", "hdmi_edid", i );
1549 sprintf ( edid_path_cfg, "ssm.handle.hdmi.port%d.edid.file.path", i );
1550 config_set_str ( CFG_SECTION_TV, edid_path_cfg, edid_path );
1551 }
1552 }
1553 m_is_set_hdmi_edid = true;
1554 }
1555 //
1556 unsigned char val = 0;
1557 Tvin_GetTvinConfig();
1558 m_last_source_input = SOURCE_INVALID;
1559 m_source_input = SOURCE_INVALID;
1560 m_mode_3d = VIDEO_3D_MODE_DISABLE;
1561 m_hdmi_sampling_rate = 0;
1562 int8_t blackout_enable;
1563 SSMReadBlackoutEnable(&blackout_enable);
1564 m_blackout_enable = blackout_enable;
1565
1566 //dtv init
1567 int rt = -1;
1568 //opendemux();
1569 //rt = mFrontDev.Open(FE_ANALOG);
1570 //mFrontDev.autoLoadFE();
1571 //rt = mFrontDev.Open(FE_ANALOG);
1572 AM_DMX_OpenPara_t para_dmx;
1573 memset ( &para_dmx, 0, sizeof ( AM_DMX_OpenPara_t ) );
1574 mTvDmx.Open(para_dmx );
1575 mTvDmx.SetSource (AM_DMX_SRC_TS2);
1576 mAv.Open();
1577 mTvEpg.Init ( 0, 0, 1, "eng zho chi", "GB2312" );
1578 resetDmxAndAvSource();
1579 // mSourceConnectDetectThread.startDetect();
1580 mSourceConnectDetectThread.startDetect();
1581
1582 if (SSMReadSerialCMDSwitchValue() == 1) {
1583 SetSerialSwitch(SERIAL_A, 1);
1584 }
1585 ClearAnalogFrontEnd();
1586
1587 mTvStatus = TV_OPEN_ED;
1588
1589 mHDMIRxCEC.start();
1590 mAutoPQparam.startAutoPQ(CTvin::Tvin_SourceInputToSourceInputType(SOURCE_MPEG));
1591 return 0;
1592}
1593
1594int CTv::CloseTv ( void ) {
1595 LOGD ( "tv close");
1596 mSigDetectThread.stopDetect();
1597 if (mpUpgradeFBC != NULL) {
1598 mpUpgradeFBC->stop();
1599 }
1600 mTvin.Tv_uninit_afe();
1601 mTvin.uninit_vdin();
1602 mVpp.Vpp_Uninit();
1603 TvMisc_DisableWDT ( gTvinConfig.userpet );
1604 mTvStatus = TV_CLOSE_ED;
1605 return 0;
1606}
1607
1608int CTv::StartTvLock () {
1609 LOGD ( "%s, tv start status = %d", __FUNCTION__, mTvStatus);
1610 if (mTvStatus == TV_START_ED)
1611 return 0;
1612
1613 Mutex::Autolock _l ( mLock );
1614 mTvAction |= TV_ACTION_STARTING;
1615 mAv.ClearVideoBuffer();
1616 SwitchAVOutBypass(0);
1617 InitSetTvAudioCard();
1618 SetAudioMuteForTv(CC_AUDIO_MUTE);
1619 mFrontDev.Open(FE_ANALOG);
1620 mFrontDev.autoLoadFE();
1621 mSigDetectThread.startDetect();
1622 mSigDetectThread.initSigState();
1623 mTvMsgQueue.startMsgQueue();
1624 resetDmxAndAvSource();
1625 SetDisplayMode ( mVpp.GetDisplayMode ( CTvin::Tvin_SourceInputToSourceInputType(m_source_input) ), CTvin::Tvin_SourceInputToSourceInputType(m_source_input), mSigDetectThread.getCurSigInfo().fmt);
1626 TvMisc_EnableWDT ( gTvinConfig.kernelpet_disable, gTvinConfig.userpet, gTvinConfig.kernelpet_timeout, gTvinConfig.userpet_timeout, gTvinConfig.userpet_reset );
1627 am_phase_t am_phase;
1628 if (mVpp.getPqData()->PQ_GetPhaseArray ( &am_phase ) == 0 ) {
1629 mTvin.TvinApi_SetCompPhase(am_phase);
1630 }
1631 mTvin.TvinApi_SetCompPhaseEnable ( 1 );
1632 mTvin.VDIN_EnableRDMA ( 1 );
1633
1634 //win pos
1635 tvin_window_pos_t win_pos;
1636 Vpp_GetDisplayResolutionInfo(&win_pos);
1637 SetPreviewWindow ( win_pos );
1638
1639 mTvin.Tvin_RemovePath ( TV_PATH_TYPE_TVIN );
1640 if ( mTvin.Tvin_RemovePath ( TV_PATH_TYPE_DEFAULT ) ) {
1641 mTvin.Tvin_AddPath ( TV_PATH_DECODER_NEW3D_WITHOUTPPMGR_AMVIDEO );
1642 }
1643
1644 mAv.SetVideoWindow (0, 0, 0, 0 );
1645
1646 mTvAction &= ~TV_ACTION_STARTING;
1647 mTvStatus = TV_START_ED;
1648 return 0;
1649}
1650
1651int CTv::DoInstabootSuspend() {
1652 CTvDatabase::GetTvDb()->UnInitTvDb();
1653 CTvSettingdoSuspend();
1654 mVpp.doSuspend();
1655 LOGD("%s, \n", __FUNCTION__);
1656 return 0;
1657}
1658
1659int CTv::DoInstabootResume() {
1660 CTvDatabase::GetTvDb()->InitTvDb(TV_DB_PATH);
1661 CTvSettingdoResume();
1662 mVpp.doResume();
1663 LOGD("%s, \n", __FUNCTION__);
1664 return 0;
1665}
1666
1667int CTv::DoSuspend(int type) {
1668 if (type == 1) {
1669 DoInstabootSuspend();
1670 }
1671 return 0;
1672}
1673
1674int CTv::DoResume(int type) {
1675 if (type == 1) {
1676 DoInstabootResume();
1677 }
1678 return 0;
1679}
1680
1681int CTv::StopTvLock ( void ) {
1682 LOGD("%s, call Tv_Stop status = %d \n", __FUNCTION__, mTvStatus);
1683 const char *value;
1684 Mutex::Autolock _l ( mLock );
1685 mAv.DisableVideoWithBlackColor();
1686 mVpp.LoadVppSettings ( SOURCE_TYPE_MPEG, TVIN_SIG_FMT_NULL, INDEX_2D, TVIN_TFMT_2D );
1687 //we should stop audio first for audio mute.
1688 mTvAction |= TV_ACTION_STOPING;
1689 mTvin.Tvin_StopDecoder();
1690 mTvin.Tvin_RemovePath ( TV_PATH_TYPE_TVIN );
1691 mTvin.VDIN_ClosePort();
1692 mTvMsgQueue.clearMsg();
1693 mSigDetectThread.requestAndWaitPauseDetect();
1694 //stop scan if scanning
1695 stopScan();
1696 mFrontDev.SetAnalogFrontEndTimerSwitch(0);
1697 //first stop play(if playing)
1698 stopPlaying();
1699 //
1700 setAudioChannel(AM_AOUT_OUTPUT_STEREO);
1701 mTvin.setMpeg2Vdin(0);
1702 mAv.setLookupPtsForDtmb(0);
1703 SwitchAVOutBypass(0);
1704 tv_audio_channel_e audio_channel = mTvin.Tvin_GetInputSourceAudioChannelIndex (SOURCE_MPEG);
1705 AudioLineInSelectChannel( audio_channel );
1706 AudioCtlUninit();
1707 SetAudioVolDigitLUTTable(SOURCE_MPEG);
1708 Tv_SetAudioInSource(SOURCE_MPEG);
1709 tvin_window_pos_t win_pos;
1710 Vpp_GetDisplayResolutionInfo(&win_pos);
1711 SetPreviewWindow (win_pos );
1712 //mVpp.LoadVppSettings ( SOURCE_TYPE_MPEG, TVIN_SIG_FMT_NULL, INDEX_2D, TVIN_TFMT_2D );
1713 SetDisplayMode ( mVpp.GetDisplayMode ( CTvin::Tvin_SourceInputToSourceInputType(SOURCE_MPEG) ), CTvin::Tvin_SourceInputToSourceInputType(SOURCE_MPEG), mSigDetectThread.getCurSigInfo().fmt);
1714 RefreshAudioMasterVolume ( SOURCE_MPEG );
1715 mVpp.VPP_SetScalerPathSel(0);
1716 mVpp.VPP_SetVideoCrop ( 0, 0, 0, 0 );
1717 m_last_source_input = SOURCE_INVALID;
1718 m_source_input = SOURCE_INVALID;
1719 mFrontDev.Close();
1720 mTvAction &= ~TV_ACTION_STOPING;
1721 mTvStatus = TV_STOP_ED;
1722 if ( Get2d4gHeadsetEnable() == 1 ) {
1723 property_set("audio.tv_open.flg", "0");
1724 }
1725
1726 Tv_SetDDDRCMode(SOURCE_MPEG);
1727 mAv.DisableVideoWithBlackColor();
1728 //mAutoPQparam.startAutoPQ(CTvin::Tvin_SourceInputToSourceInputType(SOURCE_MPEG));
1729 mAv.ClearVideoBuffer();
1730 mAv.EnableVideoBlackout();
1731 SetAudioMuteForTv ( CC_AUDIO_UNMUTE );
1732 return 0;
1733}
1734
1735const char *CTv::getPqDbPath() {
1736 return config_get_str(CFG_SECTION_TV, "pq_db_path", "/param/pq.db");
1737}
1738
1739int CTv::Tv_MiscSetBySource ( tv_source_input_t source_input ) {
1740 int ret = -1;
1741
1742 switch ( source_input ) {
1743 case SOURCE_TV:
1744 mVpp.VPP_SetScalerPathSel(1);
1745 ret = SetFileAttrValue ( "/sys/module/am_vecm/parameters/dnlp_adj_level", "4" );
1746 break;
1747
1748 case SOURCE_HDMI1:
1749 case SOURCE_HDMI2:
1750 case SOURCE_HDMI3:
1751 mVpp.VPP_SetScalerPathSel(0);
1752 //ret = mVpp.Tv_SavePanoramaMode ( VPP_PANORAMA_MODE_FULL, SOURCE_TYPE_HDMI );
1753 ret |= SetFileAttrValue ( "/sys/module/am_vecm/parameters/dnlp_adj_level", "5" );
1754 break;
1755
1756 case SOURCE_DTV:
1757 mVpp.VPP_SetScalerPathSel(0);
1758
1759 case SOURCE_AV1:
1760 case SOURCE_AV2:
1761 case SOURCE_VGA:
1762 mVpp.VPP_SetScalerPathSel(1);
1763 ret |= SetFileAttrValue ( "/sys/module/am_vecm/parameters/dnlp_adj_level", "5" );
1764 break;
1765
1766 case SOURCE_SVIDEO:
1767 case SOURCE_IPTV:
1768 mVpp.VPP_SetScalerPathSel(1);
1769 default:
1770 mVpp.VPP_SetScalerPathSel(0);
1771 ret |= SetFileAttrValue ( "/sys/module/am_vecm/parameters/dnlp_adj_level", "5" );
1772 break;
1773 }
1774 return ret;
1775}
1776
1777int CTv::SetSourceSwitchInput (tv_source_input_t source_input ) {
1778 Mutex::Autolock _l ( mLock );
1779 LOGD ( "%s, source input = %d", __FUNCTION__, source_input );
1780 tv_source_input_t cur_source_input = m_source_input;
1781 tvin_port_t cur_port;
1782 const char *config_value = NULL;
1783
1784 Tv_SetDDDRCMode(source_input);
1785 if (source_input == cur_source_input ) {
1786 LOGW ( "%s,same input change display mode", __FUNCTION__ );
1787 return 0;
1788 }
1789
1790 //if HDMI, need to set EDID of each port
1791 if (m_is_set_hdmi_edid) {
1792 int tmp_ret = 0;
1793 switch ( source_input ) {
1794 case SOURCE_HDMI1:
1795 tmp_ret = SSMSetHDMIEdid(1);
1796 break;
1797 case SOURCE_HDMI2:
1798 tmp_ret = SSMSetHDMIEdid(2);
1799 break;
1800 case SOURCE_HDMI3:
1801 tmp_ret = SSMSetHDMIEdid(3);
1802 break;
1803 default:
1804 tmp_ret = -1;
1805 break;
1806 }
1807 if (tmp_ret < 0)
1808 LOGE ( "%s, do not set hdmi port%d edid.ret=%d", __FUNCTION__, source_input - 4, tmp_ret );
1809 }
1810 mTvAction |= TV_ACTION_SOURCE_SWITCHING;
1811 m_cur_playing_prog_id = -1;
1812 //
1813 SetAudioMuteForTv(CC_AUDIO_MUTE);
1814 mSigDetectThread.requestAndWaitPauseDetect();
1815 config_value = config_get_str ( CFG_SECTION_TV, CFG_BLUE_SCREEN_COLOR, "null" );
1816 //if ( strcmp ( config_value, "black" ) == 0 ) {
1817 // mAv.DisableVideoWithBlackColor();
1818 //} else {
1819 // mAv.DisableVideoWithBlueColor();
1820 //}
1821 mAv.DisableVideoWithBlackColor();
1822 //enable blackout, when play,disable it
1823 mAv.EnableVideoBlackout();
1824 //set front dev mode
1825 if ( source_input == SOURCE_TV ) {
1826 mFrontDev.Close();
1827 mFrontDev.Open(FE_ANALOG);
1828 mFrontDev.SetAnalogFrontEndTimerSwitch(GetATVSourceTimerSwitch());
1829 //mFrontDev.setMode ( FE_ANALOG );
1830 } else if ( source_input == SOURCE_DTV ) {
1831 mFrontDev.Close();
1832 mFrontDev.Open(FE_ANALOG);
1833 //mFrontDev.setMode ( FE_DTMB);
1834 mFrontDev.SetAnalogFrontEndTimerSwitch(0);
1835 } else {
1836 mFrontDev.Close();
1837 mFrontDev.SetAnalogFrontEndTimerSwitch(0);
1838 }
1839
1840 //ok
1841 m_last_source_input = m_source_input;
1842 m_source_input = source_input;
1843 SSMSaveSourceInput ( source_input );
1844
1845 tv_source_input_t pre_source_input = cur_source_input;//change
1846 cur_source_input = source_input;
1847
1848 SetAudioVolumeCompensationVal ( 0 );
1849
1850 if ( source_input == SOURCE_DTV ) {
1851 //we should stop audio first for audio mute.
1852 SwitchAVOutBypass(0);
1853 tv_audio_channel_e audio_channel = mTvin.Tvin_GetInputSourceAudioChannelIndex (SOURCE_MPEG);
1854 AudioLineInSelectChannel( audio_channel );
1855 AudioCtlUninit();
1856 SetAudioVolDigitLUTTable(SOURCE_MPEG);
1857 //
1858 mTvin.Tvin_StopDecoder();
1859 mTvin.Tvin_RemovePath ( TV_PATH_TYPE_TVIN );
1860 mTvin.VDIN_ClosePort();
1861 //double confirm we set the main volume lut buffer to mpeg
1862 RefreshAudioMasterVolume ( SOURCE_MPEG );
1863 RefreshSrsEffectAndDacGain();
1864 SetCustomEQGain();
1865 mTvin.setMpeg2Vdin(1);
1866 mAv.setLookupPtsForDtmb(1);
1867 //mVpp.LoadVppSettings ( SOURCE_TYPE_DTV, TVIN_SIG_FMT_NULL, INDEX_2D, TVIN_TFMT_2D );
1868 //mAutoPQparam.startAutoPQ(CTvin::Tvin_SourceInputToSourceInputType(SOURCE_DTV));
1869 Tv_SetAudioInSource ( source_input );
1870 } else {
1871 mAutoPQparam.stopAutoPQ();
1872 mTvin.setMpeg2Vdin(0);
1873 mAv.setLookupPtsForDtmb(0);
1874 mTvin.Tvin_AddPath ( TV_PATH_VDIN_NEW3D_WITHOUTPPMGR_AMVIDEO );
1875 }
1876 cur_port = mTvin.Tvin_GetSourcePortBySourceInput ( cur_source_input );
1877 Tv_MiscSetBySource ( source_input );
1878
1879 //only DTV->TVIN or TVIN->DTV need start resource detect thread
1880 if ( ( pre_source_input == SOURCE_DTV || cur_source_input == SOURCE_DTV ) &&
1881 ( cur_source_input != pre_source_input ) ) {
1882 LOGD ( "%s, dtv need resource detect\n", __FUNCTION__ );
1883 int isNeedCheckD2D3 = ( gTvinConfig.memory512m) ? 1 : 0;
1884 static int sigchkcnt = 0;
1885 while ( true ) {
1886 if ( ( mTvin.Tvin_CheckPathActive ( TV_PATH_TYPE_DEFAULT, isNeedCheckD2D3 ) == TV_PATH_STATUS_INACTIVE )
1887 && ( mTvin.Tvin_CheckPathActive ( TV_PATH_TYPE_TVIN, isNeedCheckD2D3 ) == TV_PATH_STATUS_INACTIVE ) ) {
1888 LOGD("%s, path check is ok, and break\n", __FUNCTION__);
1889 break;
1890 } else {
1891 if (sigchkcnt++ > 20) {
1892 sigchkcnt = 0;
1893 break;
1894 }
1895 LOGW ( "%s,resource is busy.", __FUNCTION__);
1896 }
1897 }
1898 }
1899
1900 if ( source_input != SOURCE_DTV ) {
1901 // Uninit data
1902 UnInitTvAudio();
1903 if (source_input == SOURCE_HDMI1 || source_input == SOURCE_HDMI2 || source_input == SOURCE_HDMI3 ||
1904 source_input == SOURCE_MPEG || source_input == SOURCE_DTV ) {
1905 SwitchAVOutBypass(0);
1906 } else {
1907 SwitchAVOutBypass(1);
1908 }
1909
1910 tv_audio_channel_e audio_channel = mTvin.Tvin_GetInputSourceAudioChannelIndex (source_input);
1911 AudioLineInSelectChannel( audio_channel );
1912
1913 Tv_SetAudioInSource ( source_input );
1914 if ( source_input == SOURCE_HDMI1 || source_input == SOURCE_HDMI2 || source_input == SOURCE_HDMI3 ) {
1915 m_hdmi_sampling_rate = 0;
1916 m_hdmi_audio_data = 0;
1917 } else {
1918 InitTvAudio ( 48000, CC_IN_USE_I2S_DEVICE);
1919 HanldeAudioInputSr(-1);
1920 }
1921 //===========================================
1922 if ( mTvin.SwitchPort ( cur_port ) == 0 ) { //ok
1923 //==========================================
1924 unsigned char std;
1925 SSMReadCVBSStd(&std);
1926 int fmt = CFrontEnd::stdEnumToCvbsFmt (std, CC_ATV_AUDIO_STD_AUTO);
1927 mTvin.AFE_SetCVBSStd ( ( tvin_sig_fmt_t ) fmt );
1928
1929 //for HDMI source connect detect
1930 mTvin.VDIN_OpenHDMIPinMuxOn(true);
1931 mVpp.Vpp_ResetLastVppSettingsSourceType();
1932 //==========================================
1933 m_sig_stable_nums = 0;
1934 mSigDetectThread.setObserver ( this );
1935 mSigDetectThread.initSigState();
1936 int resumeLater = 0;
1937 if (source_input == SOURCE_HDMI1 || source_input == SOURCE_HDMI2 || source_input == SOURCE_HDMI3) {
1938 resumeLater = 1000;
1939 } else {
1940 resumeLater = 1500;
1941 }
1942 mSigDetectThread.setVdinNoSigCheckKeepTimes(150, true);
1943 mSigDetectThread.resumeDetect(resumeLater);
1944 }
1945 }
1946
1947 Tv_SetAudioSourceType(source_input);
1948 RefreshAudioMasterVolume(source_input);
1949 Tv_SetAudioOutputSwap_Type(source_input);
1950 //Tv_ADCDigitalCapture_Volume();
1951 Tv_SetAVOutPut_Input_gain(source_input);
1952
1953 mTvAction &= ~ TV_ACTION_SOURCE_SWITCHING;
1954 return 0;
1955}
1956
1957void CTv::onSigToStable() {
1958 if (m_autoset_displayfreq) {
1959 int freq = 60;
1960 if (CTvin::Tvin_SourceInputToSourceInputType(m_source_input) == SOURCE_TYPE_HDMI ) {
1961 int fps = getHDMIFrameRate();
1962 LOGD("onSigToStable HDMI fps = %d", fps);
1963 if ((30 == fps) || (60 == fps)) {
1964 freq = 60;
1965 } else {
1966 freq = 50;
1967 }
1968 } else if ( CTvin::Tvin_is50HzFrameRateFmt ( mSigDetectThread.getCurSigInfo().fmt ) ) {
1969 freq = 50;
1970 }
1971
1972 mTvin.VDIN_SetDisplayVFreq ( freq, mAv.getVideoDisplayResolution(), mHdmiOutFbc );
1973 LOGD ( "%s, SetDisplayVFreq %dHZ.", __FUNCTION__, freq);
1974 }
1975 //showbo mark hdmi auto 3d, tran fmt is 3d, so switch to 3d
1976
1977 mVpp.LoadVppSettings (CTvin::Tvin_SourceInputToSourceInputType(m_source_input), mSigDetectThread.getCurSigInfo().fmt, Check2Dor3D(m_mode_3d, mSigDetectThread.getCurSigInfo().trans_fmt ), mSigDetectThread.getCurSigInfo().trans_fmt );
1978
1979 if ( m_win_mode == PREVIEW_WONDOW ) {
1980 mAv.setVideoAxis(m_win_pos.x1, m_win_pos.y1, m_win_pos.x2, m_win_pos.y2);
1981 mAv.setVideoScreenMode ( CAv::VIDEO_WIDEOPTION_FULL_STRETCH );
1982 } else {
1983 SetDisplayMode ( mVpp.GetDisplayMode ( CTvin::Tvin_SourceInputToSourceInputType(m_source_input) ), CTvin::Tvin_SourceInputToSourceInputType(m_source_input), mSigDetectThread.getCurSigInfo().fmt);
1984 }
1985 m_sig_stable_nums = 0;
1986}
1987
1988void CTv::onSigStillStable() {
1989 if ( m_sig_stable_nums == 20) {
1990 tvin_info_t info = mSigDetectThread.getCurSigInfo();
1991 TvEvent::SignalInfoEvent ev;
1992 ev.mTrans_fmt = info.trans_fmt;
1993 ev.mFmt = info.fmt;
1994 ev.mStatus = info.status;
1995 ev.mReserved = getHDMIFrameRate();
1996 sendTvEvent ( ev );
1997 }
1998 if (m_sig_stable_nums == 2) {
1999 LOGD("still stable , to start decoder");
2000 int startdec_status = mTvin.Tvin_StartDecoder ( mSigDetectThread.getCurSigInfo() );
2001 if ( startdec_status == 0 ) { //showboz codes from start decode fun
2002 const char *value = config_get_str ( CFG_SECTION_TV, "tvin.db.reg.en", "null" );
2003 if ( strcmp ( value, "enable" ) == 0 ) {
2004 usleep ( 20 * 1000 );
2005 Tvin_SetPLLValues ();
2006 usleep ( 20 * 1000 );
2007 SetCVD2Values ();
2008 }
2009 }
2010 }
2011 if ( m_sig_stable_nums == 3) {
2012 LOGD("still stable , to unmute audio/video");
2013 CMessage msg;
2014 msg.mDelayMs = 0;
2015 msg.mType = CTvMsgQueue::TV_MSG_ENABLE_VIDEO_LATER;
2016 msg.mpPara[0] = 2;
2017 mTvMsgQueue.sendMsg ( msg );
2018 m_hdmi_audio_data = 0;
2019 }
2020 m_sig_stable_nums++;
2021}
2022
2023void CTv::onEnableVideoLater(int framecount) {
2024 LOGD("onEnableVideoLater framecount = %d", framecount);
2025 mAv.EnableVideoWhenVideoPlaying(2);
2026 //if(CTvin::Tvin_SourceInputToSourceInputType(m_source_input) != SOURCE_TYPE_HDMI ){
2027 if (CTvin::Tvin_SourceInputToSourceInputType(m_source_input) != SOURCE_TYPE_HDMI ) {
2028 SetAudioMuteForTv ( CC_AUDIO_UNMUTE );
2029 Tv_SetAudioInSource(m_source_input);
2030 //}
2031 }
2032}
2033
2034void CTv::Tv_SetAVOutPut_Input_gain(tv_source_input_t source_input) {
2035 int nPgaValueIndex = 0;
2036 int nAdcValueIndex = 0;
2037 int nDdcValueIndex= 0;
2038 int tmpAvoutBufPtr[9];
2039
2040 if (GetAvOutGainBuf_Cfg(tmpAvoutBufPtr) != 0) {
2041 GetDefaultAvOutGainBuf(tmpAvoutBufPtr);
2042 }
2043
2044 switch (source_input) {
2045 case SOURCE_AV1:
2046 case SOURCE_AV2:
2047 nPgaValueIndex = 0;
2048 nAdcValueIndex = 1;
2049 nDdcValueIndex = 2;
2050 break;
2051 case SOURCE_HDMI1:
2052 case SOURCE_HDMI2:
2053 case SOURCE_HDMI3:
2054 case SOURCE_DTV:
2055 case SOURCE_MPEG:
2056 nPgaValueIndex = 3;
2057 nAdcValueIndex = 4;
2058 nDdcValueIndex = 5;
2059 break;
2060 case SOURCE_TV:
2061 nPgaValueIndex = 6;
2062 nAdcValueIndex = 7;
2063 nDdcValueIndex = 8;
2064 break;
2065 default:
2066 break;
2067 }
2068
2069 SetPGA_IN_Value(tmpAvoutBufPtr[nPgaValueIndex]);
2070 SetADC_Digital_Capture_Volume(tmpAvoutBufPtr[nAdcValueIndex]);
2071 SetDAC_Digital_PlayBack_Volume(tmpAvoutBufPtr[nDdcValueIndex]);
2072}
2073
2074void CTv::onSigStableToUnstable() {
2075 LOGD ( "%s, stable to unstable\n", __FUNCTION__);
2076 SetAudioMuteForTv(CC_AUDIO_MUTE);
2077 mAv.DisableVideoWithBlackColor();
2078 mTvin.Tvin_StopDecoder();
2079}
2080
2081void CTv::onSigStableToUnSupport() {
2082 SetAudioMuteForTv(CC_AUDIO_MUTE);
2083 mAv.DisableVideoWithBlackColor();
2084 mTvin.Tvin_StopDecoder();
2085
2086 tvin_info_t info = mSigDetectThread.getCurSigInfo();
2087 TvEvent::SignalInfoEvent ev;
2088 ev.mTrans_fmt = info.trans_fmt;
2089 ev.mFmt = info.fmt;
2090 ev.mStatus = info.status;
2091 ev.mReserved = info.reserved;
2092 sendTvEvent ( ev );
2093 LOGD ( "%s, Enable blackscreen for signal change in StableToUnSupport!", __FUNCTION__ );
2094}
2095
2096void CTv::onSigStableToNoSig() {
2097 SetAudioMuteForTv(CC_AUDIO_MUTE);
2098 const char * value = config_get_str ( CFG_SECTION_TV, CFG_BLUE_SCREEN_COLOR, "null" );
2099 if ( strcmp ( value, "black" ) == 0 ) {
2100 mAv.DisableVideoWithBlackColor();
2101 } else {
2102 mAv.DisableVideoWithBlueColor();
2103 }
2104 //SetAudioMuteForTv(CC_AUDIO_MUTE);
2105 mTvin.Tvin_StopDecoder();
2106
2107 tvin_info_t info = mSigDetectThread.getCurSigInfo();
2108 TvEvent::SignalInfoEvent ev;
2109 ev.mTrans_fmt = info.trans_fmt;
2110 ev.mFmt = info.fmt;
2111 ev.mStatus = info.status;
2112 ev.mReserved = info.reserved;
2113 sendTvEvent ( ev );
2114 LOGD ( "%s, Enable bluescreen for signal change in StableToNoSig!", __FUNCTION__);
2115}
2116
2117void CTv::onSigUnStableToUnSupport() {
2118 mAv.DisableVideoWithBlackColor();
2119 mTvin.Tvin_StopDecoder();
2120 tvin_info_t info = mSigDetectThread.getCurSigInfo();
2121
2122 TvEvent::SignalInfoEvent ev;
2123 ev.mTrans_fmt = info.trans_fmt;
2124 ev.mFmt = info.fmt;
2125 ev.mStatus = info.status;
2126 ev.mReserved = info.reserved;
2127 sendTvEvent ( ev );
2128 LOGD ( "%s, Enable blackscreen for signal change in UnStableToUnSupport!", __FUNCTION__);
2129}
2130
2131void CTv::onSigUnStableToNoSig() {
2132 SetAudioMuteForTv(CC_AUDIO_MUTE);
2133 const char * value = config_get_str ( CFG_SECTION_TV, CFG_BLUE_SCREEN_COLOR, "null" );
2134 if ( strcmp ( value, "black" ) == 0 ) {
2135 mAv.DisableVideoWithBlackColor();
2136 } else {
2137 mAv.DisableVideoWithBlueColor();
2138 //SetAudioMuteForTv(CC_AUDIO_MUTE);
2139 }
2140 mTvin.Tvin_StopDecoder();
2141
2142 tvin_info_t info = mSigDetectThread.getCurSigInfo();
2143 TvEvent::SignalInfoEvent ev;
2144 ev.mTrans_fmt = info.trans_fmt;
2145 ev.mFmt = info.fmt;
2146 ev.mStatus = info.status;
2147 ev.mReserved = info.reserved;
2148 sendTvEvent ( ev );
2149 LOGD ( "%s, Enable bluescreen for signal change in UnStableToNoSig! status = %d", __FUNCTION__, ev.mStatus );
2150}
2151
2152void CTv::onSigNullToNoSig() {
2153 SetAudioMuteForTv(CC_AUDIO_MUTE);
2154 const char * value = config_get_str ( CFG_SECTION_TV, CFG_BLUE_SCREEN_COLOR, "null" );
2155 if ( strcmp ( value, "black" ) == 0 ) {
2156 mAv.DisableVideoWithBlackColor();
2157 } else {
2158 mAv.DisableVideoWithBlueColor();
2159 //SetAudioMuteForTv(CC_AUDIO_MUTE);
2160 }
2161 mTvin.Tvin_StopDecoder();
2162
2163 tvin_info_t info = mSigDetectThread.getCurSigInfo();
2164
2165 TvEvent::SignalInfoEvent ev;
2166 ev.mTrans_fmt = info.trans_fmt;
2167 ev.mFmt = info.fmt;
2168 ev.mStatus = info.status;
2169 ev.mReserved = info.reserved;
2170 sendTvEvent ( ev );
2171 LOGD ( "%s, Enable bluescreen for signal change in NullToNoSig!", __FUNCTION__);
2172}
2173
2174void CTv::onSigNoSigToUnstable() {
2175 const char * value = config_get_str ( CFG_SECTION_TV, CFG_BLUE_SCREEN_COLOR, "null" );
2176 if ( strcmp ( value, "black" ) == 0 ) {
2177 mAv.DisableVideoWithBlackColor();
2178 } else {
2179 mAv.DisableVideoWithBlueColor();
2180 }
2181 LOGD("Enable bluescreen for signal change in NoSigToUnstable\n");
2182}
2183
2184void CTv::onSigStillUnstable(){
2185}
2186
2187void CTv::onSigStillNosig(){
2188}
2189
2190void CTv::onSigStillNoSupport() {
2191 return;//change for gxtvbb, don't send event when sitll not support
2192 /*
2193 tvin_info_t info = mSigDetectThread.getCurSigInfo();
2194 TvEvent::SignalInfoEvent SigEv;
2195 SigEv.mTrans_fmt = info.trans_fmt;
2196 SigEv.mFmt = info.fmt;
2197 SigEv.mStatus = info.status;
2198 SigEv.mReserved = info.reserved;
2199 sendTvEvent ( SigEv );
2200 LOGD ( "%s, Unsupport signal", __FUNCTION__);
2201 */
2202}
2203
2204void CTv::onSigStillNull(){
2205}
2206
2207void CTv::onStableSigFmtChange() {
2208 if ( m_autoset_displayfreq) {
2209 if (CTvin::Tvin_SourceInputToSourceInputType(m_source_input) == SOURCE_TYPE_HDMI ) {
2210 int fps = getHDMIFrameRate();
2211 LOGD("onSigToStable HDMI fps get = %d", fps);
2212 }
2213 int freq = 60;
2214 if ( CTvin::Tvin_is50HzFrameRateFmt ( mSigDetectThread.getCurSigInfo().fmt ) ) {
2215 freq = 50;
2216 }
2217
2218 mTvin.VDIN_SetDisplayVFreq ( freq, mAv.getVideoDisplayResolution(), mHdmiOutFbc );
2219 LOGD ( "%s, SetDisplayVFreq %dHZ.", __FUNCTION__, freq);
2220 }
2221 //showbo mark hdmi auto 3d, tran fmt is 3d, so switch to 3d
2222 LOGD("hdmi trans_fmt = %d", mSigDetectThread.getCurSigInfo().trans_fmt);
2223
2224 //load pq parameters
2225 mVpp.LoadVppSettings (CTvin::Tvin_SourceInputToSourceInputType(m_source_input), mSigDetectThread.getCurSigInfo().fmt, Check2Dor3D(m_mode_3d, mSigDetectThread.getCurSigInfo().trans_fmt ), mSigDetectThread.getCurSigInfo().trans_fmt );
2226
2227 if ( m_win_mode == PREVIEW_WONDOW ) {
2228 mAv.setVideoAxis(m_win_pos.x1, m_win_pos.y1, m_win_pos.x2, m_win_pos.y2);
2229 mAv.setVideoScreenMode ( CAv::VIDEO_WIDEOPTION_FULL_STRETCH );
2230 } else {
2231 SetDisplayMode ( mVpp.GetDisplayMode ( CTvin::Tvin_SourceInputToSourceInputType(m_source_input) ), CTvin::Tvin_SourceInputToSourceInputType(m_source_input), mSigDetectThread.getCurSigInfo().fmt);
2232 }
2233}
2234
2235void CTv::onStableTransFmtChange() {
2236 LOGD("onStableTransFmtChange trans_fmt = %d", mSigDetectThread.getCurSigInfo().trans_fmt);
2237}
2238
2239void CTv::onSigDetectEnter(){
2240}
2241
2242void CTv::onSigDetectLoop() {
2243 if (( CTvin::Tvin_SourceInputToSourceInputType(m_source_input) == SOURCE_TYPE_HDMI ) ) {
2244 int sr = mTvin.get_hdmi_sampling_rate();
2245 if ( ( sr > 0 ) && ( sr != m_hdmi_sampling_rate ) ) {
2246 LOGD("HDMI SR CHANGED");
2247 CMessage msg;
2248 msg.mDelayMs = 0;
2249 msg.mType = CTvMsgQueue::TV_MSG_HDMI_SR_CHANGED;
2250 ((int *)(msg.mpPara))[0] = sr;
2251 ((int *)(msg.mpPara))[1] = m_hdmi_sampling_rate;
2252 mTvMsgQueue.sendMsg ( msg );
2253 m_hdmi_sampling_rate = sr;
2254 }
2255
2256 //m_hdmi_audio_data init is 0, not audio data , when switch to HDMI
2257 int hdmi_audio_data = mTvin.TvinApi_GetHDMIAudioStatus();
2258 if (hdmi_audio_data != m_hdmi_audio_data) {
2259 LOGD("HDMI auds_rcv_sts CHANGED = %d", hdmi_audio_data);
2260 m_hdmi_audio_data = hdmi_audio_data;
2261 onHMDIAudioStatusChanged(m_hdmi_audio_data);
2262 }
2263 }
2264}
2265
2266CTv::CTvDetectObserverForScanner::CTvDetectObserverForScanner(CTv *pTv) {
2267 mpTv = pTv;
2268 m_sig_stable_nums = 0;
2269}
2270
2271void CTv::CTvDetectObserverForScanner::onSigStableToUnstable() {
2272 LOGD ( "%s, stable to unstable\n", __FUNCTION__);
2273 mpTv->SetAudioMuteForTv(CC_AUDIO_MUTE);
2274 mpTv->SetAudioMuteForTv(CC_AUDIO_MUTE);
2275 const char * value = config_get_str ( CFG_SECTION_TV, CFG_BLUE_SCREEN_COLOR, "null" );
2276 if ( strcmp ( value, "black" ) == 0 ) {
2277 mpTv->mAv.DisableVideoWithBlackColor();
2278 } else {
2279 mpTv->mAv.DisableVideoWithBlueColor();
2280 }
2281 mpTv->mTvin.Tvin_StopDecoder();
2282}
2283
2284void CTv::CTvDetectObserverForScanner::onSigUnStableToNoSig() {
2285 mpTv->SetAudioMuteForTv(CC_AUDIO_MUTE);
2286 const char * value = config_get_str ( CFG_SECTION_TV, CFG_BLUE_SCREEN_COLOR, "null" );
2287 if ( strcmp ( value, "black" ) == 0 ) {
2288 mpTv->mAv.DisableVideoWithBlackColor();
2289 } else {
2290 mpTv->mAv.DisableVideoWithBlueColor();
2291 }
2292 mpTv->mTvin.Tvin_StopDecoder();
2293}
2294
2295void CTv::CTvDetectObserverForScanner::onSigStableToNoSig() {
2296 mpTv->SetAudioMuteForTv(CC_AUDIO_MUTE);
2297 const char * value = config_get_str ( CFG_SECTION_TV, CFG_BLUE_SCREEN_COLOR, "null" );
2298 if ( strcmp ( value, "black" ) == 0 ) {
2299 mpTv->mAv.DisableVideoWithBlackColor();
2300 } else {
2301 mpTv->mAv.DisableVideoWithBlueColor();
2302 }
2303 mpTv->mTvin.Tvin_StopDecoder();
2304 LOGD ( "%s, Enable bluescreen for signal change in StableToNoSig!", __FUNCTION__);
2305}
2306
2307void CTv::CTvDetectObserverForScanner::onSigToStable() {
2308 mpTv->mAv.setVideoScreenMode ( CAv::VIDEO_WIDEOPTION_16_9 );
2309 m_sig_stable_nums = 0;
2310}
2311
2312void CTv::CTvDetectObserverForScanner::onSigStillStable() {
2313 if (m_sig_stable_nums == 1) {
2314 LOGD("%s still stable , to start decoder", __FUNCTION__);
2315 int startdec_status = mpTv->mTvin.Tvin_StartDecoder (mpTv->mSigDetectThread.getCurSigInfo() );
2316 if ( startdec_status == 0 ) {
2317 const char * value = config_get_str ( CFG_SECTION_TV, "tvin.db.reg.en", "null" );
2318 if ( strcmp ( value, "enable" ) == 0 ) {
2319 usleep ( 20 * 1000 );
2320 mpTv->Tvin_SetPLLValues ();
2321 usleep ( 20 * 1000 );
2322 mpTv->SetCVD2Values ();
2323 }
2324 }
2325 }
2326 if ( m_sig_stable_nums == 10 ) {
2327 mpTv->mAv.EnableVideoWhenVideoPlaying();
2328 }
2329 m_sig_stable_nums++;
2330}
2331
2332void CTv::onSourceConnect(int source_type, int connect_status) {
2333 TvEvent::SourceConnectEvent ev;
2334 ev.mSourceInput = source_type;
2335 ev.connectionState = connect_status;
2336 sendTvEvent(ev);
2337}
2338
2339void CTv::onVframeSizeChange() {
2340 if (m_source_input == SOURCE_DTV) {
2341 mVpp.LoadVppSettings ( SOURCE_TYPE_DTV, mAv.getVideoResolutionToFmt(), INDEX_2D, TVIN_TFMT_2D );
2342 } else if (m_source_input == SOURCE_INVALID) {
2343 mVpp.LoadVppSettings ( SOURCE_TYPE_MPEG, mAv.getVideoResolutionToFmt(), INDEX_2D, TVIN_TFMT_2D );
2344 }
2345}
2346
2347int CTv::GetSourceConnectStatus(tv_source_input_t source_input) {
2348 return mSourceConnectDetectThread.GetSourceConnectStatus((tv_source_input_t)source_input);
2349}
2350
2351tv_source_input_t CTv::GetCurrentSourceInputLock ( void ) {
2352 Mutex::Autolock _l ( mLock );
2353 return m_source_input;
2354}
2355
2356//dtv and tvin
2357tvin_info_t CTv::GetCurrentSignalInfo ( void ) {
2358 tvin_trans_fmt det_fmt = TVIN_TFMT_2D;
2359 tvin_sig_status_t signalState = TVIN_SIG_STATUS_NULL;
2360 tvin_info_t signal_info = mSigDetectThread.getCurSigInfo();
2361
2362 int feState = mFrontDev.getStatus();
2363 if ( (CTvin::Tvin_SourceInputToSourceInputType(m_source_input) == SOURCE_TYPE_DTV ) ) {
2364 det_fmt = mTvin.TvinApi_Get3DDectMode();
2365 if ((feState & FE_HAS_LOCK) == FE_HAS_LOCK) {
2366 signal_info.status = TVIN_SIG_STATUS_STABLE;
2367 } else if ((feState & FE_TIMEDOUT) == FE_TIMEDOUT) {
2368 signal_info.status = TVIN_SIG_STATUS_NOSIG;
2369 }
2370 if ( det_fmt != TVIN_TFMT_2D ) {
2371 signal_info.trans_fmt = det_fmt;
2372 }
2373 signal_info.fmt = mAv.getVideoResolutionToFmt();
2374 }
2375 return signal_info;
2376}
2377
2378int CTv::Tv_GetHistgram(int *histgram_buf) {
2379 if (histgram_buf == NULL) {
2380 return -1;
2381 }
2382 return mTvin.VDIN_GetHistgram(histgram_buf);
2383}
2384
2385int CTv::Tv_Set3DMode ( VIDEO_3D_MODE_T mode ) {
2386 if (mode == VIDEO_3D_MODE_AUTO) {
2387 mTvin.VDIN_SetDI3DDetc (1);
2388 } else {
2389 mTvin.VDIN_SetDI3DDetc (0);
2390 }
2391
2392 mAv.set3DMode(mode, 0, 0);
2393 m_mode_3d = mode;
2394 SSMSave3DMode ( ( unsigned char ) mode );
2395 return 0;
2396}
2397
2398VIDEO_3D_MODE_T CTv::Tv_Get3DMode ( void ) {
2399 return m_mode_3d;
2400}
2401
2402int CTv::Tv_Set3DLRSwith ( int on_off) {
2403 LOGW ( "%s,Set3D LRSwith on_off %d ,status %d !!! ", __FUNCTION__, on_off);
2404 mAv.set3DMode(m_mode_3d, on_off, 0);
2405 SSMSave3DLRSwitch(on_off);
2406 return 0;
2407}
2408
2409int CTv::Tv_Get3DLRSwith ( void ) {
2410 unsigned char val = 0;
2411 SSMRead3DLRSwitch ( &val );
2412 return ( int ) val;
2413}
2414
2415int CTv::Tv_Set3DTo2DMode ( int mode) {
2416 LOGW ( "%s,Set3D to 2D mode %d ,status %d !!! ", __FUNCTION__ , mode);
2417 mAv.set3DMode(m_mode_3d, 0, mode);
2418 SSMSave3DTO2D ( mode );
2419 return 0;
2420}
2421
2422int CTv::Tv_Get3DTo2DMode ( void ) {
2423 unsigned char val = 0;
2424 SSMRead3DTO2D ( &val );
2425 return val;
2426}
2427
2428int CTv::Tv_Set3DDepth ( int value ) {
2429 mTvin.Tvin_SetDepthOf2Dto3D( value );
2430 SSMSave3DDepth ( value );
2431 return 0;
2432}
2433
2434int CTv::GetSave3DDepth ( void ) {
2435 unsigned char val = 0;
2436 SSMRead3DDepth ( &val );
2437 return val;
2438}
2439
2440is_3d_type_t CTv::Check2Dor3D ( VIDEO_3D_MODE_T mode3d, tvin_trans_fmt_t trans_fmt ) {
2441 if ( mode3d == VIDEO_3D_MODE_DISABLE ) {
2442 return INDEX_2D;
2443 } else if ( mode3d == VIDEO_3D_MODE_AUTO ) {
2444 if ( trans_fmt == TVIN_TFMT_2D ) {
2445 return INDEX_2D;
2446 } else {
2447 return INDEX_3D;
2448 }
2449 } else {
2450 return INDEX_3D;
2451 }
2452}
2453
2454int CTv::Tvin_SetPLLValues (){
2455 tvin_sig_fmt_t sig_fmt = mSigDetectThread.getCurSigInfo().fmt;
2456 tvin_port_t source_port = CTvin::Tvin_GetSourcePortBySourceInput(m_source_input);
2457 am_regs_t regs;
2458
2459 if ( mVpp.getPqData()->PQ_GetPLLParams ( source_port, sig_fmt, &regs ) == 0 ) {
2460 LOGD ("%s,PQ_GetPLLParams(source_port[%d], sig_fmt[%d],&regs).\n", __FUNCTION__, source_port, sig_fmt );
2461
2462 if ( mTvin.TvinApi_LoadPLLValues ( regs ) < 0 ) {
2463 LOGE ( "%s, TvinApi_LoadPLLValues failed!\n", __FUNCTION__ );
2464 return -1;
2465 }
2466 } else {
2467 LOGE ( "%s, PQ_GetPLLParams failed!\n", __FUNCTION__ );
2468 return -1;
2469 }
2470
2471 return 0;
2472}
2473
2474int CTv::SetCVD2Values () {
2475 tvin_sig_fmt_t sig_fmt = mSigDetectThread.getCurSigInfo().fmt;
2476 tvin_port_t source_port = CTvin::Tvin_GetSourcePortBySourceInput(m_source_input);
2477 am_regs_t regs;
2478
2479 if (mVpp.getPqData()->PQ_GetCVD2Params ( source_port, sig_fmt, &regs ) == 0) {
2480 LOGD ( "%s, PQ_GetCVD2Params(source_port[%d], sig_fmt[%d],&regs).\n", __FUNCTION__,
2481 source_port, sig_fmt );
2482
2483 if ( mTvin.TvinApi_LoadCVD2Values ( regs ) < 0 ) {
2484 LOGE ( "%s, TvinApi_LoadCVD2Values failed!\n", __FUNCTION__);
2485 return -1;
2486 }
2487 } else {
2488 LOGE ( "%s, PQ_GetCVD2Params failed!\n", __FUNCTION__);
2489 return -1;
2490 }
2491
2492 return 0;
2493}
2494
2495int CTv::SetPreviewWindow ( tvin_window_pos_t pos ) {
2496 m_win_pos.x1 = pos.x1;
2497 m_win_pos.y1 = pos.y1;
2498 m_win_pos.x2 = pos.x2;
2499 m_win_pos.y2 = pos.y2;
2500 LOGD ( "%s, SetPreviewWindow x = %d y=%d", __FUNCTION__, pos.x2, pos.y2 );
2501
2502 tvin_window_pos_t def_pos;
2503 Vpp_GetDisplayResolutionInfo(&def_pos);
2504
2505 if (pos.x1 != 0 || pos.y1 != 0 || pos.x2 != def_pos.x2 || pos.y2 != def_pos.y2) {
2506 m_win_mode = PREVIEW_WONDOW;
2507 } else {
2508 m_win_mode = NORMAL_WONDOW;
2509 }
2510
2511 return mAv.setVideoAxis(m_win_pos.x1, m_win_pos.y1, m_win_pos.x2, m_win_pos.y2);
2512}
2513
2514/*********************** Audio start **********************/
2515int CTv::SetAudioVolDigitLUTTable ( tv_source_input_t source_input ) {
2516 int tmpDefDigitLutBuf[CC_LUT_BUF_SIZE] = { 0 };
2517 int lut_table_index = 0;
2518 if (source_input == SOURCE_TV) {
2519 lut_table_index = CC_GET_LUT_TV;
2520 } else if (source_input == SOURCE_AV1 || source_input == SOURCE_AV2) {
2521 lut_table_index = CC_GET_LUT_AV;
2522 } else if (source_input == SOURCE_YPBPR1 || source_input == SOURCE_YPBPR2) {
2523 lut_table_index = CC_GET_LUT_COMP;
2524 } else if (source_input == SOURCE_VGA) {
2525 lut_table_index = CC_GET_LUT_VGA;
2526 } else if (source_input == SOURCE_HDMI1 || source_input == SOURCE_HDMI2 || source_input == SOURCE_HDMI3) {
2527 lut_table_index = CC_GET_LUT_HDMI;
2528 } else if ( source_input == SOURCE_MPEG ) {
2529 lut_table_index = CC_GET_LUT_MPEG;
2530 } else if ( source_input == SOURCE_DTV ) {
2531 lut_table_index = CC_GET_LUT_MPEG;
2532 } else if ( source_input == SOURCE_MAX) {
2533 return 0;
2534 }
2535 char MainVolLutTableName[128];
2536 const char *baseName = GetAudioAmpMainvolTableBaseName(lut_table_index);
2537 strcpy(MainVolLutTableName, baseName);
2538 const char *dName = ".";
2539 strcat(MainVolLutTableName, dName);
2540 strcat(MainVolLutTableName, GetMainVolLutTableExtraName());
2541 if ( GetAudioAmpMainvolBuf(MainVolLutTableName, tmpDefDigitLutBuf) == 0) {
2542 AudioSetVolumeDigitLUTBuf ( lut_table_index, tmpDefDigitLutBuf);
2543 }
2544 return 0;
2545}
2546
2547void CTv::RefreshAudioMasterVolume ( tv_source_input_t source_input ) {
2548 if (source_input == SOURCE_HDMI1 || source_input == SOURCE_HDMI2 || source_input == SOURCE_HDMI3) {
2549 if ( GetAudioDVISupportEnable() == 1 ) {
2550 if ( IsDVISignal() ) {
2551 SetAudioVolDigitLUTTable ( SOURCE_MPEG );
2552 SetAudioMasterVolume ( GetAudioMasterVolume() );
2553 return;
2554 }
2555 }
2556 }
2557
2558 SetAudioVolDigitLUTTable ( source_input );
2559 SetAudioMasterVolume ( GetAudioMasterVolume() );
2560}
2561
2562int CTv::Tv_SetAudioInSource (tv_source_input_t source_input) {
2563 int vol = 255;
2564 if (source_input == SOURCE_TV) {
2565 if (mTvin.Tvin_GetAudioInSourceType(source_input) == TV_AUDIO_IN_SOURCE_TYPE_ATV) {
2566 AudioSetAudioInSource(CC_AUDIO_IN_SOURCE_ATV);
2567 vol = GetAudioInternalDACDigitalPlayBackVolume_Cfg(CC_AUDIO_IN_SOURCE_ATV);
2568 LOGD("%s, atv DAC_Digital_PlayBack_Volume = %d\n", __FUNCTION__, vol);
2569 } else {
2570 LOGD("%s, dtv DAC_Digital_PlayBack_Volume = %d\n", __FUNCTION__, vol);
2571 AudioSetAudioInSource(CC_AUDIO_IN_SOURCE_LINEIN);
2572 vol = GetAudioInternalDACDigitalPlayBackVolume_Cfg(CC_AUDIO_IN_SOURCE_LINEIN);
2573 }
2574 } else if (source_input == SOURCE_AV1 || source_input == SOURCE_AV2) {
2575 AudioSetAudioInSource(CC_AUDIO_IN_SOURCE_LINEIN);
2576 vol = GetAudioInternalDACDigitalPlayBackVolume_Cfg(CC_AUDIO_IN_SOURCE_LINEIN);
2577 } else if (source_input == SOURCE_HDMI1 || source_input == SOURCE_HDMI2 || source_input == SOURCE_HDMI3) {
2578 AudioSetAudioInSource(CC_AUDIO_IN_SOURCE_HDMI);
2579 vol = GetAudioInternalDACDigitalPlayBackVolume_Cfg(CC_AUDIO_IN_SOURCE_HDMI);
2580 } else if (source_input == SOURCE_YPBPR1 || source_input == SOURCE_YPBPR2 ||
2581 source_input == SOURCE_TYPE_VGA) {
2582 AudioSetAudioInSource(CC_AUDIO_IN_SOURCE_LINEIN);
2583 vol = GetAudioInternalDACDigitalPlayBackVolume_Cfg(CC_AUDIO_IN_SOURCE_LINEIN);
2584 } else if (source_input == SOURCE_MPEG) {
2585 AudioSetAudioInSource(CC_AUDIO_IN_SOURCE_HDMI);
2586 vol = GetAudioInternalDACDigitalPlayBackVolume_Cfg(CC_AUDIO_IN_SOURCE_HDMI);
2587 } else if (source_input == SOURCE_DTV) {
2588 AudioSetAudioInSource(CC_AUDIO_IN_SOURCE_HDMI);
2589 vol = GetAudioInternalDACDigitalPlayBackVolume_Cfg(CC_AUDIO_IN_SOURCE_HDMI);
2590 LOGD("%s, dtv DAC_Digital_PlayBack_Volume = %d\n", __FUNCTION__, vol);
2591 }
2592 LOGD("%s, we have read SetDAC_Digital_PlayBack_Volume = %d\n", __FUNCTION__, vol);
2593
2594 return 0;
2595}
2596
2597int CTv::Tv_SetAudioSourceType (tv_source_input_t source_input) {
2598 int audio_source = -1;
2599
2600 if (source_input == SOURCE_TV) {
2601 audio_source = AUDIO_ATV_SOURCE;
2602 } else if (source_input == SOURCE_AV1 || source_input == SOURCE_AV2) {
2603 audio_source = AUDIO_AV_SOURCE;
2604 } else if (source_input == SOURCE_HDMI1 || source_input == SOURCE_HDMI2 ||
2605 source_input == SOURCE_HDMI3) {
2606 audio_source = AUDIO_HDMI_SOURCE;
2607 } else if (source_input == SOURCE_YPBPR1 || source_input == SOURCE_YPBPR2 ||
2608 source_input == SOURCE_TYPE_VGA) {
2609 audio_source = AUDIO_AV_SOURCE;
2610 } else if (source_input == SOURCE_DTV) {
2611 audio_source = AUDIO_MPEG_SOURCE;
2612 } else {
2613 audio_source = AUDIO_MPEG_SOURCE;
2614 }
2615
2616 return AudioSetAudioSourceType(audio_source);
2617}
2618
2619void CTv::Tv_SetAudioOutputSwap_Type (tv_source_input_t source_input) {
2620 int sw_status = GetAudioOutputSwapStatus(source_input);
2621 SetOutput_Swap(sw_status);
2622}
2623
2624void CTv::Tv_ADCDigitalCapture_Volume (void) {
2625 int capture_vol = GetADCDigitalCaptureVol_Cfg();
2626 LOGD("%s, we have read ADCDigitalCaptureVol_Config = %d \n", __FUNCTION__, capture_vol);
2627 SetADC_Digital_Capture_Volume(capture_vol);
2628}
2629
2630void CTv::Tv_SetPGAIn_Gain (void) {
2631 int gain_val = GetAudioInternalDacPGAInGain_Cfg();
2632 LOGD("%s, we have read ADCDigitalCaptureVol_Config = %d \n", __FUNCTION__, gain_val);
2633 SetPGA_IN_Value(gain_val);
2634}
2635
2636void CTv::Tv_SetDACDigitalPlayBack_Volume (int audio_src_in_type) {
2637 int vol = GetAudioInternalDACDigitalPlayBackVolume_Cfg(audio_src_in_type);
2638 LOGD("%s, we have read DACDigitalPlayBackVolume config = %d \n", __FUNCTION__, vol);
2639 SetDAC_Digital_PlayBack_Volume(vol);
2640}
2641/*********************** Audio end **********************/
2642
2643unsigned int CTv::Vpp_GetDisplayResolutionInfo(tvin_window_pos_t *win_pos) {
2644 int display_resolution = mAv.getVideoDisplayResolution();
2645 int width = 0, height = 0;
2646 switch (display_resolution) {
2647 case VPP_DISPLAY_RESOLUTION_1366X768:
2648 width = CC_RESOLUTION_1366X768_W;
2649 height = CC_RESOLUTION_1366X768_H;
2650 break;
2651 case VPP_DISPLAY_RESOLUTION_1920X1080:
2652 width = CC_RESOLUTION_1920X1080_W;
2653 height = CC_RESOLUTION_1920X1080_H;
2654 break;
2655 case VPP_DISPLAY_RESOLUTION_3840X2160:
2656 width = CC_RESOLUTION_3840X2160_W;
2657 height = CC_RESOLUTION_3840X2160_H;
2658 break;
2659 default:
2660 width = CC_RESOLUTION_3840X2160_W;
2661 height = CC_RESOLUTION_3840X2160_H;
2662 break;
2663 }
2664
2665 if (win_pos != NULL) {
2666 win_pos->x1 = 0;
2667 win_pos->y1 = 0;
2668 win_pos->x2 = width - 1;
2669 win_pos->y2 = height - 1;
2670 }
2671 return 0;
2672}
2673
2674int CTv::setBlackoutEnable(int enable) {
2675 m_blackout_enable = enable;
2676 return SSMSaveBlackoutEnable(enable);
2677}
2678
2679int CTv::getSaveBlackoutEnable() {
2680 int8_t enable;
2681 SSMReadBlackoutEnable(&enable);
2682 return enable;
2683}
2684
2685void CTv::startAutoBackLight() {
2686 if (mHdmiOutFbc) {
2687 Tv_FactorySet_FBC_Auto_Backlight_OnOff(1);
2688 } else {
2689 mAutoBackLight.startAutoBacklight(CTvin::Tvin_SourceInputToSourceInputType(m_source_input));
2690 }
2691}
2692
2693void CTv::stopAutoBackLight() {
2694 if (mHdmiOutFbc) {
2695 Tv_FactorySet_FBC_Auto_Backlight_OnOff(0);
2696 } else {
2697 mAutoBackLight.stopAutoBacklight();
2698 }
2699}
2700
2701int CTv::getAutoBackLight_on_off() {
2702 if (mHdmiOutFbc) {
2703 return Tv_FactoryGet_FBC_Auto_Backlight_OnOff();
2704 } else {
2705 return mAutoBackLight.isAutoBacklightOn() ? 1 : 0;
2706 }
2707}
2708
2709int CTv::getAverageLuma() {
2710 return mTvin.VDIN_Get_avg_luma();
2711}
2712
2713int CTv::setAutobacklightData(const char* value) {
2714 const char* KEY ="haier.autobacklight.mp.data";
2715
2716 const char * keyValue = config_get_str(CFG_SECTION_TV, KEY, "null");
2717 if (strcmp(keyValue, value) != 0) {
2718 config_set_str(CFG_SECTION_TV, KEY, value);
2719 LOGD("%s, config string now set as: %s \n", __FUNCTION__, keyValue);
2720 } else {
2721 LOGD("%s, config string has been set as: %s \n", __FUNCTION__, keyValue);
2722 }
2723 return 0;
2724}
2725
2726int CTv::getAutoBacklightData(int* data) {
2727 char datas[512] = {0};
2728 char delims[] = ",";
2729 char *result = NULL;
2730 const char* KEY ="haier.autobacklight.mp.data";
2731 int i = 0;
2732
2733 if (NULL == data) {
2734 LOGD("%s, data is null", __FUNCTION__);
2735 return -1;
2736 }
2737
2738 const char * keyValue = config_get_str(CFG_SECTION_TV, KEY, (char *) "null");
2739 if (strcmp(keyValue,"null") == 0) {
2740 LOGD("%s, value is NULL\n",__FUNCTION__);
2741 return -1;
2742 }
2743
2744 strncpy(datas, keyValue, sizeof(datas)-1);
2745 result = strtok( datas, delims );
2746 while ( result != NULL ) {
2747 char *pd = strstr(result, ":");
2748 if (pd != NULL) {
2749 data[i] = strtol(pd+1, NULL, 10 );
2750 i++;
2751 }
2752 result = strtok( NULL, delims );
2753 }
2754 return i;
2755}
2756
2757/*********************** SSM start **********************/
2758int CTv::Tv_SSMRestoreDefaultSetting() {
2759 SSMRestoreDeviceMarkValues();
2760 AudioSSMRestoreDefaultSetting();
2761 mVpp.VPPSSMRestoreDefault();
2762 MiscSSMRestoreDefault();
2763 ReservedSSMRestoreDefault();
2764 SSMSaveCVBSStd ( 0 );
2765 SSMSaveLastSelectSourceInput ( SOURCE_TV );
2766 SSMSavePanelType ( 0 );
2767 //tvconfig default
2768 saveDTVProgramID ( -1 );
2769 saveATVProgramID ( -1 );
2770 SSMSaveStandbyMode( 0 );
2771 return 0;
2772}
2773
2774int CTv::clearDbAllProgramInfoTable() {
2775 return CTvDatabase::GetTvDb()->clearDbAllProgramInfoTable();
2776}
2777
2778int CTv::Tv_SSMFacRestoreDefaultSetting() {
2779 mVpp.VPPSSMFacRestoreDefault();
2780 AudioSSMRestoreDefaultSetting();
2781 MiscSSMFacRestoreDefault();
2782
2783 return 0;
2784}
2785/*********************** SSM End **********************/
2786
2787//not in CTv, not use lock
2788void CTv::setSourceSwitchAndPlay() {
2789 int progID = 0, ret = -1;
2790 CTvProgram prog;
2791 LOGD ( "%s\n", __FUNCTION__ );
2792 static const int POWERON_SOURCE_TYPE_NONE = 0;//not play source
2793 static const int POWERON_SOURCE_TYPE_LAST = 1;//play last save source
2794 static const int POWERON_SOURCE_TYPE_SETTING = 2;//play ui set source
2795 int to_play_source = -1;
2796 int powerup_type = SSMReadPowerOnOffChannel();
2797 LOGD("read power on source type = %d", powerup_type);
2798 if (powerup_type == POWERON_SOURCE_TYPE_NONE) {
2799 return ;
2800 } else if (powerup_type == POWERON_SOURCE_TYPE_LAST) {
2801 to_play_source = SSMReadSourceInput();
2802 } else if (powerup_type == POWERON_SOURCE_TYPE_SETTING) {
2803 to_play_source = SSMReadLastSelectSourceInput();
2804 }
2805 SetSourceSwitchInput (( tv_source_input_t ) to_play_source );
2806 if ( to_play_source == SOURCE_TV ) {
2807 progID = getATVProgramID();
2808 } else if ( to_play_source == SOURCE_DTV ) {
2809 progID = getDTVProgramID();
2810 }
2811 playProgramLock(progID);
2812}
2813
2814int CTv::startCC(int country, int src, int channel, int service) {
2815 //turn_on_cc = true;
2816 return mSubtitle.sub_start_atsc_cc((enum cc_param_country)country, (enum cc_param_source_type)src, channel, (enum cc_param_caption_type)service);
2817}
2818
2819int CTv::stopCC() {
2820 //because cc,vchip data both come from vbi thread , here judge cc, vchip is whether both turn off
2821 /*turn_on_cc = false;
2822 if (config_get_int(CFG_SECTION_TV,"tv.vchip.enable", 0))
2823 {
2824 return 0; //at ATV if vchip is on, turn off CC, just set flag not display CC, but vchip still running
2825 }*/
2826 return mSubtitle.sub_stop_atsc_cc();
2827}
2828
2829void CTv::printDebugInfo() {
2830 print_version_info();
2831 LOGD("%s, TvAction = %x", __FUNCTION__, mTvAction);
2832 LOGD("%s, TvRunStatus = %d", __FUNCTION__, mTvStatus);
2833 LOGD("%s, TvCurSourceInput = %d", __FUNCTION__, m_source_input);
2834 LOGD("%s, TvLastSourceInput = %d", __FUNCTION__, m_last_source_input);
2835}
2836//==============vchip end================================
2837
2838//----------------DVR API============================
2839void CTv::SetRecordFileName ( char *name ) {
2840 char tmp[256];
2841 strcpy ( tmp, name );
2842 mTvRec.SetRecordFileName ( tmp );
2843}
2844
2845void CTv::StartToRecord() {
2846 int progID = getDTVProgramID();
2847 mTvRec.StartRecord ( progID );
2848}
2849
2850void CTv::StopRecording() {
2851 mTvRec.StopRecord();
2852}
2853
2854void CTv::SetRecCurTsOrCurProgram ( int sel ) {
2855 mTvRec.SetRecCurTsOrCurProgram ( sel );
2856}
2857
2858int CTv::GetDisplayResolutionConfig() {
2859 return mAv.getVideoDisplayResolution();
2860}
2861
2862int CTv::GetDisplayResolutionInfo() {
2863 return Vpp_GetDisplayResolutionInfo(NULL);
2864}
2865
2866void CTv::onHDMIRxCECMessage(int msg_len, unsigned char msg_buf[]) {
2867 int i = 0;
2868 TvEvent::HDMIRxCECEvent ev;
2869 ev.mDataCount = msg_len;
2870 for (i = 0; i < msg_len; i++) {
2871 ev.mDataBuf[i] = msg_buf[i];
2872 }
2873 sendTvEvent(ev);
2874}
2875
2876int CTv::SendHDMIRxCECCustomMessage(unsigned char data_buf[]) {
2877 tv_source_input_t source_input = m_source_input;
2878 return mHDMIRxCEC.SendCustomMessage(source_input, data_buf);
2879}
2880
2881int CTv::SendHDMIRxCECCustomMessageAndWaitReply(unsigned char data_buf[], unsigned char reply_buf[], int WaitCmd, int timeout) {
2882 tv_source_input_t source_input = m_source_input;
2883 return mHDMIRxCEC.SendCustomMessageAndWaitReply(source_input, data_buf, reply_buf, WaitCmd, timeout);
2884}
2885
2886int CTv::SendHDMIRxCECBoradcastStandbyMessage(void) {
2887 tv_source_input_t source_input = m_source_input;
2888 return mHDMIRxCEC.SendBoradcastStandbyMessage(source_input);
2889}
2890
2891int CTv::SendHDMIRxCECGiveCECVersionMessage(tv_source_input_t source_input, unsigned char data_buf[]) {
2892 if (mHDMIRxCEC.processRefreshSrcDevice(source_input) == 0) {
2893 return mHDMIRxCEC.SendGiveCECVersionMessage(source_input, data_buf);
2894 }
2895
2896 return -1;
2897}
2898
2899int CTv::SendHDMIRxCECGiveDeviceVendorIDMessage(tv_source_input_t source_input, unsigned char data_buf[]) {
2900 if (mHDMIRxCEC.processRefreshSrcDevice(source_input) == 0) {
2901 return mHDMIRxCEC.SendGiveDeviceVendorIDMessage(source_input, data_buf);
2902 }
2903
2904 return -1;
2905}
2906
2907int CTv::SendHDMIRxCECGiveOSDNameMessage(tv_source_input_t source_input, unsigned char data_buf[]) {
2908 if (mHDMIRxCEC.processRefreshSrcDevice(source_input) == 0) {
2909 return mHDMIRxCEC.SendGiveOSDNameMessage(source_input, data_buf);
2910 }
2911
2912 return -1;
2913}
2914
2915int CTv::GetHdmiHdcpKeyKsvInfo(int data_buf[]) {
2916 return mTvin.get_hdmi_ksv_info(m_source_input, data_buf);
2917}
2918
2919bool CTv::hdmiOutWithFbc() {
2920 const char * value = config_get_str(CFG_SECTION_TV, "platform.havefbc", "true");
2921 if (strcmp(value, "true") == 0) {
2922 return true;
2923 }
2924
2925 return false;
2926}
2927
2928void CTv::onUpgradeStatus(int state, int param) {
2929 TvEvent::UpgradeFBCEvent ev;
2930 ev.mState = state;
2931 ev.param = param;
2932 sendTvEvent(ev);
2933}
2934
2935int CTv::StartUpgradeFBC(char *file_name, int mode, int upgrade_blk_size) {
2936 if (mpUpgradeFBC != NULL) {
2937 mpUpgradeFBC->SetUpgradeFileName(file_name);
2938 mpUpgradeFBC->SetUpgradeMode(mode);
2939 mpUpgradeFBC->SetUpgradeBlockSize(upgrade_blk_size);
2940 mpUpgradeFBC->start();
2941 return 0;
2942 }
2943
2944 return -1;
2945}
2946
2947void CTv::onSerialCommunication(int dev_id, int rd_len, unsigned char data_buf[]) {
2948 int i = 0;
2949 TvEvent::SerialCommunicationEvent ev;
2950 ev.mDevId = dev_id;
2951 ev.mDataCount = rd_len;
2952 for (i = 0; i < rd_len; i++) {
2953 ev.mDataBuf[i] = data_buf[i];
2954 }
2955 sendTvEvent(ev);
2956}
2957
2958int CTv::StartHeadSetDetect() {
2959 mHeadSet.startDetect();
2960 return 0;
2961}
2962
2963void CTv::onHeadSetDetect(int state,int para) {
2964 TvEvent::HeadSetOf2d4GEvent ev;
2965 if (state == 1)
2966 property_set("audio.headset_plug.enable", "1");
2967 else
2968 property_set("audio.headset_plug.enable", "0");
2969 ev.state = state;
2970 ev.para = para;
2971 sendTvEvent(ev);
2972}
2973
2974void CTv::onThermalDetect(int state) {
2975 const char *value;
2976 const char *value_normal;
2977 const char *value_cold;
2978 int threshold = 0, val = 0;
2979 static int pre_val = -1;
2980
2981 value = config_get_str ( CFG_SECTION_TV, "tvin.thermal.threshold.enable", "null" );
2982 if ( strcmp ( value, "enable" ) == 0 ) {
2983 value = config_get_str ( CFG_SECTION_TV, "tvin.thermal.threshold.value", "null" );
2984 threshold = atoi(value);
2985 LOGD ( "%s, threshold value: %d\n", __FUNCTION__, threshold);
2986
2987 if (state > threshold) {
2988 value_normal = config_get_str ( CFG_SECTION_TV, "tvin.thermal.fbc.normal.value", "null" );
2989 val = atoi(value_normal);
2990 if (val == 0) {
2991 val = 0x4210000; //normal default
2992 }
2993 LOGD ( "%s, current temp: %d set 1\n", __FUNCTION__, state);
2994 } else {
2995 value_cold = config_get_str ( CFG_SECTION_TV, "tvin.thermal.fbc.cold.value", "null" );
2996 val = atoi(value_cold);
2997 if (val == 0) {
2998 val = 0x8210000; //cold default
2999 }
3000 LOGD ( "%s, current temp: 0x%x set 0\n", __FUNCTION__, state);
3001 }
3002
3003 if (pre_val == val) {
3004 LOGD ( "%s, pre_val == val : 0x%x,bypass\n", __FUNCTION__, val);
3005 } else {
3006 pre_val = val;
3007 Tv_FactorySet_FBC_Thermal_State(val);
3008 LOGD ( "%s, pre_val :0x%x,bypass\n", __FUNCTION__, pre_val);
3009 }
3010 } else {
3011 LOGD ( "%s, tvin.thermal.threshold.enable == disable\n", __FUNCTION__);
3012 }
3013}
3014
3015int CTv::SetDebugSerialOnOff(int on_off) {
3016 if (on_off) {
3017 property_set("ubootenv.var.console", "ttyS0,115200n8");
3018 } else {
3019 property_set("ubootenv.var.console", "off");
3020 }
3021 return 0;
3022}
3023
3024int CTv::GetDebugSerialOnOff() {
3025 char prop[256];
3026 memset(prop, '\0', 256);
3027 property_get("ubootenv.var.console", prop, "null" );
3028
3029 if (!strcmp(prop, "ttyS0,115200n8")) {
3030 return 1;
3031 } else {
3032 return 0;
3033 }
3034}
3035
3036int CTv::SetSerialSwitch(int dev_id, int switch_val) {
3037 int tmp_ret = 0;
3038 if (dev_id == SERIAL_A) {
3039 if (switch_val == 0) {
3040 tmp_ret |= mSerialA.stop();
3041 tmp_ret |= mSerialA.CloseModule();
3042
3043 tmp_ret |= system("start console");
3044 tmp_ret |= system("echo 7 > /proc/sys/kernel/printk");
3045 } else {
3046 tmp_ret |= system("echo 0 > /proc/sys/kernel/printk");
3047 tmp_ret |= system("stop console");
3048
3049 mSerialA.OpenModule(dev_id);
3050 tmp_ret |= mSerialA.start();
3051 }
3052 } else if (dev_id == SERIAL_B) {
3053 if (switch_val == 0) {
3054 tmp_ret |= mSerialB.stop();
3055 tmp_ret |= mSerialB.CloseModule();
3056 } else {
3057 mSerialB.OpenModule(dev_id);
3058 tmp_ret = mSerialB.start();
3059 }
3060 } else if (dev_id == SERIAL_C) {
3061 if (switch_val == 0) {
3062 tmp_ret |= mSerialC.stop();
3063 tmp_ret |= mSerialC.CloseModule();
3064 } else {
3065 mSerialC.OpenModule(dev_id);
3066 tmp_ret = mSerialC.start();
3067 }
3068 }
3069
3070 return tmp_ret;
3071}
3072
3073int CTv::SendSerialData(int dev_id, int data_len, unsigned char data_buf[]) {
3074 int tmp_ret = 0;
3075
3076 if (dev_id == SERIAL_A) {
3077 tmp_ret = mSerialA.sendData(data_len, data_buf);
3078 } else if (dev_id == SERIAL_B) {
3079 tmp_ret = mSerialB.sendData(data_len, data_buf);
3080 } else if (dev_id == SERIAL_C) {
3081 tmp_ret = mSerialC.sendData(data_len, data_buf);
3082 }
3083
3084 return tmp_ret;
3085}
3086
3087int CTv::ChannelExport(const char *destPath) {
3088 //DIR *dirptr = NULL;
3089 //dirptr = opendir("/storage/external_storage/sda1/");
3090 //if(NULL == dirptr) {
3091 // LOGD("%s, please insert the udisk !",__FUNCTION__);
3092 // return -2;
3093 // } else {
3094 char tmp[256];
3095 FILE *fp = NULL;
3096 if (destPath == NULL) {
3097 destPath = "/storage/external_storage/sda1/";
3098 }
3099
3100 //LOGD("%s, udisk exist !",__FUNCTION__);
3101 sprintf(tmp, "cp /param/dtv.db %s", destPath);
3102 if (system(tmp) >= 0) {
3103 LOGD("%s, copy dtv.db from /param to udisk success !", __FUNCTION__);
3104 system("sync");
3105 fp = fopen(destPath, "r");
3106 if (fp == NULL) {
3107 return -1;
3108 } else {
3109 fclose(fp);
3110 fp = NULL;
3111 return 0;
3112 }
3113 } else {
3114 return -1;
3115 }
3116 //}
3117}
3118
3119int CTv::ChannelImport(const char *srcPath) {
3120 if (srcPath == NULL) {
3121 srcPath = "/storage/external_storage/sda1/dvb.db";
3122 }
3123
3124 if (Tv_Utils_IsFileExist(srcPath)) {
3125 char tmp[256];
3126 const char *destPath = config_get_str(CFG_SECTION_TV, "tv.channel.db", (char *) "/param/dtv.db");
3127
3128 LOGD("%s, file exist !" , srcPath);
3129 CTvDatabase::GetTvDb()->UnInitTvDb();
3130 sprintf(tmp, "rm %s", destPath);
3131 if (system(tmp) >= 0) {
3132 LOGD("%s, rm %s success !", __FUNCTION__, destPath);
3133 memset(tmp, 0, sizeof(tmp));
3134 sprintf(tmp, "cp %s %s", srcPath, destPath);
3135 if (system(tmp) >= 0) {
3136 LOGD("%s, copy to %s success !", srcPath, destPath);
3137 memset(tmp, 0, sizeof(tmp));
3138 sprintf(tmp, "chmod 777 %s", destPath);
3139 if (system(tmp) >= 0) {
3140 LOGD("chmod 777 %s success !", destPath);
3141 system("sync");
3142 CTvDatabase::GetTvDb()->InitTvDb(TV_DB_PATH);
3143 return 0;
3144 } else {
3145 LOGD("%s, %s chmod failed !", __FUNCTION__, destPath);
3146 return -1;
3147 }
3148 } else {
3149 LOGD("%s, copy dtv.db from udisk to %s failed !", __FUNCTION__, destPath);
3150 return -1;
3151 }
3152 } else {
3153 LOGD("%s, rm %s failed !", __FUNCTION__, destPath);
3154 return -2;
3155 }
3156 } else {
3157 LOGD("%s, dtv.db file does not exist in the udisk!" , srcPath);
3158 return -2;
3159 }
3160}
3161
3162int CTv::Tv_GetProjectInfo(project_info_t *ptrInfo) {
3163 return GetProjectInfo(ptrInfo, fbcIns);
3164}
3165
3166int CTv::Tv_GetPlatformType() {
3167 return mHdmiOutFbc ? 1 : 0;
3168}
3169
3170int CTv::Tv_HandeHDMIEDIDFilePathConfig() {
3171 int i, file_exist_flag = 1;
3172 const char *value = NULL;
3173 char val_buf[256];
3174 char edid_path[256];
3175 char edid_path_cfg[256];
3176
3177 value = config_get_str(CFG_SECTION_TV, "ssm.handle.hdmi.edid.en", "null");
3178
3179 if (strtoul(value, NULL, 10) == 1) {
3180 LOGD( "%s, get config \"%s\" is \"%s\".\n",
3181 __FUNCTION__, "ssm.handle.hdmi.edid.en", value);
3182 //get hdmi edid use mode
3183
3184 memset(val_buf, '\0', 256);
3185 property_get("ubootenv.var.outputmode", val_buf, "null");
3186 LOGD( "%s, get property \"%s\" is \"%s\".\n",
3187 __FUNCTION__, "ubootenv.var.outputmode", val_buf);
3188 if (strcmp(val_buf, "null") != 0) {
3189 config_set_str ( CFG_SECTION_TV, CS_HDMI_EDID_USE_CFG, val_buf);
3190
3191 file_exist_flag = 1;
3192 //set file's path for hdmi edid of each port
3193 for (i = 1; i <= SSM_HDMI_PORT_MAX; i++) {
3194 memset( edid_path, '\0', 256);
3195 memset( edid_path_cfg, '\0', 256);
3196 sprintf(edid_path, "/system/etc/%s_port%d.bin", val_buf, i);
3197 sprintf(edid_path_cfg, "ssm.handle.hdmi.port%d.edid.file.path", i);
3198 if (access(edid_path, 0) < 0) {
3199 file_exist_flag = 0;
3200 break;
3201 }
3202 config_set_str(CFG_SECTION_TV, edid_path_cfg, edid_path);
3203 }
3204
3205 if (file_exist_flag == 0) {
3206 //set default hdmi edid
3207 config_set_str(CFG_SECTION_TV, CS_HDMI_EDID_USE_CFG, "hdmi_edid");
3208 //set file's path for hdmi edid of each port
3209 for (i = 1; i <= SSM_HDMI_PORT_MAX; i++) {
3210 memset(edid_path, '\0', 256);
3211 memset(edid_path_cfg, '\0', 256);
3212 sprintf(edid_path, "/system/etc/%s_port%d.bin", "hdmi_edid", i);
3213 sprintf(edid_path_cfg, "ssm.handle.hdmi.port%d.edid.file.path", i);
3214
3215 value = config_get_str(CFG_SECTION_TV, edid_path_cfg, "null");
3216 if (strcmp(value, edid_path) != 0) {
3217 config_set_str(CFG_SECTION_TV, edid_path_cfg, edid_path);
3218 }
3219 }
3220 }
3221 } else {
3222 //set default hdmi edid
3223 config_set_str(CFG_SECTION_TV, CS_HDMI_EDID_USE_CFG, "hdmi_edid");
3224 //set file's path for hdmi edid of each port
3225 for (i = 1; i <= SSM_HDMI_PORT_MAX; i++) {
3226 memset(edid_path, '\0', 256);
3227 memset(edid_path_cfg, '\0', 256);
3228 sprintf(edid_path, "/system/etc/%s_port%d.bin", "hdmi_edid", i);
3229 sprintf(edid_path_cfg, "ssm.handle.hdmi.port%d.edid.file.path", i);
3230
3231 value = config_get_str(CFG_SECTION_TV, edid_path_cfg, "null");
3232 if (strcmp(value, edid_path) != 0) {
3233 config_set_str(CFG_SECTION_TV, edid_path_cfg, edid_path);
3234 }
3235 }
3236 }
3237 m_is_set_hdmi_edid = true;
3238 }
3239 return 0;
3240}
3241
3242int CTv::Tv_SetDDDRCMode(tv_source_input_t source_input) {
3243 if (source_input == SOURCE_DTV) {
3244 if (GetPlatformHaveDDFlag() == 1) {
3245 Tv_Utils_SetFileAttrStr("/sys/class/audiodsp/ac3_drc_control", (char *)"drcmode 3");
3246 }
3247 } else {
3248 if (GetPlatformHaveDDFlag() == 1) {
3249 Tv_Utils_SetFileAttrStr("/sys/class/audiodsp/ac3_drc_control", (char *)"drcmode 2");
3250 }
3251 }
3252 return 0;
3253}
3254
3255//PQ
3256int CTv::Tv_SetBrightness ( int brightness, tv_source_input_type_t source_type, int is_save ) {
3257 return mVpp.SetBrightness(brightness, (tv_source_input_type_t)source_type, mSigDetectThread.getCurSigInfo().fmt, mSigDetectThread.getCurSigInfo().trans_fmt, Check2Dor3D(m_mode_3d, mSigDetectThread.getCurSigInfo().trans_fmt ), is_save);
3258}
3259
3260int CTv::Tv_GetBrightness ( tv_source_input_type_t source_type ) {
3261 return mVpp.GetBrightness((tv_source_input_type_t)source_type);
3262}
3263
3264int CTv::Tv_SaveBrightness ( int brightness, tv_source_input_type_t source_type ) {
3265 return SSMSaveBrightness ( source_type, brightness );
3266}
3267
3268int CTv::Tv_SetContrast ( int contrast, tv_source_input_type_t source_type, int is_save ) {
3269 return mVpp.SetContrast(contrast, (tv_source_input_type_t)source_type, mSigDetectThread.getCurSigInfo().fmt, mSigDetectThread.getCurSigInfo().trans_fmt, Check2Dor3D(m_mode_3d, mSigDetectThread.getCurSigInfo().trans_fmt ), is_save);
3270}
3271
3272int CTv::Tv_GetContrast ( tv_source_input_type_t source_type ) {
3273 return mVpp.GetContrast((tv_source_input_type_t)source_type);
3274}
3275
3276int CTv::Tv_SaveContrast ( int contrast, tv_source_input_type_t source_type ) {
3277 return SSMSaveContrast ( source_type, contrast );
3278}
3279
3280int CTv::Tv_SetSaturation ( int satuation, tv_source_input_type_t source_type, tvin_sig_fmt_t fmt, int is_save ) {
3281 return mVpp.SetSaturation(satuation, (tv_source_input_type_t)source_type, (tvin_sig_fmt_t)fmt, mSigDetectThread.getCurSigInfo().trans_fmt, Check2Dor3D(m_mode_3d, mSigDetectThread.getCurSigInfo().trans_fmt ), is_save);
3282}
3283
3284int CTv::Tv_GetSaturation ( tv_source_input_type_t source_type ) {
3285 return mVpp.GetSaturation((tv_source_input_type_t)source_type);
3286}
3287
3288int CTv::Tv_SaveSaturation ( int satuation, tv_source_input_type_t source_type ) {
3289 return SSMSaveSaturation ( source_type, satuation );
3290}
3291
3292int CTv::Tv_SetHue ( int hue, tv_source_input_type_t source_type, tvin_sig_fmt_t fmt, int is_save ) {
3293 return mVpp.SetHue(hue, (tv_source_input_type_t)source_type, (tvin_sig_fmt_t)fmt, mSigDetectThread.getCurSigInfo().trans_fmt, Check2Dor3D(m_mode_3d, mSigDetectThread.getCurSigInfo().trans_fmt ), is_save);
3294}
3295
3296int CTv::Tv_GetHue ( tv_source_input_type_t source_type ) {
3297 return mVpp.GetHue((tv_source_input_type_t)source_type);
3298}
3299
3300int CTv::Tv_SaveHue ( int hue, tv_source_input_type_t source_type ) {
3301 return SSMSaveHue ( source_type, hue );
3302}
3303
3304int CTv::Tv_SetPQMode ( vpp_picture_mode_t mode, tv_source_input_type_t source_type, int is_save ) {
3305 return mVpp.SetPQMode((vpp_picture_mode_t)mode, (tv_source_input_type_t)source_type, mSigDetectThread.getCurSigInfo().fmt, mSigDetectThread.getCurSigInfo().trans_fmt, Check2Dor3D(m_mode_3d, mSigDetectThread.getCurSigInfo().trans_fmt ), is_save);
3306}
3307
3308vpp_picture_mode_t CTv::Tv_GetPQMode ( tv_source_input_type_t source_type ) {
3309 return mVpp.GetPQMode((tv_source_input_type_t)source_type);
3310}
3311
3312int CTv::Tv_SavePQMode ( vpp_picture_mode_t mode, tv_source_input_type_t source_type ) {
3313 return mVpp.SavePQMode ( mode, source_type );
3314}
3315
3316int CTv::Tv_SetSharpness ( int value, tv_source_input_type_t source_type, int en, int is_save ) {
3317 return mVpp.SetSharpness(value, (tv_source_input_type_t)source_type, en, Check2Dor3D(m_mode_3d, mSigDetectThread.getCurSigInfo().trans_fmt ), mSigDetectThread.getCurSigInfo().fmt, mSigDetectThread.getCurSigInfo().trans_fmt, is_save);
3318}
3319
3320int CTv::Tv_GetSharpness ( tv_source_input_type_t source_type ) {
3321 return mVpp.GetSharpness((tv_source_input_type_t)source_type);
3322}
3323
3324int CTv::Tv_SaveSharpness ( int value, tv_source_input_type_t source_type ) {
3325 return SSMSaveSharpness ( source_type, value );
3326}
3327
3328int CTv::Tv_SetBacklight ( int value, tv_source_input_type_t source_type, int is_save ) {
3329 if (mHdmiOutFbc) {
3330 return Tv_FactorySet_FBC_Backlight(value);
3331 } else {
3332 return mVpp.SetBacklight(value, (tv_source_input_type_t)source_type, is_save);
3333 }
3334}
3335
3336int CTv::Tv_GetBacklight ( tv_source_input_type_t source_type ) {
3337 if (mHdmiOutFbc) {
3338 return Tv_FactoryGet_FBC_Backlight();
3339 } else {
3340 return mVpp.GetBacklight((tv_source_input_type_t)source_type);
3341 }
3342}
3343
3344int CTv::Tv_SaveBacklight ( int value, tv_source_input_type_t source_type ) {
3345 return mVpp.SaveBacklight ( value, source_type );
3346}
3347
3348int CTv::Tv_SetBacklight_Switch ( int value ) {
3349 if (mHdmiOutFbc) {
3350 return Tv_FactorySet_FBC_backlight_onoff(value);
3351 } else {
3352 return mVpp.VPP_SetBackLight_Switch(value);
3353 }
3354}
3355
3356int CTv::Tv_GetBacklight_Switch ( void ) {
3357 if (mHdmiOutFbc) {
3358 return Tv_FactoryGet_FBC_backlight_onoff();
3359 } else {
3360 return mVpp.VPP_GetBackLight_Switch();
3361 }
3362}
3363
3364int CTv::Tv_SetColorTemperature ( vpp_color_temperature_mode_t mode, tv_source_input_type_t source_type, int is_save ) {
3365 if (mHdmiOutFbc) {
3366 return Tv_FactorySet_FBC_ColorTemp_Mode(mode);
3367 } else {
3368 return mVpp.SetColorTemperature((vpp_color_temperature_mode_t)mode, (tv_source_input_type_t)source_type, is_save);
3369 }
3370}
3371
3372vpp_color_temperature_mode_t CTv::Tv_GetColorTemperature ( tv_source_input_type_t source_type ) {
3373 if (mHdmiOutFbc) {
3374 return (vpp_color_temperature_mode_t)Tv_FactoryGet_FBC_ColorTemp_Mode();
3375 } else {
3376 return mVpp.GetColorTemperature((tv_source_input_type_t)source_type);
3377 }
3378}
3379
3380int CTv::Tv_SaveColorTemperature ( vpp_color_temperature_mode_t mode, tv_source_input_type_t source_type ) {
3381 return mVpp.SaveColorTemp ( mode, source_type );
3382}
3383
3384int CTv::Tv_SetDisplayMode ( vpp_display_mode_t mode, tv_source_input_type_t source_type, tvin_sig_fmt_t fmt, int is_save ) {
3385 int ret = 0;
3386 if (m_mode_3d == VIDEO_3D_MODE_DISABLE) {
3387 ret = SetDisplayMode((vpp_display_mode_t)mode, (tv_source_input_type_t)source_type, (tvin_sig_fmt_t)fmt);
3388 } else { //3D
3389 ret = SetDisplayMode(VPP_DISPLAY_MODE_PERSON, (tv_source_input_type_t)source_type, (tvin_sig_fmt_t)fmt);
3390 }
3391 if (ret == 0) {
3392 if (is_save == 1) {
3393 ret = ret | SSMSaveDisplayMode ( source_type, (int)mode );
3394 }
3395 }
3396 return ret;
3397}
3398
3399int CTv::SetDisplayMode ( vpp_display_mode_t display_mode, tv_source_input_type_t source_type, tvin_sig_fmt_t sig_fmt ) {
3400 LOGD("SetDisplayMode, display_mode = %d, source_type = %d fmt = %d tranfmt = %d\n", display_mode, source_type, sig_fmt, mSigDetectThread.getCurSigInfo().trans_fmt);
3401
3402 tvin_cutwin_t cutwin = mVpp.GetOverscan ( source_type, sig_fmt, Check2Dor3D(m_mode_3d, mSigDetectThread.getCurSigInfo().trans_fmt ), mSigDetectThread.getCurSigInfo().trans_fmt);
3403 LOGD("SetDisplayMode , get crop %d %d %d %d \n", cutwin.vs, cutwin.hs, cutwin.ve, cutwin.he);
3404 int video_screen_mode = CAv::VIDEO_WIDEOPTION_16_9;
3405 tvin_window_pos_t win_pos;
3406 int display_resolution = Vpp_GetDisplayResolutionInfo(&win_pos);
3407
3408 switch ( display_mode ) {
3409 case VPP_DISPLAY_MODE_169:
3410 video_screen_mode = CAv::VIDEO_WIDEOPTION_16_9;
3411 break;
3412 case VPP_DISPLAY_MODE_MODE43:
3413 video_screen_mode = CAv::VIDEO_WIDEOPTION_4_3;
3414 break;
3415 case VPP_DISPLAY_MODE_NORMAL:
3416 video_screen_mode = CAv::VIDEO_WIDEOPTION_NORMAL;
3417 break;
3418 case VPP_DISPLAY_MODE_FULL:
3419 video_screen_mode = CAv::VIDEO_WIDEOPTION_NONLINEAR;
3420 mVpp.VPP_SetNonLinearFactor ( 20 );
3421 //mVpp.VPP_SetNonLinearFactor ( 20 );
3422 break;
3423 case VPP_DISPLAY_MODE_CROP_FULL:
3424 cutwin.vs = 0;
3425 cutwin.hs = 0;
3426 cutwin.ve = 0;
3427 cutwin.he = 0;
3428 break;
3429 case VPP_DISPLAY_MODE_NOSCALEUP:
3430 video_screen_mode = CAv::VIDEO_WIDEOPTION_NORMAL_NOSCALEUP;
3431 break;
3432 case VPP_DISPLAY_MODE_FULL_REAL:
3433 video_screen_mode = CAv::VIDEO_WIDEOPTION_16_9; //added for N360 by haifeng.liu
3434 break;
3435 case VPP_DISPLAY_MODE_PERSON:
3436 video_screen_mode = CAv::VIDEO_WIDEOPTION_FULL_STRETCH;
3437 cutwin.vs = cutwin.vs + 20;
3438 cutwin.ve = cutwin.ve + 20;
3439 break;
3440 case VPP_DISPLAY_MODE_MOVIE:
3441 video_screen_mode = CAv::VIDEO_WIDEOPTION_FULL_STRETCH;
3442 cutwin.vs = cutwin.vs + 40;
3443 cutwin.ve = cutwin.ve + 40;
3444 break;
3445 case VPP_DISPLAY_MODE_CAPTION:
3446 video_screen_mode = CAv::VIDEO_WIDEOPTION_FULL_STRETCH;
3447 cutwin.vs = cutwin.vs + 55;
3448 cutwin.ve = cutwin.ve + 55;
3449 break;
3450 case VPP_DISPLAY_MODE_ZOOM:
3451 video_screen_mode = CAv::VIDEO_WIDEOPTION_FULL_STRETCH;
3452 cutwin.vs = cutwin.vs + 70;
3453 cutwin.ve = cutwin.ve + 70;
3454 break;
3455 default:
3456 break;
3457 }
3458 if (source_type == SOURCE_TYPE_DTV || source_type == SOURCE_TYPE_MPEG) {
3459 cutwin.vs = cutwin.vs + 12;
3460 cutwin.ve = cutwin.ve + 12;
3461 cutwin.hs = cutwin.hs + 12;
3462 cutwin.he = cutwin.he + 12;
3463 }
3464 if (source_type == SOURCE_TYPE_HDMI) {
3465 if ((IsDVISignal()) || (mTvin.GetITContent() == 1)) {
3466 cutwin.vs = 0;
3467 cutwin.hs = 0;
3468 cutwin.ve = 0;
3469 cutwin.he = 0;
3470 }
3471
3472 if (display_mode == VPP_DISPLAY_MODE_FULL_REAL) {
3473 cutwin.vs = 0;
3474 cutwin.hs = 0;
3475 cutwin.ve = 0;
3476 cutwin.he = 0;
3477 }
3478 }
3479
3480 //mAv.setVideoAxis ( win_pos.x1, win_pos.y1, win_pos.x2, win_pos.y2 );
3481 mAv.setVideoScreenMode(video_screen_mode);
3482 mVpp.VPP_SetVideoCrop(cutwin.vs, cutwin.hs, cutwin.ve, cutwin.he);
3483 return 0;
3484}
3485
3486vpp_display_mode_t CTv::Tv_GetDisplayMode ( tv_source_input_type_t source_type ) {
3487 return mVpp.GetDisplayMode((tv_source_input_type_t)source_type);
3488}
3489
3490int CTv::Tv_SaveDisplayMode ( vpp_display_mode_t mode, tv_source_input_type_t source_type ) {
3491 return SSMSaveDisplayMode ( source_type, (int)mode );
3492}
3493
3494int CTv::Tv_SetNoiseReductionMode ( vpp_noise_reduction_mode_t mode, tv_source_input_type_t source_type, int is_save ) {
3495 return mVpp.SetNoiseReductionMode((vpp_noise_reduction_mode_t)mode, (tv_source_input_type_t)source_type, mSigDetectThread.getCurSigInfo().fmt, Check2Dor3D(m_mode_3d, mSigDetectThread.getCurSigInfo().trans_fmt ), mSigDetectThread.getCurSigInfo().trans_fmt, is_save);
3496}
3497
3498int CTv::Tv_SaveNoiseReductionMode ( vpp_noise_reduction_mode_t mode, tv_source_input_type_t source_type ) {
3499 return mVpp.SaveNoiseReductionMode ( mode, source_type );
3500}
3501
3502int CTv::Tv_Set2k4k_ScalerUp_Mode ( int value ) {
3503 int ret = 0, fmt_hd_sd = 0;
3504 int nodeVal = 0;
3505 char s[8];
3506
3507 LOGD("%s, value [%d]\n", __FUNCTION__ , value);
3508
3509 if ( CTvin::Tvin_SourceInputToSourceInputType(m_source_input) != SOURCE_TYPE_HDMI &&
3510 CTvin::Tvin_SourceInputToSourceInputType(m_source_input) != SOURCE_TYPE_AV &&
3511 CTvin::Tvin_SourceInputToSourceInputType(m_source_input) != SOURCE_TYPE_TV) {
3512 int fd = open("/sys/class/video/frame_height", O_RDONLY);
3513 if (fd <= 0) {
3514 LOGE("open /sys/class/video/frame_height ERROR!!error = -%s- \n", strerror ( errno ));
3515 return -1;
3516 }
3517 read(fd, s, sizeof(s));
3518 close(fd);
3519 nodeVal = atoi(s);
3520 if (nodeVal < 900) {
3521 fmt_hd_sd = 0;
3522 } else {
3523 fmt_hd_sd = 1;
3524 }
3525 } else if ( CTvin::Tvin_SourceInputToSourceInputType(m_source_input) == SOURCE_TYPE_HDMI ) {
3526 if (isSDFmtInHdmi()) {
3527 fmt_hd_sd = 0;
3528 } else {
3529 fmt_hd_sd = 1;
3530 }
3531 } else if ( CTvin::Tvin_SourceInputToSourceInputType(m_source_input) == SOURCE_TYPE_AV ||
3532 CTvin::Tvin_SourceInputToSourceInputType(m_source_input) == SOURCE_TYPE_TV) {
3533 fmt_hd_sd = 0;
3534 }
3535
3536 switch (value) {
3537 case 1: // on
3538 if (fmt_hd_sd) {
3539 ret = Tv_Utils_SetFileAttrStr("/sys/class/video/video_scaler_path_sel", (char *)"0");
3540 //LOGD("%s, enable, set 0.\n", __FUNCTION__);
3541 } else {
3542 ret = Tv_Utils_SetFileAttrStr("/sys/class/video/video_scaler_path_sel", (char *)"1");
3543 }
3544 break;
3545
3546 case 0: // off
3547 default:
3548 if (fmt_hd_sd) {
3549 ret = Tv_Utils_SetFileAttrStr("/sys/class/video/video_scaler_path_sel", (char *)"1");
3550 //LOGD("%s, disable, set 1.\n", __FUNCTION__);
3551 } else {
3552 ret = Tv_Utils_SetFileAttrStr("/sys/class/video/video_scaler_path_sel", (char *)"0");
3553 //LOGD("%s, disable, set 0.\n", __FUNCTION__);
3554 }
3555 break;
3556 }
3557 return ret;
3558}
3559
3560int CTv::Tv_Get2k4k_ScalerUp_Mode ( void ) {
3561 char attrV[64];
3562 int ret = 0, fmt_hd_sd = 0;
3563 int nodeVal = 0;
3564 char s[8];
3565
3566 memset (attrV, '\0', 64);
3567
3568 if ( CTvin::Tvin_SourceInputToSourceInputType(m_source_input) != SOURCE_TYPE_HDMI &&
3569 CTvin::Tvin_SourceInputToSourceInputType(m_source_input) != SOURCE_TYPE_AV &&
3570 CTvin::Tvin_SourceInputToSourceInputType(m_source_input) != SOURCE_TYPE_TV) {
3571 int fd = open("/sys/class/video/frame_height", O_RDONLY);
3572 if (fd <= 0) {
3573 LOGE("open /sys/class/video/frame_height ERROR!!error = -%s- \n", strerror ( errno ));
3574 return -1;
3575 }
3576 read(fd, s, sizeof(s));
3577 close(fd);
3578 nodeVal = atoi(s);
3579 if (nodeVal < 900) {
3580 fmt_hd_sd = 0;
3581 } else {
3582 fmt_hd_sd = 1;
3583 }
3584 } else if ( CTvin::Tvin_SourceInputToSourceInputType(m_source_input) == SOURCE_TYPE_HDMI ) {
3585 if (isSDFmtInHdmi()) {
3586 fmt_hd_sd = 0;
3587 } else {
3588 fmt_hd_sd = 1;
3589 }
3590 } else if ( CTvin::Tvin_SourceInputToSourceInputType(m_source_input) == SOURCE_TYPE_AV || CTvin::Tvin_SourceInputToSourceInputType(m_source_input) == SOURCE_TYPE_TV) {
3591 fmt_hd_sd = 0;
3592 }
3593
3594 Tv_Utils_GetFileAttrStr("/sys/class/video/video_scaler_path_sel", 64, attrV);
3595 //LOGD("%s, 11111111scaler_path_sel[%s].\n", __FUNCTION__ , attrV);
3596 if (strncasecmp(attrV, "1", strlen ("1")) == 0) {
3597 if (fmt_hd_sd) {
3598 ret = 0;
3599 } else {
3600 ret = 1;
3601 }
3602 } else if (strncasecmp(attrV, "0", strlen ("0")) == 0) {
3603 if (fmt_hd_sd) {
3604 ret = 1;
3605 } else {
3606 ret = 0;
3607 }
3608 } else {
3609 ret = -1;
3610 }
3611
3612 return ret;
3613}
3614
3615int CTv::Tv_SetSplitScreenDemoStatus(tv_source_input_type_t source_type, int onoff_status) {
3616 int ret = 0;
3617 LOGD("%s, split screen demo status source[%d],onoff_stauts[%d]\n", __FUNCTION__ , source_type, onoff_status);
3618 if (1 == onoff_status) {
3619 ret = Tv_Utils_SetFileAttrStr("/sys/class/amlogic/debug", (char *)"w 0x503c0 v 0x31d6");//sharpness screen left
3620 ret |= Tv_Utils_SetFileAttrStr("/sys/class/amlogic/debug", (char *)"w 0x07 v 0x174d");//nr screen left
3621 } else if (0 == onoff_status) {
3622 ret = Tv_Utils_SetFileAttrStr("/sys/class/amlogic/debug", (char *)"w 0x503c0 v 0x31d6");//sharpness screen left
3623 ret |= Tv_Utils_SetFileAttrStr("/sys/class/amlogic/debug", (char *)"w 0x07 v 0x174d");//nr screen left
3624 }
3625
3626 if (fbcIns != NULL && 0 == ret) {
3627 ret |= fbcIns->cfbc_SET_SPLIT_SCREEN_DEMO(COMM_DEV_SERIAL, onoff_status);
3628 }
3629
3630 return ret;
3631}
3632
3633int CTv::Tv_GetSplitScreenDemoStatus(tv_source_input_type_t source_type) {
3634 source_type = source_type;
3635 return 0;
3636}
3637
3638vpp_noise_reduction_mode_t CTv::Tv_GetNoiseReductionMode ( tv_source_input_type_t source_type ) {
3639 return mVpp.GetNoiseReductionMode((tv_source_input_type_t)source_type);
3640}
3641
3642/**
3643 * @parameter mode : 0:sharpness; 1:NR
3644 *
3645 1.sharpness分屏(可以控制宽度)
3646 分屏大小 寄存器范围是0x50000 冿x50780,左效果的范围越来越大?0x70780 冿x70000也是一样?
3647 左右调换控制 bit 17. 开僿控制 bit 16. 0-11bit 是控制宽度的。范围是0-0x780?920像素?
3648 左做效果处理 echo w 0x503c0 v 0x31d6 > /sys/class/amlogic/debug
3649 右做效果处理 echo w 0x703c0 v 0x31d6 > /sys/class/amlogic/debug
3650 echo w 0x403c0 v 0x31d6 > /sys/class/amlogic/debug
3651
3652 2. NR分屏(不能控制宽度)
3653 左做效果处理 echo w 0x07 v 0x174d > /sys /class/amlogic/debug
3654 右做效果处理 echo w 0x70 v 0x174d > /sys /class/amlogic/debug
3655 僿 echo w 0x77 v 0x174d > /sys/class/amlogic/debug
3656 */
3657int CTv::Tv_SplitScreenEffect(int mode, int width, int reverse) {
3658 int ret = -1;
3659
3660 if (mode == 0) {
3661 if (width == 0) {//close
3662 ret = mVpp.VPP_SplitScreenEffect(0x403c0, 0x31d6);
3663 } else {
3664 int val = 0;
3665 if (reverse == 0) {//left effect
3666 val = width + 0x50000;
3667 } else {//right effect
3668 val = 0x70780 - width;
3669 }
3670 ret = mVpp.VPP_SplitScreenEffect(val, 0x31d6);
3671 }
3672 } else if (mode == 1) {
3673 if (width == 0) {//close
3674 ret = mVpp.VPP_SplitScreenEffect(0x77, 0x174d);
3675 } else {
3676 if (reverse == 0)
3677 ret = mVpp.VPP_SplitScreenEffect(0x07, 0x174d);
3678 else
3679 ret = mVpp.VPP_SplitScreenEffect(0x70, 0x174d);
3680 }
3681 } else if (mode == 2) {
3682 }
3683
3684 return ret;
3685}
3686
3687int CTv::Tv_FactorySetPQMode_Brightness ( int source_type, int pq_mode, int brightness ) {
3688 return mVpp.FactorySetPQMode_Brightness(source_type, pq_mode, brightness);
3689}
3690
3691int CTv::Tv_FactoryGetPQMode_Brightness ( int source_type, int pq_mode ) {
3692 return mVpp.FactoryGetPQMode_Brightness(source_type, pq_mode);
3693}
3694
3695int CTv::Tv_FactorySetPQMode_Contrast ( int source_type, int pq_mode, int contrast ) {
3696 return mVpp.FactorySetPQMode_Contrast(source_type, pq_mode, contrast);
3697}
3698
3699int CTv::Tv_FactoryGetPQMode_Contrast ( int source_type, int pq_mode ) {
3700 return mVpp.FactoryGetPQMode_Contrast(source_type, pq_mode);
3701}
3702
3703int CTv::Tv_FactorySetPQMode_Saturation ( int source_type, int pq_mode, int saturation ) {
3704 return mVpp.FactorySetPQMode_Saturation(source_type, pq_mode, saturation);
3705}
3706
3707int CTv::Tv_FactoryGetPQMode_Saturation ( int source_type, int pq_mode ) {
3708 return mVpp.FactoryGetPQMode_Saturation(source_type, pq_mode);
3709}
3710
3711int CTv::Tv_FactorySetPQMode_Hue ( int source_type, int pq_mode, int hue ) {
3712 return mVpp.FactorySetPQMode_Hue(source_type, pq_mode, hue);
3713}
3714
3715int CTv::Tv_FactoryGetPQMode_Hue ( int source_type, int pq_mode ) {
3716 return mVpp.FactoryGetPQMode_Hue(source_type, pq_mode);
3717}
3718
3719int CTv::Tv_FactorySetPQMode_Sharpness ( int source_type, int pq_mode, int sharpness ) {
3720 return mVpp.FactorySetPQMode_Sharpness(source_type, pq_mode, sharpness);
3721}
3722
3723int CTv::Tv_FactoryGetPQMode_Sharpness ( int source_type, int pq_mode ) {
3724 return mVpp.FactoryGetPQMode_Sharpness(source_type, pq_mode);
3725}
3726
3727int CTv::GetColorTemperatureParams ( vpp_color_temperature_mode_t Tempmode, tcon_rgb_ogo_t *params ) {
3728 if (mHdmiOutFbc) {
3729 int ret = Tv_FactoryGet_FBC_ColorTemp_Batch((vpp_color_temperature_mode_t)Tempmode, params);
3730 params->r_gain = Tv_FactoryWhiteBalanceFormatOutputFbcGainParams(params->r_gain);
3731 params->g_gain = Tv_FactoryWhiteBalanceFormatOutputFbcGainParams(params->g_gain);
3732 params->b_gain = Tv_FactoryWhiteBalanceFormatOutputFbcGainParams(params->b_gain);
3733 params->r_post_offset = Tv_FactoryWhiteBalanceFormatOutputFbcOffsetParams(params->r_post_offset);
3734 params->g_post_offset = Tv_FactoryWhiteBalanceFormatOutputFbcOffsetParams(params->g_post_offset);
3735 params->b_post_offset = Tv_FactoryWhiteBalanceFormatOutputFbcOffsetParams(params->b_post_offset);
3736 return ret;
3737 } else {
3738 return mVpp.GetColorTemperatureParams(Tempmode, params);
3739 }
3740}
3741
3742int CTv::Tv_FactorySetTestPattern ( int pattern ) {
3743 switch ( pattern ) {
3744 case VPP_TEST_PATTERN_NONE:
3745 mAv.SetVideoScreenColor ( 3, 16, 128, 128 );
3746 break;
3747
3748 case VPP_TEST_PATTERN_RED:
3749 mAv.SetVideoScreenColor ( 0, 81, 90, 240 );
3750 break;
3751
3752 case VPP_TEST_PATTERN_GREEN:
3753 mAv.SetVideoScreenColor ( 0, 145, 54, 34 );
3754 break;
3755
3756 case VPP_TEST_PATTERN_BLUE:
3757 mAv.SetVideoScreenColor ( 0, 41, 240, 110 );
3758 break;
3759
3760 case VPP_TEST_PATTERN_WHITE:
3761 mAv.SetVideoScreenColor ( 0, 235, 128, 128 );
3762 break;
3763
3764 case VPP_TEST_PATTERN_BLACK:
3765 mAv.SetVideoScreenColor ( 0, 16, 128, 128 );
3766 break;
3767
3768 default:
3769 return -1;
3770 }
3771 return SSMSaveTestPattern ( pattern );
3772}
3773
3774int CTv::Tv_FactoryGetTestPattern ( void ) {
3775 return mVpp.FactoryGetTestPattern();
3776}
3777
3778int CTv::Tv_FactorySetScreenColor ( int vdin_blending_mask, int y, int u, int v ) {
3779 return mAv.SetVideoScreenColor ( vdin_blending_mask, y, u, v );
3780}
3781
3782int CTv::Tv_FactoryResetPQMode ( void ) {
3783 return mVpp.FactoryResetPQMode();
3784}
3785
3786int CTv::Tv_FactoryResetColorTemp ( void ) {
3787 return mVpp.FactoryResetColorTemp();
3788}
3789
3790int CTv::Tv_FactorySetParamsDefault ( void ) {
3791 return mVpp.FactorySetParamsDefault();
3792}
3793
3794int CTv::Tv_FactorySetDDRSSC ( int step ) {
3795 return mVpp.FactorySetDDRSSC(step);
3796}
3797
3798int CTv::Tv_FactoryGetDDRSSC ( void ) {
3799 return mVpp.FactoryGetDDRSSC();
3800}
3801
3802int CTv::Tv_FactorySetLVDSSSC ( int step ) {
3803 return mVpp.FactorySetLVDSSSC(step);
3804}
3805
3806int CTv::Tv_FactoryGetLVDSSSC ( void ) {
3807 return mVpp.FactoryGetLVDSSSC();
3808}
3809
3810void CTv::Tv_Spread_Spectrum() {
3811 int value= 0;
3812 value = mVpp.FactoryGetLVDSSSC();
3813 mVpp.FactorySetLVDSSSC(value);
3814}
3815
3816int CTv::Tv_FactorySetNolineParams ( int noline_params_type, int source_type, noline_params_t noline_params ) {
3817 return mVpp.FactorySetNolineParams(noline_params_type, source_type, noline_params);
3818}
3819
3820noline_params_t CTv::Tv_FactoryGetNolineParams ( int noline_params_type, int source_type ) {
3821 return mVpp.FactoryGetNolineParams(noline_params_type, source_type);
3822}
3823
3824int CTv::Tv_FactorySetOverscan ( int source_type, int fmt, int status_3d, int trans_fmt, tvin_cutwin_t cutwin_t ) {
3825 //tvin_cutwin_t cutwin_t = mVpp.Tv_FactoryGetOverscan(source_type, fmt, status_3d, trans_fmt);
3826 mVpp.FactorySetOverscan(source_type, fmt, status_3d, trans_fmt, cutwin_t);
3827 //} else {
3828#if 0
3829 char val_buf[256];
3830 memset(val_buf, '\0', 256);
3831 LOGD("%s,%d: %d,%d,%d,%d", __FUNCTION__, __LINE__, ( int ) cutwin_t.vs, ( int ) cutwin_t.hs, ( int ) cutwin_t.ve, ( int ) cutwin_t.he);
3832 sprintf(val_buf, "%d,%d,%d,%d", ( int ) cutwin_t.vs, ( int ) cutwin_t.hs, ( int ) cutwin_t.ve, ( int ) cutwin_t.he );
3833 config_set_str(CFG_SECTION_TV, "vpp.overscan.dtv", val_buf);
3834 //}
3835#endif
3836 return mVpp.VPP_SetVideoCrop ( ( int ) cutwin_t.vs, ( int ) cutwin_t.hs, ( int ) cutwin_t.ve, ( int ) cutwin_t.he );
3837}
3838
3839tvin_cutwin_t CTv::Tv_FactoryGetOverscan ( int source_type, int fmt, int status_3d, int trans_fmt ) {
3840 status_3d = status_3d;
3841 return mVpp.FactoryGetOverscan(source_type, fmt, Check2Dor3D(m_mode_3d, (tvin_trans_fmt_t)trans_fmt), trans_fmt);
3842#if 0
3843 else {
3844 tvin_cutwin_t cutwin;
3845 int ret = 0;
3846 char tmp_buf[16];
3847 tmp_buf[0] = 0;
3848
3849 if ((ret |= cfg_get_one_item("vpp.overscan.dtv", ",", 0, tmp_buf)) == 0) {
3850 cutwin.vs = strtol(tmp_buf, NULL, 10);
3851 }
3852 if ((ret |= cfg_get_one_item("vpp.overscan.dtv", ",", 1, tmp_buf)) == 0) {
3853 cutwin.hs = strtol(tmp_buf, NULL, 10);
3854 }
3855 if ((ret |= cfg_get_one_item("vpp.overscan.dtv", ",", 2, tmp_buf)) == 0) {
3856 cutwin.ve = strtol(tmp_buf, NULL, 10);
3857 }
3858 if ((ret |= cfg_get_one_item("vpp.overscan.dtv", ",", 3, tmp_buf)) == 0) {
3859 cutwin.he = strtol(tmp_buf, NULL, 10);
3860 }
3861 LOGD("%s,%d: %d,%d,%d,%d", __FUNCTION__, __LINE__, ( int ) cutwin.vs, ( int ) cutwin.hs, ( int ) cutwin.ve, ( int ) cutwin.he);
3862 return cutwin;
3863 }
3864#endif
3865}
3866
3867int CTv::Tv_ReplacePqDb(const char *newFilePath) {
3868 return mVpp.getPqData()->replacePqDb(newFilePath);
3869}
3870
3871int CTv::Tv_FactorySet_FBC_Brightness ( int value ) {
3872 //int temp_value = (255*value)/100;
3873 int temp_value = value;
3874
3875 if (fbcIns != NULL) {
3876 fbcIns->cfbc_Set_Brightness(COMM_DEV_SERIAL, temp_value);
3877 return 0;
3878 }
3879 return -1;
3880}
3881
3882int CTv::Tv_FactoryGet_FBC_Brightness ( void ) {
3883 int temp_value = 0;
3884 int data = 0;
3885
3886 if (fbcIns != NULL) {
3887 fbcIns->cfbc_Get_Brightness(COMM_DEV_SERIAL, &temp_value);
3888 //data = (temp_value*100)/255;
3889 data = temp_value;
3890
3891 return data;
3892 }
3893 return 0;
3894}
3895
3896int CTv::Tv_FactorySet_FBC_Contrast ( int value ) {
3897 //int temp_value = (255*value)/100;
3898 int temp_value = value;
3899
3900 if (fbcIns != NULL) {
3901 fbcIns->cfbc_Set_Contrast(COMM_DEV_SERIAL, temp_value);
3902 return 0;
3903 }
3904 return -1;
3905}
3906
3907int CTv::Tv_FactoryGet_FBC_Contrast ( void ) {
3908 int temp_value = 0;
3909 int data = 0;
3910
3911 if (fbcIns != NULL) {
3912 fbcIns->cfbc_Get_Contrast(COMM_DEV_SERIAL, &temp_value);
3913 //data = (temp_value*100)/255;
3914 data = temp_value;
3915 return data;
3916 }
3917 return 0;
3918}
3919
3920int CTv::Tv_FactorySet_FBC_Saturation ( int value ) {
3921 //int temp_value = (255*value)/100;
3922 int temp_value = value;
3923
3924 if (fbcIns != NULL) {
3925 fbcIns->cfbc_Set_Saturation(COMM_DEV_SERIAL, temp_value);
3926 return 0;
3927 }
3928 return -1;
3929}
3930
3931int CTv::Tv_FactoryGet_FBC_Saturation ( void ) {
3932 int temp_value = 0;
3933 int data = 0;
3934
3935 if (fbcIns != NULL) {
3936 fbcIns->cfbc_Get_Saturation(COMM_DEV_SERIAL, &temp_value);
3937 //data = (temp_value*100)/255;
3938 data = temp_value;
3939 return data;
3940 }
3941 return 0;
3942}
3943
3944int CTv::Tv_FactorySet_FBC_HueColorTint ( int value ) {
3945 //int temp_value = (255*value)/100;
3946 int temp_value = value;
3947
3948 if (fbcIns != NULL) {
3949 fbcIns->cfbc_Set_HueColorTint(COMM_DEV_SERIAL, temp_value);
3950 return 0;
3951 }
3952 return -1;
3953}
3954
3955int CTv::Tv_FactoryGet_FBC_HueColorTint ( void ) {
3956 int temp_value = 0;
3957 int data = 0;
3958
3959 if (fbcIns != NULL) {
3960 fbcIns->cfbc_Get_HueColorTint(COMM_DEV_SERIAL, &temp_value);
3961 //data = (temp_value*100)/255;
3962 data = temp_value;
3963 return data;
3964 }
3965 return 0;
3966}
3967
3968int CTv::Tv_FactorySet_FBC_Backlight ( int value ) {
3969 int temp_value = value;
3970 if (fbcIns != NULL) {
3971 temp_value = temp_value * 255 / 100;
3972 fbcIns->cfbc_Set_Backlight(COMM_DEV_SERIAL, temp_value);
3973 return 0;
3974 }
3975 return -1;
3976}
3977
3978int CTv::Tv_FactoryGet_FBC_Backlight ( void ) {
3979 int temp_value = 0;
3980 int data = 0;
3981
3982 if (fbcIns != NULL) {
3983 fbcIns->cfbc_Get_Backlight(COMM_DEV_SERIAL, &temp_value);
3984 if (temp_value * 100 % 255 == 0)
3985 temp_value = temp_value * 100 / 255;
3986 else
3987 temp_value = temp_value * 100 / 255 + 1;
3988 data = temp_value;
3989 return data;
3990 }
3991
3992 return 0;
3993}
3994
3995int CTv::Tv_FactorySet_FBC_Auto_Backlight_OnOff( unsigned char status) {
3996 if (fbcIns != NULL) {
3997 return fbcIns->cfbc_Set_Auto_Backlight_OnOff(COMM_DEV_SERIAL, status);
3998 }
3999
4000 return -1;
4001}
4002
4003int CTv::Tv_FactoryGet_FBC_Auto_Backlight_OnOff( void ) {
4004 int temp_status = 0;
4005
4006 if (fbcIns != NULL) {
4007 fbcIns->cfbc_Get_Auto_Backlight_OnOff(COMM_DEV_SERIAL, &temp_status);
4008 return temp_status;
4009 }
4010 return 0;
4011}
4012
4013int CTv::Tv_FactorySet_FBC_ELEC_MODE( int value ) {
4014 int val = 0;
4015
4016 if (fbcIns != NULL) {
4017 fbcIns->cfbc_Set_AUTO_ELEC_MODE(COMM_DEV_SERIAL, value);
4018 val = value;
4019 SSMSaveFBCELECmodeVal(val);
4020 return 0;
4021 }
4022 return -1;
4023}
4024
4025int CTv::Tv_FactoryGet_FBC_ELEC_MODE( void ) {
4026 int val = 0;
4027 SSMReadFBCELECmodeVal(&val);
4028 return val;
4029}
4030
4031int CTv::Tv_FactorySet_FBC_BACKLIGHT_N360( int value ) {
4032 int val = 0;
4033
4034 val = value;
4035 SSMSaveFBCELECmodeVal(val);
4036 return -1;
4037}
4038
4039int CTv::Tv_FactoryGet_FBC_BACKLIGHT_N360( void ) {
4040 int val = 0;
4041 SSMReadFBCELECmodeVal(&val);
4042 return val;
4043}
4044
4045int CTv::Tv_FactorySet_FBC_Thermal_State( int value ) {
4046 if (fbcIns != NULL) {
4047 fbcIns->cfbc_Set_Thermal_state(COMM_DEV_SERIAL, value);
4048 return 0;
4049 }
4050
4051 return -1;
4052}
4053
4054int CTv::Tv_FactorySet_FBC_Picture_Mode ( int mode ) {
4055 if (fbcIns != NULL) {
4056 fbcIns->cfbc_Set_Picture_Mode(COMM_DEV_SERIAL, mode);
4057 return 0;
4058 }
4059
4060 return -1;
4061}
4062
4063int CTv::Tv_FactoryGet_FBC_Picture_Mode ( void ) {
4064 int mode = 0;
4065
4066 if (fbcIns != NULL) {
4067 fbcIns->cfbc_Get_Picture_Mode(COMM_DEV_SERIAL, &mode);
4068 return mode;
4069 }
4070 return 0;
4071}
4072
4073int CTv::Tv_FactorySet_FBC_Set_Test_Pattern ( int mode ) {
4074 if (fbcIns != NULL) {
4075 fbcIns->cfbc_Set_Test_Pattern(COMM_DEV_SERIAL, mode);
4076 return 0;
4077 }
4078
4079 return -1;
4080}
4081
4082int CTv::Tv_FactoryGet_FBC_Get_Test_Pattern ( void ) {
4083 int mode = 0;
4084
4085 if (fbcIns != NULL) {
4086 fbcIns->cfbc_Get_Test_Pattern(COMM_DEV_SERIAL, &mode);
4087 return mode;
4088 }
4089
4090 return 0;
4091}
4092
4093int CTv::Tv_FactorySet_FBC_Gain_Red( int value ) {
4094 int temp_value = 0;
4095
4096 //temp_value = (value*255)/2047;
4097 //value 0 ~ 2047
4098 temp_value = value;
4099
4100 if (fbcIns != NULL) {
4101 fbcIns->cfbc_Set_Gain_Red(COMM_DEV_SERIAL, temp_value);
4102 return 0;
4103 }
4104
4105 return -1;
4106}
4107
4108int CTv::Tv_FactoryGet_FBC_Gain_Red ( void ) {
4109 int temp_value = 0, value = 0;
4110
4111 if (fbcIns != NULL) {
4112 fbcIns->cfbc_Get_Gain_Red(COMM_DEV_SERIAL, &temp_value);
4113 //value 0 ~ 2047
4114 //value = (temp_value*2047)/255;
4115 value = temp_value;
4116
4117 return value;
4118 }
4119
4120 return 0;
4121}
4122
4123int CTv::Tv_FactorySet_FBC_Gain_Green( int value ) {
4124 int temp_value = 0;
4125
4126 //temp_value = (value*255)/2047;
4127 //value 0 ~ 2047
4128 temp_value = value;
4129
4130 if (fbcIns != NULL) {
4131 fbcIns->cfbc_Set_Gain_Green(COMM_DEV_SERIAL, temp_value);
4132 return 0;
4133 }
4134
4135 return -1;
4136}
4137
4138int CTv::Tv_FactoryGet_FBC_Gain_Green ( void ) {
4139 int temp_value = 0, value = 0;
4140
4141 if (fbcIns != NULL) {
4142 fbcIns->cfbc_Get_Gain_Green(COMM_DEV_SERIAL, &temp_value);
4143 //value 0 ~ 2047
4144 //value = (temp_value*2047)/255;
4145 value = temp_value;
4146
4147 return value;
4148 }
4149
4150 return 0;
4151}
4152
4153int CTv::Tv_FactoryGet_FBC_VIDEO_MUTE ( void ) {
4154 if (fbcIns != NULL) {
4155 fbcIns->cfbc_Set_VMute(COMM_DEV_SERIAL, 1);
4156 }
4157
4158 return 0;
4159}
4160
4161int CTv::Tv_FactorySet_FBC_Gain_Blue( int value ) {
4162 int temp_value = 0;
4163
4164 //temp_value = (value*255)/2047;
4165 //value 0 ~ 2047
4166 temp_value = value;
4167
4168 if (fbcIns != NULL) {
4169 fbcIns->cfbc_Set_Gain_Blue(COMM_DEV_SERIAL, temp_value);
4170 return 0;
4171 }
4172
4173 return -1;
4174}
4175
4176int CTv::Tv_FactoryGet_FBC_Gain_Blue ( void ) {
4177 int temp_value = 0, value = 0;
4178
4179 if (fbcIns != NULL) {
4180 fbcIns->cfbc_Get_Gain_Blue(COMM_DEV_SERIAL, &temp_value);
4181 //value 0 ~ 2047
4182 //value = (temp_value*2047)/255;
4183 value = temp_value;
4184
4185 return value;
4186 }
4187
4188 return 0;
4189}
4190
4191int CTv::Tv_FactorySet_FBC_Offset_Red( int value ) {
4192 //value -1024~+1023
4193 int temp_value = 0;
4194
4195 //temp_value = (value+1024)*255/2047;
4196 temp_value = value;
4197
4198 if (fbcIns != NULL) {
4199 fbcIns->cfbc_Set_Offset_Red(COMM_DEV_SERIAL, temp_value);
4200 return 0;
4201 }
4202
4203 return -1;
4204}
4205
4206int CTv::Tv_FactoryGet_FBC_Offset_Red ( void ) {
4207 int temp_value = 0, value = 0;
4208
4209 if (fbcIns != NULL) {
4210 fbcIns->cfbc_Get_Offset_Red(COMM_DEV_SERIAL, &temp_value);
4211 //value -1024~+1023
4212 //value = (temp_value*2047)/255 - 1024;
4213 value = temp_value;
4214
4215 return value;
4216 }
4217
4218 return 0;
4219}
4220
4221int CTv::Tv_FactorySet_FBC_Offset_Green( int value ) {
4222 //value -1024~+1023
4223 int temp_value = 0;
4224
4225 //temp_value = (value+1024)*255/2047;
4226 temp_value = value;
4227
4228 if (fbcIns != NULL) {
4229 fbcIns->cfbc_Set_Offset_Green(COMM_DEV_SERIAL, temp_value);
4230 return 0;
4231 }
4232
4233 return -1;
4234}
4235
4236int CTv::Tv_FactoryGet_FBC_Offset_Green ( void ) {
4237 int temp_value = 0, value = 0;
4238
4239 if (fbcIns != NULL) {
4240 fbcIns->cfbc_Get_Offset_Green(COMM_DEV_SERIAL, &temp_value);
4241 //value -1024~+1023
4242 //value = (temp_value*2047)/255 - 1024;
4243 value = temp_value;
4244
4245 return value;
4246 }
4247
4248 return 0;
4249}
4250
4251int CTv::Tv_FactorySet_FBC_Offset_Blue( int value ) {
4252 //value -1024~+1023
4253 int temp_value = 0;
4254
4255 //temp_value = (value+1024)*255/2047;
4256 temp_value = value;
4257
4258 if (fbcIns != NULL) {
4259 fbcIns->cfbc_Set_Offset_Blue(COMM_DEV_SERIAL, value);
4260 return 0;
4261 }
4262
4263 return -1;
4264}
4265
4266int CTv::Tv_FactoryGet_FBC_Offset_Blue ( void ) {
4267 int temp_value = 0, value = 0;
4268
4269 if (fbcIns != NULL) {
4270 fbcIns->cfbc_Get_Offset_Blue(COMM_DEV_SERIAL, &temp_value);
4271 //value -1024~+1023
4272 //value = (temp_value*2047)/255 - 1024;
4273 value = temp_value;
4274
4275 return value;
4276 }
4277
4278 return 0;
4279}
4280
4281int CTv::Tv_FactoryGetWhiteBalanceRedGain(int source_type, int colortemp_mode) {
4282 int ret = -1;
4283 if (!mHdmiOutFbc) { // not use fbc store the white balance params
4284 LOGD("--------- call none fbc method ---------");
4285 ret = mVpp.FactoryGetColorTemp_Rgain(source_type, colortemp_mode);
4286 } else { //use fbc store the white balance params
4287 LOGD("--------- call fbc method ---------");
4288 ret = Tv_FactoryGetItemFromBatch((vpp_color_temperature_mode_t)colortemp_mode, 0);
4289 }
4290 return ret;
4291}
4292
4293int CTv::Tv_FactoryGetWhiteBalanceGreenGain(int source_type, int colortemp_mode) {
4294 int ret = -1;
4295 if (!mHdmiOutFbc) { // not use fbc store the white balance params
4296 ret = mVpp.FactoryGetColorTemp_Ggain(source_type, colortemp_mode);
4297 } else { //use fbc store the white balance params
4298 ret = Tv_FactoryGetItemFromBatch((vpp_color_temperature_mode_t)colortemp_mode, 1);
4299 }
4300 return ret;
4301}
4302
4303int CTv::Tv_FactoryGetWhiteBalanceBlueGain(int source_type, int colortemp_mode) {
4304 int ret = -1;
4305 if (!mHdmiOutFbc) { // not use fbc store the white balance params
4306 ret = mVpp.FactoryGetColorTemp_Bgain(source_type, colortemp_mode);
4307 } else { //use fbc store the white balance params
4308 ret = Tv_FactoryGetItemFromBatch((vpp_color_temperature_mode_t)colortemp_mode, 2);
4309 }
4310 return ret;
4311}
4312
4313int CTv::Tv_FactoryGetWhiteBalanceRedOffset(int source_type, int colortemp_mode) {
4314 int ret = -1;
4315 if (!mHdmiOutFbc) { // not use fbc store the white balance params
4316 ret = mVpp.FactoryGetColorTemp_Roffset(source_type, colortemp_mode);
4317 } else { //use fbc store the white balance params
4318 ret = Tv_FactoryGetItemFromBatch((vpp_color_temperature_mode_t)colortemp_mode, 3);
4319 }
4320 return ret;
4321}
4322
4323int CTv::Tv_FactoryGetWhiteBalanceGreenOffset(int source_type, int colortemp_mode) {
4324 int ret = -1;
4325 if (!mHdmiOutFbc) { // not use fbc store the white balance params
4326 ret = mVpp.FactoryGetColorTemp_Goffset(source_type, colortemp_mode);
4327 } else { //use fbc store the white balance params
4328 ret = Tv_FactoryGetItemFromBatch((vpp_color_temperature_mode_t)colortemp_mode, 4);
4329 }
4330 return ret;
4331}
4332
4333int CTv::Tv_FactoryGetWhiteBalanceBlueOffset(int source_type, int colortemp_mode) {
4334 int ret = -1;
4335 if (!mHdmiOutFbc) { // not use fbc store the white balance params
4336 ret = mVpp.FactoryGetColorTemp_Boffset(source_type, colortemp_mode);
4337 } else { //use fbc store the white balance params
4338 ret = Tv_FactoryGetItemFromBatch((vpp_color_temperature_mode_t)colortemp_mode, 5);
4339 }
4340 return ret;
4341}
4342
4343int CTv::Tv_FactorySetWhiteBalanceRedGain(int source_type, int colortemp_mode, int value) {
4344 int ret = -1;
4345 if (value < 0) {
4346 value = 0;
4347 } else if (value > 2047) {
4348 value = 2047;
4349 }
4350 if (!mHdmiOutFbc) { // not use fbc store the white balance params
4351 ret = mVpp.FactorySetColorTemp_Rgain(source_type, colortemp_mode, value);
4352 if (ret != -1) {
4353 LOGD("save the red gain to flash")
4354 ret = mVpp.FactorySaveColorTemp_Rgain(source_type, colortemp_mode, value);
4355 }
4356 } else { //use fbc store the white balance params
4357 value = Tv_FactoryWhiteBalanceFormatInputFbcGainParams(value);
4358 ret = Tv_FactorySet_FBC_Gain_Red(value);
4359 }
4360 return ret;
4361}
4362
4363int CTv::Tv_FactorySetWhiteBalanceGreenGain(int source_type, int colortemp_mode, int value) {
4364 int ret = -1;
4365 if (value < 0) {
4366 value = 0;
4367 } else if (value > 2047) {
4368 value = 2047;
4369 }
4370 if (!mHdmiOutFbc) { // not use fbc store the white balance params
4371 ret = mVpp.FactorySetColorTemp_Ggain(source_type, colortemp_mode, value);
4372 if (ret != -1) {
4373 LOGD("save the green gain to flash")
4374 ret = mVpp.FactorySaveColorTemp_Ggain(source_type, colortemp_mode, value);
4375 }
4376 } else { //use fbc store the white balance params
4377 value = Tv_FactoryWhiteBalanceFormatInputFbcGainParams(value);
4378 ret = Tv_FactorySet_FBC_Gain_Green(value);
4379 }
4380 return ret;
4381}
4382
4383int CTv::Tv_FactorySetWhiteBalanceBlueGain(int source_type, int colortemp_mode, int value) {
4384 int ret = -1;
4385 if (value < 0) {
4386 value = 0;
4387 } else if (value > 2047) {
4388 value = 2047;
4389 }
4390 if (!mHdmiOutFbc) { // not use fbc store the white balance params
4391 ret = mVpp.FactorySetColorTemp_Bgain(source_type, colortemp_mode, value);
4392 if (ret != -1) {
4393 LOGD("save the blue gain to flash")
4394 ret = mVpp.FactorySaveColorTemp_Bgain(source_type, colortemp_mode, value);
4395 }
4396 } else { //use fbc store the white balance params
4397 value = Tv_FactoryWhiteBalanceFormatInputFbcGainParams(value);
4398 ret = Tv_FactorySet_FBC_Gain_Blue(value);
4399 }
4400 return ret;
4401}
4402
4403int CTv::Tv_FactorySetWhiteBalanceRedOffset(int source_type, int colortemp_mode, int value) {
4404 int ret = -1;
4405 if (value < -1024) {
4406 value = -1024;
4407 } else if (value > 1023) {
4408 value = 1023;
4409 }
4410 if (!mHdmiOutFbc) { // not use fbc store the white balance params
4411 ret = mVpp.FactorySetColorTemp_Roffset(source_type, colortemp_mode, value);
4412 if (ret != -1) {
4413 LOGD("save the red offset to flash")
4414 ret = mVpp.FactorySaveColorTemp_Roffset(source_type, colortemp_mode, value);
4415 }
4416 } else { //use fbc store the white balance params
4417 value = Tv_FactoryWhiteBalanceFormatInputFbcOffsetParams(value);
4418 ret = Tv_FactorySet_FBC_Offset_Red(value);
4419 }
4420 return ret;
4421}
4422
4423int CTv::Tv_FactorySetWhiteBalanceGreenOffset(int source_type, int colortemp_mode, int value) {
4424 int ret = -1;
4425 if (value < -1024) {
4426 value = -1024;
4427 } else if (value > 1023) {
4428 value = 1023;
4429 }
4430 if (!mHdmiOutFbc) { // not use fbc store the white balance params
4431 ret = mVpp.FactorySetColorTemp_Goffset(source_type, colortemp_mode, value);
4432 if (ret != -1) {
4433 LOGD("save the green offset to flash")
4434 ret = mVpp.FactorySaveColorTemp_Goffset(source_type, colortemp_mode, value);
4435 }
4436 } else { //use fbc store the white balance params
4437 value = Tv_FactoryWhiteBalanceFormatInputFbcOffsetParams(value);
4438 ret = Tv_FactorySet_FBC_Offset_Green(value);
4439 }
4440 return ret;
4441}
4442
4443int CTv::Tv_FactorySetWhiteBalanceBlueOffset(int source_type, int colortemp_mode, int value) {
4444 int ret = -1;
4445 if (value < -1024) {
4446 value = -1024;
4447 } else if (value > 1023) {
4448 value = 1023;
4449 }
4450 if (!mHdmiOutFbc) { // not use fbc store the white balance params
4451 ret = mVpp.FactorySetColorTemp_Boffset(source_type, colortemp_mode, value);
4452 if (ret != -1) {
4453 LOGD("save the blue offset to flash")
4454 ret = mVpp.FactorySaveColorTemp_Boffset(source_type, colortemp_mode, value);
4455 }
4456 } else { //use fbc store the white balance params
4457 value = Tv_FactoryWhiteBalanceFormatInputFbcOffsetParams(value);
4458 ret = Tv_FactorySet_FBC_Offset_Blue(value);
4459 }
4460 return ret;
4461}
4462
4463int CTv::Tv_FactorySetWhiteBalanceColorTempMode(int source_type, int colortemp_mode, int is_save) {
4464 int ret = -1;
4465 if (!mHdmiOutFbc) { // not use fbc store the white balance params
4466 ret = mVpp.SetColorTemperature((vpp_color_temperature_mode_t)colortemp_mode, (tv_source_input_type_t)source_type, is_save);
4467 } else { //use fbc store the white balance params
4468 ret = Tv_FactorySet_FBC_ColorTemp_Mode(colortemp_mode);
4469 }
4470 return ret;
4471}
4472
4473int CTv::Tv_FactoryGetWhiteBalanceColorTempMode(int source_type ) {
4474 int ret = -1;
4475 if (!mHdmiOutFbc) { // not use fbc store the white balance params
4476 ret = mVpp.GetColorTemperature((tv_source_input_type_t)source_type);
4477 } else { //use fbc store the white balance params
4478 ret = Tv_FactoryGet_FBC_ColorTemp_Mode();
4479 }
4480 return ret;
4481}
4482
4483int CTv::Tv_FactoryWhiteBalanceFormatInputFbcGainParams(int value) {
4484 int ret = 1024;
4485 if (value < 0) {
4486 ret = 0;
4487 } else if (value > 2047) {
4488 ret = 2047;
4489 } else {
4490 ret = value;
4491 }
4492 ret = ret >> 3;
4493 return ret;
4494}
4495
4496int CTv::Tv_FactoryWhiteBalanceFormatInputFbcOffsetParams(int value) {
4497 int ret = 0;
4498 if (value < -1024) {
4499 ret = -1024;
4500 } else if (value > 1023) {
4501 ret = 1023;
4502 } else {
4503 ret = value;
4504 }
4505 ret += 1024;
4506 ret = ret >> 3;
4507 return ret;
4508}
4509
4510int CTv::Tv_FactoryWhiteBalanceFormatOutputFbcOffsetParams(int value) {
4511 if (value == 255) {
4512 value = 1023;
4513 } else {
4514 value = value << 3;
4515 value -= 1024;
4516 }
4517 return value;
4518}
4519
4520int CTv::Tv_FactoryWhiteBalanceFormatOutputFbcGainParams(int value) {
4521 value = value << 3;
4522 if (value < 0) {
4523 value = 0;
4524 } else if (value > 2047) {
4525 value = 2047;
4526 }
4527 return value;
4528}
4529
4530int CTv::Tv_FactorySaveWhiteBalancePramas(int source_type, int tempmode, int r_gain, int g_gain, int b_gain, int r_offset, int g_offset, int b_offset) {
4531 int ret = 0;
4532 if (!mHdmiOutFbc) { // not use fbc store the white balance params
4533 mVpp.SaveColorTemp((vpp_color_temperature_mode_t) tempmode, (tv_source_input_type_t) source_type);
4534 mVpp.FactorySaveColorTemp_Rgain(source_type, tempmode, r_gain);
4535 mVpp.FactorySaveColorTemp_Ggain(source_type, tempmode, g_gain);
4536 mVpp.FactorySaveColorTemp_Bgain(source_type, tempmode, b_gain);
4537 mVpp.FactorySaveColorTemp_Roffset(source_type, tempmode, r_offset);
4538 mVpp.FactorySaveColorTemp_Goffset(source_type, tempmode, g_offset);
4539 mVpp.FactorySaveColorTemp_Boffset(source_type, tempmode, b_offset);
4540 } else { //use fbc store the white balance params
4541 tcon_rgb_ogo_t params;
4542
4543 params.r_gain = Tv_FactoryWhiteBalanceFormatInputFbcGainParams(r_gain);
4544 params.g_gain = Tv_FactoryWhiteBalanceFormatInputFbcGainParams(g_gain);
4545 params.b_gain = Tv_FactoryWhiteBalanceFormatInputFbcGainParams(b_gain);
4546 params.r_post_offset = Tv_FactoryWhiteBalanceFormatInputFbcOffsetParams(r_offset);
4547 params.g_post_offset = Tv_FactoryWhiteBalanceFormatInputFbcOffsetParams(g_offset);
4548 params.b_post_offset = Tv_FactoryWhiteBalanceFormatInputFbcOffsetParams(b_offset);
4549 ret = Tv_FactorySet_FBC_ColorTemp_Batch((vpp_color_temperature_mode_t)tempmode, params);
4550 }
4551 return ret;
4552}
4553
4554/**
4555* The color temperature enum order is diffrent bettewn G9 and Fbc, so we have to make a mapping
4556**/
4557int CTv::Tv_FactoryWhiteBalanceColorTempMappingG92Fbc(int Tempmode) {
4558 int ret = Tempmode;
4559 switch (Tempmode) {
4560 case 0: //standard
4561 ret = 1;
4562 break;
4563 case 1: //warm
4564 ret = 2;
4565 break;
4566 case 2: //cold
4567 ret = 0;
4568 break;
4569 default:
4570 break;
4571 }
4572 return ret;
4573}
4574
4575/**
4576* The color temperature enum order is diffrent bettewn G9 and Fbc, so we have to make a mapping
4577**/
4578int CTv::Tv_FactoryWhiteBalanceColorTempMappingFbc2G9(int Tempmode) {
4579 int ret = Tempmode;
4580 switch (Tempmode) {
4581 case 0: //cold
4582 ret = 2;
4583 break;
4584 case 1: //standard
4585 ret = 0;
4586 break;
4587 case 2: //warm
4588 ret = 1;
4589 break;
4590 default:
4591 break;
4592 }
4593 return ret;
4594}
4595
4596int CTv::Tv_SetTestPattern(int value) {
4597 int ret = -1;
4598 if (fbcIns != NULL) {
4599 LOGD("%s, value is %d\n", __FUNCTION__, value);
4600 ret = fbcIns->cfbc_TestPattern_Select(COMM_DEV_SERIAL, value);
4601 }
4602
4603 return ret;
4604}
4605
4606int CTv::Tv_FactoryCloseWhiteBalanceGrayPattern() {
4607 int useFbc = 0;
4608 int ret = -1;
4609 if (!mHdmiOutFbc) { // not use fbc store the white balance params
4610 ret = mVpp.VPP_SetGrayPattern(0);
4611 } else { //use fbc store the white balance params
4612 ret = Tv_FactoryClose_FBC_GrayPattern();
4613 }
4614 return ret;
4615}
4616
4617int CTv::Tv_FactoryOpenWhiteBalanceGrayPattern() {
4618 int ret = 0;
4619 if (mHdmiOutFbc) { //use fbc store the white balance params
4620 ret = Tv_FactoryOpen_FBC_GrayPattern();
4621 }
4622 return ret;
4623}
4624
4625int CTv::Tv_FactorySetWhiteBalanceGrayPattern(int value) {
4626 int ret = -1;
4627 if (!mHdmiOutFbc) {
4628 ret = mVpp.VPP_SetGrayPattern(value);
4629 } else {
4630 ret = Tv_FactorySet_FBC_GrayPattern(value);
4631 }
4632 return ret;
4633}
4634
4635int CTv:: Tv_FactoryGetWhiteBalanceGrayPattern() {
4636 int ret = -1;
4637 if (!mHdmiOutFbc) {
4638 ret = mVpp.VPP_GetGrayPattern();
4639 }
4640 return ret;
4641}
4642
4643int CTv::Tv_FactorySet_FBC_GrayPattern(int value) {
4644 int ret = -1;
4645 unsigned char grayValue = 0;
4646 if (value > 255) {
4647 grayValue = 255;
4648 } else if (value < 0) {
4649 grayValue = 0;
4650 } else {
4651 grayValue = (unsigned char)(0xFF & value);
4652 }
4653 if (fbcIns != NULL) {
4654 ret = fbcIns->cfbc_WhiteBalance_SetGrayPattern(COMM_DEV_SERIAL, grayValue);
4655 }
4656 return ret;
4657}
4658
4659int CTv::Tv_FactoryOpen_FBC_GrayPattern() {
4660 int ret = -1;
4661 if (fbcIns != NULL) {
4662 ret = fbcIns->cfbc_WhiteBalance_GrayPattern_OnOff(COMM_DEV_SERIAL, 0);
4663 }
4664 return ret;
4665}
4666
4667int CTv::Tv_FactoryClose_FBC_GrayPattern() {
4668 int ret = -1;
4669 if (fbcIns != NULL) {
4670 ret = fbcIns->cfbc_WhiteBalance_GrayPattern_OnOff(COMM_DEV_SERIAL, 1);
4671 }
4672 return ret;
4673}
4674
4675int CTv::Tv_FactorySet_FBC_ColorTemp_Mode( int mode ) {
4676 if (fbcIns != NULL) {
4677 fbcIns->cfbc_Set_ColorTemp_Mode(COMM_DEV_SERIAL, mode);
4678 return 0;
4679 }
4680
4681 return -1;
4682}
4683
4684int CTv::Tv_FactoryGet_FBC_ColorTemp_Mode ( void ) {
4685 int temp_mode = 0;
4686
4687 if (fbcIns != NULL) {
4688 fbcIns->cfbc_Get_ColorTemp_Mode(COMM_DEV_SERIAL, &temp_mode);
4689 return temp_mode;
4690 }
4691
4692 return -1;
4693}
4694
4695int CTv::Tv_FactorySet_FBC_ColorTemp_Mode_N360( int mode ) {
4696 if (fbcIns != NULL) {
4697 fbcIns->cfbc_Set_ColorTemp_Mode(COMM_DEV_SERIAL, mode);
4698 SSMSaveFBCN360ColorTempVal(mode);
4699 return 0;
4700 }
4701
4702 return -1;
4703}
4704
4705int CTv::Tv_FactoryGet_FBC_ColorTemp_Mode_N360 ( void ) {
4706 int temp_mode = 0;
4707 SSMReadFBCN360ColorTempVal(&temp_mode);
4708 return temp_mode;
4709}
4710
4711int CTv::Tv_FactorySet_FBC_LockN_state(int value) {
4712 LOGE ("Tv_FactorySet_FBC_LockN_state %d!!!\n", value);
4713 if (fbcIns != NULL) {
4714 fbcIns->cfbc_Set_LockN_state(COMM_DEV_SERIAL, value);
4715 return 0;
4716 }
4717 return -1;
4718}
4719
4720int CTv::Tv_FactorySet_FBC_WB_Initial( int status ) {
4721 if (fbcIns != NULL) {
4722 fbcIns->cfbc_Set_WB_Initial(COMM_DEV_SERIAL, status);
4723 return 0;
4724 }
4725
4726 return -1;
4727}
4728
4729int CTv::Tv_FactoryGet_FBC_WB_Initial ( void ) {
4730 int temp_status = 0;
4731
4732 if (fbcIns != NULL) {
4733 fbcIns->cfbc_Get_WB_Initial(COMM_DEV_SERIAL, &temp_status);
4734 return temp_status;
4735 }
4736
4737 return 0;
4738}
4739
4740int CTv::Tv_FactorySet_FBC_ColorTemp_Batch(vpp_color_temperature_mode_t Tempmode, tcon_rgb_ogo_t params) {
4741 unsigned char mode = 0, r_gain, g_gain, b_gain, r_offset, g_offset, b_offset;
4742 switch (Tempmode) {
4743 case VPP_COLOR_TEMPERATURE_MODE_STANDARD:
4744 mode = 1; //COLOR_TEMP_STD
4745 break;
4746 case VPP_COLOR_TEMPERATURE_MODE_WARM:
4747 mode = 2; //COLOR_TEMP_WARM
4748 break;
4749 case VPP_COLOR_TEMPERATURE_MODE_COLD:
4750 mode = 0; //COLOR_TEMP_COLD
4751 break;
4752 case VPP_COLOR_TEMPERATURE_MODE_USER:
4753 mode = 3; //COLOR_TEMP_USER
4754 break;
4755 default:
4756 break;
4757 }
4758 r_gain = (params.r_gain * 255) / 2047; // u1.10, range 0~2047, default is 1024 (1.0x)
4759 g_gain = (params.g_gain * 255) / 2047;
4760 b_gain = (params.b_gain * 255) / 2047;
4761 r_offset = (params.r_post_offset + 1024) * 255 / 2047; // s11.0, range -1024~+1023, default is 0
4762 g_offset = (params.g_post_offset + 1024) * 255 / 2047;
4763 b_offset = (params.b_post_offset + 1024) * 255 / 2047;
4764 LOGD ( "~Tv_FactorySet_FBC_ColorTemp_Batch##%d,%d,%d,%d,%d,%d,##", r_gain, g_gain, b_gain, r_offset, g_offset, b_offset );
4765
4766 if (fbcIns != NULL) {
4767 fbcIns->cfbc_Set_WB_Batch(COMM_DEV_SERIAL, mode, r_gain, g_gain, b_gain, r_offset, g_offset, b_offset);
4768 return 0;
4769 }
4770
4771 return -1;
4772}
4773
4774int CTv::Tv_FactoryGet_FBC_ColorTemp_Batch ( vpp_color_temperature_mode_t Tempmode, tcon_rgb_ogo_t *params ) {
4775 unsigned char mode = 0, r_gain, g_gain, b_gain, r_offset, g_offset, b_offset;
4776 switch (Tempmode) {
4777 case VPP_COLOR_TEMPERATURE_MODE_STANDARD:
4778 mode = 1; //COLOR_TEMP_STD
4779 break;
4780 case VPP_COLOR_TEMPERATURE_MODE_WARM:
4781 mode = 2; //COLOR_TEMP_WARM
4782 break;
4783 case VPP_COLOR_TEMPERATURE_MODE_COLD:
4784 mode = 0; //COLOR_TEMP_COLD
4785 break;
4786 case VPP_COLOR_TEMPERATURE_MODE_USER:
4787 mode = 3; //COLOR_TEMP_USER
4788 break;
4789 default:
4790 break;
4791 }
4792
4793 if (fbcIns != NULL) {
4794 fbcIns->cfbc_Get_WB_Batch(COMM_DEV_SERIAL, mode, &r_gain, &g_gain, &b_gain, &r_offset, &g_offset, &b_offset);
4795 LOGD ( "~Tv_FactoryGet_FBC_ColorTemp_Batch##%d,%d,%d,%d,%d,%d,##", r_gain, g_gain, b_gain, r_offset, g_offset, b_offset );
4796
4797 params->r_gain = (r_gain * 2047) / 255;
4798 params->g_gain = (g_gain * 2047) / 255;
4799 params->b_gain = (b_gain * 2047) / 255;
4800 params->r_post_offset = (r_offset * 2047) / 255 - 1024;
4801 params->g_post_offset = (g_offset * 2047) / 255 - 1024;
4802 params->b_post_offset = (b_offset * 2047) / 255 - 1024;
4803 return 0;
4804 }
4805
4806 return -1;
4807}
4808
4809int CTv::Tv_FactorySet_WB_G9_To_FBC( vpp_color_temperature_mode_t Tempmode, tcon_rgb_ogo_t params ) {
4810 Tv_FactorySet_FBC_ColorTemp_Batch(Tempmode, params);
4811 return 0;
4812}
4813
4814int CTv::Tv_FactoryGet_WB_G9_To_FBC ( vpp_color_temperature_mode_t Tempmode, tcon_rgb_ogo_t *params ) {
4815 int temp_status = 0;
4816 Tv_FactoryGet_FBC_ColorTemp_Batch(Tempmode, params);
4817 return temp_status;
4818}
4819
4820int CTv::Tv_FactoryGetItemFromBatch(vpp_color_temperature_mode_t colortemp_mode, int item) {
4821 tcon_rgb_ogo_t params;
4822 int ret = 0;
4823
4824 Tv_FactoryGet_FBC_ColorTemp_Batch((vpp_color_temperature_mode_t)colortemp_mode, &params);
4825 switch (item) {
4826 case 0:
4827 ret = params.r_gain;
4828 ret = Tv_FactoryWhiteBalanceFormatOutputFbcGainParams(ret);
4829 break;
4830 case 1:
4831 ret = params.g_gain;
4832 ret = Tv_FactoryWhiteBalanceFormatOutputFbcGainParams(ret);
4833 break;
4834 case 2:
4835 ret = params.b_gain;
4836 ret = Tv_FactoryWhiteBalanceFormatOutputFbcGainParams(ret);
4837 break;
4838 case 3:
4839 ret = params.r_post_offset;
4840 ret = Tv_FactoryWhiteBalanceFormatOutputFbcOffsetParams(ret);
4841 break;
4842 case 4:
4843 ret = params.g_post_offset;
4844 ret = Tv_FactoryWhiteBalanceFormatOutputFbcOffsetParams(ret);
4845 break;
4846 case 5:
4847 ret = params.b_post_offset;
4848 ret = Tv_FactoryWhiteBalanceFormatOutputFbcOffsetParams(ret);
4849 break;
4850 default:
4851 ret = 0;
4852 }
4853 return ret;
4854}
4855
4856int CTv::Tv_FactorySet_FBC_CM_OnOff( unsigned char status ) {
4857 if (fbcIns != NULL) {
4858 fbcIns->cfbc_Set_CM(COMM_DEV_SERIAL, status);
4859 return 0;
4860 }
4861
4862 return -1;
4863}
4864
4865int CTv::Tv_FactoryGet_FBC_CM_OnOff (void) {
4866 int temp_status = 0;
4867
4868 if (fbcIns != NULL) {
4869 fbcIns->cfbc_Get_CM(COMM_DEV_SERIAL, &temp_status);
4870 return temp_status;
4871 }
4872
4873 return 0;
4874}
4875
4876int CTv::Tv_FactorySet_FBC_DNLP_OnOff( unsigned char status ) {
4877 if (fbcIns != NULL) {
4878 fbcIns->cfbc_Set_DNLP(COMM_DEV_SERIAL, status);
4879 return 0;
4880 }
4881
4882 return -1;
4883}
4884
4885int CTv::Tv_FactoryGet_FBC_DNLP_OnOff (void) {
4886 int temp_status = 0;
4887
4888 if (fbcIns != NULL) {
4889 fbcIns->cfbc_Get_DNLP(COMM_DEV_SERIAL, &temp_status);
4890 return temp_status;
4891 }
4892
4893 return 0;
4894}
4895
4896int CTv::Tv_FactorySet_FBC_Gamma_OnOff( unsigned char status ) {
4897 if (fbcIns != NULL) {
4898 fbcIns->cfbc_Set_Gamma(COMM_DEV_SERIAL, status);
4899 return 0;
4900 }
4901
4902 return -1;
4903}
4904
4905int CTv::Tv_FactoryGet_FBC_Gamma_OnOff (void) {
4906 int temp_status = 0;
4907
4908 if (fbcIns != NULL) {
4909 fbcIns->cfbc_Get_Gamma(COMM_DEV_SERIAL, &temp_status);
4910 return temp_status;
4911 }
4912
4913 return 0;
4914}
4915
4916int CTv::Tv_FactorySet_FBC_WhiteBalance_OnOff( unsigned char status ) {
4917 if (fbcIns != NULL) {
4918 fbcIns->cfbc_Set_WhiteBalance_OnOff(COMM_DEV_SERIAL, status);
4919 return 0;
4920 }
4921
4922 return -1;
4923}
4924
4925int CTv::Tv_FactoryGet_FBC_WhiteBalance_OnOff (void) {
4926 int temp_status = 0;
4927
4928 if (fbcIns != NULL) {
4929 fbcIns->cfbc_Get_WhiteBalance_OnOff(COMM_DEV_SERIAL, &temp_status);
4930 return temp_status;
4931 }
4932
4933 return 0;
4934}
4935
4936int CTv::Tv_FactorySet_FBC_backlight_onoff ( int value ) {
4937 if (fbcIns != NULL) {
4938 fbcIns->cfbc_Set_backlight_onoff(COMM_DEV_SERIAL, value);
4939 return 0;
4940 }
4941
4942 return -1;
4943}
4944
4945int CTv::Tv_FactoryGet_FBC_backlight_onoff ( void ) {
4946 int temp_value = 0;
4947
4948 if (fbcIns != NULL) {
4949 fbcIns->cfbc_Get_backlight_onoff(COMM_DEV_SERIAL, &temp_value);
4950 return temp_value;
4951 }
4952
4953 return 0;
4954}
4955
4956int CTv::Tv_FactorySet_FBC_LVDS_SSG_Set( int value ) {
4957 if (fbcIns != NULL) {
4958 fbcIns->cfbc_Set_LVDS_SSG_Set(COMM_DEV_SERIAL, value);
4959 return 0;
4960 }
4961
4962 return -1;
4963}
4964
4965int CTv::Tv_FactorySet_FBC_LightSensor_Status_N310 ( int value ) {
4966 int temp_value = value;
4967
4968 if (fbcIns != NULL) {
4969 fbcIns->cfbc_Set_LightSensor_N310(COMM_DEV_SERIAL, temp_value);
4970 SSMSaveFBCN310LightsensorVal(temp_value);
4971 return 0;
4972 }
4973
4974 return -1;
4975}
4976
4977int CTv::Tv_FactoryGet_FBC_LightSensor_Status_N310 ( void ) {
4978 int temp_value = 0;
4979 int data = 0;
4980
4981 if (fbcIns != NULL) {
4982 SSMReadFBCN310LightsensorVal(&temp_value);
4983 data = temp_value;
4984 return data;
4985 }
4986
4987 return 0;
4988}
4989
4990int CTv::Tv_FactorySet_FBC_Dream_Panel_Status_N310 ( int value ) {
4991 int temp_value = value;
4992
4993 if (fbcIns != NULL) {
4994 fbcIns->cfbc_Set_Dream_Panel_N310(COMM_DEV_SERIAL, temp_value);
4995 SSMSaveFBCN310Dream_PanelVal(temp_value);
4996 return 0;
4997 }
4998
4999 return -1;
5000}
5001
5002int CTv::Tv_FactoryGet_FBC_Dream_Panel_Status_N310 ( void ) {
5003 int temp_value = 0;
5004 int data = 0;
5005
5006 if (fbcIns != NULL) {
5007 SSMReadFBCN310Dream_PanelVal(&temp_value);
5008 data = temp_value;
5009 return data;
5010 }
5011
5012 return 0;
5013}
5014
5015int CTv::Tv_FactorySet_FBC_MULT_PQ_Status_N310 ( int value ) {
5016 int temp_value = value;
5017
5018 if (fbcIns != NULL) {
5019 fbcIns->cfbc_Set_MULT_PQ_N310(COMM_DEV_SERIAL, temp_value);
5020 SSMSaveFBCN310MULT_PQVal(temp_value);
5021 return 0;
5022 }
5023
5024 return -1;
5025}
5026
5027int CTv::Tv_FactoryGet_FBC_MULT_PQ_Status_N310 ( void ) {
5028 int temp_value = 0;
5029 int data = 0;
5030
5031 if (fbcIns != NULL) {
5032 SSMReadFBCN310MULT_PQVal(&temp_value);
5033 data = temp_value;
5034 return data;
5035 }
5036
5037 return 0;
5038}
5039
5040int CTv::Tv_FactorySet_FBC_MEMC_Status_N310 ( int value ) {
5041 int temp_value = value;
5042
5043 if (fbcIns != NULL) {
5044 fbcIns->cfbc_Set_MEMC_N310(COMM_DEV_SERIAL, temp_value);
5045 SSMSaveFBCN310MEMCVal(temp_value);
5046 return 0;
5047 }
5048
5049 return -1;
5050}
5051
5052int CTv::Tv_FactoryGet_FBC_MEMC_Status_N310 ( void ) {
5053 int temp_value = 0;
5054 int data = 0;
5055
5056 if (fbcIns != NULL) {
5057 SSMReadFBCN310MEMCVal(&temp_value);
5058 data = temp_value;
5059 return data;
5060 }
5061
5062 return -1;
5063}
5064
5065int CTv::Tv_FactorySet_FBC_ColorTemp_Mode_N310( int mode ) {
5066 //int colorTemp = 0;
5067 if (fbcIns != NULL) {
5068 //colorTemp = Tv_FactoryWhiteBalanceColorTempMappingG92Fbc(mode);
5069 fbcIns->cfbc_Set_ColorTemp_Mode(COMM_DEV_SERIAL, mode);
5070 SSMSaveFBCN310ColorTempVal(mode);
5071 return 0;
5072 }
5073
5074 return -1;
5075}
5076
5077int CTv::Tv_FactoryGet_FBC_ColorTemp_Mode_N310 ( void ) {
5078 int mode = 0;
5079
5080 if (fbcIns != NULL) {
5081 SSMReadFBCN310ColorTempVal(&mode);
5082 //mode = Tv_FactoryWhiteBalanceColorTempMappingFbc2G9(temp_mode);
5083
5084 return mode;
5085 }
5086 return -1;
5087}
5088
5089int CTv::Tv_FactorySet_FBC_Backlight_N310 ( int value ) {
5090 int val = 0;
5091
5092 if (fbcIns != NULL) {
5093 fbcIns->cfbc_Set_Backlight(COMM_DEV_SERIAL, value);
5094 val = value;
5095 SSMSaveFBCN310BackLightVal(val);
5096 return 0;
5097 }
5098
5099 return -1;
5100}
5101
5102int CTv::Tv_FactoryGet_FBC_Backlight_N310 ( void ) {
5103 int val = 0;
5104
5105 if (fbcIns != NULL) {
5106 SSMReadFBCN310BackLightVal(&val);
5107 return val;
5108 }
5109
5110 return -1;
5111}
5112
5113int CTv::Tv_FactorySet_FBC_Bluetooth_IIS_N310 ( int value ) {
5114 if (fbcIns != NULL) {
5115 fbcIns->cfbc_Set_Bluetooth_IIS_onoff(COMM_DEV_SERIAL, value);
5116 return 0;
5117 }
5118
5119 return -1;
5120}
5121
5122int CTv::Tv_FactoryGet_FBC_Bluetooth_IIS_N310 ( void ) {
5123 int temp_value = 0;
5124
5125 if (fbcIns != NULL) {
5126 fbcIns->cfbc_Get_Bluetooth_IIS_onoff(COMM_DEV_SERIAL, &temp_value);
5127 return temp_value;
5128 }
5129
5130 return 0;
5131}
5132
5133int CTv::Tv_FactorySet_FBC_Led_N310 ( int val_1, int val_2, int val_3 ) {
5134 int val = 0;
5135
5136 if (fbcIns != NULL) {
5137 val = fbcIns->cfbc_Set_Led_onoff(COMM_DEV_SERIAL, val_1, val_2, val_3);
5138 return val;
5139 }
5140
5141 return -1;
5142}
5143
5144int CTv::Tv_FactorySet_VbyOne_Spread_Spectrum_N311 ( int value ) {
5145 if (fbcIns != NULL) {
5146 return -1;
5147 } else {
5148 LOGD("%s, Set spectrum for T868 V-by-one....%d....\n", __FUNCTION__ , value);
5149 SSMSaveN311_VbyOne_Spread_Spectrum_Val(value);
5150
5151 switch (value) {
5152 case 0:
5153 //SetFileAttrValue ( "/sys/class/amlogic/debug" ,"w 0x135c5091 c 0x10ca");
5154 //SetFileAttrValue ( "/sys/class/amlogic/debug" ,"w 0x801da72c c 0x10cb");
5155 break;
5156 case 1:
5157 SetFileAttrValue ( "/sys/class/amlogic/debug" , "w 0x1ba05091 c 0x10ca");
5158 SetFileAttrValue ( "/sys/class/amlogic/debug" , "w 0x80bda72c c 0x10cb");
5159 break;
5160 default:
5161 LOGD("%s, Set spectrum for T868 V-by-one....%d....\n", __FUNCTION__ , value);
5162 break;
5163 }
5164
5165 return 0;
5166 }
5167}
5168
5169int CTv::Tv_FactoryGet_VbyOne_Spread_Spectrum_N311 ( void ) {
5170 int val = 0;
5171 if (fbcIns != NULL) {
5172 return -1;
5173 } else {
5174 SSMReadN311_VbyOne_Spread_Spectrum_Val(&val);
5175 return val;
5176 }
5177}
5178
5179int CTv::Tv_FactorySet_FBC_AP_STANDBY_N310 ( int value ) {
5180 if (fbcIns != NULL) {
5181 fbcIns->cfbc_Set_AP_STANDBY_N310(COMM_DEV_SERIAL, value);
5182 return 0;
5183 }
5184
5185 return -1;
5186}
5187
5188int CTv::Tv_FactoryGet_FBC_AP_STANDBY_N310( void ) {
5189 int temp_value = 0;
5190
5191 if (fbcIns != NULL) {
5192 fbcIns->cfbc_Get_AP_STANDBY_N310(COMM_DEV_SERIAL, &temp_value);
5193 return temp_value;
5194 }
5195
5196 return 0;
5197}
5198
5199int CTv::Tv_FactorySet_Uboot_Stage(int value) {
5200 if (fbcIns != NULL) {
5201 fbcIns->cfbc_Set_Fbc_Uboot_Stage(COMM_DEV_SERIAL, value);
5202 return 0;
5203 }
5204
5205 return -1;
5206}
5207
5208//audio
5209void CTv::TvAudioOpen() {
5210 SetAudioAVOutMute(CC_AUDIO_UNMUTE);
5211 SetAudioSPDIFMute(CC_AUDIO_UNMUTE);
5212 project_info_t tmp_info;
5213 if (GetProjectInfo(&tmp_info) == 0) {
5214 strncpy(mMainVolLutTableExtraName, tmp_info.amp_curve_name, CC_PROJECT_INFO_ITEM_MAX_LEN - 1);
5215 }
5216 openTvAudio();
5217}
5218
5219void CTv::AudioCtlUninit() {
5220 int oldMuteStatus;
5221
5222 oldMuteStatus = GetAudioMuteForTv();
5223 SetAudioMuteForTv(CC_AUDIO_MUTE);
5224
5225 //AudioCtlUninit();
5226 AudioSetAudioInSource (CC_AUDIO_IN_SOURCE_HDMI);
5227 SetDAC_Digital_PlayBack_Volume(255);
5228 AudioSetAudioSourceType (AUDIO_MPEG_SOURCE);
5229 UnInitTvAudio();
5230 SetAudioVolumeCompensationVal(0);
5231 SetAudioMasterVolume(GetAudioMasterVolume());
5232 UnInitSetTvAudioCard();
5233
5234 SetAudioMuteForTv(oldMuteStatus);
5235}
5236
5237char *CTv::GetMainVolLutTableExtraName() {
5238 return mMainVolLutTableExtraName;
5239}
5240
5241//audio
5242int CTv::SetAudioMuteForSystem(int muteOrUnmute) {
5243 int ret = 0;
5244 LOGD("SetAudioMuteForSystem sysMuteStats=%d, tvMuteStatus=%d, toMute=%d", mAudioMuteStatusForSystem, mAudioMuteStatusForTv, muteOrUnmute);
5245 mAudioMuteStatusForSystem = muteOrUnmute;
5246 ret |= SetDacMute(mAudioMuteStatusForSystem, CC_DAC_MUTE_TYPE_EXTERNAL);
5247 ret |= SetAudioI2sMute(mAudioMuteStatusForSystem | mAudioMuteStatusForTv);
5248 return ret;
5249}
5250
5251int CTv::GetAudioMuteForSystem() {
5252 return mAudioMuteStatusForSystem;
5253}
5254
5255int CTv::SetAudioMuteForTv(int muteOrUnmute) {
5256 int ret = 0;
5257 mAudioMuteStatusForTv = muteOrUnmute;
5258 LOGD("SetAudioMuteForTv sysMuteStats=%d, tvMuteStatus=%d, toMute=%d", mAudioMuteStatusForSystem, mAudioMuteStatusForTv, muteOrUnmute);
5259 ret |= SetDacMute(mAudioMuteStatusForSystem | mAudioMuteStatusForTv, CC_DAC_MUTE_TYPE_EXTERNAL | CC_DAC_MUTE_TYPE_INTERNAL);
5260 ret |= SetAudioI2sMute(mAudioMuteStatusForTv);
5261 return ret;
5262}
5263
5264int CTv::GetAudioMuteForTv() {
5265 return mAudioMuteStatusForTv;
5266}
5267
5268int CTv::GetDbxTvMode(int *mode, int *son_value, int *vol_value, int *sur_value) {
5269 *mode = 0;
5270 return SSMReadAudioDbxTvValue(son_value, vol_value, sur_value);
5271}
5272
5273int CTv::SetAudioSPDIFSwitch(int tmp_val) {
5274 int muteStatus = CC_AUDIO_UNMUTE;
5275
5276 SaveCurAudioSPDIFSwitch(tmp_val);
5277
5278 if (tmp_val == CC_SWITCH_OFF /*|| mAudioMuteStatusForSystem == CC_AUDIO_MUTE || mAudioMuteStatusForTv == CC_AUDIO_MUTE*/) {
5279 muteStatus = CC_AUDIO_MUTE;
5280 } else {
5281 muteStatus = CC_AUDIO_UNMUTE;
5282 }
5283
5284 SetAudioSPDIFMute(muteStatus);
5285 return 0;
5286}
5287
5288int CTv::AudioHandleHeadsetPlugIn() {
5289 return 0;
5290}
5291
5292int CTv::AudioHandleHeadsetPullOut() {
5293 return 0;
5294}
5295
5296int CTv::Tv_SetDRC_OnOff(int on_off) {
5297 on_off = on_off;
5298 return 0;
5299}
5300
5301int CTv::Tv_GetDRC_OnOff(void) {
5302 return 0;
5303}
5304
5305void CTv::updateSubtitle(int pic_width, int pic_height) {
5306 TvEvent::SubtitleEvent ev;
5307 ev.pic_width = pic_width;
5308 ev.pic_height = pic_height;
5309 sendTvEvent(ev);
5310}
5311
5312int CTv::setSubtitleBuffer(char *share_mem) {
5313 mSubtitle.setBuffer(share_mem);
5314 return 0;
5315}
5316
5317int CTv::initSubtitle(int bitmapWidth, int bitmapHeight) {
5318 return mSubtitle.sub_init(bitmapWidth, bitmapHeight);
5319}
5320
5321int CTv::lockSubtitle() {
5322 return mSubtitle.sub_lock();
5323}
5324
5325int CTv::unlockSubtitle() {
5326 return mSubtitle.sub_unlock();
5327}
5328
5329int CTv::getSubSwitchStatus() {
5330 return mSubtitle.sub_switch_status();
5331}
5332
5333int CTv::startSubtitle(int dmx_id, int pid, int page_id, int anc_page_id) {
5334 return mSubtitle.sub_start_dvb_sub(dmx_id, pid, page_id, anc_page_id);
5335}
5336
5337int CTv::stopSubtitle() {
5338 return mSubtitle.sub_stop_dvb_sub();
5339}
5340
5341//--------------------------------------------------
5342
5343
5344//Audio Mute
5345int CTv::SetAudioI2sMute(int muteStatus) {
5346 int vol = 256;
5347 if (muteStatus == CC_AUDIO_MUTE) {
5348 vol = 0;
5349 } else {
5350 vol = 256;
5351 }
5352 CFile::setFileAttrValue("/sys/class/amaudio2/aml_direct_right_gain", vol);
5353 CFile::setFileAttrValue("/sys/class/amaudio2/aml_direct_left_gain", vol);
5354 return 0;
5355}
5356
5357int CTv::SetDacMute(int muteStatus, int mute_type) {
5358 int tmp_ret = 0;
5359 if (mute_type & CC_DAC_MUTE_TYPE_INTERNAL) {
5360 tmp_ret |= mAudioAlsa.SetInternalDacMute(muteStatus);
5361 }
5362
5363 if (mute_type & CC_DAC_MUTE_TYPE_EXTERNAL) {
5364 int tmp_ret = 0, set_val = 0;
5365 int aud_arch_type = GetAudioArchitectureTypeCFG();
5366
5367 if (aud_arch_type == CC_DAC_G9TV_EXTERNAL_DAC_ON_BOARD) {
5368 if (muteStatus == CC_AUDIO_MUTE) {
5369 set_val = CC_MUTE_ON;
5370 } else if (muteStatus == CC_AUDIO_UNMUTE) {
5371 set_val = CC_MUTE_OFF;
5372 } else {
5373 return -1;
5374 }
5375
5376 mAudioAlsa.SetExternalDacChannelSwitch(1, set_val);
5377 mAudioAlsa.SetExternalDacChannelSwitch(2, set_val);
5378 //showboz: can disable it
5379 mAudioAlsa.SetExternalDacChannelSwitch(3, set_val);
5380 } else if (aud_arch_type == CC_DAC_G9TV_EXTERNAL_DAC_OFF_BOARD_FBC) {
5381 SendCmdToOffBoardFBCExternalDac(AUDIO_CMD_SET_MUTE, muteStatus);
5382 } else if (aud_arch_type == CC_DAC_G9TV_EXTERNAL_DAC_CUSTOMER_LIB) {
5383 mCustomerCtrl.SetMute((muteStatus == CC_AUDIO_MUTE) ? CAudioCustomerCtrl::MUTE : CAudioCustomerCtrl::UNMUTE);
5384 } else if (aud_arch_type == CC_DAC_G9TV_EXTERNAL_DAC_DIGITAL) {
5385 mAudioAlsa.SetDigitalMute(muteStatus);
5386 }
5387 mAudioAlsa.setAudioPcmPlaybackMute(muteStatus);
5388 }
5389 return tmp_ret;
5390}
5391
5392int CTv::SetAudioAVOutMute(int muteStatus) {
5393 SSMSaveAudioAVOutMuteVal(muteStatus);
5394 return mAudioAlsa.SetInternalDacMute(muteStatus);
5395}
5396
5397int CTv::GetAudioAVOutMute() {
5398 int8_t tmp_ch = 0;
5399 SSMReadAudioAVOutMuteVal(&tmp_ch);
5400 return tmp_ch;
5401}
5402
5403int CTv::SetAudioSPDIFMute(int muteStatus) {
5404 if (GetCurAudioSPDIFSwitch() == CC_SWITCH_OFF) {
5405 muteStatus = CC_AUDIO_MUTE;
5406 }
5407
5408 SSMSaveAudioSPIDFMuteVal(muteStatus);
5409 return mAudioAlsa.SetSPDIFMute(muteStatus);
5410}
5411
5412int CTv::GetAudioSPDIFMute() {
5413 int8_t tmp_ch = 0;
5414 SSMReadAudioSPIDFMuteVal(&tmp_ch);
5415 return tmp_ch;
5416}
5417
5418int CTv::GetCurAudioSPDIFSwitch() {
5419 return mCurAudioSPDIFSwitch;
5420}
5421
5422int CTv::SaveCurAudioSPDIFSwitch(int tmp_val) {
5423 int8_t tmp_ch = 0;
5424
5425 mCurAudioSPDIFSwitch = tmp_val;
5426 tmp_ch = tmp_val;
5427 SSMSaveAudioSPDIFSwitchVal(tmp_ch);
5428
5429 return mCurAudioSPDIFSwitch;
5430}
5431
5432int CTv::LoadCurAudioSPDIFSwitch() {
5433 int8_t tmp_ch = 0;
5434 SSMReadAudioSPDIFSwitchVal(&tmp_ch);
5435 mCurAudioSPDIFSwitch = tmp_ch;
5436 if (mCurAudioSPDIFSwitch != CC_SWITCH_ON
5437 && mCurAudioSPDIFSwitch != CC_SWITCH_OFF) {
5438 SaveCurAudioSPDIFSwitch (CC_SWITCH_ON);
5439 }
5440 return mCurAudioSPDIFSwitch;
5441}
5442
5443//Audio SPDIF Mode
5444int CTv::SetAudioSPDIFMode(int tmp_val) {
5445 LOGD("%s : tmp_val = %d\n", __FUNCTION__, tmp_val);
5446 mCurAudioSPDIFMode = tmp_val;
5447
5448 SetSPDIFMode(mCurAudioSPDIFMode);
5449 return 0;
5450}
5451
5452int CTv::GetCurAudioSPDIFMode() {
5453 return mCurAudioSPDIFMode;
5454}
5455
5456int CTv::SaveCurAudioSPDIFMode(int tmp_val) {
5457 int8_t tmp_ch = 0;
5458
5459 mCurAudioSPDIFMode = tmp_val;
5460 tmp_ch = tmp_val;
5461 SSMSaveAudioSPDIFModeVal(tmp_ch);
5462
5463 return mCurAudioSPDIFMode;
5464}
5465
5466int CTv::LoadCurAudioSPDIFMode() {
5467 int8_t tmp_ch = 0;
5468 SSMReadAudioSPDIFModeVal(&tmp_ch);
5469 mCurAudioSPDIFMode = tmp_ch;
5470 if (mCurAudioSPDIFMode != CC_SPDIF_MODE_PCM
5471 && mCurAudioSPDIFMode != CC_SPDIF_MODE_RAW) {
5472 SaveCurAudioSPDIFMode (CC_SPDIF_MODE_PCM);
5473 }
5474 return mCurAudioSPDIFMode;
5475}
5476
5477int CTv::SetAudioMasterVolume(int tmp_vol) {
5478 mCustomAudioMasterVolume = tmp_vol;
5479
5480 //Volume Compensation
5481 tmp_vol += mVolumeCompensationVal;
5482
5483 if (tmp_vol > CC_MAX_SOUND_VOL) {
5484 tmp_vol = CC_MAX_SOUND_VOL;
5485 }
5486
5487 if (tmp_vol < CC_MIN_SOUND_VOL) {
5488 tmp_vol = CC_MIN_SOUND_VOL;
5489 }
5490
5491 int tmp_ret = 0;
5492 int aud_arch_type = GetAudioArchitectureTypeCFG();
5493
5494 if (aud_arch_type == CC_DAC_G9TV_INTERNAL_DAC) {
5495 tmp_ret = mAudioAlsa.SetInternalDacMainVolume(tmp_vol);
5496 } else if (aud_arch_type == CC_DAC_G9TV_EXTERNAL_DAC_ON_BOARD) {
5497 int digit_vol = 0;
5498 int vol_gain_val = 0;
5499 int vol_buf[2] = {0, 0};
5500
5501 //handle l&r channel volume for balance
5502 mAudioAlsa.CalculateBalanceVol(255, mMainVolumeBalanceVal, vol_buf);
5503
5504 tmp_ret |= mAudioAlsa.SetExternalDacChannelVolume(1, vol_buf[0]);
5505 tmp_ret |= mAudioAlsa.SetExternalDacChannelVolume(2, vol_buf[1]);
5506
5507 //handle master channel volume
5508 digit_vol = mAudioAlsa.TransVolumeBarVolToDigitalVol(mAudioAlsa.GetMainVolDigitLutBuf(), tmp_vol);
5509
5510 vol_gain_val = mAudioAlsa.GetMainVolumeGain();
5511 digit_vol += vol_gain_val;
5512 tmp_ret |= mAudioAlsa.SetExternalDacChannelVolume(0, digit_vol);
5513 } else if (aud_arch_type == CC_DAC_G9TV_EXTERNAL_DAC_OFF_BOARD_FBC) {
5514 tmp_ret = SendCmdToOffBoardFBCExternalDac(AUDIO_CMD_SET_VOLUME_BAR, tmp_vol);
5515 } else if (aud_arch_type == CC_DAC_G9TV_EXTERNAL_DAC_CUSTOMER_LIB) {
5516 tmp_ret = mCustomerCtrl.SetVolumeBar(tmp_vol);
5517 } else if (aud_arch_type == CC_DAC_G9TV_EXTERNAL_DAC_DIGITAL) {
5518 int vol_buf[2] = {0, 0};
5519 mAudioAlsa.CalculateBalanceVol(tmp_vol, mMainVolumeBalanceVal, vol_buf);
5520 tmp_ret = mAudioAlsa.SetDigitalMainVolume(vol_buf[0], vol_buf[1]);
5521 }
5522 if ( Get2d4gHeadsetEnable() == 1 ) {
5523 setAudioPcmPlaybackVolume(tmp_vol);
5524 }
5525 return 0;
5526}
5527
5528int CTv::GetAudioMasterVolume() {
5529 return mCustomAudioMasterVolume;
5530}
5531
5532int CTv::GetCurAudioMasterVolume() {
5533 return mCurAudioMasterVolume;
5534}
5535
5536int CTv::SaveCurAudioMasterVolume(int tmp_vol) {
5537 mCurAudioMasterVolume = tmp_vol;
5538 SSMSaveAudioMasterVolume(tmp_vol);
5539 return mCurAudioMasterVolume;
5540}
5541
5542int CTv::LoadCurAudioMasterVolume() {
5543 int8_t tmp_ch = 0;
5544 SSMReadAudioMasterVolume(&tmp_ch);
5545 mCurAudioMasterVolume = tmp_ch;
5546 if (mCurAudioMasterVolume < CC_MIN_SOUND_VOL
5547 || mCurAudioMasterVolume > CC_MAX_SOUND_VOL) {
5548 SaveCurAudioMasterVolume (CC_DEF_SOUND_VOL);
5549 }
5550 mCustomAudioMasterVolume = mCurAudioMasterVolume;
5551
5552 return mCurAudioMasterVolume;
5553}
5554
5555int CTv::SetAudioBalance(int tmp_val) {
5556 mCustomAudioBalance = tmp_val;
5557
5558 int aud_arch_type = GetAudioArchitectureTypeCFG();
5559
5560 mMainVolumeBalanceVal = tmp_val;
5561
5562 if (aud_arch_type == CC_DAC_G9TV_EXTERNAL_DAC_OFF_BOARD_FBC) {
5563 SendCmdToOffBoardFBCExternalDac(AUDIO_CMD_SET_BALANCE, mMainVolumeBalanceVal);
5564 } else if (aud_arch_type == CC_DAC_G9TV_EXTERNAL_DAC_CUSTOMER_LIB) {
5565 mCustomerCtrl.SetBlance(mMainVolumeBalanceVal);
5566 } else {
5567 SetAudioMasterVolume(GetAudioMasterVolume());
5568 }
5569 return 0;
5570}
5571
5572int CTv::GetAudioBalance() {
5573 return mCustomAudioBalance;
5574}
5575
5576int CTv::GetCurAudioBalance() {
5577 return mCurAudioBalance;
5578}
5579
5580int CTv::SaveCurAudioBalance(int tmp_val) {
5581 int8_t tmp_ch = 0;
5582
5583 mCurAudioBalance = tmp_val;
5584 tmp_ch = tmp_val;
5585 SSMSaveAudioBalanceVal(tmp_ch);
5586
5587 return mCurAudioBalance;
5588}
5589
5590int CTv::LoadCurAudioBalance() {
5591 int8_t tmp_ch = 0;
5592 SSMReadAudioBalanceVal(&tmp_ch);
5593 mCurAudioBalance = tmp_ch;
5594 if (mCurAudioBalance < CC_MIN_SOUND_BALANCE_VAL
5595 || mCurAudioBalance > CC_MAX_SOUND_BALANCE_VAL) {
5596 SaveCurAudioBalance (CC_DEF_SOUND_BALANCE_VAL);
5597 }
5598
5599 mCustomAudioBalance = mCurAudioBalance;
5600
5601 return mCurAudioBalance;
5602}
5603
5604int CTv::SetAudioVolumeCompensationVal(int tmp_vol_comp_val) {
5605 mVolumeCompensationVal = tmp_vol_comp_val;
5606 LOGD("%s, new vol comp value = %d.\n", __FUNCTION__, tmp_vol_comp_val);
5607 return mVolumeCompensationVal;
5608}
5609
5610int CTv::SetAudioSupperBassVolume(int tmp_vol) {
5611 mCustomAudioSupperBassVolume = tmp_vol;
5612
5613 int aud_arch_type = GetAudioArchitectureTypeCFG();
5614 int tmp_ret = 0;
5615
5616 if (aud_arch_type == CC_DAC_G9TV_INTERNAL_DAC) {
5617 return 0;
5618 } else if (aud_arch_type == CC_DAC_G9TV_EXTERNAL_DAC_ON_BOARD) {
5619 int digit_vol = 0;
5620 int vol_gain_val = 0;
5621
5622 digit_vol = mAudioAlsa.TransVolumeBarVolToDigitalVol(mAudioAlsa.GetMainVolDigitLutBuf(), tmp_vol);
5623
5624 vol_gain_val = mAudioAlsa.GetSupperBassVolumeGain();
5625 digit_vol += vol_gain_val;
5626 if (digit_vol < CC_MIN_DAC_SUB_WOOFER_VOLUME) {
5627 digit_vol = CC_MIN_DAC_SUB_WOOFER_VOLUME;
5628 } else if (digit_vol > CC_MAX_DAC_SUB_WOOFER_VOLUME) {
5629 digit_vol = CC_MAX_DAC_SUB_WOOFER_VOLUME;
5630 }
5631
5632 tmp_ret = mAudioAlsa.SetExternalDacChannelVolume(3, digit_vol);
5633 } else if (aud_arch_type == CC_DAC_G9TV_EXTERNAL_DAC_OFF_BOARD_FBC) {
5634 tmp_ret = SendCmdToOffBoardFBCExternalDac(AUDIO_CMD_SET_SUBCHANNEL_VOLUME, tmp_vol);
5635 }
5636
5637 return tmp_ret;
5638}
5639
5640int CTv::GetAudioSupperBassVolume() {
5641 return mCustomAudioSupperBassVolume;
5642}
5643
5644int CTv::GetCurAudioSupperBassVolume() {
5645 return mCurAudioSupperBassVolume;
5646}
5647
5648int CTv::SaveCurAudioSupperBassVolume(int tmp_vol) {
5649 int8_t tmp_ch = 0;
5650
5651 mCurAudioSupperBassVolume = tmp_vol;
5652 tmp_ch = tmp_vol;
5653 SSMSaveAudioSupperBassVolume(tmp_ch);
5654
5655 return mCurAudioSupperBassVolume;
5656}
5657
5658int CTv::LoadCurAudioSupperBassVolume() {
5659 int8_t tmp_ch = 0;
5660 SSMReadAudioSupperBassVolume(&tmp_ch);
5661 mCurAudioSupperBassVolume = tmp_ch;
5662 if (mCurAudioSupperBassVolume < CC_MIN_SUPPERBASS_VOL
5663 || mCurAudioSupperBassVolume > CC_MAX_SUPPERBASS_VOL) {
5664 SaveCurAudioSupperBassVolume (CC_DEF_SUPPERBASS_VOL);
5665 }
5666 mCustomAudioSupperBassVolume = mCurAudioSupperBassVolume;
5667
5668 return mCurAudioSupperBassVolume;
5669}
5670
5671int CTv::SetAudioSupperBassSwitch(int tmp_val) {
5672 mCustomAudioSupperBassSwitch = tmp_val;
5673
5674 if (GetAudioSupperBassSwitch() == CC_SWITCH_OFF) {
5675 return SetAudioSupperBassVolume(CC_MIN_SUPPERBASS_VOL);
5676 }
5677
5678 return SetAudioSupperBassVolume(GetAudioSupperBassVolume());
5679}
5680
5681int CTv::GetAudioSupperBassSwitch() {
5682 if (GetAudioSupperBassSwitchDisableCFG() != 0) {
5683 return CC_SWITCH_ON;
5684 }
5685
5686 return mCustomAudioSupperBassSwitch;
5687}
5688
5689int CTv::GetCurAudioSupperBassSwitch() {
5690 if (GetAudioSupperBassSwitchDisableCFG() != 0) {
5691 return CC_SWITCH_ON;
5692 }
5693
5694 return mCurAudioSupperBassSwitch;
5695}
5696
5697int CTv::SaveCurAudioSupperBassSwitch(int tmp_val) {
5698 int8_t tmp_ch = 0;
5699
5700 mCurAudioSupperBassSwitch = tmp_val;
5701 tmp_ch = tmp_val;
5702 SSMSaveAudioSupperBassSwitch(tmp_ch);
5703
5704 SetSupperBassSRSSpeakerSize();
5705
5706 return mCurAudioSupperBassSwitch;
5707}
5708
5709int CTv::LoadCurAudioSupperBassSwitch() {
5710 int8_t tmp_ch = 0;
5711 SSMReadAudioSupperBassSwitch(&tmp_ch);
5712 mCurAudioSupperBassSwitch = tmp_ch;
5713 if (mCurAudioSupperBassSwitch != CC_SWITCH_ON
5714 && mCurAudioSupperBassSwitch != CC_SWITCH_OFF) {
5715 SaveCurAudioSupperBassSwitch (CC_SWITCH_OFF);
5716 }
5717 mCustomAudioSupperBassSwitch = mCurAudioSupperBassSwitch;
5718
5719 return mCurAudioSupperBassSwitch;
5720}
5721
5722void CTv::SetSupperBassSRSSpeakerSize() {
5723 int tmp_speakersize = -1;
5724
5725 if (GetAudioSrsTruBass() == CC_SWITCH_ON) {
5726 tmp_speakersize = GetAudioSRSSupperBassTrubassSpeakerSizeCfg();
5727 if (tmp_speakersize >= 0) {
5728 mAudioEffect.SetSrsTrubassSpeakerSize(tmp_speakersize);
5729 }
5730 }
5731}
5732
5733int CTv::SetAudioSRSSurround(int tmp_val) {
5734 mCustomAudioSRSSurround = tmp_val;
5735
5736 RefreshSrsEffectAndDacGain();
5737 return 0;
5738}
5739
5740int CTv::GetAudioSRSSurround() {
5741 return mCustomAudioSRSSurround;
5742}
5743
5744int CTv::GetCurAudioSRSSurround() {
5745 return mCurAudioSRSSurround;
5746}
5747
5748int CTv::SaveCurAudioSrsSurround(int tmp_val) {
5749 int8_t tmp_ch = 0;
5750
5751 mCurAudioSRSSurround = tmp_val;
5752 tmp_ch = tmp_val;
5753 SSMSaveAudioSRSSurroundSwitch(tmp_ch);
5754
5755 return mCurAudioSRSSurround;
5756}
5757
5758int CTv::LoadCurAudioSrsSurround() {
5759 int8_t tmp_ch = 0;
5760
5761 SSMReadAudioSRSSurroundSwitch(&tmp_ch);
5762 mCurAudioSRSSurround = tmp_ch;
5763 if (mCurAudioSRSSurround != CC_SWITCH_ON
5764 && mCurAudioSRSSurround != CC_SWITCH_OFF) {
5765 SaveCurAudioSrsSurround (CC_SWITCH_OFF);
5766 }
5767 mCustomAudioSRSSurround = mCurAudioSRSSurround;
5768
5769 return mCurAudioSRSSurround;
5770}
5771
5772int CTv::SetAudioSrsDialogClarity(int tmp_val) {
5773 mCustomAudioSrsDialogClarity = tmp_val;
5774 RefreshSrsEffectAndDacGain();
5775 return 0;
5776}
5777
5778int CTv::GetAudioSrsDialogClarity() {
5779 return mCustomAudioSrsDialogClarity;
5780}
5781
5782int CTv::GetCurAudioSrsDialogClarity() {
5783 return mCurAudioSrsDialogClarity;
5784}
5785
5786int CTv::SaveCurAudioSrsDialogClarity(int tmp_val) {
5787 int8_t tmp_ch = 0;
5788
5789 mCurAudioSrsDialogClarity = tmp_val;
5790 tmp_ch = tmp_val;
5791 SSMSaveAudioSRSDialogClaritySwitch(tmp_ch);
5792
5793 return mCurAudioSrsDialogClarity;
5794}
5795
5796int CTv::LoadCurAudioSrsDialogClarity() {
5797 int8_t tmp_ch = 0;
5798
5799 SSMReadAudioSRSDialogClaritySwitch(&tmp_ch);
5800 mCurAudioSrsDialogClarity = tmp_ch;
5801 if (mCurAudioSrsDialogClarity != CC_SWITCH_ON
5802 && mCurAudioSrsDialogClarity != CC_SWITCH_OFF) {
5803 SaveCurAudioSrsDialogClarity (CC_SWITCH_OFF);
5804 }
5805 mCustomAudioSrsDialogClarity = mCurAudioSrsDialogClarity;
5806
5807 return mCurAudioSrsDialogClarity;
5808}
5809
5810int CTv::SetAudioSrsTruBass(int tmp_val) {
5811 mCustomAudioSrsTruBass = tmp_val;
5812 RefreshSrsEffectAndDacGain();
5813 return 0;
5814}
5815
5816int CTv::GetAudioSrsTruBass() {
5817 return mCustomAudioSrsTruBass;
5818}
5819
5820int CTv::GetCurAudioSrsTruBass() {
5821 return mCurAudioSrsTruBass;
5822}
5823
5824int CTv::SaveCurAudioSrsTruBass(int tmp_val) {
5825 int8_t tmp_ch = 0;
5826
5827 mCurAudioSrsTruBass = tmp_val;
5828 tmp_ch = tmp_val;
5829 SSMSaveAudioSRSTruBassSwitch(tmp_ch);
5830
5831 return mCurAudioSrsTruBass;
5832}
5833
5834int CTv::LoadCurAudioSrsTruBass() {
5835 int8_t tmp_ch = 0;
5836
5837 SSMReadAudioSRSTruBassSwitch(&tmp_ch);
5838 mCurAudioSrsTruBass = tmp_ch;
5839 if (mCurAudioSrsTruBass != CC_SWITCH_ON
5840 && mCurAudioSrsTruBass != CC_SWITCH_OFF) {
5841 SaveCurAudioSrsTruBass (CC_SWITCH_OFF);
5842 }
5843 mCustomAudioSrsTruBass = mCurAudioSrsTruBass;
5844
5845 return mCurAudioSrsTruBass;
5846}
5847
5848void CTv::RefreshSrsEffectAndDacGain() {
5849 int tmp_gain_val = 0;
5850 int surround_switch = CC_SWITCH_OFF;
5851 int trubass_switch = CC_SWITCH_OFF;
5852 int dialogclarity_switch = CC_SWITCH_OFF;
5853 trubass_switch = GetAudioSrsTruBass();
5854 dialogclarity_switch = GetAudioSrsDialogClarity();
5855 surround_switch = GetAudioSRSSurround();
5856
5857 if (GetAudioSRSSourroundEnableCFG() == 0) {
5858 return;
5859 }
5860
5861 if (surround_switch == CC_SWITCH_ON) {
5862 mAudioEffect.SetSrsSurroundSwitch(CC_SWITCH_ON);
5863 tmp_gain_val = GetAudioSRSGainCfg("audio.srs.sourround.gain", 50);
5864 mAudioEffect.SetSrsSurroundGain(tmp_gain_val);
5865
5866 int input_gain_val = GetAudioSRSGainCfg("audio.srs.input.gain", 50);
5867 int out_gain_val = GetAudioSRSGainCfg("audio.srs.output.gain", 50);
5868 mAudioEffect.SetSrsInputOutputGain(input_gain_val, out_gain_val);
5869
5870 if (trubass_switch == CC_SWITCH_ON
5871 && dialogclarity_switch == CC_SWITCH_OFF) {
5872
5873 mAudioEffect.SetSrsTruBassSwitch (CC_SWITCH_ON);
5874 tmp_gain_val = GetAudioSRSGainCfg("audio.srs.trubass.gain", 50);
5875 mAudioEffect.SetSrsTruBassGain(tmp_gain_val);
5876 tmp_gain_val = GetAudioSRSGainCfg("audio.srs.trubass.speakersize", 2);
5877 mAudioEffect.SetSrsTrubassSpeakerSize(tmp_gain_val);
5878
5879 mAudioEffect.SetSrsDialogClaritySwitch (CC_SWITCH_OFF);
5880
5881 } else if (trubass_switch == CC_SWITCH_OFF
5882 && dialogclarity_switch == CC_SWITCH_ON) {
5883
5884 mAudioEffect.SetSrsDialogClaritySwitch (CC_SWITCH_ON);
5885 tmp_gain_val = GetAudioSRSGainCfg("audio.srs.dialogclarity.gain", 30);
5886 mAudioEffect.SetSrsDialogClarityGain(tmp_gain_val);
5887 tmp_gain_val = GetAudioSRSGainCfg("audio.srs.definition.gain", 20);
5888 mAudioEffect.SetSrsDefinitionGain(tmp_gain_val);
5889
5890 mAudioEffect.SetSrsTruBassSwitch (CC_SWITCH_OFF);
5891
5892 } else if (trubass_switch == CC_SWITCH_ON
5893 && dialogclarity_switch == CC_SWITCH_ON) {
5894
5895 mAudioEffect.SetSrsTruBassSwitch (CC_SWITCH_ON);
5896 tmp_gain_val = GetAudioSRSGainCfg("audio.srs.trubass.gain", 50);
5897 mAudioEffect.SetSrsTruBassGain(tmp_gain_val);
5898 tmp_gain_val = GetAudioSRSGainCfg("audio.srs.trubass.speakersize", 2);
5899 mAudioEffect.SetSrsTrubassSpeakerSize(tmp_gain_val);
5900
5901 mAudioEffect.SetSrsDialogClaritySwitch(CC_SWITCH_ON);
5902 tmp_gain_val = GetAudioSRSGainCfg("audio.srs.dialogclarity.gain", 30);
5903 mAudioEffect.SetSrsDialogClarityGain(tmp_gain_val);
5904 tmp_gain_val = GetAudioSRSGainCfg("audio.srs.definition.gain", 20);
5905 mAudioEffect.SetSrsDefinitionGain(tmp_gain_val);
5906
5907 } else if (trubass_switch == CC_SWITCH_OFF
5908 && dialogclarity_switch == CC_SWITCH_OFF) {
5909 mAudioEffect.SetSrsTruBassSwitch (CC_SWITCH_OFF);
5910 mAudioEffect.SetSrsDialogClaritySwitch(CC_SWITCH_OFF);
5911 }
5912 SetSupperBassSRSSpeakerSize();
5913 } else {
5914 mAudioEffect.SetSrsSurroundSwitch (CC_SWITCH_OFF);
5915 mAudioEffect.SetSrsTruBassSwitch(CC_SWITCH_OFF);
5916 mAudioEffect.SetSrsDialogClaritySwitch(CC_SWITCH_OFF);
5917 }
5918 //Refesh DAC gain
5919 int main_gain_val = 0;
5920 if (surround_switch == CC_SWITCH_ON) {
5921 main_gain_val = GetAudioEffectAmplifierGainCfg("audio.srs.sourround.ampmaster.gain", 6, 24);
5922 if (dialogclarity_switch == CC_SWITCH_ON
5923 && trubass_switch == CC_SWITCH_OFF) {
5924 main_gain_val = GetAudioEffectAmplifierGainCfg("audio.srs.dialogclarity.ampmaster.gain", 6, 24);
5925 } else if (dialogclarity_switch == CC_SWITCH_OFF
5926 && trubass_switch == CC_SWITCH_ON) {
5927 main_gain_val = GetAudioEffectAmplifierGainCfg("audio.srs.trubass.ampmaster.gain", 6, 24);
5928 } else if (dialogclarity_switch == CC_SWITCH_ON
5929 && trubass_switch == CC_SWITCH_ON) {
5930 main_gain_val = GetAudioEffectAmplifierGainCfg("audio.srs.trubass.dialogclarity.ampmaster.gain", 6, 24);
5931 }
5932 }
5933 mAudioAlsa.SetMainVolumeGain(main_gain_val);
5934}
5935
5936int CTv::SetAudioBassVolume(int tmp_vol) {
5937 int nMinBassVol = 0, nMaxBassVol = 0;
5938
5939 nMinBassVol = GetBassUIMinGainVal();
5940 nMaxBassVol = GetBassUIMaxGainVal();
5941
5942 if (tmp_vol < nMinBassVol || tmp_vol > nMaxBassVol) {
5943 tmp_vol = (nMaxBassVol + nMinBassVol) / 2;
5944 }
5945
5946 mCustomAudioBassVolume = tmp_vol;
5947 tmp_vol = MappingTrebleBassAndEqualizer(GetAudioBassVolume(), 0,
5948 nMinBassVol, nMaxBassVol);
5949 return SetSpecialIndexEQGain(CC_EQ_BASS_IND, tmp_vol);
5950}
5951
5952int CTv::GetAudioBassVolume() {
5953 return mCustomAudioBassVolume;
5954}
5955
5956int CTv::GetCurAudioBassVolume() {
5957 return mCurAudioBassVolume;
5958}
5959
5960int CTv::SaveCurAudioBassVolume(int tmp_vol) {
5961 int nMinBassVol = 0, nMaxBassVol = 0;
5962
5963 nMinBassVol = GetBassUIMinGainVal();
5964 nMaxBassVol = GetBassUIMaxGainVal();
5965
5966 if (tmp_vol < nMinBassVol || tmp_vol > nMaxBassVol) {
5967 tmp_vol = (nMaxBassVol + nMinBassVol) / 2;
5968 }
5969
5970 RealSaveCurAudioBassVolume(tmp_vol, 1);
5971
5972 tmp_vol = MappingTrebleBassAndEqualizer(GetCurAudioBassVolume(), 0,
5973 nMinBassVol, nMaxBassVol);
5974 return SaveSpecialIndexEQGain(CC_EQ_BASS_IND, tmp_vol);
5975}
5976
5977int CTv::RealSaveCurAudioBassVolume(int tmp_vol, int sound_mode_judge) {
5978 int8_t tmp_ch = 0;
5979 mCurAudioBassVolume = tmp_vol;
5980 tmp_ch = tmp_vol;
5981 SSMSaveAudioBassVolume(tmp_ch);
5982
5983 if (sound_mode_judge == 1) {
5984 if (GetAudioSoundMode() != CC_SOUND_MODE_USER) {
5985 SaveCurAudioSoundMode (CC_SOUND_MODE_USER);
5986 mCustomAudioSoundMode = mCurAudioSoundMode;
5987 }
5988 }
5989 return mCurAudioBassVolume;
5990}
5991
5992int CTv::LoadCurAudioBassVolume() {
5993 int nMinBassVol = 0, nMaxBassVol = 0;
5994 int8_t tmp_ch = 0;
5995
5996 nMinBassVol = GetBassUIMinGainVal();
5997 nMaxBassVol = GetBassUIMaxGainVal();
5998
5999 SSMReadAudioBassVolume(&tmp_ch);
6000 mCurAudioBassVolume = tmp_ch;
6001 if (mCurAudioBassVolume < nMinBassVol
6002 || mCurAudioBassVolume > nMaxBassVol) {
6003 RealSaveCurAudioBassVolume((nMaxBassVol + nMinBassVol) / 2, 0);
6004 }
6005
6006 mCustomAudioBassVolume = mCurAudioBassVolume;
6007 return mCurAudioBassVolume;
6008}
6009
6010int CTv::SetAudioTrebleVolume(int tmp_vol) {
6011 int nMinTrebleVol = 0, nMaxTrebleVol = 0;
6012
6013 nMinTrebleVol = GetTrebleUIMinGainVal();
6014 nMaxTrebleVol = GetTrebleUIMaxGainVal();
6015
6016 if (tmp_vol < nMinTrebleVol || tmp_vol > nMaxTrebleVol) {
6017 tmp_vol = (nMaxTrebleVol + nMinTrebleVol) / 2;
6018 }
6019
6020 mCustomAudioTrebleVolume = tmp_vol;
6021
6022 tmp_vol = MappingTrebleBassAndEqualizer(GetAudioTrebleVolume(), 0,
6023 nMinTrebleVol, nMaxTrebleVol);
6024 return SetSpecialIndexEQGain(CC_EQ_TREBLE_IND, tmp_vol);
6025}
6026
6027int CTv::GetAudioTrebleVolume() {
6028 return mCustomAudioTrebleVolume;
6029}
6030
6031int CTv::GetCurAudioTrebleVolume() {
6032 return mCurAudioTrebleVolume;
6033}
6034
6035int CTv::SaveCurAudioTrebleVolume(int tmp_vol) {
6036 int nMinTrebleVol = 0, nMaxTrebleVol = 0;
6037
6038 nMinTrebleVol = GetTrebleUIMinGainVal();
6039 nMaxTrebleVol = GetTrebleUIMaxGainVal();
6040
6041 if (tmp_vol < nMinTrebleVol || tmp_vol > nMaxTrebleVol) {
6042 tmp_vol = (nMaxTrebleVol + nMinTrebleVol) / 2;
6043 }
6044
6045 RealSaveCurAudioTrebleVolume(tmp_vol, 1);
6046
6047 tmp_vol = MappingTrebleBassAndEqualizer(GetCurAudioTrebleVolume(), 0,
6048 nMinTrebleVol, nMaxTrebleVol);
6049 return SaveSpecialIndexEQGain(CC_EQ_TREBLE_IND, tmp_vol);
6050}
6051
6052int CTv::RealSaveCurAudioTrebleVolume(int tmp_vol, int sound_mode_judge) {
6053 int8_t tmp_ch = 0;
6054 mCurAudioTrebleVolume = tmp_vol;
6055 tmp_ch = tmp_vol;
6056 SSMSaveAudioTrebleVolume(tmp_ch);
6057
6058 if (sound_mode_judge == 1) {
6059 if (GetAudioSoundMode() != CC_SOUND_MODE_USER) {
6060 SaveCurAudioSoundMode (CC_SOUND_MODE_USER);
6061 mCustomAudioSoundMode = mCurAudioSoundMode;
6062 }
6063 }
6064
6065 return mCurAudioTrebleVolume;
6066}
6067
6068int CTv::LoadCurAudioTrebleVolume() {
6069 int nMinTrebleVol = 0, nMaxTrebleVol = 0;
6070 int8_t tmp_ch = 0;
6071
6072 nMinTrebleVol = GetTrebleUIMinGainVal();
6073 nMaxTrebleVol = GetTrebleUIMaxGainVal();
6074
6075 SSMReadAudioTrebleVolume(&tmp_ch);
6076 mCurAudioTrebleVolume = tmp_ch;
6077 if (mCurAudioTrebleVolume < nMinTrebleVol
6078 || mCurAudioTrebleVolume > nMaxTrebleVol) {
6079 RealSaveCurAudioTrebleVolume((nMaxTrebleVol + nMinTrebleVol) / 2, 0);
6080 }
6081
6082 mCustomAudioTrebleVolume = mCurAudioTrebleVolume;
6083 return mCurAudioTrebleVolume;
6084}
6085
6086int CTv::SetAudioSoundMode(int tmp_val) {
6087 mCustomAudioSoundMode = tmp_val;
6088 SetSpecialModeEQGain(mCustomAudioSoundMode);
6089
6090 HandleTrebleBassVolume();
6091 return 0;
6092}
6093
6094int CTv::GetAudioSoundMode() {
6095 return mCustomAudioSoundMode;
6096}
6097
6098int CTv::GetCurAudioSoundMode() {
6099 return mCurAudioSoundMode;
6100}
6101
6102int CTv::SaveCurAudioSoundMode(int tmp_val) {
6103 mCurAudioSoundMode = tmp_val;
6104 SSMSaveAudioSoundModeVal(tmp_val);
6105 return tmp_val;
6106}
6107
6108int CTv::LoadCurAudioSoundMode() {
6109 int8_t tmp_ch = 0;
6110 SSMReadAudioSoundModeVal(&tmp_ch);
6111 mCurAudioSoundMode = tmp_ch;
6112 if (mCurAudioSoundMode < CC_SOUND_MODE_START
6113 || mCurAudioSoundMode > CC_SOUND_MODE_END) {
6114 SaveCurAudioSoundMode (CC_SOUND_MODE_STD);
6115 }
6116 mCustomAudioSoundMode = mCurAudioSoundMode;
6117 return mCurAudioSoundMode;
6118}
6119
6120int CTv::HandleTrebleBassVolume() {
6121 int tmp_vol = 0;
6122 int tmpEQGainBuf[128] = { 0 };
6123 int8_t tmp_ch = 0;
6124
6125 GetCustomEQGain(tmpEQGainBuf);
6126
6127 tmp_vol = MappingTrebleBassAndEqualizer(tmpEQGainBuf[CC_EQ_TREBLE_IND], 1,
6128 GetTrebleUIMinGainVal(), GetTrebleUIMaxGainVal());
6129 mCustomAudioTrebleVolume = tmp_vol;
6130 mCurAudioTrebleVolume = mCustomAudioTrebleVolume;
6131 tmp_ch = mCustomAudioTrebleVolume;
6132 SSMSaveAudioTrebleVolume(tmp_ch);
6133
6134 tmp_vol = MappingTrebleBassAndEqualizer(tmpEQGainBuf[CC_EQ_BASS_IND], 1,
6135 GetBassUIMinGainVal(), GetBassUIMaxGainVal());
6136 mCustomAudioBassVolume = tmp_vol;
6137 mCurAudioBassVolume = mCustomAudioBassVolume;
6138 tmp_ch = mCustomAudioBassVolume;
6139 SSMSaveAudioBassVolume(tmp_ch);
6140 return 0;
6141}
6142
6143int CTv::SetAudioWallEffect(int tmp_val) {
6144 int tmp_treble_val;
6145 int tmp_type = 0;
6146
6147 mCustomAudioWallEffect = tmp_val;
6148
6149 tmp_type = GetAudioWallEffectTypeCfg();
6150 if (tmp_type == 0) {
6151 SetCustomEQGain();
6152 } else if (tmp_type == 1) {
6153 int aud_arch_type = GetAudioArchitectureTypeCFG();
6154 if (aud_arch_type == CC_DAC_G9TV_INTERNAL_DAC) {
6155 return 0;
6156 } else if (aud_arch_type == CC_DAC_G9TV_EXTERNAL_DAC_ON_BOARD) {
6157 mAudioAlsa.SetExternalDacEQMode(tmp_val);
6158 } else if (aud_arch_type == CC_DAC_G9TV_EXTERNAL_DAC_OFF_BOARD_FBC) {
6159 SendCmdToOffBoardFBCExternalDac(AUDIO_CMD_SET_EQ_MODE, tmp_val);
6160 }
6161 }
6162 return 0;
6163}
6164
6165int CTv::GetAudioWallEffect() {
6166 return mCustomAudioWallEffect;
6167}
6168
6169int CTv::GetCurAudioWallEffect() {
6170 return mCurAudioWallEffect;
6171}
6172
6173int CTv::SaveCurAudioWallEffect(int tmp_val) {
6174 int8_t tmp_ch = 0;
6175
6176 mCurAudioWallEffect = tmp_val;
6177 tmp_ch = tmp_val;
6178 SSMSaveAudioWallEffectSwitch(tmp_ch);
6179
6180 return mCurAudioWallEffect;
6181}
6182
6183int CTv::LoadCurAudioWallEffect() {
6184 int8_t tmp_ch = 0;
6185 SSMReadAudioWallEffectSwitch(&tmp_ch);
6186 mCurAudioWallEffect = tmp_ch;
6187 if (mCurAudioWallEffect != CC_SWITCH_ON
6188 && mCurAudioWallEffect != CC_SWITCH_OFF) {
6189 SaveCurAudioWallEffect (CC_SWITCH_OFF);
6190 }
6191
6192 mCustomAudioWallEffect = mCurAudioWallEffect;
6193 return mCurAudioWallEffect;
6194}
6195
6196int CTv::SetAudioEQMode(int tmp_val) {
6197 mCustomAudioEQMode = tmp_val;
6198 return 0;
6199}
6200
6201int CTv::GetAudioEQMode() {
6202 return mCustomAudioEQMode;
6203}
6204
6205int CTv::GetCurAudioEQMode() {
6206 return mCurAudioEQMode;
6207}
6208
6209int CTv::SaveCurAudioEQMode(int tmp_val) {
6210 int8_t tmp_ch = 0;
6211
6212 mCurAudioEQMode = tmp_val;
6213 tmp_ch = tmp_val;
6214 SSMSaveAudioEQModeVal(tmp_ch);
6215
6216 return tmp_val;
6217}
6218
6219int CTv::LoadCurAudioEQMode() {
6220 int8_t tmp_ch = 0;
6221 SSMReadAudioEQModeVal(&tmp_ch);
6222 mCurAudioEQMode = tmp_ch;
6223 if (mCurAudioEQMode < CC_EQ_MODE_START
6224 || mCurAudioEQMode > CC_EQ_MODE_END) {
6225 SaveCurAudioEQMode (CC_EQ_MODE_START);
6226 }
6227 mCustomAudioEQMode = mCurAudioEQMode;
6228
6229 return mCurAudioEQMode;
6230}
6231
6232int CTv::GetAudioEQRange(int range_buf[]) {
6233 range_buf[0] = CC_MIN_EQ_GAIN_VAL;
6234 range_buf[1] = CC_MAX_EQ_GAIN_VAL;
6235 return 0;
6236}
6237
6238int CTv::GetAudioEQBandCount() {
6239 return mAudioEffect.GetEQBandCount();
6240}
6241
6242int CTv::SetAudioEQGain(int gain_buf[]) {
6243 return AudioSetEQGain(gain_buf);
6244}
6245
6246int CTv::GetAudioEQGain(int gain_buf[]) {
6247 return GetCustomEQGain(gain_buf);
6248}
6249
6250int CTv::GetCurAudioEQGain(int gain_buf[]) {
6251 RealReadCurAudioEQGain(gain_buf);
6252 return 0;
6253}
6254
6255int CTv::SaveCurAudioEQGain(int gain_buf[]) {
6256 return RealSaveCurAudioEQGain(gain_buf, 1);
6257}
6258
6259int CTv::RealReadCurAudioEQGain(int gain_buf[]) {
6260 ArrayCopy(gain_buf, mCurEQGainBuf, GetAudioEQBandCount());
6261 return 0;
6262}
6263
6264int CTv::RealSaveCurAudioEQGain(int gain_buf[], int sound_mode_judge) {
6265 ArrayCopy(mCurEQGainBuf, gain_buf, GetAudioEQBandCount());
6266 ArrayCopy(mCurEQGainChBuf, gain_buf, GetAudioEQBandCount());
6267 SSMSaveAudioEQGain(0, GetAudioEQBandCount(), mCurEQGainChBuf);
6268
6269 if (sound_mode_judge == 1) {
6270 HandleTrebleBassVolume();
6271 SaveCurAudioSoundMode (CC_SOUND_MODE_USER);
6272 mCustomAudioSoundMode = mCurAudioSoundMode;
6273 }
6274
6275 return 0;
6276}
6277
6278int CTv::LoadCurAudioEQGain() {
6279 int i = 0;
6280
6281 SSMReadAudioEQGain(0, GetAudioEQBandCount(), mCurEQGainChBuf);
6282 ArrayCopy(mCurEQGainBuf, mCurEQGainChBuf, GetAudioEQBandCount());
6283
6284 for (i = 0; i < GetAudioEQBandCount(); i++) {
6285 if (mCurEQGainBuf[i] & 0x80) {
6286 mCurEQGainBuf[i] = mCurEQGainBuf[i] - 256;
6287 }
6288 }
6289 return 0;
6290}
6291
6292int CTv::SetAudioEQSwitch(int switch_val) {
6293 return mAudioEffect.SetEQSwitch(switch_val);
6294}
6295
6296int CTv::SetDbxTvMode(int mode, int son_value, int vol_value, int sur_value) {
6297 return mAudioEffect.DbxTv_SetMode(mode, son_value, vol_value, sur_value);
6298}
6299
6300int CTv::GetBassUIMinGainVal() {
6301 return 0;
6302}
6303
6304int CTv::GetBassUIMaxGainVal() {
6305 return 100;
6306}
6307
6308int CTv::GetTrebleUIMinGainVal() {
6309 return 0;
6310}
6311
6312int CTv::GetTrebleUIMaxGainVal() {
6313 return 100;
6314}
6315
6316int CTv::MappingLine(int map_val, int src_min, int src_max, int dst_min, int dst_max) {
6317 if (dst_min < 0) {
6318 return (map_val - (src_max + src_min) / 2) * (dst_max - dst_min)
6319 / (src_max - src_min);
6320 } else {
6321 return (map_val - src_min) * (dst_max - dst_min) / (src_max - src_min);
6322 }
6323}
6324
6325int CTv::MappingTrebleBassAndEqualizer(int tmp_vol, int direct, int tb_min, int tb_max) {
6326 int tmp_ret = 0;
6327
6328 if (direct == 0) {
6329 tmp_ret = MappingLine(tmp_vol, tb_min, tb_max, CC_EQ_DEF_UI_MIN_GAIN, CC_EQ_DEF_UI_MAX_GAIN);
6330 } else {
6331 tmp_ret = MappingLine(tmp_vol, CC_EQ_DEF_UI_MIN_GAIN, CC_EQ_DEF_UI_MAX_GAIN, tb_min, tb_max);
6332 }
6333
6334 LOGD("%s, tmp_vol = %d, direct = %d, tmp_ret = %d\n", __FUNCTION__, tmp_vol,
6335 direct, tmp_ret);
6336
6337 return tmp_ret;
6338}
6339
6340int CTv::MappingEQGain(int src_gain_buf[], int dst_gain_buf[], int direct) {
6341 int i = 0;
6342 int nMinUIVal = 0, nMaxUIVal = 0, nMinVal = 0, nMaxVal = 0;
6343
6344 nMinUIVal = CC_EQ_DEF_UI_MIN_GAIN;
6345 nMaxUIVal = CC_EQ_DEF_UI_MAX_GAIN;
6346 nMinVal = CC_MIN_EQ_GAIN_VAL;
6347 nMaxVal = CC_MAX_EQ_GAIN_VAL;
6348
6349 if (nMinUIVal >= nMinVal && nMaxUIVal <= nMaxVal) {
6350 for (i = 0; i < GetAudioEQBandCount(); i++) {
6351 dst_gain_buf[i] = src_gain_buf[i];
6352 }
6353 } else {
6354 for (i = 0; i < GetAudioEQBandCount(); i++) {
6355 if (direct == 0) {
6356 dst_gain_buf[i] = MappingLine(src_gain_buf[i], nMinUIVal,
6357 nMaxUIVal, nMinVal, nMaxVal);
6358 } else {
6359 dst_gain_buf[i] = MappingLine(src_gain_buf[i], nMinVal, nMaxVal,
6360 nMinUIVal, nMaxUIVal);
6361 }
6362 }
6363 }
6364 return 0;
6365}
6366
6367int CTv::RestoreToAudioDefEQGain(int gain_buf[]) {
6368 int i = 0;
6369
6370 for (i = 0; i < GetAudioEQBandCount(); i++) {
6371 gain_buf[i] = (CC_EQ_DEF_UI_MAX_GAIN + CC_EQ_DEF_UI_MIN_GAIN) / 2;
6372 }
6373
6374 ArrayCopy(mCurEQGainBuf, gain_buf, GetAudioEQBandCount());
6375 ArrayCopy(mCurEQGainChBuf, gain_buf, GetAudioEQBandCount());
6376 SSMSaveAudioEQGain(0, GetAudioEQBandCount(), mCurEQGainChBuf);
6377
6378 HandleTrebleBassVolume();
6379 SaveCurAudioSoundMode (CC_SOUND_MODE_STD);
6380 mCustomAudioSoundMode = mCurAudioSoundMode;
6381 return 0;
6382}
6383
6384int CTv::GetCustomEQGain(int gain_buf[]) {
6385 ArrayCopy(gain_buf, mCustomEQGainBuf, GetAudioEQBandCount());
6386 return 0;
6387}
6388
6389int CTv::SetCustomEQGain() {
6390 int tmpEQGainBuf[128] = { 0 };
6391
6392 if (MappingEQGain(mCustomEQGainBuf, tmpEQGainBuf, 0) < 0) {
6393 return -1;
6394 }
6395
6396 return RealSetEQGain(tmpEQGainBuf);
6397}
6398
6399int CTv::AudioSetEQGain(int gain_buf[]) {
6400 int tmpEQGainBuf[128] = { 0 };
6401
6402 ArrayCopy(mCustomEQGainBuf, gain_buf, GetAudioEQBandCount());
6403
6404 if (MappingEQGain(mCustomEQGainBuf, tmpEQGainBuf, 0) < 0) {
6405 return -1;
6406 }
6407
6408 return RealSetEQGain(tmpEQGainBuf);
6409}
6410
6411int CTv::handleEQGainBeforeSet(int src_buf[], int dst_buf[]) {
6412 int i = 0, nMinGain, nMaxGain;
6413
6414 nMinGain = CC_MIN_EQ_GAIN_VAL;
6415 nMaxGain = CC_MAX_EQ_GAIN_VAL;
6416
6417 if (GetAudioWallEffect() == CC_SWITCH_ON && GetAudioWallEffectTypeCfg() == 0) {
6418 for (i = 0; i < GetAudioEQBandCount(); i++) {
6419 dst_buf[i] = mWallEffectValueBuf[i] + src_buf[i];
6420
6421 if (dst_buf[i] < nMinGain) {
6422 dst_buf[i] = nMinGain;
6423 }
6424
6425 if (dst_buf[i] > nMaxGain) {
6426 dst_buf[i] = nMaxGain;
6427 }
6428 }
6429 } else {
6430 for (i = 0; i < GetAudioEQBandCount(); i++) {
6431 dst_buf[i] = src_buf[i];
6432 }
6433 }
6434
6435 return 0;
6436}
6437
6438int CTv::RealSetEQGain(int gain_buf[]) {
6439 if (GetAudioWallEffect() == CC_SWITCH_ON && GetAudioWallEffectTypeCfg() == 0) {
6440 for (int i = 0; i < GetAudioEQBandCount(); i++) {
6441 gain_buf[i] = mWallEffectValueBuf[i] + gain_buf[i];
6442
6443 if (gain_buf[i] < CC_MIN_EQ_GAIN_VAL) {
6444 gain_buf[i] = CC_MIN_EQ_GAIN_VAL;
6445 }
6446
6447 if (gain_buf[i] > CC_MAX_EQ_GAIN_VAL) {
6448 gain_buf[i] = CC_MAX_EQ_GAIN_VAL;
6449 }
6450 }
6451 }
6452
6453 mAudioEffect.SetEQValue(gain_buf);
6454 return 0;
6455}
6456
6457int CTv::SetAtvInGain(int gain_val) {
6458 char set_str[32] = {0};
6459
6460 sprintf ( set_str, "audio_gain_set %x", gain_val );
6461 return SetFileAttrValue ( "/sys/class/amlatvdemod/atvdemod_debug", set_str );
6462}
6463
6464int CTv::SetSpecialModeEQGain(int tmp_val) {
6465 int i = 0;
6466 int tmpEQPresetBufPtr[24];
6467 if (GetAudioEQPresetBufferPtr(tmpEQPresetBufPtr) != 0) {
6468 GetDefault_EQGain_Table(tmpEQPresetBufPtr);
6469 }
6470 int tmpEQGainBuf[128] = { 0 };
6471
6472 if (tmp_val == CC_SOUND_MODE_USER) {
6473 RealReadCurAudioEQGain(tmpEQGainBuf);
6474 } else {
6475 ArrayCopy(tmpEQGainBuf,
6476 tmpEQPresetBufPtr + tmp_val * GetAudioEQBandCount(),
6477 GetAudioEQBandCount());
6478 }
6479
6480 AudioSetEQGain(tmpEQGainBuf);
6481 return tmp_val;
6482}
6483
6484int CTv::SetSpecialIndexEQGain(int buf_index, int w_val) {
6485 int tmpEQGainBuf[128] = { 0 };
6486
6487 if (buf_index >= 0 && buf_index < GetAudioEQBandCount()) {
6488 RealReadCurAudioEQGain(tmpEQGainBuf);
6489 tmpEQGainBuf[buf_index] = w_val;
6490
6491 return AudioSetEQGain(tmpEQGainBuf);
6492 }
6493 return -1;
6494}
6495
6496int CTv::SaveSpecialIndexEQGain(int buf_index, int w_val) {
6497 int tmpEQGainBuf[128] = { 0 };
6498
6499 if (buf_index >= 0 && buf_index < GetAudioEQBandCount()) {
6500 RealReadCurAudioEQGain(tmpEQGainBuf);
6501 tmpEQGainBuf[buf_index] = w_val;
6502
6503 return RealSaveCurAudioEQGain(tmpEQGainBuf, 0);
6504 }
6505
6506 return 0;
6507}
6508
6509// amAudio
6510int CTv::OpenAmAudio(unsigned int sr, int input_device, int output_device) {
6511 LOGD("OpenAmAudio input_device = %d", input_device);
6512 return amAudioOpen(sr, input_device, output_device);
6513}
6514
6515int CTv::CloseAmAudio(void) {
6516 return amAudioClose();
6517}
6518
6519int CTv::SetAmAudioInputSr(unsigned int sr, int output_device) {
6520 LOGD("SetAmAudioInputSr ");
6521 return amAudioSetInputSr(sr, CC_IN_USE_SPDIF_DEVICE, output_device);
6522}
6523
6524int CTv::SetAmAudioOutputMode(int mode) {
6525 if (mode != CC_AMAUDIO_OUT_MODE_DIRECT && mode != CC_AMAUDIO_OUT_MODE_INTER_MIX
6526 && mode != CC_AMAUDIO_OUT_MODE_DIRECT_MIX) {
6527 LOGE("%s, mode error, it should be mix or direct!\n", __FUNCTION__);
6528 return -1;
6529 }
6530
6531 return amAudioSetOutputMode(mode);
6532}
6533
6534int CTv::SetAmAudioMusicGain(int gain) {
6535 return amAudioSetMusicGain(gain);
6536}
6537
6538int CTv::SetAmAudioLeftGain(int gain) {
6539 return amAudioSetLeftGain(gain);
6540}
6541
6542int CTv::SetAmAudioRightGain(int gain) {
6543 return amAudioSetRightGain(gain);
6544}
6545
6546int CTv::SetAudioDumpDataFlag(int tmp_flag) {
6547 return amAudioSetDumpDataFlag(tmp_flag);
6548}
6549
6550int GetAudioDumpDataFlag() {
6551 return amAudioGetDumpDataFlag();
6552}
6553
6554static int RealCalVolDigitLUTBuf(int start_ind, int end_ind, int start_val,
6555 int end_val, int lut_buf[]) {
6556 int i = 0;
6557 float tmp_step = 0;
6558
6559 if (end_ind < start_ind) {
6560 return 0;
6561 }
6562
6563 tmp_step = (float) (end_val - start_val) / (float) (end_ind - start_ind);
6564
6565 for (i = start_ind; i < end_ind; i++) {
6566 lut_buf[i] = start_val + (int) (tmp_step * (i - start_ind));
6567 }
6568
6569 lut_buf[end_ind] = end_val;
6570 return 1;
6571}
6572
6573void CTv::AudioSetVolumeDigitLUTBuf(int lut_table_index, int *MainVolLutBuf) {
6574 int tmpDefDigitLutBuf[CC_LUT_BUF_SIZE] = { 0 };
6575 mAudioAlsa.SetMainVolDigitLutBuf(MainVolLutBuf);
6576
6577 GetAudioAmpSupbassvolBuf(lut_table_index, tmpDefDigitLutBuf);
6578 mAudioAlsa.SetSupperBassVolDigitLutBuf(tmpDefDigitLutBuf);
6579}
6580
6581int CTv::InitTvAudio(int sr, int input_device) {
6582 OpenAmAudio(sr, input_device, CC_OUT_USE_AMAUDIO);
6583
6584 RefreshSrsEffectAndDacGain();
6585 SetCustomEQGain();
6586 return 0;
6587}
6588
6589int CTv::UnInitTvAudio() {
6590 return CloseAmAudio();
6591}
6592
6593int CTv::AudioChangeSampleRate(int sr) {
6594 sr = HanldeAudioInputSr(sr);
6595
6596 if (SetAmAudioInputSr(sr, CC_OUT_USE_AMAUDIO) != 0) {
6597 return -1;
6598 }
6599
6600 RefreshSrsEffectAndDacGain();
6601 SetCustomEQGain();
6602 return 0;
6603}
6604
6605int CTv::AudioSetAudioInSource(int audio_src_in_type) {
6606 return mAudioAlsa.SetAudioInSource(audio_src_in_type);
6607}
6608
6609int CTv::AudioSetAudioSourceType(int source_type) {
6610 int aud_arch_type = GetAudioArchitectureTypeCFG();
6611
6612 if (aud_arch_type == CC_DAC_G9TV_EXTERNAL_DAC_ON_BOARD) {
6613 } else if (aud_arch_type == CC_DAC_G9TV_EXTERNAL_DAC_OFF_BOARD_FBC) {
6614 SendCmdToOffBoardFBCExternalDac(AUDIO_CMD_SET_SOURCE, source_type);
6615 } else if (aud_arch_type == CC_DAC_G9TV_EXTERNAL_DAC_CUSTOMER_LIB) {
6616 mCustomerCtrl.SetSource(source_type);
6617 } else if (aud_arch_type == CC_DAC_G9TV_EXTERNAL_DAC_DIGITAL) {
6618 }
6619 return 0;
6620}
6621
6622int CTv::AudioLineInSelectChannel(int audio_channel) {
6623 LOGD ("%s, audio_channel = %d", __FUNCTION__, audio_channel);
6624 mAudioAlsa.SetInternalDacLineInSelectChannel(audio_channel);
6625 return 0;
6626}
6627
6628int CTv::SetKalaokIO(int level) {
6629 LOGD ("%s, SetKalaokIO = %d", __FUNCTION__, level);
6630 if (GetKaraokAvEnable() == 1) {
6631 mAudioAlsa.SetAudioSwitchIO(level);
6632 }
6633 return 0;
6634}
6635
6636int CTv::AudioSetLineInCaptureVolume(int l_vol, int r_vol) {
6637 mAudioAlsa.SetInternalDacLineInCaptureVolume(l_vol, r_vol);
6638 return 0;
6639}
6640
6641int CTv::openTvAudio() {
6642 int tmp_val = 0;
6643
6644 LOGD("%s, entering...\n", __FUNCTION__);
6645 UnInitSetTvAudioCard();
6646
6647 tmp_val = GetAudioDumpDataEnableFlagCfg();
6648 SetAudioDumpDataFlag(tmp_val);
6649
6650 tmp_val = GetAudioInternalDacPGAInGain_Cfg();
6651 mAudioAlsa.SetAudioInternalDacPGAInGain(tmp_val, tmp_val);
6652
6653 mAudioAlsa.SetMixerBypassSwitch (CC_SWITCH_OFF);
6654 mAudioAlsa.SetMixerDacSwitch (CC_SWITCH_ON);
6655
6656 LoadAudioCtl();
6657
6658 RefreshSrsEffectAndDacGain();
6659 InitSetAudioCtl();
6660 return 0;
6661}
6662
6663int CTv::closeTvAudio() {
6664 return 0;
6665}
6666
6667void CTv::LoadAudioCtl() {
6668 // Get Current Audio Volume
6669 LoadCurAudioMasterVolume();
6670
6671 // Get Current Audio Balance
6672 LoadCurAudioBalance();
6673
6674 // Get Current Supper Bass Switch
6675 LoadCurAudioSupperBassSwitch();
6676
6677 // Get Current Supper Bass Volume
6678 LoadCurAudioSupperBassVolume();
6679
6680 // Get Current SRSSurround
6681 LoadCurAudioSrsSurround();
6682
6683 // Get Current SRS DialogClarity
6684 LoadCurAudioSrsDialogClarity();
6685
6686 // Get Current SRS TruBass
6687 LoadCurAudioSrsTruBass();
6688
6689 // Get Current Audio Sound Mode
6690 LoadCurAudioSoundMode();
6691
6692 // Get Current Audio Bass and Treble
6693 LoadCurAudioBassVolume();
6694 LoadCurAudioTrebleVolume();
6695
6696 // Get Current Wall Effect
6697 LoadCurAudioWallEffect();
6698
6699 // Get Current spdif switch
6700 LoadCurAudioSPDIFSwitch();
6701
6702 // Get Current spdif mode
6703 LoadCurAudioSPDIFMode();
6704
6705 // Get Current EQ mode
6706 LoadCurAudioEQMode();
6707
6708 // Get Current EQ Gain
6709 LoadCurAudioEQGain();
6710}
6711
6712void CTv::InitSetAudioCtl() {
6713 // Set Current Audio balance value
6714 SetAudioBalance(GetAudioBalance());
6715
6716 // Set Current Audio Volume
6717 SetAudioMasterVolume(GetAudioMasterVolume());
6718
6719 // Set Current Supper Bass Volume
6720 SetAudioSupperBassVolume(GetAudioSupperBassVolume());
6721
6722 // Set Current Audio Sound Mode
6723 SetAudioSoundMode(GetAudioSoundMode());
6724
6725 // Set Current Audio SPDIF Switch
6726 SetAudioSPDIFSwitch(GetCurAudioSPDIFSwitch());
6727
6728 // Set Current Audio SPDIF mode
6729 SetAudioSPDIFMode(GetCurAudioSPDIFMode());
6730}
6731
6732int CTv::SetADC_Digital_Capture_Volume(int value) {
6733 return mAudioAlsa.SetAudioInternalDacADCDigitalCaptureVolume( value, value);
6734}
6735
6736int CTv::SetPGA_IN_Value(int value) {
6737 return mAudioAlsa.SetAudioInternalDacPGAInGain( value, value);
6738}
6739
6740int CTv::SetDAC_Digital_PlayBack_Volume(int value) {
6741 return mAudioAlsa.SetAudioInternalDacDACDigitalPlayBackVolume( value, value);
6742}
6743
6744int CTv::setAudioPcmPlaybackVolume(int val) {
6745 int pcm_volume = 0;
6746 pcm_volume = val / 2;
6747 if (pcm_volume > 24) pcm_volume = 24;
6748 //return SetAudioPcmPlaybackVolume(pcm_volume);
6749 return 0;
6750}
6751
6752int CTv::HanldeAudioInputSr(unsigned int sr) {
6753 int tmp_cfg = 0;
6754
6755 tmp_cfg = GetAudioResampleTypeCFG();
6756 if (tmp_cfg & CC_AUD_RESAMPLE_TYPE_HW) {
6757 mAudioAlsa.SetHardwareResample(sr);
6758 } else {
6759 mAudioAlsa.SetHardwareResample(-1);
6760 }
6761
6762 if (!(tmp_cfg & CC_AUD_RESAMPLE_TYPE_SW)) {
6763 sr = 48000;
6764 }
6765
6766 return sr;
6767}
6768
6769int CTv::AudioSSMRestoreDefaultSetting() {
6770 int i = 0, tmp_val = 0;
6771 int nMinUIVol = 0, nMaxUIVol = 0;
6772 int *tmp_ptr = NULL;
6773 int tmpEQGainBuf[128] = { 0 };
6774 unsigned char tmp_buf[CC_NO_LINE_POINTS_MAX_CNT] = { 0 };
6775
6776 // Save Current Audio Volume
6777 SaveCurAudioMasterVolume (CC_DEF_SOUND_VOL);
6778
6779 // Save Current Audio Balance
6780 SaveCurAudioBalance (CC_DEF_SOUND_BALANCE_VAL);
6781
6782 // Save Current Supper Bass Switch
6783 SaveCurAudioSupperBassSwitch (CC_SWITCH_OFF);
6784
6785 // Save Current Supper Bass Volume
6786 SaveCurAudioSupperBassVolume (CC_DEF_SUPPERBASS_VOL);
6787
6788 // Save Current SRSSurround
6789 SaveCurAudioSrsSurround(CC_SWITCH_OFF);
6790
6791 // Save Current SRS DialogClarity
6792 SaveCurAudioSrsDialogClarity(CC_SWITCH_OFF);
6793
6794 // Save Current SRS TruBass
6795 SaveCurAudioSrsTruBass(CC_SWITCH_OFF);
6796
6797 // Save Current Audio Sound Mode
6798 SaveCurAudioSoundMode (CC_SOUND_MODE_STD);
6799
6800 // Save Current Wall Effect
6801 SaveCurAudioWallEffect(CC_SWITCH_OFF);
6802
6803 // Save Current spdif switch
6804 SaveCurAudioSPDIFSwitch (CC_SWITCH_ON);
6805
6806 // Save Current spdif mode
6807 SaveCurAudioSPDIFMode (CC_SPDIF_MODE_PCM);
6808
6809 // Save Current avout and spidif mute state
6810 SSMSaveAudioSPIDFMuteVal(CC_AUDIO_MUTE);
6811 SSMSaveAudioAVOutMuteVal(CC_AUDIO_MUTE);
6812
6813 // Save Current EQ mode
6814 SaveCurAudioEQMode (CC_EQ_MODE_NOMAL);
6815
6816 // Save Current EQ Gain
6817 RestoreToAudioDefEQGain(tmpEQGainBuf);
6818
6819 // Save Current Audio Bass and Treble
6820 nMinUIVol = GetBassUIMinGainVal();
6821 nMaxUIVol = GetBassUIMaxGainVal();
6822 RealSaveCurAudioBassVolume((nMinUIVol + nMaxUIVol) / 2, 0);
6823
6824 nMinUIVol = GetTrebleUIMinGainVal();
6825 nMaxUIVol = GetTrebleUIMaxGainVal();
6826 RealSaveCurAudioTrebleVolume((nMinUIVol + nMaxUIVol) / 2, 0);
6827 return 0;
6828}
6829
6830static const char *gDefCapturePropName = "snd.card.default.card.capture";
6831
6832int CTv::InitSetTvAudioCard() {
6833 int i = 0, totle_num = 0, capture_ind = 0;
6834 char tmp_buf[32] = { 0 };
6835 char tv_card_name[64] = { 0 };
6836 char prop_value[PROPERTY_VALUE_MAX];
6837
6838#ifndef BOARD_ALSA_AUDIO_TINY
6839 snd_card_refresh_info();
6840#endif
6841
6842 if (GetTvAudioCardNeedSet()) {
6843 memset(prop_value, '\0', PROPERTY_VALUE_MAX);
6844 property_get("snd.card.totle.num", prop_value, "0");
6845
6846 totle_num = strtoul(prop_value, NULL, 10);
6847 LOGD("%s, totle number = %d\n", __FUNCTION__, totle_num);
6848 totle_num = 8;
6849
6850 GetTvAudioCardName(tv_card_name);
6851
6852 for (i = 0; i < totle_num; i++) {
6853 sprintf(tmp_buf, "snd.card.%d.name", i);
6854 memset(prop_value, '\0', PROPERTY_VALUE_MAX);
6855 property_get(tmp_buf, prop_value, "null");
6856
6857 LOGD("%s, key string \"%s\", value string \"%s\".\n", __FUNCTION__, tmp_buf, prop_value);
6858
6859 if (strcmp(prop_value, tv_card_name) == 0) {
6860 break;
6861 }
6862 }
6863
6864 capture_ind = i;
6865
6866 if (capture_ind == totle_num) {
6867 capture_ind = -1;
6868 LOGE("%s, can't find tv card \"%s\".\n", __FUNCTION__, tv_card_name);
6869 }
6870 } else {
6871 capture_ind = -1;
6872 }
6873
6874 sprintf(tmp_buf, "%d", capture_ind);
6875 property_set(gDefCapturePropName, tmp_buf);
6876 LOGD("%s, set \"%s\" as \"%s\".\n", __FUNCTION__, gDefCapturePropName, tmp_buf);
6877 return 0;
6878}
6879
6880int CTv::UnInitSetTvAudioCard() {
6881 char tmp_buf[32] = { 0 };
6882
6883#ifndef BOARD_ALSA_AUDIO_TINY
6884 snd_card_refresh_info();
6885#endif
6886 sprintf(tmp_buf, "%d", -1);
6887 property_set(gDefCapturePropName, tmp_buf);
6888 LOGD("%s, set \"%s\" as \"%s\".\n", __FUNCTION__, gDefCapturePropName, tmp_buf);
6889 return 0;
6890}
6891
6892#define CS_SPDIF_MODE_DEV_PATH "/sys/class/audiodsp/digital_raw"
6893
6894int CTv::SetSPDIFMode(int mode_val) {
6895 FILE *spdif_mode_fp = NULL;
6896
6897 spdif_mode_fp = fopen(CS_SPDIF_MODE_DEV_PATH, "w");
6898 if (spdif_mode_fp == NULL) {
6899 LOGE("%s, Open file %s error(%s)!\n", __FUNCTION__, CS_SPDIF_MODE_DEV_PATH, strerror(errno));
6900 return -1;
6901 }
6902
6903 if (mode_val == CC_SPDIF_MODE_PCM) {
6904 fprintf(spdif_mode_fp, "%d", 0);
6905 } else if (mode_val == CC_SPDIF_MODE_RAW ) {
6906 fprintf(spdif_mode_fp, "%d", 1);
6907 }
6908
6909 fclose(spdif_mode_fp);
6910 spdif_mode_fp = NULL;
6911
6912 return 0;
6913}
6914
6915int CTv::SwitchAVOutBypass(int sw) {
6916 if (sw == 0 ) {
6917 mAudioAlsa.SetMixerBypassSwitch ( CC_SWITCH_OFF );
6918 mAudioAlsa.SetMixerDacSwitch ( CC_SWITCH_ON );
6919 } else {
6920 mAudioAlsa.SetMixerBypassSwitch ( CC_SWITCH_ON );
6921 mAudioAlsa.SetMixerDacSwitch ( CC_SWITCH_OFF );
6922 }
6923 return 0;
6924}
6925
6926int CTv::SetAudioSwitchIO(int value) {
6927 return mAudioAlsa.SetAudioSwitchIO( value);
6928}
6929
6930int CTv::SetOutput_Swap(int value) {
6931 return mAudioAlsa.SetOutput_Swap( value);
6932}
6933
6934int CTv::SendCmdToOffBoardFBCExternalDac(int cmd, int para) {
6935 int set_val = 0;
6936 CFbcCommunication *pFBC = GetSingletonFBC();
6937 if (pFBC != NULL) {
6938 if (cmd == AUDIO_CMD_SET_MUTE) {
6939 if (para == CC_AUDIO_MUTE) {
6940 set_val = CC_MUTE_ON;
6941 } else if (para == CC_AUDIO_UNMUTE) {
6942 set_val = CC_MUTE_OFF;
6943 } else {
6944 return -1;
6945 }
6946
6947 return pFBC->cfbc_Set_Mute(COMM_DEV_SERIAL, set_val);
6948 } else if (cmd == AUDIO_CMD_SET_VOLUME_BAR) {
6949 LOGD("%s, send AUDIO_CMD_SET_VOLUME_BAR (para = %d) to fbc.\n", __FUNCTION__, para);
6950 return pFBC->cfbc_Set_Volume_Bar(COMM_DEV_SERIAL, para);
6951 } else if (cmd == AUDIO_CMD_SET_BALANCE) {
6952 LOGD("%s, send AUDIO_CMD_SET_BALANCE (para = %d) to fbc.\n", __FUNCTION__, para);
6953 return pFBC->cfbc_Set_Balance(COMM_DEV_SERIAL, para);
6954 } else if (cmd == AUDIO_CMD_SET_SOURCE) {
6955 LOGD("%s, send AUDIO_CMD_SET_SOURCE (para = %d) to fbc.\n", __FUNCTION__, para);
6956 return pFBC->cfbc_Set_FBC_Audio_Source(COMM_DEV_SERIAL, para);
6957 }
6958 }
6959 return 0;
6960}
6961
6962int CTv::GetHdmiAvHotplugDetectOnoff() {
6963 return m_hdmiav_hotplugdetect_en;
6964}
6965
6966