fix
[enigma2.git] / lib / service / servicedvb.cpp
1 #include <lib/base/eerror.h>
2 #include <lib/base/object.h>
3 #include <string>
4 #include <lib/service/servicedvb.h>
5 #include <lib/service/service.h>
6 #include <lib/base/init_num.h>
7 #include <lib/base/init.h>
8
9 #include <lib/dvb/dvb.h>
10 #include <lib/dvb/db.h>
11
12 #include <lib/service/servicedvbrecord.h>
13 #include <lib/dvb/metaparser.h>
14 #include <lib/dvb/tstools.h>
15
16 class eStaticServiceDVBInformation: public iStaticServiceInformation
17 {
18         DECLARE_REF(eStaticServiceDVBInformation);
19 public:
20         RESULT getName(const eServiceReference &ref, std::string &name);
21         int getLength(const eServiceReference &ref);
22 };
23
24 DEFINE_REF(eStaticServiceDVBInformation);
25
26 RESULT eStaticServiceDVBInformation::getName(const eServiceReference &ref, std::string &name)
27 {
28         if ( ref.name.length() )
29         {
30                 name = ref.name;
31                 return 0;
32         }
33         else
34                 return -1;
35 }
36
37 int eStaticServiceDVBInformation::getLength(const eServiceReference &ref)
38 {
39         return -1;
40 }
41
42 class eStaticServiceDVBBouquetInformation: public iStaticServiceInformation
43 {
44         DECLARE_REF(eStaticServiceDVBBouquetInformation);
45 public:
46         RESULT getName(const eServiceReference &ref, std::string &name);
47         int getLength(const eServiceReference &ref);
48 };
49
50 DEFINE_REF(eStaticServiceDVBBouquetInformation);
51
52 RESULT eStaticServiceDVBBouquetInformation::getName(const eServiceReference &ref, std::string &name)
53 {
54         ePtr<iDVBChannelList> db;
55         ePtr<eDVBResourceManager> res;
56
57         int err;
58         if ((err = eDVBResourceManager::getInstance(res)) != 0)
59         {
60                 eDebug("eStaticServiceDVBBouquetInformation::getName failed.. no resource manager!");
61                 return err;
62         }
63         if ((err = res->getChannelList(db)) != 0)
64         {
65                 eDebug("eStaticServiceDVBBouquetInformation::getName failed.. no channel list!");
66                 return err;
67         }
68
69         eBouquet *bouquet=0;
70         if ((err = db->getBouquet(ref, bouquet)) != 0)
71         {
72                 eDebug("eStaticServiceDVBBouquetInformation::getName failed.. getBouquet failed!");
73                 return -1;
74         }
75
76         if ( bouquet && bouquet->m_bouquet_name.length() )
77         {
78                 name = "[Bouquet] " + bouquet->m_bouquet_name;
79                 return 0;
80         }
81         else
82                 return -1;
83 }
84
85 int eStaticServiceDVBBouquetInformation::getLength(const eServiceReference &ref)
86 {
87         return -1;
88 }
89
90 class eStaticServiceDVBPVRInformation: public iStaticServiceInformation
91 {
92         DECLARE_REF(eStaticServiceDVBPVRInformation);
93         eServiceReference m_ref;
94         eDVBMetaParser m_parser;
95 public:
96         eStaticServiceDVBPVRInformation(const eServiceReference &ref);
97         RESULT getName(const eServiceReference &ref, std::string &name);
98         int getLength(const eServiceReference &ref);
99 };
100
101 DEFINE_REF(eStaticServiceDVBPVRInformation);
102
103 eStaticServiceDVBPVRInformation::eStaticServiceDVBPVRInformation(const eServiceReference &ref)
104 {
105         m_ref = ref;
106         m_parser.parseFile(ref.path);
107 }
108
109 RESULT eStaticServiceDVBPVRInformation::getName(const eServiceReference &ref, std::string &name)
110 {
111         ASSERT(ref == m_ref);
112         name = m_parser.m_name.size() ? m_parser.m_name : ref.path;
113         return 0;
114 }
115
116 int eStaticServiceDVBPVRInformation::getLength(const eServiceReference &ref)
117 {
118         ASSERT(ref == m_ref);
119         
120         eDVBTSTools tstools;
121         
122         if (tstools.openFile(ref.path.c_str()))
123                 return 0;
124
125         pts_t len;
126         if (tstools.calcLen(len))
127                 return 0;
128
129         return len / 90000;
130 }
131
132
133
134 class eDVBPVRServiceOfflineOperations: public iServiceOfflineOperations
135 {
136         DECLARE_REF(eDVBPVRServiceOfflineOperations);
137         eServiceReferenceDVB m_ref;
138 public:
139         eDVBPVRServiceOfflineOperations(const eServiceReference &ref);
140         
141         RESULT deleteFromDisk(int simulate);
142         RESULT getListOfFilenames(std::list<std::string> &);
143 };
144
145 DEFINE_REF(eDVBPVRServiceOfflineOperations);
146
147 eDVBPVRServiceOfflineOperations::eDVBPVRServiceOfflineOperations(const eServiceReference &ref): m_ref((const eServiceReferenceDVB&)ref)
148 {
149 }
150
151 RESULT eDVBPVRServiceOfflineOperations::deleteFromDisk(int simulate)
152 {
153         if (simulate)
154                 return 0;
155         else
156         {
157                 std::list<std::string> res;
158                 if (getListOfFilenames(res))
159                         return -1;
160                 
161                                 /* TODO: deferred removing.. */
162                 for (std::list<std::string>::iterator i(res.begin()); i != res.end(); ++i)
163                 {
164                         eDebug("Removing %s...", i->c_str());
165                         ::unlink(i->c_str());
166                 }
167                 
168                 return 0;
169         }
170 }
171
172 RESULT eDVBPVRServiceOfflineOperations::getListOfFilenames(std::list<std::string> &res)
173 {
174         res.clear();
175         res.push_back(m_ref.path);
176         res.push_back(m_ref.path + ".meta");
177         return 0;
178 }
179
180 DEFINE_REF(eServiceFactoryDVB)
181
182 eServiceFactoryDVB::eServiceFactoryDVB()
183 {
184         ePtr<eServiceCenter> sc;
185         
186         eServiceCenter::getPrivInstance(sc);
187         if (sc)
188                 sc->addServiceFactory(eServiceFactoryDVB::id, this);
189 }
190
191 eServiceFactoryDVB::~eServiceFactoryDVB()
192 {
193         ePtr<eServiceCenter> sc;
194         
195         eServiceCenter::getPrivInstance(sc);
196         if (sc)
197                 sc->removeServiceFactory(eServiceFactoryDVB::id);
198 }
199
200 DEFINE_REF(eDVBServiceList);
201
202 eDVBServiceList::eDVBServiceList(const eServiceReference &parent): m_parent(parent)
203 {
204 }
205
206 eDVBServiceList::~eDVBServiceList()
207 {
208 }
209
210 RESULT eDVBServiceList::startQuery()
211 {
212         ePtr<iDVBChannelList> db;
213         ePtr<eDVBResourceManager> res;
214         
215         int err;
216         if ((err = eDVBResourceManager::getInstance(res)) != 0)
217         {
218                 eDebug("no resource manager");
219                 return err;
220         }
221         if ((err = res->getChannelList(db)) != 0)
222         {
223                 eDebug("no channel list");
224                 return err;
225         }
226         
227         ePtr<eDVBChannelQuery> q;
228         
229         if (!m_parent.path.empty())
230         {
231                 eDVBChannelQuery::compile(q, m_parent.path);
232                 if (!q)
233                 {
234                         eDebug("compile query failed");
235                         return err;
236                 }
237         }
238         
239         if ((err = db->startQuery(m_query, q, m_parent)) != 0)
240         {
241                 eDebug("startQuery failed");
242                 return err;
243         }
244
245         return 0;
246 }
247
248 RESULT eDVBServiceList::getContent(std::list<eServiceReference> &list)
249 {
250         eServiceReferenceDVB ref;
251         
252         if (!m_query)
253                 return -1;
254         
255         while (!m_query->getNextResult(ref))
256                 list.push_back(ref);
257         return 0;
258 }
259
260 RESULT eDVBServiceList::getNext(eServiceReference &ref)
261 {
262         if (!m_query)
263                 return -1;
264         
265         return m_query->getNextResult((eServiceReferenceDVB&)ref);
266 }
267
268 int eDVBServiceList::compareLessEqual(const eServiceReference &a, const eServiceReference &b)
269 {
270         return m_query->compareLessEqual((const eServiceReferenceDVB&)a, (const eServiceReferenceDVB&)b);
271 }
272
273 RESULT eDVBServiceList::startEdit(ePtr<iMutableServiceList> &res)
274 {
275         if (m_parent.flags & eServiceReference::flagDirectory) // bouquet
276         {
277                 ePtr<iDVBChannelList> db;
278                 ePtr<eDVBResourceManager> resm;
279
280                 if (eDVBResourceManager::getInstance(resm) || resm->getChannelList(db))
281                         return -1;
282
283                 if (db->getBouquet(m_parent, m_bouquet) != 0)
284                         return -1;
285
286                 res = this;
287                 
288                 return 0;
289         }
290         res = 0;
291         return -1;
292 }
293
294 RESULT eDVBServiceList::addService(eServiceReference &ref)
295 {
296         if (!m_bouquet)
297                 return -1;
298         return m_bouquet->addService(ref);
299 }
300
301 RESULT eDVBServiceList::removeService(eServiceReference &ref)
302 {
303         if (!m_bouquet)
304                 return -1;
305         return m_bouquet->removeService(ref);
306 }
307
308 RESULT eDVBServiceList::moveService(eServiceReference &ref, int pos)
309 {
310         if (!m_bouquet)
311                 return -1;
312         return m_bouquet->moveService(ref, pos);
313 }
314
315 RESULT eDVBServiceList::flushChanges()
316 {
317         if (!m_bouquet)
318                 return -1;
319         return m_bouquet->flushChanges();
320 }
321
322 RESULT eServiceFactoryDVB::play(const eServiceReference &ref, ePtr<iPlayableService> &ptr)
323 {
324         ePtr<eDVBService> service;
325         int r = lookupService(service, ref);
326         if (r)
327                 service = 0;
328                 // check resources...
329         ptr = new eDVBServicePlay(ref, service);
330         return 0;
331 }
332
333 RESULT eServiceFactoryDVB::record(const eServiceReference &ref, ePtr<iRecordableService> &ptr)
334 {
335         if (ref.path.empty())
336         {
337                 ptr = new eDVBServiceRecord((eServiceReferenceDVB&)ref);
338                 return 0;
339         } else
340         {
341                 ptr = 0;
342                 return -1;
343         }
344 }
345
346 RESULT eServiceFactoryDVB::list(const eServiceReference &ref, ePtr<iListableService> &ptr)
347 {
348         ePtr<eDVBServiceList> list = new eDVBServiceList(ref);
349         if (list->startQuery())
350         {
351                 ptr = 0;
352                 return -1;
353         }
354         
355         ptr = list;
356         return 0;
357 }
358
359 RESULT eServiceFactoryDVB::info(const eServiceReference &ref, ePtr<iStaticServiceInformation> &ptr)
360 {
361                 /* do we have a PVR service? */
362         if (ref.flags & eServiceReference::flagDirectory) // bouquet
363         {
364                 ptr = new eStaticServiceDVBBouquetInformation;
365                 return 0;
366         }
367         else if (!ref.path.empty())
368         {
369                 ptr = new eStaticServiceDVBPVRInformation(ref);
370                 return 0;
371         }
372         else
373         {
374                 ePtr<eDVBService> service;
375                 int r = lookupService(service, ref);
376                 if (r)
377                         ptr = new eStaticServiceDVBInformation;
378                 else
379                         /* eDVBService has the iStaticServiceInformation interface, so we pass it here. */
380                         ptr = service;
381                 return 0;
382         }
383 }
384
385 RESULT eServiceFactoryDVB::offlineOperations(const eServiceReference &ref, ePtr<iServiceOfflineOperations> &ptr)
386 {
387         if (ref.path.empty())
388         {
389                 ptr = 0;
390                 return -1;
391         } else
392         {
393                 ptr = new eDVBPVRServiceOfflineOperations(ref);
394                 return 0;
395         }
396 }
397
398 RESULT eServiceFactoryDVB::lookupService(ePtr<eDVBService> &service, const eServiceReference &ref)
399 {
400                         // TODO: handle the listing itself
401         // if (ref.... == -1) .. return "... bouquets ...";
402         // could be also done in another serviceFactory (with seperate ID) to seperate actual services and lists
403                         // TODO: cache
404         ePtr<iDVBChannelList> db;
405         ePtr<eDVBResourceManager> res;
406         
407         int err;
408         if ((err = eDVBResourceManager::getInstance(res)) != 0)
409         {
410                 eDebug("no resource manager");
411                 return err;
412         }
413         if ((err = res->getChannelList(db)) != 0)
414         {
415                 eDebug("no channel list");
416                 return err;
417         }
418         
419                 /* we are sure to have a ..DVB reference as the info() call was forwarded here according to it's ID. */
420         if ((err = db->getService((eServiceReferenceDVB&)ref, service)) != 0)
421         {
422                 eDebug("getService failed!");
423                 return err;
424         }
425
426         return 0;
427 }
428
429 eDVBServicePlay::eDVBServicePlay(const eServiceReference &ref, eDVBService *service): 
430         m_reference(ref), m_dvb_service(service), m_service_handler(0), m_is_paused(0)
431 {
432         m_is_pvr = !ref.path.empty();
433         
434         CONNECT(m_service_handler.serviceEvent, eDVBServicePlay::serviceEvent);
435         CONNECT(m_event_handler.m_eit_changed, eDVBServicePlay::gotNewEvent);
436 }
437
438 eDVBServicePlay::~eDVBServicePlay()
439 {
440 }
441
442 void eDVBServicePlay::gotNewEvent()
443 {
444 #if 0
445                 // debug only
446         ePtr<eServiceEvent> m_event_now, m_event_next;
447         getEvent(m_event_now, 0);
448         getEvent(m_event_next, 1);
449
450         if (m_event_now)
451                 eDebug("now running: %s (%d seconds :)", m_event_now->m_event_name.c_str(), m_event_now->m_duration);
452         if (m_event_next)
453                 eDebug("next running: %s (%d seconds :)", m_event_next->m_event_name.c_str(), m_event_next->m_duration);
454 #endif
455         m_event((iPlayableService*)this, evUpdatedEventInfo);
456 }
457
458 void eDVBServicePlay::serviceEvent(int event)
459 {
460         switch (event)
461         {
462         case eDVBServicePMTHandler::eventTuned:
463         {
464                 ePtr<iDVBDemux> m_demux;
465                 if (!m_service_handler.getDemux(m_demux))
466                 {
467 //                      eventStartedEventAcquisition
468                         m_event_handler.start(m_demux, ((eServiceReferenceDVB&)m_reference).getServiceID().get());
469                 }
470 //                      eventNoEvent
471                 break;
472         }
473         case eDVBServicePMTHandler::eventTuneFailed:
474         {
475                 eDebug("DVB service failed to tune");
476                 m_event((iPlayableService*)this, evTuneFailed);
477                 break;
478         }
479         case eDVBServicePMTHandler::eventNewProgramInfo:
480         {
481                 int vpid = -1, apid = -1, apidtype = -1, pcrpid = -1;
482                 eDVBServicePMTHandler::program program;
483                 if (m_service_handler.getProgramInfo(program))
484                         eDebug("getting program info failed.");
485                 else
486                 {
487                         eDebugNoNewLine("have %d video stream(s)", program.videoStreams.size());
488                         if (!program.videoStreams.empty())
489                         {
490                                 eDebugNoNewLine(" (");
491                                 for (std::vector<eDVBServicePMTHandler::videoStream>::const_iterator
492                                         i(program.videoStreams.begin()); 
493                                         i != program.videoStreams.end(); ++i)
494                                 {
495                                         if (vpid == -1)
496                                                 vpid = i->pid;
497                                         if (i != program.videoStreams.begin())
498                                                 eDebugNoNewLine(", ");
499                                         eDebugNoNewLine("%04x", i->pid);
500                                 }
501                                 eDebugNoNewLine(")");
502                         }
503                         eDebugNoNewLine(", and %d audio stream(s)", program.audioStreams.size());
504                         if (!program.audioStreams.empty())
505                         {
506                                 eDebugNoNewLine(" (");
507                                 for (std::vector<eDVBServicePMTHandler::audioStream>::const_iterator
508                                         i(program.audioStreams.begin()); 
509                                         i != program.audioStreams.end(); ++i)
510                                 {
511                                         if (apid == -1)
512                                         {
513                                                 apid = i->pid;
514                                                 apidtype = i->type;
515                                         }
516                                         if (i != program.audioStreams.begin())
517                                                 eDebugNoNewLine(", ");
518                                         eDebugNoNewLine("%04x", i->pid);
519                                 }
520                                 eDebugNoNewLine(")");
521                         }
522                         eDebug(", and the pcr pid is %04x", program.pcrPid);
523                         if (program.pcrPid != 0x1fff)
524                                 pcrpid = program.pcrPid;
525                 }
526                 
527                 if (!m_decoder)
528                 {
529                         ePtr<iDVBDemux> demux;
530                         m_service_handler.getDemux(demux);
531                         if (demux)
532                                 demux->getMPEGDecoder(m_decoder);
533                 }
534
535                 if (m_decoder)
536                 {
537                         m_decoder->setVideoPID(vpid);
538                         m_current_audio_stream = 0;
539                         m_decoder->setAudioPID(apid, apidtype);
540                         if (!m_is_pvr)
541                                 m_decoder->setSyncPCR(pcrpid);
542                         else
543                                 m_decoder->setSyncPCR(-1);
544                         m_decoder->start();
545 // how we can do this better?
546 // update cache pid when the user changed the audio track or video track
547 // TODO handling of difference audio types.. default audio types..
548                                 
549                                 /* don't worry about non-existing services, nor pvr services */
550                         if (m_dvb_service && !m_is_pvr)
551                         {
552                                 m_dvb_service->setCachePID(eDVBService::cVPID, vpid);
553                                 m_dvb_service->setCachePID(eDVBService::cAPID, apid);
554                                 m_dvb_service->setCachePID(eDVBService::cPCRPID, pcrpid);
555                         }
556                 }
557                 
558                 break;
559         }
560         }
561 }
562
563 RESULT eDVBServicePlay::start()
564 {
565         int r;
566         eDebug("starting DVB service");
567         r = m_service_handler.tune((eServiceReferenceDVB&)m_reference);
568         eDebug("tune result: %d", r);
569         m_event(this, evStart);
570         return 0;
571 }
572
573 RESULT eDVBServicePlay::stop()
574 {
575         eDebug("stopping..");
576         return 0;
577 }
578
579 RESULT eDVBServicePlay::connectEvent(const Slot2<void,iPlayableService*,int> &event, ePtr<eConnection> &connection)
580 {
581         connection = new eConnection((iPlayableService*)this, m_event.connect(event));
582         return 0;
583 }
584
585 RESULT eDVBServicePlay::pause(ePtr<iPauseableService> &ptr)
586 {
587         if (m_is_pvr)
588         {
589                 ptr = this;
590                 return 0;
591         }
592
593         ptr = 0;
594         return -1;
595 }
596
597 RESULT eDVBServicePlay::seek(ePtr<iSeekableService> &ptr)
598 {
599         if (m_is_pvr)
600         {
601                 ptr = this;
602                 return 0;
603         }
604         
605         ptr = 0;
606         return -1;
607 }
608
609 RESULT eDVBServicePlay::getLength(pts_t &len)
610 {
611         ePtr<iDVBPVRChannel> pvr_channel;
612         
613         if (m_service_handler.getPVRChannel(pvr_channel))
614         {
615                 eDebug("getPVRChannel failed!");
616                 return -1;
617         }
618         
619         return pvr_channel->getLength(len);
620 }
621
622 RESULT eDVBServicePlay::pause()
623 {
624         if (!m_is_paused && m_decoder)
625         {
626                 m_is_paused = 1;
627                 return m_decoder->freeze(0);
628         } else
629                 return -1;
630 }
631
632 RESULT eDVBServicePlay::unpause()
633 {
634         if (m_is_paused && m_decoder)
635         {
636                 m_is_paused = 0;
637                 return m_decoder->unfreeze();
638         } else
639                 return -1;
640 }
641
642 RESULT eDVBServicePlay::seekTo(pts_t to)
643 {
644         return -1;
645 }
646
647 RESULT eDVBServicePlay::seekRelative(int direction, pts_t to)
648 {
649         eDebug("eDVBServicePlay::seekRelative: jump %d, %lld", direction, to);
650
651         ePtr<iDVBPVRChannel> pvr_channel;
652         
653         if (m_service_handler.getPVRChannel(pvr_channel))
654                 return -1;
655         
656         to *= direction;
657         
658         ePtr<iDVBDemux> demux;
659         m_service_handler.getDemux(demux);
660         if (!demux)
661                 return -1;
662         
663         return pvr_channel->seekTo(demux, 1, to);
664 }
665
666 RESULT eDVBServicePlay::getPlayPosition(pts_t &pos)
667 {
668         ePtr<iDVBPVRChannel> pvr_channel;
669         
670         if (m_service_handler.getPVRChannel(pvr_channel))
671                 return -1;
672         
673         ePtr<iDVBDemux> demux;
674         m_service_handler.getDemux(demux);
675         if (!demux)
676                 return -1;
677         
678         return pvr_channel->getCurrentPosition(demux, pos);
679 }
680
681 RESULT eDVBServicePlay::info(ePtr<iServiceInformation> &ptr)
682 {
683         ptr = this;
684         return 0;
685 }
686
687 RESULT eDVBServicePlay::audioTracks(ePtr<iAudioTrackSelection> &ptr)
688 {
689         ptr = this;
690         return 0;
691 }
692
693 RESULT eDVBServicePlay::getName(std::string &name)
694 {
695         if (m_dvb_service)
696         {
697                 m_dvb_service->getName(m_reference, name);
698                 if (name.empty())
699                         name = "(...)";
700         } else
701                 name = "DVB service";
702         return 0;
703 }
704
705 RESULT eDVBServicePlay::getEvent(ePtr<eServiceEvent> &evt, int nownext)
706 {
707         return m_event_handler.getEvent(evt, nownext);
708 }
709
710 int eDVBServicePlay::getInfo(int w)
711 {
712         eDVBServicePMTHandler::program program;
713
714         if (m_service_handler.getProgramInfo(program))
715                 return -1;
716         
717         switch (w)
718         {
719         case sVideoPID: if (program.videoStreams.empty()) return -1; return program.videoStreams[0].pid;
720         case sAudioPID: if (program.audioStreams.empty()) return -1; return program.audioStreams[m_current_audio_stream].pid;
721         case sPCRPID: return program.pcrPid;
722         case sPMTPID: return program.pmtPid;
723         case sTXTPID: return -1;
724                 
725         case sSID: return ((const eServiceReferenceDVB&)m_reference).getServiceID().get();
726         case sONID: return ((const eServiceReferenceDVB&)m_reference).getOriginalNetworkID().get();
727         case sTSID: return ((const eServiceReferenceDVB&)m_reference).getTransportStreamID().get();
728         case sNamespace: return ((const eServiceReferenceDVB&)m_reference).getDVBNamespace().get();
729         case sProvider: if (!m_dvb_service) return -1; return -2;
730         default:
731                 return -1;
732         }
733 }
734
735 std::string eDVBServicePlay::getInfoString(int w)
736 {       
737         switch (w)
738         {
739         case sProvider:
740                 if (!m_dvb_service) return "";
741                 return m_dvb_service->m_provider_name;
742         default:
743                 return "";
744         }
745 }
746
747 int eDVBServicePlay::getNumberOfTracks()
748 {
749         eDVBServicePMTHandler::program program;
750         if (m_service_handler.getProgramInfo(program))
751                 return 0;
752         return program.audioStreams.size();
753 }
754
755 RESULT eDVBServicePlay::selectTrack(unsigned int i)
756 {
757         int ret = selectAudioStream(i);
758
759         if (m_decoder->start())
760                 return -5;
761
762         return ret;
763 }
764
765 RESULT eDVBServicePlay::getTrackInfo(struct iAudioTrackInfo &info, unsigned int i)
766 {
767         eDVBServicePMTHandler::program program;
768
769         if (m_service_handler.getProgramInfo(program))
770                 return -1;
771         
772         if (i >= program.audioStreams.size())
773                 return -2;
774         
775         if (program.audioStreams[i].type == eDVBServicePMTHandler::audioStream::atMPEG)
776                 info.m_description = "MPEG";
777         else if (program.audioStreams[i].type == eDVBServicePMTHandler::audioStream::atAC3)
778                 info.m_description = "AC3";
779         else  if (program.audioStreams[i].type == eDVBServicePMTHandler::audioStream::atDTS)
780                 info.m_description = "DTS";
781         else
782                 info.m_description = "???";
783         
784                 /* CHECK here for component tag override. */
785         info.m_language = program.audioStreams[i].language_code;
786         
787         return 0;
788 }
789
790 int eDVBServicePlay::selectAudioStream(int i)
791 {
792         eDVBServicePMTHandler::program program;
793
794         if (m_service_handler.getProgramInfo(program))
795                 return -1;
796         
797         if (i >= program.audioStreams.size())
798                 return -2;
799         
800         if (!m_decoder)
801                 return -3;
802         
803         if (m_decoder->setAudioPID(program.audioStreams[i].pid, program.audioStreams[i].type))
804                 return -4;
805
806         m_current_audio_stream = i;
807
808         return 0;
809 }
810
811 DEFINE_REF(eDVBServicePlay)
812
813 eAutoInitPtr<eServiceFactoryDVB> init_eServiceFactoryDVB(eAutoInitNumbers::service+1, "eServiceFactoryDVB");