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