summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorMartin Herkt <lachs0r@srsfckn.biz>2016-10-19 19:09:00 +0200
committerMartin Herkt <lachs0r@srsfckn.biz>2016-10-19 19:09:00 +0200
commit5d74fa7dc0fa1617d1d11b69769423b1387ec785 (patch)
tree882752015b3500c91b8ab3a4d669696f23feb817 /common
parentc226bc7616ab2ae9de6172660e9cf727f07dc374 (diff)
parenta2fa0d0b68ce200598122145254f56ae1adff91e (diff)
downloadmpv-5d74fa7dc0fa1617d1d11b69769423b1387ec785.tar.bz2
mpv-5d74fa7dc0fa1617d1d11b69769423b1387ec785.tar.xz
Merge branch 'master' into release/current
Diffstat (limited to 'common')
-rw-r--r--common/av_common.c1
-rw-r--r--common/av_common.h9
-rw-r--r--common/common.h5
-rw-r--r--common/encode_lavc.c38
-rw-r--r--common/global.h6
-rw-r--r--common/msg.c72
-rw-r--r--common/msg_control.h1
-rw-r--r--common/version.c4
8 files changed, 89 insertions, 47 deletions
diff --git a/common/av_common.c b/common/av_common.c
index 3a424b0c62..95c6947eb7 100644
--- a/common/av_common.c
+++ b/common/av_common.c
@@ -160,6 +160,7 @@ void mp_set_av_packet(AVPacket *dst, struct demux_packet *mpkt, AVRational *tb)
dst->side_data_elems = mpkt->avpacket->side_data_elems;
if (dst->data == mpkt->avpacket->data)
dst->buf = mpkt->avpacket->buf;
+ dst->flags |= mpkt->avpacket->flags;
}
if (mpkt && tb && tb->num > 0 && tb->den > 0)
dst->duration = mpkt->duration / av_q2d(*tb);
diff --git a/common/av_common.h b/common/av_common.h
index 4b13dcdd0c..b5ca034def 100644
--- a/common/av_common.h
+++ b/common/av_common.h
@@ -46,4 +46,13 @@ 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);
+#if (LIBAVCODEC_VERSION_MICRO >= 100 && \
+ LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 61, 100)) || \
+ (LIBAVCODEC_VERSION_MICRO < 100 && \
+ LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57, 24, 0))
+#define MP_AVFRAME_DEC_PTS(frame) ((frame)->pts)
+#else
+#define MP_AVFRAME_DEC_PTS(frame) ((frame)->pkt_pts)
+#endif
+
#endif
diff --git a/common/common.h b/common/common.h
index 4b7da54dbd..c78409b3f4 100644
--- a/common/common.h
+++ b/common/common.h
@@ -18,6 +18,7 @@
#ifndef MPLAYER_MPCOMMON_H
#define MPLAYER_MPCOMMON_H
+#include <assert.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdbool.h>
@@ -64,8 +65,8 @@ enum {
DATA_EOF = -2,
};
-extern const char *const mpv_version;
-extern const char *const mpv_builddate;
+extern const char mpv_version[];
+extern const char mpv_builddate[];
char *mp_format_time(double time, bool fractions);
char *mp_format_time_fmt(const char *fmt, double time);
diff --git a/common/encode_lavc.c b/common/encode_lavc.c
index 78688545b5..d0523857ee 100644
--- a/common/encode_lavc.c
+++ b/common/encode_lavc.c
@@ -36,25 +36,25 @@
#define OPT_BASE_STRUCT struct encode_opts
const struct m_sub_options encode_config = {
.opts = (const m_option_t[]) {
- OPT_STRING("o", file, CONF_GLOBAL | CONF_NOCFG | CONF_PRE_PARSE),
- OPT_STRING("of", format, CONF_GLOBAL),
- OPT_STRINGLIST("ofopts*", fopts, CONF_GLOBAL),
- OPT_FLOATRANGE("ofps", fps, CONF_GLOBAL, 0.0, 1000000.0),
- OPT_FLOATRANGE("omaxfps", maxfps, CONF_GLOBAL, 0.0, 1000000.0),
- OPT_STRING("ovc", vcodec, CONF_GLOBAL),
- OPT_STRINGLIST("ovcopts*", vopts, CONF_GLOBAL),
- OPT_STRING("oac", acodec, CONF_GLOBAL),
- OPT_STRINGLIST("oacopts*", aopts, CONF_GLOBAL),
- OPT_FLAG("oharddup", harddup, CONF_GLOBAL),
- OPT_FLOATRANGE("ovoffset", voffset, CONF_GLOBAL, -1000000.0, 1000000.0),
- OPT_FLOATRANGE("oaoffset", aoffset, CONF_GLOBAL, -1000000.0, 1000000.0),
- OPT_FLAG("ocopyts", copyts, CONF_GLOBAL),
- OPT_FLAG("orawts", rawts, CONF_GLOBAL),
- OPT_FLAG("oautofps", autofps, CONF_GLOBAL),
- OPT_FLAG("oneverdrop", neverdrop, CONF_GLOBAL),
- OPT_FLAG("ovfirst", video_first, CONF_GLOBAL),
- OPT_FLAG("oafirst", audio_first, CONF_GLOBAL),
- OPT_FLAG("ometadata", metadata, CONF_GLOBAL),
+ OPT_STRING("o", file, M_OPT_FIXED | CONF_NOCFG | CONF_PRE_PARSE),
+ OPT_STRING("of", format, M_OPT_FIXED),
+ OPT_STRINGLIST("ofopts*", fopts, M_OPT_FIXED),
+ OPT_FLOATRANGE("ofps", fps, M_OPT_FIXED, 0.0, 1000000.0),
+ OPT_FLOATRANGE("omaxfps", maxfps, M_OPT_FIXED, 0.0, 1000000.0),
+ OPT_STRING("ovc", vcodec, M_OPT_FIXED),
+ OPT_STRINGLIST("ovcopts*", vopts, M_OPT_FIXED),
+ OPT_STRING("oac", acodec, M_OPT_FIXED),
+ OPT_STRINGLIST("oacopts*", aopts, M_OPT_FIXED),
+ OPT_FLAG("oharddup", harddup, M_OPT_FIXED),
+ OPT_FLOATRANGE("ovoffset", voffset, M_OPT_FIXED, -1000000.0, 1000000.0),
+ OPT_FLOATRANGE("oaoffset", aoffset, M_OPT_FIXED, -1000000.0, 1000000.0),
+ OPT_FLAG("ocopyts", copyts, M_OPT_FIXED),
+ OPT_FLAG("orawts", rawts, M_OPT_FIXED),
+ OPT_FLAG("oautofps", autofps, M_OPT_FIXED),
+ OPT_FLAG("oneverdrop", neverdrop, M_OPT_FIXED),
+ OPT_FLAG("ovfirst", video_first, M_OPT_FIXED),
+ OPT_FLAG("oafirst", audio_first, M_OPT_FIXED),
+ OPT_FLAG("ometadata", metadata, M_OPT_FIXED),
{0}
},
.size = sizeof(struct encode_opts),
diff --git a/common/global.h b/common/global.h
index fb70b4ff01..879ca72386 100644
--- a/common/global.h
+++ b/common/global.h
@@ -5,9 +5,13 @@
// The only purpose of this is to make mpv library-safe.
// Think hard before adding new members.
struct mpv_global {
- struct MPOpts *opts;
struct mp_log *log;
+ struct m_config_shadow *config;
struct mp_client_api *client_api;
+
+ // Using this is deprecated and should be avoided (missing synchronization).
+ // Use m_config_cache to access mpv_global.config instead.
+ struct MPOpts *opts;
};
#endif
diff --git a/common/msg.c b/common/msg.c
index 534ba41cb5..6d70f88db3 100644
--- a/common/msg.c
+++ b/common/msg.c
@@ -27,12 +27,13 @@
#include "mpv_talloc.h"
#include "misc/bstr.h"
-#include "osdep/atomics.h"
+#include "osdep/atomic.h"
#include "common/common.h"
#include "common/global.h"
#include "misc/ring.h"
#include "misc/bstr.h"
#include "options/options.h"
+#include "options/path.h"
#include "osdep/terminal.h"
#include "osdep/io.h"
#include "osdep/timer.h"
@@ -59,6 +60,8 @@ struct mp_log_root {
int num_buffers;
FILE *log_file;
FILE *stats_file;
+ char *log_path;
+ char *stats_path;
// --- must be accessed atomically
/* This is incremented every time the msglevels must be reloaded.
* (This is perhaps better than maintaining a globally accessible and
@@ -286,6 +289,7 @@ static void write_log_file(struct mp_log *log, int lev, char *text)
(mp_time_us() - MP_START_TIME) / 1e6,
mp_log_levels[lev][0],
log->verbose_prefix, text);
+ fflush(root->log_file);
}
static void write_msg_to_buffers(struct mp_log *log, int lev, char *text)
@@ -457,6 +461,43 @@ void mp_msg_init(struct mpv_global *global)
mp_msg_update_msglevels(global);
}
+// If opt is different from *current_path, reopen *file and update *current_path.
+// If there's an error, _append_ it to err_buf.
+// *current_path and *file are, rather trickily, only accessible under the
+// mp_msg_lock.
+static void reopen_file(char *opt, char **current_path, FILE **file,
+ const char *type, struct mpv_global *global)
+{
+ void *tmp = talloc_new(NULL);
+ bool fail = false;
+
+ char *new_path = mp_get_user_path(tmp, global, opt);
+ if (!new_path)
+ new_path = "";
+
+ pthread_mutex_lock(&mp_msg_lock); // for *current_path/*file
+
+ char *old_path = *current_path ? *current_path : "";
+ if (strcmp(old_path, new_path) != 0) {
+ if (*file)
+ fclose(*file);
+ *file = NULL;
+ talloc_free(*current_path);
+ *current_path = talloc_strdup(NULL, new_path);
+ if (new_path[0]) {
+ *file = fopen(new_path, "wb");
+ fail = !*file;
+ }
+ }
+
+ pthread_mutex_unlock(&mp_msg_lock);
+
+ if (fail)
+ mp_err(global->log, "Failed to open %s file '%s'\n", type, new_path);
+
+ talloc_free(tmp);
+}
+
void mp_msg_update_msglevels(struct mpv_global *global)
{
struct mp_log_root *root = global->log->root;
@@ -480,11 +521,14 @@ void mp_msg_update_msglevels(struct mpv_global *global)
m_option_type_msglevels.copy(NULL, &root->msg_levels,
&global->opts->msg_levels);
- if (!root->log_file && opts->log_file && opts->log_file[0])
- root->log_file = fopen(opts->log_file, "wb");
-
atomic_fetch_add(&root->reload_counter, 1);
pthread_mutex_unlock(&mp_msg_lock);
+
+ reopen_file(opts->log_file, &root->log_path, &root->log_file,
+ "log", global);
+
+ reopen_file(opts->dump_stats, &root->stats_path, &root->stats_file,
+ "stats", global);
}
void mp_msg_force_stderr(struct mpv_global *global, bool force_stderr)
@@ -499,8 +543,10 @@ void mp_msg_uninit(struct mpv_global *global)
struct mp_log_root *root = global->log->root;
if (root->stats_file)
fclose(root->stats_file);
+ talloc_free(root->stats_path);
if (root->log_file)
fclose(root->log_file);
+ talloc_free(root->log_path);
m_option_type_msglevels.free(&root->msg_levels);
talloc_free(root);
global->log = NULL;
@@ -582,24 +628,6 @@ struct mp_log_buffer_entry *mp_msg_log_buffer_read(struct mp_log_buffer *buffer)
return ptr;
}
-int mp_msg_open_stats_file(struct mpv_global *global, const char *path)
-{
- struct mp_log_root *root = global->log->root;
- int r;
-
- pthread_mutex_lock(&mp_msg_lock);
-
- if (root->stats_file)
- fclose(root->stats_file);
- root->stats_file = fopen(path, "wb");
- r = root->stats_file ? 0 : -1;
-
- pthread_mutex_unlock(&mp_msg_lock);
-
- mp_msg_update_msglevels(global);
- return r;
-}
-
// Thread-safety: fully thread-safe, but keep in mind that the lifetime of
// log must be guaranteed during the call.
// Never call this from signal handlers.
diff --git a/common/msg_control.h b/common/msg_control.h
index d8d9b2e6e9..56091fdc2d 100644
--- a/common/msg_control.h
+++ b/common/msg_control.h
@@ -29,7 +29,6 @@ struct mp_log_buffer *mp_msg_log_buffer_new(struct mpv_global *global,
void mp_msg_log_buffer_destroy(struct mp_log_buffer *buffer);
struct mp_log_buffer_entry *mp_msg_log_buffer_read(struct mp_log_buffer *buffer);
-int mp_msg_open_stats_file(struct mpv_global *global, const char *path);
int mp_msg_find_level(const char *s);
extern const char *const mp_log_levels[MSGL_MAX + 1];
diff --git a/common/version.c b/common/version.c
index b1d42b9ab4..b98fe00ed1 100644
--- a/common/version.c
+++ b/common/version.c
@@ -22,5 +22,5 @@
#define BUILDDATE "UNKNOWN"
#endif
-const char *const mpv_version = "mpv " VERSION;
-const char *const mpv_builddate = BUILDDATE;
+const char mpv_version[] = "mpv " VERSION;
+const char mpv_builddate[] = BUILDDATE;