1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-01-13 21:28:01 +02:00

avformat/mpegtsenc: factorize determining stream_type

Signed-off-by: Marton Balint <cus@passwd.hu>
This commit is contained in:
Marton Balint 2019-12-10 23:54:06 +01:00
parent bcc19933af
commit 3958244c91

View File

@ -282,6 +282,83 @@ static void put_registration_descriptor(uint8_t **q_ptr, uint32_t tag)
*q_ptr = q;
}
static int get_dvb_stream_type(AVFormatContext *s, AVStream *st)
{
MpegTSWrite *ts = s->priv_data;
int stream_type;
switch (st->codecpar->codec_id) {
case AV_CODEC_ID_MPEG1VIDEO:
case AV_CODEC_ID_MPEG2VIDEO:
stream_type = STREAM_TYPE_VIDEO_MPEG2;
break;
case AV_CODEC_ID_MPEG4:
stream_type = STREAM_TYPE_VIDEO_MPEG4;
break;
case AV_CODEC_ID_H264:
stream_type = STREAM_TYPE_VIDEO_H264;
break;
case AV_CODEC_ID_HEVC:
stream_type = STREAM_TYPE_VIDEO_HEVC;
break;
case AV_CODEC_ID_CAVS:
stream_type = STREAM_TYPE_VIDEO_CAVS;
break;
case AV_CODEC_ID_DIRAC:
stream_type = STREAM_TYPE_VIDEO_DIRAC;
break;
case AV_CODEC_ID_VC1:
stream_type = STREAM_TYPE_VIDEO_VC1;
break;
case AV_CODEC_ID_MP2:
case AV_CODEC_ID_MP3:
if ( st->codecpar->sample_rate > 0
&& st->codecpar->sample_rate < 32000) {
stream_type = STREAM_TYPE_AUDIO_MPEG2;
} else {
stream_type = STREAM_TYPE_AUDIO_MPEG1;
}
break;
case AV_CODEC_ID_AAC:
stream_type = (ts->flags & MPEGTS_FLAG_AAC_LATM)
? STREAM_TYPE_AUDIO_AAC_LATM
: STREAM_TYPE_AUDIO_AAC;
break;
case AV_CODEC_ID_AAC_LATM:
stream_type = STREAM_TYPE_AUDIO_AAC_LATM;
break;
case AV_CODEC_ID_AC3:
stream_type = (ts->flags & MPEGTS_FLAG_SYSTEM_B)
? STREAM_TYPE_PRIVATE_DATA
: STREAM_TYPE_AUDIO_AC3;
break;
case AV_CODEC_ID_EAC3:
stream_type = (ts->flags & MPEGTS_FLAG_SYSTEM_B)
? STREAM_TYPE_PRIVATE_DATA
: STREAM_TYPE_AUDIO_EAC3;
break;
case AV_CODEC_ID_DTS:
stream_type = STREAM_TYPE_AUDIO_DTS;
break;
case AV_CODEC_ID_TRUEHD:
stream_type = STREAM_TYPE_AUDIO_TRUEHD;
break;
case AV_CODEC_ID_OPUS:
stream_type = STREAM_TYPE_PRIVATE_DATA;
break;
case AV_CODEC_ID_TIMED_ID3:
stream_type = STREAM_TYPE_METADATA;
break;
default:
av_log(s, AV_LOG_WARNING, "Stream %d, codec %s, is muxed as a private data stream "
"and may not be recognized upon reading.\n", st->index, avcodec_get_name(st->codecpar->codec_id));
stream_type = STREAM_TYPE_PRIVATE_DATA;
break;
}
return stream_type;
}
static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
{
MpegTSWrite *ts = s->priv_data;
@ -323,74 +400,8 @@ static int mpegts_write_pmt(AVFormatContext *s, MpegTSService *service)
err = 1;
break;
}
switch (st->codecpar->codec_id) {
case AV_CODEC_ID_MPEG1VIDEO:
case AV_CODEC_ID_MPEG2VIDEO:
stream_type = STREAM_TYPE_VIDEO_MPEG2;
break;
case AV_CODEC_ID_MPEG4:
stream_type = STREAM_TYPE_VIDEO_MPEG4;
break;
case AV_CODEC_ID_H264:
stream_type = STREAM_TYPE_VIDEO_H264;
break;
case AV_CODEC_ID_HEVC:
stream_type = STREAM_TYPE_VIDEO_HEVC;
break;
case AV_CODEC_ID_CAVS:
stream_type = STREAM_TYPE_VIDEO_CAVS;
break;
case AV_CODEC_ID_DIRAC:
stream_type = STREAM_TYPE_VIDEO_DIRAC;
break;
case AV_CODEC_ID_VC1:
stream_type = STREAM_TYPE_VIDEO_VC1;
break;
case AV_CODEC_ID_MP2:
case AV_CODEC_ID_MP3:
if ( st->codecpar->sample_rate > 0
&& st->codecpar->sample_rate < 32000) {
stream_type = STREAM_TYPE_AUDIO_MPEG2;
} else {
stream_type = STREAM_TYPE_AUDIO_MPEG1;
}
break;
case AV_CODEC_ID_AAC:
stream_type = (ts->flags & MPEGTS_FLAG_AAC_LATM)
? STREAM_TYPE_AUDIO_AAC_LATM
: STREAM_TYPE_AUDIO_AAC;
break;
case AV_CODEC_ID_AAC_LATM:
stream_type = STREAM_TYPE_AUDIO_AAC_LATM;
break;
case AV_CODEC_ID_AC3:
stream_type = (ts->flags & MPEGTS_FLAG_SYSTEM_B)
? STREAM_TYPE_PRIVATE_DATA
: STREAM_TYPE_AUDIO_AC3;
break;
case AV_CODEC_ID_EAC3:
stream_type = (ts->flags & MPEGTS_FLAG_SYSTEM_B)
? STREAM_TYPE_PRIVATE_DATA
: STREAM_TYPE_AUDIO_EAC3;
break;
case AV_CODEC_ID_DTS:
stream_type = STREAM_TYPE_AUDIO_DTS;
break;
case AV_CODEC_ID_TRUEHD:
stream_type = STREAM_TYPE_AUDIO_TRUEHD;
break;
case AV_CODEC_ID_OPUS:
stream_type = STREAM_TYPE_PRIVATE_DATA;
break;
case AV_CODEC_ID_TIMED_ID3:
stream_type = STREAM_TYPE_METADATA;
break;
default:
av_log(s, AV_LOG_WARNING, "Stream %d, codec %s, is muxed as a private data stream "
"and may not be recognized upon reading.\n", i, avcodec_get_name(st->codecpar->codec_id));
stream_type = STREAM_TYPE_PRIVATE_DATA;
break;
}
stream_type = get_dvb_stream_type(s, st);
*q++ = stream_type;
put16(&q, 0xe000 | ts_st->pid);