summaryrefslogtreecommitdiff
path: root/frontend_svr.h
blob: 27dad3dd5f30ac374622b5dc0e1706f67e7b2a5b (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
 * frontend_svr.h: server for remote frontends
 *
 * See the main source file 'xineliboutput.c' for copyright information and
 * how to reach the author.
 *
 * $Id: frontend_svr.h,v 1.18.2.1 2008-12-10 22:56:15 phintuka Exp $
 *
 */

#ifndef __XINELIB_FRONTEND_SVR_H
#define __XINELIB_FRONTEND_SVR_H


#include "frontend.h"

//----------------------------- cXinelibServer --------------------------------

#define MAXCLIENTS 10

class cBackgroundWriterI;
class cUdpScheduler;
class cStcFuture;
class cCmdFutures;
class cConnState;

#include "tools/cxsocket.h"

class cXinelibServer : public cXinelibThread 
{

  public:
    cXinelibServer(int listen_port);
    virtual ~cXinelibServer();

    // Thread control
    virtual void Stop(void);

  protected:
    virtual void Action(void);

  public:
    // Playback control
    virtual void TrickSpeed(int Speed);

    // Data transfer
    virtual int  Poll(cPoller &Poller, int TimeoutMs);
    virtual bool Flush(int TimeoutMs);
    virtual void Clear(void);
    virtual int  Play_PES(const uchar *buf, int len);
    virtual void OsdCmd(void *cmd);
    virtual int64_t GetSTC();
    virtual void SetHDMode(bool On);

    // Image grabbing
    virtual uchar *GrabImage(int &Size, bool Jpeg, int Quality, 
			     int SizeX, int SizeY);
    // Playback files
    virtual int  PlayFileCtrl(const char *Cmd, int TimeoutMs = -1);
    virtual bool EndOfStreamReached(void);

    // Configuration						  
    virtual bool Listen(int port);

protected:
    // Playback control
    virtual int  Xine_Control(const char *cmd);  
    virtual int  Xine_Control_Sync(const char *cmd);  

protected:

    // Handling of messages from client(s) 

    void Handle_Discovery_Broadcast(void);
    void Handle_ClientConnected(int fd);

    void Read_Control(int cli);
    void Handle_Control(int cli, const char *cmd);

    void Handle_Control_PIPE(int cli, const char *arg);
    void Handle_Control_RTP(int cli, const char *arg);
    void Handle_Control_UDP(int cli, const char *arg);
    void Handle_Control_DATA(int cli, const char *arg);
    void Handle_Control_KEY(int cli, const char *arg);
    void Handle_Control_UDP_RESEND(int cli, const char *arg);
    void Handle_Control_CONFIG(int cli);
    void Handle_Control_GRAB(int cli, const char *arg);
    void Handle_Control_CONTROL(int cli, const char *arg);
    void Handle_Control_HTTP(int cli, const char *arg);
    void Handle_Control_RTSP(int cli, const char *arg);

    void CloseDataConnection(int cli);
    void CloseConnection(int cli);

protected:

    // Data

    int  m_Port;
    int  m_ServerId;

    int  fd_listen;
    int  fd_discovery;

    cxSocket fd_control[MAXCLIENTS];
    int      fd_data[MAXCLIENTS];

    int  m_OsdTimeouts[MAXCLIENTS];
    char m_CtrlBuf[MAXCLIENTS][1024+1];
    int  m_CtrlBufPos[MAXCLIENTS];

    int  m_MasterCli;
    bool m_bUdp[MAXCLIENTS];
    int  m_ConnType[MAXCLIENTS];
    bool m_bMulticast[MAXCLIENTS];
    bool m_bConfigOk[MAXCLIENTS];
    int  m_iMulticastMask; // bit [cli] is 1 or 0. 1 == multicast in use.
    int  m_iUdpFlowMask;   // bit [cli] is 1 or 0. 1 == buffer full.

    cString m_PipesDir;

    cBackgroundWriterI *m_Writer[MAXCLIENTS]; // buffered output (pipe/tcp/http)
    cConnState        *m_State[MAXCLIENTS];  // connection state (http/rtsp)
    cUdpScheduler     *m_Scheduler;
    bool               m_Master;
    cStcFuture        *m_StcFuture;
    cCmdFutures       *m_Futures;

    int  m_Token;
    int  AllocToken(void);
    bool HasClients(void);
};

#endif // __XINELIB_FRONTEND_SVR_H