Validate desktop call IDRs with the common bitstream contract

This commit is contained in:
evgeny committed 2026-10-14 23:08:47 +02:00
1 parent f1513bb043
commit 043faeacca
2 files changed
+14 -4

No files matched your search

+4 -1
View File
@@ -1,5 +1,6 @@
#include "call_video_decoder.h"
#include "debug_config.h"
#include "../../../src/call/call_video_bitstream.h"
#include <QTransform>
#ifdef HAVE_FFMPEG
extern "C" {
@@ -34,6 +35,7 @@ bool CallVideoDecoder::decode(const call_video_frame& f, QImage& image) {
bool changed = !call_video_same_format(&m->format, &f.format);
const uint8_t* data = f.data; unsigned size = f.size;
if (f.flags & CALL_VIDEO_KEY) {
if (call_video_check_key(&f.format, f.data, f.size)) return failed("bitstream contract");
if (size < 5) return failed("KEY envelope");
uint32_t config = (uint32_t)data[0] << 24 | (uint32_t)data[1] << 16 | (uint32_t)data[2] << 8 | data[3];
if (config > 65536 || config >= size - 4) return failed("KEY config length");
@@ -60,7 +62,8 @@ bool CallVideoDecoder::decode(const call_video_frame& f, QImage& image) {
bool valid = result >= 0 && decoded->pts == f.pts_us && decoded->width == f.format.width && decoded->height == f.format.height
&& decoded->format == AV_PIX_FMT_YUV420P && !m->codec->has_b_frames && m->codec->level <= f.format.level;
int profile = f.format.codec == CALL_VIDEO_H265 ? AV_PROFILE_HEVC_MAIN : AV_PROFILE_H264_CONSTRAINED_BASELINE;
valid = valid && m->codec->profile == profile;
valid = valid && (m->codec->profile == profile || (f.format.codec == CALL_VIDEO_H264
&& f.format.profile == CALL_VIDEO_BASELINE && m->codec->profile == AV_PROFILE_H264_BASELINE));
if (valid) {
QImage output(decoded->width, decoded->height, QImage::Format_RGB888);
m->scale = sws_getCachedContext(m->scale, decoded->width, decoded->height, AV_PIX_FMT_YUV420P,