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

Function initialize

libavformat/whip.c:449–499  ·  view source on GitHub ↗

* Initialize and check the options for the WebRTC muxer. */

Source from the content-addressed store, hash-verified

447 * Initialize and check the options for the WebRTC muxer.
448 */
449static av_cold int initialize(AVFormatContext *s)
450{
451 int ret, ideal_pkt_size = 532;
452 WHIPContext *whip = s->priv_data;
453 uint32_t seed;
454
455 whip->whip_starttime = av_gettime_relative();
456
457 ret = certificate_key_init(s);
458 if (ret < 0) {
459 av_log(whip, AV_LOG_ERROR, "Failed to init certificate and key\n");
460 return ret;
461 }
462
463 /* Initialize the random number generator. */
464 seed = av_get_random_seed();
465 av_lfg_init(&whip->rnd, seed);
466
467 /* 64 bit tie breaker for ICE-CONTROLLING (RFC 8445 16.1) */
468 ret = av_random_bytes((uint8_t *)&whip->ice_tie_breaker, sizeof(whip->ice_tie_breaker));
469 if (ret < 0) {
470 av_log(whip, AV_LOG_ERROR, "Couldn't generate random bytes for ICE tie breaker\n");
471 return ret;
472 }
473
474 whip->audio_first_seq = av_lfg_get(&whip->rnd) & 0x0fff;
475 whip->video_first_seq = whip->audio_first_seq + 1;
476
477 if (whip->pkt_size < ideal_pkt_size)
478 av_log(whip, AV_LOG_WARNING, "pkt_size=%d(<%d) is too small, may cause packet loss\n",
479 whip->pkt_size, ideal_pkt_size);
480
481 whip->hist = av_calloc(whip->hist_sz, sizeof(*whip->hist));
482 if (!whip->hist)
483 return AVERROR(ENOMEM);
484
485 whip->hist_pool = av_calloc(whip->hist_sz, whip->pkt_size - DTLS_SRTP_CHECKSUM_LEN);
486 if (!whip->hist_pool)
487 return AVERROR(ENOMEM);
488
489 for (int i = 0; i < whip->hist_sz; i++)
490 whip->hist[i].buf = whip->hist_pool + i * (whip->pkt_size - DTLS_SRTP_CHECKSUM_LEN);
491
492 if (whip->state < WHIP_STATE_INIT)
493 whip->state = WHIP_STATE_INIT;
494 whip->whip_init_time = av_gettime_relative();
495 av_log(whip, AV_LOG_VERBOSE, "Init state=%d, handshake_timeout=%dms, pkt_size=%d, seed=%d, elapsed=%.2fms\n",
496 whip->state, whip->handshake_timeout, whip->pkt_size, seed, ELAPSED(whip->whip_starttime, av_gettime_relative()));
497
498 return 0;
499}
500
501/**
502 * When duplicating a stream, the demuxer has already set the extradata, profile, and

Callers 1

whip_initFunction · 0.70

Calls 8

av_gettime_relativeFunction · 0.85
certificate_key_initFunction · 0.85
av_logFunction · 0.85
av_get_random_seedFunction · 0.85
av_lfg_initFunction · 0.85
av_random_bytesFunction · 0.85
av_lfg_getFunction · 0.85
av_callocFunction · 0.85

Tested by

no test coverage detected