00001
00002
00003
00004 #include <cerrno>
00005 #include <unistd.h>
00006 #include <sys/ioctl.h>
00007
00008 #include "videodev_myth.h"
00009 #include "mythcontext.h"
00010 #include "analogsignalmonitor.h"
00011 #include "channel.h"
00012
00013 #define LOC QString("AnalogSM: ").arg(channel->GetDevice())
00014 #define LOC_ERR QString("AnalogSM, Error: ").arg(channel->GetDevice())
00015
00016 AnalogSignalMonitor::AnalogSignalMonitor(int db_cardnum, Channel *_channel,
00017 uint64_t _flags, const char *_name) :
00018 SignalMonitor(db_cardnum, _channel, _flags, _name),
00019 usingv4l2(false)
00020 {
00021 int videofd = channel->GetFd();
00022 if (videofd >= 0)
00023 usingv4l2 = CardUtil::hasV4L2(videofd);
00024 }
00025
00026 #define EMIT(SIGNAL_FUNC, SIGNAL_VAL) \
00027 do { statusLock.lock(); \
00028 SignalMonitorValue val = SIGNAL_VAL; \
00029 statusLock.unlock(); \
00030 emit SIGNAL_FUNC(val); } while (false)
00031
00032 void AnalogSignalMonitor::UpdateValues(void)
00033 {
00034 if (!running || exit)
00035 return;
00036
00037 int videofd = channel->GetFd();
00038 if (videofd < 0)
00039 return;
00040
00041 bool isLocked = false;
00042 if (usingv4l2)
00043 {
00044 struct v4l2_tuner tuner;
00045 bzero(&tuner, sizeof(tuner));
00046
00047 if (ioctl(videofd, VIDIOC_G_TUNER, &tuner, 0) < 0)
00048 {
00049 VERBOSE(VB_IMPORTANT,
00050 LOC_ERR + "Failed to probe signal (v4l2)" + ENO);
00051 }
00052 else
00053 {
00054 isLocked = tuner.signal;
00055 }
00056 }
00057 else
00058 {
00059 struct video_tuner tuner;
00060 bzero(&tuner, sizeof(tuner));
00061
00062 if (ioctl(videofd, VIDIOCGTUNER, &tuner, 0) < 0)
00063 {
00064 VERBOSE(VB_IMPORTANT,
00065 LOC_ERR + "Failed to probe signal (v4l1)" + ENO);
00066 }
00067 else
00068 {
00069 isLocked = tuner.signal;
00070 }
00071 }
00072
00073 {
00074 QMutexLocker locker(&statusLock);
00075 signalLock.SetValue(isLocked);
00076 signalStrength.SetValue(isLocked ? 100 : 0);
00077 }
00078
00079 EMIT(StatusSignalLock, signalLock);
00080 EMIT(StatusSignalStrength, signalStrength);
00081
00082 if (IsAllGood())
00083 emit AllGood();
00084 }
00085
00086 #undef EMIT