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
12 class eStaticServiceMP3Info;
13
14 class eSubtitleWidget;
15
16 class eServiceFactoryMP3: public iServiceHandler
17 {
18         DECLARE_REF(eServiceFactoryMP3);
19 public:
20         eServiceFactoryMP3();
21         virtual ~eServiceFactoryMP3();
22         enum { id = 0x1001 };
23
24                 // iServiceHandler
25         RESULT play(const eServiceReference &, ePtr<iPlayableService> &ptr);
26         RESULT record(const eServiceReference &, ePtr<iRecordableService> &ptr);
27         RESULT list(const eServiceReference &, ePtr<iListableService> &ptr);
28         RESULT info(const eServiceReference &, ePtr<iStaticServiceInformation> &ptr);
29         RESULT offlineOperations(const eServiceReference &, ePtr<iServiceOfflineOperations> &ptr);
30 private:
31         ePtr<eStaticServiceMP3Info> m_service_info;
32 };
33
34 class eStaticServiceMP3Info: public iStaticServiceInformation
35 {
36         DECLARE_REF(eStaticServiceMP3Info);
37         friend class eServiceFactoryMP3;
38         eStaticServiceMP3Info();
39 public:
40         RESULT getName(const eServiceReference &ref, std::string &name);
41         int getLength(const eServiceReference &ref);
42 };
43
44 typedef struct _GstElement GstElement;
45
46 typedef enum { atUnknown, atMPEG, atMP3, atAC3, atDTS, atAAC, atPCM, atOGG, atFLAC } audiotype_t;
47 typedef enum { stPlainText, stSSA, stSRT } subtype_t;
48 typedef enum { ctNone, ctMPEGTS, ctMPEGPS, ctMKV, ctAVI, ctMP4, ctVCD, ctCDA } containertype_t;
49
50 class eServiceMP3: public iPlayableService, public iPauseableService, 
51         public iServiceInformation, public iSeekableService, public iAudioTrackSelection, public iAudioChannelSelection, public iSubtitleOutput, public Object
52 {
53         DECLARE_REF(eServiceMP3);
54 public:
55         virtual ~eServiceMP3();
56
57                 // iPlayableService
58         RESULT connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection);
59         RESULT start();
60         RESULT stop();
61         RESULT setTarget(int target);
62         
63         RESULT pause(ePtr<iPauseableService> &ptr);
64         RESULT setSlowMotion(int ratio);
65         RESULT setFastForward(int ratio);
66
67         RESULT seek(ePtr<iSeekableService> &ptr);
68         RESULT audioTracks(ePtr<iAudioTrackSelection> &ptr);
69         RESULT audioChannel(ePtr<iAudioChannelSelection> &ptr);
70         RESULT subtitle(ePtr<iSubtitleOutput> &ptr);
71
72                 // not implemented (yet)
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 audioDelay(ePtr<iAudioDelay> &ptr) { ptr = 0; return -1; }
78         RESULT rdsDecoder(ePtr<iRdsDecoder> &ptr) { ptr = 0; return -1; }
79         RESULT stream(ePtr<iStreamableService> &ptr) { ptr = 0; return -1; }
80         RESULT keys(ePtr<iServiceKeys> &ptr) { ptr = 0; return -1; }
81
82                 // iPausableService
83         RESULT pause();
84         RESULT unpause();
85         
86         RESULT info(ePtr<iServiceInformation>&);
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         RESULT getTrackInfo(struct iAudioTrackInfo &, unsigned int n);
105         int getCurrentTrack();
106
107                 // iAudioChannelSelection       
108         int getCurrentChannel();
109         RESULT selectChannel(int i);
110
111                 // iSubtitleOutput
112         RESULT enableSubtitles(eWidget *parent, SWIG_PYOBJECT(ePyObject) entry);
113         RESULT disableSubtitles(eWidget *parent);
114         PyObject *getSubtitleList();
115         PyObject *getCachedSubtitle();
116
117         struct audioStream
118         {
119                 GstPad* pad;
120                 audiotype_t type;
121                 std::string language_code; /* iso-639, if available. */
122                 audioStream()
123                         :pad(0), type(atUnknown)
124                 {
125                 }
126         };
127         struct subtitleStream
128         {
129                 GstPad* pad;
130                 subtype_t type;
131                 std::string language_code; /* iso-639, if available. */
132                 subtitleStream()
133                         :pad(0)
134                 {
135                 }
136         };
137         struct sourceStream
138         {
139                 audiotype_t audiotype;
140                 containertype_t containertype;
141                 bool is_video;
142                 bool is_streaming;
143                 sourceStream()
144                         :audiotype(atUnknown), containertype(ctNone), is_video(FALSE), is_streaming(FALSE)
145                 {
146                 }
147         };
148 private:
149         int m_currentAudioStream;
150         int m_currentSubtitleStream;
151         int selectAudioStream(int i);
152         std::vector<audioStream> m_audioStreams;
153         std::vector<subtitleStream> m_subtitleStreams;
154         eSubtitleWidget *m_subtitle_widget;
155         int m_currentTrickRatio;
156         ePtr<eTimer> m_seekTimeout;
157         void seekTimeoutCB();
158         friend class eServiceFactoryMP3;
159         std::string m_filename;
160         eServiceMP3(const char *filename);
161         Signal2<void,iPlayableService*,int> m_event;
162         enum
163         {
164                 stIdle, stRunning, stStopped,
165         };
166         int m_state;
167         GstElement *m_gst_pipeline;
168         GstTagList *m_stream_tags;
169         eFixedMessagePump<int> m_pump;
170         std::string m_error_message;
171
172         audiotype_t gstCheckAudioPad(GstStructure* structure);
173         void gstBusCall(GstBus *bus, GstMessage *msg);
174         static GstBusSyncReply gstBusSyncHandler(GstBus *bus, GstMessage *message, gpointer user_data);
175         static void gstCBpadAdded(GstElement *decodebin, GstPad *pad, gpointer data); /* for mpegdemux */
176         static void gstCBfilterPadAdded(GstElement *filter, GstPad *pad, gpointer user_data); /* for id3demux */
177         static void gstCBnewPad(GstElement *decodebin, GstPad *pad, gboolean last, gpointer data); /* for decodebin */
178         static void gstCBunknownType(GstElement *decodebin, GstPad *pad, GstCaps *l, gpointer data);
179         static void gstCBsubtitleAvail(GstElement *element, GstBuffer *buffer, GstPad *pad, gpointer user_data);
180         static void gstCBsubtitlePadEvent(GstPad *pad, GstEvent *event, gpointer user_data);
181         GstPad* gstCreateSubtitleSink(eServiceMP3* _this, subtype_t type);
182         void gstPoll(const int&);
183         gint m_aspect, m_width, m_height, m_framerate, m_progressive;
184 };
185 #endif
186
187 #endif