MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / mpegts_init

Function mpegts_init

libavformat/mpegtsenc.c:1101–1315  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1099}
1100
1101static int mpegts_init(AVFormatContext *s)
1102{
1103 MpegTSWrite *ts = s->priv_data;
1104 AVDictionaryEntry *provider;
1105 const char *provider_name;
1106 int i, j;
1107 int ret;
1108
1109 if (ts->m2ts_mode == -1) {
1110 if (av_match_ext(s->url, "m2ts")) {
1111 ts->m2ts_mode = 1;
1112 } else {
1113 ts->m2ts_mode = 0;
1114 }
1115 }
1116
1117 ts->m2ts_video_pid = M2TS_VIDEO_PID;
1118 ts->m2ts_audio_pid = M2TS_AUDIO_START_PID;
1119 ts->m2ts_pgssub_pid = M2TS_PGSSUB_START_PID;
1120 ts->m2ts_textsub_pid = M2TS_TEXTSUB_PID;
1121
1122 if (ts->m2ts_mode) {
1123 ts->pmt_start_pid = M2TS_PMT_PID;
1124 if (s->nb_programs > 1) {
1125 av_log(s, AV_LOG_ERROR, "Only one program is allowed in m2ts mode!\n");
1126 return AVERROR(EINVAL);
1127 }
1128 }
1129
1130 if (s->max_delay < 0) /* Not set by the caller */
1131 s->max_delay = 0;
1132
1133 // round up to a whole number of TS packets
1134 ts->pes_payload_size = (ts->pes_payload_size + 14 + 183) / 184 * 184 - 14;
1135
1136 ts->sdt.remaining = SECTION_LENGTH - 3;
1137
1138 if (!s->nb_programs) {
1139 /* allocate a single DVB service */
1140 if (!mpegts_add_service(s, ts->service_id, s->metadata, NULL))
1141 return AVERROR(ENOMEM);
1142 } else {
1143 for (i = 0; i < s->nb_programs; i++) {
1144 AVProgram *program = s->programs[i];
1145 if (!mpegts_add_service(s, program->id, program->metadata, program))
1146 return AVERROR(ENOMEM);
1147 }
1148 }
1149
1150 ts->pat.pid = PAT_PID;
1151 /* Initialize at 15 so that it wraps and is equal to 0 for the
1152 * first packet we write. */
1153 ts->pat.cc = 15;
1154 ts->pat.discontinuity= ts->flags & MPEGTS_FLAG_DISCONT;
1155 ts->pat.write_packet = section_write_packet;
1156 ts->pat.opaque = s;
1157
1158 ts->sdt.pid = SDT_PID;

Callers

nothing calls this directly

Calls 14

av_match_extFunction · 0.85
av_logFunction · 0.85
mpegts_add_serviceFunction · 0.85
avpriv_set_pts_infoFunction · 0.85
avformat_alloc_contextFunction · 0.85
av_guess_formatFunction · 0.85
avformat_new_streamFunction · 0.85
avcodec_parameters_copyFunction · 0.85
avformat_write_headerFunction · 0.85
av_rescaleFunction · 0.85
select_pcr_streamsFunction · 0.85
av_dict_getFunction · 0.85

Tested by

no test coverage detected