Skip to content

Latest commit

 

History

History
94 lines (71 loc) · 2.69 KB

File metadata and controls

94 lines (71 loc) · 2.69 KB
 
Dec 31, 2011
Dec 31, 2011
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
SMPEG - SDL MPEG Player Library
Copyright (C) 1999 Loki Entertainment Software
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/* A ring-buffer class for multi-threaded applications.
This assumes a single reader and a single writer, with blocking reads.
*/
#ifndef _MPEGRING_H
#define _MPEGRING_H
#include "SDL_types.h"
#include "SDL_thread.h"
class MPEG_ring {
public:
/* Create a ring with 'count' buffers, each 'size' bytes long */
MPEG_ring(Uint32 size, Uint32 count = 16);
/* Release any waiting threads on the ring so they can be cleaned up.
The ring isn't valid after this call, so when threads are done you
should call MPRing_sdelete() on the ring.
*/
void ReleaseThreads(void);
/* Destroy a ring after all threads are no longer using it */
virtual ~MPEG_ring();
/* Returns the maximum size of each buffer */
Uint32 BufferSize( void ) {
return(bufSize);
}
/* Returns how many buffers have available data */
int BuffersWritten(void) {
return(SDL_SemValue(ring->readwait));
}
/* Reserve a buffer for writing in the ring */
Uint8 *NextWriteBuffer( void );
/* Release a buffer, written to in the ring */
void WriteDone( Uint32 len, double timestamp=-1 );
/* Reserve a buffer for reading in the ring */
Uint32 NextReadBuffer( Uint8** buffer );
/* Read the timestamp of the current buffer */
double ReadTimeStamp(void);
/* Release a buffer having read some of it */
void ReadSome( Uint32 used );
/* Release a buffer having read all of it */
void ReadDone( void );
protected:
MPEG_ring *ring; /* Converted from C code, an alias for 'this' */
/* read only */
Uint32 bufSize;
/* private */
Uint8 *begin;
Uint8 *end;
double *timestamps;
double *timestamp_read;
double *timestamp_write;
Uint8 *read;
Uint8 *write;
/* For read/write synchronization */
int active;
SDL_semaphore *readwait;
SDL_semaphore *writewait;
};
#endif /* _MPEGRING_H */