Skip to content

Commit

Permalink
MythFrame: Move more functionality into MythVideoFrame
Browse files Browse the repository at this point in the history
Refs #261
  • Loading branch information
mark-kendall committed Oct 13, 2020
1 parent ff64a44 commit 5ca0865
Show file tree
Hide file tree
Showing 30 changed files with 206 additions and 206 deletions.
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/DetectLetterbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ void DetectLetterbox::Detect(VideoFrame *Frame)
averageY = 0;

// Note - for 10/12 bit etc we only sample the most significant byte
bool triplanar = format_is_420(m_frameType);
int depth = ColorDepth(m_frameType);
bool triplanar = MythVideoFrame::FormatIs420(m_frameType);
int depth = MythVideoFrame::ColorDepth(m_frameType);
int leftshift = depth > 8 ? 1 : 0;
int rightshift = depth > 8 ? 0 : 1;

Expand Down
4 changes: 2 additions & 2 deletions mythtv/libs/libmythtv/decoders/avformatdecoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2741,7 +2741,7 @@ int get_avf_buffer(struct AVCodecContext *c, AVFrame *pic, int flags)
{
auto *decoder = static_cast<AvFormatDecoder*>(c->opaque);
VideoFrameType type = PixelFormatToFrameType(c->pix_fmt);
const VideoFrameTypeVec* supported = decoder->GetPlayer()->DirectRenderFormats();
const VideoFrameTypes* supported = decoder->GetPlayer()->DirectRenderFormats();
auto foundIt = std::find(supported->cbegin(), supported->cend(), type);
if (foundIt == supported->end())
{
Expand Down Expand Up @@ -5137,7 +5137,7 @@ bool AvFormatDecoder::GenerateDummyVideoFrames(void)
if (!frame)
return false;

clear_vf(frame);
MythVideoFrame::Clear(frame);
frame->dummy = true;
m_parent->ReleaseNextVideoFrame(frame, m_lastVPts);
m_parent->DeLimboFrame(frame);
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/decoders/decoderbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1443,7 +1443,7 @@ AVPixelFormat DecoderBase::GetBestVideoFormat(AVPixelFormat* Formats)
{
if (m_parent)
{
const VideoFrameTypeVec* mythfmts = m_parent->DirectRenderFormats();
const VideoFrameTypes* mythfmts = m_parent->DirectRenderFormats();
for (AVPixelFormat *format = Formats; *format != AV_PIX_FMT_NONE; format++)
{
for (auto fmt : *mythfmts)
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/decoders/mythmmalcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ bool MythMMALContext::GetBuffer(AVCodecContext *Context, VideoFrame *Frame, AVFr
// Ensure we can render this format
AvFormatDecoder *decoder = static_cast<AvFormatDecoder*>(Context->opaque);
VideoFrameType type = PixelFormatToFrameType(static_cast<AVPixelFormat>(AvFrame->format));
const VideoFrameTypeVec* supported = decoder->GetPlayer()->DirectRenderFormats();
const VideoFrameTypes* supported = decoder->GetPlayer()->DirectRenderFormats();
auto foundIt = std::find(supported->cbegin(), supported->cend(), type);
// No fallback currently (unlikely)
if (foundIt == supported->end())
Expand Down
8 changes: 4 additions & 4 deletions mythtv/libs/libmythtv/decoders/mythnvdeccontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,18 @@ MythCodecID MythNVDECContext::GetSupportedCodec(AVCodecContext **Context,

cudaVideoChromaFormat cudaformat = cudaVideoChromaFormat_Monochrome;
VideoFrameType type = PixelFormatToFrameType((*Context)->pix_fmt);
uint depth = static_cast<uint>(ColorDepth(type) - 8);
uint depth = static_cast<uint>(MythVideoFrame::ColorDepth(type) - 8);
QString desc = QString("'%1 %2 %3 Depth:%4 %5x%6'")
.arg(codecstr).arg(profile).arg(pixfmt).arg(depth + 8)
.arg((*Context)->width).arg((*Context)->height);

// N.B. on stream changes format is set to CUDA/NVDEC. This may break if the new
// stream has an unsupported chroma but the decoder should fail gracefully - just later.
if ((FMT_NVDEC == type) || (format_is_420(type)))
if ((FMT_NVDEC == type) || (MythVideoFrame::FormatIs420(type)))
cudaformat = cudaVideoChromaFormat_420;
else if (format_is_422(type))
else if (MythVideoFrame::FormatIs422(type))
cudaformat = cudaVideoChromaFormat_422;
else if (format_is_444(type))
else if (MythVideoFrame::FormatIs444(type))
cudaformat = cudaVideoChromaFormat_444;

if ((cudacodec == cudaVideoCodec_NumCodecs) || (cudaformat == cudaVideoChromaFormat_Monochrome))
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/decoders/mythv4l2m2mcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ bool MythV4L2M2MContext::GetBuffer(AVCodecContext *Context, VideoFrame *Frame, A
// Ensure we can render this format
auto *decoder = static_cast<AvFormatDecoder*>(Context->opaque);
VideoFrameType type = PixelFormatToFrameType(static_cast<AVPixelFormat>(AvFrame->format));
const VideoFrameTypeVec* supported = decoder->GetPlayer()->DirectRenderFormats();
const VideoFrameTypes* supported = decoder->GetPlayer()->DirectRenderFormats();
auto foundIt = std::find(supported->cbegin(), supported->cend(), type);
// No fallback currently (unlikely)
if (foundIt == supported->end())
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythtv/decoders/mythvtbcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ void MythVTBContext::InitFramesContext(AVCodecContext *Context)
return;

AVPixelFormat format = AV_PIX_FMT_NV12;
if (ColorDepth(PixelFormatToFrameType(Context->sw_pix_fmt)) > 8)
if (MythVideoFrame::ColorDepth(PixelFormatToFrameType(Context->sw_pix_fmt)) > 8)
format = AV_PIX_FMT_P010;

if (m_framesContext)
Expand Down
6 changes: 3 additions & 3 deletions mythtv/libs/libmythtv/mythdeinterlacer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void MythDeinterlacer::Filter(VideoFrame *Frame, FrameScanType Scan,
return;

// Sanity check frame format
if (!format_is_yuv(Frame->codec))
if (!MythVideoFrame::YUVFormat(Frame->codec))
{
Cleanup();
return;
Expand Down Expand Up @@ -113,7 +113,7 @@ void MythDeinterlacer::Filter(VideoFrame *Frame, FrameScanType Scan,

// libavfilter will not deinterlace NV12 frames. Allow shaders in this case.
// libswscale (for bob/onefield) is fine, as is our linearblend.
if ((deinterlacer == DEINT_HIGH) && format_is_nv12(Frame->codec))
if ((deinterlacer == DEINT_HIGH) && MythVideoFrame::FormatIsNV12(Frame->codec))
{
Cleanup();
Frame->deinterlace_single = Frame->deinterlace_single | DEINT_SHADER;
Expand Down Expand Up @@ -657,7 +657,7 @@ void MythDeinterlacer::Blend(VideoFrame *Frame, FrameScanType Scan)
src = m_bobFrame;
}

bool hidepth = ColorDepth(src->codec) > 8;
bool hidepth = MythVideoFrame::ColorDepth(src->codec) > 8;
bool top = second ? !m_topFirst : m_topFirst;
uint count = MythVideoFrame::GetNumPlanes(src->codec);
for (uint plane = 0; plane < count; plane++)
Expand Down
85 changes: 57 additions & 28 deletions mythtv/libs/libmythtv/mythframe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,6 @@
#include "mythcorecontext.h"
#include "mythlogging.h"

/// \brief Return the color depth for the given MythTV frame format
int ColorDepth(int Format)
{
switch (Format)
{
case FMT_YUV420P9:
case FMT_YUV422P9:
case FMT_YUV444P9: return 9;
case FMT_P010:
case FMT_YUV420P10:
case FMT_YUV422P10:
case FMT_YUV444P10: return 10;
case FMT_YUV420P12:
case FMT_YUV422P12:
case FMT_YUV444P12: return 12;
case FMT_YUV420P14:
case FMT_YUV422P14:
case FMT_YUV444P14: return 14;
case FMT_P016:
case FMT_YUV420P16:
case FMT_YUV422P16:
case FMT_YUV444P16: return 16;
default: break;
}
return 8;
}

MythDeintType GetSingleRateOption(const VideoFrame* Frame, MythDeintType Type,
MythDeintType Override)
{
Expand Down Expand Up @@ -105,6 +78,62 @@ void MythVideoFrame::CopyPlane(uint8_t *To, int ToPitch, const uint8_t *From, in
}
}

void MythVideoFrame::Clear(VideoFrame *Frame)
{
if (!Frame || !Frame->buf)
return;

// luma (or RGBA)
int uv_height = GetHeightForPlane(Frame->codec, Frame->height, 1);
int uv = (1 << (ColorDepth(Frame->codec) - 1)) - 1;
if (FMT_YV12 == Frame->codec || FMT_YUV422P == Frame->codec || FMT_YUV444P == Frame->codec)
{
memset(Frame->buf + Frame->offsets[0], 0, static_cast<size_t>(Frame->pitches[0] * Frame->height));
memset(Frame->buf + Frame->offsets[1], uv & 0xff, static_cast<size_t>(Frame->pitches[1] * uv_height));
memset(Frame->buf + Frame->offsets[2], uv & 0xff, static_cast<size_t>(Frame->pitches[2] * uv_height));
}
else if ((FormatIs420(Frame->codec) || FormatIs422(Frame->codec) || FormatIs444(Frame->codec)) &&
(Frame->pitches[1] == Frame->pitches[2]))
{
memset(Frame->buf + Frame->offsets[0], 0, static_cast<size_t>(Frame->pitches[0] * Frame->height));
unsigned char uv1 = (uv & 0xff00) >> 8;
unsigned char uv2 = (uv & 0x00ff);
unsigned char* buf1 = Frame->buf + Frame->offsets[1];
unsigned char* buf2 = Frame->buf + Frame->offsets[2];
for (int row = 0; row < uv_height; ++row)
{
for (int col = 0; col < Frame->pitches[1]; col += 2)
{
buf1[col] = buf2[col] = uv1;
buf1[col + 1] = buf2[col + 1] = uv2;
}
buf1 += Frame->pitches[1];
buf2 += Frame->pitches[2];
}
}
else if (FMT_NV12 == Frame->codec)
{
memset(Frame->buf + Frame->offsets[0], 0, static_cast<size_t>(Frame->pitches[0] * Frame->height));
memset(Frame->buf + Frame->offsets[1], uv & 0xff, static_cast<size_t>(Frame->pitches[1] * uv_height));
}
else if (FormatIsNV12(Frame->codec))
{
memset(Frame->buf + Frame->offsets[0], 0, static_cast<size_t>(Frame->pitches[0] * Frame->height));
unsigned char uv1 = (uv & 0xff00) >> 8;
unsigned char uv2 = (uv & 0x00ff);
unsigned char* buf = Frame->buf + Frame->offsets[1];
for (int row = 0; row < uv_height; ++row)
{
for (int col = 0; col < Frame->pitches[1]; col += 4)
{
buf[col] = buf[col + 2] = uv1;
buf[col + 1] = buf[col + 3] = uv2;
}
buf += Frame->pitches[1];
}
}
}

bool MythVideoFrame::CopyFrame(VideoFrame *To, VideoFrame *From)
{
// Sanity checks
Expand All @@ -117,7 +146,7 @@ bool MythVideoFrame::CopyFrame(VideoFrame *To, VideoFrame *From)
return false;
}

if (From->codec == FMT_NONE || format_is_hw(From->codec))
if (From->codec == FMT_NONE || HardwareFormat(From->codec))
{
LOG(VB_GENERAL, LOG_ERR, "Invalid frame format");
return false;
Expand Down
Loading

0 comments on commit 5ca0865

Please sign in to comment.