source: svn/newcon3bcm2_21bu/BSEAV/api/src/nexus/bsettop_message.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: 8.0 KB
Line 
1/***************************************************************************
2 *  Copyright (c) 2003-2009, 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: bsettop_message.c $
11 * $brcm_Revision: 9 $
12 * $brcm_Date: 10/15/09 1:54p $
13 *
14 * Module Description:
15 *
16 * Revision History:
17 *
18 * $brcm_Log: /BSEAV/api/src/nexus/bsettop_message.c $
19 *
20 * 9   10/15/09 1:54p erickson
21 * SWDEPRECATED-3717: have settop api shim default filter_group setting
22 * match nexus default filterGroup setting
23 *
24 * 8   8/18/09 6:38p katrep
25 * PR56109: Use calllbacks instead of using events for callbacks to the
26 * app.
27 *
28 * 7   4/7/08 10:40a jgarrett
29 * PR 41362: Revising pid channel management
30 *
31 * 6   4/3/08 5:41p jgarrett
32 * PR 41312: Setting callback events
33 *
34 * 5   12/4/07 3:09p erickson
35 * PR36068: call NEXUS_PidChannel_Close
36 *
37 * 4   11/2/07 1:25p erickson
38 * PR36633: update nexus enums
39 *
40 * 3   10/16/07 2:28p erickson
41 * PR36068: pass through getbuffer/readcomplete rc's. stop when closing to
42 * get bstream_close called.
43 *
44 * 2   10/16/07 12:35p erickson
45 * PR36068: brutus up over settop api/nexus
46 *
47 * 1   10/15/07 2:36p erickson
48 * PR36068: initial
49 *
50 ***************************************************************************/
51#include "bsettop_impl.h"
52
53BDBG_MODULE(message);
54
55BDBG_OBJECT_ID(bmessage);
56
57static void bmessage_p_dataready_handler(void *context,int param);
58
59bmessage_stream_t bmessage_open(bmessage_format format)
60{
61    bmessage_stream_t msg;
62
63    msg = BKNI_Malloc(sizeof(*msg));
64    BKNI_Memset(msg, 0, sizeof(*msg));
65    BDBG_OBJECT_SET(msg, bmessage);
66    msg->format = format;
67#if 0
68    msg->dataEvent = B_Event_Create(NULL);
69    if ( NULL == msg->dataEvent )
70    {
71        BKNI_Free(msg);
72        BSETTOP_ERROR(berr_external_error);
73        return NULL;
74    }
75    msg->dataEventId = b_event_register(msg->dataEvent, bmessage_p_dataready_handler, msg);
76    if ( NULL == msg->dataEventId )
77    {
78        B_Event_Destroy(msg->dataEvent);
79        BKNI_Free(msg);
80        BSETTOP_ERROR(berr_external_error);
81        return NULL;
82    }
83#endif
84    msg->dataCallback=b_callback_create(msg,bmessage_p_dataready_handler,msg,0);
85    if(msg->dataCallback==NULL)
86    {
87        BSETTOP_ERROR(berr_external_error);
88        return NULL;
89    }
90
91    return msg;
92}
93
94void bmessage_close(bmessage_stream_t msg)
95{
96    BDBG_OBJECT_ASSERT(msg, bmessage);
97    if (msg->stream) {
98        bmessage_stop(msg);
99    }
100    if (msg->nMessage) {
101        NEXUS_Message_Close(msg->nMessage);
102    }
103#if 0
104    b_event_unregister(msg->dataEventId);
105    B_Event_Destroy(msg->dataEvent);
106#endif
107    if(msg->dataCallback)
108    {
109        b_callback_destroy(msg->dataCallback);
110    }
111    BDBG_OBJECT_DESTROY(msg, bmessage);
112    BKNI_Free(msg);
113}
114
115void bmessage_stream_params_init(bmessage_stream_params *params, bmessage_stream_t msg)
116{
117    NEXUS_MessageStartSettings startSettings;
118
119    BSTD_UNUSED(msg);
120    BKNI_Memset(params, 0, sizeof(*params));
121    params->buffer_size = 4; /* 4K */
122    BKNI_Memset(params->filter.mask, 0xFF, sizeof(params->filter.mask));
123    BKNI_Memset(params->filter.excl, 0xFF, sizeof(params->filter.excl));
124
125    /* shim default should match the nexus default */
126    NEXUS_Message_GetDefaultStartSettings(NULL /*unused*/, &startSettings);
127    params->filter_group = startSettings.filterGroup;
128}
129
130/* Skip byte two (since the hardware doesn't look at that byte) */
131#define COPY_FILTER_BYTES( a, b ) \
132    do { \
133    a[0] = b[0]; \
134    a[1] = b[1]; \
135    BKNI_Memmove( &a[2], &b[3], 13 ); \
136    a[15] = 0xFF; \
137    } while(0)
138
139void bmessage_p_dataready(void *context, int param)
140{
141    bmessage_stream_t msg = (bmessage_stream_t)context;
142    BDBG_OBJECT_ASSERT(msg, bmessage);
143    BSTD_UNUSED(param);
144    /*B_Event_Set(msg->dataEvent);*/
145    b_callback_fire(msg->dataCallback);
146}
147
148static void bmessage_p_dataready_handler(void *context,int param)
149{
150    bmessage_stream_t msg = (bmessage_stream_t)context;
151    BSTD_UNUSED(param);
152    BDBG_OBJECT_ASSERT(msg, bmessage);
153    if (msg->params.data_ready_callback) {
154        /*b_unlock();*/
155        (*msg->params.data_ready_callback)(msg->params.callback_context);
156        /*b_lock();*/
157    }
158}
159
160void bmessage_p_overflow(void *context, int param)
161{
162    bmessage_stream_t msg = (bmessage_stream_t)context;
163    BSTD_UNUSED(param);
164    if (msg->params.overflow) {
165        (*msg->params.overflow)(msg->params.callback_context);
166    }
167}
168
169bresult bmessage_start(bmessage_stream_t msg, const bmessage_stream_params *params)
170{
171    NEXUS_MessageSettings settings;
172    NEXUS_MessageStartSettings startSettings;
173    NEXUS_Error rc;
174
175    BDBG_OBJECT_ASSERT(msg, bmessage);
176    BDBG_ASSERT(NULL != params);
177
178    if ( msg->stream )
179    {
180        bmessage_stop(msg);
181    }
182
183    if (msg->nMessage) {
184        NEXUS_Message_Close(msg->nMessage);
185    }
186
187    msg->params = *params;
188
189    NEXUS_Message_GetDefaultSettings(&settings);
190    settings.bufferSize = params->buffer_size * 1024;
191    if (params->data_ready_callback) {
192        settings.dataReady.callback = bmessage_p_dataready;
193        settings.dataReady.context = msg;
194    }
195    if (params->overflow) {
196        settings.overflow.callback = bmessage_p_overflow;
197        settings.overflow.context = msg;
198    }
199    msg->nMessage = NEXUS_Message_Open(&settings);
200    if (!msg->nMessage) {
201        return BSETTOP_ERROR(berr_external_error);
202    }
203
204    NEXUS_Message_GetDefaultStartSettings(msg->nMessage, &startSettings);
205    if (params->band) {
206        bstream_mpeg mpeg;
207        /* don't need pid channels, but must alloc parser band */
208        bstream_mpeg_init(&mpeg);
209        msg->stream = bstream_p_open_message(params->band, &mpeg);
210        if (!msg->stream) {
211            return BSETTOP_ERROR(berr_external_error);
212        }
213    }
214    else {
215        msg->stream = params->stream;
216        if (!msg->stream) {
217            return BSETTOP_ERROR(berr_external_error);
218        }
219    }
220    msg->nPidChannel = startSettings.pidChannel = bstream_p_open_pid(msg->stream, params->pid, bstream_pid_type_other);
221    if ( NULL == msg->nPidChannel )
222    {
223        BDBG_ERR(("Unable to open PID channel for message filtering"));
224        bmessage_stop(msg);
225        return BSETTOP_ERROR(berr_external_error);
226    }
227
228    startSettings.format = b_messageformat2nexus(msg->format);
229    startSettings.bufferMode = NEXUS_MessageBufferMode_eContinuous;
230    COPY_FILTER_BYTES(startSettings.filter.coefficient, params->filter.coef);
231    COPY_FILTER_BYTES(startSettings.filter.mask, params->filter.mask);
232    COPY_FILTER_BYTES(startSettings.filter.exclusion, params->filter.excl);
233    startSettings.filterGroup = params->filter_group;
234    startSettings.psiCrcDisabled = params->psi_crc_disabled;
235    startSettings.psfCrcDisabled = params->psf_crc_disabled;
236
237    rc = NEXUS_Message_Start(msg->nMessage, &startSettings);
238    if (rc)
239    {
240        BDBG_ERR(("Unable to start message filtering"));
241        bmessage_stop(msg);
242        return BSETTOP_ERROR(berr_external_error);
243    }
244    return 0;
245}
246
247bresult bmessage_get_buffer(bmessage_stream_t msg, const void ** p_bfr, size_t *length)
248{
249    BDBG_OBJECT_ASSERT(msg, bmessage);
250    return NEXUS_Message_GetBuffer(msg->nMessage, p_bfr, length);
251}
252
253bresult bmessage_read_complete(bmessage_stream_t msg, size_t amount_consumed)
254{
255    BDBG_OBJECT_ASSERT(msg, bmessage);
256    return NEXUS_Message_ReadComplete(msg->nMessage, amount_consumed);
257}
258
259void bmessage_stop(bmessage_stream_t msg)
260{
261    BDBG_OBJECT_ASSERT(msg, bmessage);
262    NEXUS_Message_Stop(msg->nMessage);
263    if ( msg->stream )
264    {
265        if (msg->nPidChannel)
266        {
267            bstream_p_close_pid(msg->stream, msg->nPidChannel);
268            msg->nPidChannel = NULL;
269        }
270        if ( msg->params.band )
271        {
272            bstream_close(msg->stream);
273        }
274        BLST_Q_REMOVE(&msg->stream->consumers.messageList, msg, streamNode);
275        msg->stream = NULL;
276    }
277}
278
Note: See TracBrowser for help on using the repository browser.