Skip to content

Commit b1aa643

Browse files
committed
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 f1863fb commit b1aa643

1 file changed

Lines changed: 28 additions & 9 deletions

File tree

audio/decode/ad_spdif.c

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,32 @@ static void determine_codec_params(struct mp_filter *da, AVPacket *pkt,
183183
done:
184184
av_frame_free(&frame);
185185
avcodec_free_context(&ctx);
186+
}
186187

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

191214
static int init_filter(struct mp_filter *da)
@@ -198,6 +221,8 @@ static int init_filter(struct mp_filter *da)
198221
int c_rate = 0;
199222
determine_codec_params(da, pkt, &profile, &c_rate);
200223
MP_VERBOSE(da, "In: profile=%d samplerate=%d\n", profile, c_rate);
224+
if (codec_params_warning_needed(spdif_ctx, profile, c_rate))
225+
MP_WARN(da, "Failed to parse codec parameters.\n");
201226

202227
AVFormatContext *lavf_ctx = avformat_alloc_context();
203228
if (!lavf_ctx)
@@ -248,19 +273,13 @@ static int init_filter(struct mp_filter *da)
248273
num_channels = 2;
249274
break;
250275
case AV_CODEC_ID_DTS: {
251-
bool is_hd = profile == AV_PROFILE_DTS_HD_HRA ||
252-
profile == AV_PROFILE_DTS_HD_MA ||
253-
profile == AV_PROFILE_DTS_HD_MA_X ||
254-
profile == AV_PROFILE_DTS_HD_MA_X_IMAX ||
255-
profile == AV_PROFILE_UNKNOWN;
256-
257276
// Apparently, DTS-HD over SPDIF is specified to be 7.1 (8 channels)
258277
// for DTS-HD MA, and stereo (2 channels) for DTS-HD HRA. The bit
259278
// streaming rate as well as the signaled channel count are defined
260279
// based on this value.
261280
int dts_hd_spdif_channel_count = profile == AV_PROFILE_DTS_HD_HRA ?
262281
2 : 8;
263-
if (spdif_ctx->use_dts_hd && is_hd) {
282+
if (spdif_ctx->use_dts_hd && dts_profile_maybe_hd(profile)) {
264283
av_dict_set_int(&format_opts, "dtshd_rate",
265284
dts_hd_spdif_channel_count * 96000, 0);
266285
sample_format = AF_FORMAT_S_DTSHD;

0 commit comments

Comments
 (0)