[video_core, host1x] Revert problematic ffmpeg commits #29

Closed
crueter wants to merge 1 commit from fix/revert-ffmpeg into master
2 changed files with 33 additions and 27 deletions

View file

@ -214,42 +214,48 @@ bool DecoderContext::OpenContext(const Decoder& decoder) {
} }
bool DecoderContext::SendPacket(const Packet& packet) { bool DecoderContext::SendPacket(const Packet& packet) {
m_temp_frame = std::make_shared<Frame>(); m_temp_frame = std::make_shared<Frame>();
m_got_frame = 0;
if (const int ret = avcodec_send_packet(m_codec_context, packet.GetPacket()); ret < 0) {
if (const int ret = avcodec_send_packet(m_codec_context, packet.GetPacket()); ret < 0 && ret != AVERROR_EOF) {
LOG_ERROR(HW_GPU, "avcodec_send_packet error: {}", AVError(ret)); LOG_ERROR(HW_GPU, "avcodec_send_packet error: {}", AVError(ret));
return false; return false;
} }
return true; return true;
} }
std::shared_ptr<Frame> DecoderContext::ReceiveFrame() { std::shared_ptr<Frame> DecoderContext::ReceiveFrame() {
auto ReceiveImpl = [&](AVFrame* frame) -> bool { auto receive = [&](AVFrame* dst) -> bool {
if (const int ret = avcodec_receive_frame(m_codec_context, frame); ret < 0) { if (const int ret = avcodec_receive_frame(m_codec_context, dst); ret < 0) {
LOG_ERROR(HW_GPU, "avcodec_receive_frame error: {}", AVError(ret)); LOG_ERROR(HW_GPU, "avcodec_receive_frame error: {}", AVError(ret));
return false; return false;
}
return true;
};
if (m_codec_context->hw_device_ctx) {
// If we have a hardware context, make a separate frame here to receive the
// hardware result before sending it to the output.
Frame intermediate_frame;
if (!receive(intermediate_frame.GetFrame())) {
return {};
} }
return true;
};
std::shared_ptr<Frame> intermediate_frame = std::make_shared<Frame>();
if (!ReceiveImpl(intermediate_frame->GetFrame())) {
return {};
}
const auto desc = av_pix_fmt_desc_get(intermediate_frame->GetPixelFormat());
if (m_codec_context->hw_device_ctx && (desc && desc->flags & AV_PIX_FMT_FLAG_HWACCEL)) {
m_temp_frame->SetFormat(PreferredGpuFormat); m_temp_frame->SetFormat(PreferredGpuFormat);
if (int ret = av_hwframe_transfer_data(m_temp_frame->GetFrame(), intermediate_frame->GetFrame(), 0); ret < 0) { if (int ret = av_hwframe_transfer_data(m_temp_frame->GetFrame(), intermediate_frame.GetFrame(), 0); ret < 0) {
LOG_ERROR(HW_GPU, "av_hwframe_transfer_data error: {}", AVError(ret)); LOG_ERROR(HW_GPU, "av_hwframe_transfer_data error: {}", AVError(ret));
return {}; return {};
} }
} else { } else {
m_temp_frame = std::move(intermediate_frame); // Otherwise, decode the frame as normal.
} if (!receive(m_temp_frame->GetFrame())) {
return {};
}
}
return std::move(m_temp_frame); return std::move(m_temp_frame);
} }
void DecodeApi::Reset() { void DecodeApi::Reset() {

View file

@ -24,7 +24,6 @@ extern "C" {
#include <libavcodec/avcodec.h> #include <libavcodec/avcodec.h>
#include <libavutil/opt.h> #include <libavutil/opt.h>
#include <libavutil/pixdesc.h>
#include <libavcodec/codec_internal.h> #include <libavcodec/codec_internal.h>
#if defined(__GNUC__) || defined(__clang__) #if defined(__GNUC__) || defined(__clang__)
@ -194,6 +193,7 @@ public:
private: private:
const Decoder& m_decoder; const Decoder& m_decoder;
AVCodecContext* m_codec_context{}; AVCodecContext* m_codec_context{};
s32 m_got_frame{};
std::shared_ptr<Frame> m_temp_frame{}; std::shared_ptr<Frame> m_temp_frame{};
bool m_decode_order{}; bool m_decode_order{};
}; };