Commit c37ebc8d98 for ffmpeg

commit c37ebc8d98ca6952e6b54e6ce3bdbdd15a6abba0
Author: Rainbaby <r@bgr.jp>
Date:   Fri Aug 28 16:18:10 2026 +0900

    avcodec/cavsdec: accept the AVS1-P16 Broadcasting profile

    Until now decode_seq_header() refused profile_id 0x48, so nothing the
    preceding commits added was reachable. The annex A de-emulation and the
    field decoding among them deliberately apply to JiZhun as well.

    A Broadcasting sequence that is not 8 bit 4:2:0 is refused rather than
    decoded with the wrong macroblock layer.

    The SD AVS+ mux attached to trac ticket 6948 decodes with this: both
    video streams, frame coded AEC pictures throughout.

    Fixes: https://trac.ffmpeg.org/ticket/6948
    Signed-off-by: Rainbaby <r@bgr.jp>

diff --git a/Changelog b/Changelog
index 6bb1201481..bcfc9b3b40 100644
--- a/Changelog
+++ b/Changelog
@@ -4,6 +4,7 @@ releases are sorted from youngest to oldest.
 version <next>:
 - DTS:X height channels in the DCA decoder
 - LCEVC raw demuxer and muxer
+- AVS+ (AVS1-P16, Broadcasting profile) support in the Chinese AVS decoder

 version 9.1:
 - ASTC image encoding and decoding via libastcenc, with .astc and KTX 1.0 muxers and demuxers
diff --git a/doc/general_contents.texi b/doc/general_contents.texi
index 778f433015..573107a579 100644
--- a/doc/general_contents.texi
+++ b/doc/general_contents.texi
@@ -1058,7 +1058,8 @@ following image formats are supported:
 @item CDXL                   @tab     @tab  X
     @tab Amiga CD video codec
 @item Chinese AVS video      @tab  E  @tab  X
-    @tab AVS1-P2, JiZhun profile, encoding through external library libxavs
+    @tab AVS1-P2/P16 (JiZhun and Broadcasting) decoding,
+          AVS1-P2 encoding through external library libxavs
 @item Delphine Software International CIN video  @tab     @tab  X
     @tab Codec used in Delphine Software International games.
 @item Discworld II BMV Video @tab     @tab  X
diff --git a/libavcodec/cavs.c b/libavcodec/cavs.c
index 4f90178fc4..05117a098c 100644
--- a/libavcodec/cavs.c
+++ b/libavcodec/cavs.c
@@ -1,5 +1,5 @@
 /*
- * Chinese AVS video (AVS1-P2, JiZhun profile) decoder.
+ * Chinese AVS video (AVS1-P2/P16, JiZhun and Broadcasting profiles) decoder.
  * Copyright (c) 2006  Stefan Gehrer <stefan.gehrer@gmx.de>
  *
  * This file is part of FFmpeg.
@@ -21,7 +21,7 @@

 /**
  * @file
- * Chinese AVS video (AVS1-P2, JiZhun profile) decoder
+ * Chinese AVS video (AVS1-P2/P16, JiZhun and Broadcasting profiles) decoder
  * @author Stefan Gehrer <stefan.gehrer@gmx.de>
  */

diff --git a/libavcodec/cavs.h b/libavcodec/cavs.h
index 8c3dac34ca..b51a5e6c19 100644
--- a/libavcodec/cavs.h
+++ b/libavcodec/cavs.h
@@ -1,5 +1,5 @@
 /*
- * Chinese AVS video (AVS1-P2, JiZhun profile) decoder.
+ * Chinese AVS video (AVS1-P2/P16, JiZhun and Broadcasting profiles) decoder.
  * Copyright (c) 2006  Stefan Gehrer <stefan.gehrer@gmx.de>
  *
  * This file is part of FFmpeg.
diff --git a/libavcodec/cavs_parser.c b/libavcodec/cavs_parser.c
index bada0b2a71..a3e1d48537 100644
--- a/libavcodec/cavs_parser.c
+++ b/libavcodec/cavs_parser.c
@@ -1,5 +1,5 @@
 /*
- * Chinese AVS video (AVS1-P2, JiZhun profile) parser.
+ * Chinese AVS video (AVS1-P2/P16, JiZhun and Broadcasting profiles) parser.
  * Copyright (c) 2006  Stefan Gehrer <stefan.gehrer@gmx.de>
  *
  * This file is part of FFmpeg.
@@ -21,7 +21,7 @@

 /**
  * @file
- * Chinese AVS video (AVS1-P2, JiZhun profile) parser
+ * Chinese AVS video (AVS1-P2/P16, JiZhun and Broadcasting profiles) parser
  * @author Stefan Gehrer <stefan.gehrer@gmx.de>
  */

diff --git a/libavcodec/cavsdata.c b/libavcodec/cavsdata.c
index 85434906ad..a42c9ac5c8 100644
--- a/libavcodec/cavsdata.c
+++ b/libavcodec/cavsdata.c
@@ -1,5 +1,5 @@
 /*
- * Chinese AVS video (AVS1-P2, JiZhun profile) decoder.
+ * Chinese AVS video (AVS1-P2/P16, JiZhun and Broadcasting profiles) decoder.
  * Copyright (c) 2006  Stefan Gehrer <stefan.gehrer@gmx.de>
  *
  * This file is part of FFmpeg.
diff --git a/libavcodec/cavsdec.c b/libavcodec/cavsdec.c
index ae82bece5c..efcd156d76 100644
--- a/libavcodec/cavsdec.c
+++ b/libavcodec/cavsdec.c
@@ -1,5 +1,5 @@
 /*
- * Chinese AVS video (AVS1-P2, JiZhun profile) decoder.
+ * Chinese AVS video (AVS1-P2/P16, JiZhun and Broadcasting profiles) decoder.
  * Copyright (c) 2006  Stefan Gehrer <stefan.gehrer@gmx.de>
  *
  * This file is part of FFmpeg.
@@ -21,7 +21,7 @@

 /**
  * @file
- * Chinese AVS video (AVS1-P2, JiZhun profile) decoder
+ * Chinese AVS video (AVS1-P2/P16, JiZhun and Broadcasting profiles) decoder
  * @author Stefan Gehrer <stefan.gehrer@gmx.de>
  *
  * Clause, table and figure numbers refer to GY/T 257.1-2012.
@@ -2051,10 +2051,13 @@ static int decode_seq_header(AVSContext *h)
     int width, height;
     int mb_width, mb_height;
     int progressive_seq, low_delay;
+    int chroma_format, sample_precision;
     int ret;

     profile = get_bits(&h->gb, 8);
-    if (profile != AV_PROFILE_CAVS_JIZHUN) {
+    /* the sequence header is the same for both profiles (table 14) */
+    if (profile != AV_PROFILE_CAVS_JIZHUN &&
+        profile != AV_PROFILE_CAVS_BROADCASTING) {
         avpriv_report_missing_feature(h->avctx, "Profile %#x", profile);
         return AVERROR_PATCHWELCOME;
     }
@@ -2072,8 +2075,25 @@ static int decode_seq_header(AVSContext *h)
         av_log(h->avctx, AV_LOG_ERROR, "Dimensions invalid\n");
         return AVERROR_INVALIDDATA;
     }
-    skip_bits(&h->gb, 2); //chroma format
-    skip_bits(&h->gb, 3); //sample_precision
+    chroma_format    = get_bits(&h->gb, 2);
+    sample_precision = get_bits(&h->gb, 3);
+    /* the Broadcasting macroblock layer is written for 8 bit 4:2:0 */
+    if (profile == AV_PROFILE_CAVS_BROADCASTING) {
+        if (sample_precision != 1) {
+            av_log(h->avctx, AV_LOG_ERROR,
+                   "sample_precision %d is not 8 bit\n", sample_precision);
+            return AVERROR_INVALIDDATA;
+        }
+        if (chroma_format == 2) {
+            avpriv_request_sample(h->avctx, "4:2:2 chroma");
+            return AVERROR_PATCHWELCOME;
+        }
+        if (chroma_format != 1) {
+            av_log(h->avctx, AV_LOG_ERROR,
+                   "chroma_format %d is reserved\n", chroma_format);
+            return AVERROR_INVALIDDATA;
+        }
+    }
     aspect_ratio = get_bits(&h->gb, 4);
     frame_rate_code = get_bits(&h->gb, 4);
     if (frame_rate_code == 0 || frame_rate_code > 13) {
@@ -2365,7 +2385,7 @@ static int cavs_decode_frame(AVCodecContext *avctx, AVFrame *rframe,

 const FFCodec ff_cavs_decoder = {
     .p.name         = "cavs",
-    CODEC_LONG_NAME("Chinese AVS (Audio Video Standard) (AVS1-P2, JiZhun profile)"),
+    CODEC_LONG_NAME("Chinese AVS (Audio Video Standard) (AVS1-P2/P16)"),
     .p.type         = AVMEDIA_TYPE_VIDEO,
     .p.id           = AV_CODEC_ID_CAVS,
     .priv_data_size = sizeof(AVSContext),
diff --git a/libavcodec/cavsdsp.c b/libavcodec/cavsdsp.c
index f807ae201a..8b2fa2dde9 100644
--- a/libavcodec/cavsdsp.c
+++ b/libavcodec/cavsdsp.c
@@ -1,5 +1,5 @@
 /*
- * Chinese AVS video (AVS1-P2, JiZhun profile) decoder.
+ * Chinese AVS video (AVS1-P2/P16, JiZhun and Broadcasting profiles) decoder.
  *
  * DSP functions
  *
diff --git a/libavcodec/cavsdsp.h b/libavcodec/cavsdsp.h
index 2cd9298963..57cee4939f 100644
--- a/libavcodec/cavsdsp.h
+++ b/libavcodec/cavsdsp.h
@@ -1,5 +1,5 @@
 /*
- * Chinese AVS video (AVS1-P2, JiZhun profile) decoder.
+ * Chinese AVS video (AVS1-P2/P16, JiZhun and Broadcasting profiles) decoder.
  * Copyright (c) 2006  Stefan Gehrer <stefan.gehrer@gmx.de>
  *
  * This file is part of FFmpeg.
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index e117b81f0c..fab1cd01b6 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -658,7 +658,7 @@ static const AVCodecDescriptor codec_descriptors[] = {
         .id        = AV_CODEC_ID_CAVS,
         .type      = AVMEDIA_TYPE_VIDEO,
         .name      = "cavs",
-        .long_name = NULL_IF_CONFIG_SMALL("Chinese AVS (Audio Video Standard) (AVS1-P2, JiZhun profile)"),
+        .long_name = NULL_IF_CONFIG_SMALL("Chinese AVS (Audio Video Standard) (AVS1-P2/P16)"),
         .props     = AV_CODEC_PROP_LOSSY | AV_CODEC_PROP_REORDER,
         .profiles  = NULL_IF_CONFIG_SMALL(ff_cavs_profiles),
     },