| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2002, 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: bpvrlib_dynrec.h $ |
|---|
| 11 | * $brcm_Revision: Hydra_Software_Devel/5 $ |
|---|
| 12 | * $brcm_Date: 3/12/04 3:26p $ |
|---|
| 13 | * |
|---|
| 14 | * Revision History: |
|---|
| 15 | * |
|---|
| 16 | * $brcm_Log: /magnum/syslib/pvrlib/bpvrlib_dynrec.h $ |
|---|
| 17 | * |
|---|
| 18 | * Hydra_Software_Devel/5 3/12/04 3:26p vsilyaev |
|---|
| 19 | * PR 8927: Added API to return events to the application. |
|---|
| 20 | * |
|---|
| 21 | * Hydra_Software_Devel/4 1/21/04 4:43p marcusk |
|---|
| 22 | * PR8927: Fixed to work with latest version of XPT porting interface. |
|---|
| 23 | * Validate channel number. |
|---|
| 24 | * |
|---|
| 25 | * Hydra_Software_Devel/3 1/15/04 4:40p marcusk |
|---|
| 26 | * PR8927: Initial working version of the dynamic buffer record syslib. |
|---|
| 27 | * |
|---|
| 28 | * Hydra_Software_Devel/2 1/15/04 12:40p marcusk |
|---|
| 29 | * PR8927: Fixed comment and paramter to Open() routine. |
|---|
| 30 | * |
|---|
| 31 | * Hydra_Software_Devel/1 1/15/04 11:23a marcusk |
|---|
| 32 | * PR8927: Initial version. |
|---|
| 33 | * |
|---|
| 34 | ***************************************************************************/ |
|---|
| 35 | |
|---|
| 36 | /*================== Module Overview ===================================== |
|---|
| 37 | |
|---|
| 38 | This module implements the record functionality for pvr using a list |
|---|
| 39 | of complete, free, and hardware buffers. Free buffers can be shared between |
|---|
| 40 | all record channels in order to handle peaks in bandwidth (since it is |
|---|
| 41 | less likely that all record channels will peak at the same time). This |
|---|
| 42 | allows more efficient memory utilization than having static buffers for |
|---|
| 43 | each channel. |
|---|
| 44 | |
|---|
| 45 | It is only possible to include either the standard ring buffer based record |
|---|
| 46 | or this dynamic implementation (which is why they share the same API). |
|---|
| 47 | |
|---|
| 48 | The following general overview describes the record algorithm: |
|---|
| 49 | |
|---|
| 50 | 0.0 Master Handle Creation |
|---|
| 51 | - A master record handle is created (it is then used for subsequent record |
|---|
| 52 | channel open calls) |
|---|
| 53 | - Size of entire record buffer is passed as parameter (same for all record channels) |
|---|
| 54 | |
|---|
| 55 | 1.0 Open |
|---|
| 56 | - Resources (events, lists, etc) are created. |
|---|
| 57 | |
|---|
| 58 | 1.1 Configure Record |
|---|
| 59 | - These should be performed outside the record syslib |
|---|
| 60 | - Data transport PIDs are enabled and configured |
|---|
| 61 | - Record parameters are configured (including decryption/encryption, etc) |
|---|
| 62 | - Record pid channel bitmap is enabled |
|---|
| 63 | - SCT record parameters should be set |
|---|
| 64 | |
|---|
| 65 | 1.2 Start Record (SCT record channel should be started first if required) |
|---|
| 66 | - Free buffers are added to record hardware and hardware list |
|---|
| 67 | - Record hardware is started |
|---|
| 68 | |
|---|
| 69 | 1.3 Get Data (not re-entrant for same record channel) |
|---|
| 70 | - Record buffer address and size is obtained from buffer complete list |
|---|
| 71 | (this step may block if there is no data available) |
|---|
| 72 | (blocking is disabled if the record channel is stopped) |
|---|
| 73 | - Data is copied to specified buffer |
|---|
| 74 | - Buffer complete list is updated (descriptor is added to free list) |
|---|
| 75 | - The amount of data copied from record channel is returned |
|---|
| 76 | - Overflow status is returned |
|---|
| 77 | |
|---|
| 78 | (Alternate to 1.3) |
|---|
| 79 | 1.3.1 Request to Get Data (steps 1.3.x not re-entrant for same record channel) |
|---|
| 80 | - Record buffer address and size is obtained from buffer complete list |
|---|
| 81 | (this step may block if there is no space available) |
|---|
| 82 | (blocking is disabled if the record channel is stopped) |
|---|
| 83 | - Overflow status is returned |
|---|
| 84 | |
|---|
| 85 | 1.3.2 Data is copied from specified buffer by calling code |
|---|
| 86 | |
|---|
| 87 | 1.3.3 Complete list is updated |
|---|
| 88 | - Buffer complete list is updated (descriptor is added to free list) |
|---|
| 89 | |
|---|
| 90 | 1.4 Descriptor complete ISR() |
|---|
| 91 | - First descriptor is removed from hardware list and checked for completion |
|---|
| 92 | - If complete, descriptor is added to complete list |
|---|
| 93 | - Check if next descriptor has also completed (repeat process if necessary) |
|---|
| 94 | - Set event to notify of data arrival |
|---|
| 95 | |
|---|
| 96 | 1.5 Stop Record |
|---|
| 97 | - Record hardware is stopped |
|---|
| 98 | - Wait for record done interrupt to occur if we are stopping a transport record channel |
|---|
| 99 | - Partially complete descriptor is moved to complete list (with special flag |
|---|
| 100 | specifying how much of the buffer is occupied) |
|---|
| 101 | - All left over descriptors are moved from hw to the free list |
|---|
| 102 | - Any blocking calls are released (future calls are not allowed to block) |
|---|
| 103 | - Additional get data function call should be called to get remaining |
|---|
| 104 | data from record. |
|---|
| 105 | |
|---|
| 106 | 1.6 Free |
|---|
| 107 | - Free descriptor buffer |
|---|
| 108 | - Free record buffer manager |
|---|
| 109 | |
|---|
| 110 | ========================================================================*/ |
|---|
| 111 | #ifndef __BPVRLIB_DYNREC_H__ |
|---|
| 112 | #define __BPVRLIB_DYNREC_H__ |
|---|
| 113 | |
|---|
| 114 | #include "bxpt_record.h" |
|---|
| 115 | |
|---|
| 116 | #ifdef __cplusplus |
|---|
| 117 | extern "C" { |
|---|
| 118 | #endif |
|---|
| 119 | |
|---|
| 120 | /* |
|---|
| 121 | Summary: |
|---|
| 122 | This callback is compatible with the standard 'c' memcpy routine. |
|---|
| 123 | It is used to copy data between a user buffer and the ring |
|---|
| 124 | buffer during a pvr_recordGetData() function call. |
|---|
| 125 | */ |
|---|
| 126 | typedef void *(*BPVRlib_Rec_CopyMemoryCb)( void *, const void *, size_t ); |
|---|
| 127 | |
|---|
| 128 | /* |
|---|
| 129 | Summary: |
|---|
| 130 | This handle is used to store the context of a pvr record instance. |
|---|
| 131 | */ |
|---|
| 132 | typedef struct BPVRlib_Rec_P_Handle *BPVRlib_Rec_Handle; |
|---|
| 133 | |
|---|
| 134 | /* |
|---|
| 135 | Summary: |
|---|
| 136 | This handle is used to store the context of a pvr record channel. |
|---|
| 137 | */ |
|---|
| 138 | typedef struct BPVRlib_Rec_P_MasterHandle *BPVRlib_Rec_MasterHandle; |
|---|
| 139 | |
|---|
| 140 | /* |
|---|
| 141 | Summary: |
|---|
| 142 | This structure is used to store various statistics that can |
|---|
| 143 | be used to monitor and debug a record that is in progress. |
|---|
| 144 | Note: All stats are reset when the record is started or flushed! |
|---|
| 145 | */ |
|---|
| 146 | typedef struct |
|---|
| 147 | { |
|---|
| 148 | size_t numBytesRecorded; /* Number of bytes recorded by hardware */ |
|---|
| 149 | size_t numBytesRemoved; /* Number of bytes removed from the record buffer by software */ |
|---|
| 150 | size_t numFreeDesc; /* Current number of free descriptors (for all record channels) */ |
|---|
| 151 | uint32_t numInHwDesc; /* Current number of descriptors being processed by hardware */ |
|---|
| 152 | uint32_t numCompDesc; /* Current number of complete descriptors */ |
|---|
| 153 | uint32_t numDesc; /* Total number of descriptors (for all record channels) */ |
|---|
| 154 | uint32_t numDescAdded; /* Number of descriptors added in to hardware */ |
|---|
| 155 | uint32_t numDescCompleted; /* Number of descriptors completed by hardware */ |
|---|
| 156 | uint32_t numOverFlows; /* Number of times the hardware has reached the end of its descriptor list */ |
|---|
| 157 | uint32_t numBufferBlocks; /* Number of times blocking has occurred due to buffer resources */ |
|---|
| 158 | uint32_t numTimeouts; /* Number of times blocking has failed due to a timeout */ |
|---|
| 159 | size_t maxBfrDepth; /* Maximum number of bytes stored in buffer */ |
|---|
| 160 | size_t bfrDepth; /* Current number of valid bytes stored in the buffer */ |
|---|
| 161 | size_t descSize; /* Size of each descriptor */ |
|---|
| 162 | } BPVRlib_Rec_Stats; |
|---|
| 163 | |
|---|
| 164 | /* |
|---|
| 165 | The BPVRlib_Rec_Events structure is used to return various events used by the record module. |
|---|
| 166 | Those events could be latter useful when application useed nonblocking flavor of record |
|---|
| 167 | */ |
|---|
| 168 | typedef struct BPVRlib_Rec_Events |
|---|
| 169 | { |
|---|
| 170 | BKNI_EventHandle descEvent; /* Event used to signal when descriptor is added to free list */ |
|---|
| 171 | BKNI_EventHandle finishedEvent; /* Event used to signal when the record has finished */ |
|---|
| 172 | } BPVRlib_Rec_Events; |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | /**************************************************************** |
|---|
| 176 | Summary: |
|---|
| 177 | This function allocates the resources required for a record. |
|---|
| 178 | |
|---|
| 179 | See also: |
|---|
| 180 | BPVRlib_Rec_Close(), BPVRlib_Rec_Start(), BPVRlib_Rec_GetData() |
|---|
| 181 | ****************************************************************/ |
|---|
| 182 | BERR_Code BPVRlib_Rec_Open( |
|---|
| 183 | BPVRlib_Rec_MasterHandle *pRecMasterHandle, /* [out] context handle */ |
|---|
| 184 | BXPT_Handle xptHandle, /* XPT handle */ |
|---|
| 185 | BMEM_Handle memHandle, /* Mem handle */ |
|---|
| 186 | BINT_Handle intHandle, /* Int handle */ |
|---|
| 187 | BXPT_ChanType chanType, /* Record channel type */ |
|---|
| 188 | uint8_t *p_bfr, /* pointer to buffer that should be used for record buffer, 0 to allocate the buffer internally */ |
|---|
| 189 | size_t bfrSize, /* size of record record buffer (in bytes). Should be multiple of descSize */ |
|---|
| 190 | uint32_t numDesc, /* number of descriptors to use (minimum of 3 per record channel that will be used) */ |
|---|
| 191 | BPVRlib_Rec_CopyMemoryCb copyMemCb /* function pointer for memory copies (optional) */ |
|---|
| 192 | ); |
|---|
| 193 | |
|---|
| 194 | /**************************************************************** |
|---|
| 195 | Summary: |
|---|
| 196 | This function frees any resources used by a record |
|---|
| 197 | channel. |
|---|
| 198 | ****************************************************************/ |
|---|
| 199 | BERR_Code BPVRlib_Rec_Close( |
|---|
| 200 | BPVRlib_Rec_MasterHandle recMasterHandle /* context handle */ |
|---|
| 201 | ); |
|---|
| 202 | |
|---|
| 203 | /**************************************************************** |
|---|
| 204 | Summary: |
|---|
| 205 | This function allocates the resources required for a record channel. |
|---|
| 206 | |
|---|
| 207 | Description: |
|---|
| 208 | This includes a buffer, descriptor list, etc. |
|---|
| 209 | The pvrMemCopyCb parameter only needs to be valid |
|---|
| 210 | if the BPVRlib_Rec_GetData() function is going to be |
|---|
| 211 | used. |
|---|
| 212 | |
|---|
| 213 | The buffer used by this specific record channel may be shared by |
|---|
| 214 | other record channels. |
|---|
| 215 | |
|---|
| 216 | See also: |
|---|
| 217 | BPVRlib_Rec_Close(), BPVRlib_Rec_Start(), BPVRlib_Rec_GetData() |
|---|
| 218 | ****************************************************************/ |
|---|
| 219 | BERR_Code BPVRlib_Rec_ChannelOpen( |
|---|
| 220 | BPVRlib_Rec_Handle *pRecChanHandle, /* [out] context handle */ |
|---|
| 221 | BPVRlib_Rec_MasterHandle recMasterHandle, /* master handle context */ |
|---|
| 222 | BXPT_Record_Handle xptRecHandle, /* XPT record handle */ |
|---|
| 223 | unsigned chanNum, /* record channel number */ |
|---|
| 224 | uint32_t minDesc /* minimum number of descriptors that should be always allocated for this record channel (0 is auto) */ |
|---|
| 225 | ); |
|---|
| 226 | |
|---|
| 227 | |
|---|
| 228 | /**************************************************************** |
|---|
| 229 | Summary: |
|---|
| 230 | This function frees any resources used by a record |
|---|
| 231 | channel. |
|---|
| 232 | ****************************************************************/ |
|---|
| 233 | BERR_Code BPVRlib_Rec_ChannelClose( |
|---|
| 234 | BPVRlib_Rec_Handle recChanHandle /* context handle */ |
|---|
| 235 | ); |
|---|
| 236 | |
|---|
| 237 | /**************************************************************** |
|---|
| 238 | Summary: |
|---|
| 239 | This function returns events used by the record module |
|---|
| 240 | ****************************************************************/ |
|---|
| 241 | BERR_Code BPVRlib_Rec_GetEvents( |
|---|
| 242 | BPVRlib_Rec_Handle recHandle, /* context handle*/ |
|---|
| 243 | BPVRlib_Rec_Events *events /* events would be returned in this structure */ |
|---|
| 244 | ); |
|---|
| 245 | |
|---|
| 246 | |
|---|
| 247 | /**************************************************************** |
|---|
| 248 | Summary: |
|---|
| 249 | This function starts a record channel. |
|---|
| 250 | ****************************************************************/ |
|---|
| 251 | BERR_Code BPVRlib_Rec_Start( |
|---|
| 252 | BPVRlib_Rec_Handle recChanHandle /* context handle */ |
|---|
| 253 | ); |
|---|
| 254 | |
|---|
| 255 | /**************************************************************** |
|---|
| 256 | Summary: |
|---|
| 257 | This function checks if any data has been recorded |
|---|
| 258 | into the record buffer. If not, it can optionally block |
|---|
| 259 | until data is recorded, or return immediately. When |
|---|
| 260 | data is in the record buffer, it is copied (using the |
|---|
| 261 | memcpy funtion pointer passed in pvr_recordAllocate) |
|---|
| 262 | to the destination buffer. The function always returns |
|---|
| 263 | when ANY amount of data is available, ie the destination |
|---|
| 264 | buffer will not always be filled, so make sure to |
|---|
| 265 | check the *p_bfrSize when this function returns! |
|---|
| 266 | ****************************************************************/ |
|---|
| 267 | BERR_Code BPVRlib_Rec_GetData( |
|---|
| 268 | BPVRlib_Rec_Handle recChanHandle, /* context handle */ |
|---|
| 269 | uint8_t *p_bfr, /* [out,sizeof(*p_bfrSize)] pointer to destination buffer */ |
|---|
| 270 | size_t *p_bfrSize, /* [in,out] size of destination buffer (in bytes), returns number of bytes actually copied */ |
|---|
| 271 | bool block, /* false (do not block), true (block until data is available) */ |
|---|
| 272 | bool *p_overflow /* [out] returns 1 if record overflow has occurred */ |
|---|
| 273 | ); |
|---|
| 274 | |
|---|
| 275 | /**************************************************************** |
|---|
| 276 | Summary: |
|---|
| 277 | This function checks if any data has been recorded |
|---|
| 278 | into the record buffer. If not, it can optionally block |
|---|
| 279 | until data is recorded, or return immediately. When |
|---|
| 280 | data is in the record buffer, the address and size |
|---|
| 281 | of the valid data is returned. It is up to the |
|---|
| 282 | calling code to copy data from this location and |
|---|
| 283 | update the read pointer for the record channel |
|---|
| 284 | using the BPVRlib_Rec_UpdateReadPointer() function. |
|---|
| 285 | ****************************************************************/ |
|---|
| 286 | BERR_Code BPVRlib_Rec_GetDataRequest( |
|---|
| 287 | BPVRlib_Rec_Handle recChanHandle, /* context handle */ |
|---|
| 288 | uint8_t **pp_bfr, /* [out] returns pointer to the start of valid data */ |
|---|
| 289 | size_t *p_bfrSize, /* [out] returns size of the valid data (in bytes) */ |
|---|
| 290 | bool block /* 0 (do not block), 1 (block until data is available) */ |
|---|
| 291 | ); |
|---|
| 292 | |
|---|
| 293 | /**************************************************************** |
|---|
| 294 | Summary: |
|---|
| 295 | This function updates the read pointer for the |
|---|
| 296 | record record buffer. It is used to notify the record |
|---|
| 297 | buffer when data has been copied out of the buffer and |
|---|
| 298 | this space can be re-used for new record data. |
|---|
| 299 | ****************************************************************/ |
|---|
| 300 | BERR_Code BPVRlib_Rec_UpdateReadPointer( |
|---|
| 301 | BPVRlib_Rec_Handle recChanHandle, /* context handle */ |
|---|
| 302 | size_t bytesRead, /* number of bytes that have been read from ring buffer */ |
|---|
| 303 | bool block, /* not currently used */ |
|---|
| 304 | bool *p_overflow /* [out] returns true if record overflow has occurred */ |
|---|
| 305 | ); |
|---|
| 306 | |
|---|
| 307 | /**************************************************************** |
|---|
| 308 | Summary: |
|---|
| 309 | This function stops a record channel and waits for |
|---|
| 310 | the record done interrupt to occur. After the stop |
|---|
| 311 | function is called, don't forget to remove the last |
|---|
| 312 | remains of the record from the record buffer! |
|---|
| 313 | |
|---|
| 314 | This function will return an error if there is any overflow |
|---|
| 315 | pending in the record channel (overflow must be handled |
|---|
| 316 | before the record can be stopped!) |
|---|
| 317 | ****************************************************************/ |
|---|
| 318 | BERR_Code BPVRlib_Rec_Stop( |
|---|
| 319 | BPVRlib_Rec_Handle recChanHandle /* context handle */ |
|---|
| 320 | ); |
|---|
| 321 | |
|---|
| 322 | /**************************************************************** |
|---|
| 323 | Summary: |
|---|
| 324 | This function returns the number of valid bytes in the |
|---|
| 325 | record buffer (already recorded by hardware). |
|---|
| 326 | ****************************************************************/ |
|---|
| 327 | void BPVRlib_Rec_GetBufferDepth( |
|---|
| 328 | BPVRlib_Rec_Handle recChanHandle, /* context handle */ |
|---|
| 329 | size_t *p_bfrDepth /* [out] number of valid bytes in the record buffer */ |
|---|
| 330 | ); |
|---|
| 331 | |
|---|
| 332 | /**************************************************************** |
|---|
| 333 | Summary: |
|---|
| 334 | This function sets the maximum timeout value allowed when |
|---|
| 335 | waiting for buffer space or descriptors to become available. |
|---|
| 336 | INFINITE is used by default and is the recommended value. |
|---|
| 337 | ****************************************************************/ |
|---|
| 338 | void BPVRlib_Rec_SetTimeout( |
|---|
| 339 | BPVRlib_Rec_Handle recChanHandle, /* context handle */ |
|---|
| 340 | uint32_t numMsec /* timeout value in msec */ |
|---|
| 341 | ); |
|---|
| 342 | |
|---|
| 343 | /**************************************************************** |
|---|
| 344 | Summary: |
|---|
| 345 | This function returns the current timeout value |
|---|
| 346 | used when waiting for buffer space or descriptors |
|---|
| 347 | to become available. |
|---|
| 348 | ****************************************************************/ |
|---|
| 349 | void BPVRlib_Rec_GetTimeout( |
|---|
| 350 | BPVRlib_Rec_Handle recChanHandle, /* context handle */ |
|---|
| 351 | uint32_t *p_numMsec /* [out] returns current timeout value in msec */ |
|---|
| 352 | ); |
|---|
| 353 | |
|---|
| 354 | /**************************************************************** |
|---|
| 355 | Summary: |
|---|
| 356 | This function returns various record channel statistics. |
|---|
| 357 | ****************************************************************/ |
|---|
| 358 | BERR_Code BPVRlib_Rec_GetStats( |
|---|
| 359 | BPVRlib_Rec_Handle recChanHandle, /* context handle */ |
|---|
| 360 | BPVRlib_Rec_Stats *p_stats /* [out] this structure is filled with statistics */ |
|---|
| 361 | ); |
|---|
| 362 | |
|---|
| 363 | #ifdef __cplusplus |
|---|
| 364 | } |
|---|
| 365 | #endif |
|---|
| 366 | |
|---|
| 367 | #endif |
|---|
| 368 | |
|---|