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