Ticket #4515: write_dsmcc_packets_where_no_AV_packets.diff
File write_dsmcc_packets_where_no_AV_packets.diff, 5.7 KB (added by , 16 years ago) |
---|
-
libs/libmythtv/dtvrecorder.cpp
38 38 // used for scanning pes headers for keyframes 39 39 _start_code(0xffffffff), _first_keyframe(-1), 40 40 _last_gop_seen(0), _last_seq_seen(0), 41 _last_keyframe_seen(0), 41 _last_keyframe_seen(0), _hasWrittenOtherKeyFrame(false), 42 42 // H.264 support 43 43 _pes_synced(false), 44 44 _seen_sps(false), … … 146 146 147 147 //_start_code 148 148 _first_keyframe =-1; 149 _hasWrittenOtherKeyFrame = false; 149 150 _last_keyframe_seen = 0; 150 151 _last_gop_seen = 0; 151 152 _last_seq_seen = 0; … … 344 345 return hasKeyFrame; 345 346 } 346 347 348 // Non-Audio/Video data. For streams which contain no audio/video, write just 1 key-frame 349 // at the start. 350 bool DTVRecorder::FindOtherKeyframes(const TSPacket *tspacket) 351 { 352 if (_hasWrittenOtherKeyFrame) 353 return true; 354 355 VERBOSE(VB_RECORD, LOC + "DSMCC - FindOtherKeyframes() - generating initial key-frame"); 356 _frames_seen_count++; 357 _frames_written_count++; 358 _last_keyframe_seen = _frames_seen_count; 359 HandleKeyframe(); 360 _hasWrittenOtherKeyFrame = true; 361 return true; 362 } 363 347 364 // documented in recorderbase.h 348 365 void DTVRecorder::SetNextRecording(const ProgramInfo *progInf, RingBuffer *rb) 349 366 { -
libs/libmythtv/dvbrecorder.cpp
477 477 478 478 bool DVBRecorder::ProcessVideoTSPacket(const TSPacket &tspacket) 479 479 { 480 VERBOSE(VB_RECORD, LOC + "DSMCC - ProcessVideoTSPacket()"); 480 481 uint streamType = _stream_id[tspacket.PID()]; 481 482 482 483 // Check for keyframes and count frames … … 491 492 _buffer_packets = !FindMPEG2Keyframes(&tspacket); 492 493 } 493 494 494 return Process TSPacket(tspacket);495 return ProcessAVTSPacket(tspacket); 495 496 } 496 497 497 498 bool DVBRecorder::ProcessAudioTSPacket(const TSPacket &tspacket) 498 499 { 500 VERBOSE(VB_RECORD, LOC + "DSMCC - ProcessAudioTSPacket()"); 499 501 _buffer_packets = !FindAudioKeyframes(&tspacket); 500 return Process TSPacket(tspacket);502 return ProcessAVTSPacket(tspacket); 501 503 } 502 504 503 bool DVBRecorder::ProcessTSPacket(const TSPacket &tspacket) 505 // Common code for processing either audio or video packets 506 bool DVBRecorder::ProcessAVTSPacket(const TSPacket &tspacket) 504 507 { 505 const uint pid = tspacket.PID();506 508 507 // Check continuity counter508 if ((pid != 0x1fff) && !CheckCC(pid, tspacket.ContinuityCounter()))509 {510 VERBOSE(VB_RECORD, LOC +511 QString("PID 0x%1 discontinuity detected").arg(pid,0,16));512 _continuity_error_count++;513 }514 515 509 // Sync recording start to first keyframe 510 // (Delay's until first GOP to avoid decoder crash on res change) 516 511 if (_wait_for_keyframe_option && _first_keyframe < 0) 512 { 513 VERBOSE(VB_RECORD, LOC + QString("DSMCC - ProcessAVTSPacket() - Ignoring packet")); 517 514 return true; 515 } 518 516 517 const uint pid = tspacket.PID(); 519 518 // Sync streams to the first Payload Unit Start Indicator 520 519 // _after_ first keyframe iff _wait_for_keyframe_option is true 521 520 if (!(_pid_status[pid] & kPayloadStartSeen) && tspacket.HasPayload()) 522 521 { 523 522 if (!tspacket.PayloadStart()) 523 { 524 VERBOSE(VB_RECORD, LOC + "DSMCC - ProcessAVTSPacket() - Not PayloadStart - dropping packet"); 524 525 return true; // not payload start - drop packet 526 } 525 527 526 528 VERBOSE(VB_RECORD, 527 529 QString("PID 0x%1 Found Payload Start").arg(pid,0,16)); … … 529 531 _pid_status[pid] |= kPayloadStartSeen; 530 532 } 531 533 534 return ProcessTSPacketCommon(tspacket); 535 } 536 537 bool DVBRecorder::ProcessTSPacket(const TSPacket &tspacket) 538 { 539 VERBOSE(VB_RECORD, LOC + "DSMCC - ProcessTSPacket()"); 540 _buffer_packets = !FindOtherKeyframes(&tspacket); 541 return ProcessTSPacketCommon(tspacket); 542 } 543 544 bool DVBRecorder::ProcessTSPacketCommon(const TSPacket &tspacket) 545 { 546 // Care must be taken to make sure that the packet actually gets written 547 // as the decision to actually write it has already been made 548 const uint pid = tspacket.PID(); 549 VERBOSE(VB_RECORD, LOC + QString("DSMCC - ProcessTSPacketCommon() Started (PID: 0x%1)").arg(pid,0,16)); 550 551 // Check continuity counter 552 if ((pid != 0x1fff) && !CheckCC(pid, tspacket.ContinuityCounter())) 553 { 554 VERBOSE(VB_RECORD, LOC + 555 QString("PID 0x%1 discontinuity detected").arg(pid,0,16)); 556 _continuity_error_count++; 557 } 558 532 559 BufferedWrite(tspacket); 533 560 534 561 return true; 535 562 } 563 564 void DVBRecorder::BufferedWrite(const TSPacket &tspacket) 565 { 566 VERBOSE(VB_RECORD, LOC + QString("DSMCC - BufferedWrite() - buffer: %1").arg(_buffer_packets)); 567 // Care must be taken to make sure that the packet actually gets written 568 // as the decision to actually write it has already been made 569 570 // Do we have to buffer the packet for exact keyframe detection? 571 if (_buffer_packets) 572 { 573 int idx = _payload_buffer.size(); 574 _payload_buffer.resize(idx + TSPacket::SIZE); 575 memcpy(&_payload_buffer[idx], tspacket.data(), TSPacket::SIZE); 576 return; 577 } 578 579 // We are free to write the packet, but if we have buffered packet[s] 580 // we have to write them first... 581 if (!_payload_buffer.empty()) 582 { 583 if (ringBuffer) 584 ringBuffer->Write(&_payload_buffer[0], _payload_buffer.size()); 585 _payload_buffer.clear(); 586 } 587 588 if (ringBuffer) 589 ringBuffer->Write(tspacket.data(), TSPacket::SIZE); 590 } 591