Ticket #10519: 10519-v2.patch

File 10519-v2.patch, 6.2 KB (added by danielk, 12 years ago)

Updated for latest master

  • mythtv/libs/libmythtv/mpegrecorder.cpp

    diff --git a/mythtv/libs/libmythtv/mpegrecorder.cpp b/mythtv/libs/libmythtv/mpegrecorder.cpp
    index 90724f0..671e508 100644
    a b void MpegRecorder::run(void) 
    968968    else if (_device_read_buffer)
    969969    {
    970970        LOG(VB_RECORD, LOG_INFO, LOC + "Initial startup of recorder");
    971 
    972         if (!StartEncoding(readfd))
    973         {
    974             LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to start recording");
    975             _error = "Failed to start recording";
    976         }
    977         else
    978             _device_read_buffer->Start();
     971        StartEncoding();
    979972    }
    980973
    981974    QByteArray vdevice = videodevice.toAscii();
    void MpegRecorder::run(void) 
    1005998                }
    1006999            }
    10071000        }
    1008         else
    1009         {
    1010             if (readfd < 0)
    1011             {
    1012                 if (!Open())
    1013                 {
    1014                     _error = "Failed to open device";
    1015                     break;
    1016                 }
    1017 
    1018                 if (readfd < 0)
    1019                 {
    1020                     LOG(VB_GENERAL, LOG_ERR, LOC +
    1021                         QString("Failed to open device '%1'")
    1022                             .arg(videodevice));
    1023                     continue;
    1024                 }
    1025             }
    1026         }
    10271001
    10281002        if (_device_read_buffer)
    10291003        {
    void MpegRecorder::run(void) 
    11381112
    11391113    LOG(VB_RECORD, LOG_INFO, LOC + "run finishing up");
    11401114
    1141     pauseLock.lock();
    1142     if (_device_read_buffer)
    1143     {
    1144         if (_device_read_buffer->IsRunning())
    1145             _device_read_buffer->Stop();
    1146 
    1147         delete _device_read_buffer;
    1148         _device_read_buffer = NULL;
    1149     }
    1150     pauseLock.unlock();
    1151 
    1152     StopEncoding(readfd);
     1115    StopEncoding();
    11531116
    11541117    {
    11551118        QMutexLocker locker(&pauseLock);
    bool MpegRecorder::PauseAndWait(int timeout) 
    12461209        {
    12471210            LOG(VB_RECORD, LOG_INFO, LOC + "PauseAndWait pause");
    12481211
    1249             if (_device_read_buffer)
    1250             {
    1251                 _device_read_buffer->SetRequestPause(true);
    1252                 _device_read_buffer->WaitForPaused(4000);
    1253             }
    1254 
    1255             StopEncoding(readfd);
     1212            StopEncoding();
    12561213
    12571214            paused = true;
    12581215            pauseWait.wakeAll();
    bool MpegRecorder::PauseAndWait(int timeout) 
    12771234            SetV4L2DeviceOptions(chanfd);
    12781235        }
    12791236
    1280         StartEncoding(readfd);
    1281 
    1282         if (_device_read_buffer)
    1283             _device_read_buffer->SetRequestPause(false);
     1237        StartEncoding();
    12841238
    12851239        if (_stream_data)
    12861240            _stream_data->Reset(_stream_data->DesiredProgram());
    void MpegRecorder::RestartEncoding(void) 
    12951249{
    12961250    LOG(VB_RECORD, LOG_INFO, LOC + "RestartEncoding");
    12971251
    1298     _device_read_buffer->Stop();
    1299 
    13001252    QMutexLocker locker(&start_stop_encoding_lock);
    13011253
    1302     StopEncoding(readfd);
     1254    StopEncoding();
    13031255
    13041256    // Make sure the next things in the file are a PAT & PMT
    13051257    if (_stream_data &&
    void MpegRecorder::RestartEncoding(void) 
    13131265
    13141266    if (driver == "hdpvr") // HD-PVR will sometimes reset to defaults
    13151267        SetV4L2DeviceOptions(chanfd);
    1316     if (!StartEncoding(readfd))
    1317     {
    1318         if (0 != close(readfd))
    1319             LOG(VB_GENERAL, LOG_ERR, LOC + "Close error" + ENO);
    13201268
    1321         readfd = -1;
    1322         return;
    1323     }
    1324 
    1325     _device_read_buffer->Start();
     1269    StartEncoding();
    13261270}
    13271271
    1328 bool MpegRecorder::StartEncoding(int fd)
     1272bool MpegRecorder::StartEncoding(void)
    13291273{
    13301274    QMutexLocker locker(&start_stop_encoding_lock);
    13311275
    bool MpegRecorder::StartEncoding(int fd) 
    13381282
    13391283    LOG(VB_RECORD, LOG_INFO, LOC + "StartEncoding");
    13401284
    1341     bool started = 0 == ioctl(fd, VIDIOC_ENCODER_CMD, &command);
     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);
    13421298    if (started)
    13431299    {
    13441300        if (driver == "hdpvr")
    bool MpegRecorder::StartEncoding(int fd) 
    13621318        LOG(VB_GENERAL, LOG_WARNING, LOC + "StartEncoding failed" + ENO);
    13631319    }
    13641320
    1365     return started;
     1321    if (_device_read_buffer)
     1322    {
     1323        _device_read_buffer->Reset(videodevice.toAscii().constData(), readfd);
     1324        _device_read_buffer->Start();
     1325    }
     1326
     1327    return true;
    13661328}
    13671329
    1368 bool MpegRecorder::StopEncoding(int fd)
     1330void MpegRecorder::StopEncoding(void)
    13691331{
    13701332    QMutexLocker locker(&start_stop_encoding_lock);
    13711333
     1334    if (readfd < 0)
     1335        return;
     1336
    13721337    struct v4l2_encoder_cmd command;
    13731338    memset(&command, 0, sizeof(struct v4l2_encoder_cmd));
    13741339    command.cmd   = V4L2_ENC_CMD_STOP;
    bool MpegRecorder::StopEncoding(int fd) 
    13761341
    13771342    LOG(VB_RECORD, LOG_INFO, LOC + "StopEncoding");
    13781343
    1379     bool stopped = 0 == ioctl(fd, VIDIOC_ENCODER_CMD, &command);
     1344    bool stopped = 0 == ioctl(readfd, VIDIOC_ENCODER_CMD, &command);
    13801345    if (stopped)
    13811346    {
    13821347        LOG(VB_RECORD, LOG_INFO, LOC + "Encoding stopped");
    bool MpegRecorder::StopEncoding(int fd) 
    13931358        LOG(VB_GENERAL, LOG_WARNING, LOC + "StopEncoding failed" + ENO);
    13941359    }
    13951360
    1396     return stopped;
     1361    if (_device_read_buffer && _device_read_buffer->IsRunning())
     1362    {
     1363        usleep(20 * 1000); // allow last bits of data through..
     1364        _device_read_buffer->Stop();
     1365    }
     1366
     1367    // close the fd so streamoff/streamon work in V4LChannel
     1368    close(readfd);   
     1369    readfd = -1;
    13971370}
    13981371
    13991372void MpegRecorder::SetStreamData(void)
  • mythtv/libs/libmythtv/mpegrecorder.h

    diff --git a/mythtv/libs/libmythtv/mpegrecorder.h b/mythtv/libs/libmythtv/mpegrecorder.h
    index da1b7fc..d4828b4 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    void StopEncoding(void);
    7373
    7474    void SetBitrate(int bitrate, int maxbitrate, const QString & reason);
    7575    void HandleResolutionChanges(void);