~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to mpeglib/lib/input/simpleRingBuffer.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  a thread safe ring buffer without dependencies
 
3
  Copyright (C) 1999  Martin Vogt
 
4
 
 
5
  This program is free software; you can redistribute it and/or modify
 
6
  it under the terms of the GNU Library General Public License as published by
 
7
  the Free Software Foundation.
 
8
 
 
9
  For more information look at the file COPYRIGHT in this package
 
10
 
 
11
 */
 
12
 
 
13
 
 
14
 
 
15
 
 
16
#ifndef _SIMPLERINGBUFFER_H
 
17
#define _SIMPLERINGBUFFER_H
 
18
 
 
19
#include "../util/abstract/abs_thread.h"
 
20
 
 
21
#include <iostream.h>
 
22
 
 
23
extern "C" {
 
24
  #include <stdio.h>
 
25
           }
 
26
 
 
27
 
 
28
 
 
29
 
 
30
 
 
31
/** 
 
32
   Note to parameter minLinBufSize in Constructor:
 
33
   <p>
 
34
   If the fillgrade is sufficient we can delivier at least
 
35
   this amount of bytes with one "fill"
 
36
   (If the fillgrade is not suffficient we can only deliever fillgrade)
 
37
   This values adresses the problem that a ring buffer cannot
 
38
   deliever linear memory the whole time(eg. if you read near the
 
39
   upper end)
 
40
   <p>
 
41
   If the requested Buffersize by the device is smaller than
 
42
   this number you can be sure that you get exactly
 
43
   your preferred buffersize. not more not less.(but
 
44
   only if the fillgrade allows this)
 
45
*/
 
46
 
 
47
 
 
48
 
 
49
 
 
50
class SimpleRingBuffer {
 
51
 
 
52
 
 
53
 public:
 
54
 
 
55
  SimpleRingBuffer(int ringBufferSize, int minLinBufferSize);
 
56
  virtual ~SimpleRingBuffer();
 
57
 
 
58
  // Writer thread can call these:
 
59
 
 
60
  int getWriteArea(char* &ptr,int &size);
 
61
  void forwardWritePtr(int bytes);
 
62
  int waitForSpace(int minSpace);
 
63
  void exitWaitForSpace();
 
64
  void setCanWaitForSpace(int lCanWaitForSpace);
 
65
  
 
66
  
 
67
  // Reader thread these:
 
68
 
 
69
  void forwardReadPtr(int bytes);
 
70
  int getReadArea(char* &ptr,int &size);
 
71
  int waitForData(int minData);
 
72
  void exitWaitForData();
 
73
  void setCanWaitForData(int lCanWaitForData);
 
74
  int getCanWaitForData();
 
75
 
 
76
 
 
77
  // and the lockPos
 
78
  void forwardLockPtr(int bytes);
 
79
 
 
80
 
 
81
  // both:
 
82
 
 
83
  int getFillgrade();       // return how much buffer between reader/writer
 
84
  void emptyBuffer();    // frees the space between them
 
85
  int getFreeRead();
 
86
  int getFreeWrite();
 
87
 
 
88
  int getSize();
 
89
  int getReadBytes();
 
90
  int getWriteBytes();
 
91
 
 
92
  // make sure that no one calls getReadArea/getWriteArea
 
93
  void resizeBuffer(int changeSize);
 
94
 private:
 
95
  void updateCanWrite();
 
96
  void updateCanRead();
 
97
 
 
98
  int size;
 
99
  
 
100
  int lockgrade;
 
101
  int fillgrade;
 
102
  
 
103
  char* readPos;
 
104
  char* writePos;
 
105
  char* lockPos;
 
106
 
 
107
  char* startPos;
 
108
 
 
109
  char* lastPos;
 
110
  char* eofPos;
 
111
  int canWrite;
 
112
  int canRead;
 
113
 
 
114
  int waitMinData;
 
115
  int waitMinSpace;
 
116
 
 
117
  abs_thread_mutex_t mut;
 
118
  abs_thread_cond_t dataCond;
 
119
  abs_thread_cond_t spaceCond;
 
120
  
 
121
  int insertBlock;
 
122
  int readBlock;
 
123
  int linAvail;
 
124
 
 
125
  char* minLinBuf;
 
126
  int minLinBufSize;
 
127
  int lWaitForData;
 
128
  int lWaitForSpace;
 
129
 
 
130
  // statistic purpose:
 
131
  int readBytes;
 
132
  int writeBytes;
 
133
 
 
134
  int lCanWaitForSpace;
 
135
  int lCanWaitForData;
 
136
  int instance;
 
137
};
 
138
 
 
139
#endif
 
140
 
 
141
  
 
142