Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions src/hlsoutputstream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,28 @@ HLSOutputStream::add_stream (const AVCodec **codec, enum AVCodecID codec_id)
if ((*codec)->type != AVMEDIA_TYPE_AUDIO)
return Error ("codec type must be audio");

m_enc->sample_fmt = (*codec)->sample_fmts ? (*codec)->sample_fmts[0] : AV_SAMPLE_FMT_FLTP;
const int *supported_samplerates = NULL;
const AVSampleFormat *sample_fmts = NULL;
const AVChannelLayout *ch_layouts = NULL;
#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(61, 13, 100)
supported_samplerates = (*codec)->supported_samplerates;
sample_fmts = (*codec)->sample_fmts;
ch_layouts = (*codec)->ch_layouts;
#else
avcodec_get_supported_config(m_enc, *codec, AV_CODEC_CONFIG_SAMPLE_RATE, 0, (const void**) &supported_samplerates, NULL);
avcodec_get_supported_config(m_enc, *codec, AV_CODEC_CONFIG_SAMPLE_FORMAT, 0, (const void**) &sample_fmts, NULL);
avcodec_get_supported_config(m_enc, *codec, AV_CODEC_CONFIG_CHANNEL_LAYOUT, 0, (const void**) &ch_layouts, NULL);
#endif

m_enc->sample_fmt = sample_fmts ? sample_fmts[0] : AV_SAMPLE_FMT_FLTP;
m_enc->bit_rate = m_bit_rate;
m_enc->sample_rate = m_sample_rate;
if ((*codec)->supported_samplerates)
if (supported_samplerates)
{
bool match = false;
for (int i = 0; (*codec)->supported_samplerates[i]; i++)
for (int i = 0; supported_samplerates[i]; i++)
{
if ((*codec)->supported_samplerates[i] == m_sample_rate)
if (supported_samplerates[i] == m_sample_rate)
{
m_enc->sample_rate = m_sample_rate;
match = true;
Expand All @@ -120,15 +133,15 @@ HLSOutputStream::add_stream (const AVCodec **codec, enum AVCodecID codec_id)
return Error (string_printf ("bad channel layout '%s'", m_channel_layout.c_str()));
av_channel_layout_uninit (&m_enc->ch_layout);
av_channel_layout_copy (&m_enc->ch_layout, &channel_layout);
if ((*codec)->ch_layouts)
if (ch_layouts)
{
av_channel_layout_uninit (&m_enc->ch_layout);
av_channel_layout_copy (&m_enc->ch_layout, &(*codec)->ch_layouts[0]);
for (int i = 0; (*codec)->ch_layouts[i].nb_channels; i++)
av_channel_layout_copy (&m_enc->ch_layout, &ch_layouts[0]);
for (int i = 0; ch_layouts[i].nb_channels; i++)
{
if (av_channel_layout_compare (&(*codec)->ch_layouts[i], &channel_layout) == 0) {
if (av_channel_layout_compare (&ch_layouts[i], &channel_layout) == 0) {
av_channel_layout_uninit (&m_enc->ch_layout);
av_channel_layout_copy (&m_enc->ch_layout, &(*codec)->ch_layouts[i]);
av_channel_layout_copy (&m_enc->ch_layout, &ch_layouts[i]);
}
}
}
Expand Down