From 326c39fc40c2689a463df0c34826bfa62680f44b Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Sat, 21 Sep 2013 15:00:16 +0200 Subject: [PATCH 1/7] azbox: add O_CLOEXEC to open() Origin commit data ------------------ Branch: master Commit: https://github.com/neutrino-images/ni-libstb-hal/commit/ad64d0ab4f707a4e62034edcfd7334a4f26a695c Author: Stefan Seyfried Date: 2013-09-21 (Sat, 21 Sep 2013) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- azbox/audio.cpp | 8 +++----- azbox/dmx.cpp | 3 +-- azbox/video.cpp | 8 +++----- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/azbox/audio.cpp b/azbox/audio.cpp index 6e33541..f404c61 100644 --- a/azbox/audio.cpp +++ b/azbox/audio.cpp @@ -39,9 +39,8 @@ void cAudio::openDevice(void) lt_debug("%s\n", __func__); if (fd < 0) { - if ((fd = open(AUDIO_DEVICE, O_RDWR)) < 0) + if ((fd = open(AUDIO_DEVICE, O_RDONLY|O_CLOEXEC)) < 0) lt_info("openDevice: open failed (%m)\n"); - fcntl(fd, F_SETFD, FD_CLOEXEC); do_mute(true, false); } else @@ -211,12 +210,11 @@ int cAudio::PrepareClipPlay(int ch, int srate, int bits, int little_endian) } lt_info("%s: dsp_dev %s mix_dev %s\n", __func__, dsp_dev, mix_dev); /* NULL mix_dev is ok */ /* the tdoss dsp driver seems to work only on the second open(). really. */ - clipfd = open(dsp_dev, O_WRONLY); + clipfd = open(dsp_dev, O_WRONLY|O_CLOEXEC); if (clipfd < 0) { lt_info("%s open %s: %m\n", dsp_dev, __FUNCTION__); return -1; } - fcntl(clipfd, F_SETFD, FD_CLOEXEC); /* no idea if we ever get little_endian == 0 */ if (little_endian) fmt = AFMT_S16_BE; @@ -234,7 +232,7 @@ int cAudio::PrepareClipPlay(int ch, int srate, int bits, int little_endian) if (!mix_dev) return 0; - mixer_fd = open(mix_dev, O_RDWR); + mixer_fd = open(mix_dev, O_RDWR|O_CLOEXEC); if (mixer_fd < 0) { lt_info("%s: open mixer %s failed (%m)\n", __func__, mix_dev); /* not a real error */ diff --git a/azbox/dmx.cpp b/azbox/dmx.cpp index a68327c..a76091c 100644 --- a/azbox/dmx.cpp +++ b/azbox/dmx.cpp @@ -114,7 +114,7 @@ cDemux::~cDemux() bool cDemux::Open(DMX_CHANNEL_TYPE pes_type, void * /*hVideoBuffer*/, int uBufferSize) { int devnum = num; - int flags = O_RDWR; + int flags = O_RDWR|O_CLOEXEC; if (fd > -1) lt_info("%s FD ALREADY OPENED? fd = %d\n", __FUNCTION__, fd); @@ -127,7 +127,6 @@ bool cDemux::Open(DMX_CHANNEL_TYPE pes_type, void * /*hVideoBuffer*/, int uBuffe lt_info("%s %s: %m\n", __FUNCTION__, devname[devnum]); return false; } - fcntl(fd, F_SETFD, FD_CLOEXEC); lt_debug("%s #%d pes_type: %s(%d), uBufferSize: %d fd: %d\n", __func__, num, DMX_T[pes_type], pes_type, uBufferSize, fd); diff --git a/azbox/video.cpp b/azbox/video.cpp index 335c15e..08387a5 100644 --- a/azbox/video.cpp +++ b/azbox/video.cpp @@ -90,7 +90,7 @@ cVideo::cVideo(int, void *, void *) blank_data = NULL; /* initialize */ blank_size = 0; - blankfd = open(blankname, O_RDONLY); + blankfd = open(blankname, O_RDONLY|O_CLOEXEC); if (blankfd < 0) lt_info("%s cannot open %s: %m", __func__, blankname); else @@ -129,7 +129,7 @@ void cVideo::openDevice(void) if (fd != -1) /* already open */ return; retry: - if ((fd = open(VIDEO_DEVICE, O_RDWR)) < 0) + if ((fd = open(VIDEO_DEVICE, O_RDWR|O_CLOEXEC)) < 0) { if (errno == EBUSY) { @@ -140,8 +140,6 @@ retry: } lt_info("%s cannot open %s: %m, retries %d\n", __func__, VIDEO_DEVICE, n); } - else - fcntl(fd, F_SETFD, FD_CLOEXEC); playstate = VIDEO_STOPPED; } @@ -387,7 +385,7 @@ void cVideo::ShowPicture(const char * fname) what we want. the mutex ensures proper ordering. */ pthread_mutex_lock(&stillp_mutex); - mfd = open(destname, O_RDONLY); + mfd = open(destname, O_RDONLY|O_CLOEXEC); if (mfd < 0) { lt_info("%s cannot open %s: %m", __func__, destname); From 97295707ab315220fed89cb3ba4f96f96416e18e Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Sun, 22 Sep 2013 14:41:54 +0200 Subject: [PATCH 2/7] azbox: adapt cAudio to latest drivers Origin commit data ------------------ Branch: master Commit: https://github.com/neutrino-images/ni-libstb-hal/commit/c31a1919c7b5a4c0a5d77f3d7d57c715f91b1a0b Author: Stefan Seyfried Date: 2013-09-22 (Sun, 22 Sep 2013) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- azbox/audio.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/azbox/audio.cpp b/azbox/audio.cpp index f404c61..329b8f9 100644 --- a/azbox/audio.cpp +++ b/azbox/audio.cpp @@ -50,6 +50,7 @@ void cAudio::openDevice(void) void cAudio::closeDevice(void) { lt_debug("%s\n", __func__); + ioctl(fd, AUDIO_CONTINUE); /* enigma2 also does CONTINUE before close... */ if (fd >= 0) close(fd); fd = -1; @@ -128,7 +129,9 @@ int cAudio::Start(void) int cAudio::Stop(void) { lt_debug("%s\n", __func__); - return ioctl(fd, AUDIO_STOP); + ioctl(fd, AUDIO_STOP); + ioctl(fd, AUDIO_CONTINUE); /* no idea why we have to stop and then continue => enigma2 does it, too */ + return 0; } bool cAudio::Pause(bool /*Pcm*/) From fafdfbf884c87af17a46b0bca7fc8c7809e91da2 Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Sun, 22 Sep 2013 14:42:48 +0200 Subject: [PATCH 3/7] azbox: adapt cDemux to latest drivers Origin commit data ------------------ Branch: master Commit: https://github.com/neutrino-images/ni-libstb-hal/commit/f56ead6685ee552e37c598fafa0bb8e80aeef15d Author: Stefan Seyfried Date: 2013-09-22 (Sun, 22 Sep 2013) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- azbox/dmx.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/azbox/dmx.cpp b/azbox/dmx.cpp index a76091c..c860bac 100644 --- a/azbox/dmx.cpp +++ b/azbox/dmx.cpp @@ -137,10 +137,10 @@ bool cDemux::Open(DMX_CHANNEL_TYPE pes_type, void * /*hVideoBuffer*/, int uBuffe lt_info("%s ERROR! pesfds not empty!\n", __FUNCTION__); /* TODO: error handling */ return false; } -#endif int n = DMX_SOURCE_FRONT0; if (ioctl(fd, DMX_SET_SOURCE, &n) < 0) lt_info("%s DMX_SET_SOURCE failed!\n", __func__); +#endif if (uBufferSize > 0) { /* probably uBufferSize == 0 means "use default size". TODO: find a reasonable default */ @@ -383,6 +383,7 @@ bool cDemux::sectionFilter(unsigned short pid, const unsigned char * const filte ioctl (fd, DMX_STOP); if (ioctl(fd, DMX_SET_FILTER, &s_flt) < 0) return false; + ioctl(fd, DMX_START); return true; } From 980c5c2f925857fe5e54468cbe5be5bbd73470be Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Sun, 22 Sep 2013 14:44:29 +0200 Subject: [PATCH 4/7] azbox: add cDemux hack to avoid segfaults/corruption Origin commit data ------------------ Branch: master Commit: https://github.com/neutrino-images/ni-libstb-hal/commit/2e20b8f2b6bd8d3c0fcc85a4cf57df5447126d06 Author: Stefan Seyfried Date: 2013-09-22 (Sun, 22 Sep 2013) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- azbox/dmx.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/azbox/dmx.cpp b/azbox/dmx.cpp index c860bac..cacd823 100644 --- a/azbox/dmx.cpp +++ b/azbox/dmx.cpp @@ -211,10 +211,11 @@ int cDemux::Read(unsigned char *buff, int len, int timeout) #endif int rc; int to = timeout; - struct pollfd ufds; - ufds.fd = fd; - ufds.events = POLLIN|POLLPRI|POLLERR; - ufds.revents = 0; + /* using a one-dimensional array seems to avoid strange segfaults / memory corruption?? */ + struct pollfd ufds[1]; + ufds[0].fd = fd; + ufds[0].events = POLLIN|POLLPRI|POLLERR; + ufds[0].revents = 0; /* hack: if the frontend loses and regains lock, the demuxer often will not * return from read(), so as a "emergency exit" for e.g. NIT scan, set a (long) @@ -225,7 +226,7 @@ int cDemux::Read(unsigned char *buff, int len, int timeout) if (to > 0) { retry: - rc = ::poll(&ufds, 1, to); + rc = ::poll(ufds, 1, to); if (!rc) { if (timeout == 0) /* we took the emergency exit */ @@ -252,14 +253,14 @@ int cDemux::Read(unsigned char *buff, int len, int timeout) return 0; } #endif - if (ufds.revents & POLLHUP) /* we get POLLHUP if e.g. a too big DMX_BUFFER_SIZE was set */ + if (ufds[0].revents & POLLHUP) /* we get POLLHUP if e.g. a too big DMX_BUFFER_SIZE was set */ { - dmx_err("received %s,", "POLLHUP", ufds.revents); + dmx_err("received %s,", "POLLHUP", ufds[0].revents); return -1; } - if (!(ufds.revents & POLLIN)) /* we requested POLLIN but did not get it? */ + if (!(ufds[0].revents & POLLIN)) /* we requested POLLIN but did not get it? */ { - dmx_err("received %s, please report!", "POLLIN", ufds.revents); + dmx_err("received %s, please report!", "POLLIN", ufds[0].revents); return 0; } } From 8d9d944012172d761f521a2ad2ca7eb352c364a2 Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Sun, 22 Sep 2013 14:48:36 +0200 Subject: [PATCH 5/7] azbox: remove unneeded hacks from cVideo Origin commit data ------------------ Branch: master Commit: https://github.com/neutrino-images/ni-libstb-hal/commit/f009c3e76e180bac74fb295594484a71aba71e0b Author: Stefan Seyfried Date: 2013-09-22 (Sun, 22 Sep 2013) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- azbox/video.cpp | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/azbox/video.cpp b/azbox/video.cpp index 08387a5..2477e60 100644 --- a/azbox/video.cpp +++ b/azbox/video.cpp @@ -146,8 +146,6 @@ retry: void cVideo::closeDevice(void) { lt_debug("%s\n", __func__); - /* looks like sometimes close is unhappy about non-empty buffers */ - Start(); if (fd >= 0) close(fd); fd = -1; @@ -286,16 +284,7 @@ int cVideo::SetVideoSystem(int video_system, bool remember) return 0; } lt_info("%s: old: '%s' new: '%s'\n", __func__, current, modes[video_system]); - bool stopped = false; - if (playstate == VIDEO_PLAYING) - { - lt_info("%s: playstate == VIDEO_PLAYING, stopping video\n", __func__); - Stop(); - stopped = true; - } ret = proc_put("/proc/stb/video/videomode", modes[video_system],strlen(modes[video_system])); - if (stopped) - Start(); return ret; } From 493e5a395540a63a478f6e487d99e7503ac2bc45 Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Sat, 28 Sep 2013 18:25:45 +0200 Subject: [PATCH 6/7] cVideo: add dummy functions for PIP stuff Origin commit data ------------------ Branch: master Commit: https://github.com/neutrino-images/ni-libstb-hal/commit/28b21d2295317485a52fd72d7394dce506ad34c0 Author: Stefan Seyfried Date: 2013-09-28 (Sat, 28 Sep 2013) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- azbox/video.cpp | 7 ++++++- azbox/video_lib.h | 4 +++- generic-pc/video.cpp | 7 ++++++- generic-pc/video_lib.h | 4 +++- libspark/video.cpp | 9 +++++++-- libspark/video_lib.h | 4 +++- libtriple/video_td.cpp | 7 ++++++- libtriple/video_td.h | 4 +++- 8 files changed, 37 insertions(+), 9 deletions(-) diff --git a/azbox/video.cpp b/azbox/video.cpp index 2477e60..bf08c65 100644 --- a/azbox/video.cpp +++ b/azbox/video.cpp @@ -74,7 +74,7 @@ static void show_iframe(int fd, unsigned char *iframe, size_t st_size); #define VIDEO_STREAMTYPE_VC1_SM 5 #define VIDEO_STREAMTYPE_MPEG1 6 -cVideo::cVideo(int, void *, void *) +cVideo::cVideo(int, void *, void *, unsigned int) { lt_debug("%s\n", __FUNCTION__); @@ -628,3 +628,8 @@ static void show_iframe(int fd, unsigned char *iframe, size_t st_size) ioctl(fd, VIDEO_STOP, 0); ioctl(fd, VIDEO_SELECT_SOURCE, VIDEO_SOURCE_DEMUX); } + +void cVideo::SetDemux(cDemux *) +{ + lt_debug("%s: not implemented yet\n", __func__); +} diff --git a/azbox/video_lib.h b/azbox/video_lib.h index c26d2bd..c7286e9 100644 --- a/azbox/video_lib.h +++ b/azbox/video_lib.h @@ -3,6 +3,7 @@ #include #include "../common/cs_types.h" +#include "dmx_lib.h" typedef enum { ANALOG_SD_RGB_CINCH = 0x00, @@ -141,7 +142,7 @@ class cVideo void closeDevice(void); public: /* constructor & destructor */ - cVideo(int mode, void *, void *); + cVideo(int mode, void *, void *, unsigned int unit = 0); ~cVideo(void); void * GetTVEnc() { return NULL; }; @@ -189,6 +190,7 @@ class cVideo int CloseVBI(void) { return 0; }; int StartVBI(unsigned short) { return 0; }; int StopVBI(void) { return 0; }; + void SetDemux(cDemux *dmx); }; #endif diff --git a/generic-pc/video.cpp b/generic-pc/video.cpp index 0b39414..912cbeb 100644 --- a/generic-pc/video.cpp +++ b/generic-pc/video.cpp @@ -65,7 +65,7 @@ static const AVRational aspect_ratios[6] = { { -1,-1 } }; -cVideo::cVideo(int, void *, void *) +cVideo::cVideo(int, void *, void *, unsigned int) { lt_debug("%s\n", __func__); av_register_all(); @@ -660,3 +660,8 @@ int64_t cVideo::GetPTS(void) buf_m.unlock(); return pts; } + +void cVideo::SetDemux(cDemux *) +{ + lt_debug("%s: not implemented yet\n", __func__); +} diff --git a/generic-pc/video_lib.h b/generic-pc/video_lib.h index 69ab36a..72ce7e5 100644 --- a/generic-pc/video_lib.h +++ b/generic-pc/video_lib.h @@ -6,6 +6,7 @@ #include #include #include "../common/cs_types.h" +#include "dmx_lib.h" extern "C" { #include } @@ -147,7 +148,7 @@ class cVideo : public OpenThreads::Thread int64_t GetPTS(void); public: /* constructor & destructor */ - cVideo(int mode, void *, void *); + cVideo(int mode, void *, void *, unsigned int unit = 0); ~cVideo(void); void * GetTVEnc() { return NULL; }; @@ -194,6 +195,7 @@ class cVideo : public OpenThreads::Thread int CloseVBI(void) { return 0; }; int StartVBI(unsigned short) { return 0; }; int StopVBI(void) { return 0; }; + void SetDemux(cDemux *dmx); bool GetScreenImage(unsigned char * &data, int &xres, int &yres, bool get_video = true, bool get_osd = false, bool scale_to_video = false); SWFramebuffer *getDecBuf(void); private: diff --git a/libspark/video.cpp b/libspark/video.cpp index 91f14f1..b1e3a20 100644 --- a/libspark/video.cpp +++ b/libspark/video.cpp @@ -141,9 +141,9 @@ out: } -cVideo::cVideo(int, void *, void *) +cVideo::cVideo(int, void *, void *, unsigned int unit) { - lt_debug("%s\n", __FUNCTION__); + lt_debug("%s unit %u\n", __func__, unit); //croppingMode = VID_DISPMODE_NORM; //outputformat = VID_OUTFMT_RGBC_SVIDEO; @@ -667,3 +667,8 @@ int64_t cVideo::GetPTS(void) lt_info("%s: GET_PTS failed (%m)\n", __func__); return pts; } + +void cVideo::SetDemux(cDemux *) +{ + lt_debug("%s not implemented yet\n", __func__); +} diff --git a/libspark/video_lib.h b/libspark/video_lib.h index c26d2bd..c7286e9 100644 --- a/libspark/video_lib.h +++ b/libspark/video_lib.h @@ -3,6 +3,7 @@ #include #include "../common/cs_types.h" +#include "dmx_lib.h" typedef enum { ANALOG_SD_RGB_CINCH = 0x00, @@ -141,7 +142,7 @@ class cVideo void closeDevice(void); public: /* constructor & destructor */ - cVideo(int mode, void *, void *); + cVideo(int mode, void *, void *, unsigned int unit = 0); ~cVideo(void); void * GetTVEnc() { return NULL; }; @@ -189,6 +190,7 @@ class cVideo int CloseVBI(void) { return 0; }; int StartVBI(unsigned short) { return 0; }; int StopVBI(void) { return 0; }; + void SetDemux(cDemux *dmx); }; #endif diff --git a/libtriple/video_td.cpp b/libtriple/video_td.cpp index f3dfaa7..f5c2fd6 100644 --- a/libtriple/video_td.cpp +++ b/libtriple/video_td.cpp @@ -70,7 +70,7 @@ static pthread_mutex_t stillp_mutex = PTHREAD_MUTEX_INITIALIZER; /* debugging hacks */ static bool noscart = false; -cVideo::cVideo(int, void *, void *) +cVideo::cVideo(int, void *, void *, unsigned int) { lt_debug("%s\n", __FUNCTION__); if ((fd = open(VIDEO_DEVICE, O_RDWR)) < 0) @@ -1098,3 +1098,8 @@ bool cVideo::GetScreenImage(unsigned char * &video, int &xres, int &yres, bool g close(mfd); return true; } + +void cVideo::SetDemux(cDemux *) +{ + lt_debug("%s: not implemented yet\n", __func__); +} diff --git a/libtriple/video_td.h b/libtriple/video_td.h index 58cdaa0..d689420 100644 --- a/libtriple/video_td.h +++ b/libtriple/video_td.h @@ -5,6 +5,7 @@ #define video_format_t vidDispSize_t //#define video_displayformat_t vidDispMode_t #include "../common/cs_types.h" +#include "dmx_td.h" #define STB_HAL_VIDEO_HAS_GETSCREENIMAGE 1 @@ -138,7 +139,7 @@ class cVideo int video_standby; public: /* constructor & destructor */ - cVideo(int mode, void *, void *); + cVideo(int mode, void *, void *, unsigned int unit = 0); ~cVideo(void); void * GetTVEnc() { return NULL; }; @@ -188,6 +189,7 @@ class cVideo int CloseVBI(void) { return 0; }; int StartVBI(unsigned short) { return 0; }; int StopVBI(void) { return 0; }; + void SetDemux(cDemux *dmx); bool GetScreenImage(unsigned char * &data, int &xres, int &yres, bool get_video = true, bool get_osd = false, bool scale_to_video = false); }; From 8eba568defa84dda73391818083510a8f6ddb8dc Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Sat, 28 Sep 2013 18:32:03 +0200 Subject: [PATCH 7/7] spark: implement stuff needed for PIP note that this does now work well at least on st7162 and thus is not really tested. Origin commit data ------------------ Branch: master Commit: https://github.com/neutrino-images/ni-libstb-hal/commit/642de31a8b2bdea47be8c15b2119e024ad8d6104 Author: Stefan Seyfried Date: 2013-09-28 (Sat, 28 Sep 2013) ------------------ This commit was generated by Migit --- libspark/dmx.cpp | 3 ++ libspark/video.cpp | 75 +++++++++++++++++++++++++++++++------------- libspark/video_lib.h | 1 + 3 files changed, 58 insertions(+), 21 deletions(-) diff --git a/libspark/dmx.cpp b/libspark/dmx.cpp index da9780d..6c11749 100644 --- a/libspark/dmx.cpp +++ b/libspark/dmx.cpp @@ -490,6 +490,9 @@ bool cDemux::pesFilter(const unsigned short pid) case DMX_VIDEO_CHANNEL: p_flt.pes_type = DMX_PES_VIDEO; break; + case DMX_PIP_CHANNEL: /* PIP is a special version of DMX_VIDEO_CHANNEL */ + p_flt.pes_type = DMX_PES_VIDEO1; + break; case DMX_PES_CHANNEL: p_flt.pes_type = DMX_PES_OTHER; p_flt.output = DMX_OUT_TAP; diff --git a/libspark/video.cpp b/libspark/video.cpp index b1e3a20..ca27cac 100644 --- a/libspark/video.cpp +++ b/libspark/video.cpp @@ -34,7 +34,6 @@ #include #include #include "video_lib.h" -#define VIDEO_DEVICE "/dev/dvb/adapter0/video0" #include "lt_debug.h" #define lt_debug(args...) _lt_debug(TRIPLE_DEBUG_VIDEO, this, args) #define lt_info(args...) _lt_info(TRIPLE_DEBUG_VIDEO, this, args) @@ -54,11 +53,42 @@ }) cVideo * videoDecoder = NULL; +cVideo * pipDecoder = NULL; int system_rev = 0; static bool hdmi_enabled = true; static bool stillpicture = false; +static const char *VDEV[] = { + "/dev/dvb/adapter0/video0", + "/dev/dvb/adapter0/video1" +}; +static const char *VMPEG_aspect[] = { + "/proc/stb/vmpeg/0/aspect", + "/proc/stb/vmpeg/1/aspect" +}; + +static const char *VMPEG_xres[] = { + "/proc/stb/vmpeg/0/xres", + "/proc/stb/vmpeg/1/xres" +}; + +static const char *VMPEG_yres[] = { + "/proc/stb/vmpeg/0/yres", + "/proc/stb/vmpeg/1/yres" +}; + +static const char *VMPEG_dst_all[] = { + "/proc/stb/vmpeg/0/dst_all", + "/proc/stb/vmpeg/1/dst_all" +}; + +static const char *VMPEG_framerate[] = { + "/proc/stb/vmpeg/0/framerate", + "/proc/stb/vmpeg/1/framerate" +}; + + #define VIDEO_STREAMTYPE_MPEG2 0 #define VIDEO_STREAMTYPE_MPEG4_H264 1 #define VIDEO_STREAMTYPE_VC1 3 @@ -149,6 +179,11 @@ cVideo::cVideo(int, void *, void *, unsigned int unit) //outputformat = VID_OUTFMT_RGBC_SVIDEO; scartvoltage = -1; video_standby = 0; + if (unit > 1) { + lt_info("%s: unit %d out of range, setting to 0\n", __func__, unit); + devnum = 0; + } else + devnum = unit; fd = -1; openDevice(); } @@ -161,12 +196,12 @@ cVideo::~cVideo(void) void cVideo::openDevice(void) { int n = 0; - lt_debug("%s\n", __func__); + lt_debug("#%d: %s\n", devnum, __func__); /* todo: this fd checking is racy, should be protected by a lock */ if (fd != -1) /* already open */ return; retry: - if ((fd = open(VIDEO_DEVICE, O_RDWR)) < 0) + if ((fd = open(VDEV[devnum], O_RDWR|O_CLOEXEC)) < 0) { if (errno == EBUSY) { @@ -175,10 +210,8 @@ retry: if (++n < 10) goto retry; } - lt_info("%s cannot open %s: %m, retries %d\n", __func__, VIDEO_DEVICE, n); + lt_info("#%d: %s cannot open %s: %m, retries %d\n", devnum, __func__, VDEV[devnum], n); } - else - fcntl(fd, F_SETFD, FD_CLOEXEC); playstate = VIDEO_STOPPED; } @@ -226,7 +259,7 @@ int cVideo::getAspectRatio(void) if (fd == -1) { /* in movieplayer mode, fd is not opened -> fall back to procfs */ - int n = proc_get_hex("/proc/stb/vmpeg/0/aspect"); + int n = proc_get_hex(VMPEG_aspect[devnum]); return n * 2 + 1; } if (fop(ioctl, VIDEO_GET_SIZE, &s) < 0) @@ -234,7 +267,7 @@ int cVideo::getAspectRatio(void) lt_info("%s: VIDEO_GET_SIZE %m\n", __func__); return -1; } - lt_debug("%s: %d\n", __func__, s.aspect_ratio); + lt_debug("#%d: %s: %d\n", devnum, __func__, s.aspect_ratio); return s.aspect_ratio * 2 + 1; } @@ -256,7 +289,7 @@ int cVideo::setCroppingMode(int /*vidDispMode_t format*/) int cVideo::Start(void * /*PcrChannel*/, unsigned short /*PcrPid*/, unsigned short /*VideoPid*/, void * /*hChannel*/) { - lt_debug("%s playstate=%d\n", __FUNCTION__, playstate); + lt_debug("#%d: %s playstate=%d\n", devnum, __func__, playstate); #if 0 if (playstate == VIDEO_PLAYING) return 0; @@ -270,7 +303,7 @@ int cVideo::Start(void * /*PcrChannel*/, unsigned short /*PcrPid*/, unsigned sho int cVideo::Stop(bool blank) { - lt_debug("%s(%d)\n", __FUNCTION__, blank); + lt_debug("#%d: %s(%d)\n", devnum, __func__, blank); if (stillpicture) { lt_debug("%s: stillpicture == true\n", __func__); @@ -341,7 +374,7 @@ int cVideo::getPlayState(void) void cVideo::SetVideoMode(analog_mode_t mode) { - lt_debug("%s(%d)\n", __func__, mode); + lt_debug("#%d: %s(%d)\n", devnum, __func__, mode); if (!(mode & ANALOG_SCART_MASK)) { lt_debug("%s: non-SCART mode ignored\n", __func__); @@ -513,7 +546,7 @@ int cVideo::getBlank(void) free(line); fclose(f); int ret = (count == lastcount); /* no new decode -> return 1 */ - lt_debug("%s: %d (irq++: %d)\n", __func__, ret, count - lastcount); + lt_debug("#%d: %s: %d (irq++: %d)\n", devnum, __func__, ret, count - lastcount); lastcount = count; return ret; } @@ -545,7 +578,7 @@ void cVideo::Pig(int x, int y, int w, int h, int osd_w, int osd_h) * TODO: check this in the driver sources */ int xres = 720; /* proc_get_hex("/proc/stb/vmpeg/0/xres") */ int yres = 576; /* proc_get_hex("/proc/stb/vmpeg/0/yres") */ - lt_debug("%s: x:%d y:%d w:%d h:%d ow:%d oh:%d\n", __func__, x, y, w, h, osd_w, osd_h); + lt_debug("#%d %s: x:%d y:%d w:%d h:%d ow:%d oh:%d\n", devnum, __func__, x, y, w, h, osd_w, osd_h); if (x == -1 && y == -1 && w == -1 && h == -1) { _w = xres; @@ -560,9 +593,9 @@ void cVideo::Pig(int x, int y, int w, int h, int osd_w, int osd_h) _y = y * yres / osd_h; _h = h * yres / osd_h; } - lt_debug("%s: x:%d y:%d w:%d h:%d xr:%d yr:%d\n", __func__, _x, _y, _w, _h, xres, yres); + lt_debug("#%d %s: x:%d y:%d w:%d h:%d xr:%d yr:%d\n", devnum, __func__, _x, _y, _w, _h, xres, yres); sprintf(buffer, "%x %x %x %x", _x, _y, _w, _h); - proc_put("/proc/stb/vmpeg/0/dst_all", buffer, strlen(buffer)); + proc_put(VMPEG_dst_all[devnum], buffer, strlen(buffer)); } static inline int rate2csapi(int rate) @@ -598,9 +631,9 @@ void cVideo::getPictureInfo(int &width, int &height, int &rate) if (fd == -1) { /* in movieplayer mode, fd is not opened -> fall back to procfs */ - r = proc_get_hex("/proc/stb/vmpeg/0/framerate"); - width = proc_get_hex("/proc/stb/vmpeg/0/xres"); - height = proc_get_hex("/proc/stb/vmpeg/0/yres"); + r = proc_get_hex(VMPEG_framerate[devnum]); + width = proc_get_hex(VMPEG_xres[devnum]); + height = proc_get_hex(VMPEG_yres[devnum]); rate = rate2csapi(r); return; } @@ -609,7 +642,7 @@ void cVideo::getPictureInfo(int &width, int &height, int &rate) rate = rate2csapi(r); height = s.h; width = s.w; - lt_debug("%s: rate: %d, width: %d height: %d\n", __func__, rate, width, height); + lt_debug("#%d: %s: rate: %d, width: %d height: %d\n", devnum, __func__, rate, width, height); } void cVideo::SetSyncMode(AVSYNC_TYPE mode) @@ -639,7 +672,7 @@ int cVideo::SetStreamType(VIDEO_FORMAT type) "VIDEO_FORMAT_PNG" }; int t; - lt_debug("%s type=%s\n", __FUNCTION__, VF[type]); + lt_debug("#%d: %s type=%s\n", devnum, __func__, VF[type]); switch (type) { @@ -670,5 +703,5 @@ int64_t cVideo::GetPTS(void) void cVideo::SetDemux(cDemux *) { - lt_debug("%s not implemented yet\n", __func__); + lt_debug("#%d %s not implemented yet\n", devnum, __func__); } diff --git a/libspark/video_lib.h b/libspark/video_lib.h index c7286e9..d8fab63 100644 --- a/libspark/video_lib.h +++ b/libspark/video_lib.h @@ -120,6 +120,7 @@ class cVideo private: /* video device */ int fd; + unsigned int devnum; /* apparently we cannot query the driver's state => remember it */ video_play_state_t playstate;