Skip to content

Commit

Permalink
Fix the in-recording seektable for MPEG2-TS. Also, make the in-recording
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Beirdo committed Nov 25, 2010
1 parent bd87848 commit a7d03ad
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
30 changes: 18 additions & 12 deletions mythtv/libs/libmythtv/dtvrecorder.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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: */
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/dtvrecorder.h
Expand Up @@ -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);

Expand Down

0 comments on commit a7d03ad

Please sign in to comment.