summaryrefslogtreecommitdiff
path: root/tools/backgroundwriter.h
blob: d49ee1334c4be6e125338c46096d479364b1992f (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
/*
 * backgroundwriter.h: Buffered socket/file writing thread
 *
 * See the main source file 'xineliboutput.c' for copyright information and
 * how to reach the author.
 *
 * $Id: backgroundwriter.h,v 1.2 2006-06-11 10:19:50 phintuka Exp $
 *
 */

#ifndef __BACKGROUNDWRITER_H
#define __BACKGROUNDWRITER_H

#include <stdint.h>

#include <vdr/thread.h>
#include <vdr/ringbuffer.h>


class cBackgroundWriter : public cThread {

  private:
    cRingBufferLinear m_RingBuffer;

    volatile bool m_Active;
    int m_fd;

    uint64_t m_PutPos;
    uint64_t m_DiscardStart;
    uint64_t m_DiscardEnd;

    int m_BufferOverflows;

  protected:
    virtual void Action(void);

    int Put(const uchar *Header, int HeaderCount, 
	    const uchar *Data,   int DataCount);

  public:
    cBackgroundWriter(int fd, int Size = KILOBYTE(512));
    virtual ~cBackgroundWriter() ;

    // Return largest possible Put size
    int Free(void);

    // Add PES frame to buffer
    //
    // Return value:
    // Success:     Count   (all bytes pushed to queue)
    // Error:       0       (write error ; socket disconnected)
    // Buffer full: -Count  (no bytes will be pushed to queue)
    //
    int Put(uint64_t StreamPos, const uchar *Data, int DataCount);

    // Drop all data (only complete frames) from buffer
    void Clear(void);

    //bool Poll(int TimeoutMs);
    bool Flush(int TimeoutMs);
};


#endif