fix convertDVBUTF8 default table (0 is now iso6397 but we want iso8859-1)
[enigma2.git] / lib / service / servicemp3.h
1 #ifndef __servicemp3_h
2 #define __servicemp3_h
3
4 #ifdef HAVE_GSTREAMER
5 #include <lib/base/message.h>
6 #include <lib/service/iservice.h>
7 #include <lib/dvb/pmt.h>
8 #include <lib/dvb/subtitle.h>
9 #include <lib/dvb/teletext.h>
10 #include <gst/gst.h>
11 /* for subtitles */
12 #include <lib/gui/esubtitle.h>
13
14 class eStaticServiceMP3Info;
15
16 class eSubtitleWidget;
17
18 class eServiceFactoryMP3: public iServiceHandler
19 {
20         DECLARE_REF(eServiceFactoryMP3);
21 public:
22         eServiceFactoryMP3();
23         virtual ~eServiceFactoryMP3();
24         enum { id = 0x1001 };
25
26                 // iServiceHandler
27         RESULT play(const eServiceReference &, ePtr<iPlayableService> &ptr);
28         RESULT record(const eServiceReference &, ePtr<iRecordableService> &ptr);
29         RESULT list(const eServiceReference &, ePtr<iListableService> &ptr);
30         RESULT info(const eServiceReference &, ePtr<iStaticServiceInformation> &ptr);
31         RESULT offlineOperations(const eServiceReference &, ePtr<iServiceOfflineOperations> &ptr);
32 private:
33         ePtr<eStaticServiceMP3Info> m_service_info;
34 };
35
36 class eStaticServiceMP3Info: public iStaticServiceInformation
37 {
38         DECLARE_REF(eStaticServiceMP3Info);
39         friend class eServiceFactoryMP3;
40         eStaticServiceMP3Info();
41 public:
42         RESULT getName(const eServiceReference &ref, std::string &name);
43         int getLength(const eServiceReference &ref);
44 };
45
46 typedef struct _GstElement GstElement;
47
48 typedef enum { atUnknown, atMPEG, atMP3, atAC3, atDTS, atAAC, atPCM, atOGG, atFLAC } audiotype_t;
49 typedef enum { stPlainText, stSSA, stSRT } subtype_t;
50 typedef enum { ctNone, ctMPEGTS, ctMPEGPS, ctMKV, ctAVI, ctMP4, ctVCD, ctCDA } containertype_t;
51
52 class eServiceMP3: public iPlayableService, public iPauseableService, 
53         public iServiceInformation, public iSeekableService, public iAudioTrackSelection, public iAudioChannelSelection, public iSubtitleOutput, public iStreamedService, public Object
54 {
55         DECLARE_REF(eServiceMP3);
56 public:
57         virtual ~eServiceMP3();
58
59                 // iPlayableService
60         RESULT connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection);
61         RESULT start();
62         RESULT stop();
63         RESULT setTarget(int target);
64         
65         RESULT pause(ePtr<iPauseableService> &ptr);
66         RESULT setSlowMotion(int ratio);
67         RESULT setFastForward(int ratio);
68
69         RESULT seek(ePtr<iSeekableService> &ptr);
70         RESULT audioTracks(ePtr<iAudioTrackSelection> &ptr);
71         RESULT audioChannel(ePtr<iAudioChannelSelection> &ptr);
72         RESULT subtitle(ePtr<iSubtitleOutput> &ptr);
73
74                 // not implemented (yet)
75         RESULT frontendInfo(ePtr<iFrontendInformation> &ptr) { ptr = 0; return -1; }
76         RESULT subServices(ePtr<iSubserviceList> &ptr) { ptr = 0; return -1; }
77         RESULT timeshift(ePtr<iTimeshiftService> &ptr) { ptr = 0; return -1; }
78         RESULT cueSheet(ePtr<iCueSheet> &ptr) { ptr = 0; return -1; }
79         RESULT audioDelay(ePtr<iAudioDelay> &ptr) { ptr = 0; return -1; }
80         RESULT rdsDecoder(ePtr<iRdsDecoder> &ptr) { ptr = 0; return -1; }
81         RESULT keys(ePtr<iServiceKeys> &ptr) { ptr = 0; return -1; }
82         RESULT stream(ePtr<iStreamableService> &ptr) { ptr = 0; return -1; }
83
84                 // iPausableService
85         RESULT pause();
86         RESULT unpause();
87         
88         RESULT info(ePtr<iServiceInformation>&);
89         
90                 // iSeekableService
91         RESULT getLength(pts_t &SWIG_OUTPUT);
92         RESULT seekTo(pts_t to);
93         RESULT seekRelative(int direction, pts_t to);
94         RESULT getPlayPosition(pts_t &SWIG_OUTPUT);
95         RESULT setTrickmode(int trick);
96         RESULT isCurrentlySeekable();
97
98                 // iServiceInformation
99         RESULT getName(std::string &name);
100         int getInfo(int w);
101         std::string getInfoString(int w);
102         PyObject *getInfoObject(int w);
103
104                 // iAudioTrackSelection 
105         int getNumberOfTracks();
106         RESULT selectTrack(unsigned int i);
107         RESULT getTrackInfo(struct iAudioTrackInfo &, unsigned int n);
108         int getCurrentTrack();
109
110                 // iAudioChannelSelection       
111         int getCurrentChannel();
112         RESULT selectChannel(int i);
113
114                 // iSubtitleOutput
115         RESULT enableSubtitles(eWidget *parent, SWIG_PYOBJECT(ePyObject) entry);
116         RESULT disableSubtitles(eWidget *parent);
117         PyObject *getSubtitleList();
118         PyObject *getCachedSubtitle();
119
120                 // iStreamedService
121         RESULT streamed(ePtr<iStreamedService> &ptr);
122         PyObject *getBufferCharge();
123         int setBufferSize(int size);
124
125         struct audioStream
126         {
127                 GstPad* pad;
128                 audiotype_t type;
129                 std::string language_code; /* iso-639, if available. */
130                 std::string codec; /* clear text codec description */
131                 audioStream()
132                         :pad(0), type(atUnknown)
133                 {
134                 }
135         };
136         struct subtitleStream
137         {
138                 GstPad* pad;
139                 subtype_t type;
140                 std::string language_code; /* iso-639, if available. */
141                 subtitleStream()
142                         :pad(0)
143                 {
144                 }
145         };
146         struct sourceStream
147         {
148                 audiotype_t audiotype;
149                 containertype_t containertype;
150                 bool is_video;
151                 bool is_streaming;
152                 sourceStream()
153                         :audiotype(atUnknown), containertype(ctNone), is_video(FALSE), is_streaming(FALSE)
154                 {
155                 }
156         };
157         struct bufferInfo
158         {
159                 int bufferPercent;
160                 int avgInRate;
161                 int avgOutRate;
162                 long long bufferingLeft;
163                 bufferInfo()
164                         :bufferPercent(0), avgInRate(0), avgOutRate(0), bufferingLeft(-1)
165                 {
166                 }
167         };
168 private:
169         int m_currentAudioStream;
170         int m_currentSubtitleStream;
171         int selectAudioStream(int i);
172         std::vector<audioStream> m_audioStreams;
173         std::vector<subtitleStream> m_subtitleStreams;
174         eSubtitleWidget *m_subtitle_widget;
175         int m_currentTrickRatio;
176         ePtr<eTimer> m_seekTimeout;
177         void seekTimeoutCB();
178         friend class eServiceFactoryMP3;
179         eServiceReference m_ref;
180         int m_buffer_size;
181         bufferInfo m_bufferInfo;
182         eServiceMP3(eServiceReference ref);
183         Signal2<void,iPlayableService*,int> m_event;
184         enum
185         {
186                 stIdle, stRunning, stStopped,
187         };
188         int m_state;
189         GstElement *m_gst_playbin;
190         GstTagList *m_stream_tags;
191         eFixedMessagePump<int> m_pump;
192         std::string m_error_message;
193
194         audiotype_t gstCheckAudioPad(GstStructure* structure);
195         void gstBusCall(GstBus *bus, GstMessage *msg);
196         static GstBusSyncReply gstBusSyncHandler(GstBus *bus, GstMessage *message, gpointer user_data);
197         static void gstCBsubtitleAvail(GstElement *element, gpointer user_data);
198         GstPad* gstCreateSubtitleSink(eServiceMP3* _this, subtype_t type);
199         void gstPoll(const int&);
200
201         std::list<ePangoSubtitlePage> m_subtitle_pages;
202         ePtr<eTimer> m_subtitle_sync_timer;
203         void pushSubtitles();
204         void pullSubtitle();
205         int m_subs_to_pull;
206         eSingleLock m_subs_to_pull_lock;
207
208         gint m_aspect, m_width, m_height, m_framerate, m_progressive;
209         RESULT trickSeek(gdouble ratio);
210 };
211 #endif
212
213 #endif