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