diff --git a/mythtv/libs/libmythtv/mpegrecorder.cpp b/mythtv/libs/libmythtv/mpegrecorder.cpp
index 90724f0..671e508 100644
a
|
b
|
void MpegRecorder::run(void) |
968 | 968 | else if (_device_read_buffer) |
969 | 969 | { |
970 | 970 | 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(); |
979 | 972 | } |
980 | 973 | |
981 | 974 | QByteArray vdevice = videodevice.toAscii(); |
… |
… |
void MpegRecorder::run(void) |
1005 | 998 | } |
1006 | 999 | } |
1007 | 1000 | } |
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 | | } |
1027 | 1001 | |
1028 | 1002 | if (_device_read_buffer) |
1029 | 1003 | { |
… |
… |
void MpegRecorder::run(void) |
1138 | 1112 | |
1139 | 1113 | LOG(VB_RECORD, LOG_INFO, LOC + "run finishing up"); |
1140 | 1114 | |
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(); |
1153 | 1116 | |
1154 | 1117 | { |
1155 | 1118 | QMutexLocker locker(&pauseLock); |
… |
… |
bool MpegRecorder::PauseAndWait(int timeout) |
1246 | 1209 | { |
1247 | 1210 | LOG(VB_RECORD, LOG_INFO, LOC + "PauseAndWait pause"); |
1248 | 1211 | |
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(); |
1256 | 1213 | |
1257 | 1214 | paused = true; |
1258 | 1215 | pauseWait.wakeAll(); |
… |
… |
bool MpegRecorder::PauseAndWait(int timeout) |
1277 | 1234 | SetV4L2DeviceOptions(chanfd); |
1278 | 1235 | } |
1279 | 1236 | |
1280 | | StartEncoding(readfd); |
1281 | | |
1282 | | if (_device_read_buffer) |
1283 | | _device_read_buffer->SetRequestPause(false); |
| 1237 | StartEncoding(); |
1284 | 1238 | |
1285 | 1239 | if (_stream_data) |
1286 | 1240 | _stream_data->Reset(_stream_data->DesiredProgram()); |
… |
… |
void MpegRecorder::RestartEncoding(void) |
1295 | 1249 | { |
1296 | 1250 | LOG(VB_RECORD, LOG_INFO, LOC + "RestartEncoding"); |
1297 | 1251 | |
1298 | | _device_read_buffer->Stop(); |
1299 | | |
1300 | 1252 | QMutexLocker locker(&start_stop_encoding_lock); |
1301 | 1253 | |
1302 | | StopEncoding(readfd); |
| 1254 | StopEncoding(); |
1303 | 1255 | |
1304 | 1256 | // Make sure the next things in the file are a PAT & PMT |
1305 | 1257 | if (_stream_data && |
… |
… |
void MpegRecorder::RestartEncoding(void) |
1313 | 1265 | |
1314 | 1266 | if (driver == "hdpvr") // HD-PVR will sometimes reset to defaults |
1315 | 1267 | SetV4L2DeviceOptions(chanfd); |
1316 | | if (!StartEncoding(readfd)) |
1317 | | { |
1318 | | if (0 != close(readfd)) |
1319 | | LOG(VB_GENERAL, LOG_ERR, LOC + "Close error" + ENO); |
1320 | 1268 | |
1321 | | readfd = -1; |
1322 | | return; |
1323 | | } |
1324 | | |
1325 | | _device_read_buffer->Start(); |
| 1269 | StartEncoding(); |
1326 | 1270 | } |
1327 | 1271 | |
1328 | | bool MpegRecorder::StartEncoding(int fd) |
| 1272 | bool MpegRecorder::StartEncoding(void) |
1329 | 1273 | { |
1330 | 1274 | QMutexLocker locker(&start_stop_encoding_lock); |
1331 | 1275 | |
… |
… |
bool MpegRecorder::StartEncoding(int fd) |
1338 | 1282 | |
1339 | 1283 | LOG(VB_RECORD, LOG_INFO, LOC + "StartEncoding"); |
1340 | 1284 | |
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); |
1342 | 1298 | if (started) |
1343 | 1299 | { |
1344 | 1300 | if (driver == "hdpvr") |
… |
… |
bool MpegRecorder::StartEncoding(int fd) |
1362 | 1318 | LOG(VB_GENERAL, LOG_WARNING, LOC + "StartEncoding failed" + ENO); |
1363 | 1319 | } |
1364 | 1320 | |
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; |
1366 | 1328 | } |
1367 | 1329 | |
1368 | | bool MpegRecorder::StopEncoding(int fd) |
| 1330 | void MpegRecorder::StopEncoding(void) |
1369 | 1331 | { |
1370 | 1332 | QMutexLocker locker(&start_stop_encoding_lock); |
1371 | 1333 | |
| 1334 | if (readfd < 0) |
| 1335 | return; |
| 1336 | |
1372 | 1337 | struct v4l2_encoder_cmd command; |
1373 | 1338 | memset(&command, 0, sizeof(struct v4l2_encoder_cmd)); |
1374 | 1339 | command.cmd = V4L2_ENC_CMD_STOP; |
… |
… |
bool MpegRecorder::StopEncoding(int fd) |
1376 | 1341 | |
1377 | 1342 | LOG(VB_RECORD, LOG_INFO, LOC + "StopEncoding"); |
1378 | 1343 | |
1379 | | bool stopped = 0 == ioctl(fd, VIDIOC_ENCODER_CMD, &command); |
| 1344 | bool stopped = 0 == ioctl(readfd, VIDIOC_ENCODER_CMD, &command); |
1380 | 1345 | if (stopped) |
1381 | 1346 | { |
1382 | 1347 | LOG(VB_RECORD, LOG_INFO, LOC + "Encoding stopped"); |
… |
… |
bool MpegRecorder::StopEncoding(int fd) |
1393 | 1358 | LOG(VB_GENERAL, LOG_WARNING, LOC + "StopEncoding failed" + ENO); |
1394 | 1359 | } |
1395 | 1360 | |
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; |
1397 | 1370 | } |
1398 | 1371 | |
1399 | 1372 | void MpegRecorder::SetStreamData(void) |
diff --git a/mythtv/libs/libmythtv/mpegrecorder.h b/mythtv/libs/libmythtv/mpegrecorder.h
index da1b7fc..d4828b4 100644
a
|
b
|
class MpegRecorder : public V4LRecorder, |
68 | 68 | uint GetFilteredAudioBitRate(uint audio_layer) const; |
69 | 69 | |
70 | 70 | void RestartEncoding(void); |
71 | | bool StartEncoding(int fd); |
72 | | bool StopEncoding(int fd); |
| 71 | bool StartEncoding(void); |
| 72 | void StopEncoding(void); |
73 | 73 | |
74 | 74 | void SetBitrate(int bitrate, int maxbitrate, const QString & reason); |
75 | 75 | void HandleResolutionChanges(void); |