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