4 #include <lib/base/message.h>
5 #include <lib/service/iservice.h>
6 #include <lib/dvb/pmt.h>
7 #include <lib/dvb/subtitle.h>
8 #include <lib/dvb/teletext.h>
11 #include <lib/gui/esubtitle.h>
13 class eStaticServiceMP3Info;
15 class eServiceFactoryMP3: public iServiceHandler
17 DECLARE_REF(eServiceFactoryMP3);
20 virtual ~eServiceFactoryMP3();
24 RESULT play(const eServiceReference &, ePtr<iPlayableService> &ptr);
25 RESULT record(const eServiceReference &, ePtr<iRecordableService> &ptr);
26 RESULT list(const eServiceReference &, ePtr<iListableService> &ptr);
27 RESULT info(const eServiceReference &, ePtr<iStaticServiceInformation> &ptr);
28 RESULT offlineOperations(const eServiceReference &, ePtr<iServiceOfflineOperations> &ptr);
30 ePtr<eStaticServiceMP3Info> m_service_info;
33 class eStaticServiceMP3Info: public iStaticServiceInformation
35 DECLARE_REF(eStaticServiceMP3Info);
36 friend class eServiceFactoryMP3;
37 eStaticServiceMP3Info();
39 RESULT getName(const eServiceReference &ref, std::string &name);
40 int getLength(const eServiceReference &ref);
41 int getInfo(const eServiceReference &ref, int w);
42 int isPlayable(const eServiceReference &ref, const eServiceReference &ignore, bool simulate) { return 1; }
43 long long getFileSize(const eServiceReference &ref);
44 RESULT getEvent(const eServiceReference &ref, ePtr<eServiceEvent> &ptr, time_t start_time);
47 class eStreamBufferInfo: public iStreamBufferInfo
49 DECLARE_REF(eStreamBufferInfo);
57 eStreamBufferInfo(int percentage, int inputrate, int outputrate, int space, int size);
59 int getBufferPercentage() const;
60 int getAverageInputRate() const;
61 int getAverageOutputRate() const;
62 int getBufferSpace() const;
63 int getBufferSize() const;
66 class eServiceMP3InfoContainer: public iServiceInfoContainer
68 DECLARE_REF(eServiceMP3InfoContainer);
71 GstBuffer *bufferValue;
73 unsigned char *bufferData;
74 unsigned int bufferSize;
75 #if GST_VERSION_MAJOR >= 1
80 eServiceMP3InfoContainer();
81 ~eServiceMP3InfoContainer();
83 double getDouble(unsigned int index) const;
84 unsigned char *getBuffer(unsigned int &size) const;
86 void setDouble(double value);
87 void setBuffer(GstBuffer *buffer);
90 typedef struct _GstElement GstElement;
92 typedef enum { atUnknown, atMPEG, atMP3, atAC3, atDTS, atAAC, atPCM, atOGG, atFLAC, atWMA } audiotype_t;
93 typedef enum { stUnknown, stPlainText, stSSA, stASS, stSRT, stVOB, stPGS } subtype_t;
94 typedef enum { ctNone, ctMPEGTS, ctMPEGPS, ctMKV, ctAVI, ctMP4, ctVCD, ctCDA, ctASF, ctOGG } containertype_t;
96 class eServiceMP3: public iPlayableService, public iPauseableService,
97 public iServiceInformation, public iSeekableService, public iAudioTrackSelection, public iAudioChannelSelection,
98 public iSubtitleOutput, public iStreamedService, public iAudioDelay, public Object, public iCueSheet
100 DECLARE_REF(eServiceMP3);
102 virtual ~eServiceMP3();
105 RESULT connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection);
108 RESULT setTarget(int target);
110 RESULT pause(ePtr<iPauseableService> &ptr);
111 RESULT setSlowMotion(int ratio);
112 RESULT setFastForward(int ratio);
114 RESULT seek(ePtr<iSeekableService> &ptr);
115 RESULT audioTracks(ePtr<iAudioTrackSelection> &ptr);
116 RESULT audioChannel(ePtr<iAudioChannelSelection> &ptr);
117 RESULT subtitle(ePtr<iSubtitleOutput> &ptr);
118 RESULT audioDelay(ePtr<iAudioDelay> &ptr);
119 RESULT cueSheet(ePtr<iCueSheet> &ptr);
121 // not implemented (yet)
122 RESULT frontendInfo(ePtr<iFrontendInformation> &ptr) { ptr = 0; return -1; }
123 RESULT subServices(ePtr<iSubserviceList> &ptr) { ptr = 0; return -1; }
124 RESULT timeshift(ePtr<iTimeshiftService> &ptr) { ptr = 0; return -1; }
125 // RESULT cueSheet(ePtr<iCueSheet> &ptr) { ptr = 0; return -1; }
128 PyObject *getCutList();
129 void setCutList(SWIG_PYOBJECT(ePyObject));
130 void setCutListEnable(int enable);
132 RESULT rdsDecoder(ePtr<iRdsDecoder> &ptr) { ptr = 0; return -1; }
133 RESULT keys(ePtr<iServiceKeys> &ptr) { ptr = 0; return -1; }
134 RESULT stream(ePtr<iStreamableService> &ptr) { ptr = 0; return -1; }
140 RESULT info(ePtr<iServiceInformation>&);
143 RESULT getLength(pts_t &SWIG_OUTPUT);
144 RESULT seekTo(pts_t to);
145 RESULT seekRelative(int direction, pts_t to);
146 RESULT getPlayPosition(pts_t &SWIG_OUTPUT);
147 RESULT setTrickmode(int trick);
148 RESULT isCurrentlySeekable();
150 // iServiceInformation
151 RESULT getName(std::string &name);
152 RESULT getEvent(ePtr<eServiceEvent> &evt, int nownext);
154 std::string getInfoString(int w);
155 ePtr<iServiceInfoContainer> getInfoObject(int w);
157 // iAudioTrackSelection
158 int getNumberOfTracks();
159 RESULT selectTrack(unsigned int i);
160 RESULT getTrackInfo(struct iAudioTrackInfo &, unsigned int n);
161 int getCurrentTrack();
163 // iAudioChannelSelection
164 int getCurrentChannel();
165 RESULT selectChannel(int i);
168 RESULT enableSubtitles(iSubtitleUser *user, SubtitleTrack &track);
169 RESULT disableSubtitles();
170 RESULT getSubtitleList(std::vector<SubtitleTrack> &sublist);
171 RESULT getCachedSubtitle(SubtitleTrack &track);
174 RESULT streamed(ePtr<iStreamedService> &ptr);
175 ePtr<iStreamBufferInfo> getBufferCharge();
176 int setBufferSize(int size);
181 void setAC3Delay(int);
182 void setPCMDelay(int);
188 std::string language_code; /* iso-639, if available. */
189 std::string codec; /* clear text codec description */
191 :pad(0), type(atUnknown)
195 struct subtitleStream
199 std::string language_code; /* iso-639, if available. */
207 audiotype_t audiotype;
208 containertype_t containertype;
212 :audiotype(atUnknown), containertype(ctNone), is_video(FALSE), is_streaming(FALSE)
221 gint64 bufferingLeft;
223 :bufferPercent(0), avgInRate(0), avgOutRate(0), bufferingLeft(-1)
229 std::string error_message;
230 std::string missing_codec;
234 ePtr<eTimer> m_nownext_timer;
235 ePtr<eServiceEvent> m_event_now, m_event_next;
236 void updateEpgCacheNowNext();
244 bool operator < (const struct cueEntry &o) const
246 return where < o.where;
248 cueEntry(const pts_t &where, unsigned int what) :
249 where(where), what(what)
254 std::multiset<cueEntry> m_cue_entries;
255 int m_cuesheet_changed, m_cutlist_enabled;
259 static int pcm_delay;
260 static int ac3_delay;
261 int m_currentAudioStream;
262 int m_currentSubtitleStream;
263 int m_cachedSubtitleStream;
264 int selectAudioStream(int i);
265 std::vector<audioStream> m_audioStreams;
266 std::vector<subtitleStream> m_subtitleStreams;
267 iSubtitleUser *m_subtitle_widget;
268 gdouble m_currentTrickRatio;
269 friend class eServiceFactoryMP3;
270 eServiceReference m_ref;
272 int m_ignore_buffering_messages;
274 bool m_use_prefillbuffer;
277 /* cuesheet load check */
278 bool m_cuesheet_loaded;
279 bufferInfo m_bufferInfo;
280 errorInfo m_errorInfo;
281 std::string m_download_buffer_path;
282 eServiceMP3(eServiceReference ref);
283 Signal2<void,iPlayableService*,int> m_event;
286 stIdle, stRunning, stStopped,
289 GstElement *m_gst_playbin, *audioSink, *videoSink;
290 GstTagList *m_stream_tags;
292 class GstMessageContainer: public iObject
294 DECLARE_REF(GstMessageContainer);
295 GstMessage *messagePointer;
297 GstBuffer *messageBuffer;
301 GstMessageContainer(int type, GstMessage *msg, GstPad *pad, GstBuffer *buffer)
303 messagePointer = msg;
305 messageBuffer = buffer;
308 ~GstMessageContainer()
310 if (messagePointer) gst_message_unref(messagePointer);
311 if (messagePad) gst_object_unref(messagePad);
312 if (messageBuffer) gst_buffer_unref(messageBuffer);
314 int getType() { return messageType; }
315 operator GstMessage *() { return messagePointer; }
316 operator GstPad *() { return messagePad; }
317 operator GstBuffer *() { return messageBuffer; }
319 eFixedMessagePump<ePtr<GstMessageContainer> > m_pump;
321 audiotype_t gstCheckAudioPad(GstStructure* structure);
322 void gstBusCall(GstMessage *msg);
323 void handleMessage(GstMessage *msg);
324 static GstBusSyncReply gstBusSyncHandler(GstBus *bus, GstMessage *message, gpointer user_data);
325 static void gstTextpadHasCAPS(GstPad *pad, GParamSpec * unused, gpointer user_data);
326 void gstTextpadHasCAPS_synced(GstPad *pad);
327 static void gstCBsubtitleAvail(GstElement *element, GstBuffer *buffer, gpointer user_data);
328 GstPad* gstCreateSubtitleSink(eServiceMP3* _this, subtype_t type);
329 void gstPoll(ePtr<GstMessageContainer> const &);
330 static void playbinNotifySource(GObject *object, GParamSpec *unused, gpointer user_data);
331 #if GST_VERSION_MAJOR < 1
332 static gint match_sinktype(GstElement *element, gpointer type);
334 static gint match_sinktype(const GValue *velement, const gchar *type);
336 static void handleElementAdded(GstBin *bin, GstElement *element, gpointer user_data);
338 struct subtitle_page_t
344 subtitle_page_t(uint32_t start_ms_in, uint32_t end_ms_in, const std::string& text_in)
345 : start_ms(start_ms_in), end_ms(end_ms_in), text(text_in)
350 typedef std::map<uint32_t, subtitle_page_t> subtitle_pages_map_t;
351 typedef std::pair<uint32_t, subtitle_page_t> subtitle_pages_map_pair_t;
352 subtitle_pages_map_t m_subtitle_pages;
353 ePtr<eTimer> m_subtitle_sync_timer;
355 ePtr<eTimer> m_streamingsrc_timeout;
356 pts_t m_prev_decoder_time;
357 int m_decoder_time_valid_state;
359 void pushSubtitles();
360 void pullSubtitle(GstBuffer *buffer);
361 void sourceTimeout();
362 sourceStream m_sourceinfo;
363 gulong m_subs_to_pull_handler_id;
365 RESULT seekToImpl(pts_t to);
367 gint m_aspect, m_width, m_height, m_framerate, m_progressive;
368 std::string m_useragent;
369 std::string m_extra_headers;
370 RESULT trickSeek(gdouble ratio);