Add basic AudioSelection support for video containers
[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 <gst/gst.h>
9
10 class eStaticServiceMP3Info;
11
12 class eServiceFactoryMP3: public iServiceHandler
13 {
14         DECLARE_REF(eServiceFactoryMP3);
15 public:
16         eServiceFactoryMP3();
17         virtual ~eServiceFactoryMP3();
18         enum { id = 0x1001 };
19
20                 // iServiceHandler
21         RESULT play(const eServiceReference &, ePtr<iPlayableService> &ptr);
22         RESULT record(const eServiceReference &, ePtr<iRecordableService> &ptr);
23         RESULT list(const eServiceReference &, ePtr<iListableService> &ptr);
24         RESULT info(const eServiceReference &, ePtr<iStaticServiceInformation> &ptr);
25         RESULT offlineOperations(const eServiceReference &, ePtr<iServiceOfflineOperations> &ptr);
26 private:
27         ePtr<eStaticServiceMP3Info> m_service_info;
28 };
29
30 class eStaticServiceMP3Info: public iStaticServiceInformation
31 {
32         DECLARE_REF(eStaticServiceMP3Info);
33         friend class eServiceFactoryMP3;
34         eStaticServiceMP3Info();
35 public:
36         RESULT getName(const eServiceReference &ref, std::string &name);
37         int getLength(const eServiceReference &ref);
38 };
39
40 typedef struct _GstElement GstElement;
41
42 class eServiceMP3: public iPlayableService, public iPauseableService, 
43         public iServiceInformation, public iSeekableService, public iAudioTrackSelection, public iAudioChannelSelection, public Object
44 {
45         DECLARE_REF(eServiceMP3);
46 public:
47         virtual ~eServiceMP3();
48
49                 // iPlayableService
50         RESULT connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection);
51         RESULT start();
52         RESULT stop();
53         RESULT setTarget(int target);
54         
55         RESULT pause(ePtr<iPauseableService> &ptr);
56         RESULT setSlowMotion(int ratio);
57         RESULT setFastForward(int ratio);
58
59         RESULT seek(ePtr<iSeekableService> &ptr);
60         RESULT audioTracks(ePtr<iAudioTrackSelection> &ptr);
61         RESULT audioChannel(ePtr<iAudioChannelSelection> &ptr);
62
63                 // not implemented (yet)
64         RESULT frontendInfo(ePtr<iFrontendInformation> &ptr) { ptr = 0; return -1; }
65         RESULT subServices(ePtr<iSubserviceList> &ptr) { ptr = 0; return -1; }
66         RESULT timeshift(ePtr<iTimeshiftService> &ptr) { ptr = 0; return -1; }
67         RESULT cueSheet(ePtr<iCueSheet> &ptr) { ptr = 0; return -1; }
68         RESULT subtitle(ePtr<iSubtitleOutput> &ptr) { ptr = 0; return -1; }
69         RESULT audioDelay(ePtr<iAudioDelay> &ptr) { ptr = 0; return -1; }
70         RESULT rdsDecoder(ePtr<iRdsDecoder> &ptr) { ptr = 0; return -1; }
71         RESULT stream(ePtr<iStreamableService> &ptr) { ptr = 0; return -1; }
72         RESULT keys(ePtr<iServiceKeys> &ptr) { ptr = 0; return -1; }
73
74                 // iPausableService
75         RESULT pause();
76         RESULT unpause();
77         
78         RESULT info(ePtr<iServiceInformation>&);
79         
80                 // iSeekableService
81         RESULT getLength(pts_t &SWIG_OUTPUT);
82         RESULT seekTo(pts_t to);
83         RESULT seekRelative(int direction, pts_t to);
84         RESULT getPlayPosition(pts_t &SWIG_OUTPUT);
85         RESULT setTrickmode(int trick);
86         RESULT isCurrentlySeekable();
87
88                 // iServiceInformation
89         RESULT getName(std::string &name);
90         int getInfo(int w);
91         std::string getInfoString(int w);
92
93                 // iAudioTrackSelection 
94         int getNumberOfTracks();
95         RESULT selectTrack(unsigned int i);
96         RESULT getTrackInfo(struct iAudioTrackInfo &, unsigned int n);
97         int getCurrentTrack();
98
99                 // iAudioChannelSelection       
100         int getCurrentChannel();
101         RESULT selectChannel(int i);
102
103         struct audioStream
104         {
105                 GstPad* pad;
106                 enum { atMP2, atMP3, atAC3, atDTS, atAAC };
107                 int type; // mpeg2, ac3, dts, ...
108                 std::string language_code; /* iso-639, if available. */
109         };
110 private:
111         int m_currentAudioStream;
112         std::vector<audioStream> m_audioStreams;
113         friend class eServiceFactoryMP3;
114         std::string m_filename;
115         eServiceMP3(const char *filename);
116         Signal2<void,iPlayableService*,int> m_event;
117         enum
118         {
119                 stIdle, stRunning, stStopped,
120         };
121         int m_state;
122         GstElement *m_gst_pipeline;
123         GstTagList *m_stream_tags;
124         eFixedMessagePump<int> m_pump;
125
126         void gstBusCall(GstBus *bus, GstMessage *msg);
127         static GstBusSyncReply gstBusSyncHandler(GstBus *bus, GstMessage *message, gpointer user_data);
128         static void gstCBpadAdded(GstElement *decodebin, GstPad *pad, gpointer data); /* for mpegdemux */
129         static void gstCBfilterPadAdded(GstElement *filter, GstPad *pad, gpointer user_data); /* for id3demux */
130         static void gstCBnewPad(GstElement *decodebin, GstPad *pad, gboolean last, gpointer data); /* for decodebin */
131         static void gstCBunknownType(GstElement *decodebin, GstPad *pad, GstCaps *l, gpointer data);
132         void gstPoll(const int&);
133 };
134 #endif
135
136 #endif