update new e2 subtitle/audio track api in service-type plugins
[enigma2-plugins.git] / vlcplayer / src / servicets / servicets.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 __servicets_h
11 #define __servicets_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 class eStaticServiceTSInfo;
19
20 class eServiceFactoryTS: public iServiceHandler
21 {
22 DECLARE_REF(eServiceFactoryTS);
23 public:
24         eServiceFactoryTS();
25         virtual ~eServiceFactoryTS();
26         enum { id = 0x1002 };
27
28         // iServiceHandler
29         RESULT play(const eServiceReference &, ePtr<iPlayableService> &ptr);
30         RESULT record(const eServiceReference &, ePtr<iRecordableService> &ptr);
31         RESULT list(const eServiceReference &, ePtr<iListableService> &ptr);
32         RESULT info(const eServiceReference &, ePtr<iStaticServiceInformation> &ptr);
33         RESULT offlineOperations(const eServiceReference &, ePtr<iServiceOfflineOperations> &ptr);
34 };
35
36 class TSAudioInfo {
37 DECLARE_REF(TSAudioInfo);
38 public:
39         struct StreamInfo {
40                 int pid;
41                 int type;
42                 std::string language; /* iso639 */
43                 std::string description;
44         };
45         std::vector<StreamInfo> audioStreams;
46         void addAudio(int pid, std::string lang, std::string desc, int type);
47 };
48
49
50 class eStreamThread;
51 class eServiceTS: public iPlayableService, public iPauseableService,
52         public iServiceInformation, public iSeekableService,
53         public iAudioTrackSelection, public iAudioChannelSelection, public Object
54 {
55 DECLARE_REF(eServiceTS);
56 public:
57         virtual ~eServiceTS();
58
59         // iPlayableService
60         RESULT connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection);
61         RESULT start();
62         RESULT stop();
63         RESULT pause(ePtr<iPauseableService> &ptr);
64         RESULT seek(ePtr<iSeekableService> &ptr);
65         RESULT info(ePtr<iServiceInformation>&);
66
67         // not implemented
68         RESULT setTarget(int target) { return -1; };
69         RESULT setSlowMotion(int ratio) { return -1; };
70         RESULT setFastForward(int ratio) { return -1; };
71         RESULT audioChannel(ePtr<iAudioChannelSelection> &ptr) { ptr = this; return 0; };
72         RESULT audioTracks(ePtr<iAudioTrackSelection> &ptr) { ptr = this; return 0; };
73         RESULT frontendInfo(ePtr<iFrontendInformation> &ptr) { ptr = 0; return -1; };
74         RESULT subServices(ePtr<iSubserviceList> &ptr) { ptr = 0; return -1; };
75         RESULT timeshift(ePtr<iTimeshiftService> &ptr) { ptr = 0; return -1; };
76         RESULT cueSheet(ePtr<iCueSheet> &ptr) { ptr = 0; return -1; };
77         RESULT subtitle(ePtr<iSubtitleTrackSelection> &ptr) { ptr = 0; return -1; };
78         RESULT audioDelay(ePtr<iAudioDelay> &ptr) { ptr = 0; return -1; };
79         RESULT rdsDecoder(ePtr<iRdsDecoder> &ptr) { ptr = 0; return -1; };
80         RESULT stream(ePtr<iStreamableService> &ptr) { ptr = 0; return -1; };
81         RESULT streamed(ePtr<iStreamedService> &ptr) { ptr = 0; return -1; };
82         RESULT keys(ePtr<iServiceKeys> &ptr) { ptr = 0; return -1; };
83
84         // iPausableService
85         RESULT pause();
86         RESULT unpause();
87
88         // iSeekableService
89         RESULT getLength(pts_t &SWIG_OUTPUT);
90         RESULT seekTo(pts_t to);
91         RESULT seekRelative(int direction, pts_t to);
92         RESULT getPlayPosition(pts_t &SWIG_OUTPUT);
93         RESULT setTrickmode(int trick);
94         RESULT isCurrentlySeekable();
95
96         // iServiceInformation
97         RESULT getName(std::string &name);
98         int getInfo(int w);
99         std::string getInfoString(int w);
100
101         // iAudioTrackSelection
102         int getNumberOfTracks();
103         RESULT selectTrack(unsigned int i);
104         SWIG_VOID(RESULT) getTrackInfo(struct iAudioTrackInfo &, unsigned int n);
105         int getCurrentTrack();
106
107         // iAudioChannelSelection
108         int getCurrentChannel() { return iAudioChannelSelection::STEREO; }
109         RESULT selectChannel(int i) { return 0; };
110
111 private:
112         friend class eServiceFactoryTS;
113         std::string m_filename;
114         int m_vpid, m_apid;
115         int m_destfd;
116         ePtr<iDVBDemux> m_decodedemux;
117         ePtr<iTSMPEGDecoder> m_decoder;
118         ePtr<eStreamThread> m_streamthread;
119         ePtr<TSAudioInfo> m_audioInfo;
120         eUsePtr<iDVBPVRChannel> m_channel;
121
122         eServiceTS(const eServiceReference &url);
123         int openHttpConnection(std::string url);
124
125         Signal2<void,iPlayableService*,int> m_event;
126         eFixedMessagePump<int> m_pump;
127         void recv_event(int evt);
128         void setAudioPid(int pid, int type);
129 };
130
131 class eStreamThread: public eThread, public Object {
132 DECLARE_REF(eStreamThread);
133 public:
134         eStreamThread();
135         virtual ~eStreamThread();
136         void start(int srcfd, int destfd);
137         void stop();
138         bool running() { return m_running; }
139         bool stopping() { return m_stop || !m_running; }
140
141         virtual void thread();
142         virtual void thread_finished();
143
144         RESULT getAudioInfo(ePtr<TSAudioInfo> &ptr);
145
146         enum { evtEOS, evtSOS, evtReadError, evtWriteError, evtUser, evtStreamInfo };
147         Signal1<void,int> m_event;
148 private:
149         bool m_stop;
150         bool m_running;
151         int m_srcfd, m_destfd;
152         ePtr<TSAudioInfo> m_audioInfo;
153         eFixedMessagePump<int> m_messagepump;
154         void recvEvent(const int &evt);
155         bool scanAudioInfo(unsigned char buf[], int len);
156         std::string getDescriptor(unsigned char buf[], int buflen, int type);
157 };
158
159 #endif
160
161