summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGavin Hurlbut <ghurlbut@mythtv.org>2010-11-25 00:25:38 (GMT)
committer Gavin Hurlbut <ghurlbut@mythtv.org>2010-11-25 00:25:38 (GMT)
commita7d03adff93fc1d7880e12fe9c76713426044920 (patch)
tree3c7e83230d962b6e5f21c47696fd4cc43919998e
parentbd8784829b440cc2e758226c5db2c25233b21763 (diff)
Fix the in-recording seektable for MPEG2-TS. Also, make the in-recording
seektable for MPEG2-PS better, although not yet quite correct. In particular, the file offsets are consistently earlier than they should be, but at least this makes the previews functional. The original issue seemed to be that we were recording the offest AFTER the packet in question, rather than the offset at the beginning of the packet. In MPEG2-TS, due to the packetizing of the stream, it's easy to backtrack to the beginning of the previous packet, but in MPEG2-PS, the frames are all of differing sizes, and I haven't quite got it tweaked right yet. Refs #9256 git-svn-id: http://svn.mythtv.org/svn/trunk@27338 7dbf422c-18fa-0310-86e9-fd20926502f2
-rw-r--r--mythtv/libs/libmythtv/dtvrecorder.cpp30
-rw-r--r--mythtv/libs/libmythtv/dtvrecorder.h2
2 files changed, 19 insertions, 13 deletions
diff --git a/mythtv/libs/libmythtv/dtvrecorder.cpp b/mythtv/libs/libmythtv/dtvrecorder.cpp
index cd29039..f043b64 100644
--- a/mythtv/libs/libmythtv/dtvrecorder.cpp
+++ b/mythtv/libs/libmythtv/dtvrecorder.cpp
@@ -11,6 +11,7 @@
#include "mpegstreamdata.h"
#include "dtvrecorder.h"
#include "tv_rec.h"
+#include "mythverbose.h"
extern "C" {
extern const uint8_t *ff_find_start_code(const uint8_t *p, const uint8_t *end, uint32_t *state);
@@ -329,7 +330,7 @@ bool DTVRecorder::FindMPEG2Keyframes(const TSPacket* tspacket)
if (hasKeyFrame)
{
_last_keyframe_seen = _frames_seen_count;
- HandleKeyframe();
+ HandleKeyframe(_frames_written_count, TSPacket::SIZE);
}
if (hasFrame)
@@ -388,7 +389,7 @@ bool DTVRecorder::FindAudioKeyframes(const TSPacket*)
if (1 == (_frames_seen_count & 0x7))
{
_last_keyframe_seen = _frames_seen_count;
- HandleKeyframe();
+ HandleKeyframe(_frames_written_count);
hasKeyFrame = true;
}
@@ -416,7 +417,7 @@ bool DTVRecorder::FindOtherKeyframes(const TSPacket *tspacket)
_frames_written_count++;
_last_keyframe_seen = _frames_seen_count;
- HandleKeyframe();
+ HandleKeyframe(_frames_written_count);
_has_written_other_keyframe = true;
@@ -451,12 +452,14 @@ void DTVRecorder::SetNextRecording(const ProgramInfo *progInf, RingBuffer *rb)
* \brief This save the current frame to the position maps
* and handles ringbuffer switching.
*/
-void DTVRecorder::HandleKeyframe(uint64_t extra)
+void DTVRecorder::HandleKeyframe(uint64_t frameNum, int64_t extra)
{
if (!ringBuffer)
return;
+#if 0
unsigned long long frameNum = _frames_written_count;
+#endif
_first_keyframe = (_first_keyframe < 0) ? frameNum : _first_keyframe;
@@ -466,7 +469,7 @@ void DTVRecorder::HandleKeyframe(uint64_t extra)
{
long long startpos = ringBuffer->GetWritePosition();
// FIXME: handle keyframes with start code spanning over two ts packets
- startpos += _payload_buffer.size() + extra;
+ startpos += _payload_buffer.size() - extra;
// Don't put negative offsets into the database, they get munged into
// MAX_INT64 - offset, which is an exceedingly large number, and
@@ -773,19 +776,19 @@ void DTVRecorder::FindPSKeyFrames(const uint8_t *buffer, uint len)
hasKeyFrame &= (_last_seq_seen + maxKFD) < _frames_seen_count;
}
- if (hasKeyFrame)
- {
- _last_keyframe_seen = _frames_seen_count;
- HandleKeyframe(bufptr - bufstart);
- }
-
if (hasFrame)
{
_frames_seen_count++;
- if (!_wait_for_keyframe_option || _first_keyframe>=0)
+ if (!_wait_for_keyframe_option || _first_keyframe >= 0)
_frames_written_count++;
}
+ if (hasKeyFrame)
+ {
+ _last_keyframe_seen = _frames_seen_count;
+ HandleKeyframe(_frames_written_count, bufptr - bufstart);
+ }
+
if ((aspectRatio > 0) && (aspectRatio != m_videoAspect))
{
m_videoAspect = aspectRatio;
@@ -846,6 +849,9 @@ void DTVRecorder::FindPSKeyFrames(const uint8_t *buffer, uint len)
uint64_t rem = (bufend - bufstart);
_payload_buffer.resize(idx + rem);
memcpy(&_payload_buffer[idx], bufstart, rem);
+#if 0
+VERBOSE(VB_GENERAL, QString("idx: %1, rem: %2").arg(idx).arg(rem) );
+#endif
}
/* 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/mythtv/libs/libmythtv/dtvrecorder.h
+++ b/mythtv/libs/libmythtv/dtvrecorder.h
@@ -51,7 +51,7 @@ class DTVRecorder: public RecorderBase
void FinishRecording(void);
void ResetForNewFile(void);
- void HandleKeyframe(uint64_t extra = 0);
+ void HandleKeyframe(uint64_t frameNum, int64_t extra = 0);
void BufferedWrite(const TSPacket &tspacket);