Opened 2 years ago

Closed 2 years ago

#5897 closed defect (fixed)

swresample. Incorrect work of swr_set_matrix() if the SwrContext was never initialized

Reported by: v0lt Owned by:
Priority: normal Component: swresample
Version: unspecified Keywords:
Cc: Blocked By:
Blocking: Reproduced by developer: no
Analyzed by developer: no


Summary of the bug:

Function swr_set_matrix() muted front channels when mixing from AV_CH_LAYOUT_6POINT1 in AV_CH_LAYOUT_STEREO if the SwrContext? was never initialized.

How to reproduce:

SwrContext* m_pSWRCxt = swr_alloc();

for (int i = 1; i <= 2; i++) {
	int ret = 0;


	av_opt_set_int(m_pSWRCxt, "in_sample_fmt", AV_SAMPLE_FMT_S16, 0);
	av_opt_set_int(m_pSWRCxt, "out_sample_fmt", AV_SAMPLE_FMT_FLT, 0);
	av_opt_set_int(m_pSWRCxt, "in_channel_layout", AV_CH_LAYOUT_6POINT1, 0);
	av_opt_set_int(m_pSWRCxt, "out_channel_layout", AV_CH_LAYOUT_STEREO, 0);
	av_opt_set_int(m_pSWRCxt, "in_sample_rate", 48000, 0);
	av_opt_set_int(m_pSWRCxt, "out_sample_rate", 48000, 0);

	const int in_ch  = av_popcount(AV_CH_LAYOUT_6POINT1);
	const int out_ch = av_popcount(AV_CH_LAYOUT_STEREO);
	double* m_matrix_dbl = (double*)av_mallocz(in_ch * out_ch * sizeof(*m_matrix_dbl));

	const double center_mix_level   = M_SQRT1_2;
	const double surround_mix_level = 1.0;
	const double lfe_mix_level      = 1.0;
	const double rematrix_maxval    = INT_MAX;
	const double rematrix_volume    = 0.0;
	ret = swr_build_matrix(
		m_in_layout, m_out_layout,
		center_mix_level, surround_mix_level, lfe_mix_level,
		rematrix_maxval, rematrix_volume,
		m_matrix_dbl, in_ch,

	ret = swr_set_matrix(m_pSWRCxt, m_matrix_dbl, in_ch);

	ret = swr_init(m_pSWRCxt);

	// working...
	// if i = 1 get the silence.
	// if i = 2 get the sound.


Attachments (1)

fix_swr_set_matrix.patch (1.3 KB) - added by v0lt 2 years ago.

Download all attachments as: .zip

Change History (8)

comment:1 Changed 2 years ago by cehoyos

  • Priority changed from important to normal

Is this a regression?

Changed 2 years ago by v0lt

comment:2 Changed 2 years ago by cehoyos

Please send your patch to the development mailing list, patches are ignored on this bug tracker.

comment:3 Changed 2 years ago by v0lt

I do not understand this.

comment:4 Changed 2 years ago by cehoyos

I believe you attached a patch here on the bug tracker that fixes the issue that you reported. (Is this correct?)
Unfortunately, patches are ignored on this bug tracker, so please send the patch to the development mailing list to have it reviewed:

comment:5 Changed 2 years ago by v0lt

Yes. Aleksoid1978 says that the patch solves the problem. I confirm the sound appears.

comment:6 Changed 2 years ago by cehoyos

Please ask Aleksoid1978 to send his patch to the development mailing list to get this ticket fixed.

comment:7 Changed 2 years ago by llogan

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.