source: svn/newcon3bcm2_21bu/dst/dhl/src/DHL_PSI_Rx.c @ 22

Last change on this file since 22 was 22, checked in by phkim, 11 years ago
  1. phkim
  2. newcon3sk 를 kctv 로 브랜치 함
  • Property svn:executable set to *
File size: 24.4 KB
Line 
1/**
2        @file
3                DHL_MMM.c
4
5        @brief
6                PHOENIX HAL library
7
8        ÀÌ ¸ðµâ¿¡ ´ëÇÑ °£´ÜÇÑ ¼³¸í..
9        ex: AudioVideo decoding/capture/output implementation
10
11        Copyright 2006~2010 Digital STREAM Technology, Inc.
12        All Rights Reserved
13*/
14
15#include "DHL_OSAL.h"
16#include "DHL_DBG.h"
17#include "DHL_PSI.h"
18#include "DHL_PSI_Priv.h"
19#include "DHL_OSAL_Config.h" // for task priority
20
21#include "bsettop_smessage.h"
22
23//#include <stdio.h>
24////#include <string.h>
25
26/*
27        ¸ðµç Çì´õ ÆÄÀÏÀ» Æ÷ÇÔÇÏÁö´Â ¾ÊÀ¸¸ç, compile timeÀ» ÁÙÀ̱â À§ÇØ
28        °¢ ¸ðµâÀº ÇÊ¿äÇÑ ¸¸Å­ÀÇ Çì´õ¸¦ ¼±¾ðÇϵµ·Ï ÇÔ.
29*/
30
31
32
33/*
34        DHL µð¹ö±× ¸ðµâ À̸§ Á¤ÀÇ ·ê Âü°í:
35
36        DHL ¸ðµâµéÀº ¸ðµÎ * ·Î ½ÃÀÛ.
37        API´Â ´ë¹®ÀÚ, Platform ¹× ±âŸ´Â ¼Ò¹®ÀÚ »ç¿ë.
38
39        µðÆúÆ® ·¹º§Àº 0À¸·Î ¼³Á¤ÇÑ´Ù. (0: ¿¡·¯ ¸Þ½ÃÁö¸¸ Ãâ·Â)
40       
41       
42*/
43
44//DHL_MODULE("*psi", 0);
45
46
47
48#if COMMENT
49____Config____(){}
50#endif
51
52
53#define SECTION_TID           0              /* TID index                    */
54#define SECTION_LEN_HI        1              /* length hi index              */
55#define SECTION_LEN_LO        2              /* length lo index              */
56#define SECTION_TID_EXT_HI        3              /* Table ID extension high index*/
57#define SECTION_TID_EXT_LO    4              /* Table ID extension low index */
58#define SECTION_VERSION       5              /* version number index         */
59#define SECTION_NUM           6              /* section number index         */
60#define SECTION_NUM_LAST      7              /* last section number index    */
61#define SECTION_HEADER_LENGTH 8                          /* number of bytes in section header */
62
63#define MAX_SECTION_FILTER              64  // Ĩ¿¡¼­´Â 64°³±îÁö Áö¿øÇÏÁö¸¸ 32°³·Î Á¦ÇÑ
64
65#define SECT_RCV_INFO_BUF_LEN   (32*4) // megakiss 32 -> 32*4
66
67/*
68        section ¼ö½Å½Ã °¢ ¼½¼ÇÀÇ ³¡¿¡ ºÙ´Â TagBytesÀÇ Å©±â
69        TagBytes :
70        5 bytes of TagBytes are appended to each section data. TagBytes begins with CRC check
71        result code followed by 4 bytes of PAT value. CRC check result code of 0x00 indicates CRC
72        valid and 0x80 indicates CRC invalid.
73*/ 
74#define SIZE_TAG_BYTES 5
75
76// ŽºÅ© ½ºÅÃÀÌ ¾ó¸¶³ª ³Ë³ËÇÑÁö´Â ÇöÀç °¡´ÆÇϱ⠾î·Á¿ò.
77// ³ªÁß¿¡ stack check ÇÏ´Â ±â´É ±¸Çö Àü±îÁö´Â ÃæºÐÇÏ°Ô ÇÒ´çÇÏÀÚ.
78//
79#define PSI_RX_TASK_STACK_SIZE 0x4000 // <-- 0x1000  //
80#define PSI_RX_TASK_PRIORITY   TASK_PRI_DHL_PSIPRX
81
82
83#define SECTION_BUF_SIZE (0x1000 + 0x10) // 4KB
84#define SECTION_BUF_NF_MARGIN 0x800 // 2KB
85
86
87#ifndef min
88        #define min(a,b) ((a)<(b) ? (a):(b))
89#endif
90
91
92#if COMMENT
93____Types____(){}
94#endif
95
96/*
97        ÀÌ ¸ðµâ ³»ºÎ¿¡¼­ »ç¿ëµÇ´Â structure ¹× enumerations.
98*/
99typedef struct
100{
101        void* FltId;
102        UINT8 pbuf[4096];
103        UINT32 size;
104} SECT_RCV_INFO_t;
105
106//typedef tDHL_PSI_FiltCtl* tDHL_PSI_ControlHandle;
107
108
109#if COMMENT
110____Variables____(){}
111#endif
112
113/*
114        global·Î Àû¿ëµÇ´Â variable Á¤ÀÇ.
115        °¢ function º°·Î Ư¼öÇÑ ¿ëµµÀÇ variableÀº °¢ functionX block ¿¡¼­ Á¤ÀÇ °¡´É.
116*/
117
118tDHL_PSI_FiltCtl g_fc[MAX_SECTION_FILTER];
119
120SECT_RCV_INFO_t g_sect_rcv_info_buf[SECT_RCV_INFO_BUF_LEN];
121UINT32 g_sect_rcv_info_buf_h = 0, g_sect_rcv_info_buf_t = 0;
122
123
124#if COMMENT
125____PSI_ControlHandle____(){}
126#endif
127
128
129/*
130        psi filter controlÀ» µ¿±âÈ­ Çϱâ À§ÇÑ ¹ÂÅØ½º
131        psi filter controlÀ» »ç¿ëÇÏ´Â ¸ðµç ŽºÅ© »çÀÌÀÇ race conditionÀ» ¹æÁöÇÑ´Ù.
132
133        ÄÚµå ³»¿¡¼­´Â flt_ctrl_lockÀ» Á÷Á¢ È£ÃâÇÏ¸é ¾ÈµÇ¸ç ²À lock_FiltCtl() ¿Í unlock_FiltCtl() ¸¦ ÀÌ¿ëÇÏ¿© ÄÁÆ®·Ñ.
134*/
135static DHL_OS_SEMA_ID flt_ctrl_mtx;
136#define flt_ctrl_lock() DHL_OS_TakeSemaphore(flt_ctrl_mtx, DHL_TIMEOUT_FOREVER)
137#define flt_ctrl_unlock() DHL_OS_GiveSemaphore(flt_ctrl_mtx)   
138
139
140/*
141        todo : zooyouny 100903
142        g_psi_uid_of_control_handle[] ÀÌ ²À ÇÊ¿äÇѰ¡?
143        ÀÌ Å×À̺íÀ» »ç¿ëÇÏ´Â ¸ñÀûÀÌ handle validity¸¦ À§ÇÑ °ÍÀ̶ó¸é
144        g_fc¿¡ ÀÖ´Â handle °ªÀ» ÂüÁ¶Çصµ µÇÁö ¾ÊÀ»±î?
145*/
146/*
147        psi control handleÀÇ unique id
148        unique id°¡ 0À̶ó´Â °ÍÀº psi control handleÀÌ ¾ÆÁ÷ »ý¼º µÇÁö ¾Ê¾Ò°Å³ª,
149        »ç¿ëÀÌ ³¡³ª releaseµÇ¾úÀ½À» ÀǹÌ
150*/
151static UINT16 g_psi_uid_of_control_handle[MAX_SECTION_FILTER];
152static UINT16 g_psi_control_handle_unique_id = 1;
153
154#define PSI_CTL_HANDLE_ARRAY_MASK       0x0000ffff
155#define PSI_CTL_HANDLE_UID_MASK         0xffff0000
156#define PSI_CTL_HANDLE_UID_SHIFT        16 // PSI_CTL_HANDLE_UID_MASK °ª¿¡ µû¶ó ´Þ¶óÁü
157#define PSI_CTL_HANDLE_GET_ARRAY_ID(handle)     \
158        ((UINT32)(handle) & PSI_CTL_HANDLE_ARRAY_MASK)
159#define PSI_CTL_HANDLE_GET_UID(handle) \
160        (((UINT32)(handle)&PSI_CTL_HANDLE_UID_MASK)>>PSI_CTL_HANDLE_UID_SHIFT)
161
162/*
163        tDHL_PSI_ControlHandle À» »ý¼ºÇÑ´Ù.
164        ¸ð´ÏÅ͸µÀÌ Á¾·áµÉ¶§ ¹Ýµå½Ã release µÇ¾î¾ß ÇÑ´Ù.
165        ¹Ýµå½Ã lock_FiltCtl() ¿Í unlock_FiltCtl() ¾È¿¡¼­ ¼öÇàµÇ¾î¾ß ÇÔ.
166*/
167static tDHL_PSI_ControlHandle get_psi_control_handle()
168{       
169        int i;
170        UINT32 handle = 0;
171
172        {
173                // 1. »ç¿ë °¡´ÉÇÑ g_fc ¹è¿­ À妽º(i) ȹµæ
174                // MAX_SECTION_FILTER°¡ handle¿¡¼­ ¹è¿­ À妽º·Î »ç¿ëÇÏ´Â ¹üÀ§¸¦ ³Ñ¾î¼­¸é ¾ÈµÈ´Ù.
175                // ÇöÀç´Â handleÀÇ ¹è¿­ À妽º ¹üÀ§°¡ 0~65535
176                for (i = 0; i < MAX_SECTION_FILTER; i++)
177                        if(g_psi_uid_of_control_handle[i] == 0)
178                                break;
179
180                if (i == MAX_SECTION_FILTER) // no more section filter to give
181                        return 0;
182
183                // 2. unique ID »ý¼º
184                /* ÇâÈÄ handle validity check¸¦ À§ÇØ unique id¸¦ g_psi_uid_of_control_handle¿¡ ÀúÀå*/
185                g_psi_uid_of_control_handle[i] = g_psi_control_handle_unique_id;
186
187                g_psi_control_handle_unique_id++;
188                if (g_psi_control_handle_unique_id == 0)
189                        g_psi_control_handle_unique_id = 1;                     
190               
191               
192                // 3. ÃÖÁ¾ Control Handle »ý¼º
193                handle |= (i & PSI_CTL_HANDLE_ARRAY_MASK);
194                handle |= (g_psi_uid_of_control_handle[i] << PSI_CTL_HANDLE_UID_SHIFT);
195        }
196
197        return (tDHL_PSI_ControlHandle)handle;
198}
199
200
201/*
202        tDHL_PSI_ControlHandle À» release
203        ¹Ýµå½Ã lock_FiltCtl() ¿Í unlock_FiltCtl() ¾È¿¡¼­ ¼öÇàµÇ¾î¾ß ÇÔ.
204*/
205static DHL_RESULT release_psi_control(tDHL_PSI_ControlHandle handle)
206{
207        DHL_RESULT res = DHL_OK;
208        int id = PSI_CTL_HANDLE_GET_ARRAY_ID(handle);
209
210        // handle validity check
211        if (handle == 0 || id >= MAX_SECTION_FILTER || id < 0)
212                return DHL_FAIL_INVALID_PARAM;
213       
214        {
215                if (g_psi_uid_of_control_handle[id] == 0)
216                        /*      ÀÌ¹Ì release µÇ¾ú°Å³ª »ç¿ëµÈ ÀûÀÌ ¾ø´Â ÇÚµéÀÓ   */
217                        res = DHL_FAIL_INVALID_HANDLE;
218                else if (g_psi_uid_of_control_handle[id] != PSI_CTL_HANDLE_GET_UID(handle))
219                        /*
220                                handleÀÇ uid¿Í uid list¿¡ ÀúÀåµÈ unique id°¡ ÀÏÄ¡ ÇÏÁö ¾ÊÀ½.
221                                ´Ù¸¥ filter controlÀÌ ÇÒ´ç µÈ °æ¿ìÀÓ.
222                        */
223                        res = DHL_FAIL_NOT_AVAILABLE;
224                else
225                        g_psi_uid_of_control_handle[id] = 0;
226        }
227
228        if (res != DHL_OK)
229                printf( "invalid handle(%0x) used in release_psi_control!!", handle);
230       
231        return res;
232}
233
234/*
235        tDHL_PSI_ControlHandle À» ÀÌ¿ëÇÏ¿© section info °¡ µé¾îÀÖ´Â tDHL_PSI_FiltCtl À» °¡Á®¿È.
236        handle ÀÌ release µÈ °æ¿ì NULL À» ¹Ýȯ.
237        ¹Ýµå½Ã lock_FiltCtl() ¿Í unlock_FiltCtl() ¾È¿¡¼­ ¼öÇàµÇ¾î¾ß ÇÔ.
238*/
239static tDHL_PSI_FiltCtl* get_FiltCtl(tDHL_PSI_ControlHandle handle)
240{
241        int id = PSI_CTL_HANDLE_GET_ARRAY_ID(handle);
242
243        // handle validity check
244        if (handle == 0 || id >= MAX_SECTION_FILTER || id < 0)
245                return NULL;
246
247        {
248                if (g_psi_uid_of_control_handle[id] == 0)
249                        /*      ÀÌ¹Ì release µÇ¾ú°Å³ª »ç¿ëµÈ ÀûÀÌ ¾ø´Â ÇÚµéÀÓ   */
250                        goto label_err;
251                else if (g_psi_uid_of_control_handle[id] != PSI_CTL_HANDLE_GET_UID(handle))
252                        /*
253                                handleÀÇ uid¿Í uid list¿¡ ÀúÀåµÈ unique id°¡ ÀÏÄ¡ ÇÏÁö ¾ÊÀ½.
254                                ´Ù¸¥ filter controlÀÌ ÇÒ´ç µÈ °æ¿ìÀÓ.
255                        */
256                        goto label_err;
257        }
258
259        return &g_fc[id];
260
261label_err:
262        printf( "invalid handle(%0x) is used in lock_FiltCtl..!!\n", handle);
263
264        return NULL;   
265       
266}
267
268/*     
269          g_psi_uid_of_control_handle ¿Í g_fc ¸¦ º¸È£Çϱâ À§ÇÑ lock api.
270          g_psi_uid_of_control_handle ¿Í g_fc ¸¦ ÄÁÆ®·Ñ ÇÏ´Â ¸ðµç api ´Â lock_FiltCtl() ¿Í unlock_FiltCtl() À¸·Î
271          º¸È£ µÇ¾î¾ß ÇÔ.
272*/
273static void lock_FiltCtl(void)
274{               
275        flt_ctrl_lock();
276}
277
278static void unlock_FiltCtl(void)
279{       
280        flt_ctrl_unlock();     
281}
282
283static void p_filter_control_reset(tDHL_PSI_FiltCtl* pFlt, int index)
284{
285        memset(pFlt, 0, sizeof(tDHL_PSI_FiltCtl));
286        pFlt->index = index;
287        pFlt->curVersion = -1;
288}
289
290
291#if COMMENT
292____Rx____(){}
293#endif
294
295
296//static char *psi_tid_str(UINT8 t)
297//{
298//      static char buf[10];
299//      return
300//              (t)==0x00 ? "pat" : \
301//              (t)==0x02 ? "pmt" : \
302//              (t)==0xC7 ? "mgt" : \
303//              (t)==0xC8 ? "tvt" : \
304//              (t)==0xC9 ? "cvt" : \
305//              (t)==0xCA ? "rrt" : \
306//              (t)==0xCB ? "eit" : \
307//              (t)==0xCC ? "ett" : \
308//              (t)==0xCD ? "stt" : \
309//              (t)==0xD8 ? "eas" : \
310//              (sprintf(buf, "x%02x", t), buf);
311//}
312
313static void* dhl_psi_rx_cb(void * context, size_t size)
314{
315        if (size == 0 || size > 4096)
316        {
317                printf("%s|ERR|size == %d\n", __func__, size);
318                return 0;
319        }
320        if (context == 0)
321        {
322                printf("%s|ERR|context == %d\n", __func__, context);
323                return 0;
324        }
325        tDHL_PSI_FiltCtl * pFltCtl = (tDHL_PSI_FiltCtl *)context;
326        if (pFltCtl->pRawBuff == 0)
327        {
328                printf("%s|pFltCtl->pRawBuff == 0\n", __func__);
329                return 0;
330        }
331        g_sect_rcv_info_buf[g_sect_rcv_info_buf_h].FltId = pFltCtl->Filter_ID;
332        g_sect_rcv_info_buf[g_sect_rcv_info_buf_h].size = size;
333        memcpy(g_sect_rcv_info_buf[g_sect_rcv_info_buf_h].pbuf, pFltCtl->pRawBuff, size);
334        g_sect_rcv_info_buf_h = (g_sect_rcv_info_buf_h >= SECT_RCV_INFO_BUF_LEN-1) ? 0 : g_sect_rcv_info_buf_h+1;       
335//      printf("g_sect_rcv_info_buf_h = %d\n", g_sect_rcv_info_buf_h);
336        return (void*)(pFltCtl->pRawBuff);
337}
338
339static void dhl_psi_rx_process(SECT_RCV_INFO_t *info)
340{
341        int i;
342        for (i = 0; i < MAX_SECTION_FILTER; i++)
343        {
344                if (g_fc[i].active == FALSE) continue;
345                if (g_fc[i].isPaused == TRUE) continue;
346                if (g_fc[i].Filter_ID != info->FltId) continue;
347                tDHL_PSI_FiltCtl* fltCtl = get_FiltCtl(g_fc[i].handle);
348                if (fltCtl == NULL) // ÀÌ¹Ì release µÇ¾ú°Å³ª À߸øµÈ ÇÚµéÀÓ
349                {
350                        printf( "!! invalid psi control handle..!!"); 
351                        continue;
352                }
353                int sect_size = 0;
354                tDHL_PSI_Event psi_event = dhl_psi_post_data_received(fltCtl, info->pbuf, info->size, &sect_size);
355                if (psi_event != ePSIEVENT_DATARECEIVED) continue;
356                if (fltCtl->param.eventProc ==0) continue;
357                fltCtl->param.eventProc(psi_event, (tDHL_PSI_ControlHandle)fltCtl->handle, fltCtl->param.userParam);
358        }
359}
360
361
362#if COMMENT
363____Task____(){}
364#endif
365
366
367// µå¶óÀ̹ö¿¡¼­ »ç¿ëÇÏ´Â ´Ù¸¥ event flag¿Í °ãÄ¡¸é ¾ÈµÈ´Ù.
368#define PSI_RX_TASK_STOP_EVENT 0x80000000
369
370
371static DHL_OS_TASK_ID g_psi_rx_tid;
372
373static void psi_rx_task(void* arg) 
374{
375        printf( "psi rx task start..\n");
376        while(1)
377        {
378                if (g_sect_rcv_info_buf_t == g_sect_rcv_info_buf_h)
379                {
380                        DHL_OS_Delay(10);
381                        continue;
382                }
383                lock_FiltCtl();
384                dhl_psi_rx_process(&g_sect_rcv_info_buf[g_sect_rcv_info_buf_t]);
385                unlock_FiltCtl();
386                g_sect_rcv_info_buf_t = (g_sect_rcv_info_buf_t >= SECT_RCV_INFO_BUF_LEN-1) ? 0 : g_sect_rcv_info_buf_t+1;
387//              printf("g_sect_rcv_info_buf_t = %d\n", g_sect_rcv_info_buf_t);
388        }
389        printf( "\n== psi rx task end\n");
390        DHL_OS_SelfDeleteTask();
391}
392
393
394
395void dhl_psi_start_task(void)
396{
397        if (g_psi_rx_tid) {
398                printf( "!! already task running\n");
399        }
400        else {
401                g_psi_rx_tid = DHL_OS_CreateTask(psi_rx_task, "psirx", 
402                                PSI_RX_TASK_PRIORITY, PSI_RX_TASK_STACK_SIZE, 0);
403
404                if (!g_psi_rx_tid) {
405                        printf( "!! task create err\n");
406                }
407                else {
408                        printf( "psi rx task started..\n");
409                }
410        }
411}
412
413void dhl_psi_stop_task(void)
414{
415
416}
417
418
419
420#if COMMENT
421____Group2____(){}
422#endif
423
424
425void update_psi_filter(tDHL_PSI_FiltCtl *pFltCtl)
426{       
427        if (pFltCtl == NULL)
428                return;
429       
430//errexit:
431}
432
433
434#if COMMENT
435____Resume_Pause____(){}
436#endif
437
438/*
439        one shot filter¿¡¼­ section ¼ö½Å ÈÄ ´õÀÌ»ó ¼ö½ÅÀ» ÇÏÁö ¾ÊÀ» °æ¿ì È£ÃâµÈ´Ù.     
440        resumeµÇ¸é ´Ù½Ã µ¿ÀÛ ÇÔ.
441*/
442void pause_psi_filter(tDHL_PSI_FiltCtl* pFltCtl)
443{
444        if (!pFltCtl) {
445                printf( "!! %s: invalid handle\n", __func__);
446                goto errexit;
447        }
448       
449        pFltCtl->isPaused = 1;
450
451errexit:
452        ;
453}
454
455void resume_psi_filter(tDHL_PSI_FiltCtl* pFltCtl)
456{
457        if (!pFltCtl) {
458                printf( "!! %s: invalid handle\n", __func__);
459                goto errexit;
460        }
461       
462        pFltCtl->isPaused = 0;
463       
464errexit:
465        ;
466}
467
468#if COMMENT
469____Start_Stop____(){}
470#endif
471
472/*
473        API ½ÃÀ۽à ¹Ýµå½Ã lock_FiltCtl() ·Î º¸È£µÇ¾î¾ß Çϸç API °¡ Á¾·áµÇ¸é ¹Ýµå½Ã
474        unlock_FiltCtl() ·Î unlock µÇ¾î¾ß ÇÔ.
475*/
476DHL_RESULT dhl_psi_start(
477                tDHL_TSD tsd, UINT16 pid, 
478                tDHL_PSI_Filter *pref,
479                tDHL_PSI_StartParam *param,
480                tDHL_PSI_ControlHandle *pHandle)
481{
482        DHL_RESULT dhr = DHL_OK;
483//      UINT8 tid_mask;
484//      UINT16 tid_ext_mask;
485//      UINT8 sdec_tid;
486//      UINT16 sdec_tid_ext;
487        void* idxFlt;
488        tDHL_PSI_FiltCtl *pFltCtl = NULL;
489        int i;
490       
491        if (pHandle == NULL)
492                return DHL_FAIL_INVALID_PARAM;
493
494        lock_FiltCtl();
495       
496        *pHandle = get_psi_control_handle(); // stop monitorÇÒ ¶§ ¹Ýµå½Ã release µÇ¾î¾ß ÇÔ
497        if (*pHandle == 0)
498        {
499                dhr =  DHL_FAIL_TOO_MANY_INSTANCES;
500                goto err_handle;
501        }
502       
503        pFltCtl = get_FiltCtl(*pHandle);
504        if (pFltCtl == NULL) // ÀÌ¹Ì release µÇ¾ú°Å³ª À߸øµÈ ÇÚµéÀÓ
505        {
506                printf( "!! invalid psi control handle..!!"); 
507                dhr =  DHL_FAIL_NOT_AVAILABLE;
508                goto err;
509        }
510
511        // °°Àº Á¶°ÇÀÇ filter °¡ ÀÌ¹Ì °É·Á ÀÖ´ÂÁö À̰÷¿¡¼­ °Ë»ç
512        for (i = 0; i < MAX_SECTION_FILTER; i++)
513        {
514                if (g_fc[i].active == TRUE && g_fc[i].pid == pid &&
515#if 1//BRCM
516                        g_fc[i].pFltData->coef[0] == pref->coef[0])
517#else
518                    g_fc[i].pFltData->data[0] == pref->data[0])
519#endif
520                {
521                        break;
522                }
523        }
524
525        p_filter_control_reset(pFltCtl, pFltCtl->index);
526
527       
528        if (i < MAX_SECTION_FILTER)
529        {
530                // ÀÖÀ¸¸é
531                idxFlt = g_fc[i].Filter_ID;
532        }
533        else
534        {
535#ifndef TUNER_BAND
536        #define TUNER_BAND 0
537#endif
538
539                smessage_stream_params_t msg_params;
540                smessage_stream_t   msg_idx= smessage_open(smessage_format_psi);
541                if (msg_idx == NULL)
542                {
543                        dhr =  DHL_FAIL_TOO_MANY_INSTANCES;
544                        goto err_handle;
545                }
546                idxFlt = (void*) msg_idx;
547
548                smessage_stream_params_init(&msg_params, NULL);
549
550                msg_params.band = TUNER_BAND;   //ÀÏ´Ü ¹Þ¾ÆÁü..
551
552                msg_params.pid = pid;
553
554                memcpy(msg_params.filter.coef, pref->coef, FILTER_MAX_BYTE);
555                memcpy(msg_params.filter.mask, pref->mask, FILTER_MAX_BYTE);
556                memcpy(msg_params.filter.excl, pref->excl, FILTER_MAX_BYTE);
557
558                pFltCtl->pRawBuff = msg_params.buffer = DHL_OS_Malloc(param->maxData);
559
560                msg_params.buffer_size = param->maxData;
561                /* processing is done in callback */
562                msg_params.data_ready_callback = dhl_psi_rx_cb;
563                msg_params.overflow = NULL;
564               
565                msg_params.crc_disabled = 0;
566               
567                //BKTODO: pFltCtlÀº »ç½Ç ¹Ø¿¡¼­ ÃʱâÈ­ µÈ´Ù. ¸ÕÀú callbackÀÌ ¶ß¸é ¹®Á¦ µÊ.task priority °ËÅä ÇÊ¿ä.
568                msg_params.callback_context = (void *)pFltCtl;         
569                if (b_ok != smessage_start(&msg_params, msg_idx))
570                {
571                        printf("FATAL: %s:%d\n",__FILE__, __LINE__);
572                        if(msg_params.buffer)
573                                DHL_OS_Free(&msg_params.buffer);
574                        dhr =  DHL_FAIL_TOO_MANY_INSTANCES;
575                        goto err_handle;
576                }
577        }
578
579        pFltCtl->handle = (int)*pHandle;
580        pFltCtl->Filter_ID = idxFlt;
581        pFltCtl->pid = pid;
582        pFltCtl->pFltData = pref;       // ÂüÁ¶, ±âÁ¸ ÄÚµå(NEO)ÀÇ ¼öÁ¤À» ÃÖ¼ÒÈ­ Çϱâ À§ÇØ ÂüÁ¶·Î ÇÏ¿´À½.
583        pFltCtl->param = *param;   // ÂüÁ¶°¡ ¾Æ´Ï¶ó º¹»ç!!
584        pFltCtl->isPaused = 0;
585        pFltCtl->active = 1;
586       
587        if (0)
588        {
589                DHL_OS_Printf("|%s| pid : 0x%x\n", __FUNCTION__, pFltCtl->pid);
590                DHL_OS_Printf("|%s| data : ", __FUNCTION__);
591                for (i = 0; i < FILTER_MAX_BYTE; i++)
592                {
593                        DHL_OS_Printf("%2x ", pFltCtl->pFltData->coef[i]);
594                }
595                DHL_OS_Printf("\n");
596                DHL_OS_Printf("|%s| mask : ", __FUNCTION__);
597                for (i = 0; i < FILTER_MAX_BYTE; i++)
598                {
599                        DHL_OS_Printf("%2x ", pFltCtl->pFltData->mask[i]);
600                }
601                DHL_OS_Printf("\n");
602                DHL_OS_Printf("|%s| mode : ", __FUNCTION__);
603                for (i = 0; i < FILTER_MAX_BYTE; i++)
604                {
605                        DHL_OS_Printf("%2x ", pFltCtl->pFltData->excl[i]);
606                }
607                DHL_OS_Printf("\n");
608                DHL_OS_Printf("|%s| filter id : 0x%x\n", __FUNCTION__,
609                              pFltCtl->Filter_ID);
610        }
611       
612        printf( "psi start success\n");
613
614        unlock_FiltCtl();
615       
616        return dhr;
617       
618err:
619        //yhkim, 111222, handle ÀÌ »ý¼ºµÈ ÈÄ error °¡ ¹ß»ýÇÑ °æ¿ì ¹Ýµå½Ã handle À» release ÇØÁÜ.
620        release_psi_control(*pHandle);
621
622err_handle:     
623        unlock_FiltCtl();       
624
625        return dhr;
626}
627
628/*
629        API ½ÃÀ۽à ¹Ýµå½Ã lock_FiltCtl() ·Î º¸È£µÇ¾î¾ß Çϸç API °¡ Á¾·áµÇ¸é ¹Ýµå½Ã
630        unlock_FiltCtl() ·Î unlock µÇ¾î¾ß ÇÔ.
631*/
632void dhl_psi_stop(tDHL_PSI_ControlHandle handle)
633{
634//      DHL_RESULT dhr;
635        tDHL_PSI_FiltCtl *pFltCtl = NULL;
636//      SINT8 ret;
637        int i;
638       
639        if (handle == 0)
640                return;
641       
642        lock_FiltCtl();
643       
644        pFltCtl = get_FiltCtl(handle);
645        if (!pFltCtl) // ÀÌ¹Ì release µÇ¾ú°Å³ª À߸øµÈ ÇÚµéÀÓ
646        {
647                printf( "!! %s: invalid handle %x\n", __func__, handle);
648                goto err_handle;
649        }
650       
651        pFltCtl->active = 0;
652       
653        // °°Àº Á¶°ÇÀÇ filter °¡ ÀÌ¹Ì °É·Á ÀÖ´ÂÁö À̰÷¿¡¼­ °Ë»ç
654        for (i = 0; i < MAX_SECTION_FILTER; i++)
655        {
656#if 0
657                if (g_fc[i].active == TRUE && g_fc[i].pid == pFltCtl->pid)
658#else
659                if (g_fc[i].active == TRUE && g_fc[i].pid == pFltCtl->pid &&
660#if 1//BRCM
661                        g_fc[i].pFltData->coef[0] == pFltCtl->pFltData->coef[0])
662#else
663                    g_fc[i].pFltData->data[0] == pFltCtl->pFltData->data[0])
664#endif
665#endif
666                {
667                        break;
668                }
669        }
670
671        if (i < MAX_SECTION_FILTER)
672        {
673                // ÀÖÀ¸¸é
674        }
675        else
676        {
677                if (b_ok != smessage_stop((smessage_stream_t)pFltCtl->Filter_ID))
678                {
679                        printf("FATAL: %s:%d\n",__FILE__, __LINE__);
680                        return;
681                }
682                smessage_close((smessage_stream_t)pFltCtl->Filter_ID);
683                if(pFltCtl->pRawBuff)
684                {
685                        DHL_OS_Free((void **)&pFltCtl->pRawBuff);
686                }
687        }
688       
689//label_exit:
690        if (pFltCtl->pFltData)
691        {
692                DHL_PSI_FreeFilter(pFltCtl->pFltData);
693                pFltCtl->pFltData = NULL;
694        }
695       
696        if (pFltCtl->curDataArray)
697        {
698                dhl_psi_free_data_array(pFltCtl->curDataArray);
699                pFltCtl->curDataArray = NULL;
700        }
701       
702        if (pFltCtl->nextDataArray)
703        {
704                dhl_psi_free_data_array(pFltCtl->nextDataArray);
705                pFltCtl->nextDataArray = NULL;
706        }
707        p_filter_control_reset(pFltCtl, pFltCtl->index);
708       
709//errexit:
710        //yhkim, 111222, handle À» release ÇÒ °æ¿ì ¹Ýµå½Ã unlock_FiltCtl() Àü¿¡ ÇØÁÖµµ·Ï ÇÔ.
711        release_psi_control(handle);
712       
713err_handle:
714        unlock_FiltCtl();
715}
716
717
718
719#if COMMENT
720____PSI_Data____(){}
721#endif
722
723/*     
724        API ½ÃÀ۽à ¹Ýµå½Ã lock_FiltCtl() ·Î º¸È£µÇ¾î¾ß Çϸç API °¡ Á¾·áµÇ¸é ¹Ýµå½Ã
725        unlock_FiltCtl() ·Î unlock µÇ¾î¾ß ÇÔ.
726*/
727DHL_RESULT dhl_psi_read_data(tDHL_PSI_ControlHandle handle, tDHL_PSI_DataArray **ppData)
728{
729        DHL_RESULT res = DHL_OK;
730        tDHL_PSI_FiltCtl* pFltCtl;
731        int id = PSI_CTL_HANDLE_GET_ARRAY_ID(handle);
732//      int i;
733
734        if (handle == 0 || id >= MAX_SECTION_FILTER || id < 0)
735                return DHL_FAIL_INVALID_PARAM;
736
737        lock_FiltCtl();
738
739        pFltCtl = get_FiltCtl(handle);
740        if (!pFltCtl) // ÀÌ¹Ì release µÇ¾ú°Å³ª À߸øµÈ ÇÚµéÀÓ
741        {
742                printf( "!! %s: psi data is not available..\n", __func__);
743                res = DHL_FAIL_NOT_AVAILABLE;
744                goto err;
745        }
746
747        if (pFltCtl->curDataArray) {
748                *ppData = pFltCtl->curDataArray;
749                pFltCtl->curDataArray = NULL;
750        }
751        else {
752                *ppData = NULL;
753                res = DHL_FAIL_NOT_FOUND;
754        }
755       
756err:
757        unlock_FiltCtl();
758
759        return res;
760}
761
762
763
764
765#if COMMENT
766____Debug____(){}
767#endif
768
769/*     
770        API ½ÃÀ۽à ¹Ýµå½Ã lock_FiltCtl() ·Î º¸È£µÇ¾î¾ß Çϸç API °¡ Á¾·áµÇ¸é ¹Ýµå½Ã
771        unlock_FiltCtl() ·Î unlock µÇ¾î¾ß ÇÔ.
772*/
773void dhl_psi_show()
774{
775        int i;
776        tDHL_PSI_FiltCtl *pFltCtl;
777        int nActiveFlt = 0;
778
779        DHL_OS_Printf("---- dhl psi statistics!!! ----\n");
780
781        lock_FiltCtl();
782
783        for (i=0; i<MAX_SECTION_FILTER; i++)
784        {
785                pFltCtl = &g_fc[i];
786                if (pFltCtl->active == 0) continue;
787
788                DHL_OS_Printf("(%2d) fid %x, pid %04x, tid %02x, mode %s %d\n", 
789                        i, pFltCtl->Filter_ID,
790                        pFltCtl->pid, 
791                        pFltCtl->pFltData->coef[0], // tid
792//                      pFltCtl->pFltData->data[0], // tid
793                        pFltCtl->param.psiMode==ePSIMODE_SECTION ? "sec" : "tbl",
794                        pFltCtl->param.updateMode,
795                        0);
796                nActiveFlt++;
797        }
798
799        unlock_FiltCtl();
800       
801        DHL_OS_Printf("total %d active filters\n\n", nActiveFlt);
802
803}
804
805
806
807
808#if COMMENT
809____Demux____(){}
810#endif
811
812
813// À̰÷ÀÇ Demux ¼³Á¤ ÄÚµå´Â DHL_Demux ·Î À̵¿..
814
815
816
817#if COMMENT
818____Symbol____(){}
819#endif
820
821
822#if DHL_REGISTER_DEUBG_SYMBOLS
823
824static DHL_SymbolTable _symbols[] =
825{
826        /* however, if you want typing short-cut, it is good usage.
827        DHL_FNC_SYM_ENTRY2("epg_start", App_EpgUpdateStart),
828        DHL_FNC_SYM_ENTRY2("epg_stop", App_EpgUpdateCancel),
829        DHL_FNC_SYM_ENTRY2("epg_list", Dmc_EpgPrintAllTables),
830        DHL_FNC_SYM_ENTRY2("epg_delete", App_EpgDeleteAll),
831
832        DHL_VAR_SYM_ENTRY(g_XX_TestMode),
833        */
834        0,
835};
836
837#endif  /* DHL_REGISTER_DEUBG_SYMBOLS */
838
839
840
841#if COMMENT
842____Init____(){}
843#endif
844
845
846
847void dhl_psi_init(void)
848{
849        int i;
850
851#if DHL_REGISTER_DEUBG_SYMBOLS
852        DHL_DBG_RegisterSymbols(_symbols, DHL_NUMSYMBOLS(_symbols));
853#endif
854
855        memset(&g_fc, 0, sizeof(g_fc));
856        for (i=0; i<MAX_SECTION_FILTER; i++) {
857                g_fc[i].index = i;  // assign self index..
858        }
859
860        // flt_ctrl_mtx ÃʱâÈ­
861        flt_ctrl_mtx = DHL_OS_CreateMutexSemaphore("FLTCTRL");
862        DHL_ASSERT(flt_ctrl_mtx != DHL_INVALID_SEMA_ID, "create mtx failed.. \n");
863
864        dhl_psi_start_task();
865
866}
867
868void dhl_psi_uninit(void)
869{
870        dhl_psi_stop_task();
871
872}
873
874
875#if COMMENT
876____Test____(){}
877#endif
878
879#if 0
880static BOOL sect_pause = 0;
881
882void set_sect_pause(BOOL p)
883{
884        sect_pause = p;
885}
886
887void cb_sect(MS_U8 u8DmxId, DMX_EVENT enEvent) 
888{
889        DHL_OS_Printf("|%s| id = %x, evnet = %x\n", __FUNCTION__, u8DmxId, enEvent);
890       
891        if (enEvent == DMX_EVENT_DATA_READY)
892        {
893                static MS_U8 *sect_chunk_buf = NULL;
894                MS_U32 sect_len = 0, sect_remain = 0;
895                int i;
896               
897                if (sect_pause)
898                {
899                        DHL_OS_Printf("|%s| skip section data receive(fid:0x%x).\n",
900                                              __FUNCTION__, u8DmxId);
901                       
902                        return;
903                }
904               
905                // allocate temporary buffer
906                if (sect_chunk_buf == NULL)
907                {
908                        sect_chunk_buf = (MS_U8 *)DHL_OS_Malloc(SECTION_BUF_SIZE);
909                        if (sect_chunk_buf == NULL)
910                        {
911                                DHL_OS_Printf("|%s| fail to allocate memory psi_buf.\n",
912                                              __FUNCTION__);
913                               
914                                return;
915                        }
916                }
917               
918                if (MApi_DMX_CopyData(u8DmxId, sect_chunk_buf, SECTION_BUF_SIZE,
919                                          &sect_len, &sect_remain, NULL) !=
920                    DMX_FILTER_STATUS_OK)
921                {
922                        DHL_OS_Printf("|%s| fail to copy section filter data(fid:0x%x)\n",
923                                      __FUNCTION__, u8DmxId);
924                       
925                        return;
926                }
927               
928                DHL_OS_Printf("sect_len : 0x%x, sect_remain : 0x%x\n", sect_len, sect_remain);
929                for (i = 0; i < sect_len; i++)
930                {
931                        DHL_OS_Printf("%2x ", sect_chunk_buf[i]);
932                        if ((i & 0x0f) == 0x0f)
933                        {
934                                DHL_OS_Printf("\n");
935                        }
936                }
937                if ((i & 0x0f) != 0x00)
938                {
939                        DHL_OS_Printf("\n");
940                }
941        }
942}
943
944void flush_sect(MS_U8 u8DmxId)
945{
946        int i;
947       
948        for (i = 0; i < 100; i++)
949        {
950                cb_sect(u8DmxId, DMX_EVENT_DATA_READY);
951        }
952}
953
954void start_sect(UINT8 tid, UINT16 pid)
955{
956        typedef MS_U8 SEC_BUF[SECTION_BUF_LEN / 64];  // 64 = max filter num
957        SEC_BUF *SectionBuf = (SEC_BUF *)SECTION_BUF_ADDR;
958       
959        DHL_RESULT dhr = DHL_OK;
960        MS_U8 u8FltId = 0;
961        DMX_Flt_info FltInfo;
962        DMX_FILTER_TYPE FilterType = 0;
963        UINT8 data = tid, mask = 0xff, mode = 0;
964       
965        if (MApi_DMX_Open(DMX_FILTER_TYPE_SECTION | DMX_FILTER_SOURCE_TYPE_LIVE,
966                          &u8FltId) != DMX_FILTER_STATUS_OK)
967        {
968                DHL_OS_Printf("|%s| fail to open section filter.\n", __FUNCTION__);
969               
970                dhr = DHL_FAIL;
971               
972                goto err;
973        }
974        memset(&FltInfo, 0, sizeof(FltInfo));
975        FltInfo.Info.SectInfo.SectBufAddr = (MS_PHYADDR)&(SectionBuf[u8FltId]);
976        FltInfo.Info.SectInfo.SectBufSize = sizeof(SectionBuf[u8FltId]);
977        FltInfo.Info.SectInfo.SectMode = DMX_SECT_MODE_CONTI |
978                                         DMX_SECT_MODE_CRCCHK;
979        FltInfo.Info.SectInfo.Event = DMX_EVENT_DATA_READY | DMX_EVENT_CB_SELF |
980                                      DMX_EVENT_BUF_OVERFLOW;
981        FltInfo.Info.SectInfo.pNotify = cb_sect;
982        FilterType = DMX_FILTER_TYPE_SECTION | DMX_FILTER_SOURCE_TYPE_LIVE;
983        if (MApi_DMX_Info(u8FltId, &FltInfo, &FilterType, TRUE) !=
984            DMX_FILTER_STATUS_OK)
985        {
986                DHL_OS_Printf("|%s| fail to set section info.\n", __FUNCTION__);
987               
988                dhr = DHL_FAIL;
989               
990                goto err;
991        }
992        if (MApi_DMX_SectPatternSet(u8FltId, (MS_U8 *)&data,
993                                    (MS_U8 *)&mask, (MS_U8 *)&mode,
994                                    1) != DMX_FILTER_STATUS_OK)
995        {
996                DHL_OS_Printf("|%s| fail to set section pattern.\n", __FUNCTION__);
997               
998                dhr = DHL_FAIL;
999               
1000                goto err;
1001        }
1002        if (MApi_DMX_Pid(u8FltId, (MS_U16 *)&pid, TRUE) != DMX_FILTER_STATUS_OK)
1003        {
1004                DHL_OS_Printf("|%s| fail to set section pid.\n", __FUNCTION__);
1005               
1006                dhr = DHL_FAIL;
1007               
1008                goto err;
1009        }
1010        if (MApi_DMX_SectReset(u8FltId) != DMX_FILTER_STATUS_OK)
1011        {
1012                DHL_OS_Printf("|%s| fail to reset section.\n", __FUNCTION__);
1013               
1014                dhr = DHL_FAIL;
1015               
1016                goto err;
1017        }
1018        if (MApi_DMX_Start(u8FltId) != DMX_FILTER_STATUS_OK)
1019        {
1020                DHL_OS_Printf("|%s| fail to start section pid.\n", __FUNCTION__);
1021               
1022                dhr = DHL_FAIL;
1023               
1024                goto err;
1025        }
1026       
1027        DHL_OS_Printf("filter id = %d\n", u8FltId);
1028        DHL_OS_Printf("buf start = 0x%x\n", FltInfo.Info.SectInfo.SectBufAddr);
1029        DHL_OS_Printf("buf size = 0x%x\n", FltInfo.Info.SectInfo.SectBufSize);
1030       
1031err:
1032        return;
1033}
1034
1035void stop_sect(MS_U8 id)
1036{
1037        if (MApi_DMX_Stop(id) != DMX_FILTER_STATUS_OK)
1038        {
1039                DHL_OS_Printf("|%s| fail to stop section pid.\n", __FUNCTION__);
1040               
1041                /*
1042                dhr = DHL_FAIL;
1043               
1044                goto label_exit;*/
1045        }
1046        if (MApi_DMX_Close(id) != DMX_FILTER_STATUS_OK)
1047        {
1048                DHL_OS_Printf("|%s| fail to close section filter.\n", __FUNCTION__);
1049               
1050                /*
1051                dhr = DHL_FAIL;
1052               
1053                goto label_exit;*/
1054        }
1055}
1056#endif
1057/* end of file */
1058
Note: See TracBrowser for help on using the repository browser.