diff --git a/mythtv/libs/libmythtv/recorders/dtvrecorder.cpp b/mythtv/libs/libmythtv/recorders/dtvrecorder.cpp
index 0c30b10..0b438cd 100644
|
a
|
b
|
void DTVRecorder::InitStreamData(void)
|
| 277 | 277 | void DTVRecorder::BufferedWrite(const TSPacket &tspacket) |
| 278 | 278 | { |
| 279 | 279 | // delay until first GOP to avoid decoder crash on res change |
| 280 | | if (_wait_for_keyframe_option && _first_keyframe<0) |
| | 280 | if (!_buffer_packets && _wait_for_keyframe_option && _first_keyframe<0) |
| 281 | 281 | return; |
| 282 | 282 | |
| 283 | 283 | if (curRecording && timeOfFirstDataIsSet.testAndSetRelaxed(0,1)) |
| … |
… |
void DTVRecorder::HandleKeyframe(uint64_t frameNum, int64_t extra)
|
| 762 | 762 | */ |
| 763 | 763 | bool DTVRecorder::FindH264Keyframes(const TSPacket *tspacket) |
| 764 | 764 | { |
| | 765 | bool haveBufferedData = !_payload_buffer.empty(); |
| | 766 | |
| | 767 | if (!tspacket->HasPayload()) // no payload to scan |
| | 768 | return !haveBufferedData; |
| | 769 | |
| 765 | 770 | if (!ringBuffer) |
| 766 | 771 | { |
| 767 | 772 | LOG(VB_GENERAL, LOG_ERR, LOC + "FindH264Keyframes: No ringbuffer"); |
| 768 | | return false; |
| 769 | | } |
| 770 | | |
| 771 | | bool haveBufferedData = !_payload_buffer.empty(); |
| 772 | | if (!tspacket->HasPayload()) // no payload to scan |
| 773 | 773 | return !haveBufferedData; |
| | 774 | } |
| 774 | 775 | |
| 775 | 776 | const bool payloadStart = tspacket->PayloadStart(); |
| 776 | 777 | if (payloadStart) |
| … |
… |
bool DTVRecorder::FindH264Keyframes(const TSPacket *tspacket)
|
| 789 | 790 | bool hasKeyFrame = false; |
| 790 | 791 | |
| 791 | 792 | // scan for PES packets and H.264 NAL units |
| 792 | | uint i = tspacket->AFCOffset(); |
| 793 | | for (; i < TSPacket::kSize; i++) |
| | 793 | const uint pid = tspacket->PID(); |
| | 794 | uint i = tspacket->AFCOffset(); |
| | 795 | |
| | 796 | for (; i < TSPacket::kSize; ++i) |
| 794 | 797 | { |
| 795 | 798 | // special handling required when a new PES packet begins |
| 796 | 799 | if (payloadStart && !_pes_synced) |
| … |
… |
bool DTVRecorder::FindH264Keyframes(const TSPacket *tspacket)
|
| 879 | 882 | frameRate = m_h264_parser.frameRate(); |
| 880 | 883 | } |
| 881 | 884 | } |
| 882 | | } // for (; i < TSPacket::kSize; i++) |
| | 885 | } // for (; i < TSPacket::kSize; ++i) |
| | 886 | |
| | 887 | if (!(_pid_status[pid] & kPayloadStartSeen) && tspacket->HasPayload()) |
| | 888 | { |
| | 889 | if (tspacket->PayloadStart()) |
| | 890 | { |
| | 891 | LOG(VB_RECORD, LOG_INFO, LOC + |
| | 892 | QString("PID 0x%1 Found Payload Start").arg(pid,0,16)); |
| | 893 | |
| | 894 | _pid_status[pid] |= kPayloadStartSeen; |
| | 895 | } |
| | 896 | } |
| 883 | 897 | |
| 884 | 898 | if (hasKeyFrame) |
| 885 | 899 | { |
| … |
… |
bool DTVRecorder::FindH264Keyframes(const TSPacket *tspacket)
|
| 892 | 906 | _frames_seen_count++; |
| 893 | 907 | if (!_wait_for_keyframe_option || _first_keyframe >= 0) |
| 894 | 908 | UpdateFramesWritten(); |
| | 909 | else |
| | 910 | { |
| | 911 | /* Found a frame that is not a keyframe, and we want to |
| | 912 | * start on a keyframe. */ |
| | 913 | _pid_status[pid] &= 0; |
| | 914 | _payload_buffer.clear(); |
| | 915 | } |
| 895 | 916 | } |
| 896 | 917 | |
| 897 | 918 | if ((aspectRatio > 0) && (aspectRatio != m_videoAspect)) |
| … |
… |
bool DTVRecorder::ProcessVideoTSPacket(const TSPacket &tspacket)
|
| 1287 | 1308 | // Check for keyframes and count frames |
| 1288 | 1309 | if (streamType == StreamID::H264Video) |
| 1289 | 1310 | { |
| 1290 | | _buffer_packets = !FindH264Keyframes(&tspacket); |
| 1291 | | if (_wait_for_keyframe_option && !_seen_sps) |
| | 1311 | _buffer_packets = !FindH264Keyframes(&tspacket) && |
| | 1312 | (_pid_status[tspacket.PID()] & kPayloadStartSeen); |
| | 1313 | if (!_buffer_packets && _wait_for_keyframe_option && !_seen_sps) |
| 1292 | 1314 | return true; |
| 1293 | 1315 | } |
| 1294 | 1316 | else |
| … |
… |
bool DTVRecorder::ProcessAVTSPacket(const TSPacket &tspacket)
|
| 1329 | 1351 | } |
| 1330 | 1352 | |
| 1331 | 1353 | // Sync recording start to first keyframe |
| 1332 | | if (_wait_for_keyframe_option && _first_keyframe < 0) |
| | 1354 | if (!_buffer_packets && _wait_for_keyframe_option && _first_keyframe < 0) |
| 1333 | 1355 | return true; |
| 1334 | 1356 | |
| 1335 | 1357 | // Sync streams to the first Payload Unit Start Indicator |