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 /* servicemMP3 chapter TOC support CVR */
280 #if GST_VERSION_MAJOR >= 1
281 bool m_use_chapter_entries;
283 bufferInfo m_bufferInfo;
284 errorInfo m_errorInfo;
285 std::string m_download_buffer_path;
286 eServiceMP3(eServiceReference ref);
287 Signal2<void,iPlayableService*,int> m_event;
290 stIdle, stRunning, stStopped,
293 GstElement *m_gst_playbin, *audioSink, *videoSink;
294 GstTagList *m_stream_tags;
296 class GstMessageContainer: public iObject
298 DECLARE_REF(GstMessageContainer);
299 GstMessage *messagePointer;
301 GstBuffer *messageBuffer;
305 GstMessageContainer(int type, GstMessage *msg, GstPad *pad, GstBuffer *buffer)
307 messagePointer = msg;
309 messageBuffer = buffer;
312 ~GstMessageContainer()
314 if (messagePointer) gst_message_unref(messagePointer);
315 if (messagePad) gst_object_unref(messagePad);
316 if (messageBuffer) gst_buffer_unref(messageBuffer);
318 int getType() { return messageType; }
319 operator GstMessage *() { return messagePointer; }
320 operator GstPad *() { return messagePad; }
321 operator GstBuffer *() { return messageBuffer; }
323 eFixedMessagePump<ePtr<GstMessageContainer> > m_pump;
325 audiotype_t gstCheckAudioPad(GstStructure* structure);
326 void gstBusCall(GstMessage *msg);
327 void handleMessage(GstMessage *msg);
328 static GstBusSyncReply gstBusSyncHandler(GstBus *bus, GstMessage *message, gpointer user_data);
329 static void gstTextpadHasCAPS(GstPad *pad, GParamSpec * unused, gpointer user_data);
330 void gstTextpadHasCAPS_synced(GstPad *pad);
331 static void gstCBsubtitleAvail(GstElement *element, GstBuffer *buffer, gpointer user_data);
332 GstPad* gstCreateSubtitleSink(eServiceMP3* _this, subtype_t type);
333 void gstPoll(ePtr<GstMessageContainer> const &);
334 static void playbinNotifySource(GObject *object, GParamSpec *unused, gpointer user_data);
335 #if GST_VERSION_MAJOR < 1
336 static gint match_sinktype(GstElement *element, gpointer type);
338 /* TOC processing CVR */
339 void HandleTocEntry(GstMessage *msg);
340 static gint match_sinktype(const GValue *velement, const gchar *type);
342 static void handleElementAdded(GstBin *bin, GstElement *element, gpointer user_data);
344 struct subtitle_page_t
350 subtitle_page_t(uint32_t start_ms_in, uint32_t end_ms_in, const std::string& text_in)
351 : start_ms(start_ms_in), end_ms(end_ms_in), text(text_in)
356 typedef std::map<uint32_t, subtitle_page_t> subtitle_pages_map_t;
357 typedef std::pair<uint32_t, subtitle_page_t> subtitle_pages_map_pair_t;
358 subtitle_pages_map_t m_subtitle_pages;
359 ePtr<eTimer> m_subtitle_sync_timer;
361 ePtr<eTimer> m_streamingsrc_timeout;
362 pts_t m_prev_decoder_time;
363 int m_decoder_time_valid_state;
365 void pushSubtitles();
366 void pullSubtitle(GstBuffer *buffer);
367 void sourceTimeout();
368 sourceStream m_sourceinfo;
369 gulong m_subs_to_pull_handler_id;
371 RESULT seekToImpl(pts_t to);
373 gint m_aspect, m_width, m_height, m_framerate, m_progressive;
374 std::string m_useragent;
375 std::string m_extra_headers;
376 RESULT trickSeek(gdouble ratio);