summaryrefslogtreecommitdiff
path: root/ext/mplex/vector.hh
blob: 9a4f0413504b0a60c57ba2a320827d95a8907681 (plain)
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
#ifndef __AUSTREAM_H__
#define __AUSTREAM_H__

#include <config.h>
#include <deque>
#include "mjpeg_logging.h"
#include "aunit.hh"

class AUStream
{
public:
  AUStream ();

  void init (Aunit * rec);

  void append (Aunit & rec)
  {
    if (size == BUF_SIZE)
      mjpeg_error_exit1 ("INTERNAL ERROR: AU buffer overflow");
    *buf[cur_wr] = rec;
    ++size;
    ++cur_wr;
    cur_wr = cur_wr >= BUF_SIZE ? 0 : cur_wr;
  }

  inline Aunit *next ()
  {
    if (size == 0) {
      return 0;
    } else {
      Aunit *ret;

      ret = buf[cur_rd];
      ++cur_rd;
      ++totalctr;
      --size;
      cur_rd = cur_rd >= BUF_SIZE ? 0 : cur_rd;
      return ret;
    }
  }

  inline Aunit *lookahead ()
  {
    return size == 0 ? 0 : buf[cur_rd];
  }

  inline Aunit *last ()
  {
    int i = cur_wr - 1 < 0 ? BUF_SIZE - 1 : cur_wr - 1;

    return buf[i];
  }

  static const unsigned int BUF_SIZE = 128;

  inline unsigned int current ()
  {
    return totalctr;
  }
//private:
  unsigned int cur_rd;
  unsigned int cur_wr;
  unsigned int totalctr;
  unsigned int size;
  Aunit **buf;
};




#endif // __AUSTREAM_H__