Skip to content

Commit 74356c0

Browse files
nathanlucaskasper93
authored andcommitted
ad_spdif: only warn for required codec parameters
determine_codec_params() warns when it cannot determine a codec profile. Some passthrough formats use fixed output parameters and do not require the probed profile or sample rate making the warning misleading. Warn only when a value used to configure the selected passthrough format is missing: the profile for DTS-HD, or the sample rate for core DTS and AC-3. Signed-off-by: Nathan Lucas <nlucasgit@gmail.com>
1 parent 1388a45 commit 74356c0

1 file changed

Lines changed: 29 additions & 9 deletions

File tree

audio/decode/ad_spdif.c

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,32 @@ static void determine_codec_params(struct mp_filter *da, AVPacket *pkt,
187187
done:
188188
av_frame_free(&frame);
189189
avcodec_free_context(&ctx);
190+
}
190191

191-
if (profile == AV_PROFILE_UNKNOWN)
192-
MP_WARN(da, "Failed to parse codec profile.\n");
192+
static bool dts_profile_maybe_hd(int profile)
193+
{
194+
return profile == AV_PROFILE_DTS_HD_HRA ||
195+
profile == AV_PROFILE_DTS_HD_MA ||
196+
profile == AV_PROFILE_DTS_HD_MA_X ||
197+
profile == AV_PROFILE_DTS_HD_MA_X_IMAX ||
198+
profile == AV_PROFILE_UNKNOWN;
199+
}
200+
201+
// Some codecs do not need every probed value for spdif muxer setup.
202+
static bool codec_params_warning_needed(struct spdifContext *spdif_ctx,
203+
int profile, int rate)
204+
{
205+
switch (spdif_ctx->codec_id) {
206+
case AV_CODEC_ID_DTS:
207+
if (spdif_ctx->use_dts_hd && dts_profile_maybe_hd(profile))
208+
return profile == AV_PROFILE_UNKNOWN;
209+
210+
return rate <= 0;
211+
case AV_CODEC_ID_AC3:
212+
return rate <= 0;
213+
default:
214+
return false;
215+
}
193216
}
194217

195218
static int init_filter(struct mp_filter *da)
@@ -205,6 +228,9 @@ static int init_filter(struct mp_filter *da)
205228
spdif_ctx->codec_params_probed = true;
206229
MP_VERBOSE(da, "In: profile=%d samplerate=%d\n",
207230
spdif_ctx->codec_profile, spdif_ctx->codec_rate);
231+
if (codec_params_warning_needed(spdif_ctx, spdif_ctx->codec_profile,
232+
spdif_ctx->codec_rate))
233+
MP_WARN(da, "Failed to parse codec parameters.\n");
208234
}
209235

210236
int profile = spdif_ctx->codec_profile;
@@ -259,19 +285,13 @@ static int init_filter(struct mp_filter *da)
259285
num_channels = 2;
260286
break;
261287
case AV_CODEC_ID_DTS: {
262-
bool is_hd = profile == AV_PROFILE_DTS_HD_HRA ||
263-
profile == AV_PROFILE_DTS_HD_MA ||
264-
profile == AV_PROFILE_DTS_HD_MA_X ||
265-
profile == AV_PROFILE_DTS_HD_MA_X_IMAX ||
266-
profile == AV_PROFILE_UNKNOWN;
267-
268288
// Apparently, DTS-HD over SPDIF is specified to be 7.1 (8 channels)
269289
// for DTS-HD MA, and stereo (2 channels) for DTS-HD HRA. The bit
270290
// streaming rate as well as the signaled channel count are defined
271291
// based on this value.
272292
int dts_hd_spdif_channel_count = profile == AV_PROFILE_DTS_HD_HRA ?
273293
2 : 8;
274-
if (spdif_ctx->use_dts_hd && is_hd) {
294+
if (spdif_ctx->use_dts_hd && dts_profile_maybe_hd(profile)) {
275295
av_dict_set_int(&format_opts, "dtshd_rate",
276296
dts_hd_spdif_channel_count * 96000, 0);
277297
sample_format = AF_FORMAT_S_DTSHD;

0 commit comments

Comments
 (0)