summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2019-05-24 20:12:26 +0200
committerwm4 <wm4@nowhere>2019-09-19 20:37:04 +0200
commit6d11668a9c448674ac04ef61bf902c867671d8db (patch)
tree34336a83e651cebbbde0b089587dc3c37dea1d77
parent327f3fc848e6e30d431411e103e10dbae7f461e3 (diff)
downloadmpv-6d11668a9c448674ac04ef61bf902c867671d8db.tar.bz2
mpv-6d11668a9c448674ac04ef61bf902c867671d8db.tar.xz
demux: use no overlapping packets for lossless audio
Worthless optimization, but at least it justifies that the --audio-backward-overlap option has an "auto" choice. Tested with PCM and FLAC.
-rw-r--r--DOCS/man/options.rst3
-rw-r--r--common/av_common.c7
-rw-r--r--common/av_common.h2
-rw-r--r--demux/demux.c5
4 files changed, 14 insertions, 3 deletions
diff --git a/DOCS/man/options.rst b/DOCS/man/options.rst
index f2b94a7e1e..0170dc0ae0 100644
--- a/DOCS/man/options.rst
+++ b/DOCS/man/options.rst
@@ -560,7 +560,8 @@ Playback Control
The solution is to feed a previous packet to the decoder each time, and then
discard the output. This option controls how many packets to feed. The
- ``auto`` choice is currently hardcoded to 1 for audio, and 0 for video.
+ ``auto`` choice is currently hardcoded to 0 for video, and uses 1 for lossy
+ audio, 0 for lossless audio.
``--video-backward-overlap`` can potentially handle intra-refresh video,
depending on the exact conditions. You may have to use the
diff --git a/common/av_common.c b/common/av_common.c
index 3ea1ceb872..01428ff2f4 100644
--- a/common/av_common.c
+++ b/common/av_common.c
@@ -292,6 +292,13 @@ const char *mp_codec_from_av_codec_id(int codec_id)
return name;
}
+bool mp_codec_is_lossless(const char *codec)
+{
+ const AVCodecDescriptor *desc =
+ avcodec_descriptor_get(mp_codec_to_av_codec_id(codec));
+ return desc && (desc->props & AV_CODEC_PROP_LOSSLESS);
+}
+
// kv is in the format as by OPT_KEYVALUELIST(): kv[0]=key0, kv[1]=val0, ...
// Copy them to the dict.
void mp_set_avdict(AVDictionary **dict, char **kv)
diff --git a/common/av_common.h b/common/av_common.h
index 4037afa0ad..1b3e468884 100644
--- a/common/av_common.h
+++ b/common/av_common.h
@@ -19,6 +19,7 @@
#define MP_AVCOMMON_H
#include <inttypes.h>
+#include <stdbool.h>
#include <libavutil/avutil.h>
#include <libavutil/rational.h>
@@ -44,6 +45,7 @@ void mp_add_lavc_encoders(struct mp_decoder_list *list);
char **mp_get_lavf_demuxers(void);
int mp_codec_to_av_codec_id(const char *codec);
const char *mp_codec_from_av_codec_id(int codec_id);
+bool mp_codec_is_lossless(const char *codec);
void mp_set_avdict(struct AVDictionary **dict, char **kv);
void mp_avdict_print_unset(struct mp_log *log, int msgl, struct AVDictionary *d);
int mp_set_avopts(struct mp_log *log, void *avobj, char **kv);
diff --git a/demux/demux.c b/demux/demux.c
index 27866fba83..481b87e0c7 100644
--- a/demux/demux.c
+++ b/demux/demux.c
@@ -33,6 +33,7 @@
#include "options/m_config.h"
#include "options/m_option.h"
#include "mpv_talloc.h"
+#include "common/av_common.h"
#include "common/msg.h"
#include "common/global.h"
#include "common/recorder.h"
@@ -952,8 +953,8 @@ static void demux_add_sh_stream_locked(struct demux_internal *in,
switch (ds->type) {
case STREAM_AUDIO:
ds->back_preroll = in->opts->audio_back_preroll;
- if (ds->back_preroll < 0)
- ds->back_preroll = 1; // auto
+ if (ds->back_preroll < 0) // auto
+ ds->back_preroll = mp_codec_is_lossless(sh->codec->codec) ? 0 : 1;
break;
case STREAM_VIDEO:
ds->back_preroll = in->opts->video_back_preroll;