From 46e1284d95407f1b757f23aedf59fb9332f48913 Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Sun, 30 Mar 2025 12:06:13 +0200
Subject: [PATCH] avformat/rtpenc: Check dimensions during init

Also fixes a -Wdeclaration-after-statement warning.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavformat/rtpenc.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/libavformat/rtpenc.c b/libavformat/rtpenc.c
index 8b989dca71..b220a941a2 100644
--- a/libavformat/rtpenc.c
+++ b/libavformat/rtpenc.c
@@ -219,6 +219,14 @@ static int rtp_write_header(AVFormatContext *s1)
             s->nal_length_size = (st->codecpar->extradata[21] & 0x03) + 1;
         }
         break;
+    case AV_CODEC_ID_MJPEG:
+    case AV_CODEC_ID_BITPACKED:
+    case AV_CODEC_ID_RAWVIDEO:
+        if (st->codecpar->width <= 0 || st->codecpar->height <= 0) {
+            av_log(s1, AV_LOG_ERROR, "dimensions not set\n");
+            return AVERROR(EINVAL);
+        }
+        break;
     case AV_CODEC_ID_VP9:
         if (s1->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) {
             av_log(s, AV_LOG_ERROR,
@@ -635,18 +643,10 @@ static int rtp_write_packet(AVFormatContext *s1, AVPacket *pkt)
         rtp_send_ilbc(s1, pkt->data, size);
         break;
     case AV_CODEC_ID_MJPEG:
-        if (st->codecpar->width <= 0 || st->codecpar->height <= 0) {
-            av_log(s1, AV_LOG_ERROR, "dimensions not set\n");
-            return AVERROR(EINVAL);
-        }
         ff_rtp_send_jpeg(s1, pkt->data, size);
         break;
     case AV_CODEC_ID_BITPACKED:
     case AV_CODEC_ID_RAWVIDEO: {
-        if (st->codecpar->width <= 0 || st->codecpar->height <= 0) {
-            av_log(s1, AV_LOG_ERROR, "dimensions not set\n");
-            return AVERROR(EINVAL);
-        }
         int interlaced = st->codecpar->field_order != AV_FIELD_PROGRESSIVE;
 
         ff_rtp_send_raw_rfc4175(s1, pkt->data, size, interlaced, 0);
-- 
2.45.2