avformat/mpegts: replace magic descriptor_tag values with defines

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>
Signed-off-by: Marton Balint <cus@passwd.hu>
This commit is contained in:
Brad Hards 2020-10-10 17:04:30 +11:00 committed by Marton Balint
parent 15a74d21f3
commit fcec7a6848
3 changed files with 21 additions and 11 deletions

View File

@ -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;
}

View File

@ -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);

View File

@ -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));