Skip to content

Commit

Permalink
VAAPI: More fixes
Browse files Browse the repository at this point in the history
- GetBuffer3 is never actually called
- no need for custom VAAPI hardware frames context creation - the main
problem was the 'shaders' package and the custom context broke copyback
for some 8bit files. No idea why.
  • Loading branch information
mark-kendall committed Jun 16, 2019
1 parent 8a666c0 commit bd093ba
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 49 deletions.
15 changes: 5 additions & 10 deletions mythtv/libs/libmythtv/decoders/avformatdecoder.cpp
Expand Up @@ -1537,12 +1537,11 @@ void AvFormatDecoder::InitVideoCodec(AVStream *stream, AVCodecContext *enc,
{
enc->get_buffer2 = MythCodecContext::GetBuffer;
enc->get_format = MythVAAPIContext::GetFormat;
enc->slice_flags = SLICE_FLAG_CODED_ORDER | SLICE_FLAG_ALLOW_FIELD;
}
else if (codec_is_vaapi_dec(m_video_codec_id))
{
enc->get_buffer2 = MythCodecContext::GetBuffer3;
enc->get_format = MythVAAPIContext::GetFormat2;
enc->get_format = MythVAAPIContext::GetFormat2;
m_directrendering = false;
}
else
#endif
Expand All @@ -1565,15 +1564,11 @@ void AvFormatDecoder::InitVideoCodec(AVStream *stream, AVCodecContext *enc,
else
#endif
#ifdef USING_NVDEC
if (codec_is_nvdec_dec(m_video_codec_id))
{
enc->get_buffer2 = MythCodecContext::GetBuffer3;
enc->get_format = MythNVDECContext::GetFormat;
m_directrendering = false;
}
else if (codec_is_nvdec(m_video_codec_id))
if (codec_is_nvdec_dec(m_video_codec_id) || codec_is_nvdec(m_video_codec_id))
{
enc->get_format = MythNVDECContext::GetFormat;
if (codec_is_nvdec_dec(m_video_codec_id))
m_directrendering = false;
}
else
#endif
Expand Down
2 changes: 0 additions & 2 deletions mythtv/libs/libmythtv/decoders/avformatdecoder.h
Expand Up @@ -211,8 +211,6 @@ class AvFormatDecoder : public DecoderBase

friend int get_avf_buffer(struct AVCodecContext *c, AVFrame *pic,
int flags);
friend int MythCodecContext::GetBuffer3(struct AVCodecContext*, AVFrame*, int);

friend int open_avf(URLContext *h, const char *filename, int flags);
friend int read_avf(URLContext *h, uint8_t *buf, int buf_size);
friend int write_avf(URLContext *h, uint8_t *buf, int buf_size);
Expand Down
7 changes: 0 additions & 7 deletions mythtv/libs/libmythtv/decoders/mythcodeccontext.cpp
Expand Up @@ -168,13 +168,6 @@ int MythCodecContext::GetBuffer2(struct AVCodecContext *Context, AVFrame *Frame,
return 0;
}

/// \brief A generic hardware buffer initialisation method when the frame will be copied back to main memory.
int MythCodecContext::GetBuffer3(struct AVCodecContext *Context, AVFrame *Frame, int Flags)
{
static_cast<AvFormatDecoder*>(Context->opaque)->m_directrendering = false;
return avcodec_default_get_buffer2(Context, Frame, Flags);
}

void MythCodecContext::ReleaseBuffer(void *Opaque, uint8_t *Data)
{
AvFormatDecoder *decoder = static_cast<AvFormatDecoder*>(Opaque);
Expand Down
1 change: 0 additions & 1 deletion mythtv/libs/libmythtv/decoders/mythcodeccontext.h
Expand Up @@ -49,7 +49,6 @@ class MTV_PUBLIC MythCodecContext
static MythCodecContext* CreateContext (MythCodecID Codec);
static int GetBuffer (struct AVCodecContext *Context, AVFrame *Frame, int Flags);
static int GetBuffer2 (struct AVCodecContext *Context, AVFrame *Frame, int Flags);
static int GetBuffer3 (struct AVCodecContext *Context, AVFrame *Frame, int Flags);
static int InitialiseDecoder (AVCodecContext *Context, CreateHWDecoder Callback, const QString &Debug);
static int InitialiseDecoder2 (AVCodecContext *Context, CreateHWDecoder Callback, const QString &Debug);
static void ReleaseBuffer (void *Opaque, uint8_t *Data);
Expand Down
30 changes: 1 addition & 29 deletions mythtv/libs/libmythtv/mythvaapicontext.cpp
Expand Up @@ -401,8 +401,6 @@ int MythVAAPIContext::InitialiseContext(AVCodecContext *Context)

/*! \brief Create a VAAPI hardware context without OpenGL interop.
*
* \note We create our own frames context to ensure we can set the software format
* for 10bit video (to P010).
* \note Testing with Debian Buster, 10bit copyback requires the i965-va-driver-shaders package
* instead of i965-va-driver package. Expect a purple screen otherwise:)
*/
Expand All @@ -416,33 +414,7 @@ int MythVAAPIContext::InitialiseContext2(AVCodecContext *Context)
if (!device)
return -1;

Context->hw_frames_ctx = av_hwframe_ctx_alloc(device);
if (!Context->hw_frames_ctx)
{
LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to create VAAPI hardware frames context");
av_buffer_unref(&device);
return -1;
}

AVHWFramesContext* hw_frames_ctx = reinterpret_cast<AVHWFramesContext*>(Context->hw_frames_ctx->data);
AVVAAPIFramesContext* vaapi_frames_ctx = reinterpret_cast<AVVAAPIFramesContext*>(hw_frames_ctx->hwctx);
hw_frames_ctx->sw_format = FramesFormat(Context->sw_pix_fmt);
hw_frames_ctx->format = AV_PIX_FMT_VAAPI;
hw_frames_ctx->width = Context->width;
hw_frames_ctx->height = Context->height;
hw_frames_ctx->initial_pool_size = static_cast<int>(VideoBuffers::GetNumBuffers(FMT_VAAPI));
hw_frames_ctx->free = &MythCodecContext::FramesContextFinished;
if (av_hwframe_ctx_init(Context->hw_frames_ctx) < 0)
{
LOG(VB_GENERAL, LOG_ERR, LOC + "Failed to initialise VAAPI frames context");
av_buffer_unref(&device);
av_buffer_unref(&(Context->hw_frames_ctx));
return -1;
}

LOG(VB_PLAYBACK, LOG_INFO, LOC + QString("VAAPI FFmpeg buffer pool created with %1 surfaces")
.arg(vaapi_frames_ctx->nb_surfaces));
av_buffer_unref(&device);
Context->hw_device_ctx = device;
return 0;
}

Expand Down

0 comments on commit bd093ba

Please sign in to comment.