summaryrefslogtreecommitdiffstats
path: root/audio/decode/ad_spdif.c
diff options
context:
space:
mode:
Diffstat (limited to 'audio/decode/ad_spdif.c')
-rw-r--r--audio/decode/ad_spdif.c45
1 files changed, 29 insertions, 16 deletions
diff --git a/audio/decode/ad_spdif.c b/audio/decode/ad_spdif.c
index 393af8a..98a53f3 100644
--- a/audio/decode/ad_spdif.c
+++ b/audio/decode/ad_spdif.c
@@ -37,6 +37,12 @@
#define OUTBUF_SIZE 65536
+#if LIBAVCODEC_VERSION_INT < AV_VERSION_INT(60, 26, 100)
+#define AV_PROFILE_UNKNOWN FF_PROFILE_UNKNOWN
+#define AV_PROFILE_DTS_HD_HRA FF_PROFILE_DTS_HD_HRA
+#define AV_PROFILE_DTS_HD_MA FF_PROFILE_DTS_HD_MA
+#endif
+
struct spdifContext {
struct mp_log *log;
enum AVCodecID codec_id;
@@ -53,7 +59,11 @@ struct spdifContext {
struct mp_decoder public;
};
+#if LIBAVCODEC_VERSION_MAJOR < 61
static int write_packet(void *p, uint8_t *buf, int buf_size)
+#else
+static int write_packet(void *p, const uint8_t *buf, int buf_size)
+#endif
{
struct spdifContext *ctx = p;
@@ -69,7 +79,7 @@ static int write_packet(void *p, uint8_t *buf, int buf_size)
}
// (called on both filter destruction _and_ if lavf fails to init)
-static void destroy(struct mp_filter *da)
+static void ad_spdif_destroy(struct mp_filter *da)
{
struct spdifContext *spdif_ctx = da->priv;
AVFormatContext *lavf_ctx = spdif_ctx->lavf_ctx;
@@ -79,7 +89,7 @@ static void destroy(struct mp_filter *da)
av_write_trailer(lavf_ctx);
if (lavf_ctx->pb)
av_freep(&lavf_ctx->pb->buffer);
- av_freep(&lavf_ctx->pb);
+ avio_context_free(&lavf_ctx->pb);
avformat_free_context(lavf_ctx);
spdif_ctx->lavf_ctx = NULL;
}
@@ -90,7 +100,7 @@ static void determine_codec_params(struct mp_filter *da, AVPacket *pkt,
int *out_profile, int *out_rate)
{
struct spdifContext *spdif_ctx = da->priv;
- int profile = FF_PROFILE_UNKNOWN;
+ int profile = AV_PROFILE_UNKNOWN;
AVCodecContext *ctx = NULL;
AVFrame *frame = NULL;
@@ -115,7 +125,7 @@ static void determine_codec_params(struct mp_filter *da, AVPacket *pkt,
av_parser_close(parser);
}
- if (profile != FF_PROFILE_UNKNOWN || spdif_ctx->codec_id != AV_CODEC_ID_DTS)
+ if (profile != AV_PROFILE_UNKNOWN || spdif_ctx->codec_id != AV_CODEC_ID_DTS)
return;
const AVCodec *codec = avcodec_find_decoder(spdif_ctx->codec_id);
@@ -145,7 +155,7 @@ done:
av_frame_free(&frame);
avcodec_free_context(&ctx);
- if (profile == FF_PROFILE_UNKNOWN)
+ if (profile == AV_PROFILE_UNKNOWN)
MP_WARN(da, "Failed to parse codec profile.\n");
}
@@ -155,7 +165,7 @@ static int init_filter(struct mp_filter *da)
AVPacket *pkt = spdif_ctx->avpkt;
- int profile = FF_PROFILE_UNKNOWN;
+ int profile = AV_PROFILE_UNKNOWN;
int c_rate = 0;
determine_codec_params(da, pkt, &profile, &c_rate);
MP_VERBOSE(da, "In: profile=%d samplerate=%d\n", profile, c_rate);
@@ -186,7 +196,8 @@ static int init_filter(struct mp_filter *da)
if (!stream)
goto fail;
- stream->codecpar->codec_id = spdif_ctx->codec_id;
+ stream->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
+ stream->codecpar->codec_id = spdif_ctx->codec_id;
AVDictionary *format_opts = NULL;
@@ -208,15 +219,15 @@ static int init_filter(struct mp_filter *da)
num_channels = 2;
break;
case AV_CODEC_ID_DTS: {
- bool is_hd = profile == FF_PROFILE_DTS_HD_HRA ||
- profile == FF_PROFILE_DTS_HD_MA ||
- profile == FF_PROFILE_UNKNOWN;
+ bool is_hd = profile == AV_PROFILE_DTS_HD_HRA ||
+ profile == AV_PROFILE_DTS_HD_MA ||
+ profile == AV_PROFILE_UNKNOWN;
// Apparently, DTS-HD over SPDIF is specified to be 7.1 (8 channels)
// for DTS-HD MA, and stereo (2 channels) for DTS-HD HRA. The bit
// streaming rate as well as the signaled channel count are defined
// based on this value.
- int dts_hd_spdif_channel_count = profile == FF_PROFILE_DTS_HD_HRA ?
+ int dts_hd_spdif_channel_count = profile == AV_PROFILE_DTS_HD_HRA ?
2 : 8;
if (spdif_ctx->use_dts_hd && is_hd) {
av_dict_set_int(&format_opts, "dtshd_rate",
@@ -226,7 +237,7 @@ static int init_filter(struct mp_filter *da)
num_channels = dts_hd_spdif_channel_count;
} else {
sample_format = AF_FORMAT_S_DTS;
- samplerate = 48000;
+ samplerate = c_rate > 44100 ? 48000 : 44100;
num_channels = 2;
}
break;
@@ -250,6 +261,8 @@ static int init_filter(struct mp_filter *da)
abort();
}
+ stream->codecpar->sample_rate = samplerate;
+
struct mp_chmap chmap;
mp_chmap_from_channels(&chmap, num_channels);
mp_aframe_set_chmap(spdif_ctx->fmt, &chmap);
@@ -270,12 +283,12 @@ static int init_filter(struct mp_filter *da)
return 0;
fail:
- destroy(da);
+ ad_spdif_destroy(da);
mp_filter_internal_mark_failed(da);
return -1;
}
-static void process(struct mp_filter *da)
+static void ad_spdif_process(struct mp_filter *da)
{
struct spdifContext *spdif_ctx = da->priv;
@@ -400,8 +413,8 @@ struct mp_decoder_list *select_spdif_codec(const char *codec, const char *pref)
static const struct mp_filter_info ad_spdif_filter = {
.name = "ad_spdif",
.priv_size = sizeof(struct spdifContext),
- .process = process,
- .destroy = destroy,
+ .process = ad_spdif_process,
+ .destroy = ad_spdif_destroy,
};
static struct mp_decoder *create(struct mp_filter *parent,