Unverified Commit 7d328c5b authored by Vasilis Vryniotis's avatar Vasilis Vryniotis Committed by GitHub
Browse files

[FBcode->GH] Handle images with AV_PIX_FMT_PAL8 pixel format in decoder callback (#6359)



Summary: provider callback uses video sampler to copy/scale input frames using sws_scale function, added option to use av_image_copy to copy image planes in case if sws_getContext fails (required to support AV_PIX_FMT_PAL8 pixel format)

Reviewed By: ovoietsa

Differential Revision: D36466749

fbshipit-source-id: 1674f98a362db835d147800c24bdda6f82d2f8ff
Co-authored-by: default avatarSergiy Bilobrov <sergiy@fb.com>
parent a5f0f798
...@@ -65,12 +65,29 @@ int transformImage( ...@@ -65,12 +65,29 @@ int transformImage(
if ((result = preparePlanes(outFormat, out, planes, lines)) < 0) { if ((result = preparePlanes(outFormat, out, planes, lines)) < 0) {
return result; return result;
} }
// NOTE: srcY stride always 0: this is a parameter of YUV format if (context) {
if ((result = sws_scale( // NOTE: srcY stride always 0: this is a parameter of YUV format
context, srcSlice, srcStride, 0, inFormat.height, planes, lines)) < if ((result = sws_scale(
0) { context, srcSlice, srcStride, 0, inFormat.height, planes, lines)) <
LOG(ERROR) << "sws_scale failed, err: " << Util::generateErrorDesc(result); 0) {
return result; LOG(ERROR) << "sws_scale failed, err: " << Util::generateErrorDesc(result);
return result;
}
} else if (inFormat.width == outFormat.width &&
inFormat.height == outFormat.height &&
inFormat.format == outFormat.format) {
// Copy planes without using sws_scale if sws_getContext failed.
av_image_copy(
planes,
lines,
(const uint8_t**)srcSlice,
srcStride,
(AVPixelFormat)inFormat.format,
inFormat.width,
inFormat.height);
} else {
LOG(ERROR) << "Invalid scale context format " << inFormat.format;
return AVERROR(EINVAL);
} }
return 0; return 0;
} }
...@@ -159,6 +176,9 @@ bool VideoSampler::init(const SamplerParameters& params) { ...@@ -159,6 +176,9 @@ bool VideoSampler::init(const SamplerParameters& params) {
<< params.out.video.minDimension << ", cropImage " << params.out.video.minDimension << ", cropImage "
<< params.out.video.cropImage; << params.out.video.cropImage;
// set output format
params_ = params;
scaleContext_ = sws_getContext( scaleContext_ = sws_getContext(
params.in.video.width, params.in.video.width,
params.in.video.height, params.in.video.height,
...@@ -170,10 +190,15 @@ bool VideoSampler::init(const SamplerParameters& params) { ...@@ -170,10 +190,15 @@ bool VideoSampler::init(const SamplerParameters& params) {
nullptr, nullptr,
nullptr, nullptr,
nullptr); nullptr);
// sws_getContext might fail if in/out format == AV_PIX_FMT_PAL8 (png format)
// set output format // Return true if input and output formats/width/height are identical
params_ = params; // Check scaleContext_ for nullptr in transformImage to copy planes directly
if (params.in.video.width == scaleFormat_.width &&
params.in.video.height == scaleFormat_.height &&
params.in.video.format == scaleFormat_.format) {
return true;
}
return scaleContext_ != nullptr; return scaleContext_ != nullptr;
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment