Merge branch 'master' of git.opendreambox.org:/git/enigma2
[vuplus_dvbapp] / 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 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 stream(ePtr<iStreamableService> &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         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         struct audioStream
121         {
122                 GstPad* pad;
123                 audiotype_t type;
124                 std::string language_code; /* iso-639, if available. */
125                 std::string codec; /* clear text codec description */
126                 audioStream()
127                         :pad(0), type(atUnknown)
128                 {
129                 }
130         };
131         struct subtitleStream
132         {
133                 GstPad* pad;
134                 subtype_t type;
135                 std::string language_code; /* iso-639, if available. */
136                 subtitleStream()
137                         :pad(0)
138                 {
139                 }
140         };
141         struct sourceStream
142         {
143                 audiotype_t audiotype;
144                 containertype_t containertype;
145                 bool is_video;
146                 bool is_streaming;
147                 sourceStream()
148                         :audiotype(atUnknown), containertype(ctNone), is_video(FALSE), is_streaming(FALSE)
149                 {
150                 }
151         };
152 private:
153         int m_currentAudioStream;
154         int m_currentSubtitleStream;
155         int selectAudioStream(int i);
156         std::vector<audioStream> m_audioStreams;
157         std::vector<subtitleStream> m_subtitleStreams;
158         eSubtitleWidget *m_subtitle_widget;
159         int m_currentTrickRatio;
160         ePtr<eTimer> m_seekTimeout;
161         void seekTimeoutCB();
162         friend class eServiceFactoryMP3;
163         std::string m_filename;
164         std::string m_title;
165         eServiceMP3(const char *filename, const char *title);
166         Signal2<void,iPlayableService*,int> m_event;
167         enum
168         {
169                 stIdle, stRunning, stStopped,
170         };
171         int m_state;
172         GstElement *m_gst_playbin;
173         GstTagList *m_stream_tags;
174         eFixedMessagePump<int> m_pump;
175         std::string m_error_message;
176
177         audiotype_t gstCheckAudioPad(GstStructure* structure);
178         void gstBusCall(GstBus *bus, GstMessage *msg);
179         static GstBusSyncReply gstBusSyncHandler(GstBus *bus, GstMessage *message, gpointer user_data);
180         static void gstCBpadAdded(GstElement *decodebin, GstPad *pad, gpointer data); /* for mpegdemux */
181         static void gstCBfilterPadAdded(GstElement *filter, GstPad *pad, gpointer user_data); /* for id3demux */
182         static void gstCBnewPad(GstElement *decodebin, GstPad *pad, gboolean last, gpointer data); /* for decodebin */
183         static void gstCBunknownType(GstElement *decodebin, GstPad *pad, GstCaps *l, gpointer data);
184         static void gstCBsubtitleAvail(GstElement *element, gpointer user_data);
185         static void gstCBsubtitlePadEvent(GstPad *pad, GstEvent *event, gpointer user_data);
186         GstPad* gstCreateSubtitleSink(eServiceMP3* _this, subtype_t type);
187         void gstPoll(const int&);
188
189         std::list<ePangoSubtitlePage> m_subtitle_pages;
190         ePtr<eTimer> m_subtitle_sync_timer;
191         void pushSubtitles();
192
193         gint m_aspect, m_width, m_height, m_framerate, m_progressive;
194         RESULT trickSeek(gdouble ratio);
195 };
196 #endif
197
198 #endif