source: svn/newcon3bcm2_21bu/magnum/syslib/pvrlib/bpvrlib_play.h @ 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: 19.8 KB
Line 
1/***************************************************************************
2 *     Copyright (c) 2002-2007, 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_play.h $
11 * $brcm_Revision: Hydra_Software_Devel/9 $
12 * $brcm_Date: 1/23/07 2:05p $
13 *
14 * Module Description:
15 *
16 * This module implements the playback functionality for pvr using an intermediate
17 * ring buffer.  It features a programmable buffer location, buffer size, and number
18 * of descriptors.  It also supports a constant stream by dynamically adding buffers
19 * into the transport playback hardware.
20 *
21 * Revision History:
22 *
23 * $brcm_Log: /magnum/syslib/pvrlib/bpvrlib_play.h $
24 *
25 * Hydra_Software_Devel/9   1/23/07 2:05p erickson
26 * PR27252: clarify event usage in pvrlib to avoid WaitForEvent bugs
27 *
28 * Hydra_Software_Devel/8   6/18/04 11:32a marcusk
29 * PR11591: Updated to support returning if descriptor is available when
30 * calling BPVRlib_Play_AddDataRequest()
31 *
32 * Hydra_Software_Devel/7   6/3/04 6:04p marcusk
33 * PR11347: Added new functions
34 *
35 * Hydra_Software_Devel/6   4/8/04 6:31p marcusk
36 * PR10543: Added feature to support skip size when updating ring buffer
37 * write pointer.
38 *
39 * Hydra_Software_Devel/5   2/19/04 10:32a vsilyaev
40 * PR 8927: Added function to return events used by playback module
41 *
42 * Hydra_Software_Devel/4   1/21/04 4:43p marcusk
43 * PR8927: Fixed to work with latest version of XPT porting interface.
44 * Validate channel number.
45 *
46 * Hydra_Software_Devel/3   1/10/04 10:47a marcusk
47 * PR8927: Fixed playback isses.
48 *
49 * Hydra_Software_Devel/2   1/7/04 6:12p marcusk
50 * PR8927: Initial magnum version
51 *
52 * Hydra_Software_Devel/1   12/10/03 11:00a marcusk
53 * PR 8927: Starting with 7115 PVR syslibs.
54 *
55 * Irvine_BSEAVSW_Devel/17   2/20/03 6:14p marcusk
56 * Added pvr_playbackSwitchSyncModes() function.
57 *
58 * Irvine_HDDemo_Devel/16   7/12/02 10:50a marcusk
59 * Added a few functions to override default pause and packet length
60 * settings.
61 *
62 * Irvine_HDDemo_Devel\15   3/21/02 11:26a marcusk
63 * Added feature to auto-allocate buffer if p_bfr is set to 0 during the
64 * allocate routine.
65 *
66 * \main\Irvine_HDDemo_Devel\14   3/19/02 12:8p marcusk
67 * Added CR/LF at end of file to remove linux warnings.
68 *
69 ***************************************************************************/
70
71
72 /*================== Module Overview =====================================
73 
74 The following general overview describes the playback algorithm:
75 
76  1.0 Allocate
77 
78        - The number of descriptors and buffer address are passed as parameters
79        - The ring buffer manager is allocated
80        - Array of descriptors is allocated (all descriptors are added to free list)
81 
82  1.1 Start Playback
83 
84        - Playback resync variable is set (used to reset sync detect engine)
85        - Configure playback hardware based upon sync mode
86        - Playback hardware is started
87 
88  1.2 Add Data (not re-entrant for same playback channel)
89 
90        - Buffer address and size is requested from the ring buffer manager
91        (this step may block if there is no space available)
92        - Data is copied into specified buffer
93        - Ring buffer write offset is updated
94        - Data is commited to hardware
95        - In the case of no blocking, the amount of data NOT copied is returned
96 
97  (Alternate 1.2)
98  1.2.1 Request to Add Data (steps 1.2.x not re-entrant for same playback channel)
99 
100        - Free buffer address and size is requested from the ring buffer manager
101        (this step may block if there is no space available)
102 
103  1.2.2 Data is copied to specified buffer by calling code
104 
105  1.2.3 Write pointer is updated
106 
107        - Ring buffer write offset is updated
108        - Data is commited to hardware
109 
110  1.3 Data is Commited To Hardware
111 
112        - Availability of free descriptor is checked
113        (this step may block if there is no space available)
114        - Descriptor is obtained from the free list
115        - Buffer address and size is programmed into descriptor
116        - Descriptor is added to hardware list
117        - Descriptor is programmed into playback hardware
118 
119  1.4 Hardware Data Complete
120 
121        - First descriptor is removed from hardware list
122        - Event is triggered signaling removal of descriptor
123        - Ring buffer read offset is updated
124        - Event is triggered signaling freeing of data from ring buffer
125        - Descriptor is added to free list
126        - Check if next descriptor has also completed (repeat process if necessary)
127 
128  1.5 Stop Playback
129 
130        - Playback hardware is stopped
131        - Ring buffer manager is reset
132        - All descriptors are moved from hw to the free list
133 
134  1.6 Free
135 
136        - Free descriptor buffer
137        - Free ring buffer manager
138       
139================== End Module Overview =================================*/
140 
141#ifndef BPVRLIB_PLAY_H__
142#define BPVRLIB_PLAY_H__
143
144#include "bxpt_playback.h"
145
146#ifdef __cplusplus
147extern "C" {
148#endif
149
150/*
151        This callback is compatible with the standard 'c' memcpy routine.
152        It is used to copy data between a user buffer and the ring
153        buffer during a BPVRlib_Play_AddData() function call.
154*/
155typedef void *(*BPVRlib_Play_MemCopyCb)( void *, const void *, size_t ); 
156
157/*
158Summary:
159This handle is used to store the context of a pvr record.
160*/
161typedef struct BPVRlib_Play_P_Handle *BPVRlib_Play_Handle;
162
163/*
164Summary:
165This enumeration is used to describe the various types of blocking that can
166be used when performing playback with this module.
167*/
168typedef enum
169{
170        BPVRlib_Play_BlockMode_eNone, /* Do not block */
171        BPVRlib_Play_BlockMode_eFreeBuffer, /* Block until free space is available in the buffer */
172        BPVRlib_Play_BlockMode_eFreeDescriptor, /* Block until a descriptor is available (in addition to free space) */
173        BPVRlib_Play_BlockMode_eNoCommit /* Do not commit the buffer to the hardware until later */
174} BPVRlib_Play_BlockMode;
175
176/*
177        The BPVRlib_Play_Stats structure is used to store various statistics that can
178        be used to monitor and debug a playback that is in progress.
179        Note: All stats are reset when the playback is started or flushed!
180*/
181typedef struct
182{
183        size_t          numBytesPlayed;         /* Number of bytes played back through hardware */
184        size_t          numBytesAdded;          /* Number of bytes added into ring buffer */
185        size_t          bfrSize;                        /* Total buffer size */
186        size_t          readOffset;                     /* Current read offset */
187        size_t          writeOffset;            /* Current write offset */
188        size_t          hwWriteOffset;          /* Current hw write offset (committed to hardware) */
189        size_t          numBytesNotCommitted;   /* Current number of bytes in the ring buffer that are not committed into hardware */
190        size_t          numBytesScatGat;        /* Current number of bytes in scatter gather hardware list */
191        uint32_t        numFreeDesc;            /* Current number of free descriptors */
192        uint32_t        numInHwDesc;            /* Current number of descriptors being processed by hardware */
193        uint32_t        numScatGatDesc;         /* Current number of descriptors in hardware on scatter gather list */
194        uint32_t        numDesc;                        /* Total number of descriptors */
195        uint32_t        numDescAdded;           /* Number of descriptors added in to hardware */
196        uint32_t        numDescCompleted;       /* Number of descriptors completed by hardware */
197        uint32_t        numUnderFlows;          /* Number of times the hardware has reached the end of its descriptor list */
198        uint32_t        numBufferBlocks;        /* Number of times blocking has occurred due to buffer resources */
199        uint32_t        numDescBlocks;          /* Number of times blocking has occurred due to descriptor resources */
200        uint32_t        numTimeouts;            /* Number of times blocking has failed due to a timeout */
201        uint32_t        numMultiDescDone;       /* Number of times multiple descriptors have been completed in a single call */
202} BPVRlib_Play_Stats;
203
204/*
205        The BPVRlib_Play_Events structure is used to return various events used by playback module.
206        Those events could be used by an application for non-blocking playback.
207*/
208typedef struct BPVRlib_Play_Events
209{
210        BKNI_EventHandle        descEvent;              /* Event used to signal when descriptor is added to free list */
211        BKNI_EventHandle        finishedEvent;  /* Event used to signal when the playback has finished */
212} BPVRlib_Play_Events;
213
214/****************************************************************
215Summary:
216This function allocates the resources required for a playback.  This
217includes a ring buffer manager, descriptor list, etc.  The pvrMemCopyCb
218parameter only needs to be valid if the pvr_recordAddData() function is
219going to be used. 
220****************************************************************/
221BERR_Code BPVRlib_Play_Open(
222        BPVRlib_Play_Handle *pPlayHandle,       /* [out] context handle */
223        BXPT_Handle xptHandle,                          /* XPT handle */
224        BXPT_Playback_Handle xptPlayHandle,     /* XPT playback handle */
225        BMEM_Handle memHandle,                          /* Mem handle */
226        BINT_Handle intHandle,                          /* Int handle */
227        unsigned channelNum,                            /* playback channel number */
228        uint8_t *p_bfr,                                         /* pointer to buffer that should be used for playback ring buffer, 0 to allocate the buffer internally */
229        size_t bfrSize,                                 /* size of playback ring buffer (in bytes) */
230        uint32_t numDesc,                                       /* number of descriptors to use  */
231        BPVRlib_Play_MemCopyCb pvrMemCopyCb                     /* function pointer for memory copies (optional) */
232        );
233
234/****************************************************************
235Summary:
236This function frees any resources used by a playback channel.
237****************************************************************/
238BERR_Code BPVRlib_Play_Close( 
239        BPVRlib_Play_Handle playHandle          /* context handle */
240        );
241
242/****************************************************************
243Summary:
244This function returns events used by playback module
245Description:
246The events returned by this function cannot be used along with any blocking mode
247other than BPVRlib_Play_BlockMode_eNone.
248****************************************************************/
249BERR_Code BPVRlib_Play_GetEvents( 
250        BPVRlib_Play_Handle playHandle, /* context handle*/
251        BPVRlib_Play_Events *events    /* events would be returned in this structure */ 
252        );
253
254
255/****************************************************************
256Summary:
257This function starts a playback.
258****************************************************************/
259BERR_Code BPVRlib_Play_Start( 
260        BPVRlib_Play_Handle playHandle          /* context handle */
261        );
262
263/****************************************************************
264Summary:
265This function checks if there is any room in the playback ring buffer and
266copies data from the source buffer.  If there is no space available in the
267ring buffer this function can optionally block until space is available
268and all data has been copied.  It used the pvrMemCopyCb function passed in
269the BPVRlib_Play_Open() function to perform the memory copy. 
270****************************************************************/
271BERR_Code BPVRlib_Play_AddData( 
272        BPVRlib_Play_Handle playHandle,         /* context handle */
273        uint8_t *p_bfr,         /* pointer to source buffer */
274        size_t *p_bfrSize,      /* size of source buffer (in bytes) */
275        BPVRlib_Play_BlockMode block /* block mode */
276        );
277
278/****************************************************************
279Summary:
280This function checks if there is any room in the playback
281ring buffer. If there is no space available in the ring buffer this
282function can optionally block until space is available.
283
284Description:
285This function will return BERR_TIMEOUT if there is no buffer
286space available OR no descriptors available.  It is possible
287to add additional data to the buffer without having descriptors
288available.  If this type of operation is desired, the p_bfrSize
289variable should be checked for a non-zero value that signifies
290that buffer space is available.
291****************************************************************/
292BERR_Code BPVRlib_Play_AddDataRequest( 
293        BPVRlib_Play_Handle playHandle, /* context */
294        uint8_t **pp_bfr,               /* returns pointer to free space in ring buffer */
295        size_t *p_bfrSize,      /* returns size of free space (in bytes) */
296        BPVRlib_Play_BlockMode block /* block mode */
297        );
298
299/****************************************************************
300Summary:
301This function updates the write pointer of the ring buffer.
302This function will automatically call the
303BPVRlib_Play_CommitBuffersToHardware() (with the
304block parameter passed through) after the
305write pointer has been updated.
306****************************************************************/
307BERR_Code BPVRlib_Play_UpdateWritePointer( 
308        BPVRlib_Play_Handle playHandle, /* context */
309        size_t bfrSize,         /* number of bytes copied into ring buffer */
310        BPVRlib_Play_BlockMode block /* block mode */
311        );
312
313/****************************************************************
314Summary:
315This function updates the write pointer of the ring buffer but
316will program the playback hardware to skip the specified number of
317bytes starting at the last ring buffer location returned by
318BPVRlib_Play_AddDataRequest().  The specified bfrSize is
319INCLUSIVE of the skipSize.
320
321This function requires a descriptor to be available so the block
322mode is recommended to be set as
323BPVRlib_Play_BlockMode_eFreeDescriptor.  This function is
324usefull when reading blocks of data with specific alignment
325requirements since an extra memory copy is not needed.
326****************************************************************/
327BERR_Code BPVRlib_Play_UpdateWritePointerWithSkip( 
328        BPVRlib_Play_Handle playHandle, /* context */
329        size_t bfrSize,         /* number of bytes copied into ring buffer */
330        size_t skipSize,        /* number of bytes to skip at the current ring buffer address when programming hardware */
331        BPVRlib_Play_BlockMode block /* block mode */
332        );
333
334/****************************************************************
335Summary:
336This function check if descriptors are available
337for loading into the playback hardware.  If
338not the function can block until one becomes available.
339Once a descriptor is available, any new data is
340added into the playback hardware.
341If blocking is enabled, this function will not return
342until all data has been committed into hardware.
343****************************************************************/
344BERR_Code BPVRlib_Play_CommitBuffersToHardware( 
345        BPVRlib_Play_Handle playHandle, /* context */
346        BPVRlib_Play_BlockMode block    /* block mode */
347        );
348
349/****************************************************************
350Summary:
351This function flushes any data currently in the playback ring buffer.
352****************************************************************/
353BERR_Code BPVRlib_Play_Flush( 
354        BPVRlib_Play_Handle playHandle  /* context */
355        );
356
357/****************************************************************
358Summary:
359This function stops a playback.  It also moves all
360descriptors back onto the free list and resets to
361ring buffer to be ready for a new playback.
362****************************************************************/
363BERR_Code BPVRlib_Play_Stop( 
364        BPVRlib_Play_Handle playHandle  /* context */
365        );
366
367/***********************************************************/ /**
368Summary:
369This function returns the number of valid bytes in the
370ring buffer (currently being played back by the hardware).
371****************************************************************/
372BERR_Code BPVRlib_Play_GetBufferDepth( 
373        BPVRlib_Play_Handle playHandle, /* context */
374        size_t *p_bfrDepth      /* returns number of valid bytes in the ring buffer */
375        );
376
377/***********************************************************/ /**
378Summary:
379This function waits for the playback channel to finish.
380Once the playback is done it will return.  If the playback
381is stopped or flushed it will return immediately.
382****************************************************************/
383BERR_Code BPVRlib_Play_WaitForFinished( 
384        BPVRlib_Play_Handle playHandle  /* context */
385        );
386
387/***********************************************************/ /**
388Summary:
389This function sets the maximum timeout value allowed when
390waiting for buffer space or descriptors to become available.
391INFINITE is used by default and is the recommended value.
392****************************************************************/
393BERR_Code BPVRlib_Play_SetTimeout( 
394        BPVRlib_Play_Handle playHandle, /* context */
395        uint32_t numMsec                /* timeout value in msec */
396        );
397
398/***********************************************************/ /**
399Summary:
400This function returns the current timeout value
401used when waiting for buffer space or descriptors
402to become available.
403****************************************************************/
404BERR_Code BPVRlib_Play_GetTimeout( 
405        BPVRlib_Play_Handle playHandle, /* context */
406        uint32_t *p_numMsec     /* returns current timeout value */
407        );
408
409/***********************************************************/ /**
410Summary:
411This function returns various playback channel statistics.
412****************************************************************/
413BERR_Code BPVRlib_Play_GetStats( 
414        BPVRlib_Play_Handle playHandle, /* context */
415        BPVRlib_Play_Stats *p_stats     /* function fills this structure with statistics */ 
416        );
417
418/***********************************************************/ /**
419Summary:
420This function creates a NULL packet.  It is created in place starting
421at the location specified.  Therefore, the buffer must be at least
422188 bytes, or memory will be overwritten.
423****************************************************************/
424void BPVRlib_Play_GenerateTsNullPacket( 
425        uint8_t *pkt                    /* Pointer to buffer that will contain null packet (must be at least 188 bytes) */
426        );
427
428/***********************************************************/ /**
429Summary:
430This function is an alternate way of adding data to a playback channel
431on a buffer by buffer basis.  This allows scatter gather playback
432to be accomplished by loading specified buffers directly into the playback
433channel.
434
435Description:
436The calling code needs to track the number of buffers
437added to playback and use the BPVRlib_Play_IsBufferComplete() function
438to determine when buffers have been completed.  Alternatively,
439the numScatGatDesc stat obtained by the BPVRlib_Play_GetStats()
440function can be used to detect when buffers have completed.
441
442Buffers added using this function will be directly accessed by the
443playback hardware.  Therefore, buffers must be contiguous and be
444covertable using the BMEM_ConvertAddressToOffset() function. 
445This function will not flush the CPU cache (or any other cache
446in the system) so if necessary this should be done before calling
447this function. The calling function cannot reuse the specified
448buffer until playback is done using it.
449
450This function can be called and used at the same time the ring
451buffer is being used.  The data will be queued up in the order
452that the various functions were called.
453
454This function requires all data added to the ring buffer to be
455committed to hardware and requires a free descriptor to be
456available.  The block parameter can be used to wait for these
457requirements to be satisfied before the function returns.
458****************************************************************/
459BERR_Code BPVRlib_Play_AddBuffer( 
460        BPVRlib_Play_Handle playHandle,         /* context handle */
461        const uint8_t *p_bfr,   /* pointer to source buffer. must be covertable with the BMEM_ConvertAddressToOffset() function */
462        const size_t bfrSize,   /* size of buffer (in bytes) */
463        BPVRlib_Play_BlockMode block /* block mode */
464        );
465
466/***********************************************************/ /**
467Summary:
468This function is used to detect when scatter gather buffers have
469been completed by the playback hardware since the last call to
470BPVRlib_Play_IsBufferComplete().
471
472Description:
473After scatter gather buffers have been added to the playback
474channel using the BPVRlib_Play_AddBuffer() this function can
475be used to determine when they have completed.
476
477For example, if two buffers where added, this function would be
478called until both of those buffers were reported complete.
479
480The block parameter can be used to block until one or more buffers
481have been completed.
482****************************************************************/
483BERR_Code BPVRlib_Play_IsBufferComplete( 
484        BPVRlib_Play_Handle playHandle, /* context handle */
485        unsigned *p_bfrsCompleted,      /* number of scatter gather buffers completed since last call to BPVRlib_Play_BufferComplete() */
486        BPVRlib_Play_BlockMode block /* block mode */
487        );
488
489#ifdef __cplusplus
490}
491#endif
492
493#endif
494
Note: See TracBrowser for help on using the repository browser.