Skip to content

Commit

Permalink
MythVideoFrame: Simplify software buffer re-allocation
Browse files Browse the repository at this point in the history
Refs #261
  • Loading branch information
mark-kendall committed Oct 13, 2020
1 parent bf6a361 commit 85b4a70
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 21 deletions.
6 changes: 4 additions & 2 deletions mythtv/libs/libmythtv/mythframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,10 @@ void MythVideoFrame::Init(VideoFrameType Type, int Width, int Height)
uint8_t* newbuffer = nullptr;
if (!((Type == FMT_NONE) || HardwareFormat(Type)))
{
newsize = GetBufferSize(Type, Width, Height);
newbuffer = GetAlignedBuffer(newsize);
newsize = GetBufferSize(Type, Width, Height);
bool reallocate = !((Width == width) && (Height == height) && (newsize == size) && (Type == codec));
newbuffer = reallocate ? GetAlignedBuffer(newsize) : buf;
newsize = reallocate ? newsize : size;
}
Init(Type, newbuffer, newsize, Width, Height);
}
Expand Down
25 changes: 6 additions & 19 deletions mythtv/libs/libmythtv/videobuffers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1030,36 +1030,23 @@ bool VideoBuffers::ReinitBuffer(MythVideoFrame *Frame, VideoFrameType Type, Myth
{
if (!Frame)
return false;

if (MythVideoFrame::HardwareFormat(Type) || MythVideoFrame::HardwareFormat(Frame->codec))
{
LOG(VB_GENERAL, LOG_ERR, "Cannot re-initialise a hardware buffer");
return false;
}

// Find the frame
VideoFrameType old = Frame->codec;
size_t size = MythVideoFrame::GetBufferSize(Type, Width, Height);
uint8_t* oldbuffer = Frame->buf;
uint8_t* newbuffer = nullptr;
if ((Frame->size != size) || !oldbuffer)
{
// Initialise new
newbuffer = MythVideoFrame::GetAlignedBuffer(size);
if (!newbuffer)
{
LOG(VB_GENERAL, LOG_ERR, "Failed to reallocate frame buffer");
return false;
}
}

LOG(VB_PLAYBACK, LOG_INFO, QString("Reallocated frame %1 %2x%3->%4 %5x%6 (New buffer: %7)")
LOG(VB_PLAYBACK, LOG_INFO, QString("Reallocating frame %1 %2x%3->%4 %5x%6")
.arg(MythVideoFrame::FormatDescription(old)).arg(Frame->width).arg(Frame->height)
.arg(MythVideoFrame::FormatDescription(Type)).arg(Width).arg(Height)
.arg(newbuffer != nullptr));
.arg(MythVideoFrame::FormatDescription(Type)).arg(Width).arg(Height));

MythDeintType singler = Frame->deinterlace_single;
MythDeintType doubler = Frame->deinterlace_double;
Frame->Init(Type, newbuffer ? newbuffer : oldbuffer, size, Width, Height);
Frame->Init(Type, Width, Height);
Frame->ClearBufferToBlank();

// retain deinterlacer settings and update restrictions based on new frame type
SetDeinterlacingFlags(*Frame, singler, doubler, CodecID);
return true;
Expand Down

0 comments on commit 85b4a70

Please sign in to comment.