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)");
208 eDebugNoNewLine("AUDIO_SET_BYPASS(%d) - ", bypass);
209 if (::ioctl(m_fd, AUDIO_SET_BYPASS_MODE, bypass) < 0)
210 eDebug("failed (%m)");
213 freeze(); // why freeze here?!? this is a problem when only a pid change is requested... because of the unfreeze logic in Decoder::setState
214 eDebugNoNewLine("AUDIO_PLAY - ");
215 if (::ioctl(m_fd, AUDIO_PLAY) < 0)
216 eDebug("failed (%m)");
223 void eDVBAudio::stop()
225 eDebugNoNewLine("AUDIO_STOP - ");
226 if (::ioctl(m_fd, AUDIO_STOP) < 0)
227 eDebug("failed (%m)");
230 #if HAVE_DVB_API_VERSION > 2
231 eDebugNoNewLine("DEMUX_STOP - audio - ");
232 if (::ioctl(m_fd_demux, DMX_STOP) < 0)
233 eDebug("failed (%m)");
239 void eDVBAudio::flush()
241 eDebugNoNewLine("AUDIO_CLEAR_BUFFER - ");
242 if (::ioctl(m_fd, AUDIO_CLEAR_BUFFER) < 0)
243 eDebug("failed (%m)");
248 void eDVBAudio::freeze()
250 eDebugNoNewLine("AUDIO_PAUSE - ");
251 if (::ioctl(m_fd, AUDIO_PAUSE) < 0)
252 eDebug("failed (%m)");
257 void eDVBAudio::unfreeze()
259 eDebugNoNewLine("AUDIO_CONTINUE - ");
260 if (::ioctl(m_fd, AUDIO_CONTINUE) < 0)
261 eDebug("failed (%m)");
266 void eDVBAudio::setChannel(int channel)
268 int val = AUDIO_STEREO;
271 case aMonoLeft: val = AUDIO_MONO_LEFT; break;
272 case aMonoRight: val = AUDIO_MONO_RIGHT; break;
275 eDebugNoNewLine("AUDIO_CHANNEL_SELECT(%d) - ", val);
276 if (::ioctl(m_fd, AUDIO_CHANNEL_SELECT, val) < 0)
277 eDebug("failed (%m)");
282 int eDVBAudio::getPTS(pts_t &now)
284 if (::ioctl(m_fd, AUDIO_GET_PTS, &now) < 0)
285 eDebug("AUDIO_GET_PTS failed (%m)");
289 eDVBAudio::~eDVBAudio()
291 unfreeze(); // why unfreeze here... but not unfreeze video in ~eDVBVideo ?!?
298 DEFINE_REF(eDVBVideo);
300 eDVBVideo::eDVBVideo(eDVBDemux *demux, int dev)
301 : m_demux(demux), m_dev(dev),
302 m_width(-1), m_height(-1), m_framerate(-1), m_aspect(-1), m_progressive(-1)
305 #if HAVE_DVB_API_VERSION < 3
306 sprintf(filename, "/dev/dvb/card%d/video%d", demux->adapter, dev);
307 m_fd_video = ::open("/dev/video", O_RDWR);
309 eWarning("/dev/video: %m");
311 sprintf(filename, "/dev/dvb/adapter%d/video%d", demux->adapter, dev);
313 m_fd = ::open(filename, O_RDWR);
315 eWarning("%s: %m", filename);
318 m_sn = eSocketNotifier::create(eApp, m_fd, eSocketNotifier::Priority);
319 CONNECT(m_sn->activated, eDVBVideo::video_event);
321 eDebug("Video Device: %s", filename);
322 #if HAVE_DVB_API_VERSION < 3
323 sprintf(filename, "/dev/dvb/card%d/demux%d", demux->adapter, demux->demux);
325 sprintf(filename, "/dev/dvb/adapter%d/demux%d", demux->adapter, demux->demux);
327 m_fd_demux = ::open(filename, O_RDWR);
329 eWarning("%s: %m", filename);
330 eDebug("demux device: %s", filename);
333 // not finally values i think.. !!
334 #define VIDEO_STREAMTYPE_MPEG2 0
335 #define VIDEO_STREAMTYPE_MPEG4_H264 1
336 #define VIDEO_STREAMTYPE_VC1 3
337 #define VIDEO_STREAMTYPE_MPEG4_Part2 4
338 #define VIDEO_STREAMTYPE_VC1_SM 5
339 #define VIDEO_STREAMTYPE_MPEG1 6
341 #if HAVE_DVB_API_VERSION < 3
342 int eDVBVideo::setPid(int pid)
344 if ((m_fd < 0) || (m_fd_demux < 0))
346 dmx_pes_filter_params pes;
349 pes.input = DMX_IN_FRONTEND;
350 pes.output = DMX_OUT_DECODER;
351 pes.pes_type = m_dev ? DMX_PES_VIDEO1 : DMX_PES_VIDEO0; /* FIXME */
353 eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - video - ", pid);
354 if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
356 eDebug("failed (%m)");
363 int eDVBVideo::startPid()
365 eDebugNoNewLine("DEMUX_START - video - ");
366 if (::ioctl(m_fd_demux, DMX_START) < 0)
368 eDebug("failed (%m)");
375 int eDVBVideo::start()
377 eDebugNoNewLine("VIDEO_PLAY - ");
378 if (::ioctl(m_fd, VIDEO_PLAY) < 0)
380 eDebug("failed (%m)");
387 int eDVBVideo::stopPid()
389 eDebugNoNewLine("DEMUX_STOP - video - ");
390 if (::ioctl(m_fd_demux, DMX_STOP) < 0)
392 eDebug("failed (%m)");
399 int eDVBVideo::startPid(int pid, int type)
401 int streamtype = VIDEO_STREAMTYPE_MPEG2;
403 if ((m_fd < 0) || (m_fd_demux < 0))
405 dmx_pes_filter_params pes;
413 streamtype = VIDEO_STREAMTYPE_MPEG4_H264;
416 streamtype = VIDEO_STREAMTYPE_MPEG1;
419 streamtype = VIDEO_STREAMTYPE_MPEG4_Part2;
422 streamtype = VIDEO_STREAMTYPE_VC1;
425 streamtype = VIDEO_STREAMTYPE_VC1_SM;
429 eDebugNoNewLine("VIDEO_SET_STREAMTYPE %d - ", streamtype);
430 if (::ioctl(m_fd, VIDEO_SET_STREAMTYPE, streamtype) < 0)
431 eDebug("failed (%m)");
436 pes.input = DMX_IN_FRONTEND;
437 pes.output = DMX_OUT_DECODER;
438 pes.pes_type = m_dev ? DMX_PES_VIDEO1 : DMX_PES_VIDEO0; /* FIXME */
440 eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - video - ", pid);
441 if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
443 eDebug("failed (%m)");
447 eDebugNoNewLine("DEMUX_START - video - ");
448 if (::ioctl(m_fd_demux, DMX_START) < 0)
450 eDebug("failed (%m)");
454 freeze(); // why freeze here?!? this is a problem when only a pid change is requested... because of the unfreeze logic in Decoder::setState
455 eDebugNoNewLine("VIDEO_PLAY - ");
456 if (::ioctl(m_fd, VIDEO_PLAY) < 0)
457 eDebug("failed (%m)");
464 void eDVBVideo::stop()
466 #if HAVE_DVB_API_VERSION > 2
467 eDebugNoNewLine("DEMUX_STOP - video - ");
468 if (::ioctl(m_fd_demux, DMX_STOP) < 0)
469 eDebug("failed (%m)");
473 eDebugNoNewLine("VIDEO_STOP - ");
474 if (::ioctl(m_fd, VIDEO_STOP, 1) < 0)
475 eDebug("failed (%m)");
480 void eDVBVideo::flush()
482 eDebugNoNewLine("VIDEO_CLEAR_BUFFER - ");
483 if (::ioctl(m_fd, VIDEO_CLEAR_BUFFER) < 0)
484 eDebug("failed (%m)");
489 void eDVBVideo::freeze()
491 eDebugNoNewLine("VIDEO_FREEZE - ");
492 if (::ioctl(m_fd, VIDEO_FREEZE) < 0)
493 eDebug("failed (%m)");
498 void eDVBVideo::unfreeze()
500 eDebugNoNewLine("VIDEO_CONTINUE - ");
501 if (::ioctl(m_fd, VIDEO_CONTINUE) < 0)
502 eDebug("failed (%m)");
507 int eDVBVideo::setSlowMotion(int repeat)
509 eDebugNoNewLine("VIDEO_SLOWMOTION(%d) - ", repeat);
510 int ret = ::ioctl(m_fd, VIDEO_SLOWMOTION, repeat);
512 eDebug("failed(%m)");
518 int eDVBVideo::setFastForward(int skip)
520 eDebugNoNewLine("VIDEO_FAST_FORWARD(%d) - ", skip);
521 int ret = ::ioctl(m_fd, VIDEO_FAST_FORWARD, skip);
523 eDebug("failed(%m)");
529 int eDVBVideo::getPTS(pts_t &now)
531 #if HAVE_DVB_API_VERSION < 3
532 #define VIDEO_GET_PTS_OLD _IOR('o', 1, unsigned int*)
534 int ret = ::ioctl(m_fd_video, VIDEO_GET_PTS_OLD, &pts);
538 int ret = ::ioctl(m_fd, VIDEO_GET_PTS, &now);
541 eDebug("VIDEO_GET_PTS failed(%m)");
545 eDVBVideo::~eDVBVideo()
551 #if HAVE_DVB_API_VERSION < 3
557 void eDVBVideo::video_event(int)
559 #if HAVE_DVB_API_VERSION >= 3
560 struct video_event evt;
561 eDebugNoNewLine("VIDEO_GET_EVENT - ");
562 if (::ioctl(m_fd, VIDEO_GET_EVENT, &evt) < 0)
563 eDebug("failed (%m)");
567 if (evt.type == VIDEO_EVENT_SIZE_CHANGED)
569 struct iTSMPEGDecoder::videoEvent event;
570 event.type = iTSMPEGDecoder::videoEvent::eventSizeChanged;
571 m_aspect = event.aspect = evt.u.size.aspect_ratio == 0 ? 2 : 3; // convert dvb api to etsi
572 m_height = event.height = evt.u.size.h;
573 m_width = event.width = evt.u.size.w;
574 /* emit */ m_event(event);
576 else if (evt.type == VIDEO_EVENT_FRAME_RATE_CHANGED)
578 struct iTSMPEGDecoder::videoEvent event;
579 event.type = iTSMPEGDecoder::videoEvent::eventFrameRateChanged;
580 m_framerate = event.framerate = evt.u.frame_rate;
581 /* emit */ m_event(event);
583 else if (evt.type == 16 /*VIDEO_EVENT_PROGRESSIVE_CHANGED*/)
585 struct iTSMPEGDecoder::videoEvent event;
586 event.type = iTSMPEGDecoder::videoEvent::eventProgressiveChanged;
587 m_progressive = event.progressive = evt.u.frame_rate;
588 /* emit */ m_event(event);
591 eDebug("unhandled DVBAPI Video Event %d", evt.type);
594 #warning "FIXMEE!! Video Events not implemented for old api"
598 RESULT eDVBVideo::connectEvent(const Slot1<void, struct iTSMPEGDecoder::videoEvent> &event, ePtr<eConnection> &conn)
600 conn = new eConnection(this, m_event.connect(event));
604 static int readMpegProc(char *str, int decoder)
608 sprintf(tmp, "/proc/stb/vmpeg/%d/%s", decoder, str);
609 FILE *f = fopen(tmp, "r");
612 fscanf(f, "%x", &val);
618 static int readApiSize(int fd, int &xres, int &yres, int &aspect)
620 #if HAVE_DVB_API_VERSION >= 3
622 if (!::ioctl(fd, VIDEO_GET_SIZE, &size))
626 aspect = size.aspect_ratio == 0 ? 2 : 3; // convert dvb api to etsi
629 // eDebug("VIDEO_GET_SIZE failed (%m)");
634 static int readApiFrameRate(int fd, int &framerate)
636 #if HAVE_DVB_API_VERSION >= 3
638 if (!::ioctl(fd, VIDEO_GET_FRAME_RATE, &frate))
643 // eDebug("VIDEO_GET_FRAME_RATE failed (%m)");
648 int eDVBVideo::getWidth()
651 readApiSize(m_fd, m_width, m_height, m_aspect);
653 m_width = readMpegProc("xres", m_dev);
657 int eDVBVideo::getHeight()
660 readApiSize(m_fd, m_width, m_height, m_aspect);
662 m_height = readMpegProc("yres", m_dev);
666 int eDVBVideo::getAspect()
669 readApiSize(m_fd, m_width, m_height, m_aspect);
671 m_aspect = readMpegProc("aspect", m_dev);
675 int eDVBVideo::getProgressive()
677 if (m_progressive == -1)
678 m_progressive = readMpegProc("progressive", m_dev);
679 return m_progressive;
682 int eDVBVideo::getFrameRate()
684 if (m_framerate == -1)
685 readApiFrameRate(m_fd, m_framerate);
686 if (m_framerate == -1)
687 m_framerate = readMpegProc("framerate", m_dev);
693 eDVBPCR::eDVBPCR(eDVBDemux *demux, int dev): m_demux(demux), m_dev(dev)
696 #if HAVE_DVB_API_VERSION < 3
697 sprintf(filename, "/dev/dvb/card%d/demux%d", demux->adapter, demux->demux);
699 sprintf(filename, "/dev/dvb/adapter%d/demux%d", demux->adapter, demux->demux);
701 m_fd_demux = ::open(filename, O_RDWR);
703 eWarning("%s: %m", filename);
706 #if HAVE_DVB_API_VERSION < 3
707 int eDVBPCR::setPid(int pid)
711 dmx_pes_filter_params pes;
714 pes.input = DMX_IN_FRONTEND;
715 pes.output = DMX_OUT_DECODER;
716 pes.pes_type = DMX_PES_PCR;
719 eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - pcr - ", pid);
720 if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
722 eDebug("failed (%m)");
729 int eDVBPCR::startPid()
733 eDebugNoNewLine("DEMUX_START - pcr - ");
734 if (::ioctl(m_fd_demux, DMX_START) < 0)
736 eDebug("failed (%m)");
743 int eDVBPCR::startPid(int pid)
747 dmx_pes_filter_params pes;
750 pes.input = DMX_IN_FRONTEND;
751 pes.output = DMX_OUT_DECODER;
752 pes.pes_type = m_dev ? DMX_PES_PCR1 : DMX_PES_PCR0; /* FIXME */
754 eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - pcr - ", pid);
755 if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
757 eDebug("failed (%m)");
761 eDebugNoNewLine("DEMUX_START - pcr - ");
762 if (::ioctl(m_fd_demux, DMX_START) < 0)
764 eDebug("failed (%m)");
774 eDebugNoNewLine("DEMUX_STOP - pcr - ");
775 if (::ioctl(m_fd_demux, DMX_STOP) < 0)
776 eDebug("failed(%m)");
787 DEFINE_REF(eDVBTText);
789 eDVBTText::eDVBTText(eDVBDemux *demux, int dev)
790 :m_demux(demux), m_dev(dev)
793 #if HAVE_DVB_API_VERSION < 3
794 sprintf(filename, "/dev/dvb/card%d/demux%d", demux->adapter, demux->demux);
796 sprintf(filename, "/dev/dvb/adapter%d/demux%d", demux->adapter, demux->demux);
798 m_fd_demux = ::open(filename, O_RDWR);
800 eWarning("%s: %m", filename);
803 int eDVBTText::startPid(int pid)
807 dmx_pes_filter_params pes;
810 pes.input = DMX_IN_FRONTEND;
811 pes.output = DMX_OUT_DECODER;
812 pes.pes_type = m_dev ? DMX_PES_TELETEXT1 : DMX_PES_TELETEXT0; // FIXME
815 eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - ttx - ", pid);
816 if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
818 eDebug("failed(%m)");
822 eDebugNoNewLine("DEMUX_START - ttx - ");
823 if (::ioctl(m_fd_demux, DMX_START) < 0)
825 eDebug("failed(%m)");
832 void eDVBTText::stop()
834 eDebugNoNewLine("DEMUX_STOP - ttx - ");
835 if (::ioctl(m_fd_demux, DMX_STOP) < 0)
836 eDebug("failed(%m)");
841 eDVBTText::~eDVBTText()
847 DEFINE_REF(eTSMPEGDecoder);
849 int eTSMPEGDecoder::setState()
853 int noaudio = (m_state != statePlay) && (m_state != statePause);
854 int nott = noaudio; /* actually same conditions */
856 if ((noaudio && m_audio) || (!m_audio && !noaudio))
857 m_changed |= changeAudio | changeState;
859 if ((nott && m_text) || (!m_text && !nott))
860 m_changed |= changeText | changeState;
862 const char *decoder_states[] = {"stop", "pause", "play", "decoderfastforward", "trickmode", "slowmotion"};
863 eDebug("decoder state: %s, vpid=%d, apid=%d", decoder_states[m_state], m_vpid, m_apid);
865 int changed = m_changed;
866 #if HAVE_DVB_API_VERSION < 3
867 bool checkAVSync = m_changed & (changeAudio|changeVideo|changePCR);
868 if (m_changed & changeAudio && m_audio)
870 if (m_changed & changeVideo && m_video)
872 if (m_changed & changePCR && m_pcr)
876 if (!(m_pcrpid >= 0 && m_pcrpid < 0x1ff))
877 m_changed &= ~changePCR;
879 if (m_changed & changeAudio && m_audio)
883 if (!(m_apid >= 0 && m_apid < 0x1ff))
884 m_changed &= ~changeAudio;
886 if (m_changed & changeVideo && m_video)
890 m_video_event_conn=0;
891 if (!(m_vpid >= 0 && m_vpid < 0x1ff))
892 m_changed &= ~changeVideo;
894 if (m_changed & changeVideo)
896 m_video = new eDVBVideo(m_demux, m_decoder);
897 m_video->connectEvent(slot(*this, &eTSMPEGDecoder::video_event), m_video_event_conn);
898 if (m_video->setPid(m_vpid))
901 if (m_changed & changePCR)
903 m_pcr = new eDVBPCR(m_demux, m_decoder);
904 if (m_pcr->setPid(m_pcrpid))
907 if (m_changed & changeAudio)
909 m_audio = new eDVBAudio(m_demux, m_decoder);
910 if (m_audio->setPid(m_apid, m_atype))
913 if (m_changed & changePCR)
915 if (m_pcr->startPid())
917 m_changed &= ~changePCR;
919 else if (checkAVSync && m_audio && m_video)
921 if (m_audio->setAVSync(1))
924 if (m_changed & changeVideo)
926 if (m_video->startPid() || m_video->start())
928 m_changed &= ~changeVideo;
930 if (m_changed & changeAudio)
932 if (m_audio->start() || m_audio->startPid())
934 m_changed &= ~changeAudio;
937 if (m_changed & changePCR)
943 if (m_changed & changeVideo)
949 m_video_event_conn = 0;
952 if (m_changed & changeAudio)
958 if (m_changed & changeText)
964 if (m_changed & changePCR)
966 if ((m_pcrpid >= 0) && (m_pcrpid < 0x1FFF))
968 m_pcr = new eDVBPCR(m_demux, m_decoder);
969 if (m_pcr->startPid(m_pcrpid))
972 m_changed &= ~changePCR;
974 if (m_changed & changeAudio)
976 if ((m_apid >= 0) && (m_apid < 0x1FFF) && !noaudio)
978 m_audio = new eDVBAudio(m_demux, m_decoder);
979 if (m_audio->startPid(m_apid, m_atype))
982 m_changed &= ~changeAudio;
984 if (m_changed & changeVideo)
986 if ((m_vpid >= 0) && (m_vpid < 0x1FFF))
988 m_video = new eDVBVideo(m_demux, m_decoder);
989 m_video->connectEvent(slot(*this, &eTSMPEGDecoder::video_event), m_video_event_conn);
990 if (m_video->startPid(m_vpid, m_vtype))
993 m_changed &= ~changeVideo;
995 if (m_changed & changeText)
997 if ((m_textpid >= 0) && (m_textpid < 0x1FFF) && !nott)
999 m_text = new eDVBTText(m_demux, m_decoder);
1000 if (m_text->startPid(m_textpid))
1003 m_changed &= ~changeText;
1007 if (changed & (changeState|changeVideo|changeAudio))
1009 /* play, slowmotion, fast-forward */
1010 int state_table[6][4] =
1012 /* [stateStop] = */ {0, 0, 0},
1013 /* [statePause] = */ {0, 0, 0},
1014 /* [statePlay] = */ {1, 0, 0},
1015 /* [stateDecoderFastForward] = */ {1, 0, m_ff_sm_ratio},
1016 /* [stateHighspeedFastForward] = */ {1, 0, 1},
1017 /* [stateSlowMotion] = */ {1, m_ff_sm_ratio, 0}
1019 int *s = state_table[m_state];
1020 if (changed & (changeState|changeVideo) && m_video)
1022 m_video->setSlowMotion(s[1]);
1023 m_video->setFastForward(s[2]);
1025 m_video->unfreeze();
1029 if (changed & (changeState|changeAudio) && m_audio)
1032 m_audio->unfreeze();
1036 m_changed &= ~changeState;
1039 if (changed && !m_video && m_audio && m_radio_pic.length())
1040 showSinglePic(m_radio_pic.c_str());
1045 int eTSMPEGDecoder::m_pcm_delay=-1,
1046 eTSMPEGDecoder::m_ac3_delay=-1;
1048 RESULT eTSMPEGDecoder::setHwPCMDelay(int delay)
1050 if (delay != m_pcm_delay )
1052 FILE *fp = fopen("/proc/stb/audio/audio_delay_pcm", "w");
1055 fprintf(fp, "%x", delay*90);
1057 m_pcm_delay = delay;
1064 RESULT eTSMPEGDecoder::setHwAC3Delay(int delay)
1066 if ( delay != m_ac3_delay )
1068 FILE *fp = fopen("/proc/stb/audio/audio_delay_bitstream", "w");
1071 fprintf(fp, "%x", delay*90);
1073 m_ac3_delay = delay;
1081 RESULT eTSMPEGDecoder::setPCMDelay(int delay)
1083 return m_decoder == 0 ? setHwPCMDelay(delay) : -1;
1086 RESULT eTSMPEGDecoder::setAC3Delay(int delay)
1088 return m_decoder == 0 ? setHwAC3Delay(delay) : -1;
1091 eTSMPEGDecoder::eTSMPEGDecoder(eDVBDemux *demux, int decoder)
1093 m_vpid(-1), m_vtype(-1), m_apid(-1), m_atype(-1), m_pcrpid(-1), m_textpid(-1),
1094 m_changed(0), m_decoder(decoder), m_video_clip_fd(-1), m_showSinglePicTimer(eTimer::create(eApp))
1096 demux->connectEvent(slot(*this, &eTSMPEGDecoder::demux_event), m_demux_event_conn);
1097 CONNECT(m_showSinglePicTimer->timeout, eTSMPEGDecoder::finishShowSinglePic);
1098 m_state = stateStop;
1101 eTSMPEGDecoder::~eTSMPEGDecoder()
1103 finishShowSinglePic();
1104 m_vpid = m_apid = m_pcrpid = m_textpid = pidNone;
1109 RESULT eTSMPEGDecoder::setVideoPID(int vpid, int type)
1111 if ((m_vpid != vpid) || (m_vtype != type))
1113 m_changed |= changeVideo;
1120 RESULT eTSMPEGDecoder::setAudioPID(int apid, int type)
1122 if ((m_apid != apid) || (m_atype != type))
1124 m_changed |= changeAudio;
1131 int eTSMPEGDecoder::m_audio_channel = -1;
1133 RESULT eTSMPEGDecoder::setAudioChannel(int channel)
1136 channel = ac_stereo;
1137 if (m_decoder == 0 && m_audio_channel != channel)
1141 m_audio->setChannel(channel);
1142 m_audio_channel=channel;
1145 eDebug("eTSMPEGDecoder::setAudioChannel but no audio decoder exist");
1150 int eTSMPEGDecoder::getAudioChannel()
1152 return m_audio_channel == -1 ? ac_stereo : m_audio_channel;
1155 RESULT eTSMPEGDecoder::setSyncPCR(int pcrpid)
1157 if (m_pcrpid != pcrpid)
1159 m_changed |= changePCR;
1165 RESULT eTSMPEGDecoder::setTextPID(int textpid)
1167 if (m_textpid != textpid)
1169 m_changed |= changeText;
1170 m_textpid = textpid;
1175 RESULT eTSMPEGDecoder::setSyncMaster(int who)
1180 RESULT eTSMPEGDecoder::set()
1185 RESULT eTSMPEGDecoder::play()
1187 if (m_state == statePlay)
1193 m_state = statePlay;
1194 m_changed |= changeState;
1199 RESULT eTSMPEGDecoder::pause()
1201 if (m_state == statePause)
1203 m_state = statePause;
1204 m_changed |= changeState;
1208 RESULT eTSMPEGDecoder::setFastForward(int frames_to_skip)
1210 if ((m_state == stateDecoderFastForward) && (m_ff_sm_ratio == frames_to_skip))
1213 m_state = stateDecoderFastForward;
1214 m_ff_sm_ratio = frames_to_skip;
1215 m_changed |= changeState;
1218 // return m_video->setFastForward(frames_to_skip);
1221 RESULT eTSMPEGDecoder::setSlowMotion(int repeat)
1223 if ((m_state == stateSlowMotion) && (m_ff_sm_ratio == repeat))
1226 m_state = stateSlowMotion;
1227 m_ff_sm_ratio = repeat;
1228 m_changed |= changeState;
1232 RESULT eTSMPEGDecoder::setTrickmode()
1234 if (m_state == stateTrickmode)
1237 m_state = stateTrickmode;
1238 m_changed |= changeState;
1242 RESULT eTSMPEGDecoder::flush()
1251 void eTSMPEGDecoder::demux_event(int event)
1255 case eDVBDemux::evtFlush:
1263 RESULT eTSMPEGDecoder::getPTS(int what, pts_t &pts)
1265 if (what == 0) /* auto */
1266 what = m_video ? 1 : 2;
1268 if (what == 1) /* video */
1271 return m_video->getPTS(pts);
1276 if (what == 2) /* audio */
1279 return m_audio->getPTS(pts);
1287 RESULT eTSMPEGDecoder::setRadioPic(const std::string &filename)
1289 m_radio_pic = filename;
1293 RESULT eTSMPEGDecoder::showSinglePic(const char *filename)
1297 eDebug("showSinglePic %s", filename);
1298 int f = open(filename, O_RDONLY);
1303 if (m_video_clip_fd == -1)
1304 m_video_clip_fd = open("/dev/dvb/adapter0/video0", O_WRONLY|O_NONBLOCK);
1305 if (m_video_clip_fd >= 0)
1307 bool seq_end_avail = false;
1309 unsigned char pes_header[] = { 0x00, 0x00, 0x01, 0xE0, 0x00, 0x00, 0x80, 0x00, 0x00 };
1310 unsigned char seq_end[] = { 0x00, 0x00, 0x01, 0xB7 };
1311 unsigned char iframe[s.st_size];
1312 unsigned char stuffing[8192];
1313 int streamtype = VIDEO_STREAMTYPE_MPEG2;
1314 memset(stuffing, 0, 8192);
1315 read(f, iframe, s.st_size);
1316 if (ioctl(m_video_clip_fd, VIDEO_SELECT_SOURCE, VIDEO_SOURCE_MEMORY) < 0)
1317 eDebug("VIDEO_SELECT_SOURCE MEMORY failed (%m)");
1318 if (ioctl(m_video_clip_fd, VIDEO_SET_STREAMTYPE, streamtype) < 0)
1319 eDebug("VIDEO_SET_STREAMTYPE failed(%m)");
1320 if (ioctl(m_video_clip_fd, VIDEO_PLAY) < 0)
1321 eDebug("VIDEO_PLAY failed (%m)");
1322 if (ioctl(m_video_clip_fd, VIDEO_CONTINUE) < 0)
1323 eDebug("video: VIDEO_CONTINUE: %m");
1324 if (ioctl(m_video_clip_fd, VIDEO_CLEAR_BUFFER) < 0)
1325 eDebug("video: VIDEO_CLEAR_BUFFER: %m");
1326 while(pos <= (s.st_size-4) && !(seq_end_avail = (!iframe[pos] && !iframe[pos+1] && iframe[pos+2] == 1 && iframe[pos+3] == 0xB7)))
1328 if ((iframe[3] >> 4) != 0xE) // no pes header
1329 write(m_video_clip_fd, pes_header, sizeof(pes_header));
1331 iframe[4] = iframe[5] = 0x00;
1332 write(m_video_clip_fd, iframe, s.st_size);
1334 write(m_video_clip_fd, seq_end, sizeof(seq_end));
1335 write(m_video_clip_fd, stuffing, 8192);
1336 m_showSinglePicTimer->start(150, true);
1342 eDebug("couldnt open %s", filename);
1348 eDebug("only show single pics on first decoder");
1354 void eTSMPEGDecoder::finishShowSinglePic()
1356 if (m_video_clip_fd >= 0)
1358 if (ioctl(m_video_clip_fd, VIDEO_STOP, 0) < 0)
1359 eDebug("VIDEO_STOP failed (%m)");
1360 if (ioctl(m_video_clip_fd, VIDEO_SELECT_SOURCE, VIDEO_SOURCE_DEMUX) < 0)
1361 eDebug("VIDEO_SELECT_SOURCE DEMUX failed (%m)");
1362 close(m_video_clip_fd);
1363 m_video_clip_fd = -1;
1367 RESULT eTSMPEGDecoder::connectVideoEvent(const Slot1<void, struct videoEvent> &event, ePtr<eConnection> &conn)
1369 conn = new eConnection(this, m_video_event.connect(event));
1373 void eTSMPEGDecoder::video_event(struct videoEvent event)
1375 /* emit */ m_video_event(event);
1378 int eTSMPEGDecoder::getVideoWidth()
1381 return m_video->getWidth();
1385 int eTSMPEGDecoder::getVideoHeight()
1388 return m_video->getHeight();
1392 int eTSMPEGDecoder::getVideoProgressive()
1395 return m_video->getProgressive();
1399 int eTSMPEGDecoder::getVideoFrameRate()
1402 return m_video->getFrameRate();
1406 int eTSMPEGDecoder::getVideoAspect()
1409 return m_video->getAspect();