File: MPEGring.h

package info (click to toggle)
smpeg 0.3.3-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 2,628 kB
  • ctags: 1,202
  • sloc: cpp: 12,775; sh: 8,115; ansic: 1,317; makefile: 139
file content (93 lines) | stat: -rw-r--r-- 2,616 bytes parent folder | download
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
/*
    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 */

#ifndef _MPEGRING_H
#define _MPEGRING_H

#include "SDL_types.h"
#include "SDL_thread.h"
#include "SDL_mutex.h"

class MPEG_ring {
public:
    /* Create a ring with 'count' buffers, each 'size' bytes long */
    MPEG_ring(Uint32 size, int count = 32);

    /* 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(usedCount);
    }

    /* Reserve a buffer for writing in the ring */
    Uint8 *NextWriteBuffer( void );

    /* Release a buffer, written to in the ring */
    void WriteDone( Uint32 len );

    /* Reserve a buffer for reading in the ring */
    Uint32 NextReadBuffer( Uint8** buffer );

    /* 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 */
    int bufCount;
    int usedCount;

    Uint8 *begin;
    Uint8 *end;

    Uint8 *read;
    Uint8 *write;

    /* For read/write synchronization */
    int active;
    int reader_active;
    SDL_mutex* readwait;
    int read_waiting;
    SDL_mutex* writewait;
    int write_waiting;
    int writer_active;
};

#endif /* _MPEGRING_H */