diff mbox series

[FFmpeg-devel] lavf/mpeg: replace magic descriptor_tag values with defines

Message ID 20201010060430.25354-1-bradh@frogmouth.net
State Accepted
Commit fcec7a6848e79d86bb63208e5d75c6a09acd3a84
Headers show
Series [FFmpeg-devel] lavf/mpeg: replace magic descriptor_tag values with defines | expand

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make warning Make failed

Commit Message

Brad Hards Oct. 10, 2020, 6:04 a.m. UTC
This takes the used values from ISO/IEC 13818-1 Table 2-45 and adds
them to the mpegts.h header. No functional changes.

Signed-off-by: Brad Hards <bradh@frogmouth.net>
---
 libavformat/mpegts.c    | 16 ++++++++--------
 libavformat/mpegts.h    | 10 ++++++++++
 libavformat/mpegtsenc.c |  6 +++---
 3 files changed, 21 insertions(+), 11 deletions(-)

Comments

Michael Niedermayer Oct. 11, 2020, 11:08 a.m. UTC | #1
On Sat, Oct 10, 2020 at 05:04:30PM +1100, Brad Hards wrote:
> This takes the used values from ISO/IEC 13818-1 Table 2-45 and adds
> them to the mpegts.h header. No functional changes.
> 
> Signed-off-by: Brad Hards <bradh@frogmouth.net>
> ---
>  libavformat/mpegts.c    | 16 ++++++++--------
>  libavformat/mpegts.h    | 10 ++++++++++
>  libavformat/mpegtsenc.c |  6 +++---
>  3 files changed, 21 insertions(+), 11 deletions(-)

should be ok

thx

[...]
Marton Balint Oct. 16, 2020, 9:47 p.m. UTC | #2
On Sun, 11 Oct 2020, Michael Niedermayer wrote:

> On Sat, Oct 10, 2020 at 05:04:30PM +1100, Brad Hards wrote:
>> This takes the used values from ISO/IEC 13818-1 Table 2-45 and adds
>> them to the mpegts.h header. No functional changes.
>>
>> Signed-off-by: Brad Hards <bradh@frogmouth.net>
>> ---
>>  libavformat/mpegts.c    | 16 ++++++++--------
>>  libavformat/mpegts.h    | 10 ++++++++++
>>  libavformat/mpegtsenc.c |  6 +++---
>>  3 files changed, 21 insertions(+), 11 deletions(-)
>
> should be ok

Will apply.

Thanks,
Marton
diff mbox series

Patch

diff --git a/libavformat/mpegts.c b/libavformat/mpegts.c
index 432b1c3ea2..f750989629 100644
--- a/libavformat/mpegts.c
+++ b/libavformat/mpegts.c
@@ -1804,12 +1804,12 @@  int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type
         mpegts_find_stream_type(st, desc_tag, DESC_types);
 
     switch (desc_tag) {
-    case 0x02: /* video stream descriptor */
+    case VIDEO_STREAM_DESCRIPTOR:
         if (get8(pp, desc_end) & 0x1) {
             st->disposition |= AV_DISPOSITION_STILL_IMAGE;
         }
         break;
-    case 0x1E: /* SL descriptor */
+    case SL_DESCRIPTOR:
         desc_es_id = get16(pp, desc_end);
         if (desc_es_id < 0)
             break;
@@ -1832,7 +1832,7 @@  int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type
                     mpegts_open_section_filter(ts, pid, m4sl_cb, ts, 1);
             }
         break;
-    case 0x1F: /* FMC descriptor */
+    case FMC_DESCRIPTOR:
         if (get16(pp, desc_end) < 0)
             break;
         if (mp4_descr_count > 0 &&
@@ -1958,7 +1958,7 @@  int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type
             }
         }
         break;
-    case 0x0a: /* ISO 639 language descriptor */
+    case ISO_639_LANGUAGE_DESCRIPTOR:
         for (i = 0; i + 4 <= desc_len; i += 4) {
             language[i + 0] = get8(pp, desc_end);
             language[i + 1] = get8(pp, desc_end);
@@ -1984,7 +1984,7 @@  int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type
             av_dict_set(&st->metadata, "language", language, AV_DICT_DONT_OVERWRITE);
         }
         break;
-    case 0x05: /* registration descriptor */
+    case REGISTRATION_DESCRIPTOR:
         st->codecpar->codec_tag = bytestream_get_le32(pp);
         av_log(fc, AV_LOG_TRACE, "reg_desc=%.4s\n", (char *)&st->codecpar->codec_tag);
         if (st->codecpar->codec_id == AV_CODEC_ID_NONE || st->request_probe > 0) {
@@ -1996,7 +1996,7 @@  int ff_parse_mpeg2_descriptor(AVFormatContext *fc, AVStream *st, int stream_type
     case 0x52: /* stream identifier descriptor */
         st->stream_identifier = 1 + get8(pp, desc_end);
         break;
-    case 0x26: /* metadata descriptor */
+    case METADATA_DESCRIPTOR:
         if (get16(pp, desc_end) == 0xFFFF)
             *pp += 4;
         if (get8(pp, desc_end) == 0xFF) {
@@ -2338,13 +2338,13 @@  static void pmt_cb(MpegTSFilter *filter, const uint8_t *section, int section_len
             // something else is broken, exit the program_descriptors_loop
             break;
         program_info_length -= len + 2;
-        if (tag == 0x1d) { // IOD descriptor
+        if (tag == IOD_DESCRIPTOR) {
             get8(&p, p_end); // scope
             get8(&p, p_end); // label
             len -= 2;
             mp4_read_iods(ts->stream, p, len, mp4_descr + mp4_descr_count,
                           &mp4_descr_count, MAX_MP4_DESCR_COUNT);
-        } else if (tag == 0x05 && len >= 4) { // registration descriptor
+        } else if (tag == REGISTRATION_DESCRIPTOR && len >= 4) {
             prog_reg_desc = bytestream_get_le32(&p);
             len -= 4;
         }
diff --git a/libavformat/mpegts.h b/libavformat/mpegts.h
index d70b25d018..04874e0f42 100644
--- a/libavformat/mpegts.h
+++ b/libavformat/mpegts.h
@@ -144,6 +144,16 @@ 
 #define STREAM_ID_METADATA_STREAM    0xfc
 #define STREAM_ID_EXTENDED_STREAM_ID 0xfd
 
+/* ISO/IEC 13818-1 Table 2-45 */
+#define VIDEO_STREAM_DESCRIPTOR      0x02
+#define REGISTRATION_DESCRIPTOR      0x05
+#define ISO_639_LANGUAGE_DESCRIPTOR  0x0a
+#define IOD_DESCRIPTOR               0x1d
+#define SL_DESCRIPTOR                0x1e
+#define FMC_DESCRIPTOR               0x1f
+#define METADATA_DESCRIPTOR          0x26
+#define METADATA_STD_DESCRIPTOR      0x27
+
 typedef struct MpegTSContext MpegTSContext;
 
 MpegTSContext *avpriv_mpegts_parse_open(AVFormatContext *s);
diff --git a/libavformat/mpegtsenc.c b/libavformat/mpegtsenc.c
index 1687de74ad..afdaddad8e 100644
--- a/libavformat/mpegtsenc.c
+++ b/libavformat/mpegtsenc.c
@@ -275,7 +275,7 @@  static void putbuf(uint8_t **q_ptr, const uint8_t *buf, size_t len)
 static void put_registration_descriptor(uint8_t **q_ptr, uint32_t tag)
 {
     uint8_t *q = *q_ptr;
-    *q++ = 0x05; /* MPEG-2 registration descriptor*/
+    *q++ = REGISTRATION_DESCRIPTOR;
     *q++ = 4;
     *q++ = tag;
     *q++ = tag >> 8;
@@ -600,7 +600,7 @@  static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
                 char *next = lang->value;
                 uint8_t *len_ptr;
 
-                *q++     = 0x0a; /* ISO 639 language descriptor */
+                *q++     = ISO_639_LANGUAGE_DESCRIPTOR;
                 len_ptr  = q++;
                 *len_ptr = 0;
 
@@ -728,7 +728,7 @@  static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
                 put_registration_descriptor(&q, MKTAG('K', 'L', 'V', 'A'));
             } else if (codec_id == AV_CODEC_ID_TIMED_ID3) {
                 const char *tag = "ID3 ";
-                *q++ = 0x26; /* metadata descriptor */
+                *q++ = METADATA_DESCRIPTOR;
                 *q++ = 13;
                 put16(&q, 0xffff);    /* metadata application format */
                 putbuf(&q, tag, strlen(tag));