| 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 | */ |
|---|
| 57 | typedef struct smessage_stream * smessage_stream_t; |
|---|
| 58 | |
|---|
| 59 | /** \typedef smessage_format |
|---|
| 60 | Message capture format enumeration. Following formats are supported: |
|---|
| 61 | smessage_format_ts, smessage_format_tsc, smessage_format_psi. |
|---|
| 62 | Circular buffer for raw ts capture is allocated internally by the module, in |
|---|
| 63 | case of smessage_format_tsc and smessage_format_psi, a buffer must be allocated |
|---|
| 64 | by the caller and a pointer provided as part of the smessage_stream_params_t |
|---|
| 65 | structure. |
|---|
| 66 | @see smessage_open |
|---|
| 67 | */ |
|---|
| 68 | /** \var smessage_format::smessage_format_ts |
|---|
| 69 | capture raw ts data in to circular buffer. |
|---|
| 70 | */ |
|---|
| 71 | /** \var enum smessage_format_t::smessage_format_tsc |
|---|
| 72 | capture ts data in to provided buffer with callback |
|---|
| 73 | */ |
|---|
| 74 | /** \var enum smessage_format_t::smessage_format_psi |
|---|
| 75 | capture psi sections in to provided buffer with callback |
|---|
| 76 | */ |
|---|
| 77 | typedef enum smessage_format_t { |
|---|
| 78 | smessage_format_ts, |
|---|
| 79 | smessage_format_tsc, |
|---|
| 80 | smessage_format_psi |
|---|
| 81 | } smessage_format; |
|---|
| 82 | |
|---|
| 83 | /** \struct smessage_filter |
|---|
| 84 | Structure that is used to specify a PSI filter. |
|---|
| 85 | |
|---|
| 86 | All filtering is done using bit by bit comparisons. |
|---|
| 87 | There are two types of masks that are used in conjunction with the coefficient. |
|---|
| 88 | inclusion 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 | |
|---|
| 93 | exclusion 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. |
|---|
| 98 | Results from both comparisons are AND'd together to form the final pass/fail decision. |
|---|
| 99 | Exception: Currently for MPEG2 streams, byte 2 (i.e. the message length field) |
|---|
| 100 | of 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 | */ |
|---|
| 113 | typedef struct smessage_filter { |
|---|
| 114 | uint8_t mask[16]; |
|---|
| 115 | uint8_t coef[16]; |
|---|
| 116 | uint8_t excl[16]; |
|---|
| 117 | } smessage_filter; |
|---|
| 118 | |
|---|
| 119 | /** |
|---|
| 120 | Section callback type. |
|---|
| 121 | |
|---|
| 122 | The caller must provide a function of this type to be called when the section |
|---|
| 123 | is captured by the section filters. This is the only way for a caller to obtain |
|---|
| 124 | the section. |
|---|
| 125 | After this call is called sections are longer will be captured by this filter |
|---|
| 126 | unless the callback returns non NULL pointer. User must stop and restart |
|---|
| 127 | the filter to resume the section capture. |
|---|
| 128 | |
|---|
| 129 | \warning User can not call any smessage_* api from this callback such call |
|---|
| 130 | will result in a deadlock. |
|---|
| 131 | |
|---|
| 132 | This callback is called directly from the filter task and it |
|---|
| 133 | must return fast. Delaying return from the callback will adversely impact |
|---|
| 134 | the message filter performance and may result in overflow for all the other |
|---|
| 135 | filters. If caller has to do substantial work he must convey the information |
|---|
| 136 | to another task and do the work in another context. If NULL is returned by |
|---|
| 137 | the callback message filtering will stop for this filter. If non NULL pointer |
|---|
| 138 | is 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 |
|---|
| 143 | New buffer pointer to use for the next section capture or NULL if no more |
|---|
| 144 | sections should be captured and operation of the filter should be suspended. |
|---|
| 145 | If the filter should continue to capture sections in to the old buffer, the |
|---|
| 146 | callback should return the same pointer that was originally passed to the |
|---|
| 147 | start function. Size of the new buffer must be the same or larger than the |
|---|
| 148 | size of the buffer passed in to the smessage_start function. |
|---|
| 149 | |
|---|
| 150 | @see smessage_stream_params_t |
|---|
| 151 | */ |
|---|
| 152 | typedef void * (*smessage_callback)(void * context, size_t data_size); |
|---|
| 153 | |
|---|
| 154 | /** |
|---|
| 155 | Invalid pid channel definition. |
|---|
| 156 | |
|---|
| 157 | Constant signifying that this pid channel is invalid and the default algorithm |
|---|
| 158 | for choosing the pid channel should be used by the section filter. |
|---|
| 159 | */ |
|---|
| 160 | #define SMESSAGE_INVALID_CHANNEL (0xffff) |
|---|
| 161 | |
|---|
| 162 | /** |
|---|
| 163 | Parameters for the smessage_start function. |
|---|
| 164 | |
|---|
| 165 | Structure 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 |
|---|
| 170 | is set to SMESSAGE_INVALID_CHANNEL by smessage_stream_params_init function. If |
|---|
| 171 | the user does not change this field, the message filter will allocate a pid |
|---|
| 172 | channel 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 | |
|---|
| 180 | Only following parameters are used when stream is captured in to circular |
|---|
| 181 | buffer - band, pid, pid_channel, buffer_size. All other parameters are ignored. |
|---|
| 182 | |
|---|
| 183 | @see smessage_stream_params_init, smessage_start |
|---|
| 184 | */ |
|---|
| 185 | typedef 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 | /** |
|---|
| 200 | Initialize the message subsystem. |
|---|
| 201 | No other functions can be called before this function is called or results |
|---|
| 202 | of other function calls are undefined. |
|---|
| 203 | |
|---|
| 204 | @param decode_cfgs - decoder configuration. |
|---|
| 205 | @return b_ok if success, error code otherwise. |
|---|
| 206 | */ |
|---|
| 207 | bresult smessage_init(void *decode_cfgs); |
|---|
| 208 | |
|---|
| 209 | /** |
|---|
| 210 | Initialize parameters with default values. |
|---|
| 211 | |
|---|
| 212 | This function will fill the given structure with the default values that are |
|---|
| 213 | appropriate for the message stream type. This function must be called before |
|---|
| 214 | setting 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 | */ |
|---|
| 221 | void smessage_stream_params_init( smessage_stream_params_t *params, smessage_stream_t stream); |
|---|
| 222 | |
|---|
| 223 | /** |
|---|
| 224 | Open message with the desired format. |
|---|
| 225 | |
|---|
| 226 | This call returns the message handle which is obtained from the internal list. |
|---|
| 227 | Be sure to call smessage_close after the handle is no longer needed. Failing |
|---|
| 228 | to 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 | */ |
|---|
| 235 | smessage_stream_t smessage_open(smessage_format format); |
|---|
| 236 | |
|---|
| 237 | /** |
|---|
| 238 | Start message capture. |
|---|
| 239 | |
|---|
| 240 | This call will start message filtering. When message is captured it will be |
|---|
| 241 | copied in to the provided buffer and callback will be called. After message is |
|---|
| 242 | captured this filter will be disabled if NULL is returned by callback. If |
|---|
| 243 | caller desires to continue message filtering, callback should return a pointer |
|---|
| 244 | to the buffer in which to capture next message. |
|---|
| 245 | If message callback returns NULL and user wants to resume filtering, message |
|---|
| 246 | filter should be stopped and restarted with new parameters by calling this |
|---|
| 247 | api again. |
|---|
| 248 | This 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 | */ |
|---|
| 257 | bresult smessage_start(const smessage_stream_params_t * params, smessage_stream_t stream); |
|---|
| 258 | |
|---|
| 259 | /** |
|---|
| 260 | Stop message capture. |
|---|
| 261 | Stop capture and if possible free internal hardware and software |
|---|
| 262 | resources. |
|---|
| 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 | */ |
|---|
| 270 | bresult smessage_stop(smessage_stream_t stream); |
|---|
| 271 | |
|---|
| 272 | /** |
|---|
| 273 | Close message capture for given stream. |
|---|
| 274 | |
|---|
| 275 | Close message capture for given stream and return stream to the list of free |
|---|
| 276 | streams. User must call smessage_stop before calling this api and user must |
|---|
| 277 | call this api if he no longer needs stream handle. If this api is not called |
|---|
| 278 | stream handle will be leaked and eventually system will run out of stream |
|---|
| 279 | handles as they are limited. |
|---|
| 280 | |
|---|
| 281 | @param stream - stream handle to free. |
|---|
| 282 | |
|---|
| 283 | @see smessage_open |
|---|
| 284 | */ |
|---|
| 285 | void smessage_close(smessage_stream_t stream); |
|---|
| 286 | |
|---|
| 287 | /** |
|---|
| 288 | Get circular buffer pointer for the stream capture buffer. |
|---|
| 289 | Get the pointer to the start of unread data in the circular buffer. This call |
|---|
| 290 | is valid only for some types of message capture and using it for any other |
|---|
| 291 | type will result in error. |
|---|
| 292 | |
|---|
| 293 | @param stream - desired stream handle |
|---|
| 294 | @param pbuffer - pointer to the pointer to buffer. After the function returns |
|---|
| 295 | this 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 |
|---|
| 297 | variable 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 |
|---|
| 300 | values of *pbuffer and *plength are not defined and should be discarded. |
|---|
| 301 | |
|---|
| 302 | @see smessage_read_complete, smessage_start |
|---|
| 303 | */ |
|---|
| 304 | bresult smessage_get_buffer(smessage_stream_t stream, const void ** pbuffer, size_t * plength); |
|---|
| 305 | |
|---|
| 306 | /** |
|---|
| 307 | Notify circular buffer about amount of consumed data. |
|---|
| 308 | |
|---|
| 309 | Notify the circular buffer about amount of the consumed data and advance the |
|---|
| 310 | read pointer. This call is valid only for some types of the message capture |
|---|
| 311 | and using it for any other type will result in error. Attempt to consume more |
|---|
| 312 | data 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 |
|---|
| 316 | that amount. |
|---|
| 317 | |
|---|
| 318 | @return b_ok if call was successful error otherwise. |
|---|
| 319 | |
|---|
| 320 | @see smessage_get_buffer, smessage_start |
|---|
| 321 | */ |
|---|
| 322 | bresult smessage_read_complete(smessage_stream_t stream, size_t consumed); |
|---|
| 323 | |
|---|
| 324 | |
|---|
| 325 | #endif /*__BSETTOP_SMESSAGE_H__*/ |
|---|