Commit e8475cd7 authored by Guillaume Roguez's avatar Guillaume Roguez

media: prevent incorrect down-casting

MediaEncoder::setOptions was contained a forced down-casting
from AccountCodecInfo to AccountAudioCodecInfo but the codec
may be also an Account7ideoCodecInfo.

Refs #77483

Change-Id: Ib5dc4b9834280e418163ed735f3a8d92f0d2a88f
parent 4d3c4439
......@@ -86,18 +86,20 @@ void MediaEncoder::setOptions(const MediaDescription& args)
av_dict_set(&options_, "payload_type", ring::to_string(args.payload_type).c_str(), 0);
av_dict_set(&options_, "bitrate", ring::to_string(args.codec->bitrate).c_str(), 0);
auto accountAudioCodec = std::static_pointer_cast<AccountAudioCodecInfo>(args.codec);
if (accountAudioCodec->audioformat.sample_rate)
av_dict_set(&options_, "sample_rate",
ring::to_string(accountAudioCodec->audioformat.sample_rate).c_str(), 0);
if (accountAudioCodec->audioformat.nb_channels)
av_dict_set(&options_, "channels",
ring::to_string(accountAudioCodec->audioformat.nb_channels).c_str(), 0);
if (accountAudioCodec->audioformat.sample_rate && accountAudioCodec->audioformat.nb_channels)
av_dict_set(&options_, "frame_size",
ring::to_string(static_cast<unsigned>(0.02 * accountAudioCodec->audioformat.sample_rate)).c_str(), 0);
if (args.codec->systemCodecInfo.mediaType == MEDIA_AUDIO) {
auto accountAudioCodec = std::static_pointer_cast<AccountAudioCodecInfo>(args.codec);
if (accountAudioCodec->audioformat.sample_rate)
av_dict_set(&options_, "sample_rate",
ring::to_string(accountAudioCodec->audioformat.sample_rate).c_str(), 0);
if (accountAudioCodec->audioformat.nb_channels)
av_dict_set(&options_, "channels",
ring::to_string(accountAudioCodec->audioformat.nb_channels).c_str(), 0);
if (accountAudioCodec->audioformat.sample_rate && accountAudioCodec->audioformat.nb_channels)
av_dict_set(&options_, "frame_size",
ring::to_string(static_cast<unsigned>(0.02 * accountAudioCodec->audioformat.sample_rate)).c_str(), 0);
}
if (not args.parameters.empty())
av_dict_set(&options_, "parameters", args.parameters.c_str(), 0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment