summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/asxparser.c56
-rw-r--r--common/asxparser.h3
-rw-r--r--common/av_common.c3
-rw-r--r--common/av_log.c125
-rw-r--r--common/av_log.h10
-rw-r--r--common/codecs.c17
-rw-r--r--common/codecs.h3
-rw-r--r--common/cpudetect.c13
-rw-r--r--common/encode.h8
-rw-r--r--common/encode_lavc.c211
-rw-r--r--common/encode_lavc.h2
-rw-r--r--common/msg.c402
-rw-r--r--common/msg.h163
-rw-r--r--common/playlist_parser.c86
-rw-r--r--common/playlist_parser.h6
15 files changed, 485 insertions, 623 deletions
diff --git a/common/asxparser.c b/common/asxparser.c
index 5b1d5652a3..8e77874f27 100644
--- a/common/asxparser.c
+++ b/common/asxparser.c
@@ -45,6 +45,7 @@ struct ASX_Parser_t {
char* last_body;
int deep;
struct playlist *pl;
+ struct mp_log *log;
};
ASX_Parser_t *asx_parser_new(struct playlist *pl);
@@ -105,8 +106,8 @@ asx_get_attrib(const char* attrib,char** attribs) {
return NULL;
}
-#define asx_warning_attrib_required(p,e,a) mp_msg(MSGT_PLAYTREE,MSGL_WARN,"At line %d : element %s don't have the required attribute %s",p->line,e,a)
-#define asx_warning_body_parse_error(p,e) mp_msg(MSGT_PLAYTREE,MSGL_WARN,"At line %d : error while parsing %s body",p->line,e)
+#define asx_warning_attrib_required(p,e,a) MP_WARN(parser, "At line %d : element %s don't have the required attribute %s",p->line,e,a)
+#define asx_warning_body_parse_error(p,e) MP_WARN(parser, "At line %d : error while parsing %s body",p->line,e)
ASX_Parser_t *asx_parser_new(struct playlist *pl)
{
@@ -142,7 +143,7 @@ asx_parse_attribs(ASX_Parser_t* parser,char* buffer,char*** _attribs) {
if(ptr3 == NULL) break;
for(ptr2 = ptr3-1; strchr(SPACE,*ptr2) != NULL; ptr2--) {
if (ptr2 == ptr1) {
- mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : this should never append, back to attribute begin while skipping end space",parser->line);
+ MP_ERR(parser, "At line %d : this should never append, back to attribute begin while skipping end space",parser->line);
break;
}
}
@@ -153,13 +154,13 @@ asx_parse_attribs(ASX_Parser_t* parser,char* buffer,char*** _attribs) {
ptr1 = strchr(ptr3,'"');
if(ptr1 == NULL || ptr1[1] == '\0') ptr1 = strchr(ptr3,'\'');
if(ptr1 == NULL || ptr1[1] == '\0') {
- mp_msg(MSGT_PLAYTREE,MSGL_WARN,"At line %d : can't find attribute %s value",parser->line,attrib);
+ MP_WARN(parser, "At line %d : can't find attribute %s value",parser->line,attrib);
free(attrib);
break;
}
ptr2 = strchr(ptr1+1,ptr1[0]);
if (ptr2 == NULL) {
- mp_msg(MSGT_PLAYTREE,MSGL_WARN,"At line %d : value of attribute %s isn't finished",parser->line,attrib);
+ MP_WARN(parser, "At line %d : value of attribute %s isn't finished",parser->line,attrib);
free(attrib);
break;
}
@@ -198,7 +199,7 @@ asx_get_element(ASX_Parser_t* parser,char** _buffer,
int quotes = 0;
if(_buffer == NULL || _element == NULL || _body == NULL || _attribs == NULL) {
- mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : asx_get_element called with invalid value",parser->line);
+ MP_ERR(parser, "At line %d : asx_get_element called with invalid value",parser->line);
return -1;
}
@@ -254,7 +255,7 @@ asx_get_element(ASX_Parser_t* parser,char** _buffer,
}
//ptr1 = strstr(ptr1,"-->");
if(!ptr1) {
- mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : unfinished comment",parser->line);
+ MP_ERR(parser, "At line %d : unfinished comment",parser->line);
return -1;
}
} else {
@@ -265,7 +266,7 @@ asx_get_element(ASX_Parser_t* parser,char** _buffer,
// Is this space skip very useful ??
for(ptr1++; strchr(SPACE,ptr1[0]) != NULL; ptr1++) { // Skip space
if(ptr1[0] == '\0') {
- mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : EOB reached while parsing element start",parser->line);
+ MP_ERR(parser, "At line %d : EOB reached while parsing element start",parser->line);
return -1;
}
if(ptr1[0] == '\n') parser->line++;
@@ -273,7 +274,7 @@ asx_get_element(ASX_Parser_t* parser,char** _buffer,
for(ptr2 = ptr1; strchr(LETTER,*ptr2) != NULL;ptr2++) { // Go to end of name
if(*ptr2 == '\0'){
- mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : EOB reached while parsing element start",parser->line);
+ MP_ERR(parser, "At line %d : EOB reached while parsing element start",parser->line);
return -1;
}
if(ptr2[0] == '\n') parser->line++;
@@ -285,7 +286,7 @@ asx_get_element(ASX_Parser_t* parser,char** _buffer,
for( ; strchr(SPACE,*ptr2) != NULL; ptr2++) { // Skip space
if(ptr2[0] == '\0') {
- mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : EOB reached while parsing element start",parser->line);
+ MP_ERR(parser, "At line %d : EOB reached while parsing element start",parser->line);
free(element);
return -1;
}
@@ -302,7 +303,7 @@ asx_get_element(ASX_Parser_t* parser,char** _buffer,
if(ptr3[0] == '\n') parser->line++;
}
if(ptr3[0] == '\0' || ptr3[1] == '\0') { // End of file
- mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : EOB reached while parsing element start",parser->line);
+ MP_ERR(parser, "At line %d : EOB reached while parsing element start",parser->line);
free(element);
return -1;
}
@@ -318,7 +319,7 @@ asx_get_element(ASX_Parser_t* parser,char** _buffer,
ptr3++;
for( ; strchr(SPACE,*ptr3) != NULL; ptr3++) { // Skip space on body begin
if(*ptr3 == '\0') {
- mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : EOB reached while parsing %s element body",parser->line,element);
+ MP_ERR(parser, "At line %d : EOB reached while parsing %s element body",parser->line,element);
free(element);
free(attribs);
return -1;
@@ -346,7 +347,7 @@ asx_get_element(ASX_Parser_t* parser,char** _buffer,
continue;
}
if(ptr4 == NULL || ptr4[1] == '\0') {
- mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : EOB reached while parsing %s element body",parser->line,element);
+ MP_ERR(parser, "At line %d : EOB reached while parsing %s element body",parser->line,element);
free(element);
free(attribs);
return -1;
@@ -392,7 +393,7 @@ asx_get_element(ASX_Parser_t* parser,char** _buffer,
n_attrib = asx_parse_attribs(parser,attribs,_attribs);
free(attribs);
if(n_attrib < 0) {
- mp_msg(MSGT_PLAYTREE,MSGL_WARN,"At line %d : error while parsing element %s attributes",parser->line,element);
+ MP_WARN(parser, "At line %d : error while parsing element %s attributes",parser->line,element);
free(element);
free(body);
return -1;
@@ -441,7 +442,7 @@ asx_parse_ref(ASX_Parser_t* parser, char** attribs) {
playlist_add_file(parser->pl, href);
- mp_msg(MSGT_PLAYTREE,MSGL_V,"Adding file %s to element entry\n",href);
+ MP_VERBOSE(parser, "Adding file %s to element entry\n",href);
free(href);
@@ -458,10 +459,10 @@ static void asx_parse_entryref(ASX_Parser_t* parser,char* buffer,char** _attribs
asx_warning_attrib_required(parser,"ENTRYREF" ,"HREF" );
return;
}
- mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Recursive playlist %s\n", href);
+ MP_ERR(parser, "Recursive playlist %s\n", href);
playlist_add_file(parser->pl, href);
free(href);
- //mp_msg(MSGT_PLAYTREE,MSGL_INFO,"Need to implement entryref\n");
+ //MP_INFO(parser, "Need to implement entryref\n");
}
static void asx_parse_entry(ASX_Parser_t* parser,char* buffer,char** _attribs) {
@@ -478,9 +479,9 @@ static void asx_parse_entry(ASX_Parser_t* parser,char* buffer,char** _attribs) {
}
if(strcasecmp(element,"REF") == 0) {
asx_parse_ref(parser,attribs);
- mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Adding element %s to entry\n",element);
+ MP_DBG(parser, "Adding element %s to entry\n",element);
} else
- mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Ignoring element %s\n",element);
+ MP_DBG(parser, "Ignoring element %s\n",element);
free(body);
asx_free_attribs(attribs);
}
@@ -493,7 +494,7 @@ static void asx_parse_repeat(ASX_Parser_t* parser,char* buffer,char** _attribs)
int r;
asx_get_attrib("COUNT",_attribs);
- mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Ignoring repeated playlist entries\n");
+ MP_ERR(parser, "Ignoring repeated playlist entries\n");
while(buffer && buffer[0] != '\0') {
r = asx_get_element(parser,&buffer,&element,&body,&attribs);
@@ -510,7 +511,7 @@ static void asx_parse_repeat(ASX_Parser_t* parser,char* buffer,char** _attribs)
} else if(strcasecmp(element,"REPEAT") == 0) {
asx_parse_repeat(parser,body,attribs);
} else
- mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Ignoring element %s\n",element);
+ MP_DBG(parser, "Ignoring element %s\n",element);
free(body);
asx_free_attribs(attribs);
}
@@ -518,35 +519,36 @@ static void asx_parse_repeat(ASX_Parser_t* parser,char* buffer,char** _attribs)
}
-bool asx_parse(char* buffer, struct playlist *pl)
+bool asx_parse(char* buffer, struct playlist *pl, struct mp_log *log)
{
char *element,*asx_body,**asx_attribs,*body = NULL, **attribs;
int r;
ASX_Parser_t* parser = asx_parser_new(pl);
+ parser->log = log;
parser->line = 1;
parser->deep = 0;
r = asx_get_element(parser,&buffer,&element,&asx_body,&asx_attribs);
if(r < 0) {
- mp_msg(MSGT_PLAYTREE,MSGL_ERR,"At line %d : Syntax error ???",parser->line);
+ MP_ERR(parser, "At line %d : Syntax error ???",parser->line);
asx_parser_free(parser);
return false;
} else if(r == 0) { // No contents
- mp_msg(MSGT_PLAYTREE,MSGL_ERR,"empty asx element");
+ MP_ERR(parser, "empty asx element");
asx_parser_free(parser);
return false;
}
if(strcasecmp(element,"ASX") != 0) {
- mp_msg(MSGT_PLAYTREE,MSGL_ERR,"first element isn't ASX, it's %s\n",element);
+ MP_ERR(parser, "first element isn't ASX, it's %s\n",element);
asx_free_attribs(asx_attribs);
asx_parser_free(parser);
return false;
}
if(!asx_body) {
- mp_msg(MSGT_PLAYTREE,MSGL_ERR,"ASX element is empty");
+ MP_ERR(parser, "ASX element is empty");
asx_free_attribs(asx_attribs);
asx_parser_free(parser);
return false;
@@ -569,7 +571,7 @@ bool asx_parse(char* buffer, struct playlist *pl)
} else if(strcasecmp(element,"REPEAT") == 0) {
asx_parse_repeat(parser,body,attribs);
} else
- mp_msg(MSGT_PLAYTREE,MSGL_DBG2,"Ignoring element %s\n",element);
+ MP_DBG(parser, "Ignoring element %s\n",element);
free(body);
asx_free_attribs(attribs);
}
diff --git a/common/asxparser.h b/common/asxparser.h
index e49a2cedc0..87e0f759c8 100644
--- a/common/asxparser.h
+++ b/common/asxparser.h
@@ -22,6 +22,7 @@
#include <stdbool.h>
struct playlist;
-bool asx_parse(char* buffer, struct playlist *pl);
+struct mp_log;
+bool asx_parse(char* buffer, struct playlist *pl, struct mp_log *log);
#endif /* MPLAYER_ASXPARSER_H */
diff --git a/common/av_common.c b/common/av_common.c
index cccb0f755e..9c41c03251 100644
--- a/common/av_common.c
+++ b/common/av_common.c
@@ -18,6 +18,7 @@
#include <assert.h>
#include <libavutil/common.h>
+#include <libavutil/log.h>
#include <libavcodec/avcodec.h>
#include "common/common.h"
@@ -122,7 +123,7 @@ void mp_set_avcodec_threads(AVCodecContext *avctx, int threads)
if (threads == 0) {
threads = default_thread_count();
if (threads < 1) {
- mp_msg(MSGT_GLOBAL, MSGL_WARN, "Could not determine "
+ av_log(avctx, AV_LOG_WARNING, "Could not determine "
"thread count to use, defaulting to 1.\n");
threads = 1;
}
diff --git a/common/av_log.c b/common/av_log.c
index ba47500572..1fcaf55fcc 100644
--- a/common/av_log.c
+++ b/common/av_log.c
@@ -21,11 +21,16 @@
*/
#include <stdlib.h>
+#include <stdio.h>
#include <stdbool.h>
+#include <pthread.h>
#include "av_log.h"
#include "config.h"
+#include "common/common.h"
+#include "common/global.h"
#include "common/msg.h"
+
#include <libavutil/avutil.h>
#include <libavutil/log.h>
@@ -48,10 +53,23 @@
#include <libswresample/swresample.h>
#endif
+#if LIBAVCODEC_VERSION_MICRO >= 100
+#define LIB_PREFIX "ffmpeg"
+#else
+#define LIB_PREFIX "libav"
+#endif
+
+// Needed because the av_log callback does not provide a library-safe message
+// callback.
+static pthread_mutex_t log_lock = PTHREAD_MUTEX_INITIALIZER;
+static struct mpv_global *log_mpv_instance;
+static struct mp_log *log_root, *log_decaudio, *log_decvideo, *log_demuxer;
+static bool log_print_prefix = true;
+
static int av_log_level_to_mp_level(int av_level)
{
if (av_level > AV_LOG_VERBOSE)
- return MSGL_DBG2;
+ return MSGL_DEBUG;
if (av_level > AV_LOG_INFO)
return MSGL_V;
if (av_level > AV_LOG_WARNING)
@@ -63,17 +81,17 @@ static int av_log_level_to_mp_level(int av_level)
return MSGL_FATAL;
}
-static int extract_msg_type_from_ctx(void *ptr)
+static struct mp_log *get_av_log(void *ptr)
{
if (!ptr)
- return MSGT_FIXME;
+ return log_root;
AVClass *avc = *(AVClass **)ptr;
if (!avc) {
- mp_msg(MSGT_FIXME, MSGL_WARN,
+ mp_warn(log_root,
"av_log callback called with bad parameters (NULL AVClass).\n"
"This is a bug in one of Libav/FFmpeg libraries used.\n");
- return MSGT_FIXME;
+ return log_root;
}
if (!strcmp(avc->class_name, "AVCodecContext")) {
@@ -81,59 +99,65 @@ static int extract_msg_type_from_ctx(void *ptr)
if (s->codec) {
if (s->codec->type == AVMEDIA_TYPE_AUDIO) {
if (s->codec->decode)
- return MSGT_DECAUDIO;
+ return log_decaudio;
} else if (s->codec->type == AVMEDIA_TYPE_VIDEO) {
if (s->codec->decode)
- return MSGT_DECVIDEO;
+ return log_decvideo;
}
- // FIXME subtitles, encoders
- // What msgt for them? There is nothing appropriate...
}
- return MSGT_FIXME;
}
if (!strcmp(avc->class_name, "AVFormatContext")) {
AVFormatContext *s = ptr;
if (s->iformat)
- return MSGT_DEMUXER;
- else if (s->oformat)
- return MSGT_MUXER;
- return MSGT_FIXME;
+ return log_demuxer;
}
- return MSGT_FIXME;
+ return log_root;
}
-#if LIBAVCODEC_VERSION_MICRO >= 100
-#define LIB_PREFIX "ffmpeg"
-#else
-#define LIB_PREFIX "libav"
-#endif
-
-static bool print_prefix = true;
-
static void mp_msg_av_log_callback(void *ptr, int level, const char *fmt,
va_list vl)
{
AVClass *avc = ptr ? *(AVClass **)ptr : NULL;
int mp_level = av_log_level_to_mp_level(level);
- int type = extract_msg_type_from_ctx(ptr);
- if (!mp_msg_test(type, mp_level))
+ // Note: mp_log is thread-safe, but destruction of the log instances is not.
+ pthread_mutex_lock(&log_lock);
+
+ if (!log_mpv_instance) {
+ pthread_mutex_unlock(&log_lock);
+ // Fallback to stderr
+ vfprintf(stderr, fmt, vl);
return;
+ }
+
+ struct mp_log *log = get_av_log(ptr);
+
+ if (mp_msg_test(log, mp_level)) {
+ if (log_print_prefix)
+ mp_msg(log, mp_level, "%s: ", avc ? avc->item_name(ptr) : "?");
+ log_print_prefix = fmt[strlen(fmt) - 1] == '\n';
- if (print_prefix) {
- mp_msg(type, mp_level, "[%s/%s] ", LIB_PREFIX,
- avc ? avc->item_name(ptr) : "?");
+ mp_msg_va(log, mp_level, fmt, vl);
}
- print_prefix = fmt[strlen(fmt) - 1] == '\n';
- mp_msg_va(type, mp_level, fmt, vl);
+ pthread_mutex_unlock(&log_lock);
}
-void init_libav(void)
+void init_libav(struct mpv_global *global)
{
- av_log_set_callback(mp_msg_av_log_callback);
+ pthread_mutex_lock(&log_lock);
+ if (!log_mpv_instance) {
+ log_mpv_instance = global;
+ log_root = mp_log_new(NULL, global->log, LIB_PREFIX);
+ log_decaudio = mp_log_new(log_root, log_root, "audio");
+ log_decvideo = mp_log_new(log_root, log_root, "video");
+ log_demuxer = mp_log_new(log_root, log_root, "demuxer");
+ av_log_set_callback(mp_msg_av_log_callback);
+ }
+ pthread_mutex_unlock(&log_lock);
+
avcodec_register_all();
av_register_all();
avformat_network_init();
@@ -146,31 +170,42 @@ void init_libav(void)
#endif
}
+void uninit_libav(struct mpv_global *global)
+{
+ pthread_mutex_lock(&log_lock);
+ if (log_mpv_instance == global) {
+ log_mpv_instance = NULL;
+ talloc_free(log_root);
+ }
+ pthread_mutex_unlock(&log_lock);
+}
+
#define V(x) (x)>>16, (x)>>8 & 255, (x) & 255
-static void print_version(int v, char *name, unsigned buildv, unsigned runv)
+static void print_version(struct mp_log *log, int v, char *name,
+ unsigned buildv, unsigned runv)
{
- mp_msg(MSGT_CPLAYER, v, " %-15s %d.%d.%d", name, V(buildv));
+ mp_msg(log, v, " %-15s %d.%d.%d", name, V(buildv));
if (buildv != runv)
- mp_msg(MSGT_CPLAYER, v, " (runtime %d.%d.%d)", V(runv));
- mp_msg(MSGT_CPLAYER, v, "\n");
+ mp_msg(log, v, " (runtime %d.%d.%d)", V(runv));
+ mp_msg(log, v, "\n");
}
#undef V
-void print_libav_versions(int v)
+void print_libav_versions(struct mp_log *log, int v)
{
- mp_msg(MSGT_CPLAYER, v, "%s library versions:\n", LIB_PREFIX);
+ mp_msg(log, v, "%s library versions:\n", LIB_PREFIX);
- print_version(v, "libavutil", LIBAVUTIL_VERSION_INT, avutil_version());
- print_version(v, "libavcodec", LIBAVCODEC_VERSION_INT, avcodec_version());
- print_version(v, "libavformat", LIBAVFORMAT_VERSION_INT, avformat_version());
- print_version(v, "libswscale", LIBSWSCALE_VERSION_INT, swscale_version());
+ print_version(log, v, "libavutil", LIBAVUTIL_VERSION_INT, avutil_version());
+ print_version(log, v, "libavcodec", LIBAVCODEC_VERSION_INT, avcodec_version());
+ print_version(log, v, "libavformat", LIBAVFORMAT_VERSION_INT, avformat_version());
+ print_version(log, v, "libswscale", LIBSWSCALE_VERSION_INT, swscale_version());
#if HAVE_LIBAVFILTER
- print_version(v, "libavfilter", LIBAVFILTER_VERSION_INT, avfilter_version());
+ print_version(log, v, "libavfilter", LIBAVFILTER_VERSION_INT, avfilter_version());
#endif
#if HAVE_LIBAVRESAMPLE
- print_version(v, "libavresample", LIBAVRESAMPLE_VERSION_INT, avresample_version());
+ print_version(log, v, "libavresample", LIBAVRESAMPLE_VERSION_INT, avresample_version());
#endif
#if HAVE_LIBSWRESAMPLE
- print_version(v, "libswresample", LIBSWRESAMPLE_VERSION_INT, swresample_version());
+ print_version(log, v, "libswresample", LIBSWRESAMPLE_VERSION_INT, swresample_version());
#endif
}
diff --git a/common/av_log.h b/common/av_log.h
index d5c57b0aeb..17326b609f 100644
--- a/common/av_log.h
+++ b/common/av_log.h
@@ -1,2 +1,8 @@
-void init_libav(void);
-void print_libav_versions(int v);
+#ifndef MP_AV_LOG_H
+#define MP_AV_LOG_H
+struct mpv_global;
+struct mp_log;
+void init_libav(struct mpv_global *global);
+void uninit_libav(struct mpv_global *global);
+void print_libav_versions(struct mp_log *log, int v);
+#endif
diff --git a/common/codecs.c b/common/codecs.c
index b7639a4576..1cbab44969 100644
--- a/common/codecs.c
+++ b/common/codecs.c
@@ -98,9 +98,8 @@ struct mp_decoder_list *mp_select_decoders(struct mp_decoder_list *all,
struct mp_decoder_list *dest = exclude ? remove : list;
bstr family, decoder;
if (!bstr_split_tok(entry, ":", &family, &decoder)) {
- mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Decoders must be specified as "
- "'family:decoder' for the --ad/--vd options.\n");
- break;
+ family = entry;
+ decoder = bstr0("*");
}
if (bstr_equals0(decoder, "*")) {
for (int n = 0; n < all->num_entries; n++) {
@@ -131,17 +130,17 @@ struct mp_decoder_list *mp_select_decoders(struct mp_decoder_list *all,
return list;
}
-void mp_print_decoders(int msgt, int msgl, const char *header,
+void mp_print_decoders(struct mp_log *log, int msgl, const char *header,
struct mp_decoder_list *list)
{
- mp_msg(msgt, msgl, "%s\n", header);
+ mp_msg(log, msgl, "%s\n", header);
for (int n = 0; n < list->num_entries; n++) {
struct mp_decoder_entry *entry = &list->entries[n];
- mp_msg(msgt, msgl, " %s:%s", entry->family, entry->decoder);
+ mp_msg(log, msgl, " %s:%s", entry->family, entry->decoder);
if (strcmp(entry->decoder, entry->codec) != 0)
- mp_msg(msgt, msgl, " (%s)", entry->codec);
- mp_msg(msgt, msgl, " - %s\n", entry->desc);
+ mp_msg(log, msgl, " (%s)", entry->codec);
+ mp_msg(log, msgl, " - %s\n", entry->desc);
}
if (list->num_entries == 0)
- mp_msg(msgt, msgl, " (no decoders)\n");
+ mp_msg(log, msgl, " (no decoders)\n");
}
diff --git a/common/codecs.h b/common/codecs.h
index 21ff284617..105aab5a82 100644
--- a/common/codecs.h
+++ b/common/codecs.h
@@ -37,7 +37,8 @@ struct mp_decoder_list *mp_select_decoders(struct mp_decoder_list *all,
const char *codec,
const char *selection);
-void mp_print_decoders(int msgt, int msgl, const char *header,
+struct mp_log;
+void mp_print_decoders(struct mp_log *log, int msgl, const char *header,
struct mp_decoder_list *list);
#endif
diff --git a/common/cpudetect.c b/common/cpudetect.c
index ea28cf4dd4..d68370f231 100644
--- a/common/cpudetect.c
+++ b/common/cpudetect.c
@@ -25,16 +25,9 @@
#include "config.h"
#include "common/cpudetect.h"
-#include "common/msg.h"
CpuCaps gCpuCaps;
-static void dump_flag(const char *name, bool val)
-{
- mp_msg(MSGT_CPUDETECT, MSGL_V, "CPU: %s: %s\n", name,
- val ? "enabled" : "disabled");
-}
-
void GetCpuCaps(CpuCaps *c)
{
memset(c, 0, sizeof(*c));
@@ -47,10 +40,4 @@ void GetCpuCaps(CpuCaps *c)
c->hasSSE3 = (flags & AV_CPU_FLAG_SSE3) && !(flags & AV_CPU_FLAG_SSE3SLOW);
c->hasSSSE3 = flags & AV_CPU_FLAG_SSSE3;
#endif
- dump_flag("MMX", c->hasMMX);
- dump_flag("MMX2", c->hasMMX2);
- dump_flag("SSE", c->hasSSE);
- dump_flag("SSE2", c->hasSSE2);
- dump_flag("SSE3", c->hasSSE3);
- dump_flag("SSSE3", c->hasSSSE3);
}
diff --git a/common/encode.h b/common/encode.h
index fec14045ed..a4c7d821d9 100644
--- a/common/encode.h
+++ b/common/encode.h
@@ -3,16 +3,18 @@
#include <stdbool.h>
-struct MPOpts;
+struct mpv_global;
+struct mp_log;
struct encode_lavc_context;
struct encode_output_conf;
// interface for mplayer.c
-struct encode_lavc_context *encode_lavc_init(struct encode_output_conf *options);
+struct encode_lavc_context *encode_lavc_init(struct encode_output_conf *options,
+ struct mpv_global *global);
void encode_lavc_finish(struct encode_lavc_context *ctx);
void encode_lavc_free(struct encode_lavc_context *ctx);
void encode_lavc_discontinuity(struct encode_lavc_context *ctx);
-bool encode_lavc_showhelp(struct MPOpts *opts);
+bool encode_lavc_showhelp(struct mp_log *log, struct encode_output_conf *options);
int encode_lavc_getstatus(struct encode_lavc_context *ctx, char *buf, int bufsize, float relative_position);
void encode_lavc_expect_stream(struct encode_lavc_context *ctx, int mt);
void encode_lavc_set_video_fps(struct encode_lavc_context *ctx, float fps);
diff --git a/common/encode_lavc.c b/common/encode_lavc.c
index c061ecaeaf..2cf549e538 100644
--- a/common/encode_lavc.c
+++ b/common/encode_lavc.c
@@ -23,6 +23,7 @@
#include <libavutil/avutil.h>
#include "encode_lavc.h"
+#include "common/global.h"
#include "common/msg.h"
#include "video/vfcap.h"
#include "options/options.h"
@@ -31,7 +32,9 @@
#include "talloc.h"
#include "stream/stream.h"
-static int set_to_avdictionary(AVDictionary **dictp, const char *key,
+static int set_to_avdictionary(struct encode_lavc_context *ctx,
+ AVDictionary **dictp,
+ const char *key,
const char *val)
{
char keybuf[1024];
@@ -41,9 +44,8 @@ static int set_to_avdictionary(AVDictionary **dictp, const char *key,
// we need to split at equals sign
const char *equals = strchr(val, '=');
if (!equals || equals - val >= sizeof(keybuf)) {
- mp_msg(MSGT_ENCODE, MSGL_WARN,
- "encode-lavc: option '%s' does not contain an equals sign\n",
- val);
+ MP_WARN(ctx, "option '%s' does not contain an equals sign\n",
+ val);
return 0;
}
memcpy(keybuf, val, equals - val);
@@ -63,10 +65,8 @@ static int set_to_avdictionary(AVDictionary **dictp, const char *key,
val = valuebuf;
}
- mp_msg(MSGT_ENCODE, MSGL_V,
- "encode-lavc: setting value '%s' for key '%s'\n",
- val,
- key);
+ MP_VERBOSE(ctx, "setting value '%s' for key '%s'\n",
+ val, key);
if (av_dict_set(dictp, key, *val ? val : NULL,
(val[0] == '+' || val[0] == '-') ? AV_DICT_APPEND : 0) >= 0)
@@ -96,7 +96,7 @@ static bool value_has_flag(const char *value, const char *flag)
#define CHECK_FAIL(ctx, val) \
if (ctx && (ctx->failed || ctx->finished)) { \
- mp_msg(MSGT_ENCODE, MSGL_ERR, \
+ MP_ERR(ctx, \
"Called a function on a %s encoding context. Bailing out.\n", \
ctx->failed ? "failed" : "finished"); \
return val; \
@@ -114,7 +114,8 @@ int encode_lavc_oformat_flags(struct encode_lavc_context *ctx)
return ctx->avc ? ctx->avc->oformat->flags : 0;
}
-struct encode_lavc_context *encode_lavc_init(struct encode_output_conf *options)
+struct encode_lavc_context *encode_lavc_init(struct encode_output_conf *options,
+ struct mpv_global *global)
{
struct encode_lavc_context *ctx;
const char *filename = options->file;
@@ -129,9 +130,11 @@ struct encode_lavc_context *encode_lavc_init(struct encode_output_conf *options)
!strcmp(filename, "/dev/stdout") ||
!strcmp(filename, "pipe:") ||
!strcmp(filename, "pipe:1")))
- mp_msg_stdout_in_use = 1;
+ mp_msg_force_stderr(global, true);
ctx = talloc_zero(NULL, struct encode_lavc_context);
+ ctx->log = mp_log_new(ctx, global->log, "encode-lavc");
+ ctx->global = global;
encode_lavc_discontinuity(ctx);
ctx->options = options;
@@ -153,7 +156,7 @@ struct encode_lavc_context *encode_lavc_init(struct encode_output_conf *options)
ctx->avc->oformat = av_guess_format(NULL, filename, NULL);
if (!ctx->avc->oformat) {
- encode_lavc_fail(ctx, "encode-lavc: format not found\n");
+ encode_lavc_fail(ctx, "format not found\n");
return NULL;
}
@@ -164,9 +167,8 @@ struct encode_lavc_context *encode_lavc_init(struct encode_output_conf *options)
if (ctx->options->fopts) {
char **p;
for (p = ctx->options->fopts; *p; ++p) {
- if (!set_to_avdictionary(&ctx->foptions, NULL, *p))
- mp_msg(MSGT_ENCODE, MSGL_WARN,
- "encode-lavc: could not set option %s\n", *p);
+ if (!set_to_avdictionary(ctx, &ctx->foptions, NULL, *p))
+ MP_WARN(ctx, "could not set option %s\n", *p);
}
}
@@ -210,7 +212,7 @@ struct encode_lavc_context *encode_lavc_init(struct encode_output_conf *options)
if (!ctx->vc && !ctx->ac) {
encode_lavc_fail(
- ctx, "encode-lavc: neither audio nor video codec was found\n");
+ ctx, "neither audio nor video codec was found\n");
return NULL;
}
@@ -249,7 +251,7 @@ int encode_lavc_start(struct encode_lavc_context *ctx)
break;
if (i >= ctx->avc->nb_streams) {
encode_lavc_fail(ctx,
- "encode-lavc: video stream missing, invalid codec?\n");
+ "video stream missing, invalid codec?\n");
return 0;
}
}
@@ -259,7 +261,7 @@ int encode_lavc_start(struct encode_lavc_context *ctx)
break;
if (i >= ctx->avc->nb_streams) {
encode_lavc_fail(ctx,
- "encode-lavc: audio stream missing, invalid codec?\n");
+ "audio stream missing, invalid codec?\n");
return 0;
}
}
@@ -267,12 +269,12 @@ int encode_lavc_start(struct encode_lavc_context *ctx)
ctx->header_written = -1;
if (!(ctx->avc->oformat->flags & AVFMT_NOFILE)) {
- mp_msg(MSGT_ENCODE, MSGL_INFO, "Opening output file: %s\n",
+ MP_INFO(ctx, "Opening output file: %s\n",
ctx->avc->filename);
if (avio_open(&ctx->avc->pb, ctx->avc->filename,
AVIO_FLAG_WRITE) < 0) {
- encode_lavc_fail(ctx, "encode-lavc: could not open '%s'\n",
+ encode_lavc_fail(ctx, "could not open '%s'\n",
ctx->avc->filename);
return 0;
}
@@ -280,17 +282,17 @@ int encode_lavc_start(struct encode_lavc_context *ctx)
ctx->t0 = mp_time_sec();
- mp_msg(MSGT_ENCODE, MSGL_INFO, "Opening muxer: %s [%s]\n",
+ MP_INFO(ctx, "Opening muxer: %s [%s]\n",
ctx->avc->oformat->long_name, ctx->avc->oformat->name);
if (avformat_write_header(ctx->avc, &ctx->foptions) < 0) {
- encode_lavc_fail(ctx, "encode-lavc: could not write header\n");
+ encode_lavc_fail(ctx, "could not write header\n");
return 0;
}
for (de = NULL; (de = av_dict_get(ctx->foptions, "", de,
AV_DICT_IGNORE_SUFFIX));)
- mp_msg(MSGT_ENCODE, MSGL_WARN, "ofopts: key '%s' not found.\n", de->key);
+ MP_WARN(ctx, "ofopts: key '%s' not found.\n", de->key);
av_dict_free(&ctx->foptions);
ctx->header_written = 1;
@@ -361,13 +363,12 @@ void encode_lavc_finish(struct encode_lavc_context *ctx)
ctx->twopass_bytebuffer_a = NULL;
}
- mp_msg(MSGT_ENCODE, MSGL_INFO, "vo-lavc: encoded %lld bytes\n",
+ MP_INFO(ctx, "vo-lavc: encoded %lld bytes\n",
ctx->vbytes);
- mp_msg(MSGT_ENCODE, MSGL_INFO, "ao-lavc: encoded %lld bytes\n",
+ MP_INFO(ctx, "ao-lavc: encoded %lld bytes\n",
ctx->abytes);
if (ctx->avc->pb) {
- mp_msg(MSGT_ENCODE, MSGL_INFO,
- "encode-lavc: muxing overhead %lld bytes\n",
+ MP_INFO(ctx, "muxing overhead %lld bytes\n",
(long long) (avio_size(ctx->avc->pb) - ctx->vbytes
- ctx->abytes));
avio_close(ctx->avc->pb);
@@ -398,16 +399,16 @@ static void encode_2pass_prepare(struct encode_lavc_context *ctx,
buf[sizeof(buf) - 1] = 0;
if (value_has_flag(de ? de->value : "", "pass2")) {
- if (!(*bytebuf = stream_open(buf, NULL))) {
- mp_msg(MSGT_ENCODE, MSGL_WARN, "%s: could not open '%s', "
+ if (!(*bytebuf = stream_open(buf, ctx->global))) {
+ MP_WARN(ctx, "%s: could not open '%s', "
"disabling 2-pass encoding at pass 2\n", prefix, buf);
stream->codec->flags &= ~CODEC_FLAG_PASS2;
- set_to_avdictionary(dictp, "flags", "-pass2");
+ set_to_avdictionary(ctx, dictp, "flags", "-pass2");
} else {
struct bstr content = stream_read_complete(*bytebuf, NULL,
1000000000);
if (content.start == NULL) {
- mp_msg(MSGT_ENCODE, MSGL_WARN, "%s: could not read '%s', "
+ MP_WARN(ctx, "%s: could not read '%s', "
"disabling 2-pass encoding at pass 1\n",
prefix, ctx->avc->filename);
} else {
@@ -420,13 +421,12 @@ static void encode_2pass_prepare(struct encode_lavc_context *ctx,
}
if (value_has_flag(de ? de->value : "", "pass1")) {
- if (!(*bytebuf = open_output_stream(buf, NULL))) {
- mp_msg(
- MSGT_ENCODE, MSGL_WARN,
+ if (!(*bytebuf = open_output_stream(buf, ctx->global))) {
+ MP_WARN(ctx,
"%s: could not open '%s', disabling "
"2-pass encoding at pass 1\n",
prefix, ctx->avc->filename);<