From 5d8b1e2f1127f16f36a093ddb24f248c5968865e Mon Sep 17 00:00:00 2001
From: Lawrence Rust <lvr@softsystem.co.uk>
Date: Tue, 17 May 2011 22:53:28 +0200
Subject: [PATCH 36/36] Fix building video4linux without using v1 headers

Linux >= 2.6.38 doesn't support v4l v1 and distributions using it don't ship
the <linux/videodev.h> header.  This patch enables building with v4l2 only.

Signed-off-by: Lawrence Rust <lvr@softsystem.co.uk>
---
 mythtv/configure                              |    5 +++-
 mythtv/libs/libmythtv/NuppelVideoRecorder.cpp |   21 ++++++++++++++-
 mythtv/libs/libmythtv/analogsignalmonitor.cpp |    5 +++
 mythtv/libs/libmythtv/cardutil.cpp            |    6 ++++
 mythtv/libs/libmythtv/libmythtv.pro           |    1 +
 mythtv/libs/libmythtv/v4lchannel.cpp          |   34 +++++++++++++++++++++++++
 mythtv/libs/libmythtv/vbitext/vbi.c           |    7 +++++
 7 files changed, 76 insertions(+), 3 deletions(-)

diff --git a/mythtv/configure b/mythtv/configure
index db4f661..6dfc445 100755
--- a/mythtv/configure
+++ b/mythtv/configure
@@ -1316,6 +1316,7 @@ MYTHTV_CONFIG_LIST='
     qtwebkit
     quartz_video
     v4l
+    v4l1
     valgrind
     x11
     xrandr
@@ -1715,7 +1716,8 @@ mythtranscode_deps="backend frontend"
 opengl_deps_any="agl_h GL_gl_h darwin windows x11"
 opengl_video_deps="opengl"
 opengl_vsync_deps="opengl"
-v4l_deps="backend linux_videodev_h linux_videodev2_h"
+v4l_deps="backend linux_videodev2_h"
+v4l1_deps="backend linux_videodev_h"
 vdpau_deps="opengl vdpau_vdpau_h vdpau_vdpau_x11_h"
 xrandr_deps="x11"
 xv_deps="x11"
@@ -1935,6 +1937,7 @@ enable opengl_vsync
 enable opengl_video
 enable quartz_video
 enable v4l
+enable v4l1
 enable x11
 enable xrandr
 enable xv
diff --git a/mythtv/libs/libmythtv/NuppelVideoRecorder.cpp b/mythtv/libs/libmythtv/NuppelVideoRecorder.cpp
index 739634d..b592fbe 100644
--- a/mythtv/libs/libmythtv/NuppelVideoRecorder.cpp
+++ b/mythtv/libs/libmythtv/NuppelVideoRecorder.cpp
@@ -43,7 +43,9 @@ extern "C" {
 }
 
 #ifdef USING_V4L
+#ifdef USING_V4L1
 #include <linux/videodev.h>
+#endif
 #include <linux/videodev2.h>
 
 #include "go7007_myth.h"
@@ -829,7 +831,7 @@ int NuppelVideoRecorder::AudioInit(bool skipdevice)
  */
 bool NuppelVideoRecorder::MJPEGInit(void)
 {
-#ifdef USING_V4L
+#ifdef USING_V4L1
     bool we_opened_fd = false;
     int init_fd = fd;
     if (init_fd < 0)
@@ -1130,11 +1132,13 @@ void NuppelVideoRecorder::StartRecording(void)
         DoV4L2();
         return;
     }
+#ifdef USING_V4L1
     else
         DoV4L();
+#endif
 }
 
-#ifdef USING_V4L
+#ifdef USING_V4L1
 void NuppelVideoRecorder::DoV4L(void)
 {
     struct video_capability vc;
@@ -1320,7 +1324,12 @@ void NuppelVideoRecorder::DoV4L(void)
     recording = false;
     close(fd);
 }
+#else
+void NuppelVideoRecorder::DoV4L(void)         {}
+#endif
 
+
+#ifdef USING_V4L
 bool NuppelVideoRecorder::SetFormatV4L2(void)
 {
     struct v4l2_format     vfmt;
@@ -1720,6 +1729,7 @@ again:
     close(channelfd);
 }
 
+#ifdef USING_V4L1
 void NuppelVideoRecorder::DoMJPEG(void)
 {
     struct mjpeg_params bparm;
@@ -1855,6 +1865,9 @@ void NuppelVideoRecorder::DoMJPEG(void)
     recording = false;
     close(fd);
 }
+#else
+void NuppelVideoRecorder::DoMJPEG(void)       {}
+#endif
 
 #else  // USING_V4L
 void NuppelVideoRecorder::DoV4L(void)         {}
@@ -2732,6 +2745,7 @@ void NuppelVideoRecorder::doVbiThread(void)
             vbi_add_handler(pal_tt, (void*) vbi_event, &vbicallbackdata);
         }
     }
+#ifdef USING_V4L1
     else if (VBIMode::NTSC_CC == vbimode)
     {
         ntsc_cc = new struct cc;
@@ -2746,6 +2760,7 @@ void NuppelVideoRecorder::doVbiThread(void)
         if (vbifd < 0)
             delete ntsc_cc;
     }
+#endif
     else
     {
         VERBOSE(VB_IMPORTANT, LOC_ERR + "Invalid CC/Teletext mode");
@@ -2759,6 +2774,7 @@ void NuppelVideoRecorder::doVbiThread(void)
         return;
     }
 
+#ifdef USING_V4L1
     if (VBIMode::NTSC_CC == vbimode)
     {
         // V4L v1 VBI ioctls
@@ -2794,6 +2810,7 @@ void NuppelVideoRecorder::doVbiThread(void)
             return;
         }
     }
+#endif
 
     // Qt4 requires a QMutex as a parameter...
     // not sure if this is the best solution.  Mutex Must be locked before wait.
diff --git a/mythtv/libs/libmythtv/analogsignalmonitor.cpp b/mythtv/libs/libmythtv/analogsignalmonitor.cpp
index 2a4f4c5..acdf74d 100644
--- a/mythtv/libs/libmythtv/analogsignalmonitor.cpp
+++ b/mythtv/libs/libmythtv/analogsignalmonitor.cpp
@@ -6,7 +6,10 @@
 #include <sys/ioctl.h>
 #include <poll.h>
 
+#ifdef USING_V4L1
 #include <linux/videodev.h>
+#endif
+#include <linux/videodev2.h>
 
 #include "mythverbose.h"
 #include "analogsignalmonitor.h"
@@ -149,6 +152,7 @@ void AnalogSignalMonitor::UpdateValues(void)
             }
         }
     }
+#ifdef USING_V4L1
     else
     {
         struct video_tuner tuner;
@@ -164,6 +168,7 @@ void AnalogSignalMonitor::UpdateValues(void)
             isLocked = tuner.signal;
         }
     }
+#endif
 
     {
         QMutexLocker locker(&statusLock);
diff --git a/mythtv/libs/libmythtv/cardutil.cpp b/mythtv/libs/libmythtv/cardutil.cpp
index 8852682..566aa4d 100644
--- a/mythtv/libs/libmythtv/cardutil.cpp
+++ b/mythtv/libs/libmythtv/cardutil.cpp
@@ -27,7 +27,9 @@
 #endif
 
 #ifdef USING_V4L
+#ifdef USING_V4L1
 #include <linux/videodev.h>
+#endif
 #include <linux/videodev2.h>
 #endif
 
@@ -1485,12 +1487,14 @@ bool CardUtil::GetV4LInfo(
         driver = QString::fromAscii((const char*)capability.driver);
         version = capability.version;
     }
+#ifdef USING_V4L1
     else // Fallback to V4L1 query
     {
         struct video_capability capability;
         if (ioctl(videofd, VIDIOCGCAP, &capability) >= 0)
             card = QString::fromAscii((const char*)capability.name);
     }
+#endif
 #endif // !USING_V4L
 
     if (!driver.isEmpty())
@@ -1524,6 +1528,7 @@ InputNames CardUtil::ProbeV4LVideoInputs(int videofd, bool &ok)
         return list;
     }
 
+#ifdef USING_V4L1
     // V4L v1 query
     struct video_capability vidcap;
     bzero(&vidcap, sizeof(vidcap));
@@ -1558,6 +1563,7 @@ InputNames CardUtil::ProbeV4LVideoInputs(int videofd, bool &ok)
         list[0] = "Television";
 
     ok = true;
+#endif
 #else // if !USING_V4L
     list[-1] += QObject::tr("ERROR, Compile with V4L support to query inputs");
 #endif // !USING_V4L
diff --git a/mythtv/libs/libmythtv/libmythtv.pro b/mythtv/libs/libmythtv/libmythtv.pro
index 662587b..53a48e1 100644
--- a/mythtv/libs/libmythtv/libmythtv.pro
+++ b/mythtv/libs/libmythtv/libmythtv.pro
@@ -477,6 +477,7 @@ using_backend {
 
         DEFINES += USING_V4L
     }
+    using_v4l1:DEFINES += USING_V4L1
 
     # Support for cable boxes that provide Firewire out
     using_firewire {
diff --git a/mythtv/libs/libmythtv/v4lchannel.cpp b/mythtv/libs/libmythtv/v4lchannel.cpp
index bc82b49..b24f6c6 100644
--- a/mythtv/libs/libmythtv/v4lchannel.cpp
+++ b/mythtv/libs/libmythtv/v4lchannel.cpp
@@ -16,7 +16,9 @@
 #include <iostream>
 using namespace std;
 
+#ifdef USING_V4L1
 #include <linux/videodev.h>
+#endif
 #include <linux/videodev2.h>
 
 // MythTV headers
@@ -146,6 +148,7 @@ static int format_to_mode(const QString &fmt, int v4l_version)
             return V4L2_STD_PAL;
         return V4L2_STD_NTSC;
     }
+#ifdef USING_V4L1
     else if (1 == v4l_version)
     {
         if (fmt == "NTSC-JP")
@@ -167,6 +170,7 @@ static int format_to_mode(const QString &fmt, int v4l_version)
             return VIDEO_MODE_NTSC; // We've dropped V4L ATSC support...
         return VIDEO_MODE_NTSC;
     }
+#endif
 
     VERBOSE(VB_IMPORTANT,
             "format_to_mode() does not recognize V4L" << v4l_version);
@@ -235,6 +239,7 @@ static QString mode_to_format(int mode, int v4l_version)
             return "ATSC";
         }
     }
+#ifdef USING_V4L1
     else if (1 == v4l_version)
     {
         if (mode == VIDEO_MODE_NTSC)
@@ -250,6 +255,7 @@ static QString mode_to_format(int mode, int v4l_version)
         else if (mode == 6)
             return "NTSC-JP";
     }
+#endif
     else
     {
         VERBOSE(VB_IMPORTANT,
@@ -676,6 +682,7 @@ bool V4LChannel::Tune(uint frequency, QString inputname,
         return true;
     }
 
+#ifdef USING_V4L1
     // Video4Linux version 1 tuning
     uint freq = frequency / 62500;
     ioctlval = ioctl(videofd, VIDIOCSFREQ, &freq);
@@ -691,6 +698,9 @@ bool V4LChannel::Tune(uint frequency, QString inputname,
     SetSIStandard(si_std);
 
     return true;
+#else
+    return false;
+#endif
 }
 
 /** \fn V4LChannel::Retune(void)
@@ -787,7 +797,9 @@ bool V4LChannel::SetInputAndFormat(int inputNum, QString newFmt)
         return false;
 
     int inputNumV4L = (*it)->inputNumV4L;
+#ifdef USING_V4L1
     bool usingv4l1 = !usingv4l2;
+#endif
     bool ok = true;
 
     QString msg =
@@ -856,6 +868,7 @@ bool V4LChannel::SetInputAndFormat(int inputNum, QString newFmt)
         }
     }
 
+#ifdef USING_V4L1
     if (usingv4l1)
     {
         VERBOSE(VB_CHANNEL, LOC + msg + "(v4l v1)");
@@ -883,6 +896,9 @@ bool V4LChannel::SetInputAndFormat(int inputNum, QString newFmt)
         }
     }
     return ok;
+#else
+    return false;
+#endif
 }
 
 bool V4LChannel::SwitchToInput(int inputnum, bool setstarting)
@@ -951,6 +967,7 @@ bool V4LChannel::SwitchToInput(int inputnum, bool setstarting)
     return ok;
 }
 
+#ifdef USING_V4L1
 static unsigned short *get_v4l1_field(
     int v4l2_attrib, struct video_picture &vid_pic)
 {
@@ -970,6 +987,7 @@ static unsigned short *get_v4l1_field(
     }
     return NULL;
 }
+#endif
 
 static int get_v4l2_attribute(const QString &db_col_name)
 {
@@ -1066,6 +1084,7 @@ bool V4LChannel::InitPictureAttribute(const QString db_col_name)
         return true;
     }
 
+#ifdef USING_V4L1
     // V4L1
     unsigned short *setfield;
     struct video_picture vid_pic;
@@ -1087,6 +1106,9 @@ bool V4LChannel::InitPictureAttribute(const QString db_col_name)
         VERBOSE(VB_IMPORTANT, loc_err + "failed to set controls." + ENO);
         return false;
     }
+#else
+    return false;
+#endif
 
     return true;
 }
@@ -1152,6 +1174,7 @@ static int get_v4l2_attribute_value(int videofd, int v4l2_attrib)
     return min(max((int)(mult * (ctrl.value - qctrl.minimum)), 0), 65525);
 }
 
+#ifdef USING_V4L1
 static int get_v4l1_attribute_value(int videofd, int v4l2_attrib)
 {
     struct video_picture vid_pic;
@@ -1170,12 +1193,17 @@ static int get_v4l1_attribute_value(int videofd, int v4l2_attrib)
 
     return -1;
 }
+#endif
 
 static int get_attribute_value(bool usingv4l2, int videofd, int v4l2_attrib)
 {
     if (usingv4l2)
         return get_v4l2_attribute_value(videofd, v4l2_attrib);
+#ifdef USING_V4L1
     return get_v4l1_attribute_value(videofd, v4l2_attrib);
+#else
+    return -1;
+#endif
 }
 
 static int set_v4l2_attribute_value(int videofd, int v4l2_attrib, int newvalue)
@@ -1208,6 +1236,7 @@ static int set_v4l2_attribute_value(int videofd, int v4l2_attrib, int newvalue)
     return 0;
 }
 
+#ifdef USING_V4L1
 static int set_v4l1_attribute_value(int videofd, int v4l2_attrib, int newvalue)
 {
     unsigned short *setfield;
@@ -1239,13 +1268,18 @@ static int set_v4l1_attribute_value(int videofd, int v4l2_attrib, int newvalue)
 
     return 0;
 }
+#endif
 
 static int set_attribute_value(bool usingv4l2, int videofd,
                                int v4l2_attrib, int newvalue)
 {
     if (usingv4l2)
         return set_v4l2_attribute_value(videofd, v4l2_attrib, newvalue);
+#ifdef USING_V4L1
     return set_v4l1_attribute_value(videofd, v4l2_attrib, newvalue);
+#else
+    return -1;
+#endif
 }
 
 int V4LChannel::ChangePictureAttribute(
diff --git a/mythtv/libs/libmythtv/vbitext/vbi.c b/mythtv/libs/libmythtv/vbitext/vbi.c
index 15f8d85..65942d0 100644
--- a/mythtv/libs/libmythtv/vbitext/vbi.c
+++ b/mythtv/libs/libmythtv/vbitext/vbi.c
@@ -14,7 +14,9 @@
 //       compiling with -std=c99.  We could remove this in the .pro file,
 //       but that would disable it for all .c files.
 #undef __STRICT_ANSI__
+#ifdef USING_V4L1
 #include <linux/videodev.h>
+#endif
 #include <linux/videodev2.h>
 
 // vbitext headers
@@ -539,6 +541,7 @@ setup_dev(struct vbi *vbi)
     v4l2_format.type = V4L2_BUF_TYPE_VBI_CAPTURE;
     if (ioctl(vbi->fd, VIDIOC_G_FMT, &v4l2_format) == -1)
     {
+#ifdef USING_V4L1
        // not a v4l2 device.  assume bttv and create a standard fmt-struct.
        int size;
        perror("ioctl VIDIOC_G_FMT");
@@ -564,6 +567,10 @@ setup_dev(struct vbi *vbi)
            vbifmt->count[0] = size/2;
            vbifmt->count[1] = size - size/2;
        }
+#else
+       perror("ioctl VIDIOC_G_FMT");
+       return -1;
+#endif
     }
 
     if (set_decode_parms(vbi, vbifmt) == -1)
-- 
1.7.4.1

