source: svn/trunk/newcon3bcm2_21bu/dta/src/settop_api/bsettop_smessage.h

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: 12.4 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: bsettop_smessage.h $
11 * $brcm_Revision: $
12 * $brcm_Date: $
13 *
14 * Module Description:
15 * Message filtering and raw ts capture api. Note inconsistent naming of
16 * types and members in the structures. It was done in attempt to preserve
17 * similarity with bsettop_message.h api.
18 * Revision History:
19 *
20 * $brcm_Log: $
21 *
22 *
23 ***************************************************************************/
24
25#ifndef __BSETTOP_SMESSAGE_H__
26#define __BSETTOP_SMESSAGE_H__
27
28#include "bsettop_types.h"
29
30/** \file bsettop_smessage.h
31 This file defines interfaces for PSI section filtering.
32 The DTA PSI filtering works differently than the hardware PSI filtering
33 in settop api and nexus. The DTA PSI filters are combination of the software
34 filtering with the hardware assist. For performance and efficiency reasons
35 the sections are filtered in to the application supplied buffer instead of per
36 filter circular buffer as it happens with the hardware implementation. This
37 allows application to immediately start processing the data and avoid an
38 extra copying operation.
39 The caller allocates a buffer, capable of containing maximum expected
40 section size. If the caller does not know expected section size, buffer size
41 should be 1K for standard sections and 4 K for private sections.
42 The caller then would initialize the section filtering api, fill the parameter
43 structure and start the section filtering.
44 When any of the filters match a section, the section filtering api will copy
45 this section in to the caller supplied buffer and if required would verify the
46 CRC. When the section is completely received and the CRC is verified, the
47 section filtering code will invoke the caller supplied callback. In the
48 callback the caller can process section data and chose to continue filtering
49 or choose to stop filtering sections.
50 */
51
52/**
53   Message stream handle.
54   This handle is returned by the open call and used in all subsequent
55   calls to control the psi interface functionality.
56*/
57typedef struct smessage_stream * smessage_stream_t;
58
59/** \typedef smessage_format
60Message capture format enumeration. Following formats are supported:
61smessage_format_ts, smessage_format_tsc, smessage_format_psi.
62Circular buffer for raw ts capture is allocated internally by the module, in
63case of smessage_format_tsc and smessage_format_psi, a buffer must be allocated
64by the caller and a pointer provided as part of the smessage_stream_params_t
65structure.
66@see smessage_open
67*/
68/** \var smessage_format::smessage_format_ts
69capture raw ts data in to circular buffer.
70*/
71/** \var enum smessage_format_t::smessage_format_tsc
72capture ts data in to provided buffer with callback
73*/
74/** \var enum smessage_format_t::smessage_format_psi
75capture psi sections in to provided buffer with callback
76*/
77typedef enum smessage_format_t {
78    smessage_format_ts,
79    smessage_format_tsc,
80    smessage_format_psi
81} smessage_format;
82
83/** \struct smessage_filter
84Structure that is used to specify a PSI filter.
85
86All filtering is done using bit by bit comparisons.
87There are two types of masks that are used in conjunction with the coefficient.
88inclusion mask (mask) - for all inclusion mask bits that are unmasked
89                (set to 0) ALL of the corresponding bits in the
90                message must match the bits specified by the coef in order to
91                                be included. If one bit differs, it will be excluded.
92
93exclusion mask (excl) - for all exclusion mask bits that are unmasked
94                (set to 0) at least one of the corresponding bits
95                in the message must NOT match the bits specified
96                by the coef in order to be included. If all of the bits
97                                match, it will be excluded.
98Results from both comparisons are AND'd together to form the final pass/fail decision.
99Exception: Currently for MPEG2 streams, byte 2 (i.e. the message length field)
100of the filter and the MPEG2 message data is ignored.
101*/
102/** \var smessage_filter::mask
103 Any bit of the mask that is set to 0 will allow the corresponding bit of the
104 coefficient to be compared against the PSI message data.
105*/
106/** \var smessage_filter::coef
107 Coefficient bits to be compared against the PSI message data.
108*/
109/** \var smessage_filter::excl
110 Any bit of the exclusion that is set to 0 will allow the corresponding bit
111 of the coefficient to be compared against the PSI message data.
112*/
113typedef struct smessage_filter {
114        uint8_t mask[16];
115        uint8_t coef[16];
116        uint8_t excl[16];
117} smessage_filter;
118
119/**
120Section callback type.
121
122The caller must provide a function of this type to be called when the section
123is captured by the section filters. This is the only way for a caller to obtain
124the section.
125After this call is called sections are longer will be captured by this filter
126unless the callback returns non NULL pointer. User must stop and restart
127the filter to resume the section capture.
128
129\warning User can not call any smessage_* api from this callback such call
130will result in a deadlock.
131
132 This callback is called directly from the filter task and it
133must return fast. Delaying return from the callback will adversely impact
134the message filter performance and may result in overflow for all the other
135filters. If caller has to do substantial work he must convey the information
136to another task and do the work in another context. If NULL is returned by
137the callback message filtering will stop for this filter. If non NULL pointer
138is returned filtering will continue in to the buffer pointed by this pointer.
139
140@param context - user context provided when message capture was started.
141@param data_size - size of message captured in the provided buffer.
142@return
143New buffer pointer to use for the next section capture or NULL if no more
144sections should be captured and operation of the filter should be suspended.
145If the filter should continue to capture sections in to the old buffer, the
146callback should return the same pointer that was originally passed to the
147start function. Size of the new buffer must be the same or larger than the
148size of the buffer passed in to the smessage_start function.
149
150@see smessage_stream_params_t
151*/
152typedef void * (*smessage_callback)(void * context, size_t data_size);
153
154/**
155Invalid pid channel definition.
156
157Constant signifying that this pid channel is invalid and the default algorithm
158for choosing the pid channel should be used by the section filter.
159*/
160#define SMESSAGE_INVALID_CHANNEL (0xffff)
161
162/**
163Parameters for the smessage_start function.
164
165Structure for providing parameters to the smessage_start function.
166
167@param band - parser band
168@param pid - pid to filter on
169@param pid_channel - optional pid channel supplied by the caller. This field
170is set to SMESSAGE_INVALID_CHANNEL by smessage_stream_params_init function. If
171the user does not change this field, the message filter will allocate a pid
172channel internally, else it will use the value provided in this field.
173@param filter - message filter
174@param buffer - buffer for complete message
175@param buffer_size - size of the buffer
176@param crc_disabled - disable crc checking, crc checking enabled by default.
177@param data_ready_callback - notification callback invoked when message is captured.
178@param overflow - notification callback invoked when overflow happens.
179
180Only following parameters are used when stream is captured in to circular
181buffer - band, pid, pid_channel, buffer_size. All other parameters are ignored.
182
183@see smessage_stream_params_init, smessage_start
184*/
185typedef struct smessage_stream_params_tag {
186    bband_t band;
187    uint16_t pid;
188    uint16_t pid_channel;
189    smessage_filter filter;
190    void * buffer;
191    size_t buffer_size;
192    bool crc_disabled;
193    smessage_callback data_ready_callback;
194    smessage_callback overflow;
195    void * callback_context;
196    void * priv;
197} smessage_stream_params_t;
198
199/**
200Initialize the message subsystem.
201No other functions can be called before this function is called or results
202of other function calls are undefined.
203
204@param decode_cfgs - decoder configuration.
205@return b_ok if success, error code otherwise.
206*/
207bresult smessage_init(void *decode_cfgs);
208
209/**
210Initialize parameters with default values.
211
212This function will fill the given structure with the default values that are
213appropriate for the message stream type. This function must be called before
214setting up the parameter structure for the smessage_open call.
215
216@param params - parameter structure to fill with the default values.
217@param stream - stream for which to fill the structure.
218
219@see smessage_open
220*/
221void smessage_stream_params_init( smessage_stream_params_t *params, smessage_stream_t stream);
222
223/**
224Open message with the desired format.
225
226This call returns the message handle which is obtained from the internal list.
227Be sure to call smessage_close after the handle is no longer needed. Failing
228to do so will result in memory leak and running out of handles.
229
230@param format - desired format for the message capture.
231@return smessage_stream_t handle or NULL if the call fails.
232
233@see smessage_close
234*/
235smessage_stream_t smessage_open(smessage_format format);
236
237/**
238Start message capture.
239
240This call will start message filtering. When message is captured it will be
241copied in to the provided buffer and callback will be called. After message is
242captured this filter will be disabled if NULL is returned by callback. If
243caller desires to continue message filtering, callback should return a pointer
244to the buffer in which to capture next message.
245If message callback returns NULL and user wants to resume filtering, message
246filter should be stopped and restarted with new parameters by calling this
247api again.
248This call will start capture and immediately return.
249
250@param params - parameters for message capture
251@param stream - stream handle for which to start capture.
252
253@return b_ok if capture was started, error code otherwise.
254
255@see smessage_stop, smessage_stream_params_init
256*/
257bresult smessage_start(const smessage_stream_params_t * params, smessage_stream_t stream);
258
259/**
260Stop message capture.
261Stop capture and if possible free internal hardware and software
262resources.
263
264@param stream - stream for which to stop message capture.
265
266@return b_ok if capture was stopped, error code otherwise.
267
268@see smessage_stop
269*/
270bresult smessage_stop(smessage_stream_t stream);
271
272/**
273Close message capture for given stream.
274
275Close message capture for given stream and return stream to the list of free
276streams. User must call smessage_stop before calling this api and user must
277call this api if he no longer needs stream handle. If this api is not called
278stream handle will be leaked and eventually system will run out of stream
279handles as they are limited.
280
281@param stream - stream handle to free.
282
283@see smessage_open
284*/
285void smessage_close(smessage_stream_t stream);
286
287/**
288Get circular buffer pointer for the stream capture buffer.
289Get the pointer to the start of unread data in the circular buffer. This call
290is valid only for some types of message capture and using it for any other
291type will result in error.
292
293@param stream - desired stream handle
294@param pbuffer - pointer to the pointer to buffer. After the function returns
295this variable will contain the pointer to the start of the available data.
296@param plength - pointer to the length of the data. After function returns this
297variable will contain length of the valid data in the buffer.
298
299@return b_ok if call was successful error otherwise. If error is returned
300values of *pbuffer and *plength are not defined and should be discarded.
301
302@see smessage_read_complete, smessage_start
303*/
304bresult smessage_get_buffer(smessage_stream_t stream, const void ** pbuffer, size_t * plength);
305
306/**
307Notify circular buffer about amount of consumed data.
308
309Notify the circular buffer about amount of the consumed data and advance the
310read pointer. This call is valid only for some types of the message capture
311and using it for any other type will result in error. Attempt to consume more
312data that is available in the circular buffer will result in error.
313
314@param stream - desired stream handle
315@param consumed - amount of data that was consumed. Read pointer will be advanced by
316that amount.
317
318@return b_ok if call was successful error otherwise.
319
320@see smessage_get_buffer, smessage_start
321*/
322bresult smessage_read_complete(smessage_stream_t stream, size_t consumed);
323
324
325#endif /*__BSETTOP_SMESSAGE_H__*/
Note: See TracBrowser for help on using the repository browser.