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_VIDEO1 DMX_PES_VIDEO
16 #define DMX_PES_AUDIO1 DMX_PES_AUDIO
18 #include <ost/video.h>
19 #include <ost/audio.h>
21 #include <linux/dvb/audio.h>
22 #include <linux/dvb/video.h>
23 #include <linux/dvb/dmx.h>
28 #include <sys/ioctl.h>
29 #include <sys/types.h>
33 /* these are quite new... */
35 #define AUDIO_GET_PTS _IOR('o', 19, __u64)
36 #define VIDEO_GET_PTS _IOR('o', 57, __u64)
39 DEFINE_REF(eDVBAudio);
41 eDVBAudio::eDVBAudio(eDVBDemux *demux, int dev)
42 :m_demux(demux), m_dev(dev)
45 #if HAVE_DVB_API_VERSION < 3
46 sprintf(filename, "/dev/dvb/card%d/audio%d", demux->adapter, dev);
48 sprintf(filename, "/dev/dvb/adapter%d/audio%d", demux->adapter, dev);
50 m_fd = ::open(filename, O_RDWR);
52 eWarning("%s: %m", filename);
53 #if HAVE_DVB_API_VERSION < 3
54 sprintf(filename, "/dev/dvb/card%d/demux%d", demux->adapter, demux->demux);
56 sprintf(filename, "/dev/dvb/adapter%d/demux%d", demux->adapter, demux->demux);
58 m_fd_demux = ::open(filename, O_RDWR);
60 eWarning("%s: %m", filename);
63 #if HAVE_DVB_API_VERSION < 3
64 int eDVBAudio::setPid(int pid, int type)
66 if ((m_fd < 0) || (m_fd_demux < 0))
86 if (::ioctl(m_fd, AUDIO_SET_BYPASS_MODE, bypass) < 0)
87 eDebug("failed (%m)");
89 dmx_pes_filter_params pes;
92 pes.input = DMX_IN_FRONTEND;
93 pes.output = DMX_OUT_DECODER;
94 pes.pes_type = m_dev ? DMX_PES_AUDIO1 : DMX_PES_AUDIO0; /* FIXME */
96 eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - audio - ", pid);
97 if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
99 eDebug("failed (%m)");
107 int eDVBAudio::startPid()
109 eDebugNoNewLine("DEMUX_START - audio - ");
110 if (::ioctl(m_fd_demux, DMX_START) < 0)
112 eDebug("failed (%m)");
119 int eDVBAudio::start()
121 eDebugNoNewLine("AUDIO_PLAY - ");
122 if (::ioctl(m_fd, AUDIO_PLAY) < 0)
124 eDebug("failed (%m)");
131 int eDVBAudio::stopPid()
133 eDebugNoNewLine("DEMUX_STOP - audio - ");
134 if (::ioctl(m_fd_demux, DMX_STOP) < 0)
136 eDebug("failed (%m)");
143 int eDVBAudio::setAVSync(int val)
145 eDebugNoNewLine("AUDIO_SET_AV_SYNC - ");
146 if (::ioctl(m_fd, AUDIO_SET_AV_SYNC, val) < 0)
148 eDebug("failed (%m)");
155 int eDVBAudio::startPid(int pid, int type)
157 if ((m_fd < 0) || (m_fd_demux < 0))
159 dmx_pes_filter_params pes;
162 pes.input = DMX_IN_FRONTEND;
163 pes.output = DMX_OUT_DECODER;
164 pes.pes_type = m_dev ? DMX_PES_AUDIO1 : DMX_PES_AUDIO0; /* FIXME */
166 eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - audio - ", pid);
167 if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
169 eDebug("failed (%m)");
173 eDebugNoNewLine("DEMUX_START - audio - ");
174 if (::ioctl(m_fd_demux, DMX_START) < 0)
176 eDebug("failed (%m)");
201 eDebugNoNewLine("AUDIO_SET_BYPASS(%d) - ", bypass);
202 if (::ioctl(m_fd, AUDIO_SET_BYPASS_MODE, bypass) < 0)
203 eDebug("failed (%m)");
206 freeze(); // why freeze here?!? this is a problem when only a pid change is requested... because of the unfreeze logic in Decoder::setState
207 eDebugNoNewLine("AUDIO_PLAY - ");
208 if (::ioctl(m_fd, AUDIO_PLAY) < 0)
209 eDebug("failed (%m)");
216 void eDVBAudio::stop()
218 #if HAVE_DVB_API_VERSION > 2
221 eDebugNoNewLine("AUDIO_STOP - ");
222 if (::ioctl(m_fd, AUDIO_STOP) < 0)
223 eDebug("failed (%m)");
226 #if HAVE_DVB_API_VERSION > 2
227 eDebugNoNewLine("DEMUX_STOP - audio - ");
228 if (::ioctl(m_fd_demux, DMX_STOP) < 0)
229 eDebug("failed (%m)");
235 void eDVBAudio::flush()
237 eDebugNoNewLine("AUDIO_CLEAR_BUFFER - ");
238 if (::ioctl(m_fd, AUDIO_CLEAR_BUFFER) < 0)
239 eDebug("failed (%m)");
244 void eDVBAudio::freeze()
246 eDebugNoNewLine("AUDIO_PAUSE - ");
247 if (::ioctl(m_fd, AUDIO_PAUSE) < 0)
248 eDebug("failed (%m)");
253 void eDVBAudio::unfreeze()
255 eDebugNoNewLine("AUDIO_CONTINUE - ");
256 if (::ioctl(m_fd, AUDIO_CONTINUE) < 0)
257 eDebug("failed (%m)");
262 void eDVBAudio::setChannel(int channel)
264 int val = AUDIO_STEREO;
267 case aMonoLeft: val = AUDIO_MONO_LEFT; break;
268 case aMonoRight: val = AUDIO_MONO_RIGHT; break;
271 eDebugNoNewLine("AUDIO_CHANNEL_SELECT(%d) - ", val);
272 if (::ioctl(m_fd, AUDIO_CHANNEL_SELECT, val) < 0)
273 eDebug("failed (%m)");
278 int eDVBAudio::getPTS(pts_t &now)
280 if (::ioctl(m_fd, AUDIO_GET_PTS, &now) < 0)
281 eDebug("AUDIO_GET_PTS failed (%m)");
285 eDVBAudio::~eDVBAudio()
287 unfreeze(); // why unfreeze here... but not unfreeze video in ~eDVBVideo ?!?
294 DEFINE_REF(eDVBVideo);
296 eDVBVideo::eDVBVideo(eDVBDemux *demux, int dev)
297 : m_demux(demux), m_dev(dev),
298 m_width(-1), m_height(-1), m_framerate(-1), m_aspect(-1), m_progressive(-1)
301 #if HAVE_DVB_API_VERSION < 3
302 sprintf(filename, "/dev/dvb/card%d/video%d", demux->adapter, dev);
303 m_fd_video = ::open("/dev/video", O_RDWR);
305 eWarning("/dev/video: %m");
307 sprintf(filename, "/dev/dvb/adapter%d/video%d", demux->adapter, dev);
309 m_fd = ::open(filename, O_RDWR);
311 eWarning("%s: %m", filename);
314 m_sn = eSocketNotifier::create(eApp, m_fd, eSocketNotifier::Priority);
315 CONNECT(m_sn->activated, eDVBVideo::video_event);
317 eDebug("Video Device: %s", filename);
318 #if HAVE_DVB_API_VERSION < 3
319 sprintf(filename, "/dev/dvb/card%d/demux%d", demux->adapter, demux->demux);
321 sprintf(filename, "/dev/dvb/adapter%d/demux%d", demux->adapter, demux->demux);
323 m_fd_demux = ::open(filename, O_RDWR);
325 eWarning("%s: %m", filename);
326 eDebug("demux device: %s", filename);
329 // not finally values i think.. !!
330 #define VIDEO_STREAMTYPE_MPEG2 0
331 #define VIDEO_STREAMTYPE_MPEG4_H264 1
332 #define VIDEO_STREAMTYPE_VC1 3
333 #define VIDEO_STREAMTYPE_MPEG4_Part2 4
334 #define VIDEO_STREAMTYPE_VC1_SM 5
335 #define VIDEO_STREAMTYPE_MPEG1 6
337 #if HAVE_DVB_API_VERSION < 3
338 int eDVBVideo::setPid(int pid)
340 if ((m_fd < 0) || (m_fd_demux < 0))
342 dmx_pes_filter_params pes;
345 pes.input = DMX_IN_FRONTEND;
346 pes.output = DMX_OUT_DECODER;
347 pes.pes_type = m_dev ? DMX_PES_VIDEO1 : DMX_PES_VIDEO0; /* FIXME */
349 eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - video - ", pid);
350 if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
352 eDebug("failed (%m)");
359 int eDVBVideo::startPid()
361 eDebugNoNewLine("DEMUX_START - video - ");
362 if (::ioctl(m_fd_demux, DMX_START) < 0)
364 eDebug("failed (%m)");
371 int eDVBVideo::start()
373 eDebugNoNewLine("VIDEO_PLAY - ");
374 if (::ioctl(m_fd, VIDEO_PLAY) < 0)
376 eDebug("failed (%m)");
383 int eDVBVideo::stopPid()
385 eDebugNoNewLine("DEMUX_STOP - video - ");
386 if (::ioctl(m_fd_demux, DMX_STOP) < 0)
388 eDebug("failed (%m)");
395 int eDVBVideo::startPid(int pid, int type)
397 int streamtype = VIDEO_STREAMTYPE_MPEG2;
399 if ((m_fd < 0) || (m_fd_demux < 0))
401 dmx_pes_filter_params pes;
409 streamtype = VIDEO_STREAMTYPE_MPEG4_H264;
412 streamtype = VIDEO_STREAMTYPE_MPEG1;
415 streamtype = VIDEO_STREAMTYPE_MPEG4_Part2;
418 streamtype = VIDEO_STREAMTYPE_VC1;
421 streamtype = VIDEO_STREAMTYPE_VC1_SM;
425 eDebugNoNewLine("VIDEO_SET_STREAMTYPE %d - ", streamtype);
426 if (::ioctl(m_fd, VIDEO_SET_STREAMTYPE, streamtype) < 0)
427 eDebug("failed (%m)");
432 pes.input = DMX_IN_FRONTEND;
433 pes.output = DMX_OUT_DECODER;
434 pes.pes_type = m_dev ? DMX_PES_VIDEO1 : DMX_PES_VIDEO0; /* FIXME */
436 eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - video - ", pid);
437 if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
439 eDebug("failed (%m)");
443 eDebugNoNewLine("DEMUX_START - video - ");
444 if (::ioctl(m_fd_demux, DMX_START) < 0)
446 eDebug("failed (%m)");
450 freeze(); // why freeze here?!? this is a problem when only a pid change is requested... because of the unfreeze logic in Decoder::setState
451 eDebugNoNewLine("VIDEO_PLAY - ");
452 if (::ioctl(m_fd, VIDEO_PLAY) < 0)
453 eDebug("failed (%m)");
460 void eDVBVideo::stop()
462 #if HAVE_DVB_API_VERSION > 2
463 eDebugNoNewLine("DEMUX_STOP - video - ");
464 if (::ioctl(m_fd_demux, DMX_STOP) < 0)
465 eDebug("failed (%m)");
469 eDebugNoNewLine("VIDEO_STOP - ");
470 if (::ioctl(m_fd, VIDEO_STOP, 1) < 0)
471 eDebug("failed (%m)");
476 void eDVBVideo::flush()
478 eDebugNoNewLine("VIDEO_CLEAR_BUFFER - ");
479 if (::ioctl(m_fd, VIDEO_CLEAR_BUFFER) < 0)
480 eDebug("failed (%m)");
485 void eDVBVideo::freeze()
487 eDebugNoNewLine("VIDEO_FREEZE - ");
488 if (::ioctl(m_fd, VIDEO_FREEZE) < 0)
489 eDebug("failed (%m)");
494 void eDVBVideo::unfreeze()
496 eDebugNoNewLine("VIDEO_CONTINUE - ");
497 if (::ioctl(m_fd, VIDEO_CONTINUE) < 0)
498 eDebug("failed (%m)");
503 int eDVBVideo::setSlowMotion(int repeat)
505 eDebugNoNewLine("VIDEO_SLOWMOTION(%d) - ", repeat);
506 int ret = ::ioctl(m_fd, VIDEO_SLOWMOTION, repeat);
508 eDebug("failed(%m)");
514 int eDVBVideo::setFastForward(int skip)
516 eDebugNoNewLine("VIDEO_FAST_FORWARD(%d) - ", skip);
517 int ret = ::ioctl(m_fd, VIDEO_FAST_FORWARD, skip);
519 eDebug("failed(%m)");
525 int eDVBVideo::getPTS(pts_t &now)
527 #if HAVE_DVB_API_VERSION < 3
528 #define VIDEO_GET_PTS_OLD _IOR('o', 1, unsigned int*)
530 int ret = ::ioctl(m_fd_video, VIDEO_GET_PTS_OLD, &pts);
534 int ret = ::ioctl(m_fd, VIDEO_GET_PTS, &now);
537 eDebug("VIDEO_GET_PTS failed(%m)");
541 eDVBVideo::~eDVBVideo()
547 #if HAVE_DVB_API_VERSION < 3
553 void eDVBVideo::video_event(int)
555 #if HAVE_DVB_API_VERSION >= 3
556 struct video_event evt;
557 eDebugNoNewLine("VIDEO_GET_EVENT - ");
558 if (::ioctl(m_fd, VIDEO_GET_EVENT, &evt) < 0)
559 eDebug("failed (%m)");
563 if (evt.type == VIDEO_EVENT_SIZE_CHANGED)
565 struct iTSMPEGDecoder::videoEvent event;
566 event.type = iTSMPEGDecoder::videoEvent::eventSizeChanged;
567 m_aspect = event.aspect = evt.u.size.aspect_ratio == 0 ? 2 : 3; // convert dvb api to etsi
568 m_height = event.height = evt.u.size.h;
569 m_width = event.width = evt.u.size.w;
570 /* emit */ m_event(event);
572 else if (evt.type == VIDEO_EVENT_FRAME_RATE_CHANGED)
574 struct iTSMPEGDecoder::videoEvent event;
575 event.type = iTSMPEGDecoder::videoEvent::eventFrameRateChanged;
576 m_framerate = event.framerate = evt.u.frame_rate;
577 /* emit */ m_event(event);
579 else if (evt.type == 16 /*VIDEO_EVENT_PROGRESSIVE_CHANGED*/)
581 struct iTSMPEGDecoder::videoEvent event;
582 event.type = iTSMPEGDecoder::videoEvent::eventProgressiveChanged;
583 m_progressive = event.progressive = evt.u.frame_rate;
584 /* emit */ m_event(event);
587 eDebug("unhandled DVBAPI Video Event %d", evt.type);
590 #warning "FIXMEE!! Video Events not implemented for old api"
594 RESULT eDVBVideo::connectEvent(const Slot1<void, struct iTSMPEGDecoder::videoEvent> &event, ePtr<eConnection> &conn)
596 conn = new eConnection(this, m_event.connect(event));
600 static int readMpegProc(char *str, int decoder)
604 sprintf(tmp, "/proc/stb/vmpeg/%d/%s", decoder, str);
605 FILE *f = fopen(tmp, "r");
608 fscanf(f, "%x", &val);
614 static int readApiSize(int fd, int &xres, int &yres, int &aspect)
616 #if HAVE_DVB_API_VERSION >= 3
618 if (!::ioctl(fd, VIDEO_GET_SIZE, &size))
622 aspect = size.aspect_ratio == 0 ? 2 : 3; // convert dvb api to etsi
625 // eDebug("VIDEO_GET_SIZE failed (%m)");
630 static int readApiFrameRate(int fd, int &framerate)
632 #if HAVE_DVB_API_VERSION >= 3
634 if (!::ioctl(fd, VIDEO_GET_FRAME_RATE, &frate))
639 // eDebug("VIDEO_GET_FRAME_RATE failed (%m)");
644 int eDVBVideo::getWidth()
647 readApiSize(m_fd, m_width, m_height, m_aspect);
649 m_width = readMpegProc("xres", m_dev);
653 int eDVBVideo::getHeight()
656 readApiSize(m_fd, m_width, m_height, m_aspect);
658 m_height = readMpegProc("yres", m_dev);
662 int eDVBVideo::getAspect()
665 readApiSize(m_fd, m_width, m_height, m_aspect);
667 m_aspect = readMpegProc("aspect", m_dev);
671 int eDVBVideo::getProgressive()
673 if (m_progressive == -1)
674 m_progressive = readMpegProc("progressive", m_dev);
675 return m_progressive;
678 int eDVBVideo::getFrameRate()
680 if (m_framerate == -1)
681 readApiFrameRate(m_fd, m_framerate);
682 if (m_framerate == -1)
683 m_framerate = readMpegProc("framerate", m_dev);
689 eDVBPCR::eDVBPCR(eDVBDemux *demux): m_demux(demux)
692 #if HAVE_DVB_API_VERSION < 3
693 sprintf(filename, "/dev/dvb/card%d/demux%d", demux->adapter, demux->demux);
695 sprintf(filename, "/dev/dvb/adapter%d/demux%d", demux->adapter, demux->demux);
697 m_fd_demux = ::open(filename, O_RDWR);
699 eWarning("%s: %m", filename);
702 #if HAVE_DVB_API_VERSION < 3
703 int eDVBPCR::setPid(int pid)
707 dmx_pes_filter_params pes;
710 pes.input = DMX_IN_FRONTEND;
711 pes.output = DMX_OUT_DECODER;
712 pes.pes_type = DMX_PES_PCR;
715 eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - pcr - ", pid);
716 if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
718 eDebug("failed (%m)");
725 int eDVBPCR::startPid()
729 eDebugNoNewLine("DEMUX_START - pcr - ");
730 if (::ioctl(m_fd_demux, DMX_START) < 0)
732 eDebug("failed (%m)");
739 int eDVBPCR::startPid(int pid)
743 dmx_pes_filter_params pes;
746 pes.input = DMX_IN_FRONTEND;
747 pes.output = DMX_OUT_DECODER;
748 pes.pes_type = DMX_PES_PCR;
750 eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - pcr - ", pid);
751 if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
753 eDebug("failed (%m)");
757 eDebugNoNewLine("DEMUX_START - pcr - ");
758 if (::ioctl(m_fd_demux, DMX_START) < 0)
760 eDebug("failed (%m)");
770 eDebugNoNewLine("DEMUX_STOP - pcr - ");
771 if (::ioctl(m_fd_demux, DMX_STOP) < 0)
772 eDebug("failed(%m)");
783 DEFINE_REF(eDVBTText);
785 eDVBTText::eDVBTText(eDVBDemux *demux): m_demux(demux)
788 #if HAVE_DVB_API_VERSION < 3
789 sprintf(filename, "/dev/dvb/card%d/demux%d", demux->adapter, demux->demux);
791 sprintf(filename, "/dev/dvb/adapter%d/demux%d", demux->adapter, demux->demux);
793 m_fd_demux = ::open(filename, O_RDWR);
795 eWarning("%s: %m", filename);
798 int eDVBTText::startPid(int pid)
802 dmx_pes_filter_params pes;
805 pes.input = DMX_IN_FRONTEND;
806 pes.output = DMX_OUT_DECODER;
807 pes.pes_type = DMX_PES_TELETEXT;
810 eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - ttx - ", pid);
811 if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
813 eDebug("failed(%m)");
817 eDebugNoNewLine("DEMUX_START - ttx - ");
818 if (::ioctl(m_fd_demux, DMX_START) < 0)
820 eDebug("failed(%m)");
827 void eDVBTText::stop()
829 eDebugNoNewLine("DEMUX_STOP - ttx - ");
830 if (::ioctl(m_fd_demux, DMX_STOP) < 0)
831 eDebug("failed(%m)");
836 eDVBTText::~eDVBTText()
842 DEFINE_REF(eTSMPEGDecoder);
844 int eTSMPEGDecoder::setState()
848 int noaudio = (m_state != statePlay) && (m_state != statePause);
849 int nott = noaudio; /* actually same conditions */
851 if ((noaudio && m_audio) || (!m_audio && !noaudio))
852 m_changed |= changeAudio | changeState;
854 if ((nott && m_text) || (!m_text && !nott))
855 m_changed |= changeText | changeState;
857 const char *decoder_states[] = {"stop", "pause", "play", "decoderfastforward", "trickmode", "slowmotion"};
858 eDebug("decoder state: %s, vpid=%d, apid=%d", decoder_states[m_state], m_vpid, m_apid);
860 bool changed = !!m_changed;
861 #if HAVE_DVB_API_VERSION < 3
862 bool checkAVSync = m_changed & (changeAudio|changeVideo|changePCR);
863 if (m_changed & changeAudio && m_audio)
865 if (m_changed & changeVideo && m_video)
867 if (m_changed & changePCR && m_pcr)
871 if (!(m_pcrpid >= 0 && m_pcrpid < 0x1ff))
872 m_changed &= ~changePCR;
874 if (m_changed & changeAudio && m_audio)
878 if (!(m_apid >= 0 && m_apid < 0x1ff))
879 m_changed &= ~changeAudio;
881 if (m_changed & changeVideo && m_video)
885 m_video_event_conn=0;
886 if (!(m_vpid >= 0 && m_vpid < 0x1ff))
887 m_changed &= ~changeVideo;
889 if (m_changed & changeVideo)
891 m_video = new eDVBVideo(m_demux, m_decoder);
892 m_video->connectEvent(slot(*this, &eTSMPEGDecoder::video_event), m_video_event_conn);
893 if (m_video->setPid(m_vpid))
896 if (m_changed & changePCR)
898 m_pcr = new eDVBPCR(m_demux);
899 if (m_pcr->setPid(m_pcrpid))
902 if (m_changed & changeAudio)
904 m_audio = new eDVBAudio(m_demux, m_decoder);
905 if (m_audio->setPid(m_apid, m_atype))
908 if (m_changed & changePCR)
910 if (m_pcr->startPid())
912 m_changed &= ~changePCR;
914 else if (checkAVSync && m_audio && m_video)
916 if (m_audio->setAVSync(1))
919 if (m_changed & changeVideo)
921 if (m_video->startPid() || m_video->start())
923 m_changed &= ~changeVideo;
925 if (m_changed & changeAudio)
927 if (m_audio->start() || m_audio->startPid())
929 m_changed &= ~changeAudio;
932 if (m_changed & changePCR)
938 if (m_changed & changeVideo)
944 m_video_event_conn = 0;
947 if (m_changed & changeAudio)
953 if (m_changed & changeText)
959 if (m_changed & changePCR)
961 if ((m_pcrpid >= 0) && (m_pcrpid < 0x1FFF))
963 m_pcr = new eDVBPCR(m_demux);
964 if (m_pcr->startPid(m_pcrpid))
967 m_changed &= ~changePCR;
969 if (m_changed & changeAudio)
971 if ((m_apid >= 0) && (m_apid < 0x1FFF) && !noaudio)
973 m_audio = new eDVBAudio(m_demux, m_decoder);
974 if (m_audio->startPid(m_apid, m_atype))
977 m_changed &= ~changeAudio;
979 if (m_changed & changeVideo)
981 if ((m_vpid >= 0) && (m_vpid < 0x1FFF))
983 m_video = new eDVBVideo(m_demux, m_decoder);
984 m_video->connectEvent(slot(*this, &eTSMPEGDecoder::video_event), m_video_event_conn);
985 if (m_video->startPid(m_vpid, m_vtype))
988 m_changed &= ~changeVideo;
990 if (m_changed & changeText)
992 if ((m_textpid >= 0) && (m_textpid < 0x1FFF) && !nott)
994 m_text = new eDVBTText(m_demux);
995 if (m_text->startPid(m_textpid))
998 m_changed &= ~changeText;
1002 if (m_changed & changeState)
1004 /* play, slowmotion, fast-forward */
1005 int state_table[6][4] =
1007 /* [stateStop] = */ {0, 0, 0},
1008 /* [statePause] = */ {0, 0, 0},
1009 /* [statePlay] = */ {1, 0, 0},
1010 /* [stateDecoderFastForward] = */ {1, 0, m_ff_sm_ratio},
1011 /* [stateHighspeedFastForward] = */ {1, 0, 1},
1012 /* [stateSlowMotion] = */ {1, m_ff_sm_ratio, 0}
1014 int *s = state_table[m_state];
1017 m_video->setSlowMotion(s[1]);
1018 m_video->setFastForward(s[2]);
1020 m_video->unfreeze();
1027 m_audio->unfreeze();
1031 m_changed &= ~changeState;
1034 if (changed && !m_video && m_audio && m_radio_pic.length())
1035 showSinglePic(m_radio_pic.c_str());
1040 int eTSMPEGDecoder::m_pcm_delay=-1,
1041 eTSMPEGDecoder::m_ac3_delay=-1;
1043 RESULT eTSMPEGDecoder::setPCMDelay(int delay)
1045 if (m_decoder == 0 && delay != m_pcm_delay )
1047 FILE *fp = fopen("/proc/stb/audio/audio_delay_pcm", "w");
1050 fprintf(fp, "%x", delay*90);
1052 m_pcm_delay = delay;
1059 RESULT eTSMPEGDecoder::setAC3Delay(int delay)
1061 if ( m_decoder == 0 && delay != m_ac3_delay )
1063 FILE *fp = fopen("/proc/stb/audio/audio_delay_bitstream", "w");
1066 fprintf(fp, "%x", delay*90);
1068 m_ac3_delay = delay;
1075 eTSMPEGDecoder::eTSMPEGDecoder(eDVBDemux *demux, int decoder)
1077 m_vpid(-1), m_vtype(-1), m_apid(-1), m_atype(-1), m_pcrpid(-1), m_textpid(-1),
1078 m_changed(0), m_decoder(decoder), m_video_clip_fd(-1), m_showSinglePicTimer(eTimer::create(eApp))
1080 demux->connectEvent(slot(*this, &eTSMPEGDecoder::demux_event), m_demux_event_conn);
1081 CONNECT(m_showSinglePicTimer->timeout, eTSMPEGDecoder::finishShowSinglePic);
1082 m_state = stateStop;
1085 eTSMPEGDecoder::~eTSMPEGDecoder()
1087 finishShowSinglePic();
1088 m_vpid = m_apid = m_pcrpid = m_textpid = pidNone;
1093 RESULT eTSMPEGDecoder::setVideoPID(int vpid, int type)
1095 if ((m_vpid != vpid) || (m_vtype != type))
1097 m_changed |= changeVideo;
1104 RESULT eTSMPEGDecoder::setAudioPID(int apid, int type)
1106 if ((m_apid != apid) || (m_atype != type))
1108 m_changed |= changeAudio;
1115 int eTSMPEGDecoder::m_audio_channel = -1;
1117 RESULT eTSMPEGDecoder::setAudioChannel(int channel)
1120 channel = ac_stereo;
1121 if (m_decoder == 0 && m_audio_channel != channel)
1125 m_audio->setChannel(channel);
1126 m_audio_channel=channel;
1129 eDebug("eTSMPEGDecoder::setAudioChannel but no audio decoder exist");
1134 int eTSMPEGDecoder::getAudioChannel()
1136 return m_audio_channel == -1 ? ac_stereo : m_audio_channel;
1139 RESULT eTSMPEGDecoder::setSyncPCR(int pcrpid)
1141 if (m_pcrpid != pcrpid)
1143 m_changed |= changePCR;
1149 RESULT eTSMPEGDecoder::setTextPID(int textpid)
1151 if (m_textpid != textpid)
1153 m_changed |= changeText;
1154 m_textpid = textpid;
1159 RESULT eTSMPEGDecoder::setSyncMaster(int who)
1164 RESULT eTSMPEGDecoder::set()
1169 RESULT eTSMPEGDecoder::play()
1171 if (m_state == statePlay)
1177 /* commented out because the changeState is needed to unfreeze decoders in decoder::setState... needed by normal pmt changes
1178 tmbinc please recheck this! */
1180 m_state = statePlay;
1181 m_changed |= changeState;
1186 RESULT eTSMPEGDecoder::pause()
1188 if (m_state == statePause)
1190 m_state = statePause;
1191 m_changed |= changeState;
1195 RESULT eTSMPEGDecoder::setFastForward(int frames_to_skip)
1197 if ((m_state == stateDecoderFastForward) && (m_ff_sm_ratio == frames_to_skip))
1200 m_state = stateDecoderFastForward;
1201 m_ff_sm_ratio = frames_to_skip;
1202 m_changed |= changeState;
1205 // return m_video->setFastForward(frames_to_skip);
1208 RESULT eTSMPEGDecoder::setSlowMotion(int repeat)
1210 if ((m_state == stateSlowMotion) && (m_ff_sm_ratio == repeat))
1213 m_state = stateSlowMotion;
1214 m_ff_sm_ratio = repeat;
1215 m_changed |= changeState;
1219 RESULT eTSMPEGDecoder::setTrickmode()
1221 if (m_state == stateTrickmode)
1224 m_state = stateTrickmode;
1225 m_changed |= changeState;
1229 RESULT eTSMPEGDecoder::flush()
1238 void eTSMPEGDecoder::demux_event(int event)
1242 case eDVBDemux::evtFlush:
1250 RESULT eTSMPEGDecoder::getPTS(int what, pts_t &pts)
1252 if (what == 0) /* auto */
1253 what = m_video ? 1 : 2;
1255 if (what == 1) /* video */
1258 return m_video->getPTS(pts);
1263 if (what == 2) /* audio */
1266 return m_audio->getPTS(pts);
1274 RESULT eTSMPEGDecoder::setRadioPic(const std::string &filename)
1276 m_radio_pic = filename;
1280 RESULT eTSMPEGDecoder::showSinglePic(const char *filename)
1284 eDebug("showSinglePic %s", filename);
1285 int f = open(filename, O_RDONLY);
1290 if (m_video_clip_fd == -1)
1291 m_video_clip_fd = open("/dev/dvb/adapter0/video0", O_WRONLY|O_NONBLOCK);
1292 if (m_video_clip_fd >= 0)
1294 bool seq_end_avail = false;
1296 unsigned char pes_header[] = { 0x00, 0x00, 0x01, 0xE0, 0x00, 0x00, 0x80, 0x00, 0x00 };
1297 unsigned char seq_end[] = { 0x00, 0x00, 0x01, 0xB7 };
1298 unsigned char iframe[s.st_size];
1299 unsigned char stuffing[8192];
1300 int streamtype = VIDEO_STREAMTYPE_MPEG2;
1301 memset(stuffing, 0, 8192);
1302 read(f, iframe, s.st_size);
1303 if (ioctl(m_video_clip_fd, VIDEO_SELECT_SOURCE, VIDEO_SOURCE_MEMORY) < 0)
1304 eDebug("VIDEO_SELECT_SOURCE MEMORY failed (%m)");
1305 if (ioctl(m_video_clip_fd, VIDEO_SET_STREAMTYPE, streamtype) < 0)
1306 eDebug("VIDEO_SET_STREAMTYPE failed(%m)");
1307 if (ioctl(m_video_clip_fd, VIDEO_PLAY) < 0)
1308 eDebug("VIDEO_PLAY failed (%m)");
1309 if (ioctl(m_video_clip_fd, VIDEO_CONTINUE) < 0)
1310 eDebug("video: VIDEO_CONTINUE: %m");
1311 if (ioctl(m_video_clip_fd, VIDEO_CLEAR_BUFFER) < 0)
1312 eDebug("video: VIDEO_CLEAR_BUFFER: %m");
1313 while(pos <= (s.st_size-4) && !(seq_end_avail = (!iframe[pos] && !iframe[pos+1] && iframe[pos+2] == 1 && iframe[pos+3] == 0xB7)))
1315 if ((iframe[3] >> 4) != 0xE) // no pes header
1316 write(m_video_clip_fd, pes_header, sizeof(pes_header));
1318 iframe[4] = iframe[5] = 0x00;
1319 write(m_video_clip_fd, iframe, s.st_size);
1321 write(m_video_clip_fd, seq_end, sizeof(seq_end));
1322 write(m_video_clip_fd, stuffing, 8192);
1323 m_showSinglePicTimer->start(150, true);
1329 eDebug("couldnt open %s", filename);
1335 eDebug("only show single pics on first decoder");
1341 void eTSMPEGDecoder::finishShowSinglePic()
1343 if (m_video_clip_fd >= 0)
1345 if (ioctl(m_video_clip_fd, VIDEO_STOP, 0) < 0)
1346 eDebug("VIDEO_STOP failed (%m)");
1347 if (ioctl(m_video_clip_fd, VIDEO_SELECT_SOURCE, VIDEO_SOURCE_DEMUX) < 0)
1348 eDebug("VIDEO_SELECT_SOURCE DEMUX failed (%m)");
1349 close(m_video_clip_fd);
1350 m_video_clip_fd = -1;
1354 RESULT eTSMPEGDecoder::connectVideoEvent(const Slot1<void, struct videoEvent> &event, ePtr<eConnection> &conn)
1356 conn = new eConnection(this, m_video_event.connect(event));
1360 void eTSMPEGDecoder::video_event(struct videoEvent event)
1362 /* emit */ m_video_event(event);
1365 int eTSMPEGDecoder::getVideoWidth()
1368 return m_video->getWidth();
1372 int eTSMPEGDecoder::getVideoHeight()
1375 return m_video->getHeight();
1379 int eTSMPEGDecoder::getVideoProgressive()
1382 return m_video->getProgressive();
1386 int eTSMPEGDecoder::getVideoFrameRate()
1389 return m_video->getFrameRate();
1393 int eTSMPEGDecoder::getVideoAspect()
1396 return m_video->getAspect();