diff options
author | Lars Hanisch <dvb@flensrocker.de> | 2014-01-07 22:23:17 +0100 |
---|---|---|
committer | Lars Hanisch <dvb@flensrocker.de> | 2014-01-07 22:23:17 +0100 |
commit | 271b83e9d6e33ec87dea2373eedc3fde17faff95 (patch) | |
tree | 15d09342d544981de4b16fc64bc9b2530f7bd736 | |
parent | 7b55348e7a085be33d1f9b16d77c519df1c8772a (diff) | |
download | vdr-plugin-pvrinput-271b83e9d6e33ec87dea2373eedc3fde17faff95.tar.gz vdr-plugin-pvrinput-271b83e9d6e33ec87dea2373eedc3fde17faff95.tar.bz2 |
use udev to find related radio device
-rw-r--r-- | device.c | 127 | ||||
-rw-r--r-- | device.h | 4 |
2 files changed, 63 insertions, 68 deletions
@@ -43,7 +43,7 @@ cPvrDevice::cPvrDevice(int DeviceNumber, cDevice *ParentDevice) { log(pvrDEBUG2, "new cPvrDevice (%d)", number); v4l2_fd = mpeg_fd = radio_fd = -1; - v4l2_dev = mpeg_dev = radio_dev = -1; + v4l2_dev = mpeg_dev = -1; vpid = apid = tpid = -1; cString devName; struct v4l2_capability video_vcap; @@ -90,64 +90,60 @@ cPvrDevice::cPvrDevice(int DeviceNumber, cDevice *ParentDevice) SupportsSlicedVBI = true; VBIDeviceCount++; log(pvrDEBUG1, "%s supports sliced VBI Capture, total number of VBI capable devices is now %d", *devName, VBIDeviceCount); - - cUdev::Init(); - cUdevDevice *v4ldev = cUdev::GetDeviceFromDevName(*devName); - if (v4ldev != NULL) { - static const char *propertyName = "ID_PATH"; - static const char *vbi_dev_name = "/dev/vbi"; - const char *id_path = v4ldev->GetPropertyValue(propertyName); - if (id_path != NULL) { - cList<cUdevDevice> *v4ldevices = cUdev::EnumDevices("video4linux", propertyName, id_path); - for (cUdevDevice *dev = v4ldevices->First(); dev; dev = v4ldevices->Next(dev)) { - log(pvrDEBUG1, "pvrinput: %s is related to %s", *devName, dev->GetDevnode()); - if (strncmp(dev->GetDevnode(), vbi_dev_name, strlen(vbi_dev_name)) == 0) - vbi_dev = dev->GetDevnode(); - } - delete v4ldevices; - } - delete v4ldev; - } - cUdev::Free(); } + bool supports_radio = false; + if (video_vcap.capabilities & V4L2_CAP_RADIO) + supports_radio = true; + + cUdev::Init(); + cUdevDevice *v4ldev = cUdev::GetDeviceFromDevName(*devName); + if (v4ldev != NULL) { + static const char *propertyName = "ID_PATH"; + static const char *vbi_dev_node = "/dev/vbi"; + static const char *radio_dev_node = "/dev/radio"; + const char *id_path = v4ldev->GetPropertyValue(propertyName); + if (id_path != NULL) { + cList<cUdevDevice> *v4ldevices = cUdev::EnumDevices("video4linux", propertyName, id_path); + for (cUdevDevice *dev = v4ldevices->First(); dev; dev = v4ldevices->Next(dev)) { + log(pvrDEBUG1, "pvrinput: %s is related to %s", *devName, dev->GetDevnode()); + if (SupportsSlicedVBI && (*vbi_devname == NULL) && (strncmp(dev->GetDevnode(), vbi_dev_node, strlen(vbi_dev_node)) == 0)) + vbi_devname = dev->GetDevnode(); + else if (supports_radio && (*radio_devname == NULL) && (strncmp(dev->GetDevnode(), radio_dev_node, strlen(radio_dev_node)) == 0)) + radio_devname = dev->GetDevnode(); + } + delete v4ldevices; + } + delete v4ldev; + } + cUdev::Free(); + if (video_vcap.capabilities & V4L2_CAP_VIDEO_OUTPUT_OVERLAY) hasDecoder = true; //can only be a PVR350 - for (i = 0; i < kMaxPvrDevices; i++) { - if (radio_dev<0 && (video_vcap.capabilities & V4L2_CAP_RADIO)) { //searching matching radio dev - devName = cString::sprintf("/dev/radio%d", i); - radio_fd = open(devName, O_RDWR); - if (radio_fd >= 0) { - memset(&capability, 0, sizeof(capability)); - if (IOCTL(radio_fd, VIDIOC_QUERYCAP, &capability) != 0) - log(pvrERROR, "VIDIOC_QUERYCAP failed, %d:%s", errno, strerror(errno)); - if (!strncmp(*BusID, (const char*)capability.bus_info, strlen(*BusID) - 1)) { - radio_dev = i; // store info for later - log(pvrDEBUG1, "/dev/radio%d = FM radio dev",radio_dev); - } - close(radio_fd); // a pvrusb2 will remain on input 3. The bool FirstChannelSwitch will solve this later - radio_fd = -1; - } + + if (driver == cx88_blackbird) { + for (i = 0; i < kMaxPvrDevices; i++) { + if (mpeg_dev < 0) { // the blackbird uses two (!) different devices, search the other one. + close(v4l2_fd); + v4l2_fd = -1; + devName = cString::sprintf("/dev/video%d", i); + mpeg_fd = open(devName, O_RDWR); + if (mpeg_fd > 0) { + memset(&capability, 0, sizeof(capability)); + IOCTL(mpeg_fd, VIDIOC_QUERYCAP, &capability); + if (!strncmp(*BusID, (const char*)capability.bus_info, strlen(*BusID) - 1) + && !strcmp("cx8800", (const char*)capability.driver)) { + mpeg_dev = v4l2_dev; //for this driver we found mpeg_dev up to now. + v4l2_dev = i; //reassigning, now with correct value. + log(pvrDEBUG1, "/dev/video%d = v4l2 dev (analog properties: volume/hue/brightness/inputs..)", v4l2_dev); + log(pvrDEBUG1, "/dev/video%d = mpeg dev (MPEG properties: bitrates/frame rate/filters..)", mpeg_dev); + } + close(mpeg_fd); + mpeg_fd = -1; + } + } + } // end device search loop } - if (mpeg_dev < 0 && (driver == cx88_blackbird)) { // the blackbird uses two (!) different devices, search the other one. - close(v4l2_fd); - v4l2_fd = -1; - devName = cString::sprintf("/dev/video%d", i); - mpeg_fd = open(devName, O_RDWR); - if (mpeg_fd) { - memset(&capability, 0, sizeof(capability)); - IOCTL(mpeg_fd, VIDIOC_QUERYCAP, &capability); - if (!strncmp(*BusID, (const char*)capability.bus_info, strlen(*BusID) - 1) - && !strcmp("cx8800", (const char*)capability.driver)) { - mpeg_dev = v4l2_dev; //for this driver we found mpeg_dev up to now. - v4l2_dev = i; //reassigning, now with correct value. - log(pvrDEBUG1, "/dev/video%d = v4l2 dev (analog properties: volume/hue/brightness/inputs..)", v4l2_dev); - log(pvrDEBUG1, "/dev/video%d = mpeg dev (MPEG properties: bitrates/frame rate/filters..)", mpeg_dev); - } - close(mpeg_fd); - mpeg_fd = -1; - } - } - } // end device search loop + switch (driver) { case ivtv: //ivtv, cx18, pvrusb2 and hdpvr share the same device. case cx18: @@ -682,13 +678,13 @@ void cPvrDevice::SetEncoderState(eEncState state) bool cPvrDevice::SetVBImode(int vbiLinesPerFrame, int vbistatus) { - if (*vbi_dev && SupportsSlicedVBI) { - log(pvrDEBUG1, "SetVBImode(%d, %d) on %s (%s)", vbiLinesPerFrame, vbistatus, *vbi_dev, CARDNAME[cardname]); + if (*vbi_devname && SupportsSlicedVBI) { + log(pvrDEBUG1, "SetVBImode(%d, %d) on %s (%s)", vbiLinesPerFrame, vbistatus, *vbi_devname, CARDNAME[cardname]); - int vbi_fd = open(*vbi_dev, O_RDWR); + int vbi_fd = open(*vbi_devname, O_RDWR); if (vbi_fd < 0) { log(pvrERROR, "cPvrDevice::SetVBImode(): error opening %s (%s), %d:%s", - *vbi_dev, CARDNAME[cardname], errno, strerror(errno)); + *vbi_devname, CARDNAME[cardname], errno, strerror(errno)); return false; } @@ -705,7 +701,7 @@ bool cPvrDevice::SetVBImode(int vbiLinesPerFrame, int vbistatus) ctrls.count = 1; if (IOCTL(vbi_fd, VIDIOC_S_EXT_CTRLS, &ctrls) != 0) { log(pvrERROR, "cPvrDevice::SetVBImode(): error setting vbi mode (ctrls) on %s (%s), %d:%s", - *vbi_dev, CARDNAME[cardname], errno, strerror(errno)); + *vbi_devname, CARDNAME[cardname], errno, strerror(errno)); close(vbi_fd); return false; } @@ -717,7 +713,7 @@ bool cPvrDevice::SetVBImode(int vbiLinesPerFrame, int vbistatus) if (IOCTL(vbi_fd, VIDIOC_S_FMT, &vbifmt) < 0) { log(pvrERROR, "cPvrDevice::SetVBImode():error setting vbi mode (fmt) on %s (%s), %d:%s", - *vbi_dev, CARDNAME[cardname], errno, strerror(errno)); + *vbi_devname, CARDNAME[cardname], errno, strerror(errno)); close(vbi_fd); return false; } @@ -885,13 +881,12 @@ bool cPvrDevice::OpenDvr(void) case ivtv: case cx18: case pvrusb2: - if (radio_dev < 0) + if (*radio_devname == NULL) return false; //no hardware support. if (radio_fd < 0) { - cString devName = cString::sprintf("/dev/radio%d", radio_dev); - radio_fd = open(devName, O_RDONLY); + radio_fd = open(*radio_devname, O_RDONLY); if (radio_fd < 0) { - log(pvrERROR, "Error opening FM radio device %s: %s", *devName, strerror(errno)); + log(pvrERROR, "Error opening FM radio device %s: %s", *radio_devname, strerror(errno)); return false; } if (driver == pvrusb2) @@ -1117,7 +1112,7 @@ bool cPvrDevice::ProvidesChannel(const cChannel *Channel, int Priority, bool *Ne } } if (inputType == eRadio) { - if (radio_dev < 0) { + if (*radio_devname == NULL) { log(pvrDEBUG1, "cPvrDevice::ProvidesChannel: /dev/video%d (%s) has no radio", number, CARDNAME[cardname]); return false; } @@ -73,7 +73,7 @@ private: int radio_fd; int v4l2_dev; int mpeg_dev; - int radio_dev; + cString radio_devname; int inputs[12]; int numInputs; int vpid; @@ -97,7 +97,7 @@ private: eEncState EncoderState; int driver_apiversion; bool SupportsSlicedVBI; - cString vbi_dev; + cString vbi_devname; bool hasDecoder; bool hasTuner; int streamType; |