| 1099 | } |
| 1100 | |
| 1101 | static 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; |
nothing calls this directly
no test coverage detected