summaryrefslogtreecommitdiff
path: root/src/vdr-plugin/buffer.h
blob: 0a5ee5ca009f1e1327d1a3cb39b4b1d328f3546e (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
/*
 * buffer.h: Web video plugin for the Video Disk Recorder
 *
 * See the README file for copyright information and how to reach the author.
 *
 * $Id$
 */

#ifndef __WEBVIDEO_BUFFER_H
#define __WEBVIDEO_BUFFER_H

#include <unistd.h>

// --- cMemoryBuffer -------------------------------------------------------

// FIFO character buffer.

class cMemoryBuffer {
private:
  char *buf;
  size_t offset;
  size_t len;
  size_t capacity;
protected:
  size_t Free() { return capacity-len-offset; }
  virtual void Realloc(size_t newsize);
public:
  cMemoryBuffer(size_t prealloc = 10*1024);
  virtual ~cMemoryBuffer();

  // Put data into the end of the buffer
  virtual ssize_t Put(const char *data, size_t length);
  // Put data from a file descriptor fd to the buffer
  virtual ssize_t PutFromFile(int fd, size_t length);
  // The pointer to the beginning of the buffer. Only valid until the
  // next Put() or PutFromFile().
  virtual char *Get() { return &buf[offset]; }
  // Remove first n bytes from the buffer.
  void Pop(size_t n);
  // Returns the current length of the buffer
  virtual size_t Length() { return len; }
};

#endif // __WEBVIDEO_BUFFER_H