#include <lib/base/eerror.h>
#include <lib/dvb/decoder.h>
+#if HAVE_DVB_API_VERSION < 3
+#define audioStatus audio_status
+#define videoStatus video_status
+#define pesType pes_type
+#define playState play_state
+#define audioStreamSource_t audio_stream_source_t
+#define videoStreamSource_t video_stream_source_t
+#define streamSource stream_source
+#define dmxPesFilterParams dmx_pes_filter_params
+#define DMX_PES_VIDEO DMX_PES_VIDEO0
+#define DMX_PES_AUDIO DMX_PES_AUDIO0
+#include <ost/dmx.h>
+#include <ost/video.h>
+#include <ost/audio.h>
+#else
#include <linux/dvb/audio.h>
#include <linux/dvb/video.h>
#include <linux/dvb/dmx.h>
+#endif
#include <unistd.h>
#include <fcntl.h>
eDVBAudio::eDVBAudio(eDVBDemux *demux, int dev): m_demux(demux)
{
char filename[128];
+#if HAVE_DVB_API_VERSION < 3
+ sprintf(filename, "/dev/dvb/card%d/audio%d", demux->adapter, dev);
+#else
sprintf(filename, "/dev/dvb/adapter%d/audio%d", demux->adapter, dev);
+#endif
m_fd = ::open(filename, O_RDWR);
if (m_fd < 0)
eWarning("%s: %m", filename);
+#if HAVE_DVB_API_VERSION < 3
+ sprintf(filename, "/dev/dvb/card%d/demux%d", demux->adapter, demux->demux);
+#else
sprintf(filename, "/dev/dvb/adapter%d/demux%d", demux->adapter, demux->demux);
+#endif
m_fd_demux = ::open(filename, O_RDWR);
if (m_fd_demux < 0)
eWarning("%s: %m", filename);
}
-int eDVBAudio::startPid(int pid)
+int eDVBAudio::startPid(int pid, int type)
{
- eDebug("setting audio pid to %x", pid);
if ((m_fd < 0) || (m_fd_demux < 0))
return -1;
dmx_pes_filter_params pes;
-
+
pes.pid = pid;
pes.input = DMX_IN_FRONTEND;
pes.output = DMX_OUT_DECODER;
- pes.pes_type = DMX_PES_AUDIO0;
+ pes.pes_type = DMX_PES_AUDIO; // DMX_PES_AUDIO0
pes.flags = 0;
if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
{
eWarning("audio: DMX_SET_PES_FILTER: %m");
return -errno;
}
- if (::ioctl(m_fd_demux, DMX_START, &pes) < 0)
+ if (::ioctl(m_fd_demux, DMX_START) < 0)
{
eWarning("audio: DMX_START: %m");
return -errno;
}
+ int bypass = 0;
+
+ switch (type)
+ {
+ case aMPEG:
+ bypass = 1;
+ break;
+ case aAC3:
+ bypass = 0;
+ break;
+ /*
+ case aDTS:
+ bypass = 2;
+ break;
+ */
+ }
+
+ if (::ioctl(m_fd, AUDIO_SET_BYPASS_MODE, bypass) < 0)
+ eWarning("audio: AUDIO_SET_BYPASS_MODE: %m");
+
if (::ioctl(m_fd, AUDIO_PLAY) < 0)
eWarning("audio: AUDIO_PLAY: %m");
return 0;
{
if (::ioctl(m_fd, AUDIO_STOP) < 0)
eWarning("audio: AUDIO_STOP: %m");
+#if HAVE_DVB_API_VERSION > 2
if (::ioctl(m_fd_demux, DMX_STOP) < 0)
eWarning("audio: DMX_STOP: %m");
+#endif
+}
+
+#if HAVE_DVB_API_VERSION < 3
+void eDVBAudio::stopPid()
+{
+ if (::ioctl(m_fd_demux, DMX_STOP) < 0)
+ eWarning("audio: DMX_STOP: %m");
+}
+#endif
+
+void eDVBAudio::flush()
+{
+ if (::ioctl(m_fd, AUDIO_CLEAR_BUFFER) < 0)
+ eDebug("audio: AUDIO_CLEAR_BUFFER: %m");
+}
+
+void eDVBAudio::freeze()
+{
+ if (::ioctl(m_fd, AUDIO_PAUSE) < 0)
+ eDebug("video: AUDIO_PAUSE: %m");
+}
+
+void eDVBAudio::unfreeze()
+{
+ if (::ioctl(m_fd, AUDIO_CONTINUE) < 0)
+ eDebug("video: AUDIO_CONTINUE: %m");
}
eDVBAudio::~eDVBAudio()
eDVBVideo::eDVBVideo(eDVBDemux *demux, int dev): m_demux(demux)
{
char filename[128];
+#if HAVE_DVB_API_VERSION < 3
+ sprintf(filename, "/dev/dvb/card%d/video%d", demux->adapter, dev);
+#else
sprintf(filename, "/dev/dvb/adapter%d/video%d", demux->adapter, dev);
+#endif
m_fd = ::open(filename, O_RDWR);
if (m_fd < 0)
eWarning("%s: %m", filename);
+#if HAVE_DVB_API_VERSION < 3
+ sprintf(filename, "/dev/dvb/card%d/demux%d", demux->adapter, demux->demux);
+#else
sprintf(filename, "/dev/dvb/adapter%d/demux%d", demux->adapter, demux->demux);
+#endif
m_fd_demux = ::open(filename, O_RDWR);
if (m_fd_demux < 0)
eWarning("%s: %m", filename);
if ((m_fd < 0) || (m_fd_demux < 0))
return -1;
dmx_pes_filter_params pes;
-
+
pes.pid = pid;
pes.input = DMX_IN_FRONTEND;
pes.output = DMX_OUT_DECODER;
- pes.pes_type = DMX_PES_VIDEO0;
+ pes.pes_type = DMX_PES_VIDEO;
pes.flags = 0;
if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
{
eWarning("video: DMX_SET_PES_FILTER: %m");
return -errno;
}
- if (::ioctl(m_fd_demux, DMX_START, &pes) < 0)
+ if (::ioctl(m_fd_demux, DMX_START) < 0)
{
eWarning("video: DMX_START: %m");
return -errno;
}
-
if (::ioctl(m_fd, VIDEO_PLAY) < 0)
eWarning("video: VIDEO_PLAY: %m");
- else
- eDebug("video ok");
return 0;
}
void eDVBVideo::stop()
{
- if (::ioctl(m_fd, VIDEO_STOP) < 0)
+#if HAVE_DVB_API_VERSION > 2
+ if (::ioctl(m_fd_demux, DMX_STOP) < 0)
+ eWarning("video: DMX_STOP: %m");
+#endif
+ eDebug("VIDEO_STOP");
+ if (::ioctl(m_fd, VIDEO_STOP, 1) < 0)
eWarning("video: VIDEO_STOP: %m");
+}
+
+#if HAVE_DVB_API_VERSION < 3
+void eDVBVideo::stopPid()
+{
if (::ioctl(m_fd_demux, DMX_STOP) < 0)
eWarning("video: DMX_STOP: %m");
}
+#endif
+
+void eDVBVideo::flush()
+{
+ if (::ioctl(m_fd, VIDEO_CLEAR_BUFFER) < 0)
+ eDebug("video: VIDEO_CLEAR_BUFFER: %m");
+}
+
+void eDVBVideo::freeze()
+{
+ if (::ioctl(m_fd, VIDEO_FREEZE) < 0)
+ eDebug("video: VIDEO_FREEZE: %m");
+}
+
+void eDVBVideo::unfreeze()
+{
+ if (::ioctl(m_fd, VIDEO_CONTINUE) < 0)
+ eDebug("video: VIDEO_CONTINUE: %m");
+}
+
+int eDVBVideo::setSlowMotion(int repeat)
+{
+ m_is_slow_motion = repeat;
+ return ::ioctl(m_fd, VIDEO_SLOWMOTION, repeat);
+}
+
+int eDVBVideo::setFastForward(int skip)
+{
+ m_is_fast_forward = skip;
+ return ::ioctl(m_fd, VIDEO_FAST_FORWARD, skip);
+}
eDVBVideo::~eDVBVideo()
{
+ if (m_is_slow_motion)
+ setSlowMotion(0);
+ if (m_is_fast_forward)
+ setFastForward(0);
if (m_fd >= 0)
::close(m_fd);
if (m_fd_demux >= 0)
::close(m_fd_demux);
}
+DEFINE_REF(eDVBPCR);
+
+eDVBPCR::eDVBPCR(eDVBDemux *demux): m_demux(demux)
+{
+ char filename[128];
+#if HAVE_DVB_API_VERSION < 3
+ sprintf(filename, "/dev/dvb/card%d/demux%d", demux->adapter, demux->demux);
+#else
+ sprintf(filename, "/dev/dvb/adapter%d/demux%d", demux->adapter, demux->demux);
+#endif
+ m_fd_demux = ::open(filename, O_RDWR);
+ if (m_fd_demux < 0)
+ eWarning("%s: %m", filename);
+}
+
+int eDVBPCR::startPid(int pid)
+{
+ if (m_fd_demux < 0)
+ return -1;
+ dmx_pes_filter_params pes;
+
+ pes.pid = pid;
+ pes.input = DMX_IN_FRONTEND;
+ pes.output = DMX_OUT_DECODER;
+ pes.pes_type = DMX_PES_PCR;
+ pes.flags = 0;
+ if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
+ {
+ eWarning("video: DMX_SET_PES_FILTER: %m");
+ return -errno;
+ }
+ if (::ioctl(m_fd_demux, DMX_START) < 0)
+ {
+ eWarning("video: DMX_START: %m");
+ return -errno;
+ }
+ return 0;
+}
+
+void eDVBPCR::stop()
+{
+ if (::ioctl(m_fd_demux, DMX_STOP) < 0)
+ eWarning("video: DMX_STOP: %m");
+}
+
+eDVBPCR::~eDVBPCR()
+{
+ if (m_fd_demux >= 0)
+ ::close(m_fd_demux);
+}
+
+DEFINE_REF(eDVBTText);
+
+eDVBTText::eDVBTText(eDVBDemux *demux): m_demux(demux)
+{
+ char filename[128];
+#if HAVE_DVB_API_VERSION < 3
+ sprintf(filename, "/dev/dvb/card%d/demux%d", demux->adapter, demux->demux);
+#else
+ sprintf(filename, "/dev/dvb/adapter%d/demux%d", demux->adapter, demux->demux);
+#endif
+ m_fd_demux = ::open(filename, O_RDWR);
+ if (m_fd_demux < 0)
+ eWarning("%s: %m", filename);
+}
+
+int eDVBTText::startPid(int pid)
+{
+ if (m_fd_demux < 0)
+ return -1;
+ dmx_pes_filter_params pes;
+
+ pes.pid = pid;
+ pes.input = DMX_IN_FRONTEND;
+ pes.output = DMX_OUT_DECODER;
+ pes.pes_type = DMX_PES_TELETEXT;
+ pes.flags = 0;
+ if (::ioctl(m_fd_demux, DMX_SET_PES_FILTER, &pes) < 0)
+ {
+ eWarning("video: DMX_SET_PES_FILTER: %m");
+ return -errno;
+ }
+ if (::ioctl(m_fd_demux, DMX_START) < 0)
+ {
+ eWarning("video: DMX_START: %m");
+ return -errno;
+ }
+ return 0;
+}
+
+void eDVBTText::stop()
+{
+ if (::ioctl(m_fd_demux, DMX_STOP) < 0)
+ eWarning("video: DMX_STOP: %m");
+}
+
+eDVBTText::~eDVBTText()
+{
+ if (m_fd_demux >= 0)
+ ::close(m_fd_demux);
+}
+
DEFINE_REF(eTSMPEGDecoder);
int eTSMPEGDecoder::setState()
{
int res = 0;
- eDebug("changed %x", m_changed);
+
+ int noaudio = m_is_sm || m_is_ff || m_is_trickmode;
+ int nott = noaudio; /* actually same conditions */
+
+ if ((noaudio && m_audio) || (!m_audio && !noaudio))
+ m_changed |= changeAudio;
+
+ if ((nott && m_text) || (!m_text && !nott))
+ m_changed |= changeText;
+
+#if HAVE_DVB_API_VERSION < 3
+ if (m_changed & changeAudio && m_audio)
+ m_audio->stopPid();
+ if (m_changed & changeVideo && m_video)
+ m_video->stopPid();
+ if (m_changed & changePCR && m_pcr)
+ {
+ m_pcr->stop();
+ m_pcr=0;
+ }
+ if (m_changed & changeAudio && m_audio)
+ {
+ m_audio->stop();
+ m_audio=0;
+ }
+ if (m_changed & changeVideo && m_video)
+ {
+ m_video->stop();
+ m_video=0;
+ }
+ if (m_changed & changePCR)
+ {
+ m_pcr = new eDVBPCR(m_demux);
+ if (m_pcr->startPid(m_pcrpid))
+ {
+ eWarning("pcr: startpid failed!");
+ res = -1;
+ }
+ m_changed &= ~changePCR;
+ }
+ if (m_changed & changeVideo)
+ {
+ m_video = new eDVBVideo(m_demux, 0);
+ if (m_video->startPid(m_vpid))
+ {
+ eWarning("video: startpid failed!");
+ res = -1;
+ }
+ m_changed &= ~changeVideo;
+ }
if (m_changed & changeAudio)
{
- if (m_audio)
- m_audio->stop();
- m_audio = 0;
m_audio = new eDVBAudio(m_demux, 0);
- if (m_audio->startPid(m_apid))
+ if (m_audio->startPid(m_apid, m_atype))
{
eWarning("audio: startpid failed!");
res = -1;
}
m_changed &= ~changeAudio;
}
+#else
+ if (m_changed & changePCR)
+ {
+ if (m_pcr)
+ m_pcr->stop();
+ m_pcr = 0;
+ if ((m_pcrpid >= 0) && (m_pcrpid < 0x1FFF))
+ {
+ m_pcr = new eDVBPCR(m_demux);
+ if (m_pcr->startPid(m_pcrpid))
+ {
+ eWarning("pcr: startpid failed!");
+ res = -1;
+ }
+ }
+ m_changed &= ~changePCR;
+ }
if (m_changed & changeVideo)
{
+ eDebug("VIDEO CHANGED (to %04x)", m_vpid);
if (m_video)
+ {
+ eDebug("STOP");
m_video->stop();
+ }
m_video = 0;
- m_video = new eDVBVideo(m_demux, 0);
- if (m_video->startPid(m_vpid))
+ if ((m_vpid >= 0) && (m_vpid < 0x1FFF))
{
- eWarning("video: startpid failed!");
- res = -1;
+ eDebug("new video");
+ m_video = new eDVBVideo(m_demux, 0);
+ if (m_video->startPid(m_vpid))
+ {
+ eWarning("video: startpid failed!");
+ res = -1;
+ }
}
m_changed &= ~changeVideo;
}
+ if (m_changed & changeAudio)
+ {
+ if (m_audio)
+ m_audio->stop();
+ m_audio = 0;
+ if ((m_apid >= 0) && (m_apid < 0x1FFF) && !noaudio)
+ {
+ m_audio = new eDVBAudio(m_demux, 0);
+ if (m_audio->startPid(m_apid, m_atype))
+ {
+ eWarning("audio: startpid failed!");
+ res = -1;
+ }
+ }
+ m_changed &= ~changeAudio;
+ }
+ if (m_changed & changeText)
+ {
+ if (m_text)
+ m_text->stop();
+ m_text = 0;
+ if ((m_textpid >= 0) && (m_textpid < 0x1FFF) && !nott)
+ {
+ m_text = new eDVBTText(m_demux);
+ if (m_text->startPid(m_textpid))
+ {
+ eWarning("text: startpid failed!");
+ res = -1;
+ }
+ }
+ m_changed &= ~changeText;
+ }
+#endif
return res;
}
-eTSMPEGDecoder::eTSMPEGDecoder(eDVBDemux *demux, int decoder): m_demux(demux)
+eTSMPEGDecoder::eTSMPEGDecoder(eDVBDemux *demux, int decoder): m_demux(demux), m_changed(0)
{
+ demux->connectEvent(slot(*this, &eTSMPEGDecoder::demux_event), m_demux_event);
+ m_is_ff = m_is_sm = m_is_trickmode = 0;
}
eTSMPEGDecoder::~eTSMPEGDecoder()
{
if (m_pcrpid != pcrpid)
{
- m_changed |= changeAudio;
+ m_changed |= changePCR;
m_pcrpid = pcrpid;
}
- return -1;
+ return 0;
+}
+
+RESULT eTSMPEGDecoder::setTextPID(int textpid)
+{
+ if (m_textpid != textpid)
+ {
+ m_changed |= changeText;
+ m_textpid = textpid;
+ }
+ return 0;
}
RESULT eTSMPEGDecoder::setSyncMaster(int who)
RESULT eTSMPEGDecoder::freeze(int cont)
{
- return -1;
+ if (m_video)
+ m_video->freeze();
+
+ if (m_audio)
+ m_audio->freeze();
+
+ return 0;
}
RESULT eTSMPEGDecoder::unfreeze()
{
- return -1;
+ if (m_video)
+ m_video->unfreeze();
+
+ if (m_audio)
+ m_audio->unfreeze();
+
+ return 0;
}
RESULT eTSMPEGDecoder::setSinglePictureMode(int when)
return -1;
}
+RESULT eTSMPEGDecoder::setFastForward(int frames_to_skip)
+{
+ m_is_ff = frames_to_skip != 0;
+
+ setState();
+
+ if (m_video)
+ return m_video->setFastForward(frames_to_skip);
+ else
+ return -1;
+}
+
RESULT eTSMPEGDecoder::setSlowMotion(int repeat)
{
- return -1;
+ m_is_sm = repeat != 0;
+
+ setState();
+
+ if (m_video)
+ return m_video->setSlowMotion(repeat);
+ else
+ return -1;
}
RESULT eTSMPEGDecoder::setZoom(int what)
{
return -1;
}
+
+RESULT eTSMPEGDecoder::flush()
+{
+ if (m_audio)
+ m_audio->flush();
+ if (m_video)
+ m_video->flush();
+ return 0;
+}
+
+void eTSMPEGDecoder::demux_event(int event)
+{
+ switch (event)
+ {
+ case eDVBDemux::evtFlush:
+ flush();
+ break;
+ default:
+ break;
+ }
+}
+
+RESULT eTSMPEGDecoder::setTrickmode(int what)
+{
+ m_is_trickmode = what;
+ setState();
+ return 0;
+}