From 828ab23f65866d59d5ef87146fd2ebf3314fb4ad Mon Sep 17 00:00:00 2001
From: Gavin Hurlbut <gjhurlbu@gmail.com>
Date: Fri, 12 Nov 2010 02:47:46 -0800
Subject: [PATCH] Tweaking in-recording seektable building
diff --git a/mythtv/libs/libmythtv/dtvrecorder.cpp b/mythtv/libs/libmythtv/dtvrecorder.cpp
index cd29039..f043b64 100644
|
a
|
b
|
|
| 11 | 11 | #include "mpegstreamdata.h" |
| 12 | 12 | #include "dtvrecorder.h" |
| 13 | 13 | #include "tv_rec.h" |
| | 14 | #include "mythverbose.h" |
| 14 | 15 | |
| 15 | 16 | extern "C" { |
| 16 | 17 | extern const uint8_t *ff_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state); |
| … |
… |
bool DTVRecorder::FindMPEG2Keyframes(const TSPacket* tspacket)
|
| 329 | 330 | if (hasKeyFrame) |
| 330 | 331 | { |
| 331 | 332 | _last_keyframe_seen = _frames_seen_count; |
| 332 | | HandleKeyframe(); |
| | 333 | HandleKeyframe(_frames_written_count, TSPacket::SIZE); |
| 333 | 334 | } |
| 334 | 335 | |
| 335 | 336 | if (hasFrame) |
| … |
… |
bool DTVRecorder::FindAudioKeyframes(const TSPacket*)
|
| 388 | 389 | if (1 == (_frames_seen_count & 0x7)) |
| 389 | 390 | { |
| 390 | 391 | _last_keyframe_seen = _frames_seen_count; |
| 391 | | HandleKeyframe(); |
| | 392 | HandleKeyframe(_frames_written_count); |
| 392 | 393 | hasKeyFrame = true; |
| 393 | 394 | } |
| 394 | 395 | |
| … |
… |
bool DTVRecorder::FindOtherKeyframes(const TSPacket *tspacket)
|
| 416 | 417 | _frames_written_count++; |
| 417 | 418 | _last_keyframe_seen = _frames_seen_count; |
| 418 | 419 | |
| 419 | | HandleKeyframe(); |
| | 420 | HandleKeyframe(_frames_written_count); |
| 420 | 421 | |
| 421 | 422 | _has_written_other_keyframe = true; |
| 422 | 423 | |
| … |
… |
void DTVRecorder::SetNextRecording(const ProgramInfo *progInf, RingBuffer *rb)
|
| 451 | 452 | * \brief This save the current frame to the position maps |
| 452 | 453 | * and handles ringbuffer switching. |
| 453 | 454 | */ |
| 454 | | void DTVRecorder::HandleKeyframe(uint64_t extra) |
| | 455 | void DTVRecorder::HandleKeyframe(uint64_t frameNum, int64_t extra) |
| 455 | 456 | { |
| 456 | 457 | if (!ringBuffer) |
| 457 | 458 | return; |
| 458 | 459 | |
| | 460 | #if 0 |
| 459 | 461 | unsigned long long frameNum = _frames_written_count; |
| | 462 | #endif |
| 460 | 463 | |
| 461 | 464 | _first_keyframe = (_first_keyframe < 0) ? frameNum : _first_keyframe; |
| 462 | 465 | |
| … |
… |
void DTVRecorder::HandleKeyframe(uint64_t extra)
|
| 466 | 469 | { |
| 467 | 470 | long long startpos = ringBuffer->GetWritePosition(); |
| 468 | 471 | // FIXME: handle keyframes with start code spanning over two ts packets |
| 469 | | startpos += _payload_buffer.size() + extra; |
| | 472 | startpos += _payload_buffer.size() - extra; |
| 470 | 473 | |
| 471 | 474 | // Don't put negative offsets into the database, they get munged into |
| 472 | 475 | // MAX_INT64 - offset, which is an exceedingly large number, and |
| … |
… |
void DTVRecorder::FindPSKeyFrames(const uint8_t *buffer, uint len)
|
| 773 | 776 | hasKeyFrame &= (_last_seq_seen + maxKFD) < _frames_seen_count; |
| 774 | 777 | } |
| 775 | 778 | |
| 776 | | if (hasKeyFrame) |
| 777 | | { |
| 778 | | _last_keyframe_seen = _frames_seen_count; |
| 779 | | HandleKeyframe(bufptr - bufstart); |
| 780 | | } |
| 781 | | |
| 782 | 779 | if (hasFrame) |
| 783 | 780 | { |
| 784 | 781 | _frames_seen_count++; |
| 785 | | if (!_wait_for_keyframe_option || _first_keyframe>=0) |
| | 782 | if (!_wait_for_keyframe_option || _first_keyframe >= 0) |
| 786 | 783 | _frames_written_count++; |
| 787 | 784 | } |
| 788 | 785 | |
| | 786 | if (hasKeyFrame) |
| | 787 | { |
| | 788 | _last_keyframe_seen = _frames_seen_count; |
| | 789 | HandleKeyframe(_frames_written_count, bufptr - bufstart); |
| | 790 | } |
| | 791 | |
| 789 | 792 | if ((aspectRatio > 0) && (aspectRatio != m_videoAspect)) |
| 790 | 793 | { |
| 791 | 794 | m_videoAspect = aspectRatio; |
| … |
… |
void DTVRecorder::FindPSKeyFrames(const uint8_t *buffer, uint len)
|
| 846 | 849 | uint64_t rem = (bufend - bufstart); |
| 847 | 850 | _payload_buffer.resize(idx + rem); |
| 848 | 851 | memcpy(&_payload_buffer[idx], bufstart, rem); |
| | 852 | #if 0 |
| | 853 | VERBOSE(VB_GENERAL, QString("idx: %1, rem: %2").arg(idx).arg(rem) ); |
| | 854 | #endif |
| 849 | 855 | } |
| 850 | 856 | |
| 851 | 857 | /* vim: set expandtab tabstop=4 shiftwidth=4: */ |
diff --git a/mythtv/libs/libmythtv/dtvrecorder.h b/mythtv/libs/libmythtv/dtvrecorder.h
index aa3b173..55da6ec 100644
|
a
|
b
|
class DTVRecorder: public RecorderBase
|
| 51 | 51 | void FinishRecording(void); |
| 52 | 52 | void ResetForNewFile(void); |
| 53 | 53 | |
| 54 | | void HandleKeyframe(uint64_t extra = 0); |
| | 54 | void HandleKeyframe(uint64_t frameNum, int64_t extra = 0); |
| 55 | 55 | |
| 56 | 56 | void BufferedWrite(const TSPacket &tspacket); |
| 57 | 57 | |