| 243 | } |
| 244 | |
| 245 | AVStream *avformat_new_stream(AVFormatContext *s, const AVCodec *c) |
| 246 | { |
| 247 | FFStream *sti; |
| 248 | AVStream *st; |
| 249 | AVStream **streams; |
| 250 | |
| 251 | if (s->nb_streams >= s->max_streams) { |
| 252 | av_log(s, AV_LOG_ERROR, "Number of streams exceeds max_streams parameter" |
| 253 | " (%d), see the documentation if you wish to increase it\n", |
| 254 | s->max_streams); |
| 255 | return NULL; |
| 256 | } |
| 257 | streams = av_realloc_array(s->streams, s->nb_streams + 1, sizeof(*streams)); |
| 258 | if (!streams) |
| 259 | return NULL; |
| 260 | s->streams = streams; |
| 261 | |
| 262 | sti = av_mallocz(sizeof(*sti)); |
| 263 | if (!sti) |
| 264 | return NULL; |
| 265 | st = &sti->pub; |
| 266 | |
| 267 | st->av_class = &stream_class; |
| 268 | st->codecpar = avcodec_parameters_alloc(); |
| 269 | if (!st->codecpar) |
| 270 | goto fail; |
| 271 | |
| 272 | sti->fmtctx = s; |
| 273 | |
| 274 | sti->parse_pkt = av_packet_alloc(); |
| 275 | if (!sti->parse_pkt) |
| 276 | goto fail; |
| 277 | |
| 278 | if (s->iformat) { |
| 279 | sti->avctx = avcodec_alloc_context3(NULL); |
| 280 | if (!sti->avctx) |
| 281 | goto fail; |
| 282 | |
| 283 | sti->info = av_mallocz(sizeof(*sti->info)); |
| 284 | if (!sti->info) |
| 285 | goto fail; |
| 286 | |
| 287 | #if FF_API_R_FRAME_RATE |
| 288 | sti->info->last_dts = AV_NOPTS_VALUE; |
| 289 | #endif |
| 290 | sti->info->fps_first_dts = AV_NOPTS_VALUE; |
| 291 | sti->info->fps_last_dts = AV_NOPTS_VALUE; |
| 292 | |
| 293 | /* default pts setting is MPEG-like */ |
| 294 | avpriv_set_pts_info(st, 33, 1, 90000); |
| 295 | /* we set the current DTS to 0 so that formats without any timestamps |
| 296 | * but durations get some timestamps, formats with some unknown |
| 297 | * timestamps have their first few packets buffered and the |
| 298 | * timestamps corrected before they are returned to the user */ |
| 299 | sti->cur_dts = RELATIVE_TS_BASE; |
| 300 | } else { |
| 301 | sti->cur_dts = AV_NOPTS_VALUE; |
| 302 | } |