ea06429917e2681856fea5b6a73806c0a4d4ff70
[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
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 } audiotype_t;
47 typedef enum { stPlainText, stSSA, stSRT } subtype_t;
48
49 class eServiceMP3: public iPlayableService, public iPauseableService, 
50         public iServiceInformation, public iSeekableService, public iAudioTrackSelection, public iAudioChannelSelection, public iSubtitleOutput, public Object
51 {
52         DECLARE_REF(eServiceMP3);
53 public:
54         virtual ~eServiceMP3();
55
56                 // iPlayableService
57         RESULT connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection);
58         RESULT start();
59         RESULT stop();
60         RESULT setTarget(int target);
61         
62         RESULT pause(ePtr<iPauseableService> &ptr);
63         RESULT setSlowMotion(int ratio);
64         RESULT setFastForward(int ratio);
65
66         RESULT seek(ePtr<iSeekableService> &ptr);
67         RESULT audioTracks(ePtr<iAudioTrackSelection> &ptr);
68         RESULT audioChannel(ePtr<iAudioChannelSelection> &ptr);
69         RESULT subtitle(ePtr<iSubtitleOutput> &ptr);
70
71                 // not implemented (yet)
72         RESULT frontendInfo(ePtr<iFrontendInformation> &ptr) { ptr = 0; return -1; }
73         RESULT subServices(ePtr<iSubserviceList> &ptr) { ptr = 0; return -1; }
74         RESULT timeshift(ePtr<iTimeshiftService> &ptr) { ptr = 0; return -1; }
75         RESULT cueSheet(ePtr<iCueSheet> &ptr) { ptr = 0; return -1; }
76         RESULT audioDelay(ePtr<iAudioDelay> &ptr) { ptr = 0; return -1; }
77         RESULT rdsDecoder(ePtr<iRdsDecoder> &ptr) { ptr = 0; return -1; }
78         RESULT stream(ePtr<iStreamableService> &ptr) { ptr = 0; return -1; }
79         RESULT keys(ePtr<iServiceKeys> &ptr) { ptr = 0; return -1; }
80
81                 // iPausableService
82         RESULT pause();
83         RESULT unpause();
84         
85         RESULT info(ePtr<iServiceInformation>&);
86         
87                 // iSeekableService
88         RESULT getLength(pts_t &SWIG_OUTPUT);
89         RESULT seekTo(pts_t to);
90         RESULT seekRelative(int direction, pts_t to);
91         RESULT getPlayPosition(pts_t &SWIG_OUTPUT);
92         RESULT setTrickmode(int trick);
93         RESULT isCurrentlySeekable();
94
95                 // iServiceInformation
96         RESULT getName(std::string &name);
97         int getInfo(int w);
98         std::string getInfoString(int w);
99
100                 // iAudioTrackSelection 
101         int getNumberOfTracks();
102         RESULT selectTrack(unsigned int i);
103         RESULT getTrackInfo(struct iAudioTrackInfo &, unsigned int n);
104         int getCurrentTrack();
105
106                 // iAudioChannelSelection       
107         int getCurrentChannel();
108         RESULT selectChannel(int i);
109
110                 // iSubtitleOutput
111         RESULT enableSubtitles(eWidget *parent, SWIG_PYOBJECT(ePyObject) entry);
112         RESULT disableSubtitles(eWidget *parent);
113         PyObject *getSubtitleList();
114         PyObject *getCachedSubtitle();
115
116         struct audioStream
117         {
118                 GstPad* pad;
119                 audiotype_t type;
120                 std::string language_code; /* iso-639, if available. */
121                 audioStream()
122                         :pad(0), type(atUnknown)
123                 {
124                 }
125         };
126         struct subtitleStream
127         {
128                 GstPad* pad;
129                 subtype_t type;
130                 std::string language_code; /* iso-639, if available. */
131                 subtitleStream()
132                         :pad(0)
133                 {
134                 }
135         };
136 private:
137         int m_currentAudioStream;
138         int m_currentSubtitleStream;
139         int selectAudioStream(int i);
140         std::vector<audioStream> m_audioStreams;
141         std::vector<subtitleStream> m_subtitleStreams;
142         eSubtitleWidget *m_subtitle_widget;
143         int m_currentTrickRatio;
144         eTimer m_seekTimeout;
145         void seekTimeoutCB();
146         friend class eServiceFactoryMP3;
147         std::string m_filename;
148         eServiceMP3(const char *filename);
149         Signal2<void,iPlayableService*,int> m_event;
150         enum
151         {
152                 stIdle, stRunning, stStopped,
153         };
154         int m_state;
155         GstElement *m_gst_pipeline;
156         GstTagList *m_stream_tags;
157         eFixedMessagePump<int> m_pump;
158         std::string m_error_message;
159
160         audiotype_t gstCheckAudioPad(GstStructure* structure);
161         void gstBusCall(GstBus *bus, GstMessage *msg);
162         static GstBusSyncReply gstBusSyncHandler(GstBus *bus, GstMessage *message, gpointer user_data);
163         static void gstCBpadAdded(GstElement *decodebin, GstPad *pad, gpointer data); /* for mpegdemux */
164         static void gstCBfilterPadAdded(GstElement *filter, GstPad *pad, gpointer user_data); /* for id3demux */
165         static void gstCBnewPad(GstElement *decodebin, GstPad *pad, gboolean last, gpointer data); /* for decodebin */
166         static void gstCBunknownType(GstElement *decodebin, GstPad *pad, GstCaps *l, gpointer data);
167         static void gstCBsubtitleAvail(GstElement *element, GstBuffer *buffer, GstPad *pad, gpointer user_data);
168         static void gstCBsubtitlePadEvent(GstPad *pad, GstEvent *event, gpointer user_data);
169         GstPad* gstCreateSubtitleSink(eServiceMP3* _this, subtype_t type);
170         void gstPoll(const int&);
171 };
172 #endif
173
174 #endif