source: svn/newcon3bcm2_21bu/dst/app/src/Function/App_Fnc_Audio.c

Last change on this file was 76, checked in by megakiss, 10 years ago

1W 대기전력을 만족시키기 위하여 POWEROFF시 튜너를 Standby 상태로 함

  • Property svn:executable set to *
File size: 47.4 KB
Line 
1/****************************************************************************
2* NAME: App_Fnc_Audio.c
3*----------------------------------------------------------------------------
4* Copyright (c) DIGITAL STREAM Technology Inc.
5*----------------------------------------------------------------------------
6* CREATED_BY: Chan Hun Jeon
7* CREATION_DATE: 2009/09/08
8* $Author: chjeon $
9* $Revision: 1.1 $
10* $Date: 2009/07/08 15:08:26 $
11*----------------------------------------------------------------------------
12* PURPOSE:
13*       - implement all audio related functions.
14*****************************************************************************/
15
16/*_____ I N C L U D E __________________________________________*/
17
18#include "App_Main.h"
19#include "App_Fnc_Common.h"
20
21#include "App_Fnc_Audio.h"
22#include "App_Fnc_AudioLangTable.h"
23
24#include "DLIB_PSI_Utils.h"
25
26
27/*_____ D E F I N I T I O N ____________________________________*/
28
29#if COMMENT
30_____DbgPrint_____(){}
31#endif
32
33DHL_MODULE("@f_aud", 0);
34
35
36#if COMMENT
37____Config____(){}
38#endif
39
40#define APP_REGISTER_DEBUG_SYMBOL 1
41
42
43// cafrii 060619 add new vct sourcing
44#define GET_VCT_FROM_EPG_MODULE 1
45        // ±âÁ¸¿¡ VCT¸¦ Á÷Á¢ download ¹Þ¾Ò´ø ¹æ½ÄÀÌ ±×¸® ÁÁÁö ¾ÊÀ½.
46        // EpgDB¿¡¼­ °¡Á®¿Í »çº»À» ¸¸µé¾î »ç¿ëÇÑ´Ù.
47
48#define SUPPORT_SPDIF_OUTPUT 1
49#define SUPPORT_HDMI_OUTPUT 1
50
51#define APP_AUDIO_VOLUME_MAX 20
52#define APP_AUDIO_VOLUME_MIN 0
53
54
55#if COMMENT
56____Types____(){}
57#endif
58
59
60
61
62#if COMMENT
63____Variables____(){}
64#endif
65
66
67static BOOL p_support_mpeg1_audio, p_support_mpeg2_audio;
68static BOOL p_support_aac_audio_adts, p_support_aac_audio_latm;
69
70
71static struct
72{
73        APP_AUDIO_LANG_ID id;
74        UINT32 code;
75        char name[3][30];
76
77}  p_aud_lang_code_table[] = 
78{
79        // code´Â ³ªÁß¿¡ ȣȯ ÄÚµå üũ¸¦ Çϱ⠶§¹®¿¡
80        //   ´ëÇ¥°ª Áß Çϳª¸¸ ÀûÀ¸¸é µÊ. ex: 'fra' == 'fre'
81        //
82#if 0
83#if SUPPORT_NEWBY
84        APP_AUDIO_LANG_ENG, 0x656e67, "¿µ¾î"},
85        APP_AUDIO_LANG_KOR, 0x6b6f72, "Çѱ¹¾î"},
86        APP_AUDIO_LANG_SPA, 0x737061, "½ºÆäÀξî"}
87#else
88        APP_AUDIO_LANG_ENG, 0x656e67, "English",
89        APP_AUDIO_LANG_SPA, 0x737061, "Spanish",
90        APP_AUDIO_LANG_SPA, 0x65736c, "Spanish",
91        APP_AUDIO_LANG_FRE, 0x667265, "French",
92        APP_AUDIO_LANG_FRE, 0x667261, "French",
93        APP_AUDIO_LANG_KOR, 0x6b6f72, "Korean"
94#endif
95#else
96
97        APP_AUDIO_LANG_ENG, 0x656e67, {"English","Ingl#e9s","¿µ¾î"},
98        APP_AUDIO_LANG_KOR, 0x6b6f72, {"Korean","Coreano","Çѱ¹¾î"},
99        APP_AUDIO_LANG_SPA, 0x737061, {"Spanish","Espa#f1ol","½ºÆäÀξî"},
100        APP_AUDIO_LANG_SPA, 0x65736c, {"Spanish","Espa#f1ol","½ºÆäÀξî"},
101        APP_AUDIO_LANG_SPA, 0x667265, {"French","Franc#e9s","ÇÁ¶û½º¾î"},
102        APP_AUDIO_LANG_SPA, 0x667261, {"French","Franc#e9s","ÇÁ¶û½º¾î"}
103
104#endif
105};
106
107
108static struct
109{
110        UINT8 volume: 5;         // 0~20
111        UINT8 preferedlang: 2;   // auto, english, spanish, french
112        UINT8 audioDownMix: 1;    // o:LTRT 1:LORO
113        UINT8 audioModeSPDIF: 1; // 0:AC3, 1:PCM
114        UINT8 audioModeHdmi: 1;  // 0:AC3, 1:PCM
115} p_aud_nvm_param;
116
117
118
119/*_____ F U N C T I O N ________________________________________*/
120       
121#if COMMENT
122____Private____(){}
123#endif
124
125
126//
127// µÎ°³ÀÇ language code°¡ µ¿ÀÏ ¶Ç´Â µ¿µîÇÑ °ÍÀÎÁö üũÇÑ´Ù.
128// °°Àº °ÍÀ̸é TRUE¸¦ ¸®ÅÏ.
129//
130static BOOL p_is_same_lang_code(UINT32 code1, UINT32 code2)
131{
132/*
133        change
134        µÎ NULL infoÀÇ °æ¿ì´Â TRUE (Same language)·Î °£ÁÖÇÔ.   
135        if (code1 == 0x0 || code2 == 0x0)
136                return FALSE;  // NULL code´Â Ãë±ÞÇÏÁö ¾Ê´Â´Ù.
137*/             
138        if (code1 == code2)
139                return TRUE;    // identical code
140               
141        // MAKE   code1 < code2
142        //     
143        if (code1 > code2) {
144                UINT32 temp;
145                temp = code1;
146                code1 = code2;
147                code2 = temp;
148        }
149       
150        if (code1 == 0x65736c && code2 == 0x737061) // 'esl' && 'spa'
151                return TRUE;
152               
153        if (code1 == 0x667261 && code2 == 0x667265) // 'fra' && 'fre'
154                return TRUE;
155               
156        return FALSE;
157}
158
159
160//
161//  Audio language ID¸¦ ISO639 code·Î º¯È¯ÇÑ´Ù.
162//
163static UINT32 p_aud_lang_id2code(APP_AUDIO_LANG_ID id)
164{
165        int i;
166        int size = sizeof(p_aud_lang_code_table)/sizeof(p_aud_lang_code_table[0]);
167
168        for (i=0; i<size; i++) {
169                if (p_aud_lang_code_table[i].id == id)
170                        return p_aud_lang_code_table[i].code;
171        }
172        // À߸øµÈ id.. µðÆúÆ® code·Î ¸®ÅÏÇÏÀÚ.
173        return p_aud_lang_code_table[0].code;
174}
175
176
177static char *p_aud_lang_code2name(UINT32 code)
178{
179        int i;
180        int size = sizeof(p_aud_lang_code_table)/sizeof(p_aud_lang_code_table[0]);
181       
182        for (i=0; i<size; i++) {
183                if (p_aud_lang_code_table[i].code == code)
184                        return p_aud_lang_code_table[i].name[App_NVM_GetMenuLang()];
185        }
186        return "Unknown";
187}
188       
189
190//
191//   ISO 639 code °ªÀ» ascii ¼¼±ÛÀÚ·Î Ãâ·Â.
192//
193//   °£´ÜÇÏ°Ô »ç¿ëÇÒ °æ¿ì´Â buf¸¦ NULL·Î ÁöÁ¤ÇØµÇ µÈ´Ù.
194//   ´Ü ÀÌ °æ¿ì´Â multi thread safeÇÏÁö ¾ÊÀ½.
195//
196static char *p_aud_lang_codestr(UINT32 langCode, char *buf)
197{
198        #define SafeChar(c) ((c)>=0x20 && (c)<=0x7E ? (c) : '.')
199
200        static char buf_0[10];
201
202        if (buf == NULL)
203                buf = buf_0;
204
205        buf[0] = SafeChar((langCode>>16)&0xff);
206        buf[1] = SafeChar((langCode>>8)&0xff);
207        buf[2] = SafeChar(langCode&0xff);
208        buf[3] = 0;
209
210        return buf;     
211}
212
213
214static char *p_aud_stream_type_string(int stream_type)
215{
216        return 
217                stream_type == StreamType_AC3Audio ? "AC3" :
218                stream_type == StreamType_MPEG1Audio ? "MPEG1" :
219                stream_type == StreamType_MPEG2Audio ? "MPEG2" :
220                stream_type == StreamType_AACAudioADTS ? "AAC-ADTS" :
221                stream_type == StreamType_AACAudioLATM ? "AAC-LATM" :
222                        "?";
223}
224
225
226
227/*
228        p_get_vct_info:
229       
230        Audio MTS 󸮿¡ ÇÊ¿äÇÑ VCT¸¦ ¾ò´Â ÇÔ¼öÀÌ´Ù.
231        ÇÔ¼ö°¡ È£Ã⠵Ǵ ½ÃÁ¡¿¡¼­ Á÷Á¢ ¹Þ´Â ¹æ½Ä°ú
232        EPG PSIP MW API¸¦ »ç¿ëÇÏ´Â ¹æ¹ýÀÌ ÀÖÀ½.
233       
234        pvct ´Â ȹµæÇÑ VCT Á¤º¸¸¦ ¸®ÅÏÇÏ´Â argument
235*/
236static STATUS p_get_vct_info(xvctPtr_t *pvct)
237{
238        DST_CURCHANNEL ChannelInfo;
239       
240
241#if GET_VCT_FROM_EPG_MODULE
242        DmcChannelInfo *chInfo;
243        STATUS status = statusNotFound;
244
245        *pvct = NULL;
246        Dmc_EpgLockCoreDB(TRUE);
247
248        if(App_Ucm_GetCurChInfo(&ChannelInfo) != statusOK)
249                dprint(0, "!! Get App Channel Info Err \n");
250
251        chInfo = Dmc_GetChannelInfo(g_EpgDB, ChannelInfo.nRF);
252
253        if (chInfo == NULL) {
254                Dmc_EpgLockCoreDB(FALSE);
255                return statusNotFound;
256        }
257       
258        if (chInfo->tvct)
259                status = Dmc_TranslateTvct(chInfo->tvct, pvct);
260        else if (chInfo->cvct)
261                status = Dmc_TranslateCvct(chInfo->cvct, pvct);
262
263        if (status)
264                dprint(0, "!! translate vct err, tvct %x, cvct %x, err %d\n", 
265                                chInfo->tvct, chInfo->cvct, status);
266               
267        Dmc_EpgLockCoreDB(FALSE);
268
269        return statusOK;
270
271#else
272        // ±âÁ¸ ÄÚµå..
273        STATUS status;
274        status = Dmc_GetXvct(Dmc_GetCurrentTsd(), pvct, OS_GetTicksPerSecond()/2, NULL);
275#endif
276
277}
278
279
280/*
281        p_free_vct_info:
282       
283        p_get_vct_info ·Î ºÎÅÍ ¾òÀº VCT¸¦ ´õÀÌ»ó »ç¿ëÇÏÁö ¾ÊÀ» ¶§
284        ÀÌ ÇÔ¼ö¸¦ ÀÌ¿ëÇÏ¿© ¸Þ¸ð¸® ¸®¼Ò½º¸¦ ¹ÝȯÇÑ´Ù.
285*/
286static void p_free_vct_info(xvctPtr_t *pvct)
287{
288        Dmc_FreeAtscTable(pvct);
289}
290
291
292
293
294
295#if COMMENT
296____Mute____(){}
297#endif
298
299/*
300        Audio Mute
301*/
302
303static UINT32 p_mute_status;
304        // APP_AUDIO_MUTE_TYPE °ª¿¡ ÇØ´çÇÏ´Â °¢ bit °ªÀÌ ¼³Á¤µÇ¾î ÀÖ´Ù.
305        // bit°¡ 1À̸é mute°¡ µÇ¾î ÀÖ´Â »óÅÂÀÓ.
306
307static BOOL p_is_muted;
308        // ÇöÀç Audio physical deviceÀÇ mute »óÅÂ.
309
310
311UINT32 App_GetAudioMuteStatus(void)
312{
313        return p_mute_status;
314}
315
316
317BOOL App_AudioIsUserMute(void)
318{
319        return 
320                (App_GetAudioMuteStatus() & (1UL<<APP_AUDIO_MUTE_USER)) ? TRUE : FALSE;
321}
322
323
324//
325// user¿¡ ÀÇÇÑ muteÀÎÁö,
326// AV block (rating block)¿¡ ÀÇÇÑ muteÀÎÁö,
327// Àӽà mute (ML change µî)¿¡ ÀÇÇÑ muteÀÎÁö ±¸ºÐ ÇÊ¿ä.
328//
329void App_AudioMute(BOOL bMute, APP_AUDIO_MUTE_TYPE eMuteType)
330{
331        UINT32 bitmask;
332        bitmask = 1 << (UINT32)eMuteType;
333       
334        if (bMute) 
335                p_mute_status |= bitmask;
336        else 
337                p_mute_status &= ~bitmask;
338
339        if (p_is_muted) 
340        {
341                if (p_mute_status) { // should be muted
342                        // mute -> mute
343                        // do nothing
344                }
345                else {
346                        // mute -> unmute
347                        //spdif Ãâ·ÂÀº mute¸¦ ÇÏÁö ¾Ê´Â´Ù.
348                        DHL_AV_AudioMuteControl(eDHL_AUDIO_MUTE_AMP, FALSE);
349                        DHL_AV_AudioMuteControl(eDHL_AUDIO_MUTE_HDMI, FALSE);
350                        p_is_muted = FALSE;
351                }
352        }
353        else
354        {
355                if (p_mute_status) {
356                        // unmute -> mute
357                        DHL_AV_AudioMuteControl(eDHL_AUDIO_MUTE_AMP, TRUE);
358                        DHL_AV_AudioMuteControl(eDHL_AUDIO_MUTE_HDMI, TRUE);
359                        p_is_muted = TRUE;
360                }
361                else {
362                        // unmute -> unmute
363                        // do nothing
364                }
365        }
366
367}
368
369
370// cafrii 060621 add
371// return new user mute state
372//
373BOOL App_AudioToggleUserMute(void)
374{
375        UINT32 bitmask;
376        bitmask = 1 << (UINT32)APP_AUDIO_MUTE_USER;
377
378        if (p_mute_status & bitmask)
379                // currently muted
380                App_AudioMute(FALSE, APP_AUDIO_MUTE_USER);
381        else {
382                // currently unmuted
383                App_AudioMute(TRUE, APP_AUDIO_MUTE_USER);
384
385                // TODO: After porting debug
386                //App_PrintTextMessageBox("Mute", 20);
387        }
388
389        // SDS:
390        //  mute OSD´Â 5Ãʰ£ À¯ÁöÇØ¾ß ÇÑ´Ù.
391        //
392        return (p_mute_status & bitmask) ? TRUE : FALSE;
393}
394
395
396
397#if COMMENT
398____SPDIF____(){}
399#endif
400
401#if SUPPORT_SPDIF_OUTPUT
402
403static APP_AUDIO_SPDIF_MODE p_spdif_mode;
404        // IEC digital audio format
405        // Uncompressed(PCM) or Compressed(AC3, MPEG, DTS..)
406
407static UINT32 p_spdif_mute_status;
408        // APP_SPDIF_AUDIO_MUTE_TYPE °ª¿¡ ÇØ´çÇÏ´Â °¢ bit °ªÀÌ ¼³Á¤µÇ¾î ÀÖ´Ù.
409        // bit°¡ 1À̸é mute°¡ µÇ¾î ÀÖ´Â »óÅÂÀÓ.
410
411static BOOL p_is_spdif_muted;
412        // Digital audio outputÀÌ muteÀ̸é TRUE.
413
414
415void App_AudioSetDigitalAudio(APP_AUDIO_SPDIF_MODE type, BOOL bSaveNvRam)
416{
417        // todo..
418        // ÇöÀç ¸ðµå¿Í °°ÀºÁö üũÇÒ Çʿ䰡 Àִ°¡?
419
420        tDHL_AudioIecOutFormat format;
421       
422        if (type == APP_AUDIO_SPDIF_PCM) {
423                format = eDHL_AUDIO_OUT_PCM;
424                p_spdif_mode = APP_AUDIO_SPDIF_PCM;
425        }
426        else {
427                format = eDHL_AUDIO_OUT_COMPRESSED;
428                p_spdif_mode = APP_AUDIO_SPDIF_AC3;
429        }
430
431        DHL_AV_Control(eDHL_AV_CTL_AUDIO_SPDIF_MODE, format);
432
433        if (bSaveNvRam)
434        {
435                p_aud_nvm_param.audioModeSPDIF = p_spdif_mode;
436                App_NVM_SaveModuleParam(eAPP_NVR_AUDIO, &p_aud_nvm_param);
437        }
438       
439}
440
441
442APP_AUDIO_SPDIF_MODE App_AudioGetDigitalAudio()
443{
444        return p_spdif_mode;
445}
446
447
448void App_AudioMuteDigitalAudio(BOOL bMute, APP_SPDIF_AUDIO_MUTE_TYPE eMuteType)
449{
450        UINT32 bitmask;
451        bitmask = 1 << (UINT32)eMuteType;
452       
453        if (bMute) 
454                p_spdif_mute_status |= bitmask;
455        else 
456                p_spdif_mute_status &= ~bitmask;
457
458        if (p_is_spdif_muted) 
459        {
460                if (p_spdif_mute_status) { // should be muted
461                        // mute -> mute
462                        // do nothing
463                }
464                else {
465                        // mute -> unmute
466                        DHL_AV_AudioMuteControl(eDHL_AUDIO_MUTE_SPDIF, FALSE);
467                        p_is_spdif_muted = FALSE;
468                }
469        }
470        else
471        {
472                if (p_spdif_mute_status) {
473                        // unmute -> mute
474                        DHL_AV_AudioMuteControl(eDHL_AUDIO_MUTE_SPDIF, TRUE);
475                        p_is_spdif_muted = TRUE;
476                }
477                else {
478                        // unmute -> unmute
479                        // do nothing
480                }
481        }
482}
483
484#endif // SUPPORT_SPDIF_OUTPUT
485
486
487
488
489
490#if COMMENT
491____HDMI____(){}
492#endif
493
494#if SUPPORT_HDMI_OUTPUT
495
496static APP_AUDIO_HDMI_MODE p_hdmi_mode;
497        // IEC digital audio format
498        // Uncompressed(PCM) or Compressed(AC3, MPEG, DTS..)
499
500static UINT32 p_hdmi_mute_status;
501        // APP_SPDIF_AUDIO_MUTE_TYPE °ª¿¡ ÇØ´çÇÏ´Â °¢ bit °ªÀÌ ¼³Á¤µÇ¾î ÀÖ´Ù.
502        // bit°¡ 1À̸é mute°¡ µÇ¾î ÀÖ´Â »óÅÂÀÓ.
503
504static BOOL p_is_hdmi_muted;
505        // Digital audio outputÀÌ muteÀ̸é TRUE.
506
507
508void App_AudioSetHdmiAudio(APP_AUDIO_HDMI_MODE type, BOOL bSaveNvRam)
509{
510        // todo..
511        // ÇöÀç ¸ðµå¿Í °°ÀºÁö üũÇÒ Çʿ䰡 Àִ°¡?
512
513        tDHL_AudioIecOutFormat format;
514       
515        if (type == APP_AUDIO_HDMI_PCM) {
516                format = eDHL_AUDIO_OUT_PCM;
517                p_hdmi_mode = APP_AUDIO_HDMI_PCM;
518        }
519        else {
520                format = eDHL_AUDIO_OUT_COMPRESSED;
521                p_hdmi_mode = APP_AUDIO_HDMI_AC3;
522        }
523       
524        DHL_AV_Control(eDHL_AV_CTL_AUDIO_HDMI_MODE, format);
525
526        if (bSaveNvRam)
527        {
528                p_aud_nvm_param.audioModeHdmi = p_hdmi_mode;
529                App_NVM_SaveModuleParam(eAPP_NVR_AUDIO, &p_aud_nvm_param);
530        }
531       
532}
533
534
535APP_AUDIO_HDMI_MODE App_AudioGetHdmiAudio()
536{
537        return p_hdmi_mode;
538}
539
540
541void App_AudioMuteHdmiAudio(BOOL bMute, APP_HDMI_AUDIO_MUTE_TYPE eMuteType)
542{
543        UINT32 bitmask;
544        bitmask = 1 << (UINT32)eMuteType;
545       
546        if (bMute) 
547                p_hdmi_mute_status |= bitmask;
548        else 
549                p_hdmi_mute_status &= ~bitmask;
550
551        if (p_is_hdmi_muted) 
552        {
553                if (p_hdmi_mute_status) { // should be muted
554                        // mute -> mute
555                        // do nothing
556                }
557                else {
558                        // mute -> unmute
559                        DHL_AV_AudioMuteControl(eDHL_AUDIO_MUTE_HDMI, FALSE);
560                        p_is_hdmi_muted = FALSE;
561                }
562        }
563        else
564        {
565                if (p_hdmi_mute_status) {
566                        // unmute -> mute
567                        DHL_AV_AudioMuteControl(eDHL_AUDIO_MUTE_HDMI, TRUE);
568                        p_is_hdmi_muted = TRUE;
569                }
570                else {
571                        // unmute -> unmute
572                        // do nothing
573                }
574        }
575}
576
577#endif // #if SUPPORT_HDMI_OUTPUT
578
579
580
581
582
583#if COMMENT
584____MLInfo____(){}
585#endif
586
587/*
588        Audio Multi-Lingual
589
590        ÀϹÝÀûÀÎ ±â´É:
591        - ä³Î Æ©´×½Ã ¿©·¯°³ÀÇ audio ½ºÆ®¸²ÀÌ Àִ ä³ÎÀÎ °æ¿ì
592          ƯÁ¤ ¼±È£ ¾ð¾î¸¦ °¡Áø audio ¼±Åà Àç»ýÇϱâ
593       
594        - ¸Þ´º, ¶Ç´Â RCU buttonÀ» ÀÌ¿ëÇÏ¿© ƯÁ¤ audio stream Àç»ýÇϱâ
595        - RCU buttonÀ» ÀÌ¿ëÇÏ¿© ´ÙÀ½ available audio stream Àç»ýÇϱâ
596*/
597
598static DMW_AudioElement *p_ml_info_table;  // °¡Àå ÃÖ±Ù¿¡ Á¶È¸ÇÑ ML Info Table
599static int               p_num_ml_info_table;    // À§ MLInfoTableÀÇ item °¹¼ö
600
601static DHL_OS_SEMA_ID   p_ml_sem;
602        //
603        // À§ MLInfo¿¡ Á¢±ÙÇϱâ À§ÇØ »ç¿ëÇÏ´Â mutex
604
605
606static int p_cur_aud_pid;
607        // ÇöÀç µðÄÚµù ÁßÀÎ ¿Àµð¿ÀÀÇ Audio Pid
608        // Autoscan µµÁß¿¡ 'SelectAudioStream' noti°¡ ºÒ¸®´Â °æ¿ì¿¡´Â
609        // ÀÌ °ªÀº ½ÇÁ¦·Î µðÄÚµùµÇ´Â °ªÀº ¾Æ´Ô.
610
611static UINT32 p_actual_aud_lang;
612        // cafrii 070430 add
613        // ½ÇÁ¦·Î Æ©´× µÇ¾î Ãâ·Â ÁßÀÎ audio language code
614        // Autoscan µµÁß¿¡ 'SelectAudioStream' noti°¡ ºÒ¸®´Â °æ¿ì¿¡´Â
615        // ÀÌ °ªÀº ½ÇÁ¦·Î µðÄÚµùµÇ´Â °ªÀº ¾Æ´Ô.
616
617
618#if USE_LANG_ID_FOR_AUDIO_SELECTION
619        static APP_AUDIO_LANG_ID p_audio_user_lang_id;
620                // user's preferred audio language ID
621#else
622        static UINT32 p_audio_user_lang_code;
623                // user's preferred audio language code
624#endif
625       
626
627/*
628//  App_AudioGetMLInfo:
629//
630//  - ¸Þ´º¿¡¼­ Preferred audio¸¦ º¯°æÇÑ °æ¿ì audio¸¦ ¹Ù·Î Àû¿ëÇÒ ¶§¿¡ È£Ãâ
631//  - MTS buttonÀ¸·Î audio¸¦ ¼±ÅÃÇÒ ¶§¿¡ È£Ãâ
632//
633//  ÇÔ¼ö ÀÎÀÚ´Â ¸ðµÎ [OUT] ¿ëµµÀ̰í, ML Á¤º¸¿Í ML °¹¼ö¸¦ ¸®ÅÏÇÑ´Ù.
634//  pCurrentIndex ´Â ppMLInfo Áß¿¡¼­ ¸î¹øÂ° ¿Àµð¿À°¡ ÇöÀç ¼Ò¸®°¡ ³ª°í ÀÖ´Â ¿Àµð¿ÀÀÎÁö¸¦
635//  ¾Ë·ÁÁØ´Ù.  (0 <= *pCurrentIndex < *numCount)
636//
637*/
638STATUS App_AudioGetMLInfo(DMW_AudioElement **ppMLInfo, int *numCount, int *pCurrentIndex)
639{
640        STATUS status = statusOK;
641        int i, currentIndex = -1;
642        int temp;
643        int program_number;
644        BOOL bVctNeeded=FALSE;
645        DST_CURCHANNEL ChannelInfo;
646        ProgramAVInfo *av;
647
648        dprint(0, "App_AudioGetMLInfo()\n");
649       
650        if (p_ml_sem)
651                DHL_OS_TakeSemaphore(p_ml_sem, DHL_TIMEOUT_FOREVER);
652       
653        if (p_ml_info_table)
654        {
655                // ÀÌÀü¿¡ ÀÌ ÇÔ¼ö°¡ ºÒ·Á¼­ ¸Þ¸ð¸®°¡ ÇÒ´çµÇ¾î ÀÖ´Â »óÅÂÀÓ..
656                DMW_EPG_FreeMLInfo(p_ml_info_table);
657                p_ml_info_table = NULL;
658                p_num_ml_info_table = 0;
659        }
660       
661        // ¿ì¼± ¼øÀ§´Â
662        // 1. PMT       2. VCT
663        // PMT¿¡ ¾øÀ»°æ¿ì³ª, ErrorÀϰæ¿ì¿¡ VCT¿¡¼­ ã´Â´Ù.
664        // PMT ¿Í VCTÀÇ Á¤º¸¸¦ ¼­·Î MergeÇÏÁö´Â ¾Ê´Â´Ù.
665        // !) IF.  PMT¿¡ 2°³ÀÇ AudioÁ¤º¸°¡ ÀÖ´Ù°í µÇ¾î Àִµ¥, 1°³ÀÇ AudioÁ¤º¸¸¸ À¯È¿ÇÒ °æ¿ìµµ PMTÀÇ Á¤º¸¸¦ »ç¿ëÇÑ´Ù.
666        // UnKnownÀÇ Á¤º¸´Â ¹«½ÃÇÑ´Ù.
667        //
668       
669        av = Dmc_LockAVMutex();
670       
671        if (av->pmt == NULL) {
672                bVctNeeded=TRUE;
673        }
674       
675        if(!bVctNeeded) {
676                status = DMW_EPG_GetMLInfoInPMT(av->pmt, &p_ml_info_table, &p_num_ml_info_table);
677               
678                // À§ API´Â statusOK°¡ ¸®ÅϵǾ MLÁ¤º¸°¡ ¾øÀ» ¼ö ÀÖ´Ù. ¸®ÅϰªÀ» Á¶Á¤ÇØÁÖÀÚ.
679                if (status == statusOK && p_ml_info_table == NULL)
680                        status = statusNotFound;
681       
682                // PMT¿¡¼­ ReturnµÇ¾îÁø langCode°¡ ValidÇÑÁö È®ÀÎ
683                if (status) {
684                        dprint(0, "!! MlInfo from PMT error %d..\n", status);
685                        bVctNeeded = TRUE;
686                }
687                else {
688                        bVctNeeded = FALSE;
689                        for (i=0; i<p_num_ml_info_table; i++)
690                        {
691                                if (p_ml_info_table[i].ISO639_LanguageCode == 0 ||
692                                        p_ml_info_table[i].ISO639_LanguageCode == 0x202020) {
693                                        // PMTÀÇ Audio_Info¿¡ InvalidÇÑ Á¤º¸°¡ ÀÖ´Ù.
694                                        // ÀÌÁ¤º¸ÀÇ °æ¿ì´Â PMT¿¡¼­ Á¶»çÇØ¼­ ä¿ö ³Ö´Â´Ù.
695                                        dprint(0, "!! MlInfo[%d]'s langCode NULL\n", i);
696                                        bVctNeeded = TRUE;
697                                        break;
698                                }
699                        }
700                }
701        }
702       
703        Dmc_UnlockAVMutex();
704
705        if (bVctNeeded)
706        {
707                xvctPtr_t vct = NULL;
708                xvctChannelPtr_t vctChannel = NULL;
709                        // cafrii 050712 add default NULL
710
711                status = p_get_vct_info(&vct);
712               
713                if (status || vct == NULL) {
714                        dprint(0, "!! VCT DownLoad Error %d\n", status);
715                        //status = statusNotFound;
716                        // 070718 fix
717                        // vct°¡ ¾ø´õ¶óµµ PMT¸¸À¸·Î ML list¸¦ »ý¼ºÇÒ ¼ö Àֱ⠶§¹®¿¡
718                        //  error·Î ¸®ÅÏÇÏ¸é ¾ÈµÊ.
719                        goto label_vct_done;
720                }
721
722                if(App_Ucm_GetCurChInfo(&ChannelInfo) != statusOK)
723                        dprint(0, "!! Get App Channel Info Err \n");
724
725                program_number = ChannelInfo.nProgramNumber;
726
727                for (i=0; i<vct->numChannels; i++) {
728                        if (vct->channel[i].program_number == program_number) {
729                                vctChannel = &vct->channel[i];
730                                break;
731                        }
732                }
733
734                if (vctChannel == NULL) {
735                        dprint(0, "!! __Program number #%d not found in vct\n", program_number);
736                        goto label_vct_done;
737                }
738               
739                // PMT¿ì¼±À̱⠶§¹®¿¡, PMT¿¡¼­ InvalidÀÎ °æ¿ì¸¸ ã¾Æ¼­ Ãß°¡ÇÑ´Ù.
740                // ´Ü, PMT¿¡ Á¤º¸°¡ Çϳªµµ Á¸ÀçÇÏÁö ¾ÊÀ» °æ¿ì¿¡´Â VCTÀÇ Á¤º¸¸¦ ³ªÅ¸³½´Ù.
741                if (!p_num_ml_info_table) 
742                {
743                        status = DMW_EPG_GetMLInfoInVct(vctChannel, &p_ml_info_table, &p_num_ml_info_table);
744                } 
745                else 
746                {
747                        // vct¿¡¼­ °¡Á®¿Â mlInfo´Â ¾îµð±îÁö³ª Àӽà ¿ëµµÀÌ´Ù. »ç¿ë ÈÄ free½ÃŲ´Ù.
748                        DMW_AudioElement *mlInfoVct = NULL;
749                        int mlCountVct = 0;
750
751                        status = DMW_EPG_GetMLInfoInVct(vctChannel, &mlInfoVct, &mlCountVct);
752
753                        // PMTÀÇ ml infoÀÇ ºÎÁ·ÇÑ ºÎºÐÀ» vct·ÎºÎÅÍ Ã¤¿î´Ù.
754                        for (i=0; i<p_num_ml_info_table; i++)
755                        {
756                                // PMTÀÇ ml Á¤º¸°¡ NULL ÀÎ °æ¿ì,
757                                if (p_ml_info_table[i].ISO639_LanguageCode == 0 ||
758                                        p_ml_info_table[i].ISO639_LanguageCode == 0x202020) 
759                                {
760                                        // VCTÀÇ ml¿¡¼­ ã¾Æ¼­ º¸ÃæÇÑ´Ù.
761                                        for (temp=0; temp<mlCountVct; temp++)
762                                        {
763                                                // VCTÀÇ ml¿¡µµ ¿ª½Ã NULLÀÏ ¼öµµ ÀÖÀ½¿¡ ÁÖÀÇ..
764                                                if (p_ml_info_table[i].elementaryPid == mlInfoVct[temp].elementaryPid &&
765                                                        mlInfoVct[temp].ISO639_LanguageCode != 0 &&
766                                                        mlInfoVct[temp].ISO639_LanguageCode != 0x202020) 
767                                                {
768                                                        UINT32 langCode;
769                                                        langCode = p_ml_info_table[i].ISO639_LanguageCode = 
770                                                                                                mlInfoVct[temp].ISO639_LanguageCode;
771                                                        dprint(0, "   >> replace apid %d with langCode '%s'\n", 
772                                                                        p_ml_info_table[i].elementaryPid,
773                                                                        p_aud_lang_codestr(langCode, 0));
774                                                }
775                                        }
776                                }
777                        }
778                        DMW_EPG_FreeMLInfo(mlInfoVct);
779                        mlInfoVct = NULL;  mlCountVct = 0;
780                }
781
782label_vct_done:
783
784                // cafrii 060619 add new vct sourcing
785                //Dmc_FreeAtscTable(&vct);
786                p_free_vct_info(&vct);
787
788        }
789       
790        dprint(0, "------ total %d audio streams ------\n", p_num_ml_info_table);
791       
792        // ÀÌÁ¦ ÇöÀç ¿Àµð¿À¿¡ ÇØ´çÇÏ´Â langCode¸¦ ¼±ÅÃ.
793        currentIndex = -1;
794        for (i=0; i<p_num_ml_info_table; i++)
795        {
796                UINT32 langCode = p_ml_info_table[i].ISO639_LanguageCode;
797               
798                // Áö±Ý Àç»ýÁßÀÎ ¿Àµð¿À¿Í µ¿ÀÏÇÑ Pid ¶ó¸é
799                // ¸Þ´º¿¡¼­ À̰ÍÀ» µðÆúÆ®·Î ¼±ÅÃÇØ Áà¾ß ÇÑ´Ù.
800                //
801                if (p_cur_aud_pid == p_ml_info_table[i].elementaryPid)
802                {
803                        currentIndex = i;
804
805                        // Updated by Chjeon 2007.09.21
806                        status = statusOK;
807                }
808
809                dprint(0, "   %c[%d] pid 0x%x (%d), type %d, lang 0x%x, '%s' \n", 
810                                currentIndex == i ? '+' : ' ',   // <- ÇöÀç Àç»ýÁßÀÎ ¿Àµð¿À..
811                                i, 
812                                p_ml_info_table[i].elementaryPid,
813                                p_ml_info_table[i].elementaryPid,
814                                p_ml_info_table[i].audioType,
815                                langCode, p_aud_lang_codestr(langCode, 0));
816        }
817        dprint(0, "\n");
818
819        if (currentIndex < 0) {
820                dprint(0, "!! cannot find current AudioIndex.. pid %d\n", p_cur_aud_pid);
821
822                // cafrii 070803 change
823                //  caller¿¡°Ô ÀÌ »ç½ÇÀ» ±×´ë·Î Å뺸Çϰí, ÇÊ¿äÇϸé caller°¡ Á¶Ä¡¸¦ Çϵµ·Ï ÇÑ´Ù.
824                //currentIndex = 0;
825        }
826       
827        if (ppMLInfo) 
828                *ppMLInfo = p_ml_info_table;
829        if (numCount)
830                *numCount = p_num_ml_info_table;
831        if (pCurrentIndex)
832                *pCurrentIndex = currentIndex;
833
834        if (p_ml_sem)
835                DHL_OS_GiveSemaphore(p_ml_sem);
836               
837        return status;
838}
839
840
841//---------------------------------------------
842//  App_AudioChangeMultiLingual
843//
844//  »ç¿ëÀÚ°¡ ¸Þ´º¿¡¼­ MultiLingual ¾ð¾î¸¦ º¯°æÇÒ ¶§ ¸¶´Ù È£ÃâµÈ´Ù.
845//  nIndex´Â »ç¿ëÀÚ°¡ ¸Þ´º¿¡¼­ ¼±ÅÃÇÑ Ç׸ñÀÇ indexÀÌ´Ù.
846//  ÀÌ °ªÀº ML ¸Þ´º ÇÁ·¹ÀÓ ÃʱâÈ­ ÇÒ ¶§ App_AudioGetMLInfo ÇÔ¼ö¿¡¼­
847//  °¡Á®°¬´ø ±× ML Á¤º¸ ¹è¿­ÀÇ index¿Í µ¿ÀÏÇÑ ¼ø¼­ÀÌ´Ù.
848//
849static int App_AudioChangeMultiLingual(int nIndex)
850{
851        // nIndex´Â ¹Ì¸® App_AudioGetMLInfo ÇÔ¼ö¸¦ ÀÌ¿ëÇØ¼­
852        // ¾ò¾îµÐ MLInfoTable ¹è¿­ÀÇ index.
853        //
854        int err;
855       
856        int audioPid;
857        UINT32 langCode;
858        tDHL_AudioCodingType audioType;
859       
860        ProgramAVInfo program;
861
862        // ¾Æ³¯·Î±× »óÅ À̰ųª,
863        // pmt ¾øÀÌ vct¸¸À¸·Î Æ©´×ÀÌ µÈ ºñ Á¤»óÀûÀÎ °æ¿ìÀ̰ųª,
864        // pmt¿¡ audio streamÀÌ Çϳªµµ ¾ø´Â video only source ¶ó¸é
865        // ÀÌ ±â´ÉÀÌ µ¿ÀÛÇÏÁö ¾Ê´Â´Ù.
866        //
867        Dmc_GetCurrentProgramInfo(&program);
868       
869        if (program.active == 0 || program.analog) {
870                dprint(0, "!! current DTV is not active or analog mode\n");
871                return statusInvalidState;
872        }
873       
874        if (p_ml_info_table == NULL || nIndex < 0 || nIndex >= p_num_ml_info_table)
875        {
876                dprint(0, "!! AudioMLInfo NULL or index %d invalid (numML = %d)\n",
877                                                nIndex, p_num_ml_info_table);
878                return statusError;
879        }
880       
881        audioPid  = p_ml_info_table[nIndex].elementaryPid;
882        langCode  = p_ml_info_table[nIndex].ISO639_LanguageCode;
883        audioType = p_ml_info_table[nIndex].audioType;
884       
885        if (audioPid == 0) {
886                dprint(0, "!! App_ChangeMultiLingual(%d) err, audio stream not found\n", nIndex);
887                return statusNotFound; 
888        }
889#if 0
890        //iskang 081112. delete.
891        //Á¾Àü¿¡´Â MW audio tuning¿¡ ÀÖ¾î audio pid¸¦ µ¿±âÈ­Çϸç
892        //MW/App¿¡¼­ üũ ÇÏ´Â ºÎºÐÀÌ ÀÖ¾úÀ½.
893        //MW¿¡¼­ AV program info update°¡ »¡¸® µÇÁö ¾Ê´Â ¹®Á¦ ÀÖÀ½.
894        //MW¿¡¼­ audio frame count checkÇÏ´Ù°¡ err°¡ ³ª¸é audio pid¸¦ 0À» ¸¸µë.
895        //µû¶ó¼­ MWÀÇ audio pid¸¦ Âü°íÇÏ´Â ºÎºÐÀ» ¾ø¾Ö user°¡ ¼±ÅÃÇÏ´Â audio¸¦
896        //tunning ÇÒ ¼ö ÀÖµµ·Ï ¼öÁ¤ÇÔ.
897        if (program.audio_pid == audioPid) {
898                dprint(0, " same audio.. no operation\n");
899                return statusNoResponse;
900        }
901#endif 
902        dprint(0, "ChangeAudStream pid %d, type %d\n",  audioPid, audioType);
903       
904        // pcr pid¸¦ 0À¸·Î ÁöÁ¤Çϸé ÇöÀç »ç¿ëÁßÀÎ PID¸¦ »ç¿ëÇÏ°Ô µÈ´Ù.
905        err = Dmc_ChangeAudioStream(audioPid, 0, audioType);
906       
907        p_cur_aud_pid = audioPid;
908       
909        dprint(0, "  Selected LangCode: 0x%x,  '%s'  \n", 
910                        langCode, p_aud_lang_codestr(langCode, 0));
911
912#if TODO
913        p_audio_user_lang_code = langCode;  // »ç¿ëÀÚ°¡ ¸Þ´º¿¡¼­ ¼±ÅÃÇÑ ¾ð¾î
914       
915        if (0) // AudioUserLanguage¸¦ EEPROM¿¡ ÀúÀå
916        {
917                UINT8 data[4];
918                data[0] = (p_audio_user_lang_code >> 16) & 0xff;
919                data[1] = (p_audio_user_lang_code >>  8) & 0xff;
920                data[2] = (p_audio_user_lang_code >>  0) & 0xff;
921               
922                App_Write_EEPROM_8(OFFSET_SYSFILE_AudioLang1, data[0]);
923                App_Write_EEPROM_8(OFFSET_SYSFILE_AudioLang2, data[1]);
924                App_Write_EEPROM_8(OFFSET_SYSFILE_AudioLang3, data[2]);
925        }
926#endif
927
928        return err;
929
930}
931
932const char *App_AudioLangCodeStr(UINT32 code, char *buf)
933{
934        return p_aud_lang_codestr(code, buf);
935}
936
937
938#if COMMENT
939____MTS_Callback____(){}
940#endif
941
942/*
943        App_AudioSelectAudioStream:
944
945        notification callback from Channel MW
946        ÀÌ ÇÔ¼ö´Â ½ÇÁ¦·Î ä³Î Æ©´×À» ÇÒ ¶§ (µðÄÚµùÀ» ½ÃÀÛÇÒ ¶§) ºÒ¸®´Â ÇÔ¼öÀÌ´Ù.
947        »ç¿ë °¡´ÉÇÑ audio stream Áß¿¡¼­ °¡Àå ÀûÀýÇÑ audio¸¦ ¼±ÅÃÇÏ¿© ¸®ÅÏÇÑ´Ù.
948*/
949void App_AudioSelectAudioStream(AudioPidSelectParam *apsp)
950{
951        // g_App_AudioUserLanguageXX ¿Í ÀÏÄ¡ÇÏ´Â LanguageÀÇ audio¸¦ ¼±ÅÃÇÑ´Ù.
952        // ¾øÀ¸¸é primary audio¸¦ ¼±ÅÃÇÑ´Ù.
953        //
954        int i, err;
955        MPEG_PMT *pmt;
956        xvctChannelPtr_t vctch;
957        UINT32 languageCode = 0;
958        int serviceType;
959        UINT32 temp;
960       
961        int audioPid = 0;
962        tDHL_AudioCodingType audioType = eDHL_AUDIO_TYPE_AC3;
963       
964        UINT32 targetCode;
965
966        //dprint(0, "%s\n", __FUNCTION__);
967       
968        Dmc_LockAVMutex();
969
970        pmt = apsp->pmt;
971        vctch = apsp->vctChannel;
972       
973        // pmt°¡ NULLÀÎ °æ¿ì¿¡ ´ëÇÑ Channel¿¡ ´ëÇÑ Ã³¸®..       
974        // ÇöÀç MW´Â Null PMT streamµµ Áö¿øÇϰí ÀÖÀ½.
975        //
976        if (pmt == NULL && vctch == NULL) 
977        {
978                apsp->returnAudioPid = 0;
979                apsp->returnAudioType = eDHL_AUDIO_TYPE_UNKNOWN;
980
981                dprint(0, "!! %s: pmt %x, vctch %x\n", __FUNCTION__);
982                p_cur_aud_pid = 0;
983
984                Dmc_UnlockAVMutex();
985                return;
986        }
987
988        //PrintPMT(pmt);
989        DHL_AV_Query(eDHL_AV_QUERY_AUDIO_CAP, &temp);
990
991#if SUPPORT_AAC_AUDIO   
992        p_support_aac_audio_adts=(temp&(1<<eDHL_AUDIO_TYPE_AAC_ADTS))?TRUE:FALSE;
993        p_support_aac_audio_latm=(temp&(1<<eDHL_AUDIO_TYPE_AAC_LATM))?TRUE:FALSE;
994#else
995        p_support_aac_audio_adts=p_support_aac_audio_latm=0;
996#endif         
997
998#if SUPPORT_MPEG_AUDIO
999        /* TODO : mpeg¿¡ ´ëÇØ¼­´Â ¾ÆÁ÷ DHLÀÌ ¸íÈ®ÇÏÁö ¾ÊÀº °Í °°À½ */
1000        p_support_mpeg1_audio=(temp&(1<<eDHL_AUDIO_TYPE_MPEG_1))?TRUE:FALSE;
1001        p_support_mpeg2_audio=(temp&(1<<eDHL_AUDIO_TYPE_MPEG_2))?TRUE:FALSE;
1002#else
1003        p_support_mpeg1_audio=FALSE;
1004        p_support_mpeg2_audio=FALSE;
1005#endif 
1006
1007
1008        if (p_actual_aud_lang) 
1009        {
1010                targetCode = p_actual_aud_lang;
1011                //dprint(0, "use previous lang code 0x%x '%s'\n", targetCode, p_aud_lang_codestr(targetCode, 0));
1012        }
1013        else 
1014        {
1015        #if USE_LANG_ID_FOR_AUDIO_SELECTION
1016                //audio pref.°¡ auto modeÀ̸é... pmt¿¡¼­ ¾ò¾îÁö´Â ù¹øÂ°
1017                //audio¸¦ tunningÇÑ´Ù.
1018                if(p_audio_user_lang_id == APP_AUDIO_LANG_AUTO)
1019                        goto label_default;
1020
1021                // ã°íÀÚ ÇÏ´Â language code.
1022                targetCode = p_aud_lang_id2code(p_audio_user_lang_id);
1023        #else
1024                targetCode = p_audio_user_lang_code;
1025        #endif
1026        }
1027
1028
1029        // PMTÀÇ °¢ EL. streamµéÀ» µÚÁö¸é¼­ language code°¡ ÀÏÄ¡ÇÏ´Â ½ºÆ®¸²À» ã´Â´Ù.
1030        //
1031        // ãÀ» ´ë»óÀº 'targetCode' ÀÌ´Ù.
1032        //
1033        for (i=0; pmt && i<pmt->numStreams; i++)
1034        {
1035                MPEG_PMT_stream *stream = &(pmt->streams[i]);
1036
1037        #if 0
1038                if (stream->stream_type != StreamType_AC3Audio) // Audio°¡ ¾Æ´Ï¸é °Ç³Ê¶Ü..
1039                        continue;
1040        #else
1041                // cafrii 070718 add
1042                if (stream->stream_type == StreamType_AC3Audio)
1043                        audioType = eDHL_AUDIO_TYPE_AC3;
1044                else if (p_support_mpeg1_audio && stream->stream_type == StreamType_MPEG1Audio)
1045                        audioType = eDHL_AUDIO_TYPE_MPEG_1;
1046                else if (p_support_mpeg2_audio && stream->stream_type == StreamType_MPEG2Audio) // cafrii bugfix. MPEG2 audio
1047                        audioType = eDHL_AUDIO_TYPE_MPEG_2;
1048                else if (p_support_aac_audio_adts && stream->stream_type == StreamType_AACAudioADTS)
1049                        audioType = eDHL_AUDIO_TYPE_AAC_ADTS;
1050                else if (p_support_aac_audio_latm && stream->stream_type == StreamType_AACAudioLATM)
1051                        audioType = eDHL_AUDIO_TYPE_AAC_LATM;
1052                else  // À§¿¡ ¾î´À °Íµµ ÇØ´çµÇÁö ¾ÊÀ¸¸é pass.
1053                        continue;
1054        #endif
1055               
1056                if (stream->descriptor_length <= 0)
1057                        continue;
1058
1059                err = DLIB_PSI_GetLanguageCodeFromDescriptors(stream->descriptors, 
1060                                        stream->descriptor_length, 0, &languageCode, &serviceType);
1061                                       
1062                if (err) 
1063                        languageCode = 0;
1064
1065                //dprint(0, "    pmt stream[%d]: stream type 0x%x (%s), langCode 0x%x\n",
1066                //              i, stream->stream_type, p_aud_stream_type_string(stream->stream_type),
1067                //              languageCode);
1068                if (languageCode == 0)
1069                        continue;
1070
1071                if (p_is_same_lang_code(languageCode, targetCode))
1072                {
1073                        audioPid = stream->elementary_PID;
1074                        dprint(0, "Select preferred Audio: 0x%x (stream[%d]). lang 0%x '%s'\n",
1075                                                audioPid, i, languageCode,
1076                                                p_aud_lang_codestr(languageCode, 0));
1077                        break;
1078                }
1079        }
1080       
1081        if (audioPid)
1082        {
1083                apsp->returnAudioPid = audioPid;
1084                apsp->returnAudioType = audioType;
1085               
1086                p_cur_aud_pid = audioPid;
1087                p_actual_aud_lang = targetCode;
1088               
1089                goto label_exit;
1090        }
1091
1092        // PMT¿¡¼­ ¹ß°ßµÇÁö ¾ÊÀ¸¸é.. VCT¿¡¼­µµ ã¾Æº»´Ù.
1093        //
1094        // ãÀ» ´ë»óÀº 'targetCode' ÀÌ´Ù.
1095
1096        if (vctch)
1097        {
1098                DMW_AudioElement *mlInfo;
1099                int mlCount;
1100               
1101                dprint(0, "\t use vct data to find mlinfo '%s'\n",
1102                                        p_aud_lang_codestr(targetCode, 0));
1103
1104                // AC3ÀÎÁö, MPEG audio ÀÎÁö ±¸ºÐÇÒ ¼ö ÀÖ´Â ¹æ¹ýÀº?
1105                // ATSC specÀº AC3¸¸ Áö¿øÇϹǷΠÀÏ´Ü AC3¶ó°í °¡Á¤ÇÏÀÚ.
1106                //
1107                err = DMW_EPG_GetMLInfoInVctDescriptors(vctch->descriptors, vctch->descriptor_length,
1108                                                                                 &mlInfo, &mlCount);
1109                if (!err)
1110                {
1111                        for (i=0; i<mlCount; i++)
1112                        {
1113                                if (p_is_same_lang_code(mlInfo[i].ISO639_LanguageCode, targetCode)) {
1114                                        audioPid = mlInfo[i].elementaryPid;
1115                                        break;
1116                                }
1117                        }
1118                        DMW_EPG_FreeMLInfo(mlInfo);
1119                }
1120        }
1121
1122        if (audioPid)
1123        {
1124                apsp->returnAudioPid = audioPid;
1125                apsp->returnAudioType = eDHL_AUDIO_TYPE_AC3;
1126               
1127                p_cur_aud_pid = audioPid;
1128                p_actual_aud_lang = targetCode;
1129               
1130                goto label_exit;
1131        }
1132       
1133label_default:
1134
1135        // ¿øÇÏ´Â audio language°¡ ¾ø´Ù¸é, ¸Ç óÀ½ audio¸¦ µðÆúÆ®·Î ¼±ÅÃÇÑ´Ù.
1136        // ÀÌ ¼±ÅÃµÈ °ª ¿ª½Ã ¾îµò°¡¿¡ ±â¾ïÀ» ÇØ ³õ¾Æ¾ß Menu OSD¿¡ Ç¥½Ã°¡ °¡´ÉÇÏ´Ù.
1137        //
1138        for (i=0; pmt && i<pmt->numStreams; i++)
1139        {
1140                MPEG_PMT_stream *stream = &(pmt->streams[i]);
1141
1142                dprint(2,"###audio type = %d\n", stream->stream_type);
1143
1144                // cafrii 070718 add
1145                if (stream->stream_type == StreamType_AC3Audio)
1146                        audioType = eDHL_AUDIO_TYPE_AC3;
1147                else if (p_support_mpeg1_audio && stream->stream_type == StreamType_MPEG1Audio)
1148                        audioType = eDHL_AUDIO_TYPE_MPEG_1;
1149                else if (p_support_mpeg2_audio && stream->stream_type == StreamType_MPEG2Audio)
1150                        audioType = eDHL_AUDIO_TYPE_MPEG_2;
1151                else if (p_support_aac_audio_adts && stream->stream_type == StreamType_AACAudioADTS)
1152                        audioType = eDHL_AUDIO_TYPE_AAC_ADTS;
1153                else if (p_support_aac_audio_latm && stream->stream_type == StreamType_AACAudioLATM)
1154                        audioType = eDHL_AUDIO_TYPE_AAC_LATM;
1155                else  // À§¿¡ ¾î´À °Íµµ ÇØ´çµÇÁö ¾ÊÀ¸¸é pass.
1156                        continue;
1157               
1158                //if (stream->stream_type == StreamType_AC3Audio)
1159                {
1160                        audioPid = stream->elementary_PID;
1161
1162                        err = DLIB_PSI_GetLanguageCodeFromDescriptors(stream->descriptors, 
1163                                                stream->descriptor_length, 0, &languageCode, &serviceType);
1164                        if (err)
1165                                languageCode = 0;
1166
1167                        //dprint(0, "Select primary audio: 0x%x (stream[%d]). no userLang, '%s'\n",
1168                        //                      audioPid, i, p_aud_lang_codestr(languageCode, 0));
1169                        break;
1170                }
1171        }
1172
1173
1174        if (audioPid)
1175        {
1176                apsp->returnAudioPid = audioPid;
1177                apsp->returnAudioType = audioType;
1178               
1179                p_cur_aud_pid = audioPid;
1180                p_actual_aud_lang = languageCode;
1181               
1182                goto label_exit;
1183        }
1184
1185        // ¸¸¾à ¾Æ¹« Audioµµ ¾ø´Ù¸é ±×³É audioPid = 0 À» ¸®ÅÏ
1186        //
1187        apsp->returnAudioPid = 0;
1188        apsp->returnAudioType = eDHL_AUDIO_TYPE_UNKNOWN;
1189
1190        dprint(0, "!! %s: no audio\n", __FUNCTION__);
1191        p_cur_aud_pid = 0;
1192        p_actual_aud_lang = 0;
1193//      goto label_exit;
1194label_exit:
1195
1196        dprint(2,"###apsp->returnAudioPid=%d, apsp->returnAudioType=%d\n", apsp->returnAudioPid,apsp->returnAudioType);
1197
1198        Dmc_UnlockAVMutex();   
1199}
1200
1201
1202// ÀÌ ÇÔ¼ö´Â ¼øÀüÈ÷ µð¹ö±ë ¿ëµµÀÓ.
1203// ÇöÀçÀÇ app strategy¿Í´Â »ó°ü¾øÀÌ VCT¸¸ °Ë»çÇÏ´Â ¸ñÀû..
1204//
1205void App_PrintVctSapList(int program_number)
1206{
1207        STATUS err;
1208        xvctPtr_t vct;
1209        xvctChannelPtr_t vctch = NULL;
1210       
1211        DMW_AudioElement *mlInfo = NULL;
1212        int i, nCount;
1213       
1214        err = p_get_vct_info(&vct);
1215       
1216        if (err || vct==NULL) {
1217                dprint(0, "!! vct download err %d\n", err);
1218                return;
1219        }
1220       
1221        //PrintXvct(vct);
1222               
1223        for (i=0; i<vct->numChannels; i++)
1224        {
1225                if (vct->channel[i].program_number == program_number) {
1226                        vctch = &vct->channel[i];
1227                        break;
1228                }
1229        }
1230
1231        if (vctch)
1232        {
1233                err = DMW_EPG_GetMLInfoInVct(vctch, &mlInfo, &nCount);
1234               
1235                if (!err)
1236                {
1237                        dprint(0, "-------- %d Audio --------\n", nCount);
1238                        for (i=0; i<nCount; i++)
1239                        {
1240                                UINT32 code = mlInfo[i].ISO639_LanguageCode;
1241                                dprint(0, "  [%d] 0x%x, '%c%c%c'\n", 
1242                                        i, mlInfo[i].elementaryPid, (code>>16)&0xff, (code>>8)&0xff, code&0xff);
1243                        }
1244                }
1245                DMW_EPG_FreeMLInfo(mlInfo);
1246        }
1247        else
1248                dprint(0, "!! program number #%d not found in vct\n", program_number);
1249
1250        p_free_vct_info(&vct);
1251}
1252
1253
1254#if USE_LANG_ID_FOR_AUDIO_SELECTION
1255/*
1256        return TRUE if specified 'lang' exist and play.
1257*/
1258BOOL App_AudioSetPreferredLanguageId(APP_AUDIO_LANG_ID lang, BOOL bSaveNvRam)
1259{
1260        // ÇöÀç Ȥ½Ã ÀÌ audio°¡ ¾Æ´Ï°í, langÀÌ Á¸ÀçÇÑ´Ù¸é ¼±ÅÃ..
1261
1262        // ¸¸¾à Á¸ÀçÇÏÁö ¾Ê´Â´Ù¸é º¯°æÇÏÁö ¾ÊÀ½.
1263
1264        DMW_AudioElement *pMLInfo;
1265        int nAudioCount;
1266        int nCurIndex, targetIndex;
1267        UINT32 targetCode;
1268
1269        int i, err;
1270
1271        if (lang != APP_AUDIO_LANG_AUTO &&
1272                lang != APP_AUDIO_LANG_ENG &&
1273                lang != APP_AUDIO_LANG_SPA &&
1274                lang != APP_AUDIO_LANG_FRE &&
1275                lang != APP_AUDIO_LANG_KOR) {
1276                dprint(0, "!! invalid audio lang id %d\n", lang);
1277                return FALSE;
1278        }
1279
1280        // cafrii 060630 add
1281        if (p_audio_user_lang_id != lang) {
1282                // cafrii 060630 add
1283                // ÀúÀåµÈ audio pid·Î Æ©´×À» ½ÃµµÇÏ¸é ¾ÈµÇ¹Ç·Î
1284                // ¸ðµÎ invalidate..
1285                DMW_CDB_InvalidateAllPidInfo();
1286        }
1287
1288        p_audio_user_lang_id = lang;
1289
1290        if (bSaveNvRam)
1291        {
1292                p_aud_nvm_param.preferedlang = p_audio_user_lang_id;
1293                App_NVM_SaveModuleParam(eAPP_NVR_AUDIO, &p_aud_nvm_param);
1294        }
1295        err = App_AudioGetMLInfo(&pMLInfo, &nAudioCount, &nCurIndex);
1296        if (err || pMLInfo == NULL) {
1297                // ÇöÀç tuning ÁßÀÌ ¾Æ´Ï°Å³ª,
1298                // ¾î¶² ÀÌÀ¯·Î PMT/VCT µîÀÇ tableÀ» ¸ø¹ÞÀº °æ¿ì.
1299                dprint(0, "!! No audio ML info\n");
1300                return FALSE;
1301        }
1302       
1303        //auto modeÀ̸é ã¾ÆÁö´Â ù¹øÂ° audio¸¦ ¼±ÅÃÇÑ´Ù.
1304        if (p_audio_user_lang_id == APP_AUDIO_LANG_AUTO)
1305        {
1306                App_AudioChangeMultiLingual(0);
1307                dprint(0, "selected AUTO audio active\n");
1308                return TRUE;
1309        }
1310       
1311        targetCode = p_aud_lang_id2code(lang);
1312        targetIndex = -1;
1313        for (i=0; i<nAudioCount; i++) {
1314                if (p_is_same_lang_code(pMLInfo[i].ISO639_LanguageCode, targetCode)) {
1315                        targetIndex = i;
1316                        break;
1317                }
1318        }
1319
1320        if (targetIndex >= 0)
1321        {
1322                // cafrii 070803 comment
1323                //  nCurIndex ´Â -1 µîÀÇ invalid ÇÑ °ªÀÏ ¼ö ÀÖ´Ù.
1324                //  no audio pes ÀÎ invalid stream À̰ųª, ¾ÈÅ׳ª ÄÉÀ̺íÀÌ µµÁß¿¡ ºüÁø °æ¿ì..
1325                //
1326                if (targetIndex != nCurIndex) {
1327                        // preferred audio found. change it!
1328                        dprint(0, "Change audio ML [%d] -> [%d]\n", nCurIndex, targetIndex);
1329                        App_AudioChangeMultiLingual(targetIndex);
1330                        return TRUE;
1331                }
1332                dprint(0, "selected audio %d already active\n", lang);
1333                return TRUE;
1334        }
1335
1336        dprint(0, "selected audio %d not found. no change.\n", lang);
1337       
1338        return FALSE;
1339}
1340
1341
1342APP_AUDIO_LANG_ID App_AudioGetPreferredLanguageId()
1343{
1344        return p_audio_user_lang_id;
1345}
1346
1347
1348#else // USE_LANG_ID_FOR_AUDIO_SELECTION
1349
1350
1351// index Ãß°¡ : °°Àº Audio°¡ ÀÖÀ»°æ¿ì, ¼±Åð¡´ÉÇÏ°Ô Çϱâ À§ÇÔ.
1352// -1ÀÏ °æ¿ì ¹«½Ã
1353BOOL App_AudioSetPreferredLanguageCode(UINT32 langcode, int index, BOOL bSaveNvRam)
1354{
1355        DMW_AudioElement *pMLInfo;
1356        int nAudioCount;
1357        int i, nCurIndex, targetIndex;
1358        UINT32 targetCode;
1359        STATUS err;
1360
1361        if (p_audio_user_lang_code != langcode) {
1362                // cafrii 060630 add
1363                // ÀúÀåµÈ audio pid·Î Æ©´×À» ½ÃµµÇÏ¸é ¾ÈµÇ¹Ç·Î
1364                // ¸ðµÎ invalidate..
1365                DMW_CDB_InvalidateAllPidInfo();
1366        }
1367
1368        p_audio_user_lang_code = langcode;
1369
1370#if TODO
1371        if (bSaveNvRam) {
1372                UINT8 data[4];
1373                data[0] = (p_audio_user_lang_code >> 16) & 0xff;
1374                data[1] = (p_audio_user_lang_code >>  8) & 0xff;
1375                data[2] = (p_audio_user_lang_code >>  0) & 0xff;
1376
1377               
1378                App_Write_EEPROM_8(OFFSET_SYSFILE_AudioLang1, data[0]);
1379                App_Write_EEPROM_8(OFFSET_SYSFILE_AudioLang2, data[1]);
1380                App_Write_EEPROM_8(OFFSET_SYSFILE_AudioLang3, data[2]);
1381        }
1382#endif
1383
1384        err = App_AudioGetMLInfo(&pMLInfo, &nAudioCount, &nCurIndex);
1385
1386        // err°¡ ReturnµÇµµ, Audio Á¤º¸´Â ÀÖÀ» ¼ö ÀÖ´Ù.
1387        if ((err || pMLInfo == NULL) && nAudioCount < 1) {
1388                // ÇöÀç tuning ÁßÀÌ ¾Æ´Ï°Å³ª,
1389                // ¾î¶² ÀÌÀ¯·Î PMT/VCT µîÀÇ tableÀ» ¸ø¹ÞÀº °æ¿ì.
1390                dprint(0, "!! No audio ML info\n");
1391                return FALSE;
1392        }
1393
1394        targetCode = langcode;
1395        targetIndex = -1;
1396       
1397        for (i=0; i<nAudioCount; i++) {
1398                if (p_is_same_lang_code(pMLInfo[i].ISO639_LanguageCode, targetCode)) {
1399                        // index -1ÀÏ °æ¿ì´Â ¹«½Ã.
1400                        if ((index == -1) || (i == index)) {
1401                                targetIndex = i;
1402                                break;
1403                        }
1404                }
1405        }
1406
1407        // LanguageCode°¡ 0ÀÏ °æ¿ì..
1408        if (targetIndex == -1 && langcode == 0) {
1409                targetIndex = index;
1410        }
1411
1412        if (targetIndex >= 0 && targetIndex != nCurIndex) {
1413                // preferred audio found. change it!
1414                dprint(0, "Change audio ML [%d] -> [%d]\n", nCurIndex, targetIndex);
1415                App_AudioChangeMultiLingual(targetIndex);
1416                return TRUE;
1417        }
1418
1419        dprint(0, "selected audio 0x%06x not found. no change.\n", langcode);
1420       
1421        return FALSE;
1422}
1423
1424#endif // USE_LANG_ID_FOR_AUDIO_SELECTION
1425
1426
1427//---------------
1428//  bChangeToNext °¡ TRUEÀÌ¸é ´ÙÀ½ audio·Î changeÇϰí
1429//  FALSEÀ̸é ÇöÀç audio Á¤º¸¸é º¸¿©ÁØ´Ù.
1430//
1431// ÀÌ °÷¿¡´Ù banner draw Äڵ带 ³ÖÀ» ¼öµµ ÀÖ°í
1432// caller°¡ return°ªÀ» ¹Þ¾Æ¼­ ±×·Áµµ µÈ´Ù.
1433// ¿¡·¯ ¹ß»ý½Ã NULL ¸®ÅÏ. ÀÌ ¶§´Â "No Info" µî°ú °°Àº ¸Þ½ÃÁö ó¸® ÇÊ¿ä.
1434//
1435char *App_AudioShowOrChangeMTS(BOOL bChangeToNext)
1436{
1437        DMW_AudioElement *pMLInfo;
1438        int nAudioCount;
1439        int nCurIndex;
1440       
1441        UINT32 code_selected;
1442        int index;
1443
1444        int i, err;
1445        char *str;
1446        static char buf[30];
1447
1448        dprint(0, "%s\n",__FUNCTION__);
1449       
1450        err = App_AudioGetMLInfo(&pMLInfo, &nAudioCount, &nCurIndex);
1451       
1452        dprint(0, "Audio CurIndex = %d \n", nCurIndex);
1453       
1454        if (err || pMLInfo == NULL) {
1455                // ÇöÀç tuning ÁßÀÌ ¾Æ´Ï°Å³ª,
1456                // ¾Æ³¯·Î±× »óÅ À̰ųª,
1457                // ¾î¶² ÀÌÀ¯·Î PMT/VCT µîÀÇ tableÀ» ¸ø¹ÞÀº °æ¿ì..
1458                dprint(0, "No audio info err %d\n", err);
1459                return NULL;
1460        }
1461
1462        if (nCurIndex < 0 || nCurIndex >= nAudioCount) 
1463        {
1464                ProgramAVInfo program;
1465
1466                dprint(0, "!! invalid current audio index %d\n", nCurIndex);
1467
1468                // cafrii 070803 change
1469                //  ÇöÀç audio pid°¡ list »ó¿¡ ¾ø°Å³ª audio decodingÀÌ Á¤ÁöÇÑ °æ¿ì..
1470                //return NULL;
1471
1472                // pmt ¾øÀÌ vct¸¸À¸·Î Æ©´×ÀÌ µÈ ºñ Á¤»óÀûÀÎ °æ¿ìÀ̰ųª,
1473                Dmc_GetCurrentProgramInfo(&program);
1474
1475                // weak signal ÀÎ °æ¿ì¶ó¸é ÀϽÃÀûÀ¸·Î audio change°¡ ºÒ°¡´É.
1476                // ±×·¯³ª ML info list´Â À¯È¿ÇÏ´Ù. (epg¿¡ ³²¾Æ ÀÖ´Â Á¤º¸ÀÓ)
1477                if (program.active == 0 || program.analog) {
1478                        dprint(0, "!! channel viewing is stopped now..\n");
1479                        return NULL; // "No Info" µî°ú °°Àº ³»¿ë Ç¥½Ã..
1480                }
1481
1482                // ¹«½¼ ÀÌÀ¯¿¡¼­ audio¸¸ Á¤ÁöÇØ ¹ö¸° °æ¿ì¶ó¸é
1483                // °­Á¦·Î audio¸¦ change¸¦ Çϵµ·Ï ÇÑ´Ù..
1484                dprint(0, "!! forced to change audio\n");
1485                nCurIndex = -1;  // µÚ¿¡¼­ +1À» ÇØ¼­ ù¹øÂ° audio·Î Àç»ýÇÒ °ÍÀÓ..
1486                bChangeToNext = TRUE;
1487        }
1488
1489        if (bChangeToNext) {
1490                int nNextIndex = (nCurIndex+1)%nAudioCount;
1491                err = App_AudioChangeMultiLingual(nNextIndex);
1492                if (err) 
1493                        dprint(0, "!! Cannot change to next audio (idx %d)\n", nNextIndex);
1494                        // change ½ÇÆÐ.. ±×³É ÇöÀç audio¸¦ º¸¿©ÁÖÀÚ.
1495                else
1496                        nCurIndex = nNextIndex;
1497        }
1498
1499        // userData¸¦ language index ¿ëµµ·Î ºô·Á¼­ »ç¿ëÇϹǷΠÃʱâÈ­¸¦ ½ÃŲ´Ù.
1500        for (i=0; i<nAudioCount; i++)
1501                pMLInfo[i].userData = 0;
1502
1503        // ÀÌÁ¦ index¸¦ ºÎ¿©ÇÑ´Ù.
1504
1505        code_selected = pMLInfo[nCurIndex].ISO639_LanguageCode;
1506        index = 0;
1507       
1508        for (i=0; i<nAudioCount; i++)
1509        {
1510                UINT32 code;
1511                code = pMLInfo[i].ISO639_LanguageCode;
1512
1513                // ¼±ÅÃµÈ code°¡ language table¿¡¼­ ¹ß°ßµÇÁö ¾Ê´Â °æ¿ì..
1514                if (p_aud_lang_code2name(code_selected) == NULL ||
1515                        strcmp("Unknown", p_aud_lang_code2name(code_selected)) == 0)
1516                {
1517                        if (p_aud_lang_code2name(code) == NULL ||
1518                                strcmp("Unknown", p_aud_lang_code2name(code)) == 0)
1519                                pMLInfo[i].userData = ++index;
1520                }
1521                else // ¼±ÅÃµÈ audio°¡ lang table¿¡ Á¸ÀçÇÏ´Â °æ¿ì..
1522                {
1523                        if (p_is_same_lang_code(code, code_selected))
1524                        {
1525                                pMLInfo[i].userData = ++index;
1526                        }
1527                }
1528        }
1529
1530        str = p_aud_lang_code2name(code_selected);
1531
1532        if (str && strcmp(str, "Unknown")) {
1533                // eng/spa/freÀÇ °æ¿ì´Â Çϳª¸¸ ÀÖ´Â °æ¿ì´Â ¹øÈ£¸¦ ¾ÈºÙÀδÙ.
1534                // ex:
1535                // eng°¡ ÇѰ³ÀÎ °æ¿ì: English
1536                // spa°¡ µÎ°³ÀÎ °æ¿ì: Spanish 1, Spanish 2
1537       
1538                if (pMLInfo[nCurIndex].userData && index > 1)
1539                        sprintf(buf, "%s %d", str, pMLInfo[nCurIndex].userData);
1540                else
1541                        sprintf(buf, "%s", str);
1542        }
1543        else {
1544                // eng/spa/fre°¡ ¾Æ´Ñ °æ¿ì¿¡´Â óÀ½ºÎÅÍ 1, 2, ¹øÈ£°¡ ºÙ´Â´Ù.
1545                // ex:  Audio 1, Audio 2, ...
1546#if 0//SUPPORT_NEWBY
1547                sprintf(buf, "±âŸ ¾ð¾î %d", pMLInfo[nCurIndex].userData);
1548#else
1549                sprintf(buf, "Audio %d", pMLInfo[nCurIndex].userData);
1550#endif
1551        }
1552       
1553        // TODO: After porting debug
1554        //App_PrintTextMessageBox(buf, 20);
1555       
1556        // ÁÖÀÇ!
1557        //  pMLInfo´Â free ´ë»óÀÌ ¾Æ´Ï´Ù.
1558       
1559        return buf;
1560}
1561
1562
1563/*
1564                Audio stopÀÌ µÉ ¶§ ºÒ¸®´Â ÇÔ¼ö..
1565
1566                1. ä³ÎÀÌ º¯°æµÉ ¶§¿¡´Â ¹Ýµå½Ã ºÒ·Á¾ß ÇÔ.
1567                   ÀÚµ¿À¸·Î È£ÃâµÊ.
1568                2. AutoScanÀÌ Á¾·áµÈ ÈÄ¿¡´Â ¼öµ¿À¸·Î ¹Ýµå½Ã È£ÃâÇØÁà¾ß ÇÔ.
1569*/
1570void App_AudioNotifyStop(AudioDecodeStopParam *param)
1571{
1572        // paramÀº Àý´ë ¼Õ´ëÁö ¾Ê´Â´Ù.
1573
1574        dprint(0, "%s..... audio stop (pid 0x%x)\n", __FUNCTION__, p_cur_aud_pid);
1575#if AUDIO_PORTING       
1576        if(DHL_FE_GetCurAtscAndNtscAudio()==DHL_TURNER_MODE_ATSC){
1577                p_cur_aud_pid = 0;
1578                p_actual_aud_lang = 0;
1579        }
1580#else
1581        p_cur_aud_pid = 0;
1582        p_actual_aud_lang = 0;
1583#endif
1584}
1585
1586
1587/*************************************************************************
1588        Function : App_AudioNotifyStart
1589        Author : Chan Hun Jeon
1590        Date : 2007.09.17
1591        Description :
1592        - Audio Start ½Ã¿¡ È£Ã⠵Ǵ ÇÔ¼ö.
1593        - ÇöÀç Àç»ýÁßÀÎ AudioPid¸¦ ¼³Á¤
1594        - MTS bugfix. ( p_cur_aud_pid °ªÀÌ °»½Å ¾ÈµÇ´Â ¹®Á¦)
1595**************************************************************************/
1596void App_AudioNotifyStart(AudioDecodeStartParam *param)
1597{
1598        dprint(0, "%s..... audio start (pid 0x%x)\n", __FUNCTION__, param->audPid);
1599
1600#if AUDIO_PORTING       
1601        if(DHL_FE_GetCurAtscAndNtscAudio()==DHL_TURNER_MODE_ATSC){
1602                // µðÄÚµù µÇ´Â Audio PID·Î ¼³Á¤
1603                p_cur_aud_pid = param->audPid;
1604                App_ChtuneSetChannelInfo_AudioPid(p_cur_aud_pid);
1605        }
1606        else{
1607                //ÇöÀç ¼³Á¤ µÇ¾î ÀÖ´Â ¿Àµð¿À¸¦ app¿¡ ÀúÀåÇÑ´Ù.
1608                //DHL_AV_SetNtscAudioMode( DHL_AV_GetCurNtscAudio() );
1609        }
1610#else
1611        // µðÄÚµù µÇ´Â Audio PID·Î ¼³Á¤
1612        p_cur_aud_pid = param->audPid;
1613        App_ChtuneSetChannelInfo_AudioPid(p_cur_aud_pid);       
1614#endif
1615}
1616
1617
1618
1619
1620char *App_NtscAudioShowOrChangeMTS(BOOL bChangeToNext)
1621{
1622        return NULL;
1623}
1624
1625
1626
1627
1628
1629#if COMMENT
1630____AUDIO_OUTPUT_API____(){}
1631#endif
1632
1633#if AUDIO_PORTING
1634void App_SetDigitalAudioOutput(BOOL bCompressed)
1635{
1636        DHL_AV_SetDigitalAudioOutput(bCompressed);
1637}
1638void App_SetHdmiAudioOutput(BOOL bCompressed)
1639{
1640        DHL_AV_SetHdmiAudioOutput(bCompressed);
1641}
1642void App_SetEffectVolumn(DHL_EffectVolumn aEffect)
1643{
1644        DHL_AV_SetEffectVolumn(aEffect);
1645}
1646#endif //AUDIO_PORTING
1647
1648
1649
1650
1651
1652#if COMMENT
1653____Volume____(){}
1654#endif
1655
1656static UINT8 p_aud_volume;
1657        // audio volume
1658        // APP_AUDIO_VOLUME_MIN ~ APP_AUDIO_VOLUME_MAX
1659
1660static APP_AUDIO_DOWNMIX_TYPE p_aud_downmix;//iskang 071116.
1661        // 0: LtRt, 1: LoRo
1662
1663
1664void App_AudioChangeVolume(int volume, BOOL bSaveNvRam)
1665{
1666        // this codes moved to volume up/down
1667        //   ÃʱâÈ­ °úÁ¤¿¡¼­´Â volume ¼³Á¤À» ÇØ¾ß ÇÑ´Ù.
1668        //
1669        //if (p_baud_fixed_vol_mode) {
1670        //      dprint(0, "!! Note: fixed volume mode for dolby test\n");
1671        //      return;
1672        //}
1673       
1674        if (volume < APP_AUDIO_VOLUME_MIN)
1675                volume = APP_AUDIO_VOLUME_MIN;
1676        if (volume > APP_AUDIO_VOLUME_MAX)
1677                volume = APP_AUDIO_VOLUME_MAX;
1678
1679        printf("p_aud_volume %d \n", p_aud_volume);
1680
1681        p_aud_volume = volume;
1682
1683        printf("After .. p_aud_volume %d \n", p_aud_volume);
1684
1685        DHL_AV_AudioSetVolume(p_aud_volume);
1686
1687        // º¼·ý Á¶ÀýÀ» Çϸé ÀÚµ¿À¸·Î audio mute´Â Ç®¸®µµ·Ï ÇÑ´Ù.
1688        App_AudioMute(FALSE, APP_AUDIO_MUTE_USER);
1689
1690        // cafrii 060706 add, volume 0 mute
1691        if (p_aud_volume == 0)
1692                App_AudioMute(TRUE, APP_AUDIO_MUTE_VOLUME_0);
1693        else
1694                App_AudioMute(FALSE, APP_AUDIO_MUTE_VOLUME_0);
1695
1696
1697        if (bSaveNvRam)
1698        {
1699                p_aud_nvm_param.volume = p_aud_volume;
1700                App_NVM_SaveModuleParam(eAPP_NVR_AUDIO, &p_aud_nvm_param);
1701        }
1702
1703}
1704
1705
1706static void audio_print_volume_bar(void)
1707{
1708        // µð¹ö±× Äֿܼ¡ volume control bar¸¦ ÅØ½ºÆ®·Î ±×¸®ÀÚ.
1709        char buf[80], *p;
1710        int k;
1711
1712        sprintf(buf, "Vol ");
1713
1714        p = buf + strlen(buf);
1715        for (k=APP_AUDIO_VOLUME_MIN; k<=APP_AUDIO_VOLUME_MAX; k++)
1716                *p++ = (k == p_aud_volume) ? '#' : '.';
1717        *p++ = 0;
1718
1719        sprintf(buf+strlen(buf), " %02d", p_aud_volume);
1720
1721        // TODO: After porting debug
1722        //App_PrintTextMessageBox(buf, 32);
1723}
1724
1725
1726void App_AudioVolumeUp(void)
1727{
1728        App_AudioChangeVolume((int)p_aud_volume+1, TRUE);
1729        // range Á¶Á¤Àº ³»ºÎ¿¡¼­ ÇÑ´Ù.
1730        // NvRam¿¡ ¸Å¹ø ÀúÀåÇØ¾ß ÇÑ´Ù.
1731
1732        audio_print_volume_bar();
1733}
1734
1735
1736void App_AudioVolumeDown(void)
1737{
1738        App_AudioChangeVolume((int)p_aud_volume-1, TRUE);
1739       
1740        audio_print_volume_bar();
1741}
1742
1743
1744UINT8 App_AudioGetVolume(void)
1745{
1746        return p_aud_volume;
1747}
1748
1749
1750void App_AudioSetDownMix(APP_AUDIO_DOWNMIX_TYPE downmix, BOOL bSaveNvRam)
1751{
1752        DHL_AV_Control(eDHL_AV_CTL_AUDIO_MIX_TYPE, downmix==APP_AUDIO_DOWNMIX_LTRT?
1753                eDHL_AUDIO_MIX_TYPE_LTRT:eDHL_AUDIO_MIX_TYPE_LORO);
1754
1755        p_aud_downmix=downmix;
1756       
1757        if(bSaveNvRam) {
1758                p_aud_nvm_param.audioDownMix=downmix==APP_AUDIO_DOWNMIX_LTRT?0:1;
1759                App_NVM_SaveModuleParam(eAPP_NVR_AUDIO, &p_aud_nvm_param);
1760        }
1761}
1762
1763APP_AUDIO_DOWNMIX_TYPE App_AudioGetDownMix()
1764{
1765        return p_aud_downmix;
1766}
1767
1768
1769
1770
1771
1772#if COMMENT
1773____Delay____(){}
1774#endif
1775
1776void App_AudioSetDelay(int delay)
1777{
1778        dprint(0, "%s : not supported anymore\n", __FUNCTION__);
1779}
1780
1781
1782
1783
1784
1785#if COMMENT
1786____Debug____(){}
1787#endif
1788
1789// Å×½ºÆ®¸¦ À§ÇØ audio¸¦ Àá±ñ ²ø ¶§ »ç¿ë.
1790static void audio_stop(void)
1791{
1792        DHL_AV_AudioStop();
1793}
1794
1795static void audio_start(void)
1796{
1797        DST_CURCHANNEL ChannelInfo;
1798
1799        if(App_Ucm_GetCurChInfo(&ChannelInfo) != statusOK)
1800                dprint(0, "!! Get App Channel Info Err \n");
1801
1802        dprint(0, "start audio (pid %d, pcr %d)\n", ChannelInfo.uAudPid, ChannelInfo.uPcrPid);
1803       
1804        DHL_AV_AudioStart(ChannelInfo.uAudPid, ChannelInfo.uPcrPid, eDHL_AUDIO_TYPE_AC3);
1805}
1806
1807static void audio_help(void)
1808{
1809        DHL_OS_Printf("\taudio_start: \n");
1810        DHL_OS_Printf("\taudio_stop: \n");
1811        DHL_OS_Printf("\taudio_mute [1:mute_on] [mute_type:0,1] \n");
1812        DHL_OS_Printf("\taudio_mts [1:change_to_next]\n");
1813        DHL_OS_Printf("\taudio_sel [eng/spa/fre]: set preferred lang\n");
1814        DHL_OS_Printf("\taudio_vctlist [program_number]\n");
1815}
1816
1817
1818void Print_AudioElement(DMW_AudioElement data)
1819{
1820        printf("Apid 0x%x\n", data.elementaryPid);
1821        printf("Langcode 0x%x\n", data.ISO639_LanguageCode);
1822        printf("Langcode %s\n", p_aud_lang_code2name(data.ISO639_LanguageCode));
1823}
1824
1825
1826
1827#if COMMENT
1828____Symbol____(){}
1829#endif
1830
1831#if APP_REGISTER_DEBUG_SYMBOL
1832
1833static DHL_SymbolTable _AudioSymbolx[] =
1834{
1835        DHL_FNC_SYM_ENTRY2("audio_stop", audio_stop),
1836        DHL_FNC_SYM_ENTRY2("audio_start", audio_start),
1837        DHL_FNC_SYM_ENTRY2("audio_mute", App_AudioMute),
1838        DHL_FNC_SYM_ENTRY2("audio_mts", App_AudioShowOrChangeMTS),
1839        DHL_FNC_SYM_ENTRY2("audio_sel", App_AudioSetPreferredLanguageId),
1840        DHL_FNC_SYM_ENTRY2("audio_vctlist", App_PrintVctSapList),
1841        DHL_FNC_SYM_ENTRY2("audio_help", audio_help),
1842};
1843
1844static void RegisterSymbols(void)
1845{
1846        DHL_DBG_RegisterSymbols(_AudioSymbolx, DHL_NUMSYMBOLS(_AudioSymbolx));
1847}
1848
1849#else
1850static void RegisterSymbols(void) { }
1851#endif  /* APP_REGISTER_DEBUG_SYMBOL */
1852
1853
1854
1855
1856
1857#if COMMENT
1858____Init____(){}
1859#endif
1860
1861static void p_format_aud_param()
1862{
1863        p_aud_nvm_param.volume=APP_AUDIO_VOLUME_MAX;
1864        p_aud_nvm_param.preferedlang=APP_AUDIO_LANG_AUTO;
1865        p_aud_nvm_param.audioDownMix=eDHL_AUDIO_MIX_TYPE_LORO; //¸ß½ÃÄÚÇâÀº LORO(RF3/4)°¡ ±âº»ÀÓ.
1866        p_aud_nvm_param.audioModeSPDIF=APP_AUDIO_SPDIF_PCM;
1867        p_aud_nvm_param.audioModeHdmi=APP_AUDIO_HDMI_PCM;
1868       
1869        App_NVM_SaveModuleParam(eAPP_NVR_AUDIO, &p_aud_nvm_param);
1870       
1871#if 1   //neverdai 100802 These are required because of standby mode that is implemented by SW
1872        p_aud_volume = p_aud_nvm_param.volume;
1873        p_aud_downmix = (APP_AUDIO_DOWNMIX_TYPE)p_aud_nvm_param.audioDownMix;   
1874        p_audio_user_lang_id = (APP_AUDIO_LANG_ID)p_aud_nvm_param.preferedlang;
1875        p_spdif_mode = (APP_AUDIO_SPDIF_MODE)p_aud_nvm_param.audioModeSPDIF;
1876        p_hdmi_mode = (APP_AUDIO_HDMI_MODE)p_aud_nvm_param.audioModeHdmi;
1877
1878        DHL_AV_AudioSetUserVolumeRange(0, 20);
1879
1880        {
1881                DHL_AV_AudioSetVolume(p_aud_volume);
1882        }
1883
1884       
1885        DHL_AV_Control(eDHL_AV_CTL_AUDIO_MIX_TYPE, p_aud_downmix==APP_AUDIO_DOWNMIX_LTRT?
1886                eDHL_AUDIO_MIX_TYPE_LTRT:eDHL_AUDIO_MIX_TYPE_LORO);
1887
1888        // unmute all audio path
1889        DHL_AV_AudioMuteControl(eDHL_AUDIO_MUTE_DECODER, FALSE);
1890        DHL_AV_AudioMuteControl(eDHL_AUDIO_MUTE_GPIO, FALSE);   
1891
1892        // cafrii, AMP mute is not supported in NEO DHL.
1893        //DHL_AV_AudioMuteControl(eDHL_AUDIO_MUTE_AMP, FALSE);
1894
1895#if SUPPORT_SPDIF_OUTPUT
1896        App_AudioSetDigitalAudio(p_spdif_mode, FALSE);
1897#endif
1898
1899#if SUPPORT_HDMI_OUTPUT
1900        App_AudioSetHdmiAudio(p_hdmi_mode, FALSE);
1901#endif
1902
1903#endif
1904}
1905
1906
1907
1908void App_AudioInit(void)
1909{
1910        RegisterSymbols();
1911
1912        // init
1913        p_ml_sem = DHL_OS_CreateMutexSemaphore("AudioMLInfo");
1914
1915        // load nvparam
1916        App_NVM_LoadModuleParam(eAPP_NVR_AUDIO, &p_aud_nvm_param);
1917
1918        // apply nvparam
1919        p_aud_volume = p_aud_nvm_param.volume;
1920        p_aud_downmix = (APP_AUDIO_DOWNMIX_TYPE)p_aud_nvm_param.audioDownMix;   
1921        p_audio_user_lang_id = (APP_AUDIO_LANG_ID)p_aud_nvm_param.preferedlang;
1922        p_spdif_mode = (APP_AUDIO_SPDIF_MODE)p_aud_nvm_param.audioModeSPDIF;
1923        p_hdmi_mode = (APP_AUDIO_HDMI_MODE)p_aud_nvm_param.audioModeHdmi;
1924
1925        DHL_AV_AudioSetUserVolumeRange(0, 20);
1926
1927        {
1928                DHL_AV_AudioSetVolume(p_aud_volume);
1929        }
1930
1931       
1932        DHL_AV_Control(eDHL_AV_CTL_AUDIO_MIX_TYPE, p_aud_downmix==APP_AUDIO_DOWNMIX_LTRT?
1933                eDHL_AUDIO_MIX_TYPE_LTRT:eDHL_AUDIO_MIX_TYPE_LORO);
1934
1935        // unmute all audio path
1936        DHL_AV_AudioMuteControl(eDHL_AUDIO_MUTE_DECODER, FALSE);
1937        DHL_AV_AudioMuteControl(eDHL_AUDIO_MUTE_GPIO, FALSE);   
1938
1939        // cafrii, AMP mute is not supported in NEO DHL.
1940        //DHL_AV_AudioMuteControl(eDHL_AUDIO_MUTE_AMP, FALSE);
1941
1942#if SUPPORT_SPDIF_OUTPUT
1943        App_AudioSetDigitalAudio(p_spdif_mode, FALSE);
1944#endif
1945
1946#if SUPPORT_HDMI_OUTPUT
1947        App_AudioSetHdmiAudio(p_hdmi_mode, FALSE);
1948#endif
1949
1950}
1951
1952
1953void App_AudioParamInit(void)
1954{
1955        App_NVM_RegisterModule(eAPP_NVR_AUDIO, sizeof(p_aud_nvm_param), p_format_aud_param);
1956}
1957
1958
1959
1960
1961
1962/* end of file */
Note: See TracBrowser for help on using the repository browser.