source: svn/trunk/newcon3bcm2_21bu/dta/src/settop_api/bsettop_decode.c

Last change on this file was 2, checked in by phkim, 11 years ago

1.phkim

  1. revision copy newcon3sk r27
  • Property svn:executable set to *
File size: 35.6 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2003-2006, Broadcom Corporation
3 *     All Rights Reserved
4 *     Confidential Property of Broadcom Corporation
5 *
6 *  THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE
7 *  AGREEMENT  BETWEEN THE USER AND BROADCOM.  YOU HAVE NO RIGHT TO USE OR
8 *  EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT.
9 *
10 * $brcm_Workfile:  $
11 * $brcm_Revision:  $
12 * $brcm_Date: $
13 *
14 * Module Description:
15 *
16 * Revision History:
17 *
18 * $brcm_Log:  $
19 *
20 ***************************************************************************/
21#include "bsettop_decode.h"
22#include "bsettop_p_stream.h"
23#ifdef CONFIG_EIA_708
24#include "bvbilib.h"
25#include "bvbilib_dccparse.h"
26#endif
27#include "gist.h"
28#ifndef NO_VCHIP
29#include "xds_ctrl.h"
30#endif
31#include "bos_task_priorities.h"
32#include "bkni_multi.h"
33#include "ts_psi.h" /* Included for PMT stream type definitions */ 
34
35BDBG_MODULE(decode);
36
37bool g_disable_fcc = false;
38
39#define VBI_CC_DATA_TIMEOUT             (30 * 1000)     /* 30 seconds */
40
41#ifdef CONFIG_EIA_708
42extern bresult bdisplay_vbi_clear_cc(void);
43extern bresult vbi_cc_write_isr(const unsigned char* ccData, size_t length);
44#endif
45
46#ifdef BCM_DEBUG
47        #define INIT_CHECK(a)                                           \
48        {                                                                               \
49                BDBG_MSG((#a " - Enter\n"));    \
50                if (a != BERR_SUCCESS)                          \
51                {                                                                       \
52                        BDBG_ERR((#a " #### failed in %s:%d\n",__FUNCTION__,__LINE__)); \
53                        goto failed;                                    \
54                }                                                                       \
55                BDBG_MSG((#a " - Exit\n"));     \
56        }
57#else /* BCM_DEBUG */
58        #define INIT_CHECK(x) if (x != BERR_SUCCESS) goto failed
59#endif
60
61#define MAX_TRIPLETS    (0x1F * 3)
62
63#define DECWD_TASK_STACK        0x100   /* changed from 0x400 */
64struct bdecode
65{
66        bool initialized;
67        bool first_pts_pending;
68        bool seq_pending;
69        unsigned int start_ticks;
70        bdecode_status status;
71        bdecode_config config;
72        BAVC_XptContextMap videoCtxMap;
73        b_mutex_t           mutex;
74        bstream_t           stream;
75        BXVD_Userdata_Handle    userDataHandle;
76        unsigned char       triplets[MAX_TRIPLETS];
77        bool                b708cc;
78        int                 cc608_format;
79    unsigned int                cc708_timeout;  /* reset b708cc if no 708 data for giving timeout time */
80#ifndef NO_VCHIP
81        xds_ctrl_t                      xds_ctrl;
82#endif
83        unsigned int vbi_cc_data_ticks;         /* keep tracking vbi cc data timing */
84        bool vbi_cc_data;                                       /* true if we have vbi cc data went to vbi encoder */
85
86        bool bypass_tsm;                                        /* flag to bypass TSM mode if video is H.264 to show video as long as got the GOP */
87
88        BKNI_EventHandle wdEvent; 
89        b_task_params task_params;
90        b_task_t task_h;
91        unsigned int task_stack[DECWD_TASK_STACK];
92};
93
94#define DECODE_MUTEX_TIMEOUT    1000
95#define DEF_708CC_TIMEOUT_MS    5000
96
97static struct bdecode s_decode =
98{ 
99        false,
100        false,
101        false,
102        0,
103        { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,false,false,false,false,0},
104        { NULL, NULL, NULL, NULL, NULL,0,0,0,0,0,0,0,{0, 0}, {NULL, NULL}},
105        { 0,0,0,0,0,0,0,0,0,0,0,0},
106        { 0,0,0},
107        NULL,
108};
109
110b_mutex_t           *s_p_mutex = NULL;
111
112
113
114
115/**
116Summary:
117Supported audio and video formats
118 */
119const bsettop_av_stream_type_t s_video_stream_types[] =
120{
121        { TS_PSI_ST_13818_2_Video,  BAVC_VideoCompressionStd_eMPEG2,        0,"MPEG-2"},
122        { TS_PSI_ST_ATSC_Video,     BAVC_VideoCompressionStd_eMPEG2,        0,"MPEG-2"},
123        { TS_PSI_ST_AVS_Video,      BAVC_VideoCompressionStd_eAVS,          0,"AVS"},
124        { TS_PSI_ST_14496_10_Video, BAVC_VideoCompressionStd_eH264,         0,"H.264"},
125        { TS_PSI_ST_SMPTE_VC1,      BAVC_VideoCompressionStd_eVC1,          0,"VC1"},
126        { TS_PSI_ST_14496_2_Video,  BAVC_VideoCompressionStd_eMPEG4Part2,   0,"MP4p2"}
127};
128const int s_video_stream_types_num = sizeof(s_video_stream_types)/sizeof(s_video_stream_types[0]);
129
130
131/**
132Summary:
133        Supported video format. Returns NULL if stream_type (from PMT) not supported.
134 **/
135bsettop_av_stream_type_t *bdecode_supported_video(unsigned char stream_type)
136{
137        int i;
138        for (i = 0; i < s_video_stream_types_num; ++i)
139        {
140                if (stream_type == s_video_stream_types[i].format)
141                {
142                        BDBG_MSG(("Video format[0x%02x]:  %s\n",s_video_stream_types[i].format,s_video_stream_types[i].format_name));
143                        return(bsettop_av_stream_type_t*)&s_video_stream_types[i];
144                }
145        }
146        BDBG_MSG(("Unsupported Video format[0x%02x]\n",stream_type));
147        return NULL;
148}
149
150static void bdecode_watchdog_task(void *arg);
151#define dcc_CheckParity(b)                      (!((b) & 0x80))
152
153/**************************************************************************
154 *  *
155 *  * Function:        ConvertParity
156 *  *
157 *  * Inputs:
158 *  *                  in              - input byte
159 *  *
160 *  * Outputs:
161 *  *
162 *  * Returns:         converted byte
163 *  *
164 *  * Description:
165 *  *
166 *  * ConvertParity() examines the input byte and determines whether or
167 *  * not it has a parity error, based on ODD parity.  The upper bit is
168 *  * converted from the parity bit to the parity error bit, meaning the
169 *  * high bit of the output byte is 1 iff there was a parity error on the
170 *  * input byte.
171 *  *
172 *  **************************************************************************/
173unsigned char dcc_608_P_ConvertParity(unsigned char in)
174{
175        static unsigned char ParityErrorArray[] = {1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1} ;
176        unsigned char temp = ((in & 0x0F) ^ (in >> 4)) ;
177        return((ParityErrorArray[temp]<<7) | (in&0x7F)) ;
178}
179
180#ifdef CONFIG_EIA_708
181/****************************************************************
182 *  * INPUTS:  pointer to cc data1, and cc data 2, scte_20 (DVS157), scte_21 (DVS053) or ATSC53 flag
183 *  * OUTPUTS: modified cc data if any
184 *  * RETURNS: true if ignore the pair, false good for encoding
185 *  * FUNCTION: check ctrl pair to filter out bad pair or redundant pair
186 *  ****************************************************************/
187bool dcc_check_ctrl_pair(size_t *cc1, size_t *cc2, int format)
188{
189        static unsigned char    LastB1[3], LastB2[3];
190        static bool             bLastPairWasCtrl[3] = { false, false };
191        int fmt;
192
193        unsigned char   b1, b2;
194        bool bThisPairWasCtrl[3];
195        bool bIgnore = false;
196
197        if (format == BVBIlib_DCCparse_Format_DVS053)
198                fmt = 0;        /* SCTE 21 */
199        else if (format == BVBIlib_DCCparse_Format_DVS157)
200                fmt = 1;        /* SCTE 21 */
201        else if (format == BVBIlib_DCCparse_Format_ATSC53)
202                fmt = 2;        /* ATSC 53 */
203        else {
204                BDBG_WRN(("%s: format %d not supported", __func__, format));
205                return false;
206        }       
207
208        /*
209         * * ConvertParity converts bit 7 from
210         * * parity_bit to parity_error
211         *                                        */
212        b1 = dcc_608_P_ConvertParity(*cc1);
213        b2 = dcc_608_P_ConvertParity(*cc2);
214        bThisPairWasCtrl[fmt] = false;
215
216        if ( !dcc_CheckParity(b1) ) {
217                /* if 1st fails parity, ignore pair */
218                BDBG_MSG(("1st failes parity, ignore")) ;
219                bIgnore = true;
220        }
221        else {
222                if (0x14 == (b1 & 0x7f) || 0x1c == (b1 & 0x7f)) {
223                        BDBG_MSG(("%d 0x%02x 0x%02x, lb1=%02x, lb2=%02x", fmt ? 20 : 21, b1, b2, LastB1[fmt], LastB2[fmt])) ;
224                        if ( !dcc_CheckParity(b2) )
225                        {
226                                /* if 2nd fails parity, ignore pair */
227                                BDBG_MSG(("2nd failes parity, ignore")) ;
228                                bIgnore = true;
229                        }
230                        else {
231                                bThisPairWasCtrl[fmt] = true;
232
233                                /* currently we just check EOC */
234                                if ((b2 == LastB2[fmt]) && (b1 == LastB1[fmt]) && (0x2f == b2))
235                                {
236                                        BDBG_MSG(("lastCtrl=%d, redundant 0x%02x 0x%02x", bLastPairWasCtrl[fmt], b1, b2)) ;
237                                        bIgnore = true;
238                                }
239                        }
240                }
241        }
242        if ( bThisPairWasCtrl[fmt] )
243        {
244                LastB1[fmt] = b1;
245                LastB2[fmt] = b2;
246        }
247        bLastPairWasCtrl[fmt] = bThisPairWasCtrl[fmt];
248
249        return bIgnore;
250}
251#endif
252
253
254
255#if SUPPORT_DST_PLATFORM
256
257BXVD_PictureParameterInfo* s_PrevStreamInfo;    // last seqhdr info
258
259bdecode_callback_t s_userdata_callback = NULL;
260bdecode_callback_t s_vec_isr_callback= NULL;
261bdecode_callback_t s_seq_hdr_callback= NULL;
262bdecode_callback_t s_picture_isr_callback= NULL;
263bdecode_callback_t s_video_err_callback= NULL;
264
265bdecode_callback_t bdecode_register_callback(enum bdecode_callback_type type, bdecode_callback_t fn)
266{
267        // cafrii 081212 add check whether fn is same as old one.
268        // print error msg and return null
269       
270        unsigned int flag;
271        bdecode_callback_t oldcb = NULL;
272       
273        flag = bos_enter_critical();
274        switch (type)
275        {
276#if 1           
277                case bdecode_callback_type_userdata:
278                        if (s_userdata_callback == fn)
279                                goto err;
280                        oldcb = s_userdata_callback;
281                        s_userdata_callback = fn;
282                        break;
283#endif         
284                case bdecode_callback_type_vec_isr:
285                        if (s_vec_isr_callback == fn)
286                                goto err;
287                        oldcb = s_vec_isr_callback;
288                        s_vec_isr_callback = fn;
289                        break;
290
291#if 0
292                case bdecode_callback_type_seq_hdr_isr:
293                        if (s_seq_hdr_callback == fn)
294                                goto err;
295                        oldcb = s_seq_hdr_callback;
296                        s_seq_hdr_callback = fn;
297                        break;
298#endif
299
300                case bdecode_callback_type_picture_isr:
301                        if (s_picture_isr_callback == fn)
302                                goto err;
303                        oldcb = s_picture_isr_callback;
304                        s_picture_isr_callback = fn;
305                        break;
306
307                case bdecode_callback_type_video_err:
308                        if (s_video_err_callback == fn)
309                                goto err;
310                        oldcb = s_video_err_callback;
311                        s_video_err_callback = fn;
312                        break;
313               
314        }
315        goto end;
316
317err:
318        BDBG_ERR(("%s: callback type %d: fn 0x%x is same as prev one\n", 
319                                __func__, type, fn));
320end:
321        bos_exit_critical(flag);
322       
323        return oldcb;
324}
325
326
327static unsigned char s_StreamInfoReceived = 1;
328static unsigned char s_CaptionInfoReceived = 1;
329
330static unsigned char s_MonitorFieldInfoChange;
331        // each bit corresponds to BAVC_Polarity value.
332        // BAVC_Polarity_eTopField => bit 0, 0x1
333        // BAVC_Polarity_eBotField => bit 1, 0x2
334
335       
336
337/*
338        WARNING!!
339        this query should be used just after sequence header callback is called.
340        do not use in arbitrary time.
341        returned BMVD_StreamInfo may not be same as last sequence header event info.
342*/
343BXVD_PictureParameterInfo *bdecode_get_stream_info(BXVD_PictureParameterInfo *status)
344{
345        if (s_StreamInfoReceived) {
346                uint32_t flag = bos_enter_critical();
347                status = s_PrevStreamInfo;
348                bos_exit_critical(flag);
349                return s_PrevStreamInfo;
350        }
351        return NULL;
352}
353
354#endif // SUPPORT_DST_PLATFORM
355
356
357/**
358Summary:
359        XVD Video decoder watchdog handler.
360**/
361
362
363void VideoDecoderWatchdog_isr(void *pParm1, int parm2, void *pXVD_data)
364{
365        bdecode_t decode = (bdecode_t)pParm1;
366        BDBG_ASSERT(decode);
367
368        BDBG_ERR(("BXVD_ProcessWatchdog being called!!!"));
369        BKNI_SetEvent(decode->wdEvent);
370
371        decode->status.watchdog_cnt++;
372}
373
374
375/**
376Summary:
377        XVD Video decoder PTS error handler.
378**/
379
380
381void VideoDecoder_PtsError_isr(void *data, int unused, void *pts_info)
382{
383        bdecode_t decode = (bdecode_t)data;
384        BXVD_PTSInfo *pPts = (BXVD_PTSInfo *)pts_info;
385        unsigned int stc;
386        BDBG_ASSERT(pts_info);
387        BDBG_ASSERT(decode);
388        BDBG_ASSERT(decode->stream);
389        BDBG_ASSERT(decode->stream->hPcrOffset);
390
391        BSTD_UNUSED(unused);
392        BSTD_UNUSED(pPts);
393
394        stc = BXPT_PcrOffset_GetStc_isr(decode->stream->hPcrOffset) + 
395                  BXPT_PcrOffset_GetOffset_isr(decode->stream->hPcrOffset);
396
397        BDBG_MSG(("VideoDecoder_PtsError_isr pts = %x, stc = %x, offset = %x",  pPts->ui32RunningPTS,stc,pPts->uiPCROffset));
398
399        bstream_p_pcroffset_update(decode->stream);
400
401        decode->status.pts_err_cnt++;
402}
403/**
404Summary:
405        XVD Video decoder PTS error handler.
406**/
407
408
409void VideoDecoder_RequestStc_isr(void *data, int unused, void *pts_info)
410{
411        bdecode_t decode = (bdecode_t)data;
412        BXVD_PTSInfo *pPts = (BXVD_PTSInfo *)pts_info;
413        unsigned int stc;
414        BDBG_ASSERT(pts_info);
415        BDBG_ASSERT(decode);
416        BDBG_ASSERT(decode->stream);
417        BDBG_ASSERT(decode->stream->hPcrOffset);
418
419        BSTD_UNUSED(unused);
420        BSTD_UNUSED(pPts);
421
422        stc = BXPT_PcrOffset_GetStc_isr(decode->stream->hPcrOffset) + 
423                  BXPT_PcrOffset_GetOffset_isr(decode->stream->hPcrOffset);
424
425        BDBG_MSG(("VideoDecoder_RequestStc_isr pts = %x, stc = %x, offset = %x",  pPts->ui32RunningPTS,stc,pPts->uiPCROffset));
426
427        bstream_p_pcroffset_update(decode->stream);
428
429        decode->status.req_stc_cnt++;
430}
431/**
432Summary:
433        XVD Video decoder PTS error handler.
434**/
435
436
437void VideoDecoder_FirstPtsPassed_isr(void *data, int unused, void *pts_info)
438{
439        bdecode_t decode = (bdecode_t)data;
440        BXVD_PTSInfo *pPts = (BXVD_PTSInfo *)pts_info;
441        unsigned int stc;
442        BDBG_ASSERT(pts_info);
443        BDBG_ASSERT(decode);
444        BDBG_ASSERT(decode->stream);
445        BDBG_ASSERT(decode->stream->hPcrOffset);
446
447        BSTD_UNUSED(unused);
448        BSTD_UNUSED(pPts);
449
450        stc = BXPT_PcrOffset_GetStc_isr(decode->stream->hPcrOffset) + 
451                  BXPT_PcrOffset_GetOffset_isr(decode->stream->hPcrOffset);
452
453        BDBG_MSG(("VideoDecoder_FirstPtsPassed_isr pts = %x, stc = %x, offset = %x",  pPts->ui32RunningPTS,stc,pPts->uiPCROffset));
454
455        decode->status.first_pts_cnt++;
456        if (decode->first_pts_pending)
457        {
458                decode->first_pts_pending = false;
459                decode->status.first_pts_ticks = bos_getticks()-decode->start_ticks;
460                if (s_decode.config.first_pts_callback) {
461                        s_decode.config.first_pts_callback();
462                }
463        }
464}
465/**
466Summary:
467        XVD Video decoder PTS error handler.
468**/
469
470
471void VideoDecoder_PtsStcOffset_isr(void *data, int unused, void *offset)
472{
473        uint32_t uiOffset;
474        bdecode_t decode = (bdecode_t)data;
475
476        BDBG_ASSERT(offset);
477        BDBG_ASSERT(decode);
478
479        BSTD_UNUSED(data);
480        BSTD_UNUSED(unused);
481        uiOffset = *(uint32_t*)offset;
482
483        BDBG_MSG(("VideoDecoder_PtsStcOffset_isr offset = %x",  uiOffset));
484
485        decode->status.offset_cnt++;
486}
487/**
488Summary:
489        XVD Video decoder picture info isr.
490**/
491void VideoDecoder_PictureParams_isr(void *data, int unused, void *info)
492{
493        bdecode_t decode = (bdecode_t)data;
494        BXVD_PictureParameterInfo *picInfo = (BXVD_PictureParameterInfo *)info;
495        BDBG_ASSERT(decode);
496        BDBG_ASSERT(picInfo);
497        BSTD_UNUSED(unused);
498#if SUPPORT_DST_PLATFORM//BKTEMP
499        s_PrevStreamInfo = (BXVD_PictureParameterInfo *)info;
500#endif
501        decode->status.bFrameProgressive = picInfo->bFrameProgressive;
502        decode->status.bStreamProgressive = picInfo->bStreamProgressive;
503        decode->status.display_width = picInfo->ulDisplayHorizontalSize;
504        decode->status.display_height = picInfo->ulSourceVerticalSize;
505        decode->status.hPanScan = picInfo->i32_HorizontalPanScan;
506        decode->status.source_height = picInfo->ulSourceVerticalSize;
507        decode->status.source_width = picInfo->ulSourceHorizontalSize;
508        decode->status.video_aspect_ratio = picInfo->eAspectRatio;
509        decode->status.video_format = picInfo->uiVideoFormat;
510        decode->status.video_framerate = picInfo->eFrameRateCode;
511        decode->status.vPanScan = picInfo->i32_VerticalPanScan;
512        decode->status.bitRate = picInfo->uiBitRate;
513        decode->status.profile = picInfo->uiProfile;
514        decode->status.level = picInfo->uiLevel;
515        decode->status.pic_info_cnt++;
516        if (decode->seq_pending)
517        {
518                decode->seq_pending = false;
519                decode->status.seq_ticks = bos_getticks()-decode->start_ticks;
520                if (s_decode.config.seq_hdr_callback) {
521                        s_decode.config.seq_hdr_callback();
522                }
523#if SUPPORT_DST_PLATFORM
524                if(s_seq_hdr_callback)
525                {
526                        s_seq_hdr_callback(bdecode_callback_type_seq_hdr_isr, NULL);
527                }       
528#endif
529
530                if (decode->bypass_tsm) {
531                        BXVD_SetVideoDisplayMode(GetXVDCh(), BXVD_DisplayMode_eTSMMode);//jglee 2014.05.08 BXVD_DisplayMode_eTSMMode - > BXVD_DisplayMode_eVSYNCMode
532                        decode->bypass_tsm = false;
533                }
534        }
535        if (s_decode.vbi_cc_data && ((s_decode.vbi_cc_data_ticks + MS_TO_TICKS(VBI_CC_DATA_TIMEOUT) < bos_getticks()))) {
536                s_decode.vbi_cc_data = false;
537#ifdef CONFIG_EIA_708
538                bdisplay_vbi_clear_cc();
539#endif
540        }
541}
542
543/**
544Summary:
545XVD Video decoder picture info isr.
546 **/
547
548void VideoDecoder_DecodeError_isr(void *data, int unused, void *info)
549{
550        bdecode_t decode = (bdecode_t)data;
551        BDBG_ASSERT(decode);
552        decode->status.decode_err_cnt++;
553}
554
555/**
556Summary:
557XVD Video decoder TSM result handler
558 **/
559
560void VideoDecoder_TSMResult_isr(void *data, int unused, void *info)
561{
562        BXDM_PictureProvider_TSMInfo *pTSMInfo = (BXDM_PictureProvider_TSMInfo *)info;
563        BDBG_ASSERT(pTSMInfo);
564
565        BSTD_UNUSED(data);
566        BSTD_UNUSED(unused);
567        BDBG_MSG(("TSMResult=%d", pTSMInfo->eTSMResult));
568        switch (pTSMInfo->eTSMResult)
569        {
570                case BXDM_PictureProvider_TSMResult_eTooLate:
571                        pTSMInfo->ePictureHandlingMode = BXDM_PictureProvider_PictureHandlingMode_eDrop;
572                        break;
573
574                default:
575                        pTSMInfo->ePictureHandlingMode = BXDM_PictureProvider_PictureHandlingMode_eDefault;
576                        break;
577        }
578}
579/*
580Summary:
581Use VBI lib to parse userdata
582*/
583
584#ifdef CONFIG_EIA_708
585#define B_MAX_VBI_CC_COUNT 32 /* required by VBIlib */
586
587/* to reorder UserData since some ATSC53 userdata encoder messed up field order */
588static void Reorder_UserData(BVBIlib_DCCparse_ccdata ccData[], int i)
589{
590        BVBIlib_DCCparse_ccdata ccTmp;
591
592        if (i < (B_MAX_VBI_CC_COUNT - 4))
593        {
594                if ((ccData[i].polarity == ccData[i + 1].polarity) && (ccData[i + 2].polarity == ccData[i + 3].polarity) && 
595                        (ccData[i].polarity != ccData[i + 2].polarity) && (ccData[i + 2].polarity < 2))
596                {
597                        ccTmp = ccData[i + 1];
598                        ccData[i + 1] = ccData[i + 2];
599                        ccData[i + 2] = ccTmp;
600                }
601        }
602}
603
604static void ParseUserdata_isr(bdecode_t decode, const BAVC_USERDATA_info *info)
605{
606        uint32_t offset = 0;
607        int triplet_cnt = 0;
608        int vbi_cnt = 0;
609        static uint8_t vbi_data[100];
610
611        BDBG_MSG(("ParseUserdata %d:%d:%#x:%d:%d", info->eUserDataType, info->ui32UserDataBufSize,
612                                (unsigned)info->pUserDataBuffer, info->bTopFieldFirst, info->bRepeatFirstField));
613
614#if SUPPORT_DST_PLATFORM
615                if(s_userdata_callback)
616                {
617                        s_userdata_callback(bdecode_callback_type_userdata, NULL);
618                }       
619#endif
620        while (offset < info->ui32UserDataBufSize)
621        {
622                BERR_Code rc;
623                unsigned i;
624                size_t bytesParsed = 0;
625                uint8_t ccCount = 0;
626                BVBIlib_DCCparse_ccdata ccData[B_MAX_VBI_CC_COUNT];
627
628                /* TODO: The BVBIlib_DCCparse functions should be _isr. They should also be refactored out of VBIlib. VBIlib is a syslib which is owned by the
629                   Display module. It should not be called from VideoDecoder. */
630                if (decode->stream->mpeg.video[0].format == BAVC_VideoCompressionStd_eH264)
631                {
632                        rc = BVBIlib_DCCparse_SEI(info, offset, &bytesParsed, &ccCount, ccData);
633                }
634#if 0
635                else if (videoDecoder->transportType == BAVC_VideoCompressionStd_eMPEG2DTV)
636                {
637                        /* only applies to DSS ES (SD), not DSS PES (HD) */
638                        rc = BVBIlib_DCCparse_DSS(info, offset, &bytesParsed, &ccCount, ccData);
639                }
640#endif
641                else
642                {
643                        rc = BVBIlib_DCCparse(info, offset, &bytesParsed, &ccCount, ccData);
644                }
645                /* VBIlib takes pointer w/o size, so this must be true. Otherwise we have overflow, from which there is no recovery. */
646                BDBG_ASSERT(ccCount <= B_MAX_VBI_CC_COUNT);
647
648                if (bytesParsed==0)
649                { /* we aren't going anywhere */
650                        break;
651                }
652                offset += bytesParsed;
653                /* We process bytesParsed even with error code. seems a bit dangerous. */
654                if (rc == BERR_BVBIlib_PARSE_ERROR)
655                {
656                        break;
657                }
658                else if (rc != BERR_SUCCESS)
659                {
660                        continue;
661                }
662
663
664
665                for (i=0;i<ccCount;i++)
666                {
667                        /* current drop DVS157 or SCTE 20 per Comcast spec. */
668                        //if (BVBIlib_DCCparse_Format_DVS157 == ccData[i].format)
669                        //      continue;
670
671
672                        if (ccData[i].bIsAnalog)
673                        {
674                                if (ccData[i].format == BVBIlib_DCCparse_Format_ATSC53) {
675                                        decode->cc608_format = ccData[i].format;
676                                }       
677
678                                /* discard DVS157 CC data if ATSC53 CC presents, please check s_mpegParsers for the array order */
679                                if (ccData[i].format < decode->cc608_format) continue;
680
681                                /* discard other formats that not supported, NOTE that the AFD was handled by our code already */
682                                /* TODO confirm if we need to support DVS053? */
683                                if (ccData[i].format > BVBIlib_DCCparse_Format_DVS053) continue;
684
685                                /* pass to VBI encoder */
686                                if (ccData[i].cc_valid) {
687                                        size_t cc1, cc2;
688
689#ifndef ACB612
690                                        if (ccData[i].format == BVBIlib_DCCparse_Format_ATSC53) {
691                                                if (0 == i)
692                                                {
693                                                        Reorder_UserData(ccData, i);
694                                                }
695                                        }
696#endif
697                                        cc1 = ccData[i].cc_data_1;
698                                        cc2 = ccData[i].cc_data_2;
699
700#ifndef ACB612
701                                        if (dcc_check_ctrl_pair(&cc1, &cc2, ccData[i].format)) {
702                                                BDBG_MSG(("%s not good Ctrl Code, drop",__func__));
703                                                continue;
704                                        }
705#endif
706                    /* don't encode empty data? */
707                    if (0x80 == cc1 && 0x80 == cc2)
708                        continue;
709
710                                        vbi_data[vbi_cnt] = (ccData[i].polarity == BAVC_Polarity_eTopField)?0:1;
711                                        vbi_data[vbi_cnt+1] = (unsigned char)cc1;
712                                        vbi_data[vbi_cnt+2] = (unsigned char)cc2;
713                                        vbi_cnt+=3;
714#ifndef NO_VCHIP
715                                        if (ccData[i].polarity == BAVC_Polarity_eBotField)
716                                        {
717                                                xds_ctrl_feed(&s_decode.xds_ctrl, ccData[i].cc_data_1&0x7F, ccData[i].cc_data_2&0x7F);
718                                        }
719#endif
720                                }
721                /* 608 triplet will be rendered only when program doesn't have 708 cc */
722                if (decode->b708cc == false) {
723                    if ((ccData[i].cc_valid) && ((triplet_cnt + 3) < MAX_TRIPLETS))
724                    {
725                        s_decode.triplets[triplet_cnt] = (ccData[i].polarity==BAVC_Polarity_eTopField) ? 0 : 1;
726                        s_decode.triplets[triplet_cnt + 1] = ccData[i].cc_data_1;
727                        s_decode.triplets[triplet_cnt + 2] = ccData[i].cc_data_2;
728                        triplet_cnt += 3;
729                    }
730                    else
731                    {
732                        /* don't send invalid 608 data */
733                    }
734                }
735                else {
736                    if (bos_getticks() > decode->cc708_timeout) {
737                        if (triplet_cnt) {
738                            /* post current data before new data that is different */
739                            if (s_decode.config.cc_callback && s_decode.config.cc_enabled)
740                            {
741                                                                s_decode.config.cc_callback((unsigned char*)s_decode.triplets,triplet_cnt, decode->b708cc?false:true);
742                            }
743                        }
744                        decode->b708cc = false;
745                        triplet_cnt = 0;
746                    }
747                }
748                        }
749                        else
750                        {
751                                                                       
752                                /* primary CC is 708 */
753                                /* discard DCC data if not valid */
754                                if (!ccData[i].cc_valid) {
755                                        if (0 == ccData[i].cc_data_1 && 0 == ccData[i].cc_data_2)
756                                                continue;
757                                }
758
759                                if (decode->b708cc == false) {
760                    /* if has left over from 608 data */
761                    if (triplet_cnt) {
762                        /* post current data before new data that is different */
763                        if (s_decode.config.cc_callback && s_decode.config.cc_enabled)
764                        {
765                                                        s_decode.config.cc_callback((unsigned char*)s_decode.triplets,triplet_cnt, decode->b708cc?false:true);
766                        }
767                    }
768                                        /* 708cc is detected. clear the 608cc */
769                                        triplet_cnt = 0;
770                                        decode->b708cc = true;
771                                }
772                                /* tracking 708cc timeout */
773                                decode->cc708_timeout = bos_getticks() + MS_TO_TICKS(DEF_708CC_TIMEOUT_MS);
774
775                                if ((triplet_cnt + 3) < MAX_TRIPLETS)
776                                {
777                                        s_decode.triplets[triplet_cnt] = ccData[i].seq.cc_type;
778                                        s_decode.triplets[triplet_cnt + 1] = ccData[i].cc_data_1;
779                                        s_decode.triplets[triplet_cnt + 2] = ccData[i].cc_data_2;
780                                        triplet_cnt += 3;
781                                } else
782                                {
783                                        BDBG_WRN(("%s triplet overflow\n",__FUNCTION__));
784
785                                }
786                        }
787                }
788
789                if (s_decode.config.cc_callback && s_decode.config.cc_enabled && (triplet_cnt > 0))
790                {
791                        s_decode.config.cc_callback((unsigned char*)s_decode.triplets,triplet_cnt, decode->b708cc?false:true);
792                }
793
794                if ((vbi_cnt>0)&&(!s_decode.config.block_vbi)) {
795                        //if ((info->bTopFieldFirst && vbi_data[0] != 0) && (BAVC_VideoCompressionStd_eH264 != decode->stream->mpeg.video[0].format)
796                        //              && (BVBIlib_DCCparse_Format_ATSC53 != decode->cc608_format)) {
797                        if (0) {
798                                continue;
799                        }
800                        else {
801                                if (BERR_SUCCESS != vbi_cc_write_isr(vbi_data, vbi_cnt/3)) {
802                                        BDBG_WRN(("%s vbi_cc_write_isr failed\n",__func__));
803                                }
804                                else {
805                                        s_decode.vbi_cc_data_ticks = bos_getticks();
806                                        s_decode.vbi_cc_data = true;
807                                }
808                        }
809                }
810                }
811                return;
812        }
813
814/*
815Summary:
816User data callback
817*/
818
819void UserdataReady_isr(void *data, int unused, void *not_used)
820{
821        BERR_Code rc = BXVD_ERR_USERDATA_NONE;
822        BAVC_USERDATA_info info;
823        bdecode_t decode = (bdecode_t)data;
824
825        BSTD_UNUSED(unused);
826        BSTD_UNUSED(not_used);
827
828        for ( ;; )
829        {
830                /* TODO: reduce XVD userdata buffer size because we evacuate XVD at isr time */
831
832                /* get data */
833                rc = BXVD_Userdata_Read_isr(decode->userDataHandle, &info);
834                if ( rc==BXVD_ERR_USERDATA_NONE )
835                {
836                        break;
837                }
838                else if ( rc==BXVD_ERR_USERDATA_INVALID )
839                {
840                        continue; /* keep reading data */
841                }
842                else if ( rc!=BERR_SUCCESS )
843                {
844                        BDBG_ERR(("BXVD_Userdata_Read_isr returned error %#x, ignore", rc));
845                        break;
846                }
847
848                /* parse and send data to VideoInput (in Display module) */
849                /* process CC/VCHIP data even though cc is disabled, DIG-D04 */
850                //              if (decode->config.cc_callback && decode->config.cc_enabled)
851                {
852                        ParseUserdata_isr(decode, &info);
853                }
854        }
855}
856#endif /* CONFIG_EIA_708 */
857
858/*
859Summary:
860Open a decode engine.
861Description:
862*/
863bdecode_t bdecode_open(
864                bobject_t decode_id /* decode object id */
865                )
866{
867
868        if (s_decode.initialized)
869        {
870                return(bdecode_t)0;
871        }
872
873        if (bos_create_mutex(&(s_decode.mutex)) != b_ok)
874        {
875                return(bdecode_t)0;
876        }
877        s_p_mutex = &(s_decode.mutex);
878
879        s_decode.task_params.name="vdecode";
880        s_decode.task_params.priority = DECWD_PRIORITY;
881        s_decode.task_params.stack_size = DECWD_TASK_STACK;
882        s_decode.task_params.stack = s_decode.task_stack;
883
884        INIT_CHECK(BXVD_InstallDeviceInterruptCallback(GetXVD(), 
885                                BXVD_DeviceInterrupt_eWatchdog, VideoDecoderWatchdog_isr, &s_decode, 0));
886        INIT_CHECK(BXVD_InstallInterruptCallback(GetXVDCh(), 
887                                BXVD_Interrupt_ePTSError, VideoDecoder_PtsError_isr, &s_decode, 0));
888        INIT_CHECK(BXVD_InstallInterruptCallback(GetXVDCh(), 
889                                BXVD_Interrupt_eFirstPTSPassed, VideoDecoder_FirstPtsPassed_isr, &s_decode, 0));
890        INIT_CHECK(BXVD_InstallInterruptCallback(GetXVDCh(),
891                                BXVD_Interrupt_ePtsStcOffset, VideoDecoder_PtsStcOffset_isr, &s_decode, 0));
892        INIT_CHECK(BXVD_InstallInterruptCallback(GetXVDCh(),
893                                BXVD_Interrupt_ePictureParameters, VideoDecoder_PictureParams_isr, &s_decode, 0));
894        INIT_CHECK(BXVD_InstallInterruptCallback(GetXVDCh(),
895                                BXVD_Interrupt_eDecodeError, VideoDecoder_DecodeError_isr, &s_decode, 0));
896        INIT_CHECK(BXVD_InstallInterruptCallback(GetXVDCh(),
897                                BXVD_Interrupt_eClipStart, VideoDecoder_FirstPtsPassed_isr, &s_decode, 0));
898        INIT_CHECK(BXVD_InstallInterruptCallback(GetXVDCh(),
899                                BXVD_Interrupt_eRequestSTC, VideoDecoder_RequestStc_isr, &s_decode, 0));
900        INIT_CHECK(BXVD_InstallInterruptCallback(GetXVDCh(),
901                                BXVD_Interrupt_eTSMResult, VideoDecoder_TSMResult_isr, &s_decode, 0));
902        INIT_CHECK(BXVD_Userdata_Open(GetXVDCh(), &(s_decode.userDataHandle), NULL));
903#ifdef CONFIG_EIA_708
904        INIT_CHECK(BXVD_Userdata_InstallInterruptCallback(s_decode.userDataHandle, 
905                                (BINT_CallbackFunc)UserdataReady_isr, &(s_decode), 0));
906
907        BXVD_Userdata_Enable(s_decode.userDataHandle,true);
908#endif
909
910#ifndef NO_VCHIP
911        xds_ctrl_init(&s_decode.xds_ctrl);
912#endif
913
914        BKNI_CreateEvent(&(s_decode.wdEvent));
915        bos_start_task(&(s_decode.task_h),&(s_decode.task_params),bdecode_watchdog_task,&s_decode);
916        s_decode.initialized = true;
917        return(bdecode_t)&s_decode;
918failed:
919        return(bdecode_t)0;
920}
921
922/*
923Summary:
924Close a decode engine.
925Description:
926The decode should be stopped before closing.
927After closing, the bdecode_t handle is invalid.
928*/
929void bdecode_close(
930                bdecode_t decode /* handle returned by bdecode_open */
931                ){
932        BDBG_ASSERT(decode);
933        if (s_decode.userDataHandle)
934        {
935                BXVD_Userdata_Close(s_decode.userDataHandle);
936                s_decode.userDataHandle = NULL;
937        }
938        if (decode->initialized)
939        {
940                bos_delete_mutex(&(decode->mutex));
941        }
942        bos_stop_task(decode->task_h);
943        BKNI_DestroyEvent(decode->wdEvent);
944        decode->initialized = false;
945}
946
947
948/*
949Summary:
950Start decoding a stream.
951*/
952bresult bdecode_start(
953                bdecode_t decode, /* handle returned by bdecode_open */
954                bstream_t source, /* source for the decode, either analog or digital */
955                bdecode_window_t window /* window to render decode */
956                ){
957        BERR_Code err;
958        BXVD_DecodeSettings  decodeSettings;
959        long lDisplayOffsetValue;
960
961        BDBG_ASSERT(decode);
962        BDBG_ASSERT(source);
963        BDBG_ASSERT(source->hRaveCx);
964
965        if (decode->status.bVideoDecoding)
966        {
967                bdecode_stop(decode);
968        }
969#ifdef CONFIG_EIA_708
970        decode->b708cc = false; 
971        decode->cc608_format = BVBIlib_DCCparse_Format_DVS157;
972#endif
973
974        /* clear vbi cc data flag */
975        decode->vbi_cc_data = false;
976
977        err = BERR_OS_ERROR;
978        if (bos_acquire_mutex(s_p_mutex,DECODE_MUTEX_TIMEOUT) == b_ok)
979        {
980
981                decode->stream = source;
982                BDBG_MSG(("%s codec id = %d\n",__FUNCTION__,decode->stream->mpeg.video[0].format));
983
984                err = BXVD_GetDecodeDefaultSettings(GetXVDCh(), &decodeSettings);
985                decodeSettings.eVideoCmprStd = decode->stream->mpeg.video[0].format;  /* Mpeg2 or AVC */
986                decodeSettings.ulMultiStreamId = 0;
987                decodeSettings.ulVideoSubStreamId = 0;
988                decodeSettings.bCrcMode = false;
989                decodeSettings.bPlayback = false;
990                decodeSettings.stDataXprtOutput.eXptOutputId = BAVC_XptOutputId_eParserBand0;
991                decodeSettings.stDataXprtOutput.eXptSourceId = BAVC_XptOutputId_eParserBand0;
992                decodeSettings.eTimeBase = BAVC_Timebase_e0;
993                err = bstream_p_get_rave_context_map(decode->stream,&(decode->videoCtxMap));
994                BDBG_ASSERT(err == BERR_SUCCESS);
995                decodeSettings.pContextMap = &(decode->videoCtxMap);
996                bstream_p_pcroffset_pid_ch_config(decode->stream, decode->stream->pid_ch);
997                err = bstream_p_attach_rave(decode->stream,true);
998                if (err != BERR_SUCCESS)
999                {
1000                        BDBG_ERR(("%s bstream_p_attach_rave failed %d\n",__FUNCTION__,err));
1001                }
1002                //ccmode = BXVD_ChannelChangeMode_eLastFramePreviousChannel;
1003                //decode->config.channel_change = BXVD_ChannelChangeMode_eLastFramePreviousWithFirstPicturePreview;
1004                decode->config.channel_change = BXVD_ChannelChangeMode_eMute;
1005                BXVD_SetChannelChangeMode(GetXVDCh(), decode->config.channel_change);
1006
1007                //BXVD_SetVideoDisplayMode(GetXVDCh(),BXVD_DisplayMode_eTSMMode);
1008                //BXVD_SetVideoDisplayMode(GetXVDCh(),BXVD_DisplayMode_eVSYNCMode);
1009
1010                /* note that BXVD_ChannelChangeMode_eLastFramePreviousWithFirstPicturePreview seems not work well for H.264 preview */
1011                /* currently just for H.264 stream to force first picture preview on H.264 stream */
1012                if (decode->stream->mpeg.video[0].format == BAVC_VideoCompressionStd_eH264) {
1013                        BXVD_SetVideoDisplayMode(GetXVDCh(),BXVD_DisplayMode_eVSYNCMode);
1014                        decode->bypass_tsm = true;
1015                }
1016                else {
1017                        //RLQ, to display video for sake of channel change time
1018                        BXVD_SetVideoDisplayMode(GetXVDCh(),BXVD_DisplayMode_eTSMMode);
1019                        decode->bypass_tsm = true;
1020                }
1021                if (g_disable_fcc)
1022                {
1023                        bstream_p_rave_enable(decode->stream,false);
1024                        bstream_p_rave_flush(decode->stream);
1025                }
1026                err = BXVD_StartDecode(GetXVDCh(), &decodeSettings);
1027                if (err != BERR_SUCCESS)
1028                {
1029                        bstream_p_rave_enable(decode->stream,false);
1030                        bstream_p_rave_flush(decode->stream);
1031                        bos_release_mutex(s_p_mutex);
1032
1033                        BXVD_ProcessWatchdog(GetXVD());
1034                        if (bos_acquire_mutex(s_p_mutex,DECODE_MUTEX_TIMEOUT) != b_ok) {
1035                                BDBG_ERR(("%s bos_acquire_mutex failed\n",__FUNCTION__));
1036                        }
1037                        err = BXVD_StartDecode(GetXVDCh(), &decodeSettings);
1038                }
1039                if (err == BERR_SUCCESS)
1040                {
1041                        decode->status.bVideoDecoding = true;
1042                        decode->first_pts_pending = true;
1043                        decode->seq_pending = true; //megakiss 2014.05.08 first video still true->false // jglee 2014.05.08 false -> true
1044                        decode->start_ticks = bos_getticks();
1045                        bstream_p_rave_enable(decode->stream,true);
1046                        bstream_pcroffset_config_context(decode->stream);
1047
1048#if 0
1049                        err = BXVD_GetDisplayOffset(GetXVDCh(), &lDisplayOffsetValue);
1050                        if (BERR_SUCCESS != err) {
1051                                BDBG_ERR(("%s BXVD_GetDisplayOffset failed (err=0x%x)\n",__func__,err));
1052                        }
1053                        BDBG_WRN(("%s display offset=%ld\n",__func__,lDisplayOffsetValue));
1054#endif
1055                        lDisplayOffsetValue = (15 * 45000) / 1000;
1056                        err = BXVD_SetDisplayOffset(GetXVDCh(), lDisplayOffsetValue);
1057                        bos_release_mutex(s_p_mutex);
1058                        return b_ok;
1059                }
1060                else
1061                {
1062                        BDBG_ERR(("%s BXVD_StartDecode failed %d\n",__FUNCTION__,err));
1063                        bstream_p_attach_rave(decode->stream,false);
1064                }
1065                bos_release_mutex(s_p_mutex);
1066        }
1067
1068        return err;
1069}
1070
1071/*
1072Summary:
1073Stop decoding a stream.
1074Description:
1075The stream remains valid after decode is stopped. Decode could be restarted
1076without retuning or restarting playback.
1077*/
1078void bdecode_stop(
1079                bdecode_t decode /* handle returned by bdecode_open */
1080                ){
1081        BERR_Code berr;
1082        BDBG_ASSERT(decode);
1083
1084        if (!decode->status.bVideoDecoding)
1085                return;
1086
1087#ifdef CONFIG_EIA_708
1088        bdisplay_vbi_clear_cc();
1089#endif
1090
1091        BDBG_ASSERT(decode->stream);
1092        BDBG_ASSERT(decode->stream->hRaveCx);
1093        if (bos_acquire_mutex(s_p_mutex,DECODE_MUTEX_TIMEOUT) == b_ok)
1094        {
1095                //RLQ, move it after stop decoder to fix decoder FW timeout issue if changing channel too fast
1096                //bstream_p_attach_rave(decode->stream,false);
1097                berr = BXVD_StopDecode(GetXVDCh());
1098                if (berr != BERR_SUCCESS)
1099                {
1100                        BDBG_ERR(("%s BXVD_StopDecode failed\n",__FUNCTION__));
1101                }
1102                bstream_p_attach_rave(decode->stream,false);
1103                decode->status.bVideoDecoding = false;
1104                bos_release_mutex(s_p_mutex);
1105        }
1106        //decode->status.bVideoDecoding = false;
1107}
1108
1109/*
1110Summary:
1111Get the status of the decoder and current source.
1112*/
1113bresult bdecode_get_status(
1114                bdecode_t decode,          /* handle returned by bdecode_open */
1115                bdecode_status *status  /* [out] status to be populated */
1116                ){
1117        BXPT_Rave_BufferInfo bufInfo;
1118        BXPT_Rave_RecordStats recStats;
1119        BXVD_PTSInfo PTSInfo;
1120        BXVD_ChannelStatus xvdStatus;   
1121        BXVD_DisplayMode displayMode;
1122        BDBG_ASSERT(decode);
1123
1124        BKNI_Memset(status, 0, sizeof(*status));
1125        if (!decode->status.bVideoDecoding)
1126        {
1127                return b_ok;
1128        }
1129
1130        BDBG_ASSERT(decode->stream);
1131        BDBG_ASSERT(decode->stream->hRaveCx);
1132
1133        BKNI_Memcpy(status,&(decode->status),sizeof(decode->status));
1134        BKNI_Memset(&recStats, 0, sizeof(recStats));
1135        BKNI_Memset(&bufInfo, 0, sizeof(bufInfo));
1136
1137        if (BXPT_Rave_GetBufferInfo(decode->stream->hRaveCx, &bufInfo) == BERR_SUCCESS)
1138        {
1139                status->video_fifo_depth = bufInfo.CdbDepth;
1140                status->video_fifo_size = bufInfo.CdbSize;
1141        }
1142
1143        if (BXVD_GetPTS(GetXVDCh(),&PTSInfo) == BERR_SUCCESS)
1144        {
1145                status->video_pts = PTSInfo.ui32RunningPTS;
1146                status->video_pts_error = PTSInfo.uiPCROffset;
1147        }
1148        status->bPCR_Lock = BXPT_PcrOffset_IsOffsetValid(decode->stream->hPcrOffset);
1149        status->vPID = decode->stream->mpeg.video[0].pid;
1150        status->pcrPID = decode->stream->mpeg.pcr_pid;
1151        status->video_stc = BXPT_PcrOffset_GetStc_isr(decode->stream->hPcrOffset) + 
1152                BXPT_PcrOffset_GetOffset_isr(decode->stream->hPcrOffset);
1153        BXVD_GetChannelStatus(GetXVDCh(), &xvdStatus);
1154        status->xvdch_status = xvdStatus.uiAVDStatusBlock;
1155        status->underflow_cnt = xvdStatus.ulUnderflowCount;
1156        status->decoder_drop_cnt = xvdStatus.uiDecoderDroppedCount;
1157        status->display_drop_cnt = xvdStatus.uiDisplayManagerDroppedCount;
1158        status->pic_received = xvdStatus.uiPicturesReceivedCount;
1159
1160        BXVD_GetVideoDisplayMode(GetXVDCh(), &displayMode);
1161        status->TSM_Mode = displayMode;
1162
1163        return b_ok;
1164}
1165
1166/*
1167Summary:
1168Get the config for the decoder.
1169*/
1170void bdecode_get_config(
1171                bdecode_t decode,  /* handle returned by bdecode_open */
1172                bdecode_config *cfg /* [out] configuration structure to be populated */
1173                ){
1174        unsigned int flags;
1175        flags = bos_enter_critical();
1176        *cfg = decode->config;
1177        bos_exit_critical(flags);
1178
1179}
1180
1181/*
1182Summary:
1183Set the config for the decoder.
1184*/
1185void bdecode_set_config(
1186                bdecode_t decode,  /* handle returned by bdecode_open */
1187                bdecode_config *cfg /* configuration */
1188                )
1189{
1190        BERR_Code rc;
1191
1192        if (cfg->mute != decode->config.mute)
1193        {
1194                rc = BXVD_EnableMute(GetXVDCh(),cfg->mute);
1195                if (BERR_SUCCESS != rc)
1196                {
1197                        BDBG_ERR(("BXVD_EnableMute failed %d", rc));
1198                        goto failed;
1199                }
1200        }
1201
1202        if ((cfg->channel_change != decode->config.channel_change) && !(cfg->channel_change&decode->config.channel_change)) 
1203        {
1204                BXVD_SetChannelChangeMode(GetXVDCh(), cfg->channel_change);
1205        }
1206
1207#ifndef NO_VCHIP
1208        xds_ctrl_set_cb(&decode->xds_ctrl, (xds_callback_t)cfg->xds_callback);
1209#endif
1210
1211        if (!decode->config.block_vbi && cfg->block_vbi) 
1212        {
1213#ifdef CONFIG_EIA_708
1214                bdisplay_vbi_clear_cc();
1215#endif
1216        }
1217#ifdef ACB612
1218        else {
1219                if (cfg->block_vbi) {
1220#ifdef CONFIG_EIA_708
1221                        bdisplay_vbi_clear_cc();
1222#endif
1223                }
1224        }
1225#endif
1226        decode->config = *cfg;
1227
1228        return;
1229failed:
1230        BDBG_ERR(("bdecode_set_config failed"));
1231
1232}
1233
1234
1235static void bdecode_watchdog_task(void *arg)
1236{
1237        BERR_Code rc = BERR_SUCCESS;
1238        bdecode_t decode = (bdecode_t)arg;
1239        BDBG_ASSERT(decode);
1240
1241        while (1)
1242        {
1243                if (BKNI_WaitForEvent(decode->wdEvent,BKNI_INFINITE) != BERR_SUCCESS) {
1244                        BDBG_ERR(("BKNI_WaitForEvent failed in %s",__FUNCTION__));
1245                        continue;
1246                }
1247                if (b_ok != bos_acquire_mutex(&decode->mutex, -1)) 
1248                        continue;
1249                BDBG_WRN(("process watchdog....!!!"));
1250                rc = bstream_p_rave_enable(decode->stream,false);
1251                if (BERR_SUCCESS != rc)
1252                {
1253                        BDBG_ERR(("%s:%d", __FILE__, __LINE__));
1254                        continue;
1255                }
1256                rc = bstream_p_rave_flush(decode->stream);
1257                if (BERR_SUCCESS != rc)
1258                {
1259                        BDBG_ERR(("%s:%d", __FILE__, __LINE__));
1260                        continue;
1261                }
1262                bos_release_mutex(&decode->mutex);
1263
1264                BXVD_ProcessWatchdog(GetXVD());
1265
1266                if (b_ok != bos_acquire_mutex(&decode->mutex, -1)) 
1267                        continue;
1268                rc = bstream_p_rave_enable(decode->stream,true);
1269                bos_release_mutex(&decode->mutex);
1270                if (BERR_SUCCESS != rc)
1271                {
1272                        BDBG_ERR(("%s:%d", __FILE__, __LINE__));
1273                }
1274        }
1275}
1276
1277
1278
1279
Note: See TracBrowser for help on using the repository browser.