Opened 8 years ago

Closed 8 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

Description

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;

	swr_close(m_pSWRCxt);

	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,
		AV_MATRIX_ENCODING_NONE, NULL);

	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.
}

swr_free(&m_pSWRCxt);
av_free(m_matrix_dbl);

Attachments (1)

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

Download all attachments as: .zip

Change History (8)

comment:1 by Carl Eugen Hoyos, 8 years ago

Priority: importantnormal

Is this a regression?

by v0lt, 8 years ago

Attachment: fix_swr_set_matrix.patch added

comment:2 by Carl Eugen Hoyos, 8 years ago

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

comment:3 by v0lt, 8 years ago

I do not understand this.

comment:4 by Carl Eugen Hoyos, 8 years ago

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: http://ffmpeg.org/mailman/listinfo/ffmpeg-devel

comment:5 by v0lt, 8 years ago

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

comment:6 by Carl Eugen Hoyos, 8 years ago

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

comment:7 by llogan, 8 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.