[FFmpeg-devel] [PATCH 06/11] avcodec: use s210 fourcc for 10-bit 4:2:2 packed

lance.lmwang at gmail.com lance.lmwang at gmail.com
Fri Nov 12 12:22:11 EET 2021


From: Limin Wang <lance.lmwang at gmail.com>

s210 is used by AWS Elemental Live encoder so I prefer to use same to support
4:2:2 10-bit packed uncompressed video. Refer to:
https://docs.aws.amazon.com/elemental-live/latest/ug/codec-vod-outputs.html

I split the patch for better review, next patch will rename bitpacked.c to
s210dec.c to reflect the change.

Signed-off-by: Limin Wang <lance.lmwang at gmail.com>
---
 libavcodec/Makefile          |  2 +-
 libavcodec/allcodecs.c       |  2 +-
 libavcodec/bitpacked.c       | 33 +++++++++++++++++----------------
 libavcodec/codec_desc.c      |  6 +++---
 libavcodec/codec_id.h        |  2 +-
 libavformat/rtpdec_rfc4175.c |  2 +-
 6 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 14fbd2e..8ae28e8 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -243,7 +243,7 @@ OBJS-$(CONFIG_BINK_DECODER)            += bink.o binkdsp.o
 OBJS-$(CONFIG_BINKAUDIO_DCT_DECODER)   += binkaudio.o
 OBJS-$(CONFIG_BINKAUDIO_RDFT_DECODER)  += binkaudio.o
 OBJS-$(CONFIG_BINTEXT_DECODER)         += bintext.o cga_data.o
-OBJS-$(CONFIG_BITPACKED_DECODER)       += bitpacked.o
+OBJS-$(CONFIG_S210_DECODER)            += bitpacked.o
 OBJS-$(CONFIG_BMP_DECODER)             += bmp.o msrledec.o
 OBJS-$(CONFIG_BMP_ENCODER)             += bmpenc.o
 OBJS-$(CONFIG_BMV_AUDIO_DECODER)       += bmvaudio.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 9ede09b..c461798 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -64,7 +64,7 @@ extern const AVCodec ff_ayuv_decoder;
 extern const AVCodec ff_bethsoftvid_decoder;
 extern const AVCodec ff_bfi_decoder;
 extern const AVCodec ff_bink_decoder;
-extern const AVCodec ff_bitpacked_decoder;
+extern const AVCodec ff_s210_decoder;
 extern const AVCodec ff_bmp_encoder;
 extern const AVCodec ff_bmp_decoder;
 extern const AVCodec ff_bmv_video_decoder;
diff --git a/libavcodec/bitpacked.c b/libavcodec/bitpacked.c
index d239141..7bc5dbc 100644
--- a/libavcodec/bitpacked.c
+++ b/libavcodec/bitpacked.c
@@ -1,6 +1,7 @@
 /*
- * Unpack bit-packed streams to formats supported by FFmpeg
+ * S210 decoder
  * Copyright (c) 2017 Savoir-faire Linux, Inc
+ * Copyright (c) 2021 Limin Wang
  *
  * This file is part of FFmpeg.
  *
@@ -23,7 +24,7 @@
 
 /**
  * @file
- * Bitpacked
+ * s210dec
  */
 
 #include "avcodec.h"
@@ -31,12 +32,12 @@
 #include "get_bits.h"
 #include "libavutil/imgutils.h"
 
-struct BitpackedContext {
+struct S210Context {
     int (*decode)(AVCodecContext *avctx, AVFrame *frame,
                   const AVPacket *pkt);
 };
 
-static int bitpacked_decode_yuv422p10(AVCodecContext *avctx, AVFrame *frame,
+static int s210_decode_yuv422p10(AVCodecContext *avctx, AVFrame *frame,
                                       const AVPacket *avpkt)
 {
     uint64_t frame_size = (uint64_t)avctx->width * (uint64_t)avctx->height * 20;
@@ -75,26 +76,26 @@ static int bitpacked_decode_yuv422p10(AVCodecContext *avctx, AVFrame *frame,
     return 0;
 }
 
-static av_cold int bitpacked_init_decoder(AVCodecContext *avctx)
+static av_cold int s210_init_decoder(AVCodecContext *avctx)
 {
-    struct BitpackedContext *bc = avctx->priv_data;
+    struct S210Context *bc = avctx->priv_data;
 
     if (!avctx->width || !avctx->height)
         return AVERROR_INVALIDDATA;
 
     if (avctx->bits_per_coded_sample == 20 &&
         avctx->pix_fmt == AV_PIX_FMT_YUV422P10)
-        bc->decode = bitpacked_decode_yuv422p10;
+        bc->decode = s210_decode_yuv422p10;
     else
         return AVERROR_INVALIDDATA;
 
     return 0;
 }
 
-static int bitpacked_decode(AVCodecContext *avctx, void *data, int *got_frame,
+static int s210_decode(AVCodecContext *avctx, void *data, int *got_frame,
                             AVPacket *avpkt)
 {
-    struct BitpackedContext *bc = avctx->priv_data;
+    struct S210Context *bc = avctx->priv_data;
     int buf_size = avpkt->size;
     AVFrame *frame = data;
     int res;
@@ -111,14 +112,14 @@ static int bitpacked_decode(AVCodecContext *avctx, void *data, int *got_frame,
 
 }
 
-const AVCodec ff_bitpacked_decoder = {
-    .name   = "bitpacked",
-    .long_name = NULL_IF_CONFIG_SMALL("Bitpacked"),
+const AVCodec ff_s210_decoder = {
+    .name   = "s210",
+    .long_name = NULL_IF_CONFIG_SMALL("10-bit 4:2:2 packed"),
     .type = AVMEDIA_TYPE_VIDEO,
-    .id = AV_CODEC_ID_BITPACKED,
-    .priv_data_size        = sizeof(struct BitpackedContext),
-    .init = bitpacked_init_decoder,
-    .decode = bitpacked_decode,
+    .id = AV_CODEC_ID_S210,
+    .priv_data_size        = sizeof(struct S210Context),
+    .init = s210_init_decoder,
+    .decode = s210_decode,
     .capabilities = AV_CODEC_CAP_EXPERIMENTAL,
     .caps_internal  = FF_CODEC_CAP_INIT_THREADSAFE,
 };
diff --git a/libavcodec/codec_desc.c b/libavcodec/codec_desc.c
index 0974ee0..d1cc4d0 100644
--- a/libavcodec/codec_desc.c
+++ b/libavcodec/codec_desc.c
@@ -1645,10 +1645,10 @@ static const AVCodecDescriptor codec_descriptors[] = {
         .profiles  = NULL_IF_CONFIG_SMALL(ff_av1_profiles),
     },
     {
-        .id        = AV_CODEC_ID_BITPACKED,
+        .id        = AV_CODEC_ID_S210,
         .type      = AVMEDIA_TYPE_VIDEO,
-        .name      = "bitpacked",
-        .long_name = NULL_IF_CONFIG_SMALL("Bitpacked"),
+        .name      = "s210",
+        .long_name = NULL_IF_CONFIG_SMALL("10-bit 4:2:2 packed"),
         .props     = AV_CODEC_PROP_INTRA_ONLY | AV_CODEC_PROP_LOSSLESS,
     },
     {
diff --git a/libavcodec/codec_id.h b/libavcodec/codec_id.h
index ab265ec..721174f 100644
--- a/libavcodec/codec_id.h
+++ b/libavcodec/codec_id.h
@@ -277,7 +277,7 @@ enum AVCodecID {
     AV_CODEC_ID_CLEARVIDEO,
     AV_CODEC_ID_XPM,
     AV_CODEC_ID_AV1,
-    AV_CODEC_ID_BITPACKED,
+    AV_CODEC_ID_S210,
     AV_CODEC_ID_MSCC,
     AV_CODEC_ID_SRGC,
     AV_CODEC_ID_SVG,
diff --git a/libavformat/rtpdec_rfc4175.c b/libavformat/rtpdec_rfc4175.c
index 81930ce..d39a3aa 100644
--- a/libavformat/rtpdec_rfc4175.c
+++ b/libavformat/rtpdec_rfc4175.c
@@ -57,7 +57,7 @@ static int rfc4175_parse_format(AVStream *stream, PayloadContext *data)
         } else if (data->depth == 10) {
             data->pgroup = 5;
             pixfmt = AV_PIX_FMT_YUV422P10;
-            stream->codecpar->codec_id = AV_CODEC_ID_BITPACKED;
+            stream->codecpar->codec_id = AV_CODEC_ID_S210;
         } else {
             return AVERROR_INVALIDDATA;
         }
-- 
1.8.3.1



More information about the ffmpeg-devel mailing list