[FFmpeg-devel] [PATCH 6/8] swscale/tests/swscale: remove access of AV_PIX_FMT_NB
zhilizhao
quinkblack at foxmail.com
Tue Dec 31 15:01:15 EET 2019
> On Dec 31, 2019, at 7:49 PM, Michael Niedermayer <michael at niedermayer.cc <mailto:michael at niedermayer.cc>> wrote:
>
> On Mon, Dec 30, 2019 at 09:54:17PM +0800, quinkblack at foxmail.com <mailto:quinkblack at foxmail.com> wrote:
>> From: Zhao Zhili <zhilizhao at tencent.com <mailto:zhilizhao at tencent.com>>
>>
>> ---
>> libswscale/tests/swscale.c | 17 +++++++++++++++--
>> 1 file changed, 15 insertions(+), 2 deletions(-)
>>
>> diff --git a/libswscale/tests/swscale.c b/libswscale/tests/swscale.c
>> index 19878a7877..784195f468 100644
>> --- a/libswscale/tests/swscale.c
>> +++ b/libswscale/tests/swscale.c
>> @@ -251,6 +251,18 @@ end:
>> return res;
>> }
>>
>> +static int getMaxFmt()
>> +{
>> + const AVPixFmtDescriptor *desc = NULL;
>> + int fmt_max = AV_PIX_FMT_NONE;
>> +
>> + while ((desc = av_pix_fmt_desc_next(desc))) {
>> + int fmt = av_pix_fmt_desc_get_id(desc);
>> + fmt_max = FFMAX(fmt, fmt_max);
>> + }
>> + return fmt_max;
>> +}
>> +
>> static void selfTest(const uint8_t * const ref[4], int refStride[4],
>> int w, int h,
>> enum AVPixelFormat srcFormat_in,
>> @@ -264,9 +276,10 @@ static void selfTest(const uint8_t * const ref[4], int refStride[4],
>> const int dstH[] = { srcH - srcH / 3, srcH, srcH + srcH / 3, 0 };
>> enum AVPixelFormat srcFormat, dstFormat;
>> const AVPixFmtDescriptor *desc_src, *desc_dst;
>> + const int fmt_max = getMaxFmt();
>>
>> for (srcFormat = srcFormat_in != AV_PIX_FMT_NONE ? srcFormat_in : 0;
>> - srcFormat < AV_PIX_FMT_NB; srcFormat++) {
>> + srcFormat <= fmt_max; srcFormat++) {
>> if (!sws_isSupportedInput(srcFormat) ||
>> !sws_isSupportedOutput(srcFormat))
>> continue;
>> @@ -274,7 +287,7 @@ static void selfTest(const uint8_t * const ref[4], int refStride[4],
>> desc_src = av_pix_fmt_desc_get(srcFormat);
>>
>> for (dstFormat = dstFormat_in != AV_PIX_FMT_NONE ? dstFormat_in : 0;
>> - dstFormat < AV_PIX_FMT_NB; dstFormat++) {
>> + dstFormat <= fmt_max; dstFormat++) {
>> int i, j, k;
>> int res = 0;
>
> Iam not sure this makes sense, formats added after build of the test
> would only be rejected in sws_isSupported* in the next line
>
(srcFormat < AV_PIX_FMT_NB) means (srcFormat <= AV_PIX_FMT_MAX)
in the context.
Ensure sws_isSupported* can handle invalid (unknown) input is the point of
the test, I guess. Actually, I think it would be better to test
srcFormat <= (fmt_max + 1)
However, it changed the semantics of the original code, and looks like a bug
if takes the code as ‘example’.
>
> [...]
>
> --
> Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> If you drop bombs on a foreign country and kill a hundred thousand
> innocent people, expect your government to call the consequence
> "unprovoked inhuman terrorist attacks" and use it to justify dropping
> more bombs and killing more people. The technology changed, the idea is old.
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org <mailto:ffmpeg-devel at ffmpeg.org>
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel <https://ffmpeg.org/mailman/listinfo/ffmpeg-devel>
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request at ffmpeg.org with subject "unsubscribe".
More information about the ffmpeg-devel
mailing list