| 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 | * This file was based upon: /SetTop/syslib/pvrlib/7115/pvrlib_rec.h@@Irvine_HDDemo_Devel/11 |
|---|
| 11 | * |
|---|
| 12 | * $brcm_Workfile: bpvrlib_rec.h $ |
|---|
| 13 | * $brcm_Revision: Hydra_Software_Devel/11 $ |
|---|
| 14 | * $brcm_Date: 1/24/05 6:09p $ |
|---|
| 15 | * |
|---|
| 16 | * Module Description: |
|---|
| 17 | * |
|---|
| 18 | * Revision History: |
|---|
| 19 | * |
|---|
| 20 | * $brcm_Log: /magnum/syslib/pvrlib/bpvrlib_rec.h $ |
|---|
| 21 | * |
|---|
| 22 | * Hydra_Software_Devel/11 1/24/05 6:09p marcusk |
|---|
| 23 | * PR13896: Added new function to support scd formats. |
|---|
| 24 | * |
|---|
| 25 | * Hydra_Software_Devel/10 4/12/04 10:28p vsilyaev |
|---|
| 26 | * PR10546: Added function BPVRlib_Rec_GetEvents; |
|---|
| 27 | * Fixed bug with not clearing out p_overflow. |
|---|
| 28 | * |
|---|
| 29 | * Hydra_Software_Devel/9 1/21/04 4:43p marcusk |
|---|
| 30 | * PR8927: Fixed to work with latest version of XPT porting interface. |
|---|
| 31 | * Validate channel number. |
|---|
| 32 | * |
|---|
| 33 | * Hydra_Software_Devel/8 1/10/04 10:47a marcusk |
|---|
| 34 | * PR8927: Fixed playback isses. |
|---|
| 35 | * |
|---|
| 36 | * Hydra_Software_Devel/7 12/29/03 3:59p marcusk |
|---|
| 37 | * PR9117: Updated with changes required to support interrupt ids rather |
|---|
| 38 | * than strings. |
|---|
| 39 | * |
|---|
| 40 | * Hydra_Software_Devel/6 12/19/03 3:52p marcusk |
|---|
| 41 | * PR8927: Updated to use xpt record handle allocated by higher level |
|---|
| 42 | * software. |
|---|
| 43 | * |
|---|
| 44 | * Hydra_Software_Devel/5 12/12/03 2:03p dlwin |
|---|
| 45 | * PR 8970: Change naming convention to conform to Magnum |
|---|
| 46 | * |
|---|
| 47 | * Hydra_Software_Devel/4 12/11/03 4:00p marcusk |
|---|
| 48 | * PR8936: Updated to use new APIs. |
|---|
| 49 | * |
|---|
| 50 | * Hydra_Software_Devel/3 12/10/03 2:25p marcusk |
|---|
| 51 | * PR8927: Record syslib now compiles. |
|---|
| 52 | * |
|---|
| 53 | * Hydra_Software_Devel/2 12/10/03 11:07a marcusk |
|---|
| 54 | * PR 8927: Initial magnum version (not compiled yet) |
|---|
| 55 | * |
|---|
| 56 | ***************************************************************************/ |
|---|
| 57 | |
|---|
| 58 | /*================== Module Overview ===================================== |
|---|
| 59 | |
|---|
| 60 | This module implements the record functionality for pvr using an intermediate |
|---|
| 61 | ring buffer. It features a programmable buffer location, buffer size, and number |
|---|
| 62 | of descriptors. It also supports a constant stream by dynamically adding buffers |
|---|
| 63 | into the transport record hardware. |
|---|
| 64 | |
|---|
| 65 | The following general overview describes the record algorithm: |
|---|
| 66 | |
|---|
| 67 | 1.0 Allocate |
|---|
| 68 | |
|---|
| 69 | - The number of descriptors and buffer address are passed as parameters |
|---|
| 70 | - The ring buffer manager is allocated |
|---|
| 71 | - Array of descriptors is allocated (all descriptors are added to free list) |
|---|
| 72 | |
|---|
| 73 | 1.1 Configure Record |
|---|
| 74 | |
|---|
| 75 | - Data transport PIDs are enabled and configured |
|---|
| 76 | - Record parameters are configured (including decryption/encryption, etc) |
|---|
| 77 | - Record pid channel bitmap is enabled |
|---|
| 78 | - SCT record parameters should be set |
|---|
| 79 | |
|---|
| 80 | 1.2 Start Record (SCT record channel should be started first if required) |
|---|
| 81 | |
|---|
| 82 | - Ring buffer manager is reset |
|---|
| 83 | - Entire buffer is divided evenly between all descriptors. |
|---|
| 84 | Descriptors are filled in and added to record hardware and hardware list |
|---|
| 85 | - Record hardware is started |
|---|
| 86 | |
|---|
| 87 | 1.3 Get Data (not re-entrant for same record channel) |
|---|
| 88 | |
|---|
| 89 | - Buffer address and size is requested from the ring buffer manager |
|---|
| 90 | (this step may block if there is no data available) |
|---|
| 91 | (blocking is disabled if the record channel is stopped) |
|---|
| 92 | - Data is copied unsigned char specified buffer |
|---|
| 93 | - Ring buffer read offset is updated |
|---|
| 94 | - If current read offset is large enough to accomidate descriptor |
|---|
| 95 | bfr size, the decriptor is removed from free list and |
|---|
| 96 | added back into record hardware and hardware list. |
|---|
| 97 | - The amount of data copied from record channel is returned |
|---|
| 98 | - Overflow status is returned |
|---|
| 99 | |
|---|
| 100 | (Alternate to 1.3) |
|---|
| 101 | 1.3.1 Request to Get Data (steps 1.3.x not re-entrant for same record channel) |
|---|
| 102 | |
|---|
| 103 | - Buffer address and size is requested from the ring buffer manager |
|---|
| 104 | (this step may block if there is no space available) |
|---|
| 105 | (blocking is disabled if the record channel is stopped) |
|---|
| 106 | - Overflow status is returned |
|---|
| 107 | |
|---|
| 108 | 1.3.2 Data is copied from specified buffer by calling code |
|---|
| 109 | |
|---|
| 110 | 1.3.3 Read pointer is updated |
|---|
| 111 | - Ring buffer read offset is updated |
|---|
| 112 | - If current read offset is large enough to accomidate descriptor |
|---|
| 113 | bfr size, the decriptor is removed from free list and |
|---|
| 114 | added back into record hardware and hardware list. |
|---|
| 115 | |
|---|
| 116 | 1.4 Check for Hardware Data Complete |
|---|
| 117 | |
|---|
| 118 | - First descriptor is removed from hardware list |
|---|
| 119 | - Event is triggered signaling removal of descriptor |
|---|
| 120 | - Ring buffer write offset is updated |
|---|
| 121 | - Event is triggered signaling addition of data into ring buffer |
|---|
| 122 | - Descriptor is added to free list |
|---|
| 123 | - Check if next descriptor has also completed (repeat process if necessary) |
|---|
| 124 | |
|---|
| 125 | 1.5 Stop Record |
|---|
| 126 | |
|---|
| 127 | - Record hardware is stopped |
|---|
| 128 | - Wait for record done interrupt to occur if we are stopping a transport record channel |
|---|
| 129 | (sct channels are slaved to the transport channel) |
|---|
| 130 | (Data complete interrupt handler updates read pointer based upon what |
|---|
| 131 | data is recorded after stop occurs) |
|---|
| 132 | - All left over descriptors are moved from hw to the free list |
|---|
| 133 | - Any blocking calls are released (future calls are not allowed to block) |
|---|
| 134 | - Additional get data function call should be called to get remaining |
|---|
| 135 | data from record. |
|---|
| 136 | |
|---|
| 137 | 1.6 Free |
|---|
| 138 | |
|---|
| 139 | - Free descriptor buffer |
|---|
| 140 | - Free ring buffer manager |
|---|
| 141 | |
|---|
| 142 | ========================================================================*/ |
|---|
| 143 | |
|---|
| 144 | #ifndef __BPVRLIB_REC_H__ |
|---|
| 145 | #define __BPVRLIB_REC_H__ |
|---|
| 146 | |
|---|
| 147 | #include "bxpt_record.h" |
|---|
| 148 | |
|---|
| 149 | #ifdef __cplusplus |
|---|
| 150 | extern "C" { |
|---|
| 151 | #endif |
|---|
| 152 | |
|---|
| 153 | /* |
|---|
| 154 | Summary: |
|---|
| 155 | This callback is compatible with the standard 'c' memcpy routine. |
|---|
| 156 | It is used to copy data between a user buffer and the ring |
|---|
| 157 | buffer during a pvr_recordGetData() function call. |
|---|
| 158 | */ |
|---|
| 159 | typedef void *(*BPVRlib_Rec_CopyMemoryCb)( void *, const void *, size_t ); |
|---|
| 160 | |
|---|
| 161 | /* |
|---|
| 162 | Summary: |
|---|
| 163 | This handle is used to store the context of a pvr record. |
|---|
| 164 | */ |
|---|
| 165 | typedef struct BPVRlib_Rec_P_Handle *BPVRlib_Rec_Handle; |
|---|
| 166 | |
|---|
| 167 | /* |
|---|
| 168 | Summary: |
|---|
| 169 | This structure is used to store various statistics that can |
|---|
| 170 | be used to monitor and debug a record that is in progress. |
|---|
| 171 | Note: All stats are reset when the record is started or flushed! |
|---|
| 172 | */ |
|---|
| 173 | typedef struct |
|---|
| 174 | { |
|---|
| 175 | uint32_t numBytesRecorded; /* Number of bytes recorded by hardware */ |
|---|
| 176 | uint32_t numBytesRemoved; /* Number of bytes removed from the ring buffer by software */ |
|---|
| 177 | size_t bfrSize; /* Total buffer size */ |
|---|
| 178 | uint32_t readOffset; /* Current read offset */ |
|---|
| 179 | uint32_t writeOffset; /* Current write offset */ |
|---|
| 180 | uint32_t numFreeDesc; /* Current number of free descriptors */ |
|---|
| 181 | uint32_t numInHwDesc; /* Current number of descriptors being processed by hardware */ |
|---|
| 182 | uint32_t numDesc; /* Total number of descriptors */ |
|---|
| 183 | uint32_t numDescAdded; /* Number of descriptors added in to hardware */ |
|---|
| 184 | uint32_t numDescCompleted; /* Number of descriptors completed by hardware */ |
|---|
| 185 | uint32_t numOverFlows; /* Number of times the hardware has reached the end of its descriptor list */ |
|---|
| 186 | uint32_t numBufferBlocks; /* Number of times blocking has occurred due to buffer resources */ |
|---|
| 187 | uint32_t numTimeouts; /* Number of times blocking has failed due to a timeout */ |
|---|
| 188 | uint32_t maxBfrDepth; /* Maximum number of bytes stored in buffer */ |
|---|
| 189 | } BPVRlib_Rec_Stats; |
|---|
| 190 | |
|---|
| 191 | /* |
|---|
| 192 | The BPVRlib_Rec_Events structure is used to return various events used by the record module. |
|---|
| 193 | Those events could be latter useful when application useed nonblocking flavor of record |
|---|
| 194 | */ |
|---|
| 195 | typedef struct BPVRlib_Rec_Events |
|---|
| 196 | { |
|---|
| 197 | BKNI_EventHandle descEvent; /* Event used to signal when descriptor is added to free list */ |
|---|
| 198 | BKNI_EventHandle finishedEvent; /* Event used to signal when the record has finished */ |
|---|
| 199 | } BPVRlib_Rec_Events; |
|---|
| 200 | |
|---|
| 201 | |
|---|
| 202 | /**************************************************************** |
|---|
| 203 | Summary: |
|---|
| 204 | This function allocates the resources required for a |
|---|
| 205 | record. |
|---|
| 206 | |
|---|
| 207 | Description: |
|---|
| 208 | This includes a ring buffer manager, |
|---|
| 209 | descriptor list, etc. The record ring buffer is evenly |
|---|
| 210 | divided between the number of descriptors. This requires |
|---|
| 211 | the size of the buffer to be cleanly divisable (on a 32 bit |
|---|
| 212 | boundary) by the number of requested descriptors. |
|---|
| 213 | The pvrMemCopyCb parameter only needs to be valid |
|---|
| 214 | if the BPVRlib_Rec_GetData() function is going to be |
|---|
| 215 | used. |
|---|
| 216 | |
|---|
| 217 | See also: |
|---|
| 218 | BPVRlib_Rec_Close(), BPVRlib_Rec_Start(), BPVRlib_Rec_GetData() |
|---|
| 219 | ****************************************************************/ |
|---|
| 220 | BERR_Code BPVRlib_Rec_Open( |
|---|
| 221 | BPVRlib_Rec_Handle *pRecHandle, /* [out] context handle */ |
|---|
| 222 | BXPT_Handle xptHandle, /* XPT handle */ |
|---|
| 223 | BXPT_Record_Handle xptRecHandle, /* XPT record handle */ |
|---|
| 224 | BMEM_Handle memHandle, /* Mem handle */ |
|---|
| 225 | BINT_Handle intHandle, /* Int handle */ |
|---|
| 226 | BXPT_ChanType chanType, /* Record channel type */ |
|---|
| 227 | unsigned chanNum, /* record channel number */ |
|---|
| 228 | uint8_t *p_bfr, /* pointer to buffer that should be used for record ring buffer, 0 to allocate the buffer internally */ |
|---|
| 229 | size_t bfrSize, /* size of record ring buffer (in bytes) */ |
|---|
| 230 | uint32_t numDesc, /* number of descriptors to use */ |
|---|
| 231 | BPVRlib_Rec_CopyMemoryCb copyMemCb /* function pointer for memory copies (optional) */ |
|---|
| 232 | ); |
|---|
| 233 | |
|---|
| 234 | /**************************************************************** |
|---|
| 235 | Summary: |
|---|
| 236 | This function frees any resources used by a record |
|---|
| 237 | channel. |
|---|
| 238 | ****************************************************************/ |
|---|
| 239 | BERR_Code BPVRlib_Rec_Close( |
|---|
| 240 | BPVRlib_Rec_Handle recHandle /* context handle */ |
|---|
| 241 | ); |
|---|
| 242 | |
|---|
| 243 | /**************************************************************** |
|---|
| 244 | Summary: |
|---|
| 245 | This function returns events used by the record module |
|---|
| 246 | ****************************************************************/ |
|---|
| 247 | BERR_Code BPVRlib_Rec_GetEvents( |
|---|
| 248 | BPVRlib_Rec_Handle recHandle, /* context handle*/ |
|---|
| 249 | BPVRlib_Rec_Events *events /* events would be returned in this structure */ |
|---|
| 250 | ); |
|---|
| 251 | |
|---|
| 252 | |
|---|
| 253 | /**************************************************************** |
|---|
| 254 | Summary: |
|---|
| 255 | This function starts a record channel. |
|---|
| 256 | ****************************************************************/ |
|---|
| 257 | BERR_Code BPVRlib_Rec_Start( |
|---|
| 258 | BPVRlib_Rec_Handle recHandle /* context handle */ |
|---|
| 259 | ); |
|---|
| 260 | |
|---|
| 261 | /**************************************************************** |
|---|
| 262 | Summary: |
|---|
| 263 | This function checks if any data has been recorded |
|---|
| 264 | into the ring buffer. If not, it can optionally block |
|---|
| 265 | until data is recorded, or return immediately. When |
|---|
| 266 | data is in the record buffer, it is copied (using the |
|---|
| 267 | memcpy funtion pointer passed in pvr_recordAllocate) |
|---|
| 268 | to the destination buffer. The function always returns |
|---|
| 269 | when ANY amount of data is available, ie the destination |
|---|
| 270 | buffer will not always be filled, so make sure to |
|---|
| 271 | check the *p_bfrSize when this function returns! |
|---|
| 272 | ****************************************************************/ |
|---|
| 273 | BERR_Code BPVRlib_Rec_GetData( |
|---|
| 274 | BPVRlib_Rec_Handle recHandle, /* context handle */ |
|---|
| 275 | uint8_t *p_bfr, /* [out,sizeof(*p_bfrSize)] pointer to destination buffer */ |
|---|
| 276 | size_t *p_bfrSize, /* [in,out] size of destination buffer (in bytes), returns number of bytes actually copied */ |
|---|
| 277 | bool block, /* false (do not block), true (block until data is available) */ |
|---|
| 278 | bool *p_overflow /* [out] returns 1 if record overflow has occurred */ |
|---|
| 279 | ); |
|---|
| 280 | |
|---|
| 281 | /**************************************************************** |
|---|
| 282 | Summary: |
|---|
| 283 | This function checks if any data has been recorded |
|---|
| 284 | into the ring buffer. If not, it can optionally block |
|---|
| 285 | until data is recorded, or return immediately. When |
|---|
| 286 | data is in the record buffer, the address and size |
|---|
| 287 | of the valid data is returned. It is up to the |
|---|
| 288 | calling code to copy data from this location and |
|---|
| 289 | update the read pointer for the record channel |
|---|
| 290 | using the BPVRlib_Rec_UpdateReadPointer() function. |
|---|
| 291 | ****************************************************************/ |
|---|
| 292 | BERR_Code BPVRlib_Rec_GetDataRequest( |
|---|
| 293 | BPVRlib_Rec_Handle recHandle, /* context handle */ |
|---|
| 294 | uint8_t **pp_bfr, /* [out] returns pointer to the start of valid data */ |
|---|
| 295 | size_t *p_bfrSize, /* [out] returns size of the valid data (in bytes) */ |
|---|
| 296 | bool block /* 0 (do not block), 1 (block until data is available) */ |
|---|
| 297 | ); |
|---|
| 298 | |
|---|
| 299 | /**************************************************************** |
|---|
| 300 | Summary: |
|---|
| 301 | This function updates the read pointer for the |
|---|
| 302 | record ring buffer. It is used to notify the ring |
|---|
| 303 | buffer when data has been copied out of the buffer and |
|---|
| 304 | this space can be re-used for new record data. |
|---|
| 305 | NOTE: The p_overflow variable will not be reset |
|---|
| 306 | when there is not an overflow. It is up to the calling |
|---|
| 307 | function to set this variable to false BEFORE calling |
|---|
| 308 | this function! |
|---|
| 309 | ****************************************************************/ |
|---|
| 310 | BERR_Code BPVRlib_Rec_UpdateReadPointer( |
|---|
| 311 | BPVRlib_Rec_Handle recHandle, /* context handle */ |
|---|
| 312 | size_t bytesRead, /* number of bytes that have been read from ring buffer */ |
|---|
| 313 | bool block, /* not currently used */ |
|---|
| 314 | bool *p_overflow /* [out] returns true if record overflow has occurred */ |
|---|
| 315 | ); |
|---|
| 316 | |
|---|
| 317 | /**************************************************************** |
|---|
| 318 | Summary: |
|---|
| 319 | This function stops a record channel and waits for |
|---|
| 320 | the record done interrupt to occur. After the stop |
|---|
| 321 | function is called, don't forget to remove the last |
|---|
| 322 | remains of the record from the ring buffer! |
|---|
| 323 | ****************************************************************/ |
|---|
| 324 | BERR_Code BPVRlib_Rec_Stop( |
|---|
| 325 | BPVRlib_Rec_Handle recHandle /* context handle */ |
|---|
| 326 | ); |
|---|
| 327 | |
|---|
| 328 | /**************************************************************** |
|---|
| 329 | Summary: |
|---|
| 330 | This function returns the number of valid bytes in the |
|---|
| 331 | ring buffer (already recorded by hardware). |
|---|
| 332 | ****************************************************************/ |
|---|
| 333 | void BPVRlib_Rec_GetBufferDepth( |
|---|
| 334 | BPVRlib_Rec_Handle recHandle, /* context handle */ |
|---|
| 335 | size_t *p_bfrDepth /* [out] number of valid bytes in the ring buffer */ |
|---|
| 336 | ); |
|---|
| 337 | |
|---|
| 338 | /**************************************************************** |
|---|
| 339 | Summary: |
|---|
| 340 | This function sets the maximum timeout value allowed when |
|---|
| 341 | waiting for buffer space or descriptors to become available. |
|---|
| 342 | INFINITE is used by default and is the recommended value. |
|---|
| 343 | ****************************************************************/ |
|---|
| 344 | void BPVRlib_Rec_SetTimeout( |
|---|
| 345 | BPVRlib_Rec_Handle recHandle, /* context handle */ |
|---|
| 346 | uint32_t numMsec /* timeout value in msec */ |
|---|
| 347 | ); |
|---|
| 348 | |
|---|
| 349 | /**************************************************************** |
|---|
| 350 | Summary: |
|---|
| 351 | This function returns the current timeout value |
|---|
| 352 | used when waiting for buffer space or descriptors |
|---|
| 353 | to become available. |
|---|
| 354 | ****************************************************************/ |
|---|
| 355 | void BPVRlib_Rec_GetTimeout( |
|---|
| 356 | BPVRlib_Rec_Handle recHandle, /* context handle */ |
|---|
| 357 | uint32_t *p_numMsec /* [out] returns current timeout value in msec */ |
|---|
| 358 | ); |
|---|
| 359 | |
|---|
| 360 | /**************************************************************** |
|---|
| 361 | Summary: |
|---|
| 362 | This function returns various record channel statistics. |
|---|
| 363 | ****************************************************************/ |
|---|
| 364 | BERR_Code BPVRlib_Rec_GetStats( |
|---|
| 365 | BPVRlib_Rec_Handle recHandle, /* context handle */ |
|---|
| 366 | BPVRlib_Rec_Stats *p_stats /* [out] this structure is filled with statistics */ |
|---|
| 367 | ); |
|---|
| 368 | |
|---|
| 369 | /**************************************************************** |
|---|
| 370 | Summary: |
|---|
| 371 | This function sets the format of a SCD record channel. |
|---|
| 372 | |
|---|
| 373 | Description: |
|---|
| 374 | This function is only valid for a BXPT_ChanType_eScd type of |
|---|
| 375 | record channel. It is ignored for other types of record channels. |
|---|
| 376 | ****************************************************************/ |
|---|
| 377 | void BPVRlib_Rec_SetIndexType( |
|---|
| 378 | BPVRlib_Rec_Handle recHandle, /* context handle */ |
|---|
| 379 | BXPT_IndexTable indexType /* type of index data to record (default is BXPT_IndexTable_eStartCode4Word) */ |
|---|
| 380 | ); |
|---|
| 381 | |
|---|
| 382 | #ifdef __cplusplus |
|---|
| 383 | } |
|---|
| 384 | #endif |
|---|
| 385 | |
|---|
| 386 | #endif |
|---|
| 387 | |
|---|