DefaultSink::DefaultSink(UsageEnvironment & env, MediaSubsession & subsession, char const * sink_url, char const * stream_id) : MediaSink(env), _subsession(subsession), _receive_buffer(RECEIVE_BUFFER_SIZE), _stream_id(stream_id), _writer(libc2rtsp::sink::SinkFactory().gen(sink_url)), _verbose(true), _sprop_parameter_sets(), _have_written_first_frame(false) { if (::strcmp(subsession.codecName(), "H264") == 0) { // For H.264 video stream, we use a special sink that adds 'start codes', // and (at the start) the SPS and PPS NAL units: _sprop_parameter_sets.emplace_back(std::string(subsession.fmtp_spropparametersets())); } else if (::strcmp(subsession.codecName(), "H265") == 0) { // For H.265 video stream, we use a special sink that adds 'start codes', // and (at the start) the VPS, SPS, and PPS NAL units: _sprop_parameter_sets.emplace_back(std::string(subsession.fmtp_spropvps())); // VPS _sprop_parameter_sets.emplace_back(std::string(subsession.fmtp_spropsps())); // SPS _sprop_parameter_sets.emplace_back(std::string(subsession.fmtp_sproppps())); // PPS } else { crLogE("DefaultSink::DefaultSink() Unsupported subsession: {}/{}", subsession.mediumName(), subsession.codecName()); throw std::bad_alloc(); } }