define iStreamedService pointer
[enigma2-plugins.git] / partnerbox / src / servicewebts / servicewebts.h
1 /*******************************************************************************
2  VLC Player Plugin by A. Lätsch 2007
3
4  This is free software; you can redistribute it and/or modify it under
5  the terms of the GNU General Public License as published by the Free
6  Software Foundation; either version 2, or (at your option) any later
7  version.
8 ********************************************************************************/
9
10 #ifndef __servicewebts_h
11 #define __servicewebts_h
12
13 #include <lib/base/ioprio.h>
14 #include <lib/base/message.h>
15 #include <lib/service/iservice.h>
16 #include <lib/dvb/dvb.h>
17
18
19
20
21
22 #define PRIVATE_STREAM1  0xBD
23 #define PRIVATE_STREAM2  0xBF
24
25 #define AUDIO_STREAM_S   0xC0
26 #define AUDIO_STREAM_E   0xDF
27
28 #define VIDEO_STREAM_S   0xE0
29 #define VIDEO_STREAM_E   0xEF
30
31 #define TS_SIZE          188
32 #define IN_SIZE          65424
33
34 #define PID_MASK_HI      0x1F
35
36
37
38
39
40
41
42
43 class eStaticServiceWebTSInfo;
44
45 class eServiceFactoryWebTS: public iServiceHandler
46 {
47 DECLARE_REF(eServiceFactoryWebTS);
48 public:
49         eServiceFactoryWebTS();
50         virtual ~eServiceFactoryWebTS();
51         enum { id = 0x1012 };
52
53         // iServiceHandler
54         RESULT play(const eServiceReference &, ePtr<iPlayableService> &ptr);
55         RESULT record(const eServiceReference &, ePtr<iRecordableService> &ptr);
56         RESULT list(const eServiceReference &, ePtr<iListableService> &ptr);
57         RESULT info(const eServiceReference &, ePtr<iStaticServiceInformation> &ptr);
58         RESULT offlineOperations(const eServiceReference &, ePtr<iServiceOfflineOperations> &ptr);
59 };
60
61 class TSAudioInfoWeb {
62 DECLARE_REF(TSAudioInfoWeb);
63 public:
64         struct StreamInfo {
65                 int pid;
66                 int type;
67                 std::string language; /* iso639 */
68                 std::string description;
69         };
70         std::vector<StreamInfo> audioStreams;
71         void addAudio(int pid, std::string lang, std::string desc, int type);
72 };
73
74
75 class eStreamThreadWeb;
76 class eServiceWebTS: public iPlayableService, public iPauseableService,
77         public iServiceInformation, public iSeekableService,
78         public iAudioTrackSelection, public iAudioChannelSelection, public Object
79 {
80 DECLARE_REF(eServiceWebTS);
81 public:
82         virtual ~eServiceWebTS();
83
84         // iPlayableService
85         RESULT connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection);
86         RESULT start();
87         RESULT stop();
88         RESULT pause(ePtr<iPauseableService> &ptr);
89         RESULT seek(ePtr<iSeekableService> &ptr);
90         RESULT info(ePtr<iServiceInformation>&);
91
92         // not implemented
93         RESULT setTarget(int target) { return -1; };
94         RESULT setSlowMotion(int ratio) { return -1; };
95         RESULT setFastForward(int ratio) { return -1; };
96         RESULT audioChannel(ePtr<iAudioChannelSelection> &ptr) { ptr = this; return 0; };
97         RESULT audioTracks(ePtr<iAudioTrackSelection> &ptr) { ptr = this; return 0; };
98         RESULT frontendInfo(ePtr<iFrontendInformation> &ptr) { ptr = 0; return -1; };
99         RESULT subServices(ePtr<iSubserviceList> &ptr) { ptr = 0; return -1; };
100         RESULT timeshift(ePtr<iTimeshiftService> &ptr) { ptr = 0; return -1; };
101         RESULT cueSheet(ePtr<iCueSheet> &ptr) { ptr = 0; return -1; };
102         RESULT subtitle(ePtr<iSubtitleOutput> &ptr) { ptr = 0; return -1; };
103         RESULT audioDelay(ePtr<iAudioDelay> &ptr) { ptr = 0; return -1; };
104         RESULT rdsDecoder(ePtr<iRdsDecoder> &ptr) { ptr = 0; return -1; };
105         RESULT stream(ePtr<iStreamableService> &ptr) { ptr = 0; return -1; };
106         RESULT streamed(ePtr<iStreamedService> &ptr) { ptr = 0; return -1; };
107         RESULT keys(ePtr<iServiceKeys> &ptr) { ptr = 0; return -1; };
108
109         // iPausableService
110         RESULT pause();
111         RESULT unpause();
112
113
114         // iSeekableService
115         RESULT getLength(pts_t &SWIG_OUTPUT);
116         RESULT seekTo(pts_t to);
117         RESULT seekRelative(int direction, pts_t to);
118         RESULT getPlayPosition(pts_t &SWIG_OUTPUT);
119         RESULT setTrickmode(int trick);
120         RESULT isCurrentlySeekable();
121
122         // iServiceInformation
123         RESULT getName(std::string &name);
124         int getInfo(int w);
125         std::string getInfoString(int w);
126
127         // iAudioTrackSelection
128         int getNumberOfTracks();
129         RESULT selectTrack(unsigned int i);
130         SWIG_VOID(RESULT) getTrackInfo(struct iAudioTrackInfo &, unsigned int n);
131         int getCurrentTrack();
132
133         // iAudioChannelSelection
134         int getCurrentChannel() { return iAudioChannelSelection_ENUMS::STEREO; };
135         RESULT selectChannel(int i) { return 0; };
136
137 private:
138         friend class eServiceFactoryWebTS;
139         std::string m_filename;
140         int m_vpid, m_apid;
141         int m_srcfd, m_destfd;
142         ePtr<iDVBDemux> m_decodedemux;
143         ePtr<iTSMPEGDecoder> m_decoder;
144         ePtr<eStreamThreadWeb> m_streamthread;
145         ePtr<TSAudioInfoWeb> m_audioInfo;
146
147         eServiceWebTS(const eServiceReference &url);
148         int openHttpConnection(std::string url);
149
150         Signal2<void,iPlayableService*,int> m_event;
151         enum
152         {
153                 stIdle, stRunning, stStopped
154         };
155         int m_state;
156         eFixedMessagePump<int> m_pump;
157         void recv_event(int evt);
158         void setAudioPid(int pid, int type);
159 };
160
161 class eStreamThreadWeb: public eThread, public Object {
162 DECLARE_REF(eStreamThreadWeb);
163 public:
164         eStreamThreadWeb();
165         virtual ~eStreamThreadWeb();
166         void start(int srcfd, int destfd);
167         void stop();
168
169         virtual void thread();
170         virtual void thread_finished();
171
172         RESULT getAudioInfo(ePtr<TSAudioInfoWeb> &ptr);
173
174         enum { evtEOS, evtSOS, evtReadError, evtWriteError, evtUser, evtStreamInfo };
175         Signal1<void,int> m_event;
176 private:
177         bool m_stop;
178         int m_srcfd, m_destfd;
179         ePtr<TSAudioInfoWeb> m_audioInfo;
180         eFixedMessagePump<int> m_messagepump;
181         void recvEvent(const int &evt);
182         bool scanAudioInfo(unsigned char buf[], int len);
183         std::string getDescriptor(unsigned char buf[], int buflen, int type);
184 };
185
186 #endif
187