2011-10-12 17:23:08 +00:00
|
|
|
/*
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
* Copyright (C) 2012 Naoya OYAMA
|
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* This file is part of mpv.
|
|
|
|
*
|
2017-05-21 10:35:53 +00:00
|
|
|
* mpv is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2011-10-12 17:23:08 +00:00
|
|
|
*
|
2015-04-13 07:36:54 +00:00
|
|
|
* mpv is distributed in the hope that it will be useful,
|
2011-10-12 17:23:08 +00:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2017-05-21 10:35:53 +00:00
|
|
|
* GNU Lesser General Public License for more details.
|
2011-10-12 17:23:08 +00:00
|
|
|
*
|
2017-05-21 10:35:53 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with mpv. If not, see <http://www.gnu.org/licenses/>.
|
2011-10-12 17:23:08 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
audio: add support for using non-interleaved audio from decoders directly
Most libavcodec decoders output non-interleaved audio. Add direct
support for this, and remove the hack that repacked non-interleaved
audio back to packed audio.
Remove the minlen argument from the decoder callback. Instead of
forcing every decoder to have its own decode loop to fill the buffer
until minlen is reached, leave this to the caller. So if a decoder
doesn't return enough data, it's simply called again. (In future, I
even want to change it so that decoders don't read packets directly,
but instead the caller has to pass packets to the decoders. This fits
well with this change, because now the decoder callback typically
decodes at most one packet.)
ad_mpg123.c receives some heavy refactoring. The main problem is that
it wanted to handle format changes when there was no data in the decode
output buffer yet. This sounds reasonable, but actually it would write
data into a buffer prepared for old data, since the caller doesn't know
about the format change yet. (I.e. the best place for a format change
would be _after_ writing the last sample to the output buffer.) It's
possible that this code was not perfectly sane before this commit,
and perhaps lost one frame of data after a format change, but I didn't
confirm this. Trying to fix this, I ended up rewriting the decoding
and also the probing.
2013-11-12 21:27:44 +00:00
|
|
|
#include <assert.h>
|
2011-10-12 17:23:08 +00:00
|
|
|
|
|
|
|
#include <libavformat/avformat.h>
|
|
|
|
#include <libavcodec/avcodec.h>
|
|
|
|
#include <libavutil/opt.h>
|
|
|
|
|
2018-01-29 05:18:33 +00:00
|
|
|
#include "audio/aframe.h"
|
2024-06-08 21:17:53 +00:00
|
|
|
#include "audio/chmap_avchannel.h"
|
2018-01-29 05:18:33 +00:00
|
|
|
#include "audio/format.h"
|
2013-12-17 01:39:45 +00:00
|
|
|
#include "common/av_common.h"
|
2018-01-29 05:18:33 +00:00
|
|
|
#include "common/codecs.h"
|
|
|
|
#include "common/msg.h"
|
|
|
|
#include "demux/packet.h"
|
|
|
|
#include "demux/stheader.h"
|
|
|
|
#include "filters/f_decoder_wrapper.h"
|
|
|
|
#include "filters/filter_internal.h"
|
2013-12-17 01:02:25 +00:00
|
|
|
#include "options/options.h"
|
2011-10-12 17:23:08 +00:00
|
|
|
|
|
|
|
#define OUTBUF_SIZE 65536
|
2013-11-08 23:32:44 +00:00
|
|
|
|
2011-10-12 17:23:08 +00:00
|
|
|
struct spdifContext {
|
2013-12-21 17:23:59 +00:00
|
|
|
struct mp_log *log;
|
2024-05-20 14:33:21 +00:00
|
|
|
struct mp_codec_params *codec;
|
2015-05-19 19:34:30 +00:00
|
|
|
enum AVCodecID codec_id;
|
2011-10-12 17:23:08 +00:00
|
|
|
AVFormatContext *lavf_ctx;
|
ffmpeg: update to handle deprecation of `av_init_packet`
This has been a long standing annoyance - ffmpeg is removing
sizeof(AVPacket) from the API which means you cannot stack-allocate
AVPacket anymore. However, that is something we take advantage of
because we use short-lived AVPackets to bridge from native mpv packets
in our main decoding paths.
We don't think that switching these to `av_packet_alloc` is desirable,
given the cost of heap allocation, so this change takes a different
approach - allocating a single packet in the relevant context and
reusing it over and over.
That's fairly straight-forward, with the main caveat being that
re-initialising the packet is unintuitive. There is no function that
does exactly what we need (what `av_init_packet` did). The closest is
`av_packet_unref`, which additionally frees buffers and side-data.
However, we don't copy those things - we just assign them in from our
own packet, so we have to explicitly clear the pointers before calling
`av_packet_unref`. But at least we can make a wrapper function for
that.
The weirdest part of the change is the handling of the vtt subtitle
conversion. This requires two packets, so I had to pre-allocate two in
the context struct. That sounds excessive, but if allocating the
primary packet is too expensive, then allocating the secondary one for
vtt subtitles must also be too expensive.
This change is not conditional as heap allocated AVPackets were
available for years and years before the deprecation.
2022-11-29 19:15:16 +00:00
|
|
|
AVPacket *avpkt;
|
2011-10-12 17:23:08 +00:00
|
|
|
int out_buffer_len;
|
2014-07-21 17:29:37 +00:00
|
|
|
uint8_t out_buffer[OUTBUF_SIZE];
|
2013-11-08 23:32:44 +00:00
|
|
|
bool need_close;
|
2015-06-05 20:34:48 +00:00
|
|
|
bool use_dts_hd;
|
audio: introduce a new type to hold audio frames
This is pretty pointless, but I believe it allows us to claim that the
new code is not affected by the copyright of the old code. This is
needed, because the original mp_audio struct was written by someone who
has disagreed with LGPL relicensing (it was called af_data at the time,
and was defined in af.h).
The "GPL'ed" struct contents that surive are pretty trivial: just the
data pointer, and some metadata like the format, samplerate, etc. - but
at least in this case, any new code would be extremely similar anyway,
and I'm not really sure whether it's OK to claim different copyright. So
what we do is we just use AVFrame (which of course is LGPL with 100%
certainty), and add some accessors around it to adapt it to mpv
conventions.
Also, this gets rid of some annoying conventions of mp_audio, like the
struct fields that require using an accessor to write to them anyway.
For the most part, this change is only dumb replacements of mp_audio
related functions and fields. One minor actual change is that you can't
allocate the new type on the stack anymore.
Some code still uses mp_audio. All audio filter code will be deleted, so
it makes no sense to convert this code. (Audio filters which are LGPL
and which we keep will have to be ported to a new filter infrastructure
anyway.) player/audio.c uses it because it interacts with the old filter
code. push.c has some complex use of mp_audio and mp_audio_buffer, but
this and pull.c will most likely be rewritten to do something else.
2017-08-16 19:00:20 +00:00
|
|
|
struct mp_aframe *fmt;
|
|
|
|
int sstride;
|
|
|
|
struct mp_aframe_pool *pool;
|
2018-01-29 05:18:33 +00:00
|
|
|
|
|
|
|
struct mp_decoder public;
|
2011-10-12 17:23:08 +00:00
|
|
|
};
|
|
|
|
|
2024-06-22 12:58:07 +00:00
|
|
|
#if LIBAVFORMAT_VERSION_MAJOR < 61
|
2011-10-12 17:23:08 +00:00
|
|
|
static int write_packet(void *p, uint8_t *buf, int buf_size)
|
2024-03-07 19:42:25 +00:00
|
|
|
#else
|
|
|
|
static int write_packet(void *p, const uint8_t *buf, int buf_size)
|
|
|
|
#endif
|
2011-10-12 17:23:08 +00:00
|
|
|
{
|
|
|
|
struct spdifContext *ctx = p;
|
|
|
|
|
2014-07-21 17:29:37 +00:00
|
|
|
int buffer_left = OUTBUF_SIZE - ctx->out_buffer_len;
|
2013-11-08 23:32:44 +00:00
|
|
|
if (buf_size > buffer_left) {
|
2013-12-21 17:23:59 +00:00
|
|
|
MP_ERR(ctx, "spdif packet too large.\n");
|
2013-11-08 23:32:44 +00:00
|
|
|
buf_size = buffer_left;
|
|
|
|
}
|
|
|
|
|
|
|
|
memcpy(&ctx->out_buffer[ctx->out_buffer_len], buf, buf_size);
|
|
|
|
ctx->out_buffer_len += buf_size;
|
|
|
|
return buf_size;
|
2011-10-12 17:23:08 +00:00
|
|
|
}
|
|
|
|
|
2018-01-29 05:18:33 +00:00
|
|
|
// (called on both filter destruction _and_ if lavf fails to init)
|
2024-04-10 05:47:05 +00:00
|
|
|
static void ad_spdif_destroy(struct mp_filter *da)
|
2011-10-12 17:23:08 +00:00
|
|
|
{
|
2013-11-23 20:22:17 +00:00
|
|
|
struct spdifContext *spdif_ctx = da->priv;
|
2013-11-08 23:32:44 +00:00
|
|
|
AVFormatContext *lavf_ctx = spdif_ctx->lavf_ctx;
|
|
|
|
|
|
|
|
if (lavf_ctx) {
|
|
|
|
if (spdif_ctx->need_close)
|
|
|
|
av_write_trailer(lavf_ctx);
|
|
|
|
if (lavf_ctx->pb)
|
|
|
|
av_freep(&lavf_ctx->pb->buffer);
|
2024-04-03 19:43:37 +00:00
|
|
|
avio_context_free(&lavf_ctx->pb);
|
2013-11-08 23:32:44 +00:00
|
|
|
avformat_free_context(lavf_ctx);
|
2016-07-04 00:41:45 +00:00
|
|
|
spdif_ctx->lavf_ctx = NULL;
|
2013-11-08 23:32:44 +00:00
|
|
|
}
|
ffmpeg: update to handle deprecation of `av_init_packet`
This has been a long standing annoyance - ffmpeg is removing
sizeof(AVPacket) from the API which means you cannot stack-allocate
AVPacket anymore. However, that is something we take advantage of
because we use short-lived AVPackets to bridge from native mpv packets
in our main decoding paths.
We don't think that switching these to `av_packet_alloc` is desirable,
given the cost of heap allocation, so this change takes a different
approach - allocating a single packet in the relevant context and
reusing it over and over.
That's fairly straight-forward, with the main caveat being that
re-initialising the packet is unintuitive. There is no function that
does exactly what we need (what `av_init_packet` did). The closest is
`av_packet_unref`, which additionally frees buffers and side-data.
However, we don't copy those things - we just assign them in from our
own packet, so we have to explicitly clear the pointers before calling
`av_packet_unref`. But at least we can make a wrapper function for
that.
The weirdest part of the change is the handling of the vtt subtitle
conversion. This requires two packets, so I had to pre-allocate two in
the context struct. That sounds excessive, but if allocating the
primary packet is too expensive, then allocating the secondary one for
vtt subtitles must also be too expensive.
This change is not conditional as heap allocated AVPackets were
available for years and years before the deprecation.
2022-11-29 19:15:16 +00:00
|
|
|
mp_free_av_packet(&spdif_ctx->avpkt);
|
2011-10-12 17:23:08 +00:00
|
|
|
}
|
|
|
|
|
2018-01-29 05:18:33 +00:00
|
|
|
static void determine_codec_params(struct mp_filter *da, AVPacket *pkt,
|
2017-01-18 09:19:29 +00:00
|
|
|
int *out_profile, int *out_rate)
|
2015-05-19 19:34:30 +00:00
|
|
|
{
|
|
|
|
struct spdifContext *spdif_ctx = da->priv;
|
2024-03-04 17:48:20 +00:00
|
|
|
int profile = AV_PROFILE_UNKNOWN;
|
2015-05-19 19:35:43 +00:00
|
|
|
AVCodecContext *ctx = NULL;
|
|
|
|
AVFrame *frame = NULL;
|
|
|
|
|
2017-01-18 09:19:29 +00:00
|
|
|
AVCodecParserContext *parser = av_parser_init(spdif_ctx->codec_id);
|
|
|
|
if (parser) {
|
|
|
|
// Don't make it wait for the next frame.
|
|
|
|
parser->flags |= PARSER_FLAG_COMPLETE_FRAMES;
|
|
|
|
|
|
|
|
ctx = avcodec_alloc_context3(NULL);
|
2017-07-10 14:40:52 +00:00
|
|
|
if (!ctx) {
|
|
|
|
av_parser_close(parser);
|
|
|
|
goto done;
|
|
|
|
}
|
2017-01-18 09:19:29 +00:00
|
|
|
|
|
|
|
uint8_t *d = NULL;
|
|
|
|
int s = 0;
|
2024-05-20 18:44:33 +00:00
|
|
|
if (av_parser_parse2(parser, ctx, &d, &s, pkt->data, pkt->size, 0, 0, 0) > 0) {
|
|
|
|
*out_profile = profile = ctx->profile;
|
|
|
|
*out_rate = ctx->sample_rate;
|
|
|
|
spdif_ctx->codec->codec_profile = avcodec_profile_name(spdif_ctx->codec_id, profile);
|
|
|
|
}
|
2017-01-18 09:19:29 +00:00
|
|
|
|
2017-07-10 14:40:52 +00:00
|
|
|
avcodec_free_context(&ctx);
|
2017-01-18 09:19:29 +00:00
|
|
|
av_parser_close(parser);
|
|
|
|
}
|
|
|
|
|
2024-06-08 21:17:53 +00:00
|
|
|
if (profile != AV_PROFILE_UNKNOWN)
|
2017-01-18 09:19:29 +00:00
|
|
|
return;
|
|
|
|
|
2021-05-01 19:53:56 +00:00
|
|
|
const AVCodec *codec = avcodec_find_decoder(spdif_ctx->codec_id);
|
2015-05-19 19:35:43 +00:00
|
|
|
if (!codec)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
frame = av_frame_alloc();
|
|
|
|
if (!frame)
|
|
|
|
goto done;
|
|
|
|
|
|
|
|
ctx = avcodec_alloc_context3(codec);
|
|
|
|
if (!ctx)
|
|
|
|
goto done;
|
|
|
|
|
2017-07-16 10:51:48 +00:00
|
|
|
if (avcodec_open2(ctx, codec, NULL) < 0)
|
2015-05-19 19:35:43 +00:00
|
|
|
goto done;
|
|
|
|
|
2016-04-20 17:37:45 +00:00
|
|
|
if (avcodec_send_packet(ctx, pkt) < 0)
|
|
|
|
goto done;
|
|
|
|
if (avcodec_receive_frame(ctx, frame) < 0)
|
|
|
|
goto done;
|
2015-05-19 19:35:43 +00:00
|
|
|
|
2017-01-18 09:19:29 +00:00
|
|
|
*out_profile = profile = ctx->profile;
|
|
|
|
*out_rate = ctx->sample_rate;
|
2015-05-19 19:35:43 +00:00
|
|
|
|
2024-05-20 14:33:21 +00:00
|
|
|
struct mp_codec_params *c = spdif_ctx->codec;
|
|
|
|
c->codec_profile = av_get_profile_name(ctx->codec, ctx->profile);
|
|
|
|
if (!c->codec_profile)
|
|
|
|
c->codec_profile = avcodec_profile_name(ctx->codec_id, ctx->profile);
|
|
|
|
c->codec = ctx->codec_descriptor->name;
|
|
|
|
c->codec_desc = ctx->codec_descriptor->long_name;
|
2024-06-08 21:17:53 +00:00
|
|
|
mp_chmap_from_av_layout(&c->channels, &ctx->ch_layout);
|
2024-05-20 14:33:21 +00:00
|
|
|
|
2015-05-19 19:35:43 +00:00
|
|
|
done:
|
|
|
|
av_frame_free(&frame);
|
|
|
|
avcodec_free_context(&ctx);
|
|
|
|
|
2024-03-04 17:48:20 +00:00
|
|
|
if (profile == AV_PROFILE_UNKNOWN)
|
2015-05-19 19:35:43 +00:00
|
|
|
MP_WARN(da, "Failed to parse codec profile.\n");
|
|
|
|
}
|
|
|
|
|
2023-07-27 20:33:28 +00:00
|
|
|
static int init_filter(struct mp_filter *da)
|
2015-05-19 19:35:43 +00:00
|
|
|
{
|
|
|
|
struct spdifContext *spdif_ctx = da->priv;
|
|
|
|
|
2023-08-07 21:08:32 +00:00
|
|
|
AVPacket *pkt = spdif_ctx->avpkt;
|
2023-07-27 20:33:28 +00:00
|
|
|
|
2024-03-04 17:48:20 +00:00
|
|
|
int profile = AV_PROFILE_UNKNOWN;
|
2017-01-18 09:19:29 +00:00
|
|
|
int c_rate = 0;
|
|
|
|
determine_codec_params(da, pkt, &profile, &c_rate);
|
|
|
|
MP_VERBOSE(da, "In: profile=%d samplerate=%d\n", profile, c_rate);
|
2015-05-19 19:34:30 +00:00
|
|
|
|
2013-11-09 23:52:55 +00:00
|
|
|
AVFormatContext *lavf_ctx = avformat_alloc_context();
|
|
|
|
if (!lavf_ctx)
|
|
|
|
goto fail;
|
|
|
|
|
2015-05-19 19:34:30 +00:00
|
|
|
spdif_ctx->lavf_ctx = lavf_ctx;
|
|
|
|
|
2013-11-09 23:52:55 +00:00
|
|
|
lavf_ctx->oformat = av_guess_format("spdif", NULL, NULL);
|
|
|
|
if (!lavf_ctx->oformat)
|
2011-10-12 17:23:08 +00:00
|
|
|
goto fail;
|
|
|
|
|
2013-11-08 23:32:44 +00:00
|
|
|
void *buffer = av_mallocz(OUTBUF_SIZE);
|
2024-03-20 02:23:23 +00:00
|
|
|
MP_HANDLE_OOM(buffer);
|
2013-11-08 23:32:44 +00:00
|
|
|
lavf_ctx->pb = avio_alloc_context(buffer, OUTBUF_SIZE, 1, spdif_ctx, NULL,
|
|
|
|
write_packet, NULL);
|
|
|
|
if (!lavf_ctx->pb) {
|
|
|
|
av_free(buffer);
|
2011-10-12 17:23:08 +00:00
|
|
|
goto fail;
|
2013-11-08 23:32:44 +00:00
|
|
|
}
|
|
|
|
|
Remove remains of Libav compatibility
Libav seems rather dead: no release for 2 years, no new git commits in
master for almost a year (with one exception ~6 months ago). From what I
can tell, some developers resigned themselves to the horrifying idea to
post patches to ffmpeg-devel instead, while the rest of the developers
went on to greener pastures.
Libav was a better project than FFmpeg. Unfortunately, FFmpeg won,
because it managed to keep the name and website. Libav was pushed more
and more into obscurity: while there was initially a big push for Libav,
FFmpeg just remained "in place" and visible for most people. FFmpeg was
slowly draining all manpower and energy from Libav. A big part of this
was that FFmpeg stole code from Libav (regular merges of the entire
Libav git tree), making it some sort of Frankenstein mirror of Libav,
think decaying zombie with additional legs ("features") nailed to it.
"Stealing" surely is the wrong word; I'm just aping the language that
some of the FFmpeg members used to use. All that is in the past now, I'm
probably the only person left who is annoyed by this, and with this
commit I'm putting this decade long problem finally to an end. I just
thought I'd express my annoyance about this fucking shitshow one last
time.
The most intrusive change in this commit is the resample filter, which
originally used libavresample. Since the FFmpeg developer refused to
enable libavresample by default for drama reasons, and the API was
slightly different, so the filter used some big preprocessor mess to
make it compatible to libswresample. All that falls away now. The
simplification to the build system is also significant.
2020-02-16 14:14:55 +00:00
|
|
|
// Request minimal buffering
|
2013-11-08 23:32:44 +00:00
|
|
|
lavf_ctx->pb->direct = 1;
|
|
|
|
|
|
|
|
AVStream *stream = avformat_new_stream(lavf_ctx, 0);
|
2011-10-12 17:23:08 +00:00
|
|
|
if (!stream)
|
|
|
|
goto fail;
|
|
|
|
|
2024-04-02 15:58:48 +00:00
|
|
|
stream->codecpar->codec_type = AVMEDIA_TYPE_AUDIO;
|
|
|
|
stream->codecpar->codec_id = spdif_ctx->codec_id;
|
2013-11-08 23:32:44 +00:00
|
|
|
|
|
|
|
AVDictionary *format_opts = NULL;
|
2011-10-12 17:23:08 +00:00
|
|
|
|
audio: introduce a new type to hold audio frames
This is pretty pointless, but I believe it allows us to claim that the
new code is not affected by the copyright of the old code. This is
needed, because the original mp_audio struct was written by someone who
has disagreed with LGPL relicensing (it was called af_data at the time,
and was defined in af.h).
The "GPL'ed" struct contents that surive are pretty trivial: just the
data pointer, and some metadata like the format, samplerate, etc. - but
at least in this case, any new code would be extremely similar anyway,
and I'm not really sure whether it's OK to claim different copyright. So
what we do is we just use AVFrame (which of course is LGPL with 100%
certainty), and add some accessors around it to adapt it to mpv
conventions.
Also, this gets rid of some annoying conventions of mp_audio, like the
struct fields that require using an accessor to write to them anyway.
For the most part, this change is only dumb replacements of mp_audio
related functions and fields. One minor actual change is that you can't
allocate the new type on the stack anymore.
Some code still uses mp_audio. All audio filter code will be deleted, so
it makes no sense to convert this code. (Audio filters which are LGPL
and which we keep will have to be ported to a new filter infrastructure
anyway.) player/audio.c uses it because it interacts with the old filter
code. push.c has some complex use of mp_audio and mp_audio_buffer, but
this and pull.c will most likely be rewritten to do something else.
2017-08-16 19:00:20 +00:00
|
|
|
spdif_ctx->fmt = mp_aframe_create();
|
|
|
|
talloc_steal(spdif_ctx, spdif_ctx->fmt);
|
|
|
|
|
2013-04-06 20:43:12 +00:00
|
|
|
int num_channels = 0;
|
2013-11-23 20:25:05 +00:00
|
|
|
int sample_format = 0;
|
|
|
|
int samplerate = 0;
|
2015-05-19 19:34:30 +00:00
|
|
|
switch (spdif_ctx->codec_id) {
|
2013-03-09 07:49:56 +00:00
|
|
|
case AV_CODEC_ID_AAC:
|
audio: cleanup spdif format definitions
Before this commit, there was AF_FORMAT_AC3 (the original spdif format,
used for AC3 and DTS core), and AF_FORMAT_IEC61937 (used for AC3, DTS
and DTS-HD), which was handled as some sort of superset for
AF_FORMAT_AC3. There also was AF_FORMAT_MPEG2, which used
IEC61937-framing, but still was handled as something "separate".
Technically, all of them are pretty similar, but may use different
bitrates. Since digital passthrough pretends to be PCM (just with
special headers that wrap digital packets), this is easily detectable by
the higher samplerate or higher number of channels, so I don't know why
you'd need a separate "class" of sample formats (AF_FORMAT_AC3 vs.
AF_FORMAT_IEC61937) to distinguish them. Actually, this whole thing is
just a mess.
Simplify this by handling all these formats the same way.
AF_FORMAT_IS_IEC61937() now returns 1 for all spdif formats (even MP3).
All AOs just accept all spdif formats now - whether that works or not is
not really clear (seems inconsistent due to earlier attempts to make
DTS-HD work). But on the other hand, enabling spdif requires manual user
interaction, so it doesn't matter much if initialization fails in
slightly less graceful ways if it can't work at all.
At a later point, we will support passthrough with ao_pulse. It seems
the PulseAudio API wants to know the codec type (or maybe not - feeding
it DTS while telling it it's AC3 works), add separate formats for each
codecs. While this reminds of the earlier chaos, it's stricter, and most
code just uses AF_FORMAT_IS_IEC61937().
Also, modify AF_FORMAT_TYPE_MASK (renamed from AF_FORMAT_POINT_MASK) to
include special formats, so that it always describes the fundamental
sample format type. This also ensures valid AF formats are never 0 (this
was probably broken in one of the earlier commits from today).
2014-09-23 20:44:54 +00:00
|
|
|
sample_format = AF_FORMAT_S_AAC;
|
2013-11-23 20:25:05 +00:00
|
|
|
samplerate = 48000;
|
2013-04-06 20:43:12 +00:00
|
|
|
num_channels = 2;
|
2011-10-12 17:23:08 +00:00
|
|
|
break;
|
2013-03-09 07:49:56 +00:00
|
|
|
case AV_CODEC_ID_AC3:
|
audio: cleanup spdif format definitions
Before this commit, there was AF_FORMAT_AC3 (the original spdif format,
used for AC3 and DTS core), and AF_FORMAT_IEC61937 (used for AC3, DTS
and DTS-HD), which was handled as some sort of superset for
AF_FORMAT_AC3. There also was AF_FORMAT_MPEG2, which used
IEC61937-framing, but still was handled as something "separate".
Technically, all of them are pretty similar, but may use different
bitrates. Since digital passthrough pretends to be PCM (just with
special headers that wrap digital packets), this is easily detectable by
the higher samplerate or higher number of channels, so I don't know why
you'd need a separate "class" of sample formats (AF_FORMAT_AC3 vs.
AF_FORMAT_IEC61937) to distinguish them. Actually, this whole thing is
just a mess.
Simplify this by handling all these formats the same way.
AF_FORMAT_IS_IEC61937() now returns 1 for all spdif formats (even MP3).
All AOs just accept all spdif formats now - whether that works or not is
not really clear (seems inconsistent due to earlier attempts to make
DTS-HD work). But on the other hand, enabling spdif requires manual user
interaction, so it doesn't matter much if initialization fails in
slightly less graceful ways if it can't work at all.
At a later point, we will support passthrough with ao_pulse. It seems
the PulseAudio API wants to know the codec type (or maybe not - feeding
it DTS while telling it it's AC3 works), add separate formats for each
codecs. While this reminds of the earlier chaos, it's stricter, and most
code just uses AF_FORMAT_IS_IEC61937().
Also, modify AF_FORMAT_TYPE_MASK (renamed from AF_FORMAT_POINT_MASK) to
include special formats, so that it always describes the fundamental
sample format type. This also ensures valid AF formats are never 0 (this
was probably broken in one of the earlier commits from today).
2014-09-23 20:44:54 +00:00
|
|
|
sample_format = AF_FORMAT_S_AC3;
|
2017-01-18 09:19:29 +00:00
|
|
|
samplerate = c_rate > 0 ? c_rate : 48000;
|
2013-04-06 20:43:12 +00:00
|
|
|
num_channels = 2;
|
2011-10-12 17:23:08 +00:00
|
|
|
break;
|
2015-05-19 19:35:43 +00:00
|
|
|
case AV_CODEC_ID_DTS: {
|
2024-03-04 17:48:20 +00:00
|
|
|
bool is_hd = profile == AV_PROFILE_DTS_HD_HRA ||
|
|
|
|
profile == AV_PROFILE_DTS_HD_MA ||
|
2024-07-31 23:10:47 +00:00
|
|
|
profile == AV_PROFILE_DTS_HD_MA_X ||
|
|
|
|
profile == AV_PROFILE_DTS_HD_MA_X_IMAX ||
|
2024-03-04 17:48:20 +00:00
|
|
|
profile == AV_PROFILE_UNKNOWN;
|
2018-10-29 23:36:38 +00:00
|
|
|
|
|
|
|
// 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.
|
2024-03-10 19:51:36 +00:00
|
|
|
int dts_hd_spdif_channel_count = profile == AV_PROFILE_DTS_HD_HRA ?
|
2018-10-29 23:36:38 +00:00
|
|
|
2 : 8;
|
2015-06-05 20:34:48 +00:00
|
|
|
if (spdif_ctx->use_dts_hd && is_hd) {
|
2018-10-29 23:36:38 +00:00
|
|
|
av_dict_set_int(&format_opts, "dtshd_rate",
|
|
|
|
dts_hd_spdif_channel_count * 96000, 0);
|
2015-05-19 19:34:30 +00:00
|
|
|
sample_format = AF_FORMAT_S_DTSHD;
|
|
|
|
samplerate = 192000;
|
2018-10-29 23:36:38 +00:00
|
|
|
num_channels = dts_hd_spdif_channel_count;
|
2013-03-03 17:48:20 +00:00
|
|
|
} else {
|
2015-05-19 19:34:30 +00:00
|
|
|
sample_format = AF_FORMAT_S_DTS;
|
2024-01-23 12:23:42 +00:00
|
|
|
samplerate = c_rate > 44100 ? 48000 : 44100;
|
2015-05-19 19:34:30 +00:00
|
|
|
num_channels = 2;
|
2013-03-03 17:48:20 +00:00
|
|
|
}
|
2011-10-12 17:23:08 +00:00
|
|
|
break;
|
2015-05-19 19:35:43 +00:00
|
|
|
}
|
2013-03-09 07:49:56 +00:00
|
|
|
case AV_CODEC_ID_EAC3:
|
audio: cleanup spdif format definitions
Before this commit, there was AF_FORMAT_AC3 (the original spdif format,
used for AC3 and DTS core), and AF_FORMAT_IEC61937 (used for AC3, DTS
and DTS-HD), which was handled as some sort of superset for
AF_FORMAT_AC3. There also was AF_FORMAT_MPEG2, which used
IEC61937-framing, but still was handled as something "separate".
Technically, all of them are pretty similar, but may use different
bitrates. Since digital passthrough pretends to be PCM (just with
special headers that wrap digital packets), this is easily detectable by
the higher samplerate or higher number of channels, so I don't know why
you'd need a separate "class" of sample formats (AF_FORMAT_AC3 vs.
AF_FORMAT_IEC61937) to distinguish them. Actually, this whole thing is
just a mess.
Simplify this by handling all these formats the same way.
AF_FORMAT_IS_IEC61937() now returns 1 for all spdif formats (even MP3).
All AOs just accept all spdif formats now - whether that works or not is
not really clear (seems inconsistent due to earlier attempts to make
DTS-HD work). But on the other hand, enabling spdif requires manual user
interaction, so it doesn't matter much if initialization fails in
slightly less graceful ways if it can't work at all.
At a later point, we will support passthrough with ao_pulse. It seems
the PulseAudio API wants to know the codec type (or maybe not - feeding
it DTS while telling it it's AC3 works), add separate formats for each
codecs. While this reminds of the earlier chaos, it's stricter, and most
code just uses AF_FORMAT_IS_IEC61937().
Also, modify AF_FORMAT_TYPE_MASK (renamed from AF_FORMAT_POINT_MASK) to
include special formats, so that it always describes the fundamental
sample format type. This also ensures valid AF formats are never 0 (this
was probably broken in one of the earlier commits from today).
2014-09-23 20:44:54 +00:00
|
|
|
sample_format = AF_FORMAT_S_EAC3;
|
2013-11-23 20:25:05 +00:00
|
|
|
samplerate = 192000;
|
2013-04-06 20:43:12 +00:00
|
|
|
num_channels = 2;
|
2011-10-12 17:23:08 +00:00
|
|
|
break;
|
2013-03-09 07:49:56 +00:00
|
|
|
case AV_CODEC_ID_MP3:
|
audio: cleanup spdif format definitions
Before this commit, there was AF_FORMAT_AC3 (the original spdif format,
used for AC3 and DTS core), and AF_FORMAT_IEC61937 (used for AC3, DTS
and DTS-HD), which was handled as some sort of superset for
AF_FORMAT_AC3. There also was AF_FORMAT_MPEG2, which used
IEC61937-framing, but still was handled as something "separate".
Technically, all of them are pretty similar, but may use different
bitrates. Since digital passthrough pretends to be PCM (just with
special headers that wrap digital packets), this is easily detectable by
the higher samplerate or higher number of channels, so I don't know why
you'd need a separate "class" of sample formats (AF_FORMAT_AC3 vs.
AF_FORMAT_IEC61937) to distinguish them. Actually, this whole thing is
just a mess.
Simplify this by handling all these formats the same way.
AF_FORMAT_IS_IEC61937() now returns 1 for all spdif formats (even MP3).
All AOs just accept all spdif formats now - whether that works or not is
not really clear (seems inconsistent due to earlier attempts to make
DTS-HD work). But on the other hand, enabling spdif requires manual user
interaction, so it doesn't matter much if initialization fails in
slightly less graceful ways if it can't work at all.
At a later point, we will support passthrough with ao_pulse. It seems
the PulseAudio API wants to know the codec type (or maybe not - feeding
it DTS while telling it it's AC3 works), add separate formats for each
codecs. While this reminds of the earlier chaos, it's stricter, and most
code just uses AF_FORMAT_IS_IEC61937().
Also, modify AF_FORMAT_TYPE_MASK (renamed from AF_FORMAT_POINT_MASK) to
include special formats, so that it always describes the fundamental
sample format type. This also ensures valid AF formats are never 0 (this
was probably broken in one of the earlier commits from today).
2014-09-23 20:44:54 +00:00
|
|
|
sample_format = AF_FORMAT_S_MP3;
|
2013-11-23 20:25:05 +00:00
|
|
|
samplerate = 48000;
|
2013-04-06 20:43:12 +00:00
|
|
|
num_channels = 2;
|
2011-10-12 17:23:08 +00:00
|
|
|
break;
|
2013-03-09 07:49:56 +00:00
|
|
|
case AV_CODEC_ID_TRUEHD:
|
audio: cleanup spdif format definitions
Before this commit, there was AF_FORMAT_AC3 (the original spdif format,
used for AC3 and DTS core), and AF_FORMAT_IEC61937 (used for AC3, DTS
and DTS-HD), which was handled as some sort of superset for
AF_FORMAT_AC3. There also was AF_FORMAT_MPEG2, which used
IEC61937-framing, but still was handled as something "separate".
Technically, all of them are pretty similar, but may use different
bitrates. Since digital passthrough pretends to be PCM (just with
special headers that wrap digital packets), this is easily detectable by
the higher samplerate or higher number of channels, so I don't know why
you'd need a separate "class" of sample formats (AF_FORMAT_AC3 vs.
AF_FORMAT_IEC61937) to distinguish them. Actually, this whole thing is
just a mess.
Simplify this by handling all these formats the same way.
AF_FORMAT_IS_IEC61937() now returns 1 for all spdif formats (even MP3).
All AOs just accept all spdif formats now - whether that works or not is
not really clear (seems inconsistent due to earlier attempts to make
DTS-HD work). But on the other hand, enabling spdif requires manual user
interaction, so it doesn't matter much if initialization fails in
slightly less graceful ways if it can't work at all.
At a later point, we will support passthrough with ao_pulse. It seems
the PulseAudio API wants to know the codec type (or maybe not - feeding
it DTS while telling it it's AC3 works), add separate formats for each
codecs. While this reminds of the earlier chaos, it's stricter, and most
code just uses AF_FORMAT_IS_IEC61937().
Also, modify AF_FORMAT_TYPE_MASK (renamed from AF_FORMAT_POINT_MASK) to
include special formats, so that it always describes the fundamental
sample format type. This also ensures valid AF formats are never 0 (this
was probably broken in one of the earlier commits from today).
2014-09-23 20:44:54 +00:00
|
|
|
sample_format = AF_FORMAT_S_TRUEHD;
|
2013-11-23 20:25:05 +00:00
|
|
|
samplerate = 192000;
|
2013-04-06 20:43:12 +00:00
|
|
|
num_channels = 8;
|
2011-10-12 17:23:08 +00:00
|
|
|
break;
|
|
|
|
default:
|
2013-11-08 23:32:44 +00:00
|
|
|
abort();
|
2011-10-12 17:23:08 +00:00
|
|
|
}
|
audio: introduce a new type to hold audio frames
This is pretty pointless, but I believe it allows us to claim that the
new code is not affected by the copyright of the old code. This is
needed, because the original mp_audio struct was written by someone who
has disagreed with LGPL relicensing (it was called af_data at the time,
and was defined in af.h).
The "GPL'ed" struct contents that surive are pretty trivial: just the
data pointer, and some metadata like the format, samplerate, etc. - but
at least in this case, any new code would be extremely similar anyway,
and I'm not really sure whether it's OK to claim different copyright. So
what we do is we just use AVFrame (which of course is LGPL with 100%
certainty), and add some accessors around it to adapt it to mpv
conventions.
Also, this gets rid of some annoying conventions of mp_audio, like the
struct fields that require using an accessor to write to them anyway.
For the most part, this change is only dumb replacements of mp_audio
related functions and fields. One minor actual change is that you can't
allocate the new type on the stack anymore.
Some code still uses mp_audio. All audio filter code will be deleted, so
it makes no sense to convert this code. (Audio filters which are LGPL
and which we keep will have to be ported to a new filter infrastructure
anyway.) player/audio.c uses it because it interacts with the old filter
code. push.c has some complex use of mp_audio and mp_audio_buffer, but
this and pull.c will most likely be rewritten to do something else.
2017-08-16 19:00:20 +00:00
|
|
|
|
2024-04-02 15:58:48 +00:00
|
|
|
stream->codecpar->sample_rate = samplerate;
|
|
|
|
|
audio: introduce a new type to hold audio frames
This is pretty pointless, but I believe it allows us to claim that the
new code is not affected by the copyright of the old code. This is
needed, because the original mp_audio struct was written by someone who
has disagreed with LGPL relicensing (it was called af_data at the time,
and was defined in af.h).
The "GPL'ed" struct contents that surive are pretty trivial: just the
data pointer, and some metadata like the format, samplerate, etc. - but
at least in this case, any new code would be extremely similar anyway,
and I'm not really sure whether it's OK to claim different copyright. So
what we do is we just use AVFrame (which of course is LGPL with 100%
certainty), and add some accessors around it to adapt it to mpv
conventions.
Also, this gets rid of some annoying conventions of mp_audio, like the
struct fields that require using an accessor to write to them anyway.
For the most part, this change is only dumb replacements of mp_audio
related functions and fields. One minor actual change is that you can't
allocate the new type on the stack anymore.
Some code still uses mp_audio. All audio filter code will be deleted, so
it makes no sense to convert this code. (Audio filters which are LGPL
and which we keep will have to be ported to a new filter infrastructure
anyway.) player/audio.c uses it because it interacts with the old filter
code. push.c has some complex use of mp_audio and mp_audio_buffer, but
this and pull.c will most likely be rewritten to do something else.
2017-08-16 19:00:20 +00:00
|
|
|
struct mp_chmap chmap;
|
|
|
|
mp_chmap_from_channels(&chmap, num_channels);
|
|
|
|
mp_aframe_set_chmap(spdif_ctx->fmt, &chmap);
|
|
|
|
mp_aframe_set_format(spdif_ctx->fmt, sample_format);
|
|
|
|
mp_aframe_set_rate(spdif_ctx->fmt, samplerate);
|
|
|
|
|
|
|
|
spdif_ctx->sstride = mp_aframe_get_sstride(spdif_ctx->fmt);
|
2011-10-12 17:23:08 +00:00
|
|
|
|
2013-11-08 23:32:44 +00:00
|
|
|
if (avformat_write_header(lavf_ctx, &format_opts) < 0) {
|
2013-12-21 17:23:59 +00:00
|
|
|
MP_FATAL(da, "libavformat spdif initialization failed.\n");
|
2013-11-08 23:32:44 +00:00
|
|
|
av_dict_free(&format_opts);
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
av_dict_free(&format_opts);
|
|
|
|
|
|
|
|
spdif_ctx->need_close = true;
|
|
|
|
|
2015-05-19 19:34:30 +00:00
|
|
|
return 0;
|
2011-10-12 17:23:08 +00:00
|
|
|
|
|
|
|
fail:
|
2024-04-10 05:47:05 +00:00
|
|
|
ad_spdif_destroy(da);
|
2018-01-29 05:18:33 +00:00
|
|
|
mp_filter_internal_mark_failed(da);
|
2015-05-19 19:34:30 +00:00
|
|
|
return -1;
|
2011-10-12 17:23:08 +00:00
|
|
|
}
|
|
|
|
|
2024-04-10 05:47:05 +00:00
|
|
|
static void ad_spdif_process(struct mp_filter *da)
|
2011-10-12 17:23:08 +00:00
|
|
|
{
|
2013-11-23 20:22:17 +00:00
|
|
|
struct spdifContext *spdif_ctx = da->priv;
|
2011-10-12 17:23:08 +00:00
|
|
|
|
2018-01-29 05:18:33 +00:00
|
|
|
if (!mp_pin_can_transfer_data(da->ppins[1], da->ppins[0]))
|
|
|
|
return;
|
2017-01-11 10:58:26 +00:00
|
|
|
|
2018-01-29 05:18:33 +00:00
|
|
|
struct mp_frame inframe = mp_pin_out_read(da->ppins[0]);
|
|
|
|
if (inframe.type == MP_FRAME_EOF) {
|
|
|
|
mp_pin_in_write(da->ppins[1], inframe);
|
|
|
|
return;
|
|
|
|
} else if (inframe.type != MP_FRAME_PACKET) {
|
|
|
|
if (inframe.type) {
|
|
|
|
MP_ERR(da, "unknown frame type\n");
|
|
|
|
mp_filter_internal_mark_failed(da);
|
|
|
|
}
|
|
|
|
return;
|
2017-01-11 10:58:26 +00:00
|
|
|
}
|
audio: add support for using non-interleaved audio from decoders directly
Most libavcodec decoders output non-interleaved audio. Add direct
support for this, and remove the hack that repacked non-interleaved
audio back to packed audio.
Remove the minlen argument from the decoder callback. Instead of
forcing every decoder to have its own decode loop to fill the buffer
until minlen is reached, leave this to the caller. So if a decoder
doesn't return enough data, it's simply called again. (In future, I
even want to change it so that decoders don't read packets directly,
but instead the caller has to pass packets to the decoders. This fits
well with this change, because now the decoder callback typically
decodes at most one packet.)
ad_mpg123.c receives some heavy refactoring. The main problem is that
it wanted to handle format changes when there was no data in the decode
output buffer yet. This sounds reasonable, but actually it would write
data into a buffer prepared for old data, since the caller doesn't know
about the format change yet. (I.e. the best place for a format change
would be _after_ writing the last sample to the output buffer.) It's
possible that this code was not perfectly sane before this commit,
and perhaps lost one frame of data after a format change, but I didn't
confirm this. Trying to fix this, I ended up rewriting the decoding
and also the probing.
2013-11-12 21:27:44 +00:00
|
|
|
|
2018-01-29 05:18:33 +00:00
|
|
|
struct demux_packet *mpkt = inframe.data;
|
|
|
|
struct mp_aframe *out = NULL;
|
|
|
|
double pts = mpkt->pts;
|
2015-11-08 16:22:56 +00:00
|
|
|
|
2023-08-07 21:08:32 +00:00
|
|
|
if (!spdif_ctx->avpkt) {
|
|
|
|
spdif_ctx->avpkt = av_packet_alloc();
|
|
|
|
MP_HANDLE_OOM(spdif_ctx->avpkt);
|
|
|
|
}
|
|
|
|
mp_set_av_packet(spdif_ctx->avpkt, mpkt, NULL);
|
|
|
|
spdif_ctx->avpkt->pts = spdif_ctx->avpkt->dts = 0;
|
2015-05-19 19:34:30 +00:00
|
|
|
if (!spdif_ctx->lavf_ctx) {
|
2023-07-27 20:33:28 +00:00
|
|
|
if (init_filter(da) < 0)
|
2017-01-11 10:58:26 +00:00
|
|
|
goto done;
|
2023-07-27 20:33:28 +00:00
|
|
|
assert(spdif_ctx->avpkt);
|
2024-06-15 18:00:07 +00:00
|
|
|
assert(spdif_ctx->lavf_ctx);
|
2015-05-19 19:34:30 +00:00
|
|
|
}
|
2023-07-27 20:33:28 +00:00
|
|
|
|
2017-01-11 10:58:26 +00:00
|
|
|
spdif_ctx->out_buffer_len = 0;
|
ffmpeg: update to handle deprecation of `av_init_packet`
This has been a long standing annoyance - ffmpeg is removing
sizeof(AVPacket) from the API which means you cannot stack-allocate
AVPacket anymore. However, that is something we take advantage of
because we use short-lived AVPackets to bridge from native mpv packets
in our main decoding paths.
We don't think that switching these to `av_packet_alloc` is desirable,
given the cost of heap allocation, so this change takes a different
approach - allocating a single packet in the relevant context and
reusing it over and over.
That's fairly straight-forward, with the main caveat being that
re-initialising the packet is unintuitive. There is no function that
does exactly what we need (what `av_init_packet` did). The closest is
`av_packet_unref`, which additionally frees buffers and side-data.
However, we don't copy those things - we just assign them in from our
own packet, so we have to explicitly clear the pointers before calling
`av_packet_unref`. But at least we can make a wrapper function for
that.
The weirdest part of the change is the handling of the vtt subtitle
conversion. This requires two packets, so I had to pre-allocate two in
the context struct. That sounds excessive, but if allocating the
primary packet is too expensive, then allocating the secondary one for
vtt subtitles must also be too expensive.
This change is not conditional as heap allocated AVPackets were
available for years and years before the deprecation.
2022-11-29 19:15:16 +00:00
|
|
|
int ret = av_write_frame(spdif_ctx->lavf_ctx, spdif_ctx->avpkt);
|
2015-05-19 19:34:30 +00:00
|
|
|
avio_flush(spdif_ctx->lavf_ctx->pb);
|
2017-01-19 11:44:28 +00:00
|
|
|
if (ret < 0) {
|
|
|
|
MP_ERR(da, "spdif mux error: '%s'\n", mp_strerror(AVUNERROR(ret)));
|
2017-01-11 10:58:26 +00:00
|
|
|
goto done;
|
2017-01-19 11:44:28 +00:00
|
|
|
}
|
audio: add support for using non-interleaved audio from decoders directly
Most libavcodec decoders output non-interleaved audio. Add direct
support for this, and remove the hack that repacked non-interleaved
audio back to packed audio.
Remove the minlen argument from the decoder callback. Instead of
forcing every decoder to have its own decode loop to fill the buffer
until minlen is reached, leave this to the caller. So if a decoder
doesn't return enough data, it's simply called again. (In future, I
even want to change it so that decoders don't read packets directly,
but instead the caller has to pass packets to the decoders. This fits
well with this change, because now the decoder callback typically
decodes at most one packet.)
ad_mpg123.c receives some heavy refactoring. The main problem is that
it wanted to handle format changes when there was no data in the decode
output buffer yet. This sounds reasonable, but actually it would write
data into a buffer prepared for old data, since the caller doesn't know
about the format change yet. (I.e. the best place for a format change
would be _after_ writing the last sample to the output buffer.) It's
possible that this code was not perfectly sane before this commit,
and perhaps lost one frame of data after a format change, but I didn't
confirm this. Trying to fix this, I ended up rewriting the decoding
and also the probing.
2013-11-12 21:27:44 +00:00
|
|
|
|
2018-01-29 05:18:33 +00:00
|
|
|
out = mp_aframe_new_ref(spdif_ctx->fmt);
|
audio: introduce a new type to hold audio frames
This is pretty pointless, but I believe it allows us to claim that the
new code is not affected by the copyright of the old code. This is
needed, because the original mp_audio struct was written by someone who
has disagreed with LGPL relicensing (it was called af_data at the time,
and was defined in af.h).
The "GPL'ed" struct contents that surive are pretty trivial: just the
data pointer, and some metadata like the format, samplerate, etc. - but
at least in this case, any new code would be extremely similar anyway,
and I'm not really sure whether it's OK to claim different copyright. So
what we do is we just use AVFrame (which of course is LGPL with 100%
certainty), and add some accessors around it to adapt it to mpv
conventions.
Also, this gets rid of some annoying conventions of mp_audio, like the
struct fields that require using an accessor to write to them anyway.
For the most part, this change is only dumb replacements of mp_audio
related functions and fields. One minor actual change is that you can't
allocate the new type on the stack anymore.
Some code still uses mp_audio. All audio filter code will be deleted, so
it makes no sense to convert this code. (Audio filters which are LGPL
and which we keep will have to be ported to a new filter infrastructure
anyway.) player/audio.c uses it because it interacts with the old filter
code. push.c has some complex use of mp_audio and mp_audio_buffer, but
this and pull.c will most likely be rewritten to do something else.
2017-08-16 19:00:20 +00:00
|
|
|
int samples = spdif_ctx->out_buffer_len / spdif_ctx->sstride;
|
2018-01-29 05:18:33 +00:00
|
|
|
if (mp_aframe_pool_allocate(spdif_ctx->pool, out, samples) < 0) {
|
|
|
|
TA_FREEP(&out);
|
2017-01-11 10:58:26 +00:00
|
|
|
goto done;
|
audio: introduce a new type to hold audio frames
This is pretty pointless, but I believe it allows us to claim that the
new code is not affected by the copyright of the old code. This is
needed, because the original mp_audio struct was written by someone who
has disagreed with LGPL relicensing (it was called af_data at the time,
and was defined in af.h).
The "GPL'ed" struct contents that surive are pretty trivial: just the
data pointer, and some metadata like the format, samplerate, etc. - but
at least in this case, any new code would be extremely similar anyway,
and I'm not really sure whether it's OK to claim different copyright. So
what we do is we just use AVFrame (which of course is LGPL with 100%
certainty), and add some accessors around it to adapt it to mpv
conventions.
Also, this gets rid of some annoying conventions of mp_audio, like the
struct fields that require using an accessor to write to them anyway.
For the most part, this change is only dumb replacements of mp_audio
related functions and fields. One minor actual change is that you can't
allocate the new type on the stack anymore.
Some code still uses mp_audio. All audio filter code will be deleted, so
it makes no sense to convert this code. (Audio filters which are LGPL
and which we keep will have to be ported to a new filter infrastructure
anyway.) player/audio.c uses it because it interacts with the old filter
code. push.c has some complex use of mp_audio and mp_audio_buffer, but
this and pull.c will most likely be rewritten to do something else.
2017-08-16 19:00:20 +00:00
|
|
|
}
|
|
|
|
|
2018-01-29 05:18:33 +00:00
|
|
|
uint8_t **data = mp_aframe_get_data_rw(out);
|
audio: introduce a new type to hold audio frames
This is pretty pointless, but I believe it allows us to claim that the
new code is not affected by the copyright of the old code. This is
needed, because the original mp_audio struct was written by someone who
has disagreed with LGPL relicensing (it was called af_data at the time,
and was defined in af.h).
The "GPL'ed" struct contents that surive are pretty trivial: just the
data pointer, and some metadata like the format, samplerate, etc. - but
at least in this case, any new code would be extremely similar anyway,
and I'm not really sure whether it's OK to claim different copyright. So
what we do is we just use AVFrame (which of course is LGPL with 100%
certainty), and add some accessors around it to adapt it to mpv
conventions.
Also, this gets rid of some annoying conventions of mp_audio, like the
struct fields that require using an accessor to write to them anyway.
For the most part, this change is only dumb replacements of mp_audio
related functions and fields. One minor actual change is that you can't
allocate the new type on the stack anymore.
Some code still uses mp_audio. All audio filter code will be deleted, so
it makes no sense to convert this code. (Audio filters which are LGPL
and which we keep will have to be ported to a new filter infrastructure
anyway.) player/audio.c uses it because it interacts with the old filter
code. push.c has some complex use of mp_audio and mp_audio_buffer, but
this and pull.c will most likely be rewritten to do something else.
2017-08-16 19:00:20 +00:00
|
|
|
if (!data) {
|
2018-01-29 05:18:33 +00:00
|
|
|
TA_FREEP(&out);
|
audio: introduce a new type to hold audio frames
This is pretty pointless, but I believe it allows us to claim that the
new code is not affected by the copyright of the old code. This is
needed, because the original mp_audio struct was written by someone who
has disagreed with LGPL relicensing (it was called af_data at the time,
and was defined in af.h).
The "GPL'ed" struct contents that surive are pretty trivial: just the
data pointer, and some metadata like the format, samplerate, etc. - but
at least in this case, any new code would be extremely similar anyway,
and I'm not really sure whether it's OK to claim different copyright. So
what we do is we just use AVFrame (which of course is LGPL with 100%
certainty), and add some accessors around it to adapt it to mpv
conventions.
Also, this gets rid of some annoying conventions of mp_audio, like the
struct fields that require using an accessor to write to them anyway.
For the most part, this change is only dumb replacements of mp_audio
related functions and fields. One minor actual change is that you can't
allocate the new type on the stack anymore.
Some code still uses mp_audio. All audio filter code will be deleted, so
it makes no sense to convert this code. (Audio filters which are LGPL
and which we keep will have to be ported to a new filter infrastructure
anyway.) player/audio.c uses it because it interacts with the old filter
code. push.c has some complex use of mp_audio and mp_audio_buffer, but
this and pull.c will most likely be rewritten to do something else.
2017-08-16 19:00:20 +00:00
|
|
|
goto done;
|
|
|
|
}
|
2014-11-10 21:01:23 +00:00
|
|
|
|
audio: introduce a new type to hold audio frames
This is pretty pointless, but I believe it allows us to claim that the
new code is not affected by the copyright of the old code. This is
needed, because the original mp_audio struct was written by someone who
has disagreed with LGPL relicensing (it was called af_data at the time,
and was defined in af.h).
The "GPL'ed" struct contents that surive are pretty trivial: just the
data pointer, and some metadata like the format, samplerate, etc. - but
at least in this case, any new code would be extremely similar anyway,
and I'm not really sure whether it's OK to claim different copyright. So
what we do is we just use AVFrame (which of course is LGPL with 100%
certainty), and add some accessors around it to adapt it to mpv
conventions.
Also, this gets rid of some annoying conventions of mp_audio, like the
struct fields that require using an accessor to write to them anyway.
For the most part, this change is only dumb replacements of mp_audio
related functions and fields. One minor actual change is that you can't
allocate the new type on the stack anymore.
Some code still uses mp_audio. All audio filter code will be deleted, so
it makes no sense to convert this code. (Audio filters which are LGPL
and which we keep will have to be ported to a new filter infrastructure
anyway.) player/audio.c uses it because it interacts with the old filter
code. push.c has some complex use of mp_audio and mp_audio_buffer, but
this and pull.c will most likely be rewritten to do something else.
2017-08-16 19:00:20 +00:00
|
|
|
memcpy(data[0], spdif_ctx->out_buffer, spdif_ctx->out_buffer_len);
|
2018-01-29 05:18:33 +00:00
|
|
|
mp_aframe_set_pts(out, pts);
|
2014-07-21 17:29:37 +00:00
|
|
|
|
2017-01-11 10:58:26 +00:00
|
|
|
done:
|
2018-01-29 05:18:33 +00:00
|
|
|
talloc_free(mpkt);
|
|
|
|
if (out) {
|
|
|
|
mp_pin_in_write(da->ppins[1], MAKE_FRAME(MP_FRAME_AUDIO, out));
|
|
|
|
} else {
|
|
|
|
mp_filter_internal_mark_failed(da);
|
2017-01-11 10:58:26 +00:00
|
|
|
}
|
2011-10-12 17:23:08 +00:00
|
|
|
}
|
|
|
|
|
2013-11-08 23:32:44 +00:00
|
|
|
static const int codecs[] = {
|
|
|
|
AV_CODEC_ID_AAC,
|
|
|
|
AV_CODEC_ID_AC3,
|
|
|
|
AV_CODEC_ID_DTS,
|
|
|
|
AV_CODEC_ID_EAC3,
|
|
|
|
AV_CODEC_ID_MP3,
|
|
|
|
AV_CODEC_ID_TRUEHD,
|
|
|
|
AV_CODEC_ID_NONE
|
|
|
|
};
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
|
2016-12-23 17:03:16 +00:00
|
|
|
static bool find_codec(const char *name)
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
{
|
2013-03-09 07:49:56 +00:00
|
|
|
for (int n = 0; codecs[n] != AV_CODEC_ID_NONE; n++) {
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
const char *format = mp_codec_from_av_codec_id(codecs[n]);
|
2016-12-23 17:03:16 +00:00
|
|
|
if (format && name && strcmp(format, name) == 0)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
// codec is the libavcodec name of the source audio codec.
|
|
|
|
// pref is a ","-separated list of names, some of them which do not match with
|
|
|
|
// libavcodec names (like dts-hd).
|
|
|
|
struct mp_decoder_list *select_spdif_codec(const char *codec, const char *pref)
|
|
|
|
{
|
|
|
|
struct mp_decoder_list *list = talloc_zero(NULL, struct mp_decoder_list);
|
|
|
|
|
|
|
|
if (!find_codec(codec))
|
|
|
|
return list;
|
|
|
|
|
|
|
|
bool spdif_allowed = false, dts_hd_allowed = false;
|
|
|
|
bstr sel = bstr0(pref);
|
|
|
|
while (sel.len) {
|
|
|
|
bstr decoder;
|
|
|
|
bstr_split_tok(sel, ",", &decoder, &sel);
|
|
|
|
if (decoder.len) {
|
|
|
|
if (bstr_equals0(decoder, codec))
|
|
|
|
spdif_allowed = true;
|
|
|
|
if (bstr_equals0(decoder, "dts-hd") && strcmp(codec, "dts") == 0)
|
|
|
|
spdif_allowed = dts_hd_allowed = true;
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-23 17:03:16 +00:00
|
|
|
|
|
|
|
if (!spdif_allowed)
|
|
|
|
return list;
|
|
|
|
|
|
|
|
const char *suffix_name = dts_hd_allowed ? "dts_hd" : codec;
|
|
|
|
char name[80];
|
|
|
|
snprintf(name, sizeof(name), "spdif_%s", suffix_name);
|
2018-01-31 03:21:02 +00:00
|
|
|
mp_add_decoder(list, codec, name,
|
2015-06-05 20:34:48 +00:00
|
|
|
"libavformat/spdifenc audio pass-through decoder");
|
2016-12-23 17:03:16 +00:00
|
|
|
return list;
|
core: redo how codecs are mapped, remove codecs.conf
Use codec names instead of FourCCs to identify codecs. Rewrite how
codecs are selected and initialized. Now each decoder exports a list
of decoders (and the codec it supports) via add_decoders(). The order
matters, and the first decoder for a given decoder is preferred over
the other decoders. E.g. all ad_mpg123 decoders are preferred over
ad_lavc, because it comes first in the mpcodecs_ad_drivers array.
Likewise, decoders within ad_lavc that are enumerated first by
libavcodec (using av_codec_next()) are preferred. (This is actually
critical to select h264 software decoding by default instead of vdpau.
libavcodec and ffmpeg/avconv use the same method to select decoders by
default, so we hope this is sane.)
The codec names follow libavcodec's codec names as defined by
AVCodecDescriptor.name (see libavcodec/codec_desc.c). Some decoders
have names different from the canonical codec name. The AVCodecDescriptor
API is relatively new, so we need a compatibility layer for older
libavcodec versions for codec names that are referenced internally,
and which are different from the decoder name. (Add a configure check
for that, because checking versions is getting way too messy.)
demux/codec_tags.c is generated from the former codecs.conf (minus
"special" decoders like vdpau, and excluding the mappings that are the
same as the mappings libavformat's exported RIFF tables). It contains
all the mappings from FourCCs to codec name. This is needed for
demux_mkv, demux_mpg, demux_avi and demux_asf. demux_lavf will set the
codec as determined by libavformat, while the other demuxers have to do
this on their own, using the mp_set_audio/video_codec_from_tag()
functions. Note that the sh_audio/video->format members don't uniquely
identify the codec anymore, and sh->codec takes over this role.
Replace the --ac/--vc/--afm/--vfm with new --vd/--ad options, which
provide cover the functionality of the removed switched.
Note: there's no CODECS_FLAG_FLIP flag anymore. This means some obscure
container/video combinations (e.g. the sample Film_200_zygo_pro.mov)
are played flipped. ffplay/avplay doesn't handle this properly either,
so we don't care and blame ffmeg/libav instead.
2013-02-09 14:15:19 +00:00
|
|
|
}
|
2013-07-22 12:41:56 +00:00
|
|
|
|
2018-01-29 05:18:33 +00:00
|
|
|
static const struct mp_filter_info ad_spdif_filter = {
|
|
|
|
.name = "ad_spdif",
|
|
|
|
.priv_size = sizeof(struct spdifContext),
|
2024-04-10 05:47:05 +00:00
|
|
|
.process = ad_spdif_process,
|
|
|
|
.destroy = ad_spdif_destroy,
|
2018-01-29 05:18:33 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct mp_decoder *create(struct mp_filter *parent,
|
|
|
|
struct mp_codec_params *codec,
|
|
|
|
const char *decoder)
|
|
|
|
{
|
|
|
|
struct mp_filter *da = mp_filter_create(parent, &ad_spdif_filter);
|
|
|
|
if (!da)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
mp_filter_add_pin(da, MP_PIN_IN, "in");
|
|
|
|
mp_filter_add_pin(da, MP_PIN_OUT, "out");
|
|
|
|
|
|
|
|
da->log = mp_log_new(da, parent->log, NULL);
|
|
|
|
|
|
|
|
struct spdifContext *spdif_ctx = da->priv;
|
|
|
|
spdif_ctx->log = da->log;
|
2024-05-20 14:33:21 +00:00
|
|
|
spdif_ctx->codec = codec;
|
2018-01-29 05:18:33 +00:00
|
|
|
spdif_ctx->pool = mp_aframe_pool_create(spdif_ctx);
|
|
|
|
spdif_ctx->public.f = da;
|
|
|
|
|
|
|
|
if (strcmp(decoder, "spdif_dts_hd") == 0)
|
|
|
|
spdif_ctx->use_dts_hd = true;
|
|
|
|
|
|
|
|
spdif_ctx->codec_id = mp_codec_to_av_codec_id(codec->codec);
|
|
|
|
|
|
|
|
|
|
|
|
if (spdif_ctx->codec_id == AV_CODEC_ID_NONE) {
|
|
|
|
talloc_free(da);
|
|
|
|
return NULL;
|
|
|
|
}
|
ffmpeg: update to handle deprecation of `av_init_packet`
This has been a long standing annoyance - ffmpeg is removing
sizeof(AVPacket) from the API which means you cannot stack-allocate
AVPacket anymore. However, that is something we take advantage of
because we use short-lived AVPackets to bridge from native mpv packets
in our main decoding paths.
We don't think that switching these to `av_packet_alloc` is desirable,
given the cost of heap allocation, so this change takes a different
approach - allocating a single packet in the relevant context and
reusing it over and over.
That's fairly straight-forward, with the main caveat being that
re-initialising the packet is unintuitive. There is no function that
does exactly what we need (what `av_init_packet` did). The closest is
`av_packet_unref`, which additionally frees buffers and side-data.
However, we don't copy those things - we just assign them in from our
own packet, so we have to explicitly clear the pointers before calling
`av_packet_unref`. But at least we can make a wrapper function for
that.
The weirdest part of the change is the handling of the vtt subtitle
conversion. This requires two packets, so I had to pre-allocate two in
the context struct. That sounds excessive, but if allocating the
primary packet is too expensive, then allocating the secondary one for
vtt subtitles must also be too expensive.
This change is not conditional as heap allocated AVPackets were
available for years and years before the deprecation.
2022-11-29 19:15:16 +00:00
|
|
|
|
2024-05-19 18:24:31 +00:00
|
|
|
const AVCodecDescriptor *desc = avcodec_descriptor_get(spdif_ctx->codec_id);
|
|
|
|
if (desc)
|
|
|
|
codec->codec_desc = desc->long_name;
|
|
|
|
|
2018-01-29 05:18:33 +00:00
|
|
|
return &spdif_ctx->public;
|
|
|
|
}
|
|
|
|
|
|
|
|
const struct mp_decoder_fns ad_spdif = {
|
|
|
|
.create = create,
|
2013-07-22 12:41:56 +00:00
|
|
|
};
|