[FFmpeg-devel] [PATCH 1/2] avformat/mpegtsenc: simplify code by using OFFSET() and ENC macros

lance.lmwang at gmail.com lance.lmwang at gmail.com
Wed May 20 17:31:13 EEST 2020


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

Signed-off-by: Limin Wang <lance.lmwang at gmail.com>
---
 libavformat/mpegtsenc.c | 92 +++++++++++++++++++++++++------------------------
 1 file changed, 47 insertions(+), 45 deletions(-)

diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index bf1a7ee..9909d25 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -1962,94 +1962,96 @@ static int mpegts_check_bitstream(struct AVFormatContext *s, const AVPacket *pkt
     return ret;
 }
 
+#define OFFSET(x) offsetof(MpegTSWrite, x)
+#define ENC AV_OPT_FLAG_ENCODING_PARAM
 static const AVOption options[] = {
     { "mpegts_transport_stream_id", "Set transport_stream_id field.",
-      offsetof(MpegTSWrite, transport_stream_id), AV_OPT_TYPE_INT,
-      { .i64 = 0x0001 }, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM },
+      OFFSET(transport_stream_id), AV_OPT_TYPE_INT,
+      { .i64 = 0x0001 }, 0x0001, 0xffff, ENC },
     { "mpegts_original_network_id", "Set original_network_id field.",
-      offsetof(MpegTSWrite, original_network_id), AV_OPT_TYPE_INT,
-      { .i64 = DVB_PRIVATE_NETWORK_START }, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM },
+      OFFSET(original_network_id), AV_OPT_TYPE_INT,
+      { .i64 = DVB_PRIVATE_NETWORK_START }, 0x0001, 0xffff, ENC },
     { "mpegts_service_id", "Set service_id field.",
-      offsetof(MpegTSWrite, service_id), AV_OPT_TYPE_INT,
-      { .i64 = 0x0001 }, 0x0001, 0xffff, AV_OPT_FLAG_ENCODING_PARAM },
+      OFFSET(service_id), AV_OPT_TYPE_INT,
+      { .i64 = 0x0001 }, 0x0001, 0xffff, ENC },
     { "mpegts_service_type", "Set service_type field.",
-      offsetof(MpegTSWrite, service_type), AV_OPT_TYPE_INT,
-      { .i64 = 0x01 }, 0x01, 0xff, AV_OPT_FLAG_ENCODING_PARAM, "mpegts_service_type" },
+      OFFSET(service_type), AV_OPT_TYPE_INT,
+      { .i64 = 0x01 }, 0x01, 0xff, ENC, "mpegts_service_type" },
     { "digital_tv", "Digital Television.",
       0, AV_OPT_TYPE_CONST, { .i64 = MPEGTS_SERVICE_TYPE_DIGITAL_TV }, 0x01, 0xff,
-      AV_OPT_FLAG_ENCODING_PARAM, "mpegts_service_type" },
+      ENC, "mpegts_service_type" },
     { "digital_radio", "Digital Radio.",
       0, AV_OPT_TYPE_CONST, { .i64 = MPEGTS_SERVICE_TYPE_DIGITAL_RADIO }, 0x01, 0xff,
-      AV_OPT_FLAG_ENCODING_PARAM, "mpegts_service_type" },
+      ENC, "mpegts_service_type" },
     { "teletext", "Teletext.",
       0, AV_OPT_TYPE_CONST, { .i64 = MPEGTS_SERVICE_TYPE_TELETEXT }, 0x01, 0xff,
-      AV_OPT_FLAG_ENCODING_PARAM, "mpegts_service_type" },
+      ENC, "mpegts_service_type" },
     { "advanced_codec_digital_radio", "Advanced Codec Digital Radio.",
       0, AV_OPT_TYPE_CONST, { .i64 = MPEGTS_SERVICE_TYPE_ADVANCED_CODEC_DIGITAL_RADIO }, 0x01, 0xff,
-      AV_OPT_FLAG_ENCODING_PARAM, "mpegts_service_type" },
+      ENC, "mpegts_service_type" },
     { "mpeg2_digital_hdtv", "MPEG2 Digital HDTV.",
       0, AV_OPT_TYPE_CONST, { .i64 = MPEGTS_SERVICE_TYPE_MPEG2_DIGITAL_HDTV }, 0x01, 0xff,
-      AV_OPT_FLAG_ENCODING_PARAM, "mpegts_service_type" },
+      ENC, "mpegts_service_type" },
     { "advanced_codec_digital_sdtv", "Advanced Codec Digital SDTV.",
       0, AV_OPT_TYPE_CONST, { .i64 = MPEGTS_SERVICE_TYPE_ADVANCED_CODEC_DIGITAL_SDTV }, 0x01, 0xff,
-      AV_OPT_FLAG_ENCODING_PARAM, "mpegts_service_type" },
+      ENC, "mpegts_service_type" },
     { "advanced_codec_digital_hdtv", "Advanced Codec Digital HDTV.",
       0, AV_OPT_TYPE_CONST, { .i64 = MPEGTS_SERVICE_TYPE_ADVANCED_CODEC_DIGITAL_HDTV }, 0x01, 0xff,
-      AV_OPT_FLAG_ENCODING_PARAM, "mpegts_service_type" },
+      ENC, "mpegts_service_type" },
     { "hevc_digital_hdtv", "HEVC Digital Television Service.",
       0, AV_OPT_TYPE_CONST, { .i64 = MPEGTS_SERVICE_TYPE_HEVC_DIGITAL_HDTV }, 0x01, 0xff,
-      AV_OPT_FLAG_ENCODING_PARAM, "mpegts_service_type" },
+      ENC, "mpegts_service_type" },
     { "mpegts_pmt_start_pid", "Set the first pid of the PMT.",
-      offsetof(MpegTSWrite, pmt_start_pid), AV_OPT_TYPE_INT,
-      { .i64 = 0x1000 }, FIRST_OTHER_PID, LAST_OTHER_PID, AV_OPT_FLAG_ENCODING_PARAM },
+      OFFSET(pmt_start_pid), AV_OPT_TYPE_INT,
+      { .i64 = 0x1000 }, FIRST_OTHER_PID, LAST_OTHER_PID, ENC },
     { "mpegts_start_pid", "Set the first pid.",
-      offsetof(MpegTSWrite, start_pid), AV_OPT_TYPE_INT,
-      { .i64 = 0x0100 }, FIRST_OTHER_PID, LAST_OTHER_PID, AV_OPT_FLAG_ENCODING_PARAM },
+      OFFSET(start_pid), AV_OPT_TYPE_INT,
+      { .i64 = 0x0100 }, FIRST_OTHER_PID, LAST_OTHER_PID, ENC },
     { "mpegts_m2ts_mode", "Enable m2ts mode.",
-      offsetof(MpegTSWrite, m2ts_mode), AV_OPT_TYPE_BOOL,
-      { .i64 = -1 }, -1, 1, AV_OPT_FLAG_ENCODING_PARAM },
+      OFFSET(m2ts_mode), AV_OPT_TYPE_BOOL,
+      { .i64 = -1 }, -1, 1, ENC },
     { "muxrate", NULL,
-      offsetof(MpegTSWrite, mux_rate), AV_OPT_TYPE_INT,
-      { .i64 = 1 }, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
+      OFFSET(mux_rate), AV_OPT_TYPE_INT,
+      { .i64 = 1 }, 0, INT_MAX, ENC },
     { "pes_payload_size", "Minimum PES packet payload in bytes",
-      offsetof(MpegTSWrite, pes_payload_size), AV_OPT_TYPE_INT,
-      { .i64 = DEFAULT_PES_PAYLOAD_SIZE }, 0, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
+      OFFSET(pes_payload_size), AV_OPT_TYPE_INT,
+      { .i64 = DEFAULT_PES_PAYLOAD_SIZE }, 0, INT_MAX, ENC },
     { "mpegts_flags", "MPEG-TS muxing flags",
-      offsetof(MpegTSWrite, flags), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, 0, INT_MAX,
-      AV_OPT_FLAG_ENCODING_PARAM, "mpegts_flags" },
+      OFFSET(flags), AV_OPT_TYPE_FLAGS, { .i64 = 0 }, 0, INT_MAX,
+      ENC, "mpegts_flags" },
     { "resend_headers", "Reemit PAT/PMT before writing the next packet",
       0, AV_OPT_TYPE_CONST, { .i64 = MPEGTS_FLAG_REEMIT_PAT_PMT }, 0, INT_MAX,
-      AV_OPT_FLAG_ENCODING_PARAM, "mpegts_flags" },
+      ENC, "mpegts_flags" },
     { "latm", "Use LATM packetization for AAC",
       0, AV_OPT_TYPE_CONST, { .i64 = MPEGTS_FLAG_AAC_LATM }, 0, INT_MAX,
-      AV_OPT_FLAG_ENCODING_PARAM, "mpegts_flags" },
+      ENC, "mpegts_flags" },
     { "pat_pmt_at_frames", "Reemit PAT and PMT at each video frame",
       0, AV_OPT_TYPE_CONST, { .i64 = MPEGTS_FLAG_PAT_PMT_AT_FRAMES}, 0, INT_MAX,
-      AV_OPT_FLAG_ENCODING_PARAM, "mpegts_flags" },
+      ENC, "mpegts_flags" },
     { "system_b", "Conform to System B (DVB) instead of System A (ATSC)",
       0, AV_OPT_TYPE_CONST, { .i64 = MPEGTS_FLAG_SYSTEM_B }, 0, INT_MAX,
-      AV_OPT_FLAG_ENCODING_PARAM, "mpegts_flags" },
+      ENC, "mpegts_flags" },
     { "initial_discontinuity", "Mark initial packets as discontinuous",
       0, AV_OPT_TYPE_CONST, { .i64 = MPEGTS_FLAG_DISCONT }, 0, INT_MAX,
-      AV_OPT_FLAG_ENCODING_PARAM, "mpegts_flags" },
+      ENC, "mpegts_flags" },
     { "mpegts_copyts", "don't offset dts/pts",
-      offsetof(MpegTSWrite, copyts), AV_OPT_TYPE_BOOL,
-      { .i64 = -1 }, -1, 1, AV_OPT_FLAG_ENCODING_PARAM },
+      OFFSET(copyts), AV_OPT_TYPE_BOOL,
+      { .i64 = -1 }, -1, 1, ENC },
     { "tables_version", "set PAT, PMT and SDT version",
-      offsetof(MpegTSWrite, tables_version), AV_OPT_TYPE_INT,
-      { .i64 = 0 }, 0, 31, AV_OPT_FLAG_ENCODING_PARAM },
+      OFFSET(tables_version), AV_OPT_TYPE_INT,
+      { .i64 = 0 }, 0, 31, ENC },
     { "omit_video_pes_length", "Omit the PES packet length for video packets",
-      offsetof(MpegTSWrite, omit_video_pes_length), AV_OPT_TYPE_BOOL,
-      { .i64 = 1 }, 0, 1, AV_OPT_FLAG_ENCODING_PARAM },
+      OFFSET(omit_video_pes_length), AV_OPT_TYPE_BOOL,
+      { .i64 = 1 }, 0, 1, ENC },
     { "pcr_period", "PCR retransmission time in milliseconds",
-      offsetof(MpegTSWrite, pcr_period_ms), AV_OPT_TYPE_INT,
-      { .i64 = -1 }, -1, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
+      OFFSET(pcr_period_ms), AV_OPT_TYPE_INT,
+      { .i64 = -1 }, -1, INT_MAX, ENC },
     { "pat_period", "PAT/PMT retransmission time limit in seconds",
-      offsetof(MpegTSWrite, pat_period_us), AV_OPT_TYPE_DURATION,
-      { .i64 = PAT_RETRANS_TIME * 1000LL }, 0, INT64_MAX, AV_OPT_FLAG_ENCODING_PARAM },
+      OFFSET(pat_period_us), AV_OPT_TYPE_DURATION,
+      { .i64 = PAT_RETRANS_TIME * 1000LL }, 0, INT64_MAX, ENC },
     { "sdt_period", "SDT retransmission time limit in seconds",
-      offsetof(MpegTSWrite, sdt_period_us), AV_OPT_TYPE_DURATION,
-      { .i64 = SDT_RETRANS_TIME * 1000LL }, 0, INT64_MAX, AV_OPT_FLAG_ENCODING_PARAM },
+      OFFSET(sdt_period_us), AV_OPT_TYPE_DURATION,
+      { .i64 = SDT_RETRANS_TIME * 1000LL }, 0, INT64_MAX, ENC },
     { NULL },
 };
 
-- 
1.8.3.1



More information about the ffmpeg-devel mailing list