1 #include <lib/base/ebase.h>
2 #include <lib/base/eerror.h>
3 #include <lib/dvb/decoder.h>
4 #if HAVE_DVB_API_VERSION < 3
5 #define audioStatus audio_status
6 #define videoStatus video_status
7 #define pesType pes_type
8 #define playState play_state
9 #define audioStreamSource_t audio_stream_source_t
10 #define videoStreamSource_t video_stream_source_t
11 #define streamSource stream_source
12 #define dmxPesFilterParams dmx_pes_filter_params
13 #define DMX_PES_VIDEO0 DMX_PES_VIDEO
14 #define DMX_PES_AUDIO0 DMX_PES_AUDIO
15 #define DMX_PES_PCR0 DMX_PES_PCR
16 #define DMX_PES_TELETEXT0 DMX_PES_TELETEXT
17 #define DMX_PES_VIDEO1 DMX_PES_VIDEO
18 #define DMX_PES_AUDIO1 DMX_PES_AUDIO
19 #define DMX_PES_PCR1 DMX_PES_PCR
20 #define DMX_PES_TELETEXT1 DMX_PES_TELETEXT
22 #include <ost/video.h>
23 #include <ost/audio.h>
25 #include <linux/dvb/audio.h>
26 #include <linux/dvb/video.h>
27 #include <linux/dvb/dmx.h>
32 #include <sys/ioctl.h>
33 #include <sys/types.h>
37 /* these are quite new... */
39 #define AUDIO_GET_PTS _IOR('o', 19, __u64)
40 #define VIDEO_GET_PTS _IOR('o', 57, __u64)
43 DEFINE_REF(eDVBAudio);
45 eDVBAudio::eDVBAudio(eDVBDemux *demux, int dev)
46 :m_demux(demux), m_dev(dev)
49 #if HAVE_DVB_API_VERSION < 3
50 sprintf(filename, "/dev/dvb/card%d/audio%d", demux->adapter, dev);
52 sprintf(filename, "/dev/dvb/adapter%d/audio%d", demux->adapter, dev);
54 m_fd = ::open(filename, O_RDWR);
56 eWarning("%s: %m", filename);
57 #if HAVE_DVB_API_VERSION < 3
58 sprintf(filename, "/dev/dvb/card%d/demux%d", demux->adapter, demux->demux);
60 sprintf(filename, "/dev/dvb/adapter%d/demux%d", demux->adapter, demux->demux);
62 m_fd_demux = ::open(filename, O_RDWR);
64 eWarning("%s: %m", filename);
67 #if HAVE_DVB_API_VERSION < 3
68 int eDVBAudio::setPid(int pid, int type)
70 if ((m_fd < 0) || (m_fd_demux < 0))
90 if (::ioctl(m_fd, AUDIO_SET_BYPASS_MODE, bypass) < 0)
91 eDebug("failed (%m)");
93 dmx_pes_filter_params pes;
96 pes.input = DMX_IN_FRONTEND;
97 pes.output = DMX_OUT_DECODER;
98 pes.pes_type = m_dev ? DMX_PES_AUDIO1 : DMX_PES_AUDIO0; /* FIXME */
100 eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - audio - ", pid);
101 if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
103 eDebug("failed (%m)");
111 int eDVBAudio::startPid()
113 eDebugNoNewLine("DEMUX_START - audio - ");
114 if (::ioctl(m_fd_demux, DMX_START) < 0)
116 eDebug("failed (%m)");
123 int eDVBAudio::start()
125 eDebugNoNewLine("AUDIO_PLAY - ");
126 if (::ioctl(m_fd, AUDIO_PLAY) < 0)
128 eDebug("failed (%m)");
135 int eDVBAudio::stopPid()
137 eDebugNoNewLine("DEMUX_STOP - audio - ");
138 if (::ioctl(m_fd_demux, DMX_STOP) < 0)
140 eDebug("failed (%m)");
147 int eDVBAudio::setAVSync(int val)
149 eDebugNoNewLine("AUDIO_SET_AV_SYNC - ");
150 if (::ioctl(m_fd, AUDIO_SET_AV_SYNC, val) < 0)
152 eDebug("failed (%m)");
159 int eDVBAudio::startPid(int pid, int type)
161 if ((m_fd < 0) || (m_fd_demux < 0))
163 dmx_pes_filter_params pes;
166 pes.input = DMX_IN_FRONTEND;
167 pes.output = DMX_OUT_DECODER;
168 pes.pes_type = m_dev ? DMX_PES_AUDIO1 : DMX_PES_AUDIO0; /* FIXME */
170 eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - audio - ", pid);
171 if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
173 eDebug("failed (%m)");
177 eDebugNoNewLine("DEMUX_START - audio - ");
178 if (::ioctl(m_fd_demux, DMX_START) < 0)
180 eDebug("failed (%m)");
211 eDebugNoNewLine("AUDIO_SET_BYPASS(%d) - ", bypass);
212 if (::ioctl(m_fd, AUDIO_SET_BYPASS_MODE, bypass) < 0)
213 eDebug("failed (%m)");
216 freeze(); // why freeze here?!? this is a problem when only a pid change is requested... because of the unfreeze logic in Decoder::setState
217 eDebugNoNewLine("AUDIO_PLAY - ");
218 if (::ioctl(m_fd, AUDIO_PLAY) < 0)
219 eDebug("failed (%m)");
226 void eDVBAudio::stop()
228 eDebugNoNewLine("AUDIO_STOP - ");
229 if (::ioctl(m_fd, AUDIO_STOP) < 0)
230 eDebug("failed (%m)");
233 #if HAVE_DVB_API_VERSION > 2
234 eDebugNoNewLine("DEMUX_STOP - audio - ");
235 if (::ioctl(m_fd_demux, DMX_STOP) < 0)
236 eDebug("failed (%m)");
242 void eDVBAudio::flush()
244 eDebugNoNewLine("AUDIO_CLEAR_BUFFER - ");
245 if (::ioctl(m_fd, AUDIO_CLEAR_BUFFER) < 0)
246 eDebug("failed (%m)");
251 void eDVBAudio::freeze()
253 eDebugNoNewLine("AUDIO_PAUSE - ");
254 if (::ioctl(m_fd, AUDIO_PAUSE) < 0)
255 eDebug("failed (%m)");
260 void eDVBAudio::unfreeze()
262 eDebugNoNewLine("AUDIO_CONTINUE - ");
263 if (::ioctl(m_fd, AUDIO_CONTINUE) < 0)
264 eDebug("failed (%m)");
269 void eDVBAudio::setChannel(int channel)
271 int val = AUDIO_STEREO;
274 case aMonoLeft: val = AUDIO_MONO_LEFT; break;
275 case aMonoRight: val = AUDIO_MONO_RIGHT; break;
278 eDebugNoNewLine("AUDIO_CHANNEL_SELECT(%d) - ", val);
279 if (::ioctl(m_fd, AUDIO_CHANNEL_SELECT, val) < 0)
280 eDebug("failed (%m)");
285 int eDVBAudio::getPTS(pts_t &now)
287 if (::ioctl(m_fd, AUDIO_GET_PTS, &now) < 0)
288 eDebug("AUDIO_GET_PTS failed (%m)");
292 eDVBAudio::~eDVBAudio()
294 unfreeze(); // why unfreeze here... but not unfreeze video in ~eDVBVideo ?!?
301 DEFINE_REF(eDVBVideo);
303 eDVBVideo::eDVBVideo(eDVBDemux *demux, int dev)
304 : m_demux(demux), m_dev(dev),
305 m_width(-1), m_height(-1), m_framerate(-1), m_aspect(-1), m_progressive(-1)
308 #if HAVE_DVB_API_VERSION < 3
309 sprintf(filename, "/dev/dvb/card%d/video%d", demux->adapter, dev);
310 m_fd_video = ::open("/dev/video", O_RDWR);
312 eWarning("/dev/video: %m");
314 sprintf(filename, "/dev/dvb/adapter%d/video%d", demux->adapter, dev);
316 m_fd = ::open(filename, O_RDWR);
318 eWarning("%s: %m", filename);
321 m_sn = eSocketNotifier::create(eApp, m_fd, eSocketNotifier::Priority);
322 CONNECT(m_sn->activated, eDVBVideo::video_event);
324 eDebug("Video Device: %s", filename);
325 #if HAVE_DVB_API_VERSION < 3
326 sprintf(filename, "/dev/dvb/card%d/demux%d", demux->adapter, demux->demux);
328 sprintf(filename, "/dev/dvb/adapter%d/demux%d", demux->adapter, demux->demux);
330 m_fd_demux = ::open(filename, O_RDWR);
332 eWarning("%s: %m", filename);
333 eDebug("demux device: %s", filename);
336 // not finally values i think.. !!
337 #define VIDEO_STREAMTYPE_MPEG2 0
338 #define VIDEO_STREAMTYPE_MPEG4_H264 1
339 #define VIDEO_STREAMTYPE_VC1 3
340 #define VIDEO_STREAMTYPE_MPEG4_Part2 4
341 #define VIDEO_STREAMTYPE_VC1_SM 5
342 #define VIDEO_STREAMTYPE_MPEG1 6
344 #if HAVE_DVB_API_VERSION < 3
345 int eDVBVideo::setPid(int pid)
347 if ((m_fd < 0) || (m_fd_demux < 0))
349 dmx_pes_filter_params pes;
352 pes.input = DMX_IN_FRONTEND;
353 pes.output = DMX_OUT_DECODER;
354 pes.pes_type = m_dev ? DMX_PES_VIDEO1 : DMX_PES_VIDEO0; /* FIXME */
356 eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - video - ", pid);
357 if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
359 eDebug("failed (%m)");
366 int eDVBVideo::startPid()
368 eDebugNoNewLine("DEMUX_START - video - ");
369 if (::ioctl(m_fd_demux, DMX_START) < 0)
371 eDebug("failed (%m)");
378 int eDVBVideo::start()
380 eDebugNoNewLine("VIDEO_PLAY - ");
381 if (::ioctl(m_fd, VIDEO_PLAY) < 0)
383 eDebug("failed (%m)");
390 int eDVBVideo::stopPid()
392 eDebugNoNewLine("DEMUX_STOP - video - ");
393 if (::ioctl(m_fd_demux, DMX_STOP) < 0)
395 eDebug("failed (%m)");
402 int eDVBVideo::startPid(int pid, int type)
404 int streamtype = VIDEO_STREAMTYPE_MPEG2;
406 if ((m_fd < 0) || (m_fd_demux < 0))
408 dmx_pes_filter_params pes;
416 streamtype = VIDEO_STREAMTYPE_MPEG4_H264;
419 streamtype = VIDEO_STREAMTYPE_MPEG1;
422 streamtype = VIDEO_STREAMTYPE_MPEG4_Part2;
425 streamtype = VIDEO_STREAMTYPE_VC1;
428 streamtype = VIDEO_STREAMTYPE_VC1_SM;
432 eDebugNoNewLine("VIDEO_SET_STREAMTYPE %d - ", streamtype);
433 if (::ioctl(m_fd, VIDEO_SET_STREAMTYPE, streamtype) < 0)
434 eDebug("failed (%m)");
439 pes.input = DMX_IN_FRONTEND;
440 pes.output = DMX_OUT_DECODER;
441 pes.pes_type = m_dev ? DMX_PES_VIDEO1 : DMX_PES_VIDEO0; /* FIXME */
443 eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - video - ", pid);
444 if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
446 eDebug("failed (%m)");
450 eDebugNoNewLine("DEMUX_START - video - ");
451 if (::ioctl(m_fd_demux, DMX_START) < 0)
453 eDebug("failed (%m)");
457 freeze(); // why freeze here?!? this is a problem when only a pid change is requested... because of the unfreeze logic in Decoder::setState
458 eDebugNoNewLine("VIDEO_PLAY - ");
459 if (::ioctl(m_fd, VIDEO_PLAY) < 0)
460 eDebug("failed (%m)");
467 void eDVBVideo::stop()
469 #if HAVE_DVB_API_VERSION > 2
470 eDebugNoNewLine("DEMUX_STOP - video - ");
471 if (::ioctl(m_fd_demux, DMX_STOP) < 0)
472 eDebug("failed (%m)");
476 eDebugNoNewLine("VIDEO_STOP - ");
477 if (::ioctl(m_fd, VIDEO_STOP, 1) < 0)
478 eDebug("failed (%m)");
483 void eDVBVideo::flush()
485 eDebugNoNewLine("VIDEO_CLEAR_BUFFER - ");
486 if (::ioctl(m_fd, VIDEO_CLEAR_BUFFER) < 0)
487 eDebug("failed (%m)");
492 void eDVBVideo::freeze()
494 eDebugNoNewLine("VIDEO_FREEZE - ");
495 if (::ioctl(m_fd, VIDEO_FREEZE) < 0)
496 eDebug("failed (%m)");
501 void eDVBVideo::unfreeze()
503 eDebugNoNewLine("VIDEO_CONTINUE - ");
504 if (::ioctl(m_fd, VIDEO_CONTINUE) < 0)
505 eDebug("failed (%m)");
510 int eDVBVideo::setSlowMotion(int repeat)
512 eDebugNoNewLine("VIDEO_SLOWMOTION(%d) - ", repeat);
513 int ret = ::ioctl(m_fd, VIDEO_SLOWMOTION, repeat);
515 eDebug("failed(%m)");
521 int eDVBVideo::setFastForward(int skip)
523 eDebugNoNewLine("VIDEO_FAST_FORWARD(%d) - ", skip);
524 int ret = ::ioctl(m_fd, VIDEO_FAST_FORWARD, skip);
526 eDebug("failed(%m)");
532 int eDVBVideo::getPTS(pts_t &now)
534 #if HAVE_DVB_API_VERSION < 3
535 #define VIDEO_GET_PTS_OLD _IOR('o', 1, unsigned int*)
537 int ret = ::ioctl(m_fd_video, VIDEO_GET_PTS_OLD, &pts);
541 int ret = ::ioctl(m_fd, VIDEO_GET_PTS, &now);
544 eDebug("VIDEO_GET_PTS failed(%m)");
548 eDVBVideo::~eDVBVideo()
554 #if HAVE_DVB_API_VERSION < 3
560 void eDVBVideo::video_event(int)
562 #if HAVE_DVB_API_VERSION >= 3
563 struct video_event evt;
564 eDebugNoNewLine("VIDEO_GET_EVENT - ");
565 if (::ioctl(m_fd, VIDEO_GET_EVENT, &evt) < 0)
566 eDebug("failed (%m)");
570 if (evt.type == VIDEO_EVENT_SIZE_CHANGED)
572 struct iTSMPEGDecoder::videoEvent event;
573 event.type = iTSMPEGDecoder::videoEvent::eventSizeChanged;
574 m_aspect = event.aspect = evt.u.size.aspect_ratio == 0 ? 2 : 3; // convert dvb api to etsi
575 m_height = event.height = evt.u.size.h;
576 m_width = event.width = evt.u.size.w;
577 /* emit */ m_event(event);
579 else if (evt.type == VIDEO_EVENT_FRAME_RATE_CHANGED)
581 struct iTSMPEGDecoder::videoEvent event;
582 event.type = iTSMPEGDecoder::videoEvent::eventFrameRateChanged;
583 m_framerate = event.framerate = evt.u.frame_rate;
584 /* emit */ m_event(event);
586 else if (evt.type == 16 /*VIDEO_EVENT_PROGRESSIVE_CHANGED*/)
588 struct iTSMPEGDecoder::videoEvent event;
589 event.type = iTSMPEGDecoder::videoEvent::eventProgressiveChanged;
590 m_progressive = event.progressive = evt.u.frame_rate;
591 /* emit */ m_event(event);
594 eDebug("unhandled DVBAPI Video Event %d", evt.type);
597 #warning "FIXMEE!! Video Events not implemented for old api"
601 RESULT eDVBVideo::connectEvent(const Slot1<void, struct iTSMPEGDecoder::videoEvent> &event, ePtr<eConnection> &conn)
603 conn = new eConnection(this, m_event.connect(event));
607 static int readMpegProc(const char *str, int decoder)
611 sprintf(tmp, "/proc/stb/vmpeg/%d/%s", decoder, str);
612 FILE *f = fopen(tmp, "r");
615 fscanf(f, "%x", &val);
621 static int readApiSize(int fd, int &xres, int &yres, int &aspect)
623 #if HAVE_DVB_API_VERSION >= 3
625 if (!::ioctl(fd, VIDEO_GET_SIZE, &size))
629 aspect = size.aspect_ratio == 0 ? 2 : 3; // convert dvb api to etsi
632 // eDebug("VIDEO_GET_SIZE failed (%m)");
637 static int readApiFrameRate(int fd, int &framerate)
639 #if HAVE_DVB_API_VERSION >= 3
641 if (!::ioctl(fd, VIDEO_GET_FRAME_RATE, &frate))
646 // eDebug("VIDEO_GET_FRAME_RATE failed (%m)");
651 int eDVBVideo::getWidth()
654 readApiSize(m_fd, m_width, m_height, m_aspect);
656 m_width = readMpegProc("xres", m_dev);
660 int eDVBVideo::getHeight()
663 readApiSize(m_fd, m_width, m_height, m_aspect);
665 m_height = readMpegProc("yres", m_dev);
669 int eDVBVideo::getAspect()
672 readApiSize(m_fd, m_width, m_height, m_aspect);
674 m_aspect = readMpegProc("aspect", m_dev);
678 int eDVBVideo::getProgressive()
680 if (m_progressive == -1)
681 m_progressive = readMpegProc("progressive", m_dev);
682 return m_progressive;
685 int eDVBVideo::getFrameRate()
687 if (m_framerate == -1)
688 readApiFrameRate(m_fd, m_framerate);
689 if (m_framerate == -1)
690 m_framerate = readMpegProc("framerate", m_dev);
696 eDVBPCR::eDVBPCR(eDVBDemux *demux, int dev): m_demux(demux), m_dev(dev)
699 #if HAVE_DVB_API_VERSION < 3
700 sprintf(filename, "/dev/dvb/card%d/demux%d", demux->adapter, demux->demux);
702 sprintf(filename, "/dev/dvb/adapter%d/demux%d", demux->adapter, demux->demux);
704 m_fd_demux = ::open(filename, O_RDWR);
706 eWarning("%s: %m", filename);
709 #if HAVE_DVB_API_VERSION < 3
710 int eDVBPCR::setPid(int pid)
714 dmx_pes_filter_params pes;
717 pes.input = DMX_IN_FRONTEND;
718 pes.output = DMX_OUT_DECODER;
719 pes.pes_type = DMX_PES_PCR;
722 eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - pcr - ", pid);
723 if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
725 eDebug("failed (%m)");
732 int eDVBPCR::startPid()
736 eDebugNoNewLine("DEMUX_START - pcr - ");
737 if (::ioctl(m_fd_demux, DMX_START) < 0)
739 eDebug("failed (%m)");
746 int eDVBPCR::startPid(int pid)
750 dmx_pes_filter_params pes;
753 pes.input = DMX_IN_FRONTEND;
754 pes.output = DMX_OUT_DECODER;
755 pes.pes_type = m_dev ? DMX_PES_PCR1 : DMX_PES_PCR0; /* FIXME */
757 eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - pcr - ", pid);
758 if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
760 eDebug("failed (%m)");
764 eDebugNoNewLine("DEMUX_START - pcr - ");
765 if (::ioctl(m_fd_demux, DMX_START) < 0)
767 eDebug("failed (%m)");
777 eDebugNoNewLine("DEMUX_STOP - pcr - ");
778 if (::ioctl(m_fd_demux, DMX_STOP) < 0)
779 eDebug("failed(%m)");
790 DEFINE_REF(eDVBTText);
792 eDVBTText::eDVBTText(eDVBDemux *demux, int dev)
793 :m_demux(demux), m_dev(dev)
796 #if HAVE_DVB_API_VERSION < 3
797 sprintf(filename, "/dev/dvb/card%d/demux%d", demux->adapter, demux->demux);
799 sprintf(filename, "/dev/dvb/adapter%d/demux%d", demux->adapter, demux->demux);
801 m_fd_demux = ::open(filename, O_RDWR);
803 eWarning("%s: %m", filename);
806 int eDVBTText::startPid(int pid)
810 dmx_pes_filter_params pes;
813 pes.input = DMX_IN_FRONTEND;
814 pes.output = DMX_OUT_DECODER;
815 pes.pes_type = m_dev ? DMX_PES_TELETEXT1 : DMX_PES_TELETEXT0; // FIXME
818 eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - ttx - ", pid);
819 if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
821 eDebug("failed(%m)");
825 eDebugNoNewLine("DEMUX_START - ttx - ");
826 if (::ioctl(m_fd_demux, DMX_START) < 0)
828 eDebug("failed(%m)");
835 void eDVBTText::stop()
837 eDebugNoNewLine("DEMUX_STOP - ttx - ");
838 if (::ioctl(m_fd_demux, DMX_STOP) < 0)
839 eDebug("failed(%m)");
844 eDVBTText::~eDVBTText()
850 DEFINE_REF(eTSMPEGDecoder);
852 int eTSMPEGDecoder::setState()
856 int noaudio = (m_state != statePlay) && (m_state != statePause);
857 int nott = noaudio; /* actually same conditions */
859 if ((noaudio && m_audio) || (!m_audio && !noaudio))
860 m_changed |= changeAudio | changeState;
862 if ((nott && m_text) || (!m_text && !nott))
863 m_changed |= changeText | changeState;
865 const char *decoder_states[] = {"stop", "pause", "play", "decoderfastforward", "trickmode", "slowmotion"};
866 eDebug("decoder state: %s, vpid=%d, apid=%d", decoder_states[m_state], m_vpid, m_apid);
868 int changed = m_changed;
869 #if HAVE_DVB_API_VERSION < 3
870 bool checkAVSync = m_changed & (changeAudio|changeVideo|changePCR);
871 if (m_changed & changeAudio && m_audio)
873 if (m_changed & changeVideo && m_video)
875 if (m_changed & changePCR && m_pcr)
879 if (!(m_pcrpid >= 0 && m_pcrpid < 0x1ff))
880 m_changed &= ~changePCR;
882 if (m_changed & changeAudio && m_audio)
886 if (!(m_apid >= 0 && m_apid < 0x1ff))
887 m_changed &= ~changeAudio;
889 if (m_changed & changeVideo && m_video)
893 m_video_event_conn=0;
894 if (!(m_vpid >= 0 && m_vpid < 0x1ff))
895 m_changed &= ~changeVideo;
897 if (m_changed & changeVideo)
899 m_video = new eDVBVideo(m_demux, m_decoder);
900 m_video->connectEvent(slot(*this, &eTSMPEGDecoder::video_event), m_video_event_conn);
901 if (m_video->setPid(m_vpid))
904 if (m_changed & changePCR)
906 m_pcr = new eDVBPCR(m_demux, m_decoder);
907 if (m_pcr->setPid(m_pcrpid))
910 if (m_changed & changeAudio)
912 m_audio = new eDVBAudio(m_demux, m_decoder);
913 if (m_audio->setPid(m_apid, m_atype))
916 if (m_changed & changePCR)
918 if (m_pcr->startPid())
920 m_changed &= ~changePCR;
922 else if (checkAVSync && m_audio && m_video)
924 if (m_audio->setAVSync(1))
927 if (m_changed & changeVideo)
929 if (m_video->startPid() || m_video->start())
931 m_changed &= ~changeVideo;
933 if (m_changed & changeAudio)
935 if (m_audio->start() || m_audio->startPid())
937 m_changed &= ~changeAudio;
940 if (m_changed & changePCR)
946 if (m_changed & changeVideo)
952 m_video_event_conn = 0;
955 if (m_changed & changeAudio)
961 if (m_changed & changeText)
967 if (m_changed & changePCR)
969 if ((m_pcrpid >= 0) && (m_pcrpid < 0x1FFF))
971 m_pcr = new eDVBPCR(m_demux, m_decoder);
972 if (m_pcr->startPid(m_pcrpid))
975 m_changed &= ~changePCR;
977 if (m_changed & changeAudio)
979 if ((m_apid >= 0) && (m_apid < 0x1FFF) && !noaudio)
981 m_audio = new eDVBAudio(m_demux, m_decoder);
982 if (m_audio->startPid(m_apid, m_atype))
985 m_changed &= ~changeAudio;
987 if (m_changed & changeVideo)
989 if ((m_vpid >= 0) && (m_vpid < 0x1FFF))
991 m_video = new eDVBVideo(m_demux, m_decoder);
992 m_video->connectEvent(slot(*this, &eTSMPEGDecoder::video_event), m_video_event_conn);
993 if (m_video->startPid(m_vpid, m_vtype))
996 m_changed &= ~changeVideo;
998 if (m_changed & changeText)
1000 if ((m_textpid >= 0) && (m_textpid < 0x1FFF) && !nott)
1002 m_text = new eDVBTText(m_demux, m_decoder);
1003 if (m_text->startPid(m_textpid))
1006 m_changed &= ~changeText;
1010 if (changed & (changeState|changeVideo|changeAudio))
1012 /* play, slowmotion, fast-forward */
1013 int state_table[6][4] =
1015 /* [stateStop] = */ {0, 0, 0},
1016 /* [statePause] = */ {0, 0, 0},
1017 /* [statePlay] = */ {1, 0, 0},
1018 /* [stateDecoderFastForward] = */ {1, 0, m_ff_sm_ratio},
1019 /* [stateHighspeedFastForward] = */ {1, 0, 1},
1020 /* [stateSlowMotion] = */ {1, m_ff_sm_ratio, 0}
1022 int *s = state_table[m_state];
1023 if (changed & (changeState|changeVideo) && m_video)
1025 m_video->setSlowMotion(s[1]);
1026 m_video->setFastForward(s[2]);
1028 m_video->unfreeze();
1032 if (changed & (changeState|changeAudio) && m_audio)
1035 m_audio->unfreeze();
1039 m_changed &= ~changeState;
1042 if (changed && !m_video && m_audio && m_radio_pic.length())
1043 showSinglePic(m_radio_pic.c_str());
1048 int eTSMPEGDecoder::m_pcm_delay=-1,
1049 eTSMPEGDecoder::m_ac3_delay=-1;
1051 RESULT eTSMPEGDecoder::setHwPCMDelay(int delay)
1053 if (delay != m_pcm_delay )
1055 FILE *fp = fopen("/proc/stb/audio/audio_delay_pcm", "w");
1058 fprintf(fp, "%x", delay*90);
1060 m_pcm_delay = delay;
1067 RESULT eTSMPEGDecoder::setHwAC3Delay(int delay)
1069 if ( delay != m_ac3_delay )
1071 FILE *fp = fopen("/proc/stb/audio/audio_delay_bitstream", "w");
1074 fprintf(fp, "%x", delay*90);
1076 m_ac3_delay = delay;
1084 RESULT eTSMPEGDecoder::setPCMDelay(int delay)
1086 return m_decoder == 0 ? setHwPCMDelay(delay) : -1;
1089 RESULT eTSMPEGDecoder::setAC3Delay(int delay)
1091 return m_decoder == 0 ? setHwAC3Delay(delay) : -1;
1094 eTSMPEGDecoder::eTSMPEGDecoder(eDVBDemux *demux, int decoder)
1096 m_vpid(-1), m_vtype(-1), m_apid(-1), m_atype(-1), m_pcrpid(-1), m_textpid(-1),
1097 m_changed(0), m_decoder(decoder), m_video_clip_fd(-1), m_showSinglePicTimer(eTimer::create(eApp))
1099 demux->connectEvent(slot(*this, &eTSMPEGDecoder::demux_event), m_demux_event_conn);
1100 CONNECT(m_showSinglePicTimer->timeout, eTSMPEGDecoder::finishShowSinglePic);
1101 m_state = stateStop;
1104 eTSMPEGDecoder::~eTSMPEGDecoder()
1106 finishShowSinglePic();
1107 m_vpid = m_apid = m_pcrpid = m_textpid = pidNone;
1112 RESULT eTSMPEGDecoder::setVideoPID(int vpid, int type)
1114 if ((m_vpid != vpid) || (m_vtype != type))
1116 m_changed |= changeVideo;
1123 RESULT eTSMPEGDecoder::setAudioPID(int apid, int type)
1125 if ((m_apid != apid) || (m_atype != type))
1127 m_changed |= changeAudio;
1134 int eTSMPEGDecoder::m_audio_channel = -1;
1136 RESULT eTSMPEGDecoder::setAudioChannel(int channel)
1139 channel = ac_stereo;
1140 if (m_decoder == 0 && m_audio_channel != channel)
1144 m_audio->setChannel(channel);
1145 m_audio_channel=channel;
1148 eDebug("eTSMPEGDecoder::setAudioChannel but no audio decoder exist");
1153 int eTSMPEGDecoder::getAudioChannel()
1155 return m_audio_channel == -1 ? ac_stereo : m_audio_channel;
1158 RESULT eTSMPEGDecoder::setSyncPCR(int pcrpid)
1160 if (m_pcrpid != pcrpid)
1162 m_changed |= changePCR;
1168 RESULT eTSMPEGDecoder::setTextPID(int textpid)
1170 if (m_textpid != textpid)
1172 m_changed |= changeText;
1173 m_textpid = textpid;
1178 RESULT eTSMPEGDecoder::setSyncMaster(int who)
1183 RESULT eTSMPEGDecoder::set()
1188 RESULT eTSMPEGDecoder::play()
1190 if (m_state == statePlay)
1196 m_state = statePlay;
1197 m_changed |= changeState;
1202 RESULT eTSMPEGDecoder::pause()
1204 if (m_state == statePause)
1206 m_state = statePause;
1207 m_changed |= changeState;
1211 RESULT eTSMPEGDecoder::setFastForward(int frames_to_skip)
1213 if ((m_state == stateDecoderFastForward) && (m_ff_sm_ratio == frames_to_skip))
1216 m_state = stateDecoderFastForward;
1217 m_ff_sm_ratio = frames_to_skip;
1218 m_changed |= changeState;
1221 // return m_video->setFastForward(frames_to_skip);
1224 RESULT eTSMPEGDecoder::setSlowMotion(int repeat)
1226 if ((m_state == stateSlowMotion) && (m_ff_sm_ratio == repeat))
1229 m_state = stateSlowMotion;
1230 m_ff_sm_ratio = repeat;
1231 m_changed |= changeState;
1235 RESULT eTSMPEGDecoder::setTrickmode()
1237 if (m_state == stateTrickmode)
1240 m_state = stateTrickmode;
1241 m_changed |= changeState;
1245 RESULT eTSMPEGDecoder::flush()
1254 void eTSMPEGDecoder::demux_event(int event)
1258 case eDVBDemux::evtFlush:
1266 RESULT eTSMPEGDecoder::getPTS(int what, pts_t &pts)
1268 if (what == 0) /* auto */
1269 what = m_video ? 1 : 2;
1271 if (what == 1) /* video */
1274 return m_video->getPTS(pts);
1279 if (what == 2) /* audio */
1282 return m_audio->getPTS(pts);
1290 RESULT eTSMPEGDecoder::setRadioPic(const std::string &filename)
1292 m_radio_pic = filename;
1296 RESULT eTSMPEGDecoder::showSinglePic(const char *filename)
1300 eDebug("showSinglePic %s", filename);
1301 int f = open(filename, O_RDONLY);
1307 if (m_video_clip_fd == -1)
1308 m_video_clip_fd = open("/dev/dvb/adapter0/video0", O_WRONLY);
1309 if (m_video_clip_fd >= 0)
1311 bool seq_end_avail = false;
1313 unsigned char pes_header[] = { 0x00, 0x00, 0x01, 0xE0, 0x00, 0x00, 0x80, 0x00, 0x00 };
1314 unsigned char seq_end[] = { 0x00, 0x00, 0x01, 0xB7 };
1315 unsigned char iframe[s.st_size];
1316 unsigned char stuffing[8192];
1317 int streamtype = VIDEO_STREAMTYPE_MPEG2;
1318 memset(stuffing, 0, 8192);
1319 read(f, iframe, s.st_size);
1320 if (ioctl(m_video_clip_fd, VIDEO_SELECT_SOURCE, VIDEO_SOURCE_MEMORY) < 0)
1321 eDebug("VIDEO_SELECT_SOURCE MEMORY failed (%m)");
1322 if (ioctl(m_video_clip_fd, VIDEO_SET_STREAMTYPE, streamtype) < 0)
1323 eDebug("VIDEO_SET_STREAMTYPE failed(%m)");
1324 if (ioctl(m_video_clip_fd, VIDEO_PLAY) < 0)
1325 eDebug("VIDEO_PLAY failed (%m)");
1326 if (ioctl(m_video_clip_fd, VIDEO_CONTINUE) < 0)
1327 eDebug("video: VIDEO_CONTINUE: %m");
1328 if (ioctl(m_video_clip_fd, VIDEO_CLEAR_BUFFER) < 0)
1329 eDebug("video: VIDEO_CLEAR_BUFFER: %m");
1330 while(pos <= (s.st_size-4) && !(seq_end_avail = (!iframe[pos] && !iframe[pos+1] && iframe[pos+2] == 1 && iframe[pos+3] == 0xB7)))
1332 if ((iframe[3] >> 4) != 0xE) // no pes header
1333 write(m_video_clip_fd, pes_header, sizeof(pes_header));
1335 iframe[4] = iframe[5] = 0x00;
1336 write(m_video_clip_fd, iframe, s.st_size);
1338 write(m_video_clip_fd, seq_end, sizeof(seq_end));
1339 write(m_video_clip_fd, stuffing, 8192);
1340 m_showSinglePicTimer->start(150, true);
1346 eDebug("couldnt open %s", filename);
1352 eDebug("only show single pics on first decoder");
1358 void eTSMPEGDecoder::finishShowSinglePic()
1360 if (m_video_clip_fd >= 0)
1362 if (ioctl(m_video_clip_fd, VIDEO_STOP, 0) < 0)
1363 eDebug("VIDEO_STOP failed (%m)");
1364 if (ioctl(m_video_clip_fd, VIDEO_SELECT_SOURCE, VIDEO_SOURCE_DEMUX) < 0)
1365 eDebug("VIDEO_SELECT_SOURCE DEMUX failed (%m)");
1366 close(m_video_clip_fd);
1367 m_video_clip_fd = -1;
1371 RESULT eTSMPEGDecoder::connectVideoEvent(const Slot1<void, struct videoEvent> &event, ePtr<eConnection> &conn)
1373 conn = new eConnection(this, m_video_event.connect(event));
1377 void eTSMPEGDecoder::video_event(struct videoEvent event)
1379 /* emit */ m_video_event(event);
1382 int eTSMPEGDecoder::getVideoWidth()
1385 return m_video->getWidth();
1389 int eTSMPEGDecoder::getVideoHeight()
1392 return m_video->getHeight();
1396 int eTSMPEGDecoder::getVideoProgressive()
1399 return m_video->getProgressive();
1403 int eTSMPEGDecoder::getVideoFrameRate()
1406 return m_video->getFrameRate();
1410 int eTSMPEGDecoder::getVideoAspect()
1413 return m_video->getAspect();