Ticket #10519: 10519-v1.patch

File 10519-v1.patch, 11.9 KB (added by danielk, 8 years ago)
  • mythtv/libs/libmythbase/mythdb.cpp

    diff --git a/mythtv/libs/libmythbase/mythdb.cpp b/mythtv/libs/libmythbase/mythdb.cpp
    index 2ab7962..ea30783 100644
    a b bool MythDB::GetSettings(QMap<QString,QString> &_key_value_pairs) 
    452452                }
    453453            }
    454454        }
    455         else
     455        for (; kvit != _key_value_pairs.end(); ++dit, ++kvit)
    456456        {
    457             for (; kvit != _key_value_pairs.end(); ++dit, ++kvit)
     457            SettingsMap::const_iterator it =
     458                d->overriddenSettings.find(dit.key());
     459            if (it != d->overriddenSettings.end())
    458460            {
    459                 SettingsMap::const_iterator it =
    460                     d->overriddenSettings.find(dit.key());
    461                 if (it != d->overriddenSettings.end())
    462                 {
    463                     *kvit = *it;
    464                     *dit = true;
    465                     done_cnt++;
    466                 }
     461                *kvit = *it;
     462                *dit = true;
     463                done_cnt++;
    467464            }
    468465        }
    469466        d->settingsCacheLock.unlock();
    QString MythDB::GetSettingOnHost(const QString &_key, const QString &_host, 
    605602            return value;
    606603        }
    607604    }
    608     else
     605    SettingsMap::const_iterator it = d->overriddenSettings.find(myKey);
     606    if (it != d->overriddenSettings.end())
    609607    {
    610         SettingsMap::const_iterator it = d->overriddenSettings.find(myKey);
    611         if (it != d->overriddenSettings.end())
    612         {
    613             value = *it;
    614             d->settingsCacheLock.unlock();
    615             return value;
    616         }
     608        value = *it;
     609        d->settingsCacheLock.unlock();
     610        return value;
    617611    }
    618612    d->settingsCacheLock.unlock();
    619613
  • mythtv/libs/libmythtv/mpegrecorder.cpp

    diff --git a/mythtv/libs/libmythtv/mpegrecorder.cpp b/mythtv/libs/libmythtv/mpegrecorder.cpp
    index 8728faa..18e1766 100644
    a b bool MpegRecorder::OpenV4L2DeviceAsInput(void) 
    423423        SetRecordingVolume(chanfd); // we don't care if this fails...
    424424
    425425    if (!SetV4L2DeviceOptions(chanfd))
     426    {
     427        close(chanfd);
     428        chanfd = -1;
    426429        return false;
     430    }
    427431
    428432    SetVBIOptions(chanfd); // we don't care if this fails...
    429433
    bool MpegRecorder::OpenV4L2DeviceAsInput(void) 
    451455    if (!_device_read_buffer)
    452456    {
    453457        LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to allocate DRB buffer");
    454         _error = true;
     458        _error = "Failed to allocate DRB buffer";
    455459        close(chanfd);
    456460        chanfd = -1;
    457461        close(readfd);
    bool MpegRecorder::OpenV4L2DeviceAsInput(void) 
    461465
    462466    if (!_device_read_buffer->Setup(vdevice.constData(), readfd))
    463467    {
    464         LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to allocate DRB buffer");
    465         _error = true;
     468        LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to setup DRB buffer");
     469        _error = "Failed to setup DRB buffer";
    466470        close(chanfd);
    467471        chanfd = -1;
    468472        close(readfd);
    void MpegRecorder::run(void) 
    902906{
    903907    if (!Open())
    904908    {
    905         _error = "Failed to open V4L device";
     909        if (_error.isEmpty())
     910            _error = "Failed to open V4L device";
    906911        return;
    907912    }
    908913
    void MpegRecorder::run(void) 
    963968    else if (_device_read_buffer)
    964969    {
    965970        LOG(VB_RECORD, LOG_INFO, LOC + "Initial startup of recorder");
    966 
    967         if (!StartEncoding(readfd))
    968         {
    969             LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to start recording");
    970             _error = true;
    971         }
    972         else
    973             _device_read_buffer->Start();
     971        StartEncoding();
    974972    }
    975973
    976974    QByteArray vdevice = videodevice.toAscii();
    void MpegRecorder::run(void) 
    1000998                }
    1001999            }
    10021000        }
    1003         else
    1004         {
    1005             if (readfd < 0)
    1006             {
    1007                 if (!Open())
    1008                 {
    1009                     _error = true;
    1010                     break;
    1011                 }
    1012 
    1013                 if (readfd < 0)
    1014                 {
    1015                     LOG(VB_GENERAL, LOG_ERR, LOC +
    1016                         QString("Failed to open device '%1'")
    1017                             .arg(videodevice));
    1018                     continue;
    1019                 }
    1020             }
    1021         }
    10221001
    10231002        if (_device_read_buffer)
    10241003        {
    void MpegRecorder::run(void) 
    10361015                     IsRecordingRequested())
    10371016            {
    10381017                LOG(VB_GENERAL, LOG_ERR, LOC + "Device EOF detected");
    1039                 _error = true;
     1018                _error = "Device EOF detected";
    10401019            }
    10411020        }
    10421021        else
    void MpegRecorder::run(void) 
    11331112
    11341113    LOG(VB_RECORD, LOG_INFO, LOC + "run finishing up");
    11351114
    1136     pauseLock.lock();
    1137     if (_device_read_buffer)
    1138     {
    1139         if (_device_read_buffer->IsRunning())
    1140             _device_read_buffer->Stop();
    1141 
    1142         delete _device_read_buffer;
    1143         _device_read_buffer = NULL;
    1144     }
    1145     pauseLock.unlock();
    1146 
    1147     StopEncoding(readfd);
     1115    StopEncoding();
    11481116
    11491117    {
    11501118        QMutexLocker locker(&pauseLock);
    bool MpegRecorder::PauseAndWait(int timeout) 
    12411209        {
    12421210            LOG(VB_RECORD, LOG_INFO, LOC + "PauseAndWait pause");
    12431211
    1244             if (_device_read_buffer)
    1245             {
    1246                 _device_read_buffer->SetRequestPause(true);
    1247                 _device_read_buffer->WaitForPaused(4000);
    1248             }
    1249 
    1250             StopEncoding(readfd);
     1212            StopEncoding();
    12511213
    12521214            paused = true;
    12531215            pauseWait.wakeAll();
    bool MpegRecorder::PauseAndWait(int timeout) 
    12721234            SetV4L2DeviceOptions(chanfd);
    12731235        }
    12741236
    1275         StartEncoding(readfd);
    1276 
    1277         if (_device_read_buffer)
    1278             _device_read_buffer->SetRequestPause(false);
     1237        StartEncoding();
    12791238
    12801239        if (_stream_data)
    12811240            _stream_data->Reset(_stream_data->DesiredProgram());
    void MpegRecorder::RestartEncoding(void) 
    12901249{
    12911250    LOG(VB_RECORD, LOG_INFO, LOC + "RestartEncoding");
    12921251
    1293     _device_read_buffer->Stop();
    1294 
    12951252    QMutexLocker locker(&start_stop_encoding_lock);
    12961253
    1297     StopEncoding(readfd);
     1254    StopEncoding();
    12981255
    12991256    // Make sure the next things in the file are a PAT & PMT
    13001257    if (_stream_data &&
    void MpegRecorder::RestartEncoding(void) 
    13081265
    13091266    if (driver == "hdpvr") // HD-PVR will sometimes reset to defaults
    13101267        SetV4L2DeviceOptions(chanfd);
    1311     if (!StartEncoding(readfd))
    1312     {
    1313         if (0 != close(readfd))
    1314             LOG(VB_GENERAL, LOG_ERR, LOC + "Close error" + ENO);
    13151268
    1316         readfd = -1;
    1317         return;
    1318     }
    1319 
    1320     _device_read_buffer->Start();
     1269    StartEncoding();
    13211270}
    13221271
    1323 bool MpegRecorder::StartEncoding(int fd)
     1272bool MpegRecorder::StartEncoding(void)
    13241273{
    13251274    QMutexLocker locker(&start_stop_encoding_lock);
    13261275
    bool MpegRecorder::StartEncoding(int fd) 
    13331282
    13341283    LOG(VB_RECORD, LOG_INFO, LOC + "StartEncoding");
    13351284
    1336     if (ioctl(fd, VIDIOC_ENCODER_CMD, &command) == 0)
     1285    if (readfd < 0)
     1286    {
     1287        readfd = open(videodevice.toAscii().constData(), O_RDWR | O_NONBLOCK);
     1288        if (readfd < 0)
     1289        {
     1290            LOG(VB_GENERAL, LOG_ERR, LOC +
     1291                "StartEncoding: Can't open video device." + ENO);
     1292            _error = "Failed to start recording";
     1293            return false;
     1294        }
     1295    }
     1296
     1297    bool started = 0 == ioctl(readfd, VIDIOC_ENCODER_CMD, &command);
     1298    if (started)
    13371299    {
    13381300        if (driver == "hdpvr")
    13391301        {
    bool MpegRecorder::StartEncoding(int fd) 
    13411303            _wait_for_keyframe_option = true;
    13421304            _seen_sps = false;
    13431305        }
    1344 
    13451306        LOG(VB_RECORD, LOG_INFO, LOC + "Encoding started");
    1346         return true;
     1307    }
     1308    else if ((ENOTTY == errno) || (EINVAL == errno))
     1309    {
     1310        // Some drivers do not support this ioctl at all.  It is marked as
     1311        // "experimental" in the V4L2 API spec. These drivers return EINVAL
     1312        // in older kernels and ENOTTY in 3.1+
     1313        started = true;
     1314    }
     1315    else
     1316    {
     1317        LOG(VB_GENERAL, LOG_WARNING, LOC + "StartEncoding failed" + ENO);
    13471318    }
    13481319
    1349     // Some drivers do not support this ioctl at all.  It is marked as
    1350     // "experimental" in the V4L2 API spec.  If we fail with EINVAL (which
    1351     // happens if the ioctl isn't supported), treat it as a success, but
    1352     // put a warning in the logs.  This should keep any driver without this
    1353     // support (such as saa7164) recording without affecting those that do
    1354     // use it.
    1355     if (errno == EINVAL)
    1356         return true;
     1320    if (_device_read_buffer)
     1321    {
     1322        _device_read_buffer->Reset(videodevice.toAscii().constData(), readfd);
     1323        _device_read_buffer->Start();
     1324    }
    13571325
    1358     LOG(VB_GENERAL, LOG_WARNING, LOC + "StartEncoding failed" + ENO);
    1359     return false;
     1326    return true;
    13601327}
    13611328
    1362 bool MpegRecorder::StopEncoding(int fd)
     1329bool MpegRecorder::StopEncoding(void)
    13631330{
    13641331    QMutexLocker locker(&start_stop_encoding_lock);
    13651332
     1333    if (readfd < 0)
     1334        return true;
     1335
    13661336    struct v4l2_encoder_cmd command;
    13671337    memset(&command, 0, sizeof(struct v4l2_encoder_cmd));
    13681338    command.cmd   = V4L2_ENC_CMD_STOP;
    bool MpegRecorder::StopEncoding(int fd) 
    13701340
    13711341    LOG(VB_RECORD, LOG_INFO, LOC + "StopEncoding");
    13721342
    1373     if (ioctl(fd, VIDIOC_ENCODER_CMD, &command) == 0)
     1343    bool stopped = 0 == ioctl(readfd, VIDIOC_ENCODER_CMD, &command);
     1344    if (stopped)
    13741345    {
    13751346        LOG(VB_RECORD, LOG_INFO, LOC + "Encoding stopped");
    1376         return true;
     1347    }
     1348    else if ((ENOTTY == errno) || (EINVAL == errno))
     1349    {
     1350        // Some drivers do not support this ioctl at all.  It is marked as
     1351        // "experimental" in the V4L2 API spec. These drivers return EINVAL
     1352        // in older kernels and ENOTTY in 3.1+
     1353        stopped = true;
     1354    }
     1355    else
     1356    {
     1357        LOG(VB_GENERAL, LOG_WARNING, LOC + "StopEncoding failed" + ENO);
    13771358    }
    13781359
    1379     // Some drivers do not support this ioctl at all.  It is marked as
    1380     // "experimental" in the V4L2 API spec.  If we fail with EINVAL (which
    1381     // happens if the ioctl isn't supported), treat it as a success, but
    1382     // put a warning in the logs.  This should keep any driver without this
    1383     // support (such as saa7164) recording without affecting those that do
    1384     // use it.
    1385     if (errno == EINVAL)
    1386         return true;
     1360    if (_device_read_buffer && _device_read_buffer->IsRunning())
     1361    {
     1362        usleep(20 * 1000); // allow last bits of data through..
     1363        _device_read_buffer->Stop();
     1364    }
     1365
     1366    // close the fd so streamoff/streamon work in V4LChannel
     1367    close(readfd);   
     1368    readfd = -1;
    13871369
    1388     LOG(VB_GENERAL, LOG_WARNING, LOC + "StopEncoding failed" + ENO);
    1389     return false;
     1370    return stopped;
    13901371}
    13911372
    13921373void MpegRecorder::SetStreamData(void)
  • mythtv/libs/libmythtv/mpegrecorder.h

    diff --git a/mythtv/libs/libmythtv/mpegrecorder.h b/mythtv/libs/libmythtv/mpegrecorder.h
    index da1b7fc..d27a62d 100644
    a b class MpegRecorder : public V4LRecorder, 
    6868    uint GetFilteredAudioBitRate(uint audio_layer) const;
    6969
    7070    void RestartEncoding(void);
    71     bool StartEncoding(int fd);
    72     bool StopEncoding(int fd);
     71    bool StartEncoding(void);
     72    bool StopEncoding(void);
    7373
    7474    void SetBitrate(int bitrate, int maxbitrate, const QString & reason);
    7575    void HandleResolutionChanges(void);
  • mythtv/libs/libmythtv/v4lchannel.cpp

    diff --git a/mythtv/libs/libmythtv/v4lchannel.cpp b/mythtv/libs/libmythtv/v4lchannel.cpp
    index e8ab9d9..a128523 100644
    a b bool V4LChannel::Open(void) 
    9999    has_tuner      = !!(capabilities & V4L2_CAP_TUNER);
    100100    has_sliced_vbi = !!(capabilities & V4L2_CAP_SLICED_VBI_CAPTURE);
    101101
    102     if (driver_name == "bttv" || driver_name == "cx8800")
    103         has_stream_io = false; // driver workaround, see #9825 & #10519
    104 
    105102    LOG(VB_CHANNEL, LOG_INFO, LOC + QString("Device name '%1' driver '%2'.")
    106103            .arg(device_name).arg(driver_name));
    107104