Ticket #1970: dvbrecorder_save_pidfilters.3.diff
File dvbrecorder_save_pidfilters.3.diff, 7.6 KB (added by , 18 years ago) |
---|
-
libs/libmythtv/dvbrecorder.cpp
old new const int DVBRecorder::POLL_WARNING_TIME 76 76 77 77 #define TS_TICKS_PER_SEC 90000 78 78 #define DUMMY_VIDEO_PID VIDEO_PID(0x20) 79 #define PMT_LOW_PRIORITY -7 79 80 80 81 #define LOC QString("DVBRec(%1): ").arg(_card_number_option) 81 82 #define LOC_WARN QString("DVBRec(%1) Warning: ").arg(_card_number_option) … … int DVBRecorder::OpenFilterFd(uint pid, 374 375 { 375 376 close(fd_tmp); 376 377 377 VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to set demux filter." + ENO); 378 VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to set demux filter. " 379 "Probably listening on more PMT PIDs than available." + ENO); 378 380 return -1; 379 381 } 380 382 381 383 return fd_tmp; 382 384 } 383 385 384 void DVBRecorder::OpenFilter(uint pid, int pes_type, uint stream_type) 386 /** \fn DVBRecorder::OpenFilter(uint, int, uint) 387 * \brief management of pid filter opening 388 * \returns false if a low priority was closed or no filter was opened 389 * true otherwise 390 */ 391 bool DVBRecorder::OpenFilter(uint pid, int pes_type, uint stream_type, 392 int priority) 385 393 { 386 394 PIDInfo *info = NULL; 387 395 int fd_tmp = -1; 396 bool avail = true; 388 397 389 398 QMutexLocker change_lock(&_pid_lock); 390 399 PIDInfoMap::iterator it = _pid_infos.find(pid); … … void DVBRecorder::OpenFilter(uint pid, i 400 409 if (fd_tmp < 0) 401 410 fd_tmp = OpenFilterFd(pid, pes_type, stream_type); 402 411 412 // try to close a low priority filter 413 if (fd_tmp < 0) 414 { 415 // no free filters available 416 avail = false; 417 PIDInfoMap::iterator lp_it = _pid_infos.begin(); 418 for (;lp_it != _pid_infos.end(); ++lp_it) 419 { 420 if (lp_it != it && (*lp_it)->priority < 0) 421 { 422 (*lp_it)->Close(); 423 break; 424 } 425 } 426 if (lp_it != _pid_infos.end()) 427 { 428 // PMT PIDs are the only low priority pids 429 uint lp_pid = lp_it.key(); 430 VERBOSE(VB_RECORD, LOC + QString("Closing low priority PID filter " 431 "on PID 0x%1.").arg(lp_pid, 0, 16)); 432 _pmt_monitoring_pids.push_back(lp_pid); 433 delete *lp_it; 434 _pid_infos.erase(lp_it); 435 fd_tmp = OpenFilterFd(pid, pes_type, stream_type); 436 } 437 else 438 VERBOSE(VB_RECORD, LOC + "No low priority PID filter available, " 439 "open will fail."); 440 } 441 403 442 if (fd_tmp < 0) 404 443 { 405 444 if (info) … … void DVBRecorder::OpenFilter(uint pid, i 407 446 delete *it; 408 447 _pid_infos.erase(it); 409 448 } 410 return ;449 return avail; 411 450 } 412 451 413 452 if (!info) … … void DVBRecorder::OpenFilter(uint pid, i 417 456 info->filter_fd = fd_tmp; 418 457 info->streamType = stream_type; 419 458 info->pesType = pes_type; 459 info->priority = priority; 420 460 421 461 // Add the new info to the map 422 462 _pid_infos[pid] = info; 463 464 return avail; 423 465 } 424 466 425 467 bool DVBRecorder::AdjustFilters(void) 426 468 { 469 _pmt_monitoring_pids.clear(); 427 470 StopDummyVideo(); // Stop the dummy video before acquiring the lock. 428 471 429 472 QMutexLocker change_lock(&_pid_lock); … … bool DVBRecorder::AdjustFilters(void) 437 480 add_stream_type.push_back(StreamID::PrivSec); 438 481 _stream_data->AddListeningPID(MPEG_PAT_PID); 439 482 440 for (uint i = 0; i < _input_pat->ProgramCount(); i++)441 {442 add_pid.push_back(_input_pat->ProgramPID(i));443 add_stream_type.push_back(StreamID::PrivSec);444 _stream_data->AddListeningPID(_input_pat->ProgramPID(i));445 }446 447 483 // Record the streams in the PMT... 448 484 bool need_pcr_pid = true; 449 485 for (uint i = 0; i < _input_pmt->StreamCount(); i++) … … bool DVBRecorder::AdjustFilters(void) 470 506 _stream_data->AddListeningPID(_eit_pids[i]); 471 507 } 472 508 509 // Adding PMT PIDs to monitoring queue and register them with StreamData 510 for (uint i = 0; i < _input_pat->ProgramCount(); i++) 511 { 512 uint pid = _input_pat->ProgramPID(i); 513 _stream_data->AddListeningPID(pid); 514 _pmt_monitoring_pids.push_back(pid); 515 } 516 473 517 // Delete filters for pids we no longer wish to monitor 474 518 PIDInfoMap::iterator it = _pid_infos.begin(); 475 519 PIDInfoMap::iterator next = it; … … bool DVBRecorder::AdjustEITPIDs(void) 536 580 return true; 537 581 } 538 582 583 void DVBRecorder::AdjustMonitoringPMTPIDs() 584 { 585 QMutexLocker change_lock(&_pid_lock); 586 bool filters_available = true; 587 588 while (!_pmt_monitoring_pids.empty() && filters_available) 589 { 590 uint pid = _pmt_monitoring_pids.front(); 591 filters_available = OpenFilter(pid, DMX_PES_OTHER, StreamID::PrivSec, 592 PMT_LOW_PRIORITY); 593 _pmt_monitoring_pids.pop_front(); 594 } 595 VERBOSE(VB_RECORD, LOC + QString("Currently not listening on %1 PMT PIDs, " 596 "%3 PID filters open") 597 .arg(_pmt_monitoring_pids.size()-1).arg(_pid_infos.size())); 598 } 599 539 600 void DVBRecorder::StartRecording(void) 540 601 { 541 602 if (!Open()) … … void DVBRecorder::StartRecording(void) 565 626 } 566 627 _drb->Start(); 567 628 629 int count = 0; 568 630 while (_request_recording && !_error) 569 631 { 570 632 if (PauseAndWait()) … … void DVBRecorder::StartRecording(void) 602 664 } 603 665 } 604 666 667 if (count-- <= 0) 668 { 669 AdjustMonitoringPMTPIDs(); 670 count = 250; 671 } 672 605 673 ssize_t len = _drb->Read(_buffer, _buffer_size); 606 674 if (len > 0) 607 675 ProcessDataTS(_buffer, len); -
libs/libmythtv/dvbrecorder.h
old new 10 10 11 11 // C++ includes 12 12 #include <vector> 13 #include <deque> 13 14 using namespace std; 14 15 15 16 // Qt includes … … class PIDInfo 31 32 PIDInfo() : 32 33 filter_fd(-1), continuityCount(0xFF), 33 34 streamType(0), pesType(-1), 34 isEncrypted(false), payloadStartSeen(false) {;}35 isEncrypted(false), payloadStartSeen(false), priority(0) {;} 35 36 36 37 int filter_fd; ///< Input filter file descriptor 37 38 uint continuityCount; ///< last Continuity Count (sentinel 0xFF) … … class PIDInfo 39 40 int pesType; ///< PESStreamID 40 41 bool isEncrypted; ///< true if PID is marked as encrypted 41 42 bool payloadStartSeen; ///< true if payload start packet seen on PID 43 int priority; ///< filters with priority < 0 can be closed 44 // if a new filter can't be opened 42 45 43 46 inline void Close(void); 44 47 inline bool CheckCC(uint cc); … … class DVBRecorder : public DTVRecorder, 91 94 92 95 bool AdjustFilters(void); 93 96 bool AdjustEITPIDs(void); 97 void AdjustMonitoringPMTPIDs(void); 94 98 void CloseFilters(void); 95 void OpenFilter(uint pid, int pes_type, uint mpeg_stream_type); 99 bool OpenFilter(uint pid, int pes_type, uint mpeg_stream_type, 100 int priority=0); 96 101 int OpenFilterFd(uint pid, int pes_type, uint stream_type); 97 102 98 103 void SetOutputPAT(ProgramAssociationTable*); … … class DVBRecorder : public DTVRecorder, 132 137 PIDInfoMap _pid_infos; 133 138 uint_vec_t _eit_pids; 134 139 140 deque<uint> _pmt_monitoring_pids; 141 135 142 /// PAT on input side 136 143 ProgramAssociationTable *_input_pat; 137 144 /// PMT on input side