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_VIDEO1 DMX_PES_VIDEO
17 #define DMX_PES_AUDIO1 DMX_PES_AUDIO
18 #define DMX_PES_PCR1 DMX_PES_PCR
20 #include <ost/video.h>
21 #include <ost/audio.h>
23 #include <linux/dvb/audio.h>
24 #include <linux/dvb/video.h>
25 #include <linux/dvb/dmx.h>
30 #include <sys/ioctl.h>
31 #include <sys/types.h>
35 /* these are quite new... */
37 #define AUDIO_GET_PTS _IOR('o', 19, __u64)
38 #define VIDEO_GET_PTS _IOR('o', 57, __u64)
41 DEFINE_REF(eDVBAudio);
43 eDVBAudio::eDVBAudio(eDVBDemux *demux, int dev)
44 :m_demux(demux), m_dev(dev)
47 #if HAVE_DVB_API_VERSION < 3
48 sprintf(filename, "/dev/dvb/card%d/audio%d", demux->adapter, dev);
50 sprintf(filename, "/dev/dvb/adapter%d/audio%d", demux->adapter, dev);
52 m_fd = ::open(filename, O_RDWR);
54 eWarning("%s: %m", filename);
55 #if HAVE_DVB_API_VERSION < 3
56 sprintf(filename, "/dev/dvb/card%d/demux%d", demux->adapter, demux->demux);
58 sprintf(filename, "/dev/dvb/adapter%d/demux%d", demux->adapter, demux->demux);
60 m_fd_demux = ::open(filename, O_RDWR);
62 eWarning("%s: %m", filename);
65 #if HAVE_DVB_API_VERSION < 3
66 int eDVBAudio::setPid(int pid, int type)
68 if ((m_fd < 0) || (m_fd_demux < 0))
88 if (::ioctl(m_fd, AUDIO_SET_BYPASS_MODE, bypass) < 0)
89 eDebug("failed (%m)");
91 dmx_pes_filter_params pes;
94 pes.input = DMX_IN_FRONTEND;
95 pes.output = DMX_OUT_DECODER;
96 pes.pes_type = m_dev ? DMX_PES_AUDIO1 : DMX_PES_AUDIO0; /* FIXME */
98 eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - audio - ", pid);
99 if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
101 eDebug("failed (%m)");
109 int eDVBAudio::startPid()
111 eDebugNoNewLine("DEMUX_START - audio - ");
112 if (::ioctl(m_fd_demux, DMX_START) < 0)
114 eDebug("failed (%m)");
121 int eDVBAudio::start()
123 eDebugNoNewLine("AUDIO_PLAY - ");
124 if (::ioctl(m_fd, AUDIO_PLAY) < 0)
126 eDebug("failed (%m)");
133 int eDVBAudio::stopPid()
135 eDebugNoNewLine("DEMUX_STOP - audio - ");
136 if (::ioctl(m_fd_demux, DMX_STOP) < 0)
138 eDebug("failed (%m)");
145 int eDVBAudio::setAVSync(int val)
147 eDebugNoNewLine("AUDIO_SET_AV_SYNC - ");
148 if (::ioctl(m_fd, AUDIO_SET_AV_SYNC, val) < 0)
150 eDebug("failed (%m)");
157 int eDVBAudio::startPid(int pid, int type)
159 if ((m_fd < 0) || (m_fd_demux < 0))
161 dmx_pes_filter_params pes;
164 pes.input = DMX_IN_FRONTEND;
165 pes.output = DMX_OUT_DECODER;
166 pes.pes_type = m_dev ? DMX_PES_AUDIO1 : DMX_PES_AUDIO0; /* FIXME */
168 eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - audio - ", pid);
169 if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
171 eDebug("failed (%m)");
175 eDebugNoNewLine("DEMUX_START - audio - ");
176 if (::ioctl(m_fd_demux, DMX_START) < 0)
178 eDebug("failed (%m)");
203 eDebugNoNewLine("AUDIO_SET_BYPASS(%d) - ", bypass);
204 if (::ioctl(m_fd, AUDIO_SET_BYPASS_MODE, bypass) < 0)
205 eDebug("failed (%m)");
208 freeze(); // why freeze here?!? this is a problem when only a pid change is requested... because of the unfreeze logic in Decoder::setState
209 eDebugNoNewLine("AUDIO_PLAY - ");
210 if (::ioctl(m_fd, AUDIO_PLAY) < 0)
211 eDebug("failed (%m)");
218 void eDVBAudio::stop()
220 #if HAVE_DVB_API_VERSION > 2
223 eDebugNoNewLine("AUDIO_STOP - ");
224 if (::ioctl(m_fd, AUDIO_STOP) < 0)
225 eDebug("failed (%m)");
228 #if HAVE_DVB_API_VERSION > 2
229 eDebugNoNewLine("DEMUX_STOP - audio - ");
230 if (::ioctl(m_fd_demux, DMX_STOP) < 0)
231 eDebug("failed (%m)");
237 void eDVBAudio::flush()
239 eDebugNoNewLine("AUDIO_CLEAR_BUFFER - ");
240 if (::ioctl(m_fd, AUDIO_CLEAR_BUFFER) < 0)
241 eDebug("failed (%m)");
246 void eDVBAudio::freeze()
248 eDebugNoNewLine("AUDIO_PAUSE - ");
249 if (::ioctl(m_fd, AUDIO_PAUSE) < 0)
250 eDebug("failed (%m)");
255 void eDVBAudio::unfreeze()
257 eDebugNoNewLine("AUDIO_CONTINUE - ");
258 if (::ioctl(m_fd, AUDIO_CONTINUE) < 0)
259 eDebug("failed (%m)");
264 void eDVBAudio::setChannel(int channel)
266 int val = AUDIO_STEREO;
269 case aMonoLeft: val = AUDIO_MONO_LEFT; break;
270 case aMonoRight: val = AUDIO_MONO_RIGHT; break;
273 eDebugNoNewLine("AUDIO_CHANNEL_SELECT(%d) - ", val);
274 if (::ioctl(m_fd, AUDIO_CHANNEL_SELECT, val) < 0)
275 eDebug("failed (%m)");
280 int eDVBAudio::getPTS(pts_t &now)
282 if (::ioctl(m_fd, AUDIO_GET_PTS, &now) < 0)
283 eDebug("AUDIO_GET_PTS failed (%m)");
287 eDVBAudio::~eDVBAudio()
289 unfreeze(); // why unfreeze here... but not unfreeze video in ~eDVBVideo ?!?
296 DEFINE_REF(eDVBVideo);
298 eDVBVideo::eDVBVideo(eDVBDemux *demux, int dev)
299 : m_demux(demux), m_dev(dev),
300 m_width(-1), m_height(-1), m_framerate(-1), m_aspect(-1), m_progressive(-1)
303 #if HAVE_DVB_API_VERSION < 3
304 sprintf(filename, "/dev/dvb/card%d/video%d", demux->adapter, dev);
305 m_fd_video = ::open("/dev/video", O_RDWR);
307 eWarning("/dev/video: %m");
309 sprintf(filename, "/dev/dvb/adapter%d/video%d", demux->adapter, dev);
311 m_fd = ::open(filename, O_RDWR);
313 eWarning("%s: %m", filename);
316 m_sn = eSocketNotifier::create(eApp, m_fd, eSocketNotifier::Priority);
317 CONNECT(m_sn->activated, eDVBVideo::video_event);
319 eDebug("Video Device: %s", filename);
320 #if HAVE_DVB_API_VERSION < 3
321 sprintf(filename, "/dev/dvb/card%d/demux%d", demux->adapter, demux->demux);
323 sprintf(filename, "/dev/dvb/adapter%d/demux%d", demux->adapter, demux->demux);
325 m_fd_demux = ::open(filename, O_RDWR);
327 eWarning("%s: %m", filename);
328 eDebug("demux device: %s", filename);
331 // not finally values i think.. !!
332 #define VIDEO_STREAMTYPE_MPEG2 0
333 #define VIDEO_STREAMTYPE_MPEG4_H264 1
334 #define VIDEO_STREAMTYPE_VC1 3
335 #define VIDEO_STREAMTYPE_MPEG4_Part2 4
336 #define VIDEO_STREAMTYPE_VC1_SM 5
337 #define VIDEO_STREAMTYPE_MPEG1 6
339 #if HAVE_DVB_API_VERSION < 3
340 int eDVBVideo::setPid(int pid)
342 if ((m_fd < 0) || (m_fd_demux < 0))
344 dmx_pes_filter_params pes;
347 pes.input = DMX_IN_FRONTEND;
348 pes.output = DMX_OUT_DECODER;
349 pes.pes_type = m_dev ? DMX_PES_VIDEO1 : DMX_PES_VIDEO0; /* FIXME */
351 eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - video - ", pid);
352 if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
354 eDebug("failed (%m)");
361 int eDVBVideo::startPid()
363 eDebugNoNewLine("DEMUX_START - video - ");
364 if (::ioctl(m_fd_demux, DMX_START) < 0)
366 eDebug("failed (%m)");
373 int eDVBVideo::start()
375 eDebugNoNewLine("VIDEO_PLAY - ");
376 if (::ioctl(m_fd, VIDEO_PLAY) < 0)
378 eDebug("failed (%m)");
385 int eDVBVideo::stopPid()
387 eDebugNoNewLine("DEMUX_STOP - video - ");
388 if (::ioctl(m_fd_demux, DMX_STOP) < 0)
390 eDebug("failed (%m)");
397 int eDVBVideo::startPid(int pid, int type)
399 int streamtype = VIDEO_STREAMTYPE_MPEG2;
401 if ((m_fd < 0) || (m_fd_demux < 0))
403 dmx_pes_filter_params pes;
411 streamtype = VIDEO_STREAMTYPE_MPEG4_H264;
414 streamtype = VIDEO_STREAMTYPE_MPEG1;
417 streamtype = VIDEO_STREAMTYPE_MPEG4_Part2;
420 streamtype = VIDEO_STREAMTYPE_VC1;
423 streamtype = VIDEO_STREAMTYPE_VC1_SM;
427 eDebugNoNewLine("VIDEO_SET_STREAMTYPE %d - ", streamtype);
428 if (::ioctl(m_fd, VIDEO_SET_STREAMTYPE, streamtype) < 0)
429 eDebug("failed (%m)");
434 pes.input = DMX_IN_FRONTEND;
435 pes.output = DMX_OUT_DECODER;
436 pes.pes_type = m_dev ? DMX_PES_VIDEO1 : DMX_PES_VIDEO0; /* FIXME */
438 eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - video - ", pid);
439 if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
441 eDebug("failed (%m)");
445 eDebugNoNewLine("DEMUX_START - video - ");
446 if (::ioctl(m_fd_demux, DMX_START) < 0)
448 eDebug("failed (%m)");
452 freeze(); // why freeze here?!? this is a problem when only a pid change is requested... because of the unfreeze logic in Decoder::setState
453 eDebugNoNewLine("VIDEO_PLAY - ");
454 if (::ioctl(m_fd, VIDEO_PLAY) < 0)
455 eDebug("failed (%m)");
462 void eDVBVideo::stop()
464 #if HAVE_DVB_API_VERSION > 2
465 eDebugNoNewLine("DEMUX_STOP - video - ");
466 if (::ioctl(m_fd_demux, DMX_STOP) < 0)
467 eDebug("failed (%m)");
471 eDebugNoNewLine("VIDEO_STOP - ");
472 if (::ioctl(m_fd, VIDEO_STOP, 1) < 0)
473 eDebug("failed (%m)");
478 void eDVBVideo::flush()
480 eDebugNoNewLine("VIDEO_CLEAR_BUFFER - ");
481 if (::ioctl(m_fd, VIDEO_CLEAR_BUFFER) < 0)
482 eDebug("failed (%m)");
487 void eDVBVideo::freeze()
489 eDebugNoNewLine("VIDEO_FREEZE - ");
490 if (::ioctl(m_fd, VIDEO_FREEZE) < 0)
491 eDebug("failed (%m)");
496 void eDVBVideo::unfreeze()
498 eDebugNoNewLine("VIDEO_CONTINUE - ");
499 if (::ioctl(m_fd, VIDEO_CONTINUE) < 0)
500 eDebug("failed (%m)");
505 int eDVBVideo::setSlowMotion(int repeat)
507 eDebugNoNewLine("VIDEO_SLOWMOTION(%d) - ", repeat);
508 int ret = ::ioctl(m_fd, VIDEO_SLOWMOTION, repeat);
510 eDebug("failed(%m)");
516 int eDVBVideo::setFastForward(int skip)
518 eDebugNoNewLine("VIDEO_FAST_FORWARD(%d) - ", skip);
519 int ret = ::ioctl(m_fd, VIDEO_FAST_FORWARD, skip);
521 eDebug("failed(%m)");
527 int eDVBVideo::getPTS(pts_t &now)
529 #if HAVE_DVB_API_VERSION < 3
530 #define VIDEO_GET_PTS_OLD _IOR('o', 1, unsigned int*)
532 int ret = ::ioctl(m_fd_video, VIDEO_GET_PTS_OLD, &pts);
536 int ret = ::ioctl(m_fd, VIDEO_GET_PTS, &now);
539 eDebug("VIDEO_GET_PTS failed(%m)");
543 eDVBVideo::~eDVBVideo()
549 #if HAVE_DVB_API_VERSION < 3
555 void eDVBVideo::video_event(int)
557 #if HAVE_DVB_API_VERSION >= 3
558 struct video_event evt;
559 eDebugNoNewLine("VIDEO_GET_EVENT - ");
560 if (::ioctl(m_fd, VIDEO_GET_EVENT, &evt) < 0)
561 eDebug("failed (%m)");
565 if (evt.type == VIDEO_EVENT_SIZE_CHANGED)
567 struct iTSMPEGDecoder::videoEvent event;
568 event.type = iTSMPEGDecoder::videoEvent::eventSizeChanged;
569 m_aspect = event.aspect = evt.u.size.aspect_ratio == 0 ? 2 : 3; // convert dvb api to etsi
570 m_height = event.height = evt.u.size.h;
571 m_width = event.width = evt.u.size.w;
572 /* emit */ m_event(event);
574 else if (evt.type == VIDEO_EVENT_FRAME_RATE_CHANGED)
576 struct iTSMPEGDecoder::videoEvent event;
577 event.type = iTSMPEGDecoder::videoEvent::eventFrameRateChanged;
578 m_framerate = event.framerate = evt.u.frame_rate;
579 /* emit */ m_event(event);
581 else if (evt.type == 16 /*VIDEO_EVENT_PROGRESSIVE_CHANGED*/)
583 struct iTSMPEGDecoder::videoEvent event;
584 event.type = iTSMPEGDecoder::videoEvent::eventProgressiveChanged;
585 m_progressive = event.progressive = evt.u.frame_rate;
586 /* emit */ m_event(event);
589 eDebug("unhandled DVBAPI Video Event %d", evt.type);
592 #warning "FIXMEE!! Video Events not implemented for old api"
596 RESULT eDVBVideo::connectEvent(const Slot1<void, struct iTSMPEGDecoder::videoEvent> &event, ePtr<eConnection> &conn)
598 conn = new eConnection(this, m_event.connect(event));
602 static int readMpegProc(char *str, int decoder)
606 sprintf(tmp, "/proc/stb/vmpeg/%d/%s", decoder, str);
607 FILE *f = fopen(tmp, "r");
610 fscanf(f, "%x", &val);
616 static int readApiSize(int fd, int &xres, int &yres, int &aspect)
618 #if HAVE_DVB_API_VERSION >= 3
620 if (!::ioctl(fd, VIDEO_GET_SIZE, &size))
624 aspect = size.aspect_ratio == 0 ? 2 : 3; // convert dvb api to etsi
627 // eDebug("VIDEO_GET_SIZE failed (%m)");
632 static int readApiFrameRate(int fd, int &framerate)
634 #if HAVE_DVB_API_VERSION >= 3
636 if (!::ioctl(fd, VIDEO_GET_FRAME_RATE, &frate))
641 // eDebug("VIDEO_GET_FRAME_RATE failed (%m)");
646 int eDVBVideo::getWidth()
649 readApiSize(m_fd, m_width, m_height, m_aspect);
651 m_width = readMpegProc("xres", m_dev);
655 int eDVBVideo::getHeight()
658 readApiSize(m_fd, m_width, m_height, m_aspect);
660 m_height = readMpegProc("yres", m_dev);
664 int eDVBVideo::getAspect()
667 readApiSize(m_fd, m_width, m_height, m_aspect);
669 m_aspect = readMpegProc("aspect", m_dev);
673 int eDVBVideo::getProgressive()
675 if (m_progressive == -1)
676 m_progressive = readMpegProc("progressive", m_dev);
677 return m_progressive;
680 int eDVBVideo::getFrameRate()
682 if (m_framerate == -1)
683 readApiFrameRate(m_fd, m_framerate);
684 if (m_framerate == -1)
685 m_framerate = readMpegProc("framerate", m_dev);
691 eDVBPCR::eDVBPCR(eDVBDemux *demux, int dev): m_demux(demux), m_dev(dev)
694 #if HAVE_DVB_API_VERSION < 3
695 sprintf(filename, "/dev/dvb/card%d/demux%d", demux->adapter, demux->demux);
697 sprintf(filename, "/dev/dvb/adapter%d/demux%d", demux->adapter, demux->demux);
699 m_fd_demux = ::open(filename, O_RDWR);
701 eWarning("%s: %m", filename);
704 #if HAVE_DVB_API_VERSION < 3
705 int eDVBPCR::setPid(int pid)
709 dmx_pes_filter_params pes;
712 pes.input = DMX_IN_FRONTEND;
713 pes.output = DMX_OUT_DECODER;
714 pes.pes_type = DMX_PES_PCR;
717 eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - pcr - ", pid);
718 if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
720 eDebug("failed (%m)");
727 int eDVBPCR::startPid()
731 eDebugNoNewLine("DEMUX_START - pcr - ");
732 if (::ioctl(m_fd_demux, DMX_START) < 0)
734 eDebug("failed (%m)");
741 int eDVBPCR::startPid(int pid)
745 dmx_pes_filter_params pes;
748 pes.input = DMX_IN_FRONTEND;
749 pes.output = DMX_OUT_DECODER;
750 pes.pes_type = m_dev ? DMX_PES_PCR1 : DMX_PES_PCR0; /* FIXME */
752 eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - pcr - ", pid);
753 if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
755 eDebug("failed (%m)");
759 eDebugNoNewLine("DEMUX_START - pcr - ");
760 if (::ioctl(m_fd_demux, DMX_START) < 0)
762 eDebug("failed (%m)");
772 eDebugNoNewLine("DEMUX_STOP - pcr - ");
773 if (::ioctl(m_fd_demux, DMX_STOP) < 0)
774 eDebug("failed(%m)");
785 DEFINE_REF(eDVBTText);
787 eDVBTText::eDVBTText(eDVBDemux *demux, int dev)
788 :m_demux(demux), m_dev(dev)
791 #if HAVE_DVB_API_VERSION < 3
792 sprintf(filename, "/dev/dvb/card%d/demux%d", demux->adapter, demux->demux);
794 sprintf(filename, "/dev/dvb/adapter%d/demux%d", demux->adapter, demux->demux);
796 m_fd_demux = ::open(filename, O_RDWR);
798 eWarning("%s: %m", filename);
801 int eDVBTText::startPid(int pid)
805 dmx_pes_filter_params pes;
808 pes.input = DMX_IN_FRONTEND;
809 pes.output = DMX_OUT_DECODER;
810 pes.pes_type = m_dev ? DMX_PES_TELETEXT1 : DMX_PES_TELETEXT0; // FIXME
813 eDebugNoNewLine("DMX_SET_PES_FILTER(0x%02x) - ttx - ", pid);
814 if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
816 eDebug("failed(%m)");
820 eDebugNoNewLine("DEMUX_START - ttx - ");
821 if (::ioctl(m_fd_demux, DMX_START) < 0)
823 eDebug("failed(%m)");
830 void eDVBTText::stop()
832 eDebugNoNewLine("DEMUX_STOP - ttx - ");
833 if (::ioctl(m_fd_demux, DMX_STOP) < 0)
834 eDebug("failed(%m)");
839 eDVBTText::~eDVBTText()
845 DEFINE_REF(eTSMPEGDecoder);
847 int eTSMPEGDecoder::setState()
851 int noaudio = (m_state != statePlay) && (m_state != statePause);
852 int nott = noaudio; /* actually same conditions */
854 if ((noaudio && m_audio) || (!m_audio && !noaudio))
855 m_changed |= changeAudio | changeState;
857 if ((nott && m_text) || (!m_text && !nott))
858 m_changed |= changeText | changeState;
860 const char *decoder_states[] = {"stop", "pause", "play", "decoderfastforward", "trickmode", "slowmotion"};
861 eDebug("decoder state: %s, vpid=%d, apid=%d", decoder_states[m_state], m_vpid, m_apid);
863 bool changed = !!m_changed;
864 #if HAVE_DVB_API_VERSION < 3
865 bool checkAVSync = m_changed & (changeAudio|changeVideo|changePCR);
866 if (m_changed & changeAudio && m_audio)
868 if (m_changed & changeVideo && m_video)
870 if (m_changed & changePCR && m_pcr)
874 if (!(m_pcrpid >= 0 && m_pcrpid < 0x1ff))
875 m_changed &= ~changePCR;
877 if (m_changed & changeAudio && m_audio)
881 if (!(m_apid >= 0 && m_apid < 0x1ff))
882 m_changed &= ~changeAudio;
884 if (m_changed & changeVideo && m_video)
888 m_video_event_conn=0;
889 if (!(m_vpid >= 0 && m_vpid < 0x1ff))
890 m_changed &= ~changeVideo;
892 if (m_changed & changeVideo)
894 m_video = new eDVBVideo(m_demux, m_decoder);
895 m_video->connectEvent(slot(*this, &eTSMPEGDecoder::video_event), m_video_event_conn);
896 if (m_video->setPid(m_vpid))
899 if (m_changed & changePCR)
901 m_pcr = new eDVBPCR(m_demux);
902 if (m_pcr->setPid(m_pcrpid))
905 if (m_changed & changeAudio)
907 m_audio = new eDVBAudio(m_demux, m_decoder);
908 if (m_audio->setPid(m_apid, m_atype))
911 if (m_changed & changePCR)
913 if (m_pcr->startPid())
915 m_changed &= ~changePCR;
917 else if (checkAVSync && m_audio && m_video)
919 if (m_audio->setAVSync(1))
922 if (m_changed & changeVideo)
924 if (m_video->startPid() || m_video->start())
926 m_changed &= ~changeVideo;
928 if (m_changed & changeAudio)
930 if (m_audio->start() || m_audio->startPid())
932 m_changed &= ~changeAudio;
935 if (m_changed & changePCR)
941 if (m_changed & changeVideo)
947 m_video_event_conn = 0;
950 if (m_changed & changeAudio)
956 if (m_changed & changeText)
962 if (m_changed & changePCR)
964 if ((m_pcrpid >= 0) && (m_pcrpid < 0x1FFF))
966 m_pcr = new eDVBPCR(m_demux, m_decoder);
967 if (m_pcr->startPid(m_pcrpid))
970 m_changed &= ~changePCR;
972 if (m_changed & changeAudio)
974 if ((m_apid >= 0) && (m_apid < 0x1FFF) && !noaudio)
976 m_audio = new eDVBAudio(m_demux, m_decoder);
977 if (m_audio->startPid(m_apid, m_atype))
980 m_changed &= ~changeAudio;
982 if (m_changed & changeVideo)
984 if ((m_vpid >= 0) && (m_vpid < 0x1FFF))
986 m_video = new eDVBVideo(m_demux, m_decoder);
987 m_video->connectEvent(slot(*this, &eTSMPEGDecoder::video_event), m_video_event_conn);
988 if (m_video->startPid(m_vpid, m_vtype))
991 m_changed &= ~changeVideo;
993 if (m_changed & changeText)
995 if ((m_textpid >= 0) && (m_textpid < 0x1FFF) && !nott)
997 m_text = new eDVBTText(m_demux, m_decoder);
998 if (m_text->startPid(m_textpid))
1001 m_changed &= ~changeText;
1005 if (m_changed & (changeState|changeVideo|changeAudio))
1007 /* play, slowmotion, fast-forward */
1008 int state_table[6][4] =
1010 /* [stateStop] = */ {0, 0, 0},
1011 /* [statePause] = */ {0, 0, 0},
1012 /* [statePlay] = */ {1, 0, 0},
1013 /* [stateDecoderFastForward] = */ {1, 0, m_ff_sm_ratio},
1014 /* [stateHighspeedFastForward] = */ {1, 0, 1},
1015 /* [stateSlowMotion] = */ {1, m_ff_sm_ratio, 0}
1017 int *s = state_table[m_state];
1018 if (m_changed & (changeState|changeVideo) && m_video)
1020 m_video->setSlowMotion(s[1]);
1021 m_video->setFastForward(s[2]);
1023 m_video->unfreeze();
1027 if (m_changed & (changeState|changeAudio) && m_audio)
1030 m_audio->unfreeze();
1034 m_changed &= ~changeState;
1037 if (changed && !m_video && m_audio && m_radio_pic.length())
1038 showSinglePic(m_radio_pic.c_str());
1043 int eTSMPEGDecoder::m_pcm_delay=-1,
1044 eTSMPEGDecoder::m_ac3_delay=-1;
1046 RESULT eTSMPEGDecoder::setPCMDelay(int delay)
1048 if (m_decoder == 0 && delay != m_pcm_delay )
1050 FILE *fp = fopen("/proc/stb/audio/audio_delay_pcm", "w");
1053 fprintf(fp, "%x", delay*90);
1055 m_pcm_delay = delay;
1062 RESULT eTSMPEGDecoder::setAC3Delay(int delay)
1064 if ( m_decoder == 0 && delay != m_ac3_delay )
1066 FILE *fp = fopen("/proc/stb/audio/audio_delay_bitstream", "w");
1069 fprintf(fp, "%x", delay*90);
1071 m_ac3_delay = delay;
1078 eTSMPEGDecoder::eTSMPEGDecoder(eDVBDemux *demux, int decoder)
1080 m_vpid(-1), m_vtype(-1), m_apid(-1), m_atype(-1), m_pcrpid(-1), m_textpid(-1),
1081 m_changed(0), m_decoder(decoder), m_video_clip_fd(-1), m_showSinglePicTimer(eTimer::create(eApp))
1083 demux->connectEvent(slot(*this, &eTSMPEGDecoder::demux_event), m_demux_event_conn);
1084 CONNECT(m_showSinglePicTimer->timeout, eTSMPEGDecoder::finishShowSinglePic);
1085 m_state = stateStop;
1088 eTSMPEGDecoder::~eTSMPEGDecoder()
1090 finishShowSinglePic();
1091 m_vpid = m_apid = m_pcrpid = m_textpid = pidNone;
1096 RESULT eTSMPEGDecoder::setVideoPID(int vpid, int type)
1098 if ((m_vpid != vpid) || (m_vtype != type))
1100 m_changed |= changeVideo;
1107 RESULT eTSMPEGDecoder::setAudioPID(int apid, int type)
1109 if ((m_apid != apid) || (m_atype != type))
1111 m_changed |= changeAudio;
1118 int eTSMPEGDecoder::m_audio_channel = -1;
1120 RESULT eTSMPEGDecoder::setAudioChannel(int channel)
1123 channel = ac_stereo;
1124 if (m_decoder == 0 && m_audio_channel != channel)
1128 m_audio->setChannel(channel);
1129 m_audio_channel=channel;
1132 eDebug("eTSMPEGDecoder::setAudioChannel but no audio decoder exist");
1137 int eTSMPEGDecoder::getAudioChannel()
1139 return m_audio_channel == -1 ? ac_stereo : m_audio_channel;
1142 RESULT eTSMPEGDecoder::setSyncPCR(int pcrpid)
1144 if (m_pcrpid != pcrpid)
1146 m_changed |= changePCR;
1152 RESULT eTSMPEGDecoder::setTextPID(int textpid)
1154 if (m_textpid != textpid)
1156 m_changed |= changeText;
1157 m_textpid = textpid;
1162 RESULT eTSMPEGDecoder::setSyncMaster(int who)
1167 RESULT eTSMPEGDecoder::set()
1172 RESULT eTSMPEGDecoder::play()
1174 if (m_state == statePlay)
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();