diff options
author | wm4 <wm4@nowhere> | 2013-12-21 20:24:20 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2013-12-21 21:43:16 +0100 |
commit | 3dbc9007b080028f0aebbbf8b9ab1233cd70c45b (patch) | |
tree | e6e46e5dd238338c44d421ef4f9101c9898c3cbf | |
parent | 9149e2af568d4cb251f8b105f360c3e6b9fd9d86 (diff) |
demux: mp_msg conversions
The TV code pretends to be part of stream/, but it's actually demuxer
code too. The audio_in code is shared between the TV code and
stream_radio.c, so stream_radio.c needs a small hack until stream.c is
converted.
-rw-r--r-- | common/playlist_parser.c | 2 | ||||
-rw-r--r-- | demux/demux.c | 96 | ||||
-rw-r--r-- | demux/demux.h | 7 | ||||
-rw-r--r-- | demux/demux_lavf.c | 59 | ||||
-rw-r--r-- | demux/demux_libass.c | 2 | ||||
-rw-r--r-- | demux/demux_mf.c | 10 | ||||
-rw-r--r-- | demux/demux_mkv.c | 297 | ||||
-rw-r--r-- | demux/demux_raw.c | 5 | ||||
-rw-r--r-- | demux/demux_subreader.c | 58 | ||||
-rw-r--r-- | demux/ebml.c | 72 | ||||
-rw-r--r-- | demux/ebml.h | 8 | ||||
-rw-r--r-- | demux/mf.c | 37 | ||||
-rw-r--r-- | demux/mf.h | 7 | ||||
-rw-r--r-- | player/loadfile.c | 5 | ||||
-rw-r--r-- | player/main.c | 2 | ||||
-rw-r--r-- | player/timeline/tl_cue.c | 4 | ||||
-rw-r--r-- | player/timeline/tl_matroska.c | 6 | ||||
-rw-r--r-- | player/timeline/tl_mpv_edl.c | 2 | ||||
-rw-r--r-- | stream/ai_alsa1x.c | 36 | ||||
-rw-r--r-- | stream/ai_oss.c | 42 | ||||
-rw-r--r-- | stream/ai_sndio.c | 4 | ||||
-rw-r--r-- | stream/audio_in.c | 19 | ||||
-rw-r--r-- | stream/audio_in.h | 5 | ||||
-rw-r--r-- | stream/stream_radio.c | 2 | ||||
-rw-r--r-- | stream/tv.c | 110 | ||||
-rw-r--r-- | stream/tv.h | 7 | ||||
-rw-r--r-- | stream/tvi_dummy.c | 6 | ||||
-rw-r--r-- | stream/tvi_v4l2.c | 195 |
28 files changed, 544 insertions, 561 deletions
diff --git a/common/playlist_parser.c b/common/playlist_parser.c index ee5fe07b91..f33f7204b6 100644 --- a/common/playlist_parser.c +++ b/common/playlist_parser.c @@ -539,7 +539,7 @@ static struct playlist *do_parse(struct stream* stream, bool forced, }; bool success = false; - struct demuxer *pl_demux = demux_open(stream, "playlist", NULL, global->opts); + struct demuxer *pl_demux = demux_open(stream, "playlist", NULL, global); if (pl_demux && pl_demux->playlist) { playlist_transfer_entries(p.pl, pl_demux->playlist); success = true; diff --git a/demux/demux.c b/demux/demux.c index 8d46f79391..7643b58a38 100644 --- a/demux/demux.c +++ b/demux/demux.c @@ -33,6 +33,7 @@ #include "common/av_common.h" #include "talloc.h" #include "common/msg.h" +#include "common/global.h" #include "stream/stream.h" #include "demux.h" @@ -225,7 +226,7 @@ struct demux_packet *demux_copy_packet(struct demux_packet *dp) struct sh_stream *new_sh_stream(demuxer_t *demuxer, enum stream_type type) { if (demuxer->num_streams > MAX_SH_STREAMS) { - mp_msg(MSGT_DEMUXER, MSGL_WARN, "Too many streams."); + MP_WARN(demuxer, "Too many streams."); return NULL; } @@ -353,8 +354,7 @@ int demuxer_add_packet(demuxer_t *demuxer, struct sh_stream *stream, if (stream->type != STREAM_VIDEO && dp->pts == MP_NOPTS_VALUE) dp->pts = dp->dts; - mp_msg(MSGT_DEMUXER, MSGL_DBG2, - "DEMUX: Append packet to %s, len=%d pts=%5.3f pos=%"PRIu64" " + MP_DBG(demuxer, "DEMUX: Append packet to %s, len=%d pts=%5.3f pos=%"PRIu64" " "[packs: A=%d V=%d S=%d]\n", stream_type_name(stream->type), dp->len, dp->pts, dp->pos, count_packs(demuxer, STREAM_AUDIO), count_packs(demuxer, STREAM_VIDEO), count_packs(demuxer, STREAM_SUB)); @@ -373,13 +373,13 @@ static bool demux_check_queue_full(demuxer_t *demux) overflow: if (!demux->warned_queue_overflow) { - mp_msg(MSGT_DEMUXER, MSGL_ERR, "\nToo many packets in the demuxer " - "packet queue (video: %d packets in %d bytes, audio: %d " - "packets in %d bytes, sub: %d packets in %d bytes).\n", - count_packs(demux, STREAM_VIDEO), count_bytes(demux, STREAM_VIDEO), - count_packs(demux, STREAM_AUDIO), count_bytes(demux, STREAM_AUDIO), - count_packs(demux, STREAM_SUB), count_bytes(demux, STREAM_SUB)); - mp_msg(MSGT_DEMUXER, MSGL_HINT, "Maybe you are playing a non-" + MP_ERR(demux, "\nToo many packets in the demuxer " + "packet queue (video: %d packets in %d bytes, audio: %d " + "packets in %d bytes, sub: %d packets in %d bytes).\n", + count_packs(demux, STREAM_VIDEO), count_bytes(demux, STREAM_VIDEO), + count_packs(demux, STREAM_AUDIO), count_bytes(demux, STREAM_AUDIO), + count_packs(demux, STREAM_SUB), count_bytes(demux, STREAM_SUB)); + MP_INFO(demux, "Maybe you are playing a non-" "interleaved stream/file or the codec failed?\n"); } demux->warned_queue_overflow = true; @@ -399,8 +399,8 @@ static void ds_get_packets(struct sh_stream *sh) { struct demux_stream *ds = sh->ds; demuxer_t *demux = sh->demuxer; - mp_msg(MSGT_DEMUXER, MSGL_DBG3, "ds_get_packets (%s) called\n", - stream_type_name(sh->type)); + MP_TRACE(demux, "ds_get_packets (%s) called\n", + stream_type_name(sh->type)); while (1) { if (ds->head) return; @@ -411,8 +411,8 @@ static void ds_get_packets(struct sh_stream *sh) if (!demux_fill_buffer(demux)) break; // EOF } - mp_msg(MSGT_DEMUXER, MSGL_V, "ds_get_packets: EOF reached (stream: %s)\n", - stream_type_name(sh->type)); + MP_VERBOSE(demux, "ds_get_packets: EOF reached (stream: %s)\n", + stream_type_name(sh->type)); ds->eof = 1; } @@ -476,16 +476,15 @@ bool demux_stream_eof(struct sh_stream *sh) // ==================================================================== -void demuxer_help(void) +void demuxer_help(struct mp_log *log) { int i; - mp_msg(MSGT_DEMUXER, MSGL_INFO, "Available demuxers:\n"); - mp_msg(MSGT_DEMUXER, MSGL_INFO, " demuxer: info:\n"); - mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_DEMUXERS\n"); + mp_info(log, "Available demuxers:\n"); + mp_info(log, " demuxer: info:\n"); for (i = 0; demuxer_list[i]; i++) { - mp_msg(MSGT_DEMUXER, MSGL_INFO, "%10s %s\n", - demuxer_list[i]->name, demuxer_list[i]->desc); + mp_info(log, "%10s %s\n", + demuxer_list[i]->name, demuxer_list[i]->desc); } } @@ -500,7 +499,8 @@ static const char *d_level(enum demux_check level) abort(); } -static struct demuxer *open_given_type(struct MPOpts *opts, +static struct demuxer *open_given_type(struct mpv_global *global, + struct mp_log *log, const struct demuxer_desc *desc, struct stream *stream, struct demuxer_params *params, @@ -516,25 +516,26 @@ static struct demuxer *open_given_type(struct MPOpts *opts, stream->end_pos > 0, .accurate_seek = true, .filepos = -1, - .opts = opts, + .opts = global->opts, + .global = global, + .log = mp_log_new(demuxer, log, desc->name), .filename = talloc_strdup(demuxer, stream->url), .metadata = talloc_zero(demuxer, struct mp_tags), }; demuxer->params = params; // temporary during open() stream_seek(stream, stream->start_pos); - mp_msg(MSGT_DEMUXER, MSGL_V, "Trying demuxer: %s (force-level: %s)\n", - desc->name, d_level(check)); + mp_verbose(log, "Trying demuxer: %s (force-level: %s)\n", + desc->name, d_level(check)); int ret = demuxer->desc->open(demuxer, check); if (ret >= 0) { demuxer->params = NULL; if (demuxer->filetype) - mp_msg(MSGT_DEMUXER, MSGL_INFO, "Detected file format: %s (%s)\n", + mp_info(log, "Detected file format: %s (%s)\n", demuxer->filetype, desc->desc); else - mp_msg(MSGT_DEMUXER, MSGL_INFO, "Detected file format: %s\n", - desc->desc); + mp_info(log, "Detected file format: %s\n", desc->desc); if (stream_manages_timeline(demuxer->stream)) { // Incorrect, but fixes some behavior with DVD/BD demuxer->ts_resets_possible = false; @@ -548,8 +549,8 @@ static struct demuxer *open_given_type(struct MPOpts *opts, demux_info_update(demuxer); // Pretend we can seek if we can't seek, but there's a cache. if (!demuxer->seekable && stream->uncached_stream) { - mp_msg(MSGT_DEMUXER, MSGL_WARN, - "File is not seekable, but there's a cache: enabling seeking.\n"); + mp_warn(log, + "File is not seekable, but there's a cache: enabling seeking.\n"); demuxer->seekable = true; } return demuxer; @@ -564,10 +565,13 @@ static const int d_request[] = {DEMUX_CHECK_REQUEST, -1}; static const int d_force[] = {DEMUX_CHECK_FORCE, -1}; struct demuxer *demux_open(struct stream *stream, char *force_format, - struct demuxer_params *params, struct MPOpts *opts) + struct demuxer_params *params, + struct mpv_global *global) { const int *check_levels = d_normal; const struct demuxer_desc *check_desc = NULL; + struct mp_log *log = mp_log_new(NULL, global->log, "!demux"); + struct demuxer *demuxer = NULL; if (!force_format) force_format = stream->demuxer; @@ -583,9 +587,8 @@ struct demuxer *demux_open(struct stream *stream, char *force_format, check_desc = demuxer_list[n]; } if (!check_desc) { - mp_msg(MSGT_DEMUXER, MSGL_ERR, "Demuxer %s does not exist.\n", - force_format); - return NULL; + mp_err(log, "Demuxer %s does not exist.\n", force_format); + goto done; } } @@ -599,15 +602,16 @@ struct demuxer *demux_open(struct stream *stream, char *force_format, for (int n = 0; demuxer_list[n]; n++) { const struct demuxer_desc *desc = demuxer_list[n]; if (!check_desc || desc == check_desc) { - struct demuxer *demuxer = open_given_type(opts, desc, stream, - params, level); + demuxer = open_given_type(global, log, desc, stream, params, level); if (demuxer) - return demuxer; + goto done; } } } - return NULL; +done: + talloc_free(log); + return demuxer; } void demux_flush(demuxer_t *demuxer) @@ -620,7 +624,7 @@ void demux_flush(demuxer_t *demuxer) int demux_seek(demuxer_t *demuxer, float rel_seek_secs, int flags) { if (!demuxer->seekable) { - mp_msg(MSGT_DEMUXER, MSGL_WARN, "Cannot seek in this file.\n"); + MP_WARN(demuxer, "Cannot seek in this file.\n"); return 0; } @@ -716,7 +720,7 @@ int demux_info_add_bstr(demuxer_t *demuxer, struct bstr opt, struct bstr param) if (oldval) { if (bstrcmp0(param, oldval) == 0) return 0; - mp_msg(MSGT_DEMUX, MSGL_INFO, "Demuxer info %.*s changed to %.*s\n", + MP_INFO(demuxer, "Demuxer info %.*s changed to %.*s\n", BSTR_P(opt), BSTR_P(param)); } @@ -732,16 +736,16 @@ int demux_info_print(demuxer_t *demuxer) if (!info || !info->num_keys) return 0; - mp_msg(MSGT_DEMUX, MSGL_INFO, "Clip info:\n"); + MP_INFO(demuxer, "Clip info:\n"); for (n = 0; n < info->num_keys; n++) { - mp_msg(MSGT_DEMUX, MSGL_INFO, " %s: %s\n", info->keys[n], - info->values[n]); - mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CLIP_INFO_NAME%d=%s\n", n, - info->keys[n]); - mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CLIP_INFO_VALUE%d=%s\n", n, + MP_INFO(demuxer, " %s: %s\n", info->keys[n], info->values[n]); + MP_SMODE(demuxer, "ID_CLIP_INFO_NAME%d=%s\n", n, + info->keys[n]); + MP_SMODE(demuxer, "ID_CLIP_INFO_VALUE%d=%s\n", n, + info->values[n]); } - mp_msg(MSGT_IDENTIFY, MSGL_INFO, "ID_CLIP_INFO_N=%d\n", n); + MP_SMODE(demuxer, "ID_CLIP_INFO_N=%d\n", n); return 0; } diff --git a/demux/demux.h b/demux/demux.h index 6d5253786f..7b25032011 100644 --- a/demux/demux.h +++ b/demux/demux.h @@ -194,6 +194,8 @@ typedef struct demuxer { void *priv; // demuxer-specific internal data struct MPOpts *opts; + struct mpv_global *global; + struct mp_log *log; struct demuxer_params *params; } demuxer_t; @@ -227,7 +229,8 @@ bool demux_stream_eof(struct sh_stream *sh); struct sh_stream *new_sh_stream(struct demuxer *demuxer, enum stream_type type); struct demuxer *demux_open(struct stream *stream, char *force_format, - struct demuxer_params *params, struct MPOpts *opts); + struct demuxer_params *params, + struct mpv_global *global); void demux_flush(struct demuxer *demuxer); int demux_seek(struct demuxer *demuxer, float rel_seek_secs, int flags); @@ -247,7 +250,7 @@ void demuxer_select_track(struct demuxer *demuxer, struct sh_stream *stream, bool selected); void demuxer_enable_autoselect(struct demuxer *demuxer); -void demuxer_help(void); +void demuxer_help(struct mp_log *log); int demuxer_add_attachment(struct demuxer *demuxer, struct bstr name, struct bstr type, struct bstr data); diff --git a/demux/demux_lavf.c b/demux/demux_lavf.c index 9057284c1e..ceef14f4d0 100644 --- a/demux/demux_lavf.c +++ b/demux/demux_lavf.c @@ -121,8 +121,7 @@ static int mp_read(void *opaque, uint8_t *buf, int size) ret = stream_read(stream, buf, size); - mp_msg(MSGT_HEADER, MSGL_DBG2, - "%d=mp_read(%p, %p, %d), pos: %"PRId64", eof:%d\n", + MP_DBG(demuxer, "%d=mp_read(%p, %p, %d), pos: %"PRId64", eof:%d\n", ret, stream, buf, size, stream_tell(stream), stream->eof); return ret; } @@ -132,7 +131,7 @@ static int64_t mp_seek(void *opaque, int64_t pos, int whence) struct demuxer *demuxer = opaque; struct stream *stream = demuxer->stream; int64_t current_pos; - mp_msg(MSGT_HEADER, MSGL_DBG2, "mp_seek(%p, %"PRId64", %d)\n", + MP_DBG(demuxer, "mp_seek(%p, %"PRId64", %d)\n", stream, pos, whence); if (whence == SEEK_CUR) pos += stream_tell(stream); @@ -171,12 +170,12 @@ static int64_t mp_read_seek(void *opaque, int stream_idx, int64_t ts, int flags) return ret; } -static void list_formats(void) +static void list_formats(struct demuxer *demuxer) { - mp_msg(MSGT_DEMUX, MSGL_INFO, "Available lavf input formats:\n"); + MP_INFO(demuxer, "Available lavf input formats:\n"); AVInputFormat *fmt = NULL; while ((fmt = av_iformat_next(fmt))) - mp_msg(MSGT_DEMUX, MSGL_INFO, "%15s : %s\n", fmt->name, fmt->long_name); + MP_INFO(demuxer, "%15s : %s\n", fmt->name, fmt->long_name); } static char *remove_prefix(char *s, const char **prefixes) @@ -206,7 +205,7 @@ static int lavf_check_file(demuxer_t *demuxer, enum demux_check check) priv->filename = s->url; if (!priv->filename) { priv->filename = "mp:unknown"; - mp_msg(MSGT_DEMUX, MSGL_WARN, "Stream url is not set!\n"); + MP_WARN(demuxer, "Stream url is not set!\n"); } priv->filename = remove_prefix(priv->filename, prefixes); @@ -216,8 +215,7 @@ static int lavf_check_file(demuxer_t *demuxer, enum demux_check check) // always require filename in the form "format:filename" char *sep = strchr(priv->filename, ':'); if (!sep) { - mp_msg(MSGT_DEMUX, MSGL_FATAL, - "Must specify filename in 'format:filename' form\n"); + MP_FATAL(demuxer, "Must specify filename in 'format:filename' form\n"); return -1; } avdevice_format = talloc_strndup(priv, priv->filename, @@ -244,15 +242,15 @@ static int lavf_check_file(demuxer_t *demuxer, enum demux_check check) format = avdevice_format; if (format) { if (strcmp(format, "help") == 0) { - list_formats(); + list_formats(demuxer); return -1; } priv->avif = av_find_input_format(format); if (!priv->avif) { - mp_msg(MSGT_DEMUX, MSGL_FATAL, "Unknown lavf format %s\n", format); + MP_FATAL(demuxer, "Unknown lavf format %s\n", format); return -1; } - mp_msg(MSGT_DEMUX, MSGL_INFO, "Forced lavf %s demuxer\n", + MP_INFO(demuxer, "Forced lavf %s demuxer\n", priv->avif->long_name); goto success; } @@ -284,7 +282,7 @@ static int lavf_check_file(demuxer_t *demuxer, enum demux_check check) priv->avif = av_probe_input_format2(&avpd, avpd.buf_size > 0, &score); if (priv->avif) { - mp_msg(MSGT_HEADER, MSGL_V, "Found '%s' at score=%d size=%d.\n", + MP_VERBOSE(demuxer, "Found '%s' at score=%d size=%d.\n", priv->avif->name, score, avpd.buf_size); if (score >= min_probe) @@ -305,7 +303,7 @@ static int lavf_check_file(demuxer_t *demuxer, enum demux_check check) if (priv->avif && !format) { for (int n = 0; format_blacklist[n]; n++) { if (strcmp(format_blacklist[n], priv->avif->name) == 0) { - mp_msg(MSGT_HEADER, MSGL_V, "Format blacklisted.\n"); + MP_VERBOSE(demuxer, "Format blacklisted.\n"); priv->avif = NULL; break; } @@ -313,8 +311,7 @@ static int lavf_check_file(demuxer_t *demuxer, enum demux_check check) } if (!priv->avif) { - mp_msg(MSGT_HEADER, MSGL_V, - "No format found, try lowering probescore or forcing the format.\n"); + MP_VERBOSE(demuxer, "No format found, try lowering probescore or forcing the format.\n"); return -1; } @@ -444,7 +441,7 @@ static void handle_stream(demuxer_t *demuxer, int i) // This also applies to vfw-muxed mkv, but we can't detect these easily. sh_video->avi_dts = matches_avinputformat_name(priv, "avi"); - mp_msg(MSGT_DEMUX, MSGL_DBG2, "aspect= %d*%d/(%d*%d)\n", + MP_DBG(demuxer, "aspect= %d*%d/(%d*%d)\n", codec->width, codec->sample_aspect_ratio.num, codec->height, codec->sample_aspect_ratio.den); break; @@ -542,8 +539,7 @@ static int demux_open_lavf(demuxer_t *demuxer, enum demux_check check) if (lavfdopts->probesize) { if (av_opt_set_int(avfc, "probesize", lavfdopts->probesize, 0) < 0) - mp_msg(MSGT_HEADER, MSGL_ERR, - "demux_lavf, couldn't set option probesize to %u\n", + MP_ERR(demuxer, "demux_lavf, couldn't set option probesize to %u\n", lavfdopts->probesize); } @@ -554,14 +550,13 @@ static int demux_open_lavf(demuxer_t *demuxer, enum demux_check check) if (analyze_duration > 0) { if (av_opt_set_int(avfc, "analyzeduration", analyze_duration * AV_TIME_BASE, 0) < 0) - mp_msg(MSGT_HEADER, MSGL_ERR, "demux_lavf, couldn't set option " + MP_ERR(demuxer, "demux_lavf, couldn't set option " "analyzeduration to %f\n", analyze_duration); } if (lavfdopts->avopt) { if (parse_avopts(avfc, lavfdopts->avopt) < 0) { - mp_msg(MSGT_HEADER, MSGL_ERR, - "Your options /%s/ look like gibberish to me pal\n", + MP_ERR(demuxer, "Your options /%s/ look like gibberish to me pal\n", lavfdopts->avopt); return -1; } @@ -601,27 +596,25 @@ static int demux_open_lavf(demuxer_t *demuxer, enum demux_check check) } if (avformat_open_input(&avfc, priv->filename, priv->avif, &dopts) < 0) { - mp_msg(MSGT_HEADER, MSGL_ERR, - "LAVF_header: avformat_open_input() failed\n"); + MP_ERR(demuxer, "LAVF_header: avformat_open_input() failed\n"); av_dict_free(&dopts); return -1; } t = NULL; while ((t = av_dict_get(dopts, "", t, AV_DICT_IGNORE_SUFFIX))) { - mp_msg(MSGT_OPEN, MSGL_V, "[lavf] Could not set demux option %s=%s\n", + MP_VERBOSE(demuxer, "[lavf] Could not set demux option %s=%s\n", t->key, t->value); } av_dict_free(&dopts); priv->avfc = avfc; if (avformat_find_stream_info(avfc, NULL) < 0) { - mp_msg(MSGT_HEADER, MSGL_ERR, - "LAVF_header: av_find_stream_info() failed\n"); + MP_ERR(demuxer, "LAVF_header: av_find_stream_info() failed\n"); return -1; } - mp_msg(MSGT_HEADER, MSGL_V, "demux_lavf: avformat_find_stream_info() " + MP_VERBOSE(demuxer, "demux_lavf: avformat_find_stream_info() " "finished after %"PRId64" bytes.\n", stream_tell(demuxer->stream)); for (i = 0; i < avfc->nb_chapters; i++) { @@ -658,13 +651,13 @@ static int demux_open_lavf(demuxer_t *demuxer, enum demux_check check) for (p = 0; p < avfc->nb_programs; p++) { AVProgram *program = avfc->programs[p]; t = av_dict_get(program->metadata, "title", NULL, 0); - mp_msg(MSGT_HEADER, MSGL_INFO, "LAVF: Program %d %s\n", + MP_INFO(demuxer, "LAVF: Program %d %s\n", program->id, t ? t->value : ""); - mp_msg(MSGT_IDENTIFY, MSGL_V, "PROGRAM_ID=%d\n", program->id); + MP_VERBOSE(demuxer, "PROGRAM_ID=%d\n", program->id); } } - mp_msg(MSGT_HEADER, MSGL_V, "LAVF: build %d\n", LIBAVFORMAT_BUILD); + MP_VERBOSE(demuxer, "LAVF: build %d\n", LIBAVFORMAT_BUILD); demuxer->ts_resets_possible = priv->avif->flags & AVFMT_TS_DISCONT; @@ -680,7 +673,7 @@ static int demux_lavf_fill_buffer(demuxer_t *demux) { lavf_priv_t *priv = demux->priv; demux_packet_t *dp; - mp_msg(MSGT_DEMUX, MSGL_DBG2, "demux_lavf_fill_buffer()\n"); + MP_DBG(demux, "demux_lavf_fill_buffer()\n"); AVPacket *pkt = talloc(NULL, AVPacket); if (av_read_frame(priv->avfc, pkt) < 0) { @@ -737,7 +730,7 @@ static void demux_seek_lavf(demuxer_t *demuxer, float rel_seek_secs, int flags) { lavf_priv_t *priv = demuxer->priv; int avsflags = 0; - mp_msg(MSGT_DEMUX, MSGL_DBG2, "demux_seek_lavf(%p, %f, %d)\n", + MP_DBG(demuxer, "demux_seek_lavf(%p, %f, %d)\n", demuxer, rel_seek_secs, flags); if (flags & SEEK_ABSOLUTE) diff --git a/demux/demux_libass.c b/demux/demux_libass.c index f01b999d9e..15f5195cfc 100644 --- a/demux/demux_libass.c +++ b/demux/demux_libass.c @@ -73,7 +73,7 @@ static int d_check_file(struct demuxer *demuxer, enum demux_check check) bstr buf = stream_read_complete(s, NULL, 100000000); if (!buf.start) { - mp_msg(MSGT_ASS, MSGL_ERR, "Refusing to load subtitle file " + MP_ERR(demuxer, "Refusing to load subtitle file " "larger than 100 MB: %s\n", demuxer->filename); return -1; } diff --git a/demux/demux_mf.c b/demux/demux_mf.c index 876b17a025..1d80cfaa85 100644 --- a/demux/demux_mf.c +++ b/demux/demux_mf.c @@ -158,11 +158,9 @@ static const char *probe_format(mf_t *mf, enum demux_check check) } if (check == DEMUX_CHECK_REQUEST) { if (!mf_type) { - mp_msg(MSGT_DEMUX, MSGL_ERR, - "[demux_mf] file type was not set! (try --mf-type=ext)\n"); + MP_ERR(mf, "file type was not set! (try --mf-type=ext)\n"); } else { - mp_msg(MSGT_DEMUX, MSGL_ERR, - "[demux_mf] --mf-type set to an unknown codec!\n"); + MP_ERR(mf, "--mf-type set to an unknown codec!\n"); } } return NULL; @@ -175,9 +173,9 @@ static int demux_open_mf(demuxer_t *demuxer, enum demux_check check) if (strncmp(demuxer->stream->url, "mf://", 5) == 0 && demuxer->stream->type == STREAMTYPE_MF) - mf = open_mf_pattern(demuxer, demuxer->stream->url + 5); + mf = open_mf_pattern(demuxer, demuxer->log, demuxer->stream->url + 5); else { - mf = open_mf_single(demuxer, demuxer->stream->url); + mf = open_mf_single(demuxer, demuxer->log, demuxer->stream->url); int bog = 0; MP_TARRAY_APPEND(mf, mf->streams, bog, demuxer->stream); } diff --git a/demux/demux_mkv.c b/demux/demux_mkv.c index 52ab592eb0..8c3189b539 100644 --- a/demux/demux_mkv.c +++ b/demux/demux_mkv.c @@ -249,7 +249,8 @@ static int aac_get_sample_rate_index(uint32_t sample_rate) return i; } -static bstr demux_mkv_decode(mkv_track_t *track, bstr data, uint32_t type) +static bstr demux_mkv_decode(struct mp_log *log, mkv_track_t *track, + bstr data, uint32_t type) { uint8_t *src = data.start; uint8_t *orig_src = src; @@ -278,8 +279,7 @@ static bstr demux_mkv_decode(mkv_track_t *track, bstr data, uint32_t type) zstream.zfree = (free_func) 0; zstream.opaque = (voidpf) 0; if (inflateInit(&zstream) != Z_OK) { - mp_msg(MSGT_DEMUX, MSGL_WARN, - "[mkv] zlib initialization failed.\n"); + mp_warn(log, "zlib initialization failed.\n"); goto error; } zstream.next_in = (Bytef *) src; @@ -294,8 +294,7 @@ static bstr demux_mkv_decode(mkv_track_t *track, bstr data, uint32_t type) zstream.next_out = (Bytef *) (dest + zstream.total_out); result = inflate(&zstream, Z_NO_FLUSH); if (result != Z_OK && result != Z_STREAM_END) { - mp_msg(MSGT_DEMUX, MSGL_WARN, - "[mkv] zlib decompression failed.\n"); + mp_warn(log, "zlib decompression failed.\n"); talloc_free(dest); dest = NULL; inflateEnd(&zstream); @@ -323,14 +322,12 @@ static bstr demux_mkv_decode(mkv_track_t *track, bstr data, uint32_t type) if (result == 0) break; if (!(result & AV_LZO_OUTPUT_FULL)) { - mp_msg(MSGT_DEMUX, MSGL_WARN, - "[mkv] lzo decompression failed.\n"); + mp_warn(log, "lzo decompression failed.\n"); talloc_free(dest); dest = NULL; goto error; } - mp_msg(MSGT_DEMUX, MSGL_DBG2, - "[mkv] lzo decompression buffer too small.\n"); + mp_dbg(log, "lzo decompression buffer too small.\n"); dstlen *= 2; } size = dstlen - out_avail; @@ -359,17 +356,16 @@ static int demux_mkv_read_info(demuxer_t *demuxer) mkv_d->duration = 0; struct ebml_info info = {0}; - struct ebml_parse_ctx parse_ctx = {0}; + struct ebml_parse_ctx parse_ctx = {demuxer->log}; if (ebml_read_element(s, &parse_ctx, &info, &ebml_info_desc) < 0) return -1; if (info.n_timecode_scale) { mkv_d->tc_scale = info.timecode_scale; - mp_msg(MSGT_DEMUX, MSGL_V, - "[mkv] | + timecode scale: %" PRIu64 "\n", mkv_d->tc_scale); + MP_VERBOSE(demuxer, "| + timecode scale: %" PRIu64 "\n", mkv_d->tc_scale); } if (info.n_duration) { mkv_d->duration = info.duration * mkv_d->tc_scale / 1e9; - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + duration: %.3fs\n", + MP_VERBOSE(demuxer, "| + duration: %.3fs\n", mkv_d->duration); } if (info.n_title) { @@ -378,16 +374,15 @@ static int demux_mkv_read_info(demuxer_t *demuxer) if (info.n_segment_uid) { int len = info.segment_uid.len; if (len != sizeof(demuxer->matroska_data.uid.segment)) { - mp_msg(MSGT_DEMUX, MSGL_INFO, - "[mkv] segment uid invalid length %d\n", len); + MP_INFO(demuxer, "segment uid invalid length %d\n", len); } else { memcpy(demuxer->matroska_data.uid.segment, info.segment_uid.start, len); - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + segment uid"); + MP_VERBOSE(demuxer, "| + segment uid"); for (int i = 0; i < len; i++) - mp_msg(MSGT_DEMUX, MSGL_V, " %02x", + MP_VERBOSE(demuxer, " %02x", demuxer->matroska_data.uid.segment[i]); - mp_msg(MSGT_DEMUX, MSGL_V, "\n"); + MP_VERBOSE(demuxer, "\n"); } } if (demuxer->params && demuxer->params->matroska_wanted_uids) { @@ -400,8 +395,7 @@ static int demux_mkv_read_info(demuxer_t *demuxer) } } } - mp_msg(MSGT_DEMUX, MSGL_INFO, - "[mkv] This is not one of the wanted files. " + MP_INFO(demuxer, "This is not one of the wanted files. " "Stopping attempt to open.\n"); res = -2; } @@ -439,29 +433,26 @@ static void parse_trackencodings(struct demuxer *demuxer, } if (e.type == 1) { - mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Track " + MP_WARN(demuxer, "Track " "number %u has been encrypted and " "decryption has not yet been\n" - "[mkv] implemented. Skipping track.\n", + "implemented. Skipping track.\n", track->tnum); } else if (e.type != 0) { - mp_msg(MSGT_DEMUX, MSGL_WARN, - "[mkv] Unknown content encoding type for " + MP_WARN(demuxer, "Unknown content encoding type for " "track %u. Skipping track.\n", track->tnum); } else if (e.comp_algo != 0 && e.comp_algo != 2 && e.comp_algo != 3) { - mp_msg(MSGT_DEMUX, MSGL_WARN, - "[mkv] Track %u has been compressed with " + MP_WARN(demuxer, "Track %u has been compressed with " "an unknown/unsupported compression\n" - "[mkv] algorithm (%" PRIu64 "). Skipping track.\n", + "algorithm (%" PRIu64 "). Skipping track.\n", track->tnum, e.comp_algo); } #if !HAVE_ZLIB else if (e.comp_algo == 0) { - mp_msg(MSGT_DEMUX, MSGL_WARN, - "[mkv] Track %u was compressed with zlib " + MP_WARN(demuxer, "Track %u was compressed with zlib " "but mpv has not been compiled\n" - "[mkv] with support for zlib compression. " + "with support for zlib compression. " "Skipping track.\n", track->tnum); } @@ -485,26 +476,24 @@ static void parse_trackaudio(struct demuxer *demuxer, struct mkv_track *track, { if (audio->n_sampling_frequency) { track->a_sfreq = audio->sampling_frequency; - mp_msg(MSGT_DEMUX, MSGL_V, - "[mkv] | + Sampling frequency: %f\n", track->a_sfreq); + MP_VERBOSE(demuxer, "| + Sampling frequency: %f\n", track->a_sfreq); } else { track->a_sfreq = 8000; } if (audio->n_output_sampling_frequency) { track->a_osfreq = audio->output_sampling_frequency; - mp_msg(MSGT_DEMUX, MSGL_V, - "[mkv] | + Output sampling frequency: %f\n", track->a_osfreq); + MP_VERBOSE(demuxer, "| + Output sampling frequency: %f\n", track->a_osfreq); } else { track->a_osfreq = track->a_sfreq; } if (audio->n_bit_depth) { track->a_bps = audio->bit_depth; - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Bit depth: %u\n", + MP_VERBOSE(demuxer, "| + Bit depth: %u\n", track->a_bps); } if (audio->n_channels) { track->a_channels = audio->channels; - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Channels: %u\n", + MP_VERBOSE(demuxer, "| + Channels: %u\n", track->a_channels); } else { track->a_channels = 1; @@ -516,7 +505,7 @@ static void parse_trackvideo(struct demuxer *demuxer, struct mkv_track *track, { if (video->n_frame_rate) { track->v_frate = video->frame_rate; - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Frame rate: %f\n", + MP_VERBOSE(demuxer, "| + Frame rate: %f\n", track->v_frate); if (track->v_frate > 0) track->default_duration = 1 / track->v_frate; @@ -524,29 +513,29 @@ static void parse_trackvideo(struct demuxer *demuxer, struct mkv_track *track, if (video->n_display_width) { track->v_dwidth = video->display_width; track->v_dwidth_set = true; - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Display width: %u\n", + MP_VERBOSE(demuxer, "| + Display width: %u\n", track->v_dwidth); } if (video->n_display_height) { track->v_dheight = video->display_height; track->v_dheight_set = true; - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Display height: %u\n", + MP_VERBOSE(demuxer, "| + Display height: %u\n", track->v_dheight); } if (video->n_pixel_width) { track->v_width = video->pixel_width; - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Pixel width: %u\n", + MP_VERBOSE(demuxer, "| + Pixel width: %u\n", track->v_width); } if (video->n_pixel_height) { track->v_height = video->pixel_height; - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Pixel height: %u\n", + MP_VERBOSE(demuxer, "| + Pixel height: %u\n", track->v_height); } if (video->n_colour_space && video->colour_space.len == 4) { uint8_t *d = (uint8_t *)&video->colour_space.start[0]; track->colorspace = d[0] | (d[1] << 8) | (d[2] << 16) | (d[3] << 24); - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Colorspace: %#x\n", + MP_VERBOSE(demuxer, "| + Colorspace: %#x\n", (unsigned int)track->colorspace); } } @@ -569,43 +558,43 @@ static void parse_trackentry(struct demuxer *demuxer, track->tnum = entry->track_number; if (track->tnum) { - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Track number: %u\n", + MP_VERBOSE(demuxer, "| + Track number: %u\n", track->tnum); } else { - mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] Missing track number!\n"); + MP_ERR(demuxer, "Missing track number!\n"); } if (entry->n_name) { track->name = talloc_strndup(track, entry->name.start, entry->name.len); - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Name: %s\n", + MP_VERBOSE(demuxer, "| + Name: %s\n", track->name); } track->type = entry->track_type; - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Track type: "); + MP_VERBOSE(demuxer, "| + Track type: "); switch (track->type) { case MATROSKA_TRACK_AUDIO: - mp_msg(MSGT_DEMUX, MSGL_V, "Audio\n"); + MP_VERBOSE(demuxer, "Audio\n"); break; case MATROSKA_TRACK_VIDEO: - mp_msg(MSGT_DEMUX, MSGL_V, "Video\n"); + MP_VERBOSE(demuxer, "Video\n"); break; case MATROSKA_TRACK_SUBTITLE: - mp_msg(MSGT_DEMUX, MSGL_V, "Subtitle\n"); + MP_VERBOSE(demuxer, "Subtitle\n"); break; default: - mp_msg(MSGT_DEMUX, MSGL_V, "unknown\n"); + MP_VERBOSE(demuxer, "unknown\n"); break; } if (entry->n_audio) { - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Audio track\n"); + MP_VERBOSE(demuxer, "| + Audio track\n"); parse_trackaudio(demuxer, track, &entry->audio); } if (entry->n_video) { - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Video track\n"); + MP_VERBOSE(demuxer, "| + Video track\n"); parse_trackvideo(demuxer, track, &entry->video); } @@ -615,10 +604,10 @@ static void parse_trackentry(struct demuxer *demuxer, if (!strcmp(track->codec_id, MKV_V_MSCOMP) || !strcmp(track->codec_id, MKV_A_ACM)) track->ms_compat = 1; - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Codec ID: %s\n", + MP_VERBOSE(demuxer, "| + Codec ID: %s\n", track->codec_id); } else { - mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] Missing codec ID!\n"); + MP_ERR(demuxer, "Missing codec ID!\n"); track->codec_id = ""; } @@ -627,14 +616,14 @@ static void parse_trackentry(struct demuxer *demuxer, track->private_data = talloc_size(track, len + AV_LZO_INPUT_PADDING); memcpy(track->private_data, entry->codec_private.start, len); track->private_size = len; - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + CodecPrivate, length %u\n", + MP_VERBOSE(demuxer, "| + CodecPrivate, length %u\n", track->private_size); } if (entry->n_language) { track->language = talloc_strndup(track, entry->language.start, entry->language.len); - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Language: %s\n", + MP_VERBOSE(demuxer, "| + Language: %s\n", track->language); } else { track->language = talloc_strdup(track, "eng"); @@ -642,7 +631,7 @@ static void parse_trackentry(struct demuxer *demuxer, if (entry->n_flag_default) { track->default_track = entry->flag_default; - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Default flag: %u\n", + MP_VERBOSE(demuxer, "| + Default flag: %u\n", track->default_track); } else { track->default_track = 1; @@ -651,12 +640,11 @@ static void parse_trackentry(struct demuxer *demuxer, if (entry->n_default_duration) { track->default_duration = entry->default_duration / 1e9; if (entry->default_duration == 0) { - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + Default duration: 0"); + MP_VERBOSE(demuxer, "| + Default duration: 0"); } else { if (!track->v_frate) track->v_frate = 1e9 / entry->default_duration; - mp_msg(MSGT_DEMUX, MSGL_V, - "[mkv] | + Default duration: %.3fms ( = %.3f fps)\n", + MP_VERBOSE(demuxer, "| + Default duration: %.3fms ( = %.3f fps)\n", entry->default_duration / 1000000.0, track->v_frate); } } @@ -673,14 +661,14 @@ static int demux_mkv_read_tracks(demuxer_t *demuxer) stream_t *s = demuxer->stream; struct ebml_tracks tracks = {0}; - struct ebml_parse_ctx parse_ctx = {0}; + struct ebml_parse_ctx parse_ctx = {demuxer->log}; if (ebml_read_element(s, &parse_ctx, &tracks, &ebml_tracks_desc) < 0) return -1; mkv_d->tracks = talloc_size(mkv_d, tracks.n_track_entry * sizeof(*mkv_d->tracks)); for (int i = 0; i < tracks.n_track_entry; i++) { - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] | + a track...\n"); + MP_VERBOSE(demuxer, "| + a track...\n"); parse_trackentry(demuxer, &tracks.track_entry[i]); } talloc_free(parse_ctx.talloc_ctx); @@ -730,9 +718,9 @@ static int demux_mkv_read_cues(demuxer_t *demuxer) return 0; } - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] /---- [ parsing cues ] -----------\n"); + MP_VERBOSE(demuxer, "/---- [ parsing cues ] -----------\n"); struct ebml_cues cues = {0}; - struct ebml_parse_ctx parse_ctx = {0}; + struct ebml_parse_ctx parse_ctx = {demuxer->log}; if (ebml_read_element(s, &parse_ctx, &cues, &ebml_cues_desc) < 0) return -1; @@ -741,7 +729,7 @@ static int demux_mkv_read_cues(demuxer_t *demuxer) for (int i = 0; i < cues.n_cue_point; i++) { struct ebml_cue_point *cuepoint = &cues.cue_point[i]; if (cuepoint->n_cue_time != 1 || !cuepoint->n_cue_track_positions) { - mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Malformed CuePoint element\n"); + MP_WARN(demuxer, "Malformed CuePoint element\n"); continue; } uint64_t time = cuepoint->cue_time; @@ -750,8 +738,7 @@ static int demux_mkv_read_cues(demuxer_t *demuxer) &cuepoint->cue_track_positions[c]; uint64_t pos = mkv_d->segment_start + trackpos->cue_cluster_position; cue_index_add(demuxer, trackpos->cue_track, pos, time); - mp_msg(MSGT_DEMUX, MSGL_DBG2, - "[mkv] |+ found cue point for track %" PRIu64 + MP_DBG(demuxer, "|+ found cue point for track %" PRIu64 ": timecode %" PRIu64 ", filepos: %" PRIu64 "\n", trackpos->cue_track, time, pos); } @@ -760,7 +747,7 @@ static int demux_mkv_read_cues(demuxer_t *demuxer) // Do not attempt to create index on the fly. mkv_d->index_complete = true; - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] \\---- [ parsing cues ] -----------\n"); + MP_VERBOSE(demuxer, "\\---- [ parsing cues ] -----------\n"); talloc_free(parse_ctx.talloc_ctx); return 0; } @@ -774,11 +761,11 @@ static void read_deferred_cues(demuxer_t *demuxer) int64_t pos = mkv_d->deferred_cues; mkv_d->deferred_cues = 0; if (!stream_seek(s, pos)) { - mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Failed to seek to cues\n"); + MP_WARN(demuxer, "Failed to seek to cues\n"); return; } if (ebml_read_id(s, NULL) != MATROSKA_ID_CUES) { - mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Expected element not found\n"); + MP_WARN(demuxer, "Expected element not found\n"); return; } demux_mkv_read_cues(demuxer); @@ -797,9 +784,9 @@ static int demux_mkv_read_chapters(struct demuxer *demuxer) if (wanted_edition_uid) wanted_edition = -1; - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] /---- [ parsing chapters ] ---------\n"); + MP_VERBOSE(demuxer, "/---- [ parsing chapters ] ---------\n"); struct ebml_chapters file_chapters = {0}; - struct ebml_parse_ctx parse_ctx = {0}; + struct ebml_parse_ctx parse_ctx = {demuxer->log}; if (ebml_read_element(s, &parse_ctx, &file_chapters, &ebml_chapters_desc) < 0) return -1; @@ -809,7 +796,7 @@ static int demux_mkv_read_chapters(struct demuxer *demuxer) struct ebml_edition_entry *editions = file_chapters.edition_entry; if (wanted_edition >= 0 && wanted_edition < num_editions) { selected_edition = wanted_edition; - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] User-specified edition: %d\n", + MP_VERBOSE(demuxer, "User-specified edition: %d\n", selected_edition); } else { for (int i = 0; i < num_editions; i++) { @@ -819,15 +806,14 @@ static int demux_mkv_read_chapters(struct demuxer *demuxer) break; } else if (editions[i].edition_flag_default) { selected_edition = i; - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Default edition: %d\n", i); + MP_VERBOSE(demuxer, "Default edition: %d\n", i); break; } } } if (selected_edition < 0) { if (wanted_edition_uid) { - mp_msg(MSGT_DEMUX, MSGL_ERR, - "[mkv] Unable to find expected edition uid: %"PRIu64"\n", + MP_ERR(demuxer, "Unable to find expected edition uid: %"PRIu64"\n", wanted_edition_uid); return -1; } else { @@ -836,13 +822,13 @@ static int demux_mkv_read_chapters(struct demuxer *demuxer) } for (int idx = 0; idx < num_editions; idx++) { - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] New edition %d\n", idx); + MP_VERBOSE(demuxer, "New edition %d\n", idx); int warn_level = idx == selected_edition ? MSGL_WARN : MSGL_V; if (editions[idx].n_edition_flag_default) - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Default edition flag: %"PRIu64 + MP_VERBOSE(demuxer, "Default edition flag: %"PRIu64 "\n", editions[idx].edition_flag_default); if (editions[idx].n_edition_flag_ordered) - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Ordered chapter flag: %"PRIu64 + MP_VERBOSE(demuxer, "Ordered chapter flag: %"PRIu64 "\n", editions[idx].edition_flag_ordered); int chapter_count = editions[idx].n_chapter_atom; @@ -860,17 +846,17 @@ static int demux_mkv_read_chapters(struct demuxer *demuxer) struct bstr name = { "(unnamed)", 9 }; if (!ca->n_chapter_time_start) - mp_msg(MSGT_DEMUX, warn_level, - "[mkv] Chapter lacks start time\n"); + MP_MSG(demuxer, warn_level, + "Chapter lacks start time\n"); chapter.start = ca->chapter_time_start; chapter.end = ca->chapter_time_end; if (ca->n_chapter_display) { if (ca->n_chapter_display > 1) - mp_msg(MSGT_DEMUX, warn_level, "[mkv] Multiple chapter " + MP_MSG(demuxer, warn_level, "Multiple chapter " "names not supported, picking first\n"); if (!ca->chapter_display[0].n_chap_string) - mp_msg(MSGT_DEMUX, warn_level, "[mkv] Malformed chapter " + MP_MSG(demuxer, warn_level, "Malformed chapter " "name entry\n"); else name = ca->chapter_display[0].chap_string; @@ -880,8 +866,8 @@ static int demux_mkv_read_chapters(struct demuxer *demuxer) chapter.has_segment_uid = true; int len = ca->chapter_segment_uid.len; if (len != sizeof(chapter.uid.segment)) - mp_msg(MSGT_DEMUX, warn_level, - "[mkv] Chapter segment uid bad length %d\n", len); + MP_MSG(demuxer, warn_level, + "Chapter segment uid bad length %d\n", len); else { memcpy(chapter.uid.segment, ca->chapter_segment_uid.start, len); @@ -889,16 +875,15 @@ static int demux_mkv_read_chapters(struct demuxer *demuxer) chapter.uid.edition = ca->chapter_segment_edition_uid; else chapter.uid.edition = 0; - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Chapter segment uid "); + MP_VERBOSE(demuxer, "Chapter segment uid "); for (int n = 0; n < len; n++) - mp_msg(MSGT_DEMUX, MSGL_V, "%02x ", + MP_VERBOSE(demuxer, "%02x ", chapter.uid.segment[n]); - mp_msg(MSGT_DEMUX, MSGL_V, "\n"); + MP_VERBOSE(demuxer, "\n"); } } - mp_msg(MSGT_DEMUX, MSGL_V, - "[mkv] Chapter %u from %02d:%02d:%02d.%03d " + MP_VERBOSE(demuxer, "Chapter %u from %02d:%02d:%02d.%03d " "to %02d:%02d:%02d.%03d, %.*s\n", i, (int) (chapter.start / 60 / 60 / 1000000000), (int) ((chapter.start / 60 / 1000000000) % 60), @@ -921,16 +906,14 @@ static int demux_mkv_read_chapters(struct demuxer *demuxer) } } if (num_editions > 1) - mp_msg(MSGT_DEMUX, MSGL_INFO, - "[mkv] Found %d editions, will play #%d (first is 0).\n", + MP_INFO(demuxer, "Found %d editions, will play #%d (first is 0).\n", num_editions, selected_edition); demuxer->num_editions = num_editions; demuxer->edition = selected_edition; talloc_free(parse_ctx.talloc_ctx); - mp_msg(MSGT_DEMUX, MSGL_V, - "[mkv] \\---- [ parsing chapters ] ---------\n"); + MP_VERBOSE(demuxer, "\\---- [ parsing chapters ] ---------\n"); return 0; } @@ -938,7 +921,7 @@ static int demux_mkv_read_tags(demuxer_t *demuxer) { stream_t *s = demuxer->stream; - struct ebml_parse_ctx parse_ctx = {0}; + struct ebml_parse_ctx parse_ctx = {demuxer->log}; struct ebml_tags tags = {0}; if (ebml_read_element(s, &parse_ctx, &tags, &ebml_tags_desc) < 0) return -1; @@ -971,11 +954,10 @@ static int demux_mkv_read_attachments(demuxer_t *demuxer) { stream_t *s = demuxer->stream; - mp_msg(MSGT_DEMUX, MSGL_V, - "[mkv] /---- [ parsing attachments ] ---------\n"); + MP_VERBOSE(demuxer, "/---- [ parsing attachments ] ---------\n"); struct ebml_attachments attachments = {0}; - struct ebml_parse_ctx parse_ctx = {0}; + struct ebml_parse_ctx parse_ctx = {demuxer->log}; if (ebml_read_element(s, &parse_ctx, &attachments, &ebml_attachments_desc) < 0) return -1; @@ -984,19 +966,18 @@ static int demux_mkv_read_attachments(demuxer_t *demuxer) struct ebml_attached_file *attachment = &attachments.attached_file[i]; if (!attachment->n_file_name || !attachment->n_file_mime_type || !attachment->n_file_data) { - mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Malformed attachment\n"); + MP_WARN(demuxer, "Malformed attachment\n"); continue; } struct bstr name = attachment->file_name; struct bstr mime = attachment->file_mime_type; demuxer_add_attachment(demuxer, name, mime, attachment->file_data); - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Attachment: %.*s, %.*s, %zu bytes\n", + MP_VERBOSE(demuxer, "Attachment: %.*s, %.*s, %zu bytes\n", BSTR_P(name), BSTR_P(mime), attachment->file_data.len); } talloc_free(parse_ctx.talloc_ctx); - mp_msg(MSGT_DEMUX, MSGL_V, - "[mkv] \\---- [ parsing attachments ] ---------\n"); + MP_VERBOSE(demuxer, "\\---- [ parsing attachments ] ---------\n"); return 0; } @@ -1009,10 +990,9 @@ static int demux_mkv_read_seekhead(demuxer_t *demuxer) struct stream *s = demuxer->stream; int res = 0; struct ebml_seek_head seekhead = {0}; - struct ebml_parse_ctx parse_ctx = {0}; + struct ebml_parse_ctx parse_ctx = {demuxer->log}; - mp_msg(MSGT_DEMUX, MSGL_V, - "[mkv] /---- [ parsing seek head ] ---------\n"); + MP_VERBOSE(demuxer, "/---- [ parsing seek head ] ---------\n"); if (ebml_read_element(s, &parse_ctx, &seekhead, &ebml_seek_head_desc) < 0) { res = -1; goto out; @@ -1022,12 +1002,12 @@ static int demux_mkv_read_seekhead(demuxer_t *demuxer) for (int i = 0; i < seekhead.n_seek; i++) { struct ebml_seek *seek = &seekhead.seek[i]; if (seek->n_seek_id != 1 || seek->n_seek_position != 1) { - mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Invalid SeekHead entry\n"); + MP_WARN(demuxer, "Invalid SeekHead entry\n"); continue; } uint64_t pos = seek->seek_position + mkv_d->segment_start; if (pos >= s->end_pos) { - mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] SeekHead position beyond " + MP_WARN(demuxer, "SeekHead position beyond " "end of file - incomplete file?\n"); continue; } @@ -1038,25 +1018,25 @@ static int demux_mkv_read_seekhead(demuxer_t *demuxer) } } if (!stream_seek(s, off)) { - mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] Couldn't seek back after " + MP_ERR(demuxer, "Couldn't seek back after " "SeekHead??\n"); res = -1; } out: - mp_msg(MSGT_DEMUX, MSGL_V, - "[mkv] \\---- [ parsing seek head ] ---------\n"); + MP_VERBOSE(demuxer, "\\---- [ parsing seek head ] ---------\n"); talloc_free(parse_ctx.talloc_ctx); return res; } -static bool seek_pos_id(struct stream *s, int64_t pos, uint32_t id) +static bool seek_pos_id(struct demuxer *demuxer, int64_t pos, uint32_t id) { + stream_t *s = demuxer->stream; if (!stream_seek(s, pos)) { - mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Failed to seek in file\n"); + MP_WARN(demuxer, "Failed to seek in file\n"); return false; } if (ebml_read_id(s, NULL) != id) { - mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Expected element not found\n"); + MP_WARN(demuxer, "Expected element not found\n"); return false; } return true; @@ -1074,19 +1054,19 @@ static int read_header_element(struct demuxer *demuxer, uint32_t id, case MATROSKA_ID_INFO: if (mkv_d->parsed_info) break; - if (at_filepos && !seek_pos_id(s, at_filepos, id)) + if (at_filepos && !seek_pos_id(demuxer, at_filepos, id)) return -1; - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] |+ segment information...\n"); + MP_VERBOSE(demuxer, "|+ segment information...\n"); mkv_d->parsed_info = true; return demux_mkv_read_info(demuxer); case MATROSKA_ID_TRACKS: if (mkv_d->parsed_tracks) break; - if (at_filepos && !seek_pos_id(s, at_filepos, id)) + if (at_filepos && !seek_pos_id(demuxer, at_filepos, id)) return -1; mkv_d->parsed_tracks = true; - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] |+ segment tracks...\n"); + MP_VERBOSE(demuxer, "|+ segment tracks...\n"); return demux_mkv_read_tracks(demuxer); case MATROSKA_ID_CUES: @@ -1104,7 +1084,7 @@ static int read_header_element(struct demuxer *demuxer, uint32_t id, case MATROSKA_ID_TAGS: if (mkv_d->parsed_tags) break; - if (at_filepos && !seek_pos_id(s, at_filepos, id)) + if (at_filepos && !seek_pos_id(demuxer, at_filepos, id)) return -1; mkv_d->parsed_tags = true; return demux_mkv_read_tags(demuxer); @@ -1112,14 +1092,14 @@ static int read_header_element(struct demuxer *demuxer, uint32_t id, case MATROSKA_ID_SEEKHEAD: if (is_parsed_header(mkv_d, pos)) break; - if (at_filepos && !seek_pos_id(s, at_filepos, id)) + if (at_filepos && !seek_pos_id(demuxer, at_filepos, id)) return -1; return demux_mkv_read_seekhead(demuxer); case MATROSKA_ID_CHAPTERS: if (mkv_d->parsed_chapters) break; - if (at_filepos && !seek_pos_id(s, at_filepos, id)) + if (at_filepos && !seek_pos_id(demuxer, at_filepos, id)) return -1; mkv_d->parsed_chapters = true; return demux_mkv_read_chapters(demuxer); @@ -1127,7 +1107,7 @@ static int read_header_element(struct demuxer *demuxer, uint32_t id, case MATROSKA_ID_ATTACHMENTS: if (mkv_d->parsed_attachments) break; - if (at_filepos && !seek_pos_id(s, at_filepos, id)) + if (at_filepos && !seek_pos_id(demuxer, at_filepos, id)) return -1; mkv_d->parsed_attachments = true; return demux_mkv_read_attachments(demuxer); @@ -1171,12 +1151,11 @@ static void display_create_tracks(demuxer_t *demuxer) break; } if (mkv_d->tracks[i]->name) - mp_msg(MSGT_DEMUX, MSGL_V, - "[mkv] Track ID %u: %s (%s) \"%s\"\n", + MP_VERBOSE(demuxer, "Track ID %u: %s (%s) \"%s\"\n", mkv_d->tracks[i]->tnum, type, mkv_d->tracks[i]->codec_id, mkv_d->tracks[i]->name); else - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Track ID %u: %s (%s)\n", + MP_VERBOSE(demuxer, "Track ID %u: %s (%s)\n", mkv_d->tracks[i]->tnum, type, mkv_d->tracks[i]->codec_id); } } @@ -1286,9 +1265,9 @@ static int demux_mkv_open_video(demuxer_t *demuxer, mkv_track_t *track) extradata_size = track->private_size; } if (!vi->id) { - mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Unknown/unsupported " + MP_WARN(demuxer, "Unknown/unsupported " "CodecID (%s) or missing/bad CodecPrivate\n" - "[mkv] data (track %u).\n", + "data (track %u).\n", track->codec_id, track->tnum); return 1; } @@ -1304,7 +1283,7 @@ static int demux_mkv_open_video(demuxer_t *demuxer, mkv_track_t *track) sh->title = talloc_strdup(sh_v, track->name); sh_v->bih = talloc_size(sh_v, sizeof(MP_BITMAPINFOHEADER) + extradata_size); if (!sh_v->bih) { - mp_msg(MSGT_DEMUX, MSGL_FATAL, "Memory allocation failure!\n"); + MP_FATAL(demuxer, "Memory allocation failure!\n"); abort(); } *sh_v->bih = *bih; @@ -1337,7 +1316,7 @@ static int demux_mkv_open_video(demuxer_t *demuxer, mkv_track_t *track) sh_v->disp_w = track->v_dwidth; sh_v->disp_h = track->v_dheight; } - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Aspect: %f\n", sh_v->aspect); + MP_VERBOSE(demuxer, "Aspect: %f\n", sh_v->aspect); sh_v->avi_dts = track->ms_compat; return 0; @@ -1407,7 +1386,7 @@ static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track) if (track->ms_compat) { if (track->private_size < sizeof(*sh_a->wf)) goto error; - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] track with MS compat audio.\n"); + MP_VERBOSE(demuxer, "track with MS compat audio.\n"); MP_WAVEFORMATEX *wf = (MP_WAVEFORMATEX *) track->private_data; sh_a->wf = talloc_zero_size(sh_a, track->private_size); sh_a->wf->wFormatTag = le2me_16(wf->wFormatTag); @@ -1652,8 +1631,8 @@ static int demux_mkv_open_audio(demuxer_t *demuxer, mkv_track_t *track) return 0; error: - mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Unknown/unsupported audio " - "codec ID '%s' for track %u or missing/faulty\n[mkv] " + MP_WARN(demuxer, "Unknown/unsupported audio " + "codec ID '%s' for track %u or missing/faulty\n" "private codec data.\n", track->codec_id, track->tnum); return 1; } @@ -1691,7 +1670,7 @@ static int demux_mkv_open_sub(demuxer_t *demuxer, mkv_track_t *track) sh->demuxer_id = track->tnum; track->sh_sub = sh_s; sh->codec = subtitle_type; - bstr buffer = demux_mkv_decode(track, in, 2); + bstr buffer = demux_mkv_decode(demuxer->log, track, in, 2); if (buffer.start && buffer.start != track->private_data) { talloc_free(track->private_data); talloc_steal(track, buffer.start); @@ -1707,8 +1686,7 @@ static int demux_mkv_open_sub(demuxer_t *demuxer, mkv_track_t *track) sh->default_track = track->default_track; if (!subtitle_type) { - mp_msg(MSGT_DEMUX, MSGL_ERR, - "[mkv] Subtitle type '%s' is not supported.\n", + MP_ERR(demuxer, "Subtitle type '%s' is not supported.\n", track->codec_id); } @@ -1732,20 +1710,20 @@ static int read_ebml_header(demuxer_t *demuxer) if (ebml_read_id(s, NULL) != EBML_ID_EBML) return 0; struct ebml_ebml ebml_master = {{0}}; - struct ebml_parse_ctx parse_ctx = { .no_error_messages = true }; + struct ebml_parse_ctx parse_ctx = { demuxer->log, .no_error_messages = true }; if (ebml_read_element(s, &parse_ctx, &ebml_master, &ebml_ebml_desc) < 0) return 0; if (ebml_master.doc_type.start == NULL) { - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] File has EBML header but no doctype." + MP_VERBOSE(demuxer, "File has EBML header but no doctype." " Assuming \"matroska\".\n"); } else if (bstrcmp(ebml_master.doc_type, bstr0("matroska")) != 0 && bstrcmp(ebml_master.doc_type, bstr0("webm")) != 0) { - mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] no head found\n"); + MP_DBG(demuxer, "no head found\n"); talloc_free(parse_ctx.talloc_ctx); return 0; } if (ebml_master.doc_type_read_version > 2) { - mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] This looks like a Matroska file, " + MP_WARN(demuxer, "This looks like a Matroska file, " "but we don't support format version %"PRIu64"\n", ebml_master.doc_type_read_version); talloc_free(parse_ctx.talloc_ctx); @@ -1758,7 +1736,7 @@ static int read_ebml_header(demuxer_t *demuxer) || (ebml_master.n_ebml_max_id_length && ebml_master.ebml_max_id_length != 4)) { - mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] This looks like a Matroska file, " + MP_WARN(demuxer, "This looks like a Matroska file, " "but the header has bad parameters\n"); talloc_free(parse_ctx.talloc_ctx); return 0; @@ -1777,22 +1755,22 @@ static int read_mkv_segment_header(demuxer_t *demuxer) while (!s->eof) { if (ebml_read_id(s, NULL) != MATROSKA_ID_SEGMENT) { - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] segment not found\n"); + MP_VERBOSE(demuxer, "segment not found\n"); return 0; } - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] + a segment...\n"); + MP_VERBOSE(demuxer, "+ a segment...\n"); uint64_t len = ebml_read_length(s, NULL); if (num_skip <= 0) return 1; num_skip--; - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] (skipping)\n"); + MP_VERBOSE(demuxer, " (skipping)\n"); if (len == EBML_UINT_INVALID) break; int64_t next = stream_tell(s) + len; if (next >= s->end_pos) return 0; if (!stream_seek(s, next)) { - mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Failed to seek in file\n"); + MP_WARN(demuxer, "Failed to seek in file\n"); return 0; } // Segments are like concatenated Matroska files @@ -1800,7 +1778,7 @@ static int read_mkv_segment_header(demuxer_t *demuxer) return 0; } - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] End of file, no further segments.\n"); + MP_VERBOSE(demuxer, "End of file, no further segments.\n"); return 0; } @@ -1813,7 +1791,7 @@ static int demux_mkv_open(demuxer_t *demuxer, enum demux_check check) if (!read_ebml_header(demuxer)) return -1; - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] Found the head...\n"); + MP_VERBOSE(demuxer, "Found the head...\n"); if (!read_mkv_segment_header(demuxer)) return -1; @@ -1829,12 +1807,11 @@ static int demux_mkv_open(demuxer_t *demuxer, enum demux_check check) while (1) { uint32_t id = ebml_read_id(s, NULL); if (s->eof) { - mp_msg(MSGT_DEMUX, MSGL_WARN, - "[mkv] Unexpected end of file (no clusters found)\n"); + MP_WARN(demuxer, "Unexpected end of file (no clusters found)\n"); break; } if (id == MATROSKA_ID_CLUSTER) { - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] |+ found cluster, headers are " + MP_VERBOSE(demuxer, "|+ found cluster, headers are " "parsed completely :)\n"); stream_seek(s, stream_tell(s) - 4); break; @@ -1936,7 +1913,6 @@ static int demux_mkv_read_block_lacing(bstr *buffer, int *laces, return 0; error: - mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] Bad input [lacing]\n"); return 1; } @@ -2311,8 +2287,10 @@ static int handle_block(demuxer_t *demuxer, struct block_info *block_info) if (!demuxer_stream_is_selected(demuxer, stream)) return 0; - if (demux_mkv_read_block_lacing(&data, &laces, lace_size)) + if (demux_mkv_read_block_lacing(&data, &laces, lace_size)) { + MP_ERR(demuxer, "Bad input [lacing]\n"); return 0; + } current_pts = tc / 1e9; @@ -2336,7 +2314,7 @@ static int handle_block(demuxer_t *demuxer, struct block_info *block_info) } if (use_this_block) { if (laces > 1) { - mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] Subtitles use Matroska " + MP_WARN(demuxer, "Subtitles use Matroska " "lacing. This is abnormal and not supported.\n"); use_this_block = 0; } @@ -2357,7 +2335,7 @@ static int handle_block(demuxer_t *demuxer, struct block_info *block_info) else if (stream->type == STREAM_AUDIO && track->realmedia) handle_realaudio(demuxer, track, block, keyframe); else { - bstr buffer = demux_mkv_decode(track, block, 1); + bstr buffer = demux_mkv_decode(demuxer->log, track, block, 1); mkv_parse_packet(track, &buffer); if (buffer.start) { demux_packet_t *dp = @@ -2426,7 +2404,7 @@ static int read_block_group(demuxer_t *demuxer, int64_t end, goto error; default: - if (ebml_read_skip_or_resync_cluster(s, NULL) != 0) + if (ebml_read_skip_or_resync_cluster(demuxer->log, s, NULL) != 0) goto error; break; } @@ -2485,7 +2463,7 @@ static int read_next_block(demuxer_t *demuxer, struct block_info *block) goto find_next_cluster; default: ; - if (ebml_read_skip_or_resync_cluster(s, NULL) != 0) + if (ebml_read_skip_or_resync_cluster(demuxer->log, s, NULL) != 0) goto find_next_cluster; break; } @@ -2500,7 +2478,7 @@ static int read_next_block(demuxer_t *demuxer, struct block_info *block) break; if (s->eof) return -1; - ebml_read_skip_or_resync_cluster(s, NULL); + ebml_read_skip_or_resync_cluster(demuxer->log, s, NULL); } next_cluster: mkv_d->cluster_end = ebml_read_length(s, NULL); @@ -2564,8 +2542,7 @@ static int create_index_until(struct demuxer *demuxer, uint64_t timecode) uint64_t old_cluster_tc = mkv_d->cluster_tc; if (index) stream_seek(s, index->filepos); - mp_msg(MSGT_DEMUX, MSGL_V, - "[mkv] creating index until TC %" PRIu64 "\n", timecode); + MP_VERBOSE(demuxer, "creating index until TC %" PRIu64 "\n", timecode); for (;;) { int res; struct block_info block; @@ -2586,7 +2563,7 @@ static int create_index_until(struct demuxer *demuxer, uint64_t timecode) mkv_d->cluster_tc = old_cluster_tc; } if (!mkv_d->indexes) { - mp_msg(MSGT_DEMUX, MSGL_WARN, "[mkv] no target for seek found\n"); + MP_WARN(demuxer, "no target for seek found\n"); return -1; } return 0; @@ -2707,7 +2684,7 @@ static void demux_mkv_seek(demuxer_t *demuxer, float rel_seek_secs, int flags) demux_mkv_fill_buffer(demuxer); } else if (!(flags & SEEK_ABSOLUTE)) - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] seek unsupported flags\n"); + MP_VERBOSE(demuxer, "seek unsupported flags\n"); else { stream_t *s = demuxer->stream; uint64_t target_filepos; @@ -2717,7 +2694,7 @@ static void demux_mkv_seek(demuxer_t *demuxer, float rel_seek_secs, int flags) read_deferred_cues(demuxer); if (!mkv_d->index_complete) { /* not implemented without index */ - mp_msg(MSGT_DEMUX, MSGL_V, "[mkv] seek unsupported flags\n"); + MP_VERBOSE(demuxer, "seek unsupported flags\n"); stream_seek(s, old_pos); return; } diff --git a/demux/demux_raw.c b/demux/demux_raw.c index 12fa1741a8..63674cea0c 100644 --- a/demux/demux_raw.c +++ b/demux/demux_raw.c @@ -120,7 +120,7 @@ static int demux_rawvideo_open(demuxer_t *demuxer, enum demux_check check) return -1; if (!width || !height) { - mp_msg(MSGT_DEMUX, MSGL_ERR, "rawvideo: width or height not specified!\n"); + MP_ERR(demuxer, "rawvideo: width or height not specified!\n"); return -1; } @@ -166,8 +166,7 @@ static int demux_rawvideo_open(demuxer_t *demuxer, enum demux_check check) break; } if (!bpp) { - mp_msg(MSGT_DEMUX, MSGL_ERR, - "rawvideo: img size not specified and unknown format!\n"); + MP_ERR(demuxer, "rawvideo: img size not specified and unknown format!\n"); return -1; } imgsize = width * height * bpp / 8; diff --git a/demux/demux_subreader.c b/demux/demux_subreader.c index e2b4c1cac4..fa029655fc 100644 --- a/demux/demux_subreader.c +++ b/demux/demux_subreader.c @@ -90,6 +90,7 @@ typedef struct sub_data { // Parameter struct for the format-specific readline functions struct readline_args { + struct mp_log *log; int utf16; struct MPOpts *opts; @@ -319,14 +320,15 @@ static const char *sub_readtext(const char *source, char **dest) { else return NULL; // last text field } -static subtitle *set_multiline_text(subtitle *current, const char *text, int start) +static subtitle *set_multiline_text(struct readline_args *arg, subtitle *current, + const char *text, int start) { int i = start; while ((text = sub_readtext(text, current->text + i))) { if (current->text[i] == ERR) return ERR; i++; if (i >= SUB_MAX_TEXT) { - mp_msg(MSGT_SUBREADER, MSGL_WARN, "Too many lines in a subtitle\n"); + MP_WARN(arg, "Too many lines in a subtitle\n"); current->lines = i; return current; } @@ -351,7 +353,7 @@ static subtitle *sub_read_line_microdvd(stream_t *st,subtitle *current, "{%ld}{%ld}%[^\r\n]", &(current->start), &(current->end), line2) < 3)); - return set_multiline_text(current, line2, 0); + return set_multiline_text(args, current, line2, 0); } static subtitle *sub_read_line_mpl2(stream_t *st,subtitle *current, @@ -369,7 +371,7 @@ static subtitle *sub_read_line_mpl2(stream_t *st,subtitle *current, current->start *= 10; current->end *= 10; - return set_multiline_text(current, line2, 0); + return set_multiline_text(args, current, line2, 0); } static subtitle *sub_read_line_subrip(stream_t* st, subtitle *current, @@ -521,7 +523,7 @@ static subtitle *sub_read_line_vplayer(stream_t *st,subtitle *current, ++p; } if (p==NULL) { - printf("SUB: Skipping incorrect subtitle line!\n"); + printf("Skipping incorrect subtitle line!\n"); continue; } */ @@ -532,7 +534,7 @@ static subtitle *sub_read_line_vplayer(stream_t *st,subtitle *current, if (*p!='|') { // - return set_multiline_text(current, p, 0); + return set_multiline_text(args, current, p, 0); } } return current; @@ -581,7 +583,7 @@ static subtitle *sub_read_line_rt(stream_t *st,subtitle *current, next = strstr(line,"<clear/>"); if(next && strlen(next)>8){ next+=8; - return set_multiline_text(current, next, 0); + return set_multiline_text(args, current, next, 0); } } return current; @@ -770,7 +772,7 @@ retry: if (!stream_read_line (st, line, LINE_LEN, utf16)) return current; - if (set_multiline_text(current, line, 1) == ERR) + if (set_multiline_text(args, current, line, 1) == ERR) return ERR; if (!strlen(current->text[0]) && !strlen(current->text[1])) @@ -806,7 +808,7 @@ retry: current->text[0]=""; // just to be sure that string is clear - if (set_multiline_text(current, line, 0) == ERR) + if (set_multiline_text(args, current, line, 0) == ERR) return ERR; if (!strlen(current->text[0]) && current->lines <= 1) @@ -1061,7 +1063,17 @@ static int sub_autodetect (stream_t* st, int *uses_time, int utf16) { return SUB_INVALID; // too many bad lines } -static void adjust_subs_time(subtitle* sub, float subtime, float fps, +struct subreader { + subtitle * (*read)(stream_t *st, subtitle *dest, + struct readline_args *args); + void (*post)(subtitle *dest); + const char *name; + const char *codec_name; + struct readline_args args; +}; + +static void adjust_subs_time(struct subreader *srp, subtitle* sub, + float subtime, float fps, float sub_fps, int block, int sub_num, int sub_uses_time) { int n,m; @@ -1091,20 +1103,11 @@ static void adjust_subs_time(subtitle* sub, float subtime, float fps, sub = nextsub; m = 0; } - if (n) mp_msg(MSGT_SUBREADER,MSGL_V,"SUB: Adjusted %d subtitle(s).\n", n); + if (n) MP_VERBOSE(&srp->args, "Adjusted %d subtitle(s).\n", n); } -struct subreader { - subtitle * (*read)(stream_t *st, subtitle *dest, - struct readline_args *args); - void (*post)(subtitle *dest); - const char *name; - const char *codec_name; - struct readline_args args; -}; - static bool subreader_autodetect(stream_t *fd, struct MPOpts *opts, - struct subreader *out) + struct mp_log *log, struct subreader *out) { static const struct subreader sr[]= { @@ -1135,14 +1138,15 @@ static bool subreader_autodetect(stream_t *fd, struct MPOpts *opts, utf16--; if (sub_format==SUB_INVALID) { - mp_msg(MSGT_SUBREADER,MSGL_V,"SUB: Could not determine file format\n"); + mp_verbose(log, "Could not determine file format\n"); return false; } srp=sr+sub_format; - mp_msg(MSGT_SUBREADER, MSGL_V, "SUB: Detected subtitle file format: %s\n", srp->name); + mp_verbose(log, "Detected subtitle file format: %s\n", srp->name); *out = *srp; out->args = (struct readline_args) { + .log = log, .utf16 = utf16, .opts = opts, .sub_slacktime = 20000, //20 sec @@ -1233,8 +1237,8 @@ static sub_data* sub_read_file(stream_t *fd, struct subreader *srp) free(alloced_sub); -// printf ("SUB: Subtitle format %s time.\n", uses_time?"uses":"doesn't use"); - mp_msg(MSGT_SUBREADER, MSGL_V,"SUB: Read %i subtitles, %i bad line(s).\n", +// printf ("Subtitle format %s time.\n", uses_time?"uses":"doesn't use"); + MP_VERBOSE(&srp->args, "Read %i subtitles, %i bad line(s).\n", sub_num, sub_errs); if(sub_num<=0){ @@ -1242,7 +1246,7 @@ static sub_data* sub_read_file(stream_t *fd, struct subreader *srp) return NULL; } - adjust_subs_time(first, 6.0, fps, opts->sub_fps, 1, sub_num, args.uses_time);/*~6 secs AST*/ + adjust_subs_time(srp, first, 6.0, fps, opts->sub_fps, 1, sub_num, args.uses_time);/*~6 secs AST*/ return_sub = first; if (return_sub == NULL) return NULL; @@ -1334,7 +1338,7 @@ static int d_open_file(struct demuxer *demuxer, enum demux_check check) struct stream *ps = read_probe_stream(demuxer->stream, PROBE_SIZE); struct subreader sr; - bool res = subreader_autodetect(ps, demuxer->opts, &sr); + bool res = subreader_autodetect(ps, demuxer->opts, demuxer->log, &sr); free_stream(ps); diff --git a/demux/ebml.c b/demux/ebml.c index dabdebb9ea..6565b9c3a9 100644 --- a/demux/ebml.c +++ b/demux/ebml.c @@ -272,17 +272,16 @@ int ebml_read_skip(stream_t *s, uint64_t *length) /* * Skip to (probable) next cluster (MATROSKA_ID_CLUSTER) element start position. */ -int ebml_resync_cluster(stream_t *s) +int ebml_resync_cluster(struct mp_log *log, stream_t *s) { int64_t pos = stream_tell(s); uint32_t last_4_bytes = 0; - mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] Corrupt file detected. " + mp_err(log, "Corrupt file detected. " "Trying to resync starting from position %"PRId64"...\n", pos); while (!s->eof) { // Assumes MATROSKA_ID_CLUSTER is 4 bytes, with no 0 bytes. if (last_4_bytes == MATROSKA_ID_CLUSTER) { - mp_msg(MSGT_DEMUX, MSGL_ERR, - "[mkv] Cluster found at %"PRId64".\n", pos - 4); + mp_err(log, "Cluster found at %"PRId64".\n", pos - 4); stream_seek(s, pos - 4); return 0; } @@ -295,7 +294,8 @@ int ebml_resync_cluster(stream_t *s) /* * Skip the current element, or on error, call ebml_resync_cluster(). */ -int ebml_read_skip_or_resync_cluster(stream_t *s, uint64_t *length) +int ebml_read_skip_or_resync_cluster(struct mp_log *log, stream_t *s, + uint64_t *length) { uint64_t len; int l; @@ -319,7 +319,7 @@ int ebml_read_skip_or_resync_cluster(stream_t *s, uint64_t *length) return 0; resync: - return ebml_resync_cluster(s) < 0 ? -1 : 1; + return ebml_resync_cluster(log, s) < 0 ? -1 : 1; } /* @@ -455,8 +455,7 @@ static void ebml_parse_element(struct ebml_parse_ctx *ctx, void *target, { assert(type->type == EBML_TYPE_SUBELEMENTS); assert(level < 8); - mp_msg(MSGT_DEMUX, MSGL_DBG2, "%.*s[mkv] Parsing element %s\n", - level, " ", type->name); + MP_DBG(ctx, "%.*sParsing element %s\n", level, " ", type->name); char *s = target; uint8_t *end = data + size; @@ -469,8 +468,7 @@ static void ebml_parse_element(struct ebml_parse_ctx *ctx, void *target, if (len > end - p) goto past_end_error; if (len < 0) { - mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] Error parsing subelement " - "id\n"); + MP_DBG(ctx, "Error parsing subelement id\n"); goto other_error; } p += len; @@ -478,8 +476,7 @@ static void ebml_parse_element(struct ebml_parse_ctx *ctx, void *target, if (len > end - p) goto past_end_error; if (len < 0) { - mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] Error parsing subelement " - "length\n"); + MP_DBG(ctx, "Error parsing subelement length\n"); goto other_error; } p += len; @@ -495,7 +492,7 @@ static void ebml_parse_element(struct ebml_parse_ctx *ctx, void *target, if (length > end - p) { if (field_idx >= 0 && type->fields[field_idx].desc->type != EBML_TYPE_SUBELEMENTS) { - mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] Subelement content goes " + MP_DBG(ctx, "Subelement content goes " "past end of containing element\n"); goto other_error; } @@ -508,7 +505,7 @@ static void ebml_parse_element(struct ebml_parse_ctx *ctx, void *target, continue; past_end_error: - mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] Subelement headers go " + MP_DBG(ctx, "Subelement headers go " "past end of containing element\n"); other_error: ctx->has_errors = true; @@ -564,7 +561,7 @@ static void ebml_parse_element(struct ebml_parse_ctx *ctx, void *target, if (length > end - data) { // Try to parse what is possible from inside this partial element length = end - data; - mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] Next subelement content goes " + MP_DBG(ctx, "Next subelement content goes " "past end of containing element, will be truncated\n"); } int field_idx = -1; @@ -575,14 +572,14 @@ static void ebml_parse_element(struct ebml_parse_ctx *ctx, void *target, } if (field_idx < 0) { if (id == 0xec) - mp_msg(MSGT_DEMUX, MSGL_DBG2, "%.*s[mkv] Ignoring Void element " + MP_DBG(ctx, "%.*sIgnoring Void element " "size: %"PRIu64"\n", level+1, " ", length); else if (id == 0xbf) - mp_msg(MSGT_DEMUX, MSGL_DBG2, "%.*s[mkv] Ignoring CRC-32 " + MP_DBG(ctx, "%.*sIgnoring CRC-32 " "element size: %"PRIu64"\n", level+1, " ", length); else - mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] Ignoring unrecognized " + MP_DBG(ctx, "Ignoring unrecognized " "subelement. ID: %x size: %"PRIu64"\n", id, length); data += length; continue; @@ -593,26 +590,26 @@ static void ebml_parse_element(struct ebml_parse_ctx *ctx, void *target, int *countptr = (int *) (s + fd->count_offset); if (*countptr >= num_elems[field_idx]) { // Shouldn't happen with on any sane file without bugs - mp_msg(MSGT_DEMUX, MSGL_ERR, "[mkv] Too many subelems?\n"); + MP_ERR(ctx, "Too many subelems?\n"); ctx->has_errors = true; data += length; continue; } if (*countptr > 0 && !multiple) { - mp_msg(MSGT_DEMUX, MSGL_DBG2, "[mkv] Another subelement of type " + MP_DBG(ctx, "Another subelement of type " "%x %s (size: %"PRIu64"). Only one allowed. Ignoring.\n", id, ed->name, length); ctx->has_errors = true; data += length; continue; } - mp_msg(MSGT_DEMUX, MSGL_DBG2, "%.*s[mkv] Parsing %x %s size: %"PRIu64 + MP_DBG(ctx, "%.*sParsing %x %s size: %"PRIu64 " value: ", level+1, " ", id, ed->name, length); char *fieldptr = s + fd->offset; switch (ed->type) { case EBML_TYPE_SUBELEMENTS: - mp_msg(MSGT_DEMUX, MSGL_DBG2, "subelements\n"); + MP_DBG(ctx, "subelements\n"); char *subelptr; if (multiple) { char *array_start = (char *) *(generic_struct **) fieldptr; @@ -631,36 +628,36 @@ static void ebml_parse_element(struct ebml_parse_ctx *ctx, void *target, subelptr = (fieldtype *) fieldptr GETPTR(uintptr, uint64_t); if (length < 1 || length > 8) { - mp_msg(MSGT_DEMUX, MSGL_DBG2, "uint invalid length %"PRIu64 + MP_DBG(ctx, "uint invalid length %"PRIu64 "\n", length); goto error; } *uintptr = ebml_parse_uint(data, length); - mp_msg(MSGT_DEMUX, MSGL_DBG2, "uint %"PRIu64"\n", *uintptr); + MP_DBG(ctx, "uint %"PRIu64"\n", *uintptr); break; case EBML_TYPE_SINT:; int64_t *sintptr; GETPTR(sintptr, int64_t); if (length < 1 || length > 8) { - mp_msg(MSGT_DEMUX, MSGL_DBG2, "sint invalid length %"PRIu64 + MP_DBG(ctx, "sint invalid length %"PRIu64 "\n", length); goto error; } *sintptr = ebml_parse_sint(data, length); - mp_msg(MSGT_DEMUX, MSGL_DBG2, "sint %"PRId64"\n", *sintptr); + MP_DBG(ctx, "sint %"PRId64"\n", *sintptr); break; case EBML_TYPE_FLOAT:; double *floatptr; GETPTR(floatptr, double); if (length != 4 && length != 8) { - mp_msg(MSGT_DEMUX, MSGL_DBG2, "float invalid length %"PRIu64 + MP_DBG(ctx, "float invalid length %"PRIu64 "\n", length); goto error; } *floatptr = ebml_parse_float(data, length); - mp_msg(MSGT_DEMUX, MSGL_DBG2, "float %f\n", *floatptr); + MP_DBG(ctx, "float %f\n", *floatptr); break; case EBML_TYPE_STR: @@ -670,10 +667,10 @@ static void ebml_parse_element(struct ebml_parse_ctx *ctx, void *target, strptr->start = data; strptr->len = length; if (ed->type == EBML_TYPE_STR) - mp_msg(MSGT_DEMUX, MSGL_DBG2, "string \"%.*s\"\n", + MP_DBG(ctx, "string \"%.*s\"\n", BSTR_P(*strptr)); else - mp_msg(MSGT_DEMUX, MSGL_DBG2, "binary %zd bytes\n", + MP_DBG(ctx, "binary %zd bytes\n", strptr->len); break; @@ -682,10 +679,10 @@ static void ebml_parse_element(struct ebml_parse_ctx *ctx, void *target, GETPTR(idptr, uint32_t); *idptr = ebml_parse_id(data, &len); if (len != length) { - mp_msg(MSGT_DEMUX, MSGL_DBG2, "ebml_id broken value\n"); + MP_DBG(ctx, "ebml_id broken value\n"); goto error; } - mp_msg(MSGT_DEMUX, MSGL_DBG2, "ebml_id %x\n", (unsigned)*idptr); + MP_DBG(ctx, "ebml_id %x\n", (unsigned)*idptr); break; default: abort(); @@ -704,24 +701,21 @@ int ebml_read_element(struct stream *s, struct ebml_parse_ctx *ctx, int msglevel = ctx->no_error_messages ? MSGL_DBG2 : MSGL_WARN; uint64_t length = ebml_read_length(s, &ctx->bytes_read); if (s->eof) { - mp_msg(MSGT_DEMUX, msglevel, "[mkv] Unexpected end of file " + MP_MSG(ctx, msglevel, "Unexpected end of file " "- partial or corrupt file?\n"); return -1; } if (length > 1000000000) { - mp_msg(MSGT_DEMUX, msglevel, "[mkv] Refusing to read element over " - "100 MB in size\n"); + MP_MSG(ctx, msglevel, "Refusing to read element over 100 MB in size\n"); return -1; } ctx->talloc_ctx = talloc_size(NULL, length + 8); int read_len = stream_read(s, ctx->talloc_ctx, length); ctx->bytes_read += read_len; if (read_len < length) - mp_msg(MSGT_DEMUX, msglevel, "[mkv] Unexpected end of file " - "- partial or corrupt file?\n"); + MP_MSG(ctx, msglevel, "Unexpected end of file - partial or corrupt file?\n"); ebml_parse_element(ctx, target, ctx->talloc_ctx, read_len, desc, 0); if (ctx->has_errors) - mp_msg(MSGT_DEMUX, msglevel, "[mkv] Error parsing element %s\n", - desc->name); + MP_MSG(ctx, msglevel, "Error parsing element %s\n", desc->name); return 0; } diff --git a/demux/ebml.h b/demux/ebml.h index 8652746e48..9bfea7a8a6 100644 --- a/demux/ebml.h +++ b/demux/ebml.h @@ -26,6 +26,8 @@ #include "stream/stream.h" #include "bstr/bstr.h" +struct mp_log; + /* EBML version supported */ #define EBML_VERSION 1 @@ -57,6 +59,7 @@ struct ebml_elem_desc { }; struct ebml_parse_ctx { + struct mp_log *log; void *talloc_ctx; int bytes_read; bool has_errors; @@ -99,8 +102,9 @@ double ebml_read_float (stream_t *s, uint64_t *length); char *ebml_read_ascii (stream_t *s, uint64_t *length); char *ebml_read_utf8 (stream_t *s, uint64_t *length); int ebml_read_skip (stream_t *s, uint64_t *length); -int ebml_read_skip_or_resync_cluster(stream_t *s, uint64_t *length); -int ebml_resync_cluster(stream_t *s); +int ebml_read_skip_or_resync_cluster(struct mp_log *log, stream_t *s, + uint64_t *length); +int ebml_resync_cluster(struct mp_log *log, stream_t *s); uint32_t ebml_read_master (stream_t *s, uint64_t *length); int ebml_read_element(struct stream *s, struct ebml_parse_ctx *ctx, diff --git a/demux/mf.c b/demux/mf.c index 02a576c51d..0aabd46bb8 100644 --- a/demux/mf.c +++ b/demux/mf.c @@ -52,13 +52,14 @@ static void mf_add(mf_t *mf, const char *fname) MP_TARRAY_APPEND(mf, mf->names, mf->nr_of_files, entry); } -mf_t *open_mf_pattern(void *talloc_ctx, char *filename) +mf_t *open_mf_pattern(void *talloc_ctx, struct mp_log *log, char *filename) { #if defined(HAVE_GLOB) || defined(__MINGW32__) int error_count = 0; int count = 0; mf_t *mf = talloc_zero(talloc_ctx, mf_t); + mf->log = log; if (filename[0] == '@') { FILE *lst_f = fopen(filename + 1, "r"); @@ -70,24 +71,21 @@ mf_t *open_mf_pattern(void *talloc_ctx, char *filename) while (t > fname && isspace(*t)) *(t--) = 0; if (!mp_path_exists(fname)) { - mp_msg(MSGT_STREAM, MSGL_V, "[mf] file not found: '%s'\n", - fname); + mp_verbose(log, "file not found: '%s'\n", fname); } else { mf_add(mf, fname); } } fclose(lst_f); - mp_msg(MSGT_STREAM, MSGL_INFO, "[mf] number of files: %d\n", - mf->nr_of_files); + mp_info(log, "number of files: %d\n", mf->nr_of_files); goto exit_mf; } - mp_msg(MSGT_STREAM, MSGL_INFO, "[mf] %s is not indirect filelist\n", - filename + 1); + mp_info(log, "%s is not indirect filelist\n", filename + 1); } if (strchr(filename, ',')) { - mp_msg(MSGT_STREAM, MSGL_INFO, "[mf] filelist: %s\n", filename); + mp_info(log, "filelist: %s\n", filename); bstr bfilename = bstr0(filename); while (bfilename.len) { @@ -96,15 +94,13 @@ mf_t *open_mf_pattern(void *talloc_ctx, char *filename) char *fname2 = bstrdup0(mf, bfname); if (!mp_path_exists(fname2)) - mp_msg(MSGT_STREAM, MSGL_V, "[mf] file not found: '%s'\n", - fname2); + mp_verbose(log, "file not found: '%s'\n", fname2); else { mf_add(mf, fname2); } talloc_free(fname2); } - mp_msg(MSGT_STREAM, MSGL_INFO, "[mf] number of files: %d\n", - mf->nr_of_files); + mp_info(log, "number of files: %d\n", mf->nr_of_files); goto exit_mf; } @@ -116,7 +112,7 @@ mf_t *open_mf_pattern(void *talloc_ctx, char *filename) if (!strchr(filename, '*')) strcat(fname, "*"); - mp_msg(MSGT_STREAM, MSGL_INFO, "[mf] search expr: %s\n", fname); + mp_info(log, "search expr: %s\n", fname); glob_t gg; if (glob(fname, 0, NULL, &gg)) { @@ -129,38 +125,37 @@ mf_t *open_mf_pattern(void *talloc_ctx, char *filename) continue; mf_add(mf, gg.gl_pathv[i]); } - mp_msg(MSGT_STREAM, MSGL_INFO, "[mf] number of files: %d\n", - mf->nr_of_files); + mp_info(log, "number of files: %d\n", mf->nr_of_files); globfree(&gg); goto exit_mf; } - mp_msg(MSGT_STREAM, MSGL_INFO, "[mf] search expr: %s\n", filename); + mp_info(log, "search expr: %s\n", filename); while (error_count < 5) { sprintf(fname, filename, count++); if (!mp_path_exists(fname)) { error_count++; - mp_msg(MSGT_STREAM, MSGL_V, "[mf] file not found: '%s'\n", fname); + mp_verbose(log, "file not found: '%s'\n", fname); } else { mf_add(mf, fname); } } - mp_msg(MSGT_STREAM, MSGL_INFO, "[mf] number of files: %d\n", - mf->nr_of_files); + mp_info(log, "number of files: %d\n", mf->nr_of_files); exit_mf: return mf; #else - mp_msg(MSGT_STREAM, MSGL_FATAL, "[mf] mf support is disabled on your os\n"); + mp_fatal(log, "mf support is disabled on your os\n"); return 0; #endif } -mf_t *open_mf_single(void *talloc_ctx, char *filename) +mf_t *open_mf_single(void *talloc_ctx, struct mp_log *log, char *filename) { mf_t *mf = talloc_zero(talloc_ctx, mf_t); + mf->log = log; mf_add(mf, filename); return mf; } diff --git a/demux/mf.h b/demux/mf.h index 5511e3188b..09f6e03b4f 100644 --- a/demux/mf.h +++ b/demux/mf.h @@ -19,10 +19,13 @@ #ifndef MPLAYER_MF_H #define MPLAYER_MF_H +struct mp_log; + extern double mf_fps; extern char * mf_type; typedef struct mf { + struct mp_log *log; struct sh_video *sh; int curr_frame; int nr_of_files; @@ -31,7 +34,7 @@ typedef struct mf { struct stream **streams; } mf_t; -mf_t *open_mf_pattern(void *talloc_ctx, char *filename); -mf_t *open_mf_single(void *talloc_ctx, char *filename); +mf_t *open_mf_pattern(void *talloc_ctx, struct mp_log *log, char *filename); +mf_t *open_mf_single(void *talloc_ctx, struct mp_log *log, char *filename); #endif /* MPLAYER_MF_H */ diff --git a/player/loadfile.c b/player/loadfile.c index 8ca793941f..1d668b9c2c 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -735,7 +735,7 @@ static struct track *open_external_file(struct MPContext *mpctx, char *filename, .ass_library = mpctx->ass_library, // demux_libass requires it }; struct demuxer *demuxer = - demux_open(stream, demuxer_name, ¶ms, mpctx->opts); + demux_open(stream, demuxer_name, ¶ms, mpctx->global); if (!demuxer) { free_stream(stream); goto err_out; @@ -1083,7 +1083,8 @@ goto_reopen_demuxer: ; mpctx->audio_delay = opts->audio_delay; - mpctx->demuxer = demux_open(mpctx->stream, opts->demuxer_name, NULL, opts); + mpctx->demuxer = demux_open(mpctx->stream, opts->demuxer_name, NULL, + mpctx->global); mpctx->master_demuxer = mpctx->demuxer; if (!mpctx->demuxer) { MP_ERR(mpctx, "Failed to recognize file format.\n"); diff --git a/player/main.c b/player/main.c index 1211a32f39..71ce31e082 100644 --- a/player/main.c +++ b/player/main.c @@ -219,7 +219,7 @@ static bool handle_help_options(struct MPContext *mpctx) if ((opts->demuxer_name && strcmp(opts->demuxer_name, "help") == 0) || (opts->audio_demuxer_name && strcmp(opts->audio_demuxer_name, "help") == 0) || (opts->sub_demuxer_name && strcmp(opts->sub_demuxer_name, "help") == 0)) { - demuxer_help(); + demuxer_help(log); MP_INFO(mpctx, "\n"); opt_exit = 1; } diff --git a/player/timeline/tl_cue.c b/player/timeline/tl_cue.c index 646aa24ee3..80eaf5ef76 100644 --- a/player/timeline/tl_cue.c +++ b/player/timeline/tl_cue.c @@ -191,7 +191,7 @@ static bool try_open(struct MPContext *mpctx, char *filename) struct stream *s = stream_open(filename, mpctx->opts); if (!s) return false; - struct demuxer *d = demux_open(s, NULL, NULL, mpctx->opts); + struct demuxer *d = demux_open(s, NULL, NULL, mpctx->global); // Since .bin files are raw PCM data with no headers, we have to explicitly // open them. Also, try to avoid to open files that are most likely not .bin // files, as that would only play noise. Checking the file extension is @@ -200,7 +200,7 @@ static bool try_open(struct MPContext *mpctx, char *filename) // CD sector size (2352 bytes) if (!d && bstr_case_endswith(bfilename, bstr0(".bin"))) { MP_WARN(mpctx, "CUE: Opening as BIN file!\n"); - d = demux_open(s, "rawaudio", NULL, mpctx->opts); + d = demux_open(s, "rawaudio", NULL, mpctx->global); } if (d) { add_source(mpctx, d); diff --git a/player/timeline/tl_matroska.c b/player/timeline/tl_matroska.c index f5a01a3860..720bd3f979 100644 --- a/player/timeline/tl_matroska.c +++ b/player/timeline/tl_matroska.c @@ -139,7 +139,7 @@ static int enable_cache(struct MPContext *mpctx, struct stream **stream, opts->stream_cache_min_percent, opts->stream_cache_seek_min_percent); - *demuxer = demux_open(*stream, "mkv", params, opts); + *demuxer = demux_open(*stream, "mkv", params, mpctx->global); if (!*demuxer) { talloc_free(filename); free_stream(*stream); @@ -177,7 +177,7 @@ static bool check_file_seg(struct MPContext *mpctx, struct demuxer ***sources, struct stream *s = stream_open(filename, mpctx->opts); if (!s) return false; - struct demuxer *d = demux_open(s, "mkv", ¶ms, mpctx->opts); + struct demuxer *d = demux_open(s, "mkv", ¶ms, mpctx->global); if (!d) { free_stream(s); @@ -264,7 +264,7 @@ static int find_ordered_chapter_sources(struct MPContext *mpctx, MP_INFO(mpctx, "Loading references from '%s'.\n", opts->ordered_chapters_files); struct playlist *pl = - playlist_parse_file(opts->ordered_chapters_files, opts); + playlist_parse_file(opts->ordered_chapters_files, mpctx->global); talloc_steal(tmp, pl); for (struct playlist_entry *e = pl->first; e; e = e->next) MP_TARRAY_APPEND(tmp, filenames, num_filenames, e->filename); diff --git a/player/timeline/tl_mpv_edl.c b/player/timeline/tl_mpv_edl.c index 473502d2c8..b256e0bdd5 100644 --- a/player/timeline/tl_mpv_edl.c +++ b/player/timeline/tl_mpv_edl.c @@ -130,7 +130,7 @@ static struct demuxer *open_file(char *filename, struct MPContext *mpctx) opts->stream_cache_def_size, opts->stream_cache_min_percent, opts->stream_cache_seek_min_percent); - d = demux_open(s, NULL, NULL, opts); + d = demux_open(s, NULL, NULL, mpctx->global); } if (!d) { MP_ERR(mpctx, "EDL: Could not open source file '%s'.\n", diff --git a/stream/ai_alsa1x.c b/stream/ai_alsa1x.c index 880817a94e..8360c88100 100644 --- a/stream/ai_alsa1x.c +++ b/stream/ai_alsa1x.c @@ -40,27 +40,27 @@ int ai_alsa_setup(audio_in_t *ai) err = snd_pcm_hw_params_any(ai->alsa.handle, params); if (err < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "Broken configuration for this PCM: no configurations available.\n"); + MP_ERR(ai, "Broken configuration for this PCM: no configurations available.\n"); return -1; } err = snd_pcm_hw_params_set_access(ai->alsa.handle, params, SND_PCM_ACCESS_RW_INTERLEAVED); if (err < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "Access type not available.\n"); + MP_ERR(ai, "Access type not available.\n"); return -1; } err = snd_pcm_hw_params_set_format(ai->alsa.handle, params, SND_PCM_FORMAT_S16_LE); if (err < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "Sample format not available.\n"); + MP_ERR(ai, "Sample format not available.\n"); return -1; } err = snd_pcm_hw_params_set_channels(ai->alsa.handle, params, ai->req_channels); if (err < 0) { snd_pcm_hw_params_get_channels(params, &ai->channels); - mp_msg(MSGT_TV, MSGL_ERR, "Channel count not available - reverting to default: %d\n", + MP_ERR(ai, "Channel count not available - reverting to default: %d\n", ai->channels); } else { ai->channels = ai->req_channels; @@ -70,7 +70,7 @@ int ai_alsa_setup(audio_in_t *ai) rate = ai->req_samplerate; err = snd_pcm_hw_params_set_rate_near(ai->alsa.handle, params, &rate, &dir); if (err < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "Cannot set samplerate.\n"); + MP_ERR(ai, "Cannot set samplerate.\n"); } ai->samplerate = rate; @@ -79,7 +79,7 @@ int ai_alsa_setup(audio_in_t *ai) err = snd_pcm_hw_params_set_buffer_time_near(ai->alsa.handle, params, &ai->alsa.buffer_time, &dir); if (err < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "Cannot set buffer time.\n"); + MP_ERR(ai, "Cannot set buffer time.\n"); } dir = 0; @@ -87,12 +87,12 @@ int ai_alsa_setup(audio_in_t *ai) err = snd_pcm_hw_params_set_period_time_near(ai->alsa.handle, params, &ai->alsa.period_time, &dir); if (err < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "Cannot set period time.\n"); + MP_ERR(ai, "Cannot set period time.\n"); } err = snd_pcm_hw_params(ai->alsa.handle, params); if (err < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "Unable to install hardware parameters: %s", snd_strerror(err)); + MP_ERR(ai, "Unable to install hardware parameters: %s", snd_strerror(err)); snd_pcm_hw_params_dump(params, ai->alsa.log); return -1; } @@ -102,7 +102,7 @@ int ai_alsa_setup(audio_in_t *ai) snd_pcm_hw_params_get_buffer_size(params, &buffer_size); ai->alsa.chunk_size = period_size; if (period_size == buffer_size) { - mp_msg(MSGT_TV, MSGL_ERR, "Can't use period equal to buffer size (%u == %lu)\n", ai->alsa.chunk_size, (long)buffer_size); + MP_ERR(ai, "Can't use period equal to buffer size (%u == %lu)\n", ai->alsa.chunk_size, (long)buffer_size); return -1; } @@ -113,12 +113,12 @@ int ai_alsa_setup(audio_in_t *ai) err = snd_pcm_sw_params_set_stop_threshold(ai->alsa.handle, swparams, buffer_size); if (snd_pcm_sw_params(ai->alsa.handle, swparams) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "Unable to install software parameters:\n"); + MP_ERR(ai, "Unable to install software parameters:\n"); snd_pcm_sw_params_dump(swparams, ai->alsa.log); return -1; } - if (mp_msg_test(MSGT_TV, MSGL_V)) { + if (mp_msg_test_log(ai->log, MSGL_V)) { snd_pcm_dump(ai->alsa.handle, ai->alsa.log); } @@ -137,7 +137,7 @@ int ai_alsa_init(audio_in_t *ai) err = snd_pcm_open(&ai->alsa.handle, ai->alsa.device, SND_PCM_STREAM_CAPTURE, 0); if (err < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "Error opening audio: %s\n", snd_strerror(err)); + MP_ERR(ai, "Error opening audio: %s\n", snd_strerror(err)); return -1; } @@ -171,7 +171,7 @@ int ai_alsa_xrun(audio_in_t *ai) snd_pcm_status_alloca(&status); if ((res = snd_pcm_status(ai->alsa.handle, status))<0) { - mp_msg(MSGT_TV, MSGL_ERR, "ALSA status error: %s", snd_strerror(res)); + MP_ERR(ai, "ALSA status error: %s", snd_strerror(res)); return -1; } if (snd_pcm_status_get_state(status) == SND_PCM_STATE_XRUN) { @@ -179,18 +179,18 @@ int ai_alsa_xrun(audio_in_t *ai) gettimeofday(&now, 0); snd_pcm_status_get_trigger_tstamp(status, &tstamp); timersub(&now, &tstamp, &diff); - mp_msg(MSGT_TV, MSGL_ERR, "ALSA xrun!!! (at least %.3f ms long)\n", + MP_ERR(ai, "ALSA xrun!!! (at least %.3f ms long)\n", diff.tv_sec * 1000 + diff.tv_usec / 1000.0); - if (mp_msg_test(MSGT_TV, MSGL_V)) { - mp_msg(MSGT_TV, MSGL_ERR, "ALSA Status:\n"); + if (mp_msg_test_log(ai->log, MSGL_V)) { + MP_ERR(ai, "ALSA Status:\n"); snd_pcm_status_dump(status, ai->alsa.log); } if ((res = snd_pcm_prepare(ai->alsa.handle))<0) { - mp_msg(MSGT_TV, MSGL_ERR, "ALSA xrun: prepare error: %s", snd_strerror(res)); + MP_ERR(ai, "ALSA xrun: prepare error: %s", snd_strerror(res)); return -1; } return 0; /* ok, data should be accepted again */ } - mp_msg(MSGT_TV, MSGL_ERR, "ALSA read/write error"); + MP_ERR(ai, "ALSA read/write error"); return -1; } diff --git a/stream/ai_oss.c b/stream/ai_oss.c index bf57ec4198..8672d13fc0 100644 --- a/stream/ai_oss.c +++ b/stream/ai_oss.c @@ -57,10 +57,10 @@ int ai_oss_set_channels(audio_in_t *ai) if (ai->req_channels > 2) { ioctl_param = ai->req_channels; - mp_msg(MSGT_TV, MSGL_V, "ioctl dsp channels: %d\n", + MP_VERBOSE(ai, "ioctl dsp channels: %d\n", err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_CHANNELS, &ioctl_param)); if (err < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "Unable to set channel count: %d\n", + MP_ERR(ai, "Unable to set channel count: %d\n", ai->req_channels); return -1; } @@ -69,11 +69,11 @@ int ai_oss_set_channels(audio_in_t *ai) else { ioctl_param = (ai->req_channels == 2); - mp_msg(MSGT_TV, MSGL_V, "ioctl dsp stereo: %d (req: %d)\n", + MP_VERBOSE(ai, "ioctl dsp stereo: %d (req: %d)\n", err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_STEREO, &ioctl_param), ioctl_param); if (err < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "Unable to set stereo: %d\n", + MP_ERR(ai, "Unable to set stereo: %d\n", ai->req_channels == 2); return -1; } @@ -90,65 +90,65 @@ int ai_oss_init(audio_in_t *ai) ai->oss.audio_fd = open(ai->oss.device, O_RDONLY | O_CLOEXEC); if (ai->oss.audio_fd < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "Unable to open '%s': %s\n", + MP_ERR(ai, "Unable to open '%s': %s\n", ai->oss.device, strerror(errno)); return -1; } ioctl_param = 0 ; - mp_msg(MSGT_TV, MSGL_V, "ioctl dsp getfmt: %d\n", + MP_VERBOSE(ai, "ioctl dsp getfmt: %d\n", ioctl(ai->oss.audio_fd, SNDCTL_DSP_GETFMTS, &ioctl_param)); - mp_msg(MSGT_TV, MSGL_V, "Supported formats: %x\n", ioctl_param); + MP_VERBOSE(ai, "Supported formats: %x\n", ioctl_param); if (!(ioctl_param & AFMT_S16_LE)) - mp_msg(MSGT_TV, MSGL_ERR, "unsupported format\n"); + MP_ERR(ai, "unsupported format\n"); ioctl_param = AFMT_S16_LE; - mp_msg(MSGT_TV, MSGL_V, "ioctl dsp setfmt: %d\n", + MP_VERBOSE(ai, "ioctl dsp setfmt: %d\n", err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_SETFMT, &ioctl_param)); if (err < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "Unable to set audio format."); + MP_ERR(ai, "Unable to set audio format."); return -1; } if (ai_oss_set_channels(ai) < 0) return -1; ioctl_param = ai->req_samplerate; - mp_msg(MSGT_TV, MSGL_V, "ioctl dsp speed: %d\n", + MP_VERBOSE(ai, "ioctl dsp speed: %d\n", err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_SPEED, &ioctl_param)); if (err < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "Unable to set samplerate: %d\n", + MP_ERR(ai, "Unable to set samplerate: %d\n", ai->req_samplerate); return -1; } ai->samplerate = ioctl_param; - mp_msg(MSGT_TV, MSGL_V, "ioctl dsp trigger: %d\n", + MP_VERBOSE(ai, "ioctl dsp trigger: %d\n", ioctl(ai->oss.audio_fd, SNDCTL_DSP_GETTRIGGER, &ioctl_param)); - mp_msg(MSGT_TV, MSGL_V, "trigger: %x\n", ioctl_param); + MP_VERBOSE(ai, "trigger: %x\n", ioctl_param); ioctl_param = PCM_ENABLE_INPUT; - mp_msg(MSGT_TV, MSGL_V, "ioctl dsp trigger: %d\n", + MP_VERBOSE(ai, "ioctl dsp trigger: %d\n", err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_SETTRIGGER, &ioctl_param)); if (err < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "Unable to set trigger: %d\n", + MP_ERR(ai, "Unable to set trigger: %d\n", PCM_ENABLE_INPUT); } ai->blocksize = 0; - mp_msg(MSGT_TV, MSGL_V, "ioctl dsp getblocksize: %d\n", + MP_VERBOSE(ai, "ioctl dsp getblocksize: %d\n", err = ioctl(ai->oss.audio_fd, SNDCTL_DSP_GETBLKSIZE, &ai->blocksize)); if (err < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "Unable to get block size!\n"); + MP_ERR(ai, "Unable to get block size!\n"); } - mp_msg(MSGT_TV, MSGL_V, "blocksize: %d\n", ai->blocksize); + MP_VERBOSE(ai, "blocksize: %d\n", ai->blocksize); // correct the blocksize to a reasonable value if (ai->blocksize <= 0) { ai->blocksize = 4096*ai->channels*2; - mp_msg(MSGT_TV, MSGL_ERR, "Audio block size is zero, setting to %d!\n", ai->blocksize); + MP_ERR(ai, "Audio block size is zero, setting to %d!\n", ai->blocksize); } else if (ai->blocksize < 4096*ai->channels*2) { ai->blocksize *= 4096*ai->channels*2/ai->blocksize; - mp_msg(MSGT_TV, MSGL_ERR, "Audio block size too low, setting to %d!\n", ai->blocksize); + MP_ERR(ai, "Audio block size too low, setting to %d!\n", ai->blocksize); } ai->samplesize = 16; diff --git a/stream/ai_sndio.c b/stream/ai_sndio.c index 08ddac1e03..3cd68e5ee1 100644 --- a/stream/ai_sndio.c +++ b/stream/ai_sndio.c @@ -21,7 +21,7 @@ int ai_sndio_setup(audio_in_t *ai) par.appbufsz = ai->req_samplerate; /* 1 sec */ if (!sio_setpar(ai->sndio.hdl, &par) || !sio_getpar(ai->sndio.hdl, &par)) { - mp_msg(MSGT_TV, MSGL_ERR, "could not configure sndio audio"); + MP_ERR(ai, "could not configure sndio audio"); return -1; } @@ -39,7 +39,7 @@ int ai_sndio_init(audio_in_t *ai) int err; if ((ai->sndio.hdl = sio_open(ai->sndio.device, SIO_REC, 0)) == NULL) { - mp_msg(MSGT_TV, MSGL_ERR, "could not open sndio audio"); + MP_ERR(ai, "could not open sndio audio"); return -1; } diff --git a/stream/audio_in.c b/stream/audio_in.c index 1d80ab762b..6592735aa9 100644 --- a/stream/audio_in.c +++ b/stream/audio_in.c @@ -28,10 +28,11 @@ #include <errno.h> // sanitizes ai structure before calling other functions -int audio_in_init(audio_in_t *ai, int type) +int audio_in_init(audio_in_t *ai, struct mp_log *log, int type) { ai->type = type; ai->setup = 0; + ai->log = log; ai->channels = -1; ai->samplerate = -1; @@ -247,16 +248,16 @@ int audio_in_read_chunk(audio_in_t *ai, unsigned char *buffer) ret = snd_pcm_readi(ai->alsa.handle, buffer, ai->alsa.chunk_size); if (ret != ai->alsa.chunk_size) { if (ret < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "\nError reading audio: %s\n", snd_strerror(ret)); + MP_ERR(ai, "\nError reading audio: %s\n", snd_strerror(ret)); if (ret == -EPIPE) { if (ai_alsa_xrun(ai) == 0) { - mp_msg(MSGT_TV, MSGL_ERR, "Recovered from cross-run, some frames may be left out!\n"); + MP_ERR(ai, "Recovered from cross-run, some frames may be left out!\n"); } else { - mp_msg(MSGT_TV, MSGL_ERR, "Fatal error, cannot recover!\n"); + MP_ERR(ai, "Fatal error, cannot recover!\n"); } } } else { - mp_msg(MSGT_TV, MSGL_ERR, "\nNot enough audio samples!\n"); + MP_ERR(ai, "\nNot enough audio samples!\n"); } return -1; } @@ -267,10 +268,10 @@ int audio_in_read_chunk(audio_in_t *ai, unsigned char *buffer) ret = read(ai->oss.audio_fd, buffer, ai->blocksize); if (ret != ai->blocksize) { if (ret < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "\nError reading audio: %s\n", strerror(errno)); + MP_ERR(ai, "\nError reading audio: %s\n", strerror(errno)); } else { - mp_msg(MSGT_TV, MSGL_ERR, "\nNot enough audio samples!\n"); + MP_ERR(ai, "\nNot enough audio samples!\n"); } return -1; } @@ -281,9 +282,9 @@ int audio_in_read_chunk(audio_in_t *ai, unsigned char *buffer) ret = sio_read(ai->sndio.hdl, buffer, ai->blocksize); if (ret != ai->blocksize) { if (ret < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "\nError reading audio: %s\n", strerror(errno)); + MP_ERR(ai, "\nError reading audio: %s\n", strerror(errno)); } else { - mp_msg(MSGT_TV, MSGL_ERR, "\nNot enough audio samples!\n"); + MP_ERR(ai, "\nNot enough audio samples!\n"); } return -1; } diff --git a/stream/audio_in.h b/stream/audio_in.h index af2cecd28d..0afd926335 100644 --- a/stream/audio_in.h +++ b/stream/audio_in.h @@ -25,6 +25,8 @@ #include "config.h" +struct mp_log; + #if HAVE_ALSA #include <alsa/asoundlib.h> @@ -58,6 +60,7 @@ typedef struct { typedef struct { + struct mp_log *log; int type; int setup; @@ -83,7 +86,7 @@ typedef struct #endif } audio_in_t; -int audio_in_init(audio_in_t *ai, int type); +int audio_in_init(audio_in_t *ai, struct mp_log *log, int type); int audio_in_setup(audio_in_t *ai); int audio_in_set_device(audio_in_t *ai, char *device); int audio_in_set_samplerate(audio_in_t *ai, int rate); diff --git a/stream/stream_radio.c b/stream/stream_radio.c index 3a954251f0..3f60bb77c2 100644 --- a/stream/stream_radio.c +++ b/stream/stream_radio.c @@ -574,7 +574,7 @@ static int init_audio(radio_priv_t *priv) tmp[0] = ','; #endif - if(audio_in_init(&priv->audio_in, is_oss?AUDIO_IN_OSS:AUDIO_IN_ALSA)<0){ + if(audio_in_init(&priv->audio_in, mp_null_log, is_oss?AUDIO_IN_OSS:AUDIO_IN_ALSA)<0){ mp_msg(MSGT_RADIO, MSGL_ERR, "[radio] audio_in_init failed.\n"); } diff --git a/stream/tv.c b/stream/tv.c index 594af4fd30..b9e5a97b9b 100644 --- a/stream/tv.c +++ b/stream/tv.c @@ -67,7 +67,7 @@ static const tvi_info_t* tvi_driver_list[]={ NULL }; -tvi_handle_t *tv_new_handle(int size, const tvi_functions_t *functions) +tvi_handle_t *tv_new_handle(int size, struct mp_log *log, const tvi_functions_t *functions) { tvi_handle_t *h = malloc(sizeof(*h)); @@ -81,6 +81,7 @@ tvi_handle_t *tv_new_handle(int size, const tvi_functions_t *functions) return NULL; } + h->log = log; h->functions = functions; h->seq = 0; h->chanlist = -1; @@ -103,7 +104,7 @@ void tv_free_handle(tvi_handle_t *h) void tv_start_scan(tvi_handle_t *tvh, int start) { - mp_msg(MSGT_TV,MSGL_INFO,"start scan\n"); + MP_INFO(tvh, "start scan\n"); tvh->tv_param->scan=start?1:0; } @@ -124,7 +125,7 @@ static void tv_scan(tvi_handle_t *tvh) //Channel scanner without tuner is useless and causes crash due to uninitialized chanlist_s if (tvh->functions->control(tvh->priv, TVI_CONTROL_IS_TUNER, 0) != TVI_CONTROL_TRUE) { - mp_msg(MSGT_TV, MSGL_WARN, "Channel scanner is not available without tuner\n"); + MP_WARN(tvh, "Channel scanner is not available without tuner\n"); tvh->tv_param->scan=0; return; } @@ -154,7 +155,7 @@ static void tv_scan(tvi_handle_t *tvh) tv_channel_tmp=tv_channel_tmp->next; } if (!found) { - mp_msg(MSGT_TV, MSGL_INFO, "Found new channel: %s (#%d). \n",cl.name,index); + MP_INFO(tvh, "Found new channel: %s (#%d). \n",cl.name,index); scan->new_channels++; tv_channel_tmp = malloc(sizeof(tv_channels_t)); tv_channel_tmp->index=index; @@ -171,24 +172,24 @@ static void tv_scan(tvi_handle_t *tvh) tv_channel_list->prev=tv_channel_tmp; } }else - mp_msg(MSGT_TV, MSGL_INFO, "Found existing channel: %s-%s.\n", + MP_INFO(tvh, "Found existing channel: %s-%s.\n", tv_channel_tmp->number,tv_channel_tmp->name); } scan->channel_num++; scan->scan_timer=now+1e6*tvh->tv_param->scan_period; if (scan->channel_num>=chanlists[tvh->chanlist].count) { tvh->tv_param->scan=0; - mp_msg(MSGT_TV, MSGL_INFO, "TV scan end. Found %d new channels.\n", scan->new_channels); + MP_INFO(tvh, "TV scan end. Found %d new channels.\n", scan->new_channels); tv_channel_tmp=tv_channel_list; if(tv_channel_tmp){ - mp_msg(MSGT_TV,MSGL_INFO,"channels="); + MP_INFO(tvh, "channels="); while(tv_channel_tmp){ - mp_msg(MSGT_TV,MSGL_INFO,"%s-%s",tv_channel_tmp->number,tv_channel_tmp->name); + MP_INFO(tvh, "%s-%s",tv_channel_tmp->number,tv_channel_tmp->name); if(tv_channel_tmp->next) - mp_msg(MSGT_TV,MSGL_INFO,","); + MP_INFO(tvh, ","); tv_channel_tmp=tv_channel_tmp->next; } - mp_msg(MSGT_TV, MSGL_INFO, "\n"); + MP_INFO(tvh, "\n"); } if (!tv_channel_current) tv_channel_current=tv_channel_list; if (tv_channel_current) @@ -198,7 +199,7 @@ static void tv_scan(tvi_handle_t *tvh) }else{ cl = tvh->chanlist_s[scan->channel_num]; tv_set_freq_float(tvh, cl.freq); - mp_msg(MSGT_TV, MSGL_INFO, "Trying: %s (%.2f). \n",cl.name,1e-3*cl.freq); + MP_INFO(tvh, "Trying: %s (%.2f). \n",cl.name,1e-3*cl.freq); } } @@ -276,7 +277,7 @@ static int norm_from_string(tvi_handle_t *tvh, char* norm) if(ret!=TVI_CONTROL_UNKNOWN) { - mp_msg(MSGT_TV, MSGL_WARN, "tv.c: norm_from_string(%s): Bogus norm parameter, setting %s.\n", norm,"default"); + MP_WARN(tvh, "tv.c: norm_from_string(%s): Bogus norm parameter, setting %s.\n", norm,"default"); return 0; } @@ -295,7 +296,7 @@ static int norm_from_string(tvi_handle_t *tvh, char* norm) else if (!strcasecmp(norm, "ntscjp")) return TV_NORM_NTSCJP; else { - mp_msg(MSGT_TV, MSGL_WARN, "tv.c: norm_from_string(%s): Bogus norm parameter, setting %s.\n", norm, "PAL"); + MP_WARN(tvh, "tv.c: norm_from_string(%s): Bogus norm parameter, setting %s.\n", norm, "PAL"); return TV_NORM_PAL; } } @@ -304,7 +305,7 @@ static void parse_channels(tvi_handle_t *tvh) { char** channels = tvh->tv_param->channels; - mp_msg(MSGT_TV, MSGL_INFO, "TV channel names detected.\n"); + MP_INFO(tvh, "TV channel names detected.\n"); tv_channel_list = malloc(sizeof(tv_channels_t)); tv_channel_list->index=1; tv_channel_list->next=NULL; @@ -344,7 +345,7 @@ static void parse_channels(tvi_handle_t *tvh) } } if (tv_channel_current->freq == 0) - mp_msg(MSGT_TV, MSGL_ERR, "Couldn't find frequency for channel %s (%s)\n", + MP_ERR(tvh, "Couldn't find frequency for channel %s (%s)\n", tv_channel_current->number, tv_channel_current->name); else { sep = strchr(tv_channel_current->name, '-'); @@ -364,7 +365,7 @@ static void parse_channels(tvi_handle_t *tvh) } } - /*mp_msg(MSGT_TV, MSGL_INFO, "-- Detected channel %s - %s (%5.3f)\n", + /*MP_INFO(tvh, "-- Detected channel %s - %s (%5.3f)\n", tv_channel_current->number, tv_channel_current->name, (float)tv_channel_current->freq/1000);*/ @@ -384,9 +385,9 @@ int tv_set_norm(tvi_handle_t *tvh, char* norm) { tvh->norm = norm_from_string(tvh, norm); - mp_msg(MSGT_TV, MSGL_V, "Selected norm : %s\n", norm); + MP_VERBOSE(tvh, "Selected norm : %s\n", norm); if (tvh->functions->control(tvh->priv, TVI_CONTROL_TUN_SET_NORM, &tvh->norm) != TVI_CONTROL_TRUE) { - mp_msg(MSGT_TV, MSGL_ERR, "Error: Cannot set norm!\n"); + MP_ERR(tvh, "Error: Cannot set norm!\n"); return 0; } return 1; @@ -396,9 +397,9 @@ static int tv_set_norm_i(tvi_handle_t *tvh, int norm) { tvh->norm = norm; - mp_msg(MSGT_TV, MSGL_V, "Selected norm id: %d\n", norm); + MP_VERBOSE(tvh, "Selected norm id: %d\n", norm); if (tvh->functions->control(tvh->priv, TVI_CONTROL_TUN_SET_NORM, &tvh->norm) != TVI_CONTROL_TRUE) { - mp_msg(MSGT_TV, MSGL_ERR, "Error: Cannot set norm!\n"); + MP_ERR(tvh, "Error: Cannot set norm!\n"); return 0; } @@ -407,7 +408,7 @@ static int tv_set_norm_i(tvi_handle_t *tvh, int norm) static void set_norm_and_freq(tvi_handle_t *tvh, tv_channels_t *chan) { - mp_msg(MSGT_TV, MSGL_INFO, "Selected channel: %s - %s (freq: %.3f)\n", + MP_INFO(tvh, "Selected channel: %s - %s (freq: %.3f)\n", chan->number, chan->name, chan->freq/1000.0); tv_set_norm_i(tvh, chan->norm); tv_set_freq_float(tvh, chan->freq); @@ -430,7 +431,7 @@ static int open_tv(tvi_handle_t *tvh) if (funcs->control(tvh->priv, TVI_CONTROL_IS_VIDEO, 0) != TVI_CONTROL_TRUE) { - mp_msg(MSGT_TV, MSGL_ERR, "Error: No video input present!\n"); + MP_ERR(tvh, "Error: No video input present!\n"); return 0; } @@ -458,8 +459,7 @@ static int open_tv(tvi_handle_t *tvh) case MP_FOURCC_BGR15: break; default: - mp_msg(MSGT_TV, MSGL_ERR, - "==================================================================\n"\ + MP_ERR(tvh, "==================================================================\n"\ " WARNING: UNTESTED OR UNKNOWN OUTPUT IMAGE FORMAT REQUESTED (0x%x)\n"\ " This may cause buggy playback or program crash! Bug reports will\n"\ " be ignored! You should try again with YV12 (which is the default\n"\ @@ -492,7 +492,7 @@ static int open_tv(tvi_handle_t *tvh) funcs->control(tvh->priv, TVI_CONTROL_VID_SET_WIDTH, &tvh->tv_param->width); else { - mp_msg(MSGT_TV, MSGL_ERR, "Unable to set requested width: %d\n", tvh->tv_param->width); + MP_ERR(tvh, "Unable to set requested width: %d\n", tvh->tv_param->width); funcs->control(tvh->priv, TVI_CONTROL_VID_GET_WIDTH, &tvh->tv_param->width); } } @@ -504,14 +504,14 @@ static int open_tv(tvi_handle_t *tvh) funcs->control(tvh->priv, TVI_CONTROL_VID_SET_HEIGHT, &tvh->tv_param->height); else { - mp_msg(MSGT_TV, MSGL_ERR, "Unable to set requested height: %d\n", tvh->tv_param->height); + MP_ERR(tvh, "Unable to set requested height: %d\n", tvh->tv_param->height); funcs->control(tvh->priv, TVI_CONTROL_VID_GET_HEIGHT, &tvh->tv_param->height); } } if (funcs->control(tvh->priv, TVI_CONTROL_IS_TUNER, 0) != TVI_CONTROL_TRUE) { - mp_msg(MSGT_TV, MSGL_WARN, "Selected input hasn't got a tuner!\n"); + MP_WARN(tvh, "Selected input hasn't got a tuner!\n"); goto done; } @@ -527,16 +527,16 @@ static int open_tv(tvi_handle_t *tvh) } if (tvh->chanlist == -1) { - mp_msg(MSGT_TV, MSGL_WARN, "Unable to find selected channel list! (%s)\n", + MP_WARN(tvh, "Unable to find selected channel list! (%s)\n", tvh->tv_param->chanlist); return 0; } else - mp_msg(MSGT_TV, MSGL_V, "Selected channel list: %s (including %d channels)\n", + MP_VERBOSE(tvh, "Selected channel list: %s (including %d channels)\n", chanlists[tvh->chanlist].name, chanlists[tvh->chanlist].count); if (tvh->tv_param->freq && tvh->tv_param->channel) { - mp_msg(MSGT_TV, MSGL_WARN, "You can't set frequency and channel simultaneously!\n"); + MP_WARN(tvh, "You can't set frequency and channel simultaneously!\n"); goto done; } @@ -589,14 +589,14 @@ static int open_tv(tvi_handle_t *tvh) funcs->control(tvh->priv, TVI_CONTROL_TUN_SET_FREQ, &freq); funcs->control(tvh->priv, TVI_CONTROL_TUN_GET_FREQ, &freq); - mp_msg(MSGT_TV, MSGL_V, "Selected frequency: %lu (%.3f)\n", + MP_VERBOSE(tvh, "Selected frequency: %lu (%.3f)\n", freq, freq/16.0); } if (tvh->tv_param->channel) { struct CHANLIST cl; - mp_msg(MSGT_TV, MSGL_V, "Requested channel: %s\n", tvh->tv_param->channel); + MP_VERBOSE(tvh, "Requested channel: %s\n", tvh->tv_param->channel); for (i = 0; i < chanlists[tvh->chanlist].count; i++) { cl = tvh->chanlist_s[i]; @@ -606,7 +606,7 @@ static int open_tv(tvi_handle_t *tvh) { strcpy(tv_channel_last_real, cl.name); tvh->channel = i; - mp_msg(MSGT_TV, MSGL_INFO, "Selected channel: %s (freq: %.3f)\n", + MP_INFO(tvh, "Selected channel: %s (freq: %.3f)\n", cl.name, cl.freq/1000.0); tv_set_freq_float(tvh, cl.freq); break; @@ -639,24 +639,24 @@ done: return 1; } -static tvi_handle_t *tv_begin(tv_param_t* tv_param) +static tvi_handle_t *tv_begin(tv_param_t* tv_param, struct mp_log *log) { int i; tvi_handle_t* h; if(tv_param->driver && !strcmp(tv_param->driver,"help")){ - mp_msg(MSGT_TV,MSGL_INFO,"Available drivers:\n"); + mp_info(log, "Available drivers:\n"); for(i=0;tvi_driver_list[i];i++){ - mp_msg(MSGT_TV,MSGL_INFO," %s\t%s",tvi_driver_list[i]->short_name,tvi_driver_list[i]->name); + mp_info(log, " %s\t%s",tvi_driver_list[i]->short_name,tvi_driver_list[i]->name); if(tvi_driver_list[i]->comment) - mp_msg(MSGT_TV,MSGL_INFO," (%s)",tvi_driver_list[i]->comment); - mp_msg(MSGT_TV,MSGL_INFO,"\n"); + mp_info(log, " (%s)",tvi_driver_list[i]->comment); + mp_info(log, "\n"); } return NULL; } for(i=0;tvi_driver_list[i];i++){ if (!tv_param->driver || !strcmp(tvi_driver_list[i]->short_name, tv_param->driver)){ - h=tvi_driver_list[i]->tvi_init(tv_param); + h=tvi_driver_list[i]->tvi_init(log, tv_param); //Requested driver initialization failed if (!h && tv_param->driver) return NULL; @@ -665,7 +665,7 @@ static tvi_handle_t *tv_begin(tv_param_t* tv_param) continue; h->tv_param=tv_param; - mp_msg(MSGT_TV, MSGL_INFO, "Selected driver: %s\n name: %s\n author: %s\n comment: %s\n", tvi_driver_list[i]->short_name, + MP_INFO(h, "Selected driver: %s\n name: %s\n author: %s\n comment: %s\n", tvi_driver_list[i]->short_name, tvi_driver_list[i]->name, tvi_driver_list[i]->author, tvi_driver_list[i]->comment?tvi_driver_list[i]->comment:""); @@ -675,9 +675,9 @@ static tvi_handle_t *tv_begin(tv_param_t* tv_param) } if(tv_param->driver) - mp_msg(MSGT_TV, MSGL_ERR, "No such driver: %s\n", tv_param->driver); + mp_err(log, "No such driver: %s\n", tv_param->driver); else - mp_msg(MSGT_TV, MSGL_ERR, "TV driver autodetection failed.\n"); + mp_err(log, "TV driver autodetection failed.\n"); return NULL; } @@ -705,7 +705,7 @@ static int demux_open_tv(demuxer_t *demuxer, enum demux_check check) return -1; demuxer->priv=NULL; - if(!(tvh=tv_begin(demuxer->stream->priv))) return -1; + if(!(tvh=tv_begin(demuxer->stream->priv, demuxer->log))) return -1; if (!tvh->functions->init(tvh->priv)) return -1; tvh->demuxer = demuxer; @@ -784,7 +784,7 @@ static int demux_open_tv(demuxer_t *demuxer, enum demux_check check) break; case AF_FORMAT_MPEG2: default: - mp_msg(MSGT_TV, MSGL_ERR, "Audio type '%s' unsupported!\n", + MP_ERR(tvh, "Audio type '%s' unsupported!\n", af_fmt_to_str(audio_format)); goto no_audio; } @@ -816,7 +816,7 @@ static int demux_open_tv(demuxer_t *demuxer, enum demux_check check) sh_audio->wf->nBlockAlign = samplesize * sh_audio->channels.num; sh_audio->wf->nAvgBytesPerSec = sh_audio->i_bps; - mp_msg(MSGT_DECVIDEO, MSGL_V, " TV audio: %d channels, %d bits, %d Hz\n", + MP_VERBOSE(tvh, " TV audio: %d channels, %d bits, %d Hz\n", sh_audio->wf->nChannels, sh_audio->wf->wBitsPerSample, sh_audio->wf->nSamplesPerSec); } @@ -836,7 +836,7 @@ no_audio: if(tvh->tv_param->gain!=-1) if(funcs->control(tvh->priv,TVI_CONTROL_VID_SET_GAIN,&tvh->tv_param->gain)!=TVI_CONTROL_TRUE) - mp_msg(MSGT_TV,MSGL_WARN,"Unable to set gain control!\n"); + MP_WARN(tvh, "Unable to set gain control!\n"); return 0; } @@ -865,7 +865,7 @@ int tv_set_color_options(tvi_handle_t *tvh, int opt, int value) case TV_COLOR_CONTRAST: return funcs->control(tvh->priv, TVI_CONTROL_VID_SET_CONTRAST, &value); default: - mp_msg(MSGT_TV, MSGL_WARN, "Unknown color option (%d) specified!\n", opt); + MP_WARN(tvh, "Unknown color option (%d) specified!\n", opt); } return TVI_CONTROL_UNKNOWN; @@ -886,7 +886,7 @@ int tv_get_color_options(tvi_handle_t *tvh, int opt, int* value) case TV_COLOR_CONTRAST: return funcs->control(tvh->priv, TVI_CONTROL_VID_GET_CONTRAST, value); default: - mp_msg(MSGT_TV, MSGL_WARN, "Unknown color option (%d) specified!\n", opt); + MP_WARN(tvh, "Unknown color option (%d) specified!\n", opt); } return TVI_CONTROL_UNKNOWN; @@ -897,7 +897,7 @@ int tv_get_freq(tvi_handle_t *tvh, unsigned long *freq) if (tvh->functions->control(tvh->priv, TVI_CONTROL_IS_TUNER, 0) == TVI_CONTROL_TRUE) { tvh->functions->control(tvh->priv, TVI_CONTROL_TUN_GET_FREQ, freq); - mp_msg(MSGT_TV, MSGL_V, "Current frequency: %lu (%.3f)\n", + MP_VERBOSE(tvh, "Current frequency: %lu (%.3f)\n", *freq, *freq/16.0); } return 1; @@ -913,7 +913,7 @@ int tv_set_freq(tvi_handle_t *tvh, unsigned long freq) tvh->functions->control(tvh->priv, TVI_CONTROL_TUN_SET_FREQ, &freq); tvh->functions->control(tvh->priv, TVI_CONTROL_TUN_GET_FREQ, &freq); - mp_msg(MSGT_TV, MSGL_V, "Current frequency: %lu (%.3f)\n", + MP_VERBOSE(tvh, "Current frequency: %lu (%.3f)\n", freq, freq/16.0); } return 1; @@ -956,7 +956,7 @@ int tv_step_channel_real(tvi_handle_t *tvh, int direction) { strcpy(tv_channel_last_real, tvh->chanlist_s[tvh->channel].name); cl = tvh->chanlist_s[--tvh->channel]; - mp_msg(MSGT_TV, MSGL_INFO, "Selected channel: %s (freq: %.3f)\n", + MP_INFO(tvh, "Selected channel: %s (freq: %.3f)\n", cl.name, cl.freq/1000.0); tv_set_freq_float(tvh, cl.freq); } @@ -968,7 +968,7 @@ int tv_step_channel_real(tvi_handle_t *tvh, int direction) { strcpy(tv_channel_last_real, tvh->chanlist_s[tvh->channel].name); cl = tvh->chanlist_s[++tvh->channel]; - mp_msg(MSGT_TV, MSGL_INFO, "Selected channel: %s (freq: %.3f)\n", + MP_INFO(tvh, "Selected channel: %s (freq: %.3f)\n", cl.name, cl.freq/1000.0); tv_set_freq_float(tvh, cl.freq); } @@ -1014,7 +1014,7 @@ int tv_set_channel_real(tvi_handle_t *tvh, char *channel) { if (!strcasecmp(cl.name, channel)) { tvh->channel = i; - mp_msg(MSGT_TV, MSGL_INFO, "Selected channel: %s (freq: %.3f)\n", + MP_INFO(tvh, "Selected channel: %s (freq: %.3f)\n", cl.name, cl.freq/1000.0); tv_set_freq_float(tvh, cl.freq); break; @@ -1061,7 +1061,7 @@ int tv_last_channel(tvi_handle_t *tvh) { { strcpy(tv_channel_last_real, tvh->chanlist_s[tvh->channel].name); tvh->channel = i; - mp_msg(MSGT_TV, MSGL_INFO, "Selected channel: %s (freq: %.3f)\n", + MP_INFO(tvh, "Selected channel: %s (freq: %.3f)\n", cl.name, cl.freq/1000.0); tv_set_freq_float(tvh, cl.freq); break; @@ -1079,7 +1079,7 @@ int tv_step_norm(tvi_handle_t *tvh) tvh->norm = 0; if (tvh->functions->control(tvh->priv, TVI_CONTROL_TUN_SET_NORM, &tvh->norm) != TVI_CONTROL_TRUE) { - mp_msg(MSGT_TV, MSGL_ERR, "Error: Cannot set norm!\n"); + MP_ERR(tvh, "Error: Cannot set norm!\n"); return 0; } } diff --git a/stream/tv.h b/stream/tv.h index 9cbc7ef652..4ab064e7fd 100644 --- a/stream/tv.h +++ b/stream/tv.h @@ -25,6 +25,8 @@ #ifndef MPLAYER_TV_H #define MPLAYER_TV_H +struct mp_log; + typedef struct tv_param_s { char *freq; char *channel; @@ -77,7 +79,7 @@ extern tv_param_t stream_tv_defaults; typedef struct tvi_info_s { - struct tvi_handle_s * (*tvi_init)(tv_param_t* tv_param); + struct tvi_handle_s * (*tvi_init)(struct mp_log *log, tv_param_t* tv_param); const char *name; const char *short_name; const char *author; @@ -100,6 +102,7 @@ typedef struct tvi_functions_s } tvi_functions_t; typedef struct tvi_handle_s { + struct mp_log *log; const tvi_functions_t *functions; void *priv; int seq; @@ -225,7 +228,7 @@ int tv_set_norm(tvi_handle_t *tvh, char* norm); void tv_start_scan(tvi_handle_t *tvh, int start); -tvi_handle_t *tv_new_handle(int size, const tvi_functions_t *functions); +tvi_handle_t *tv_new_handle(int size, struct mp_log *log, const tvi_functions_t *functions); void tv_free_handle(tvi_handle_t *h); #define TV_NORM_PAL 1 diff --git a/stream/tvi_dummy.c b/stream/tvi_dummy.c index 24590fa428..0d9e86c210 100644 --- a/stream/tvi_dummy.c +++ b/stream/tvi_dummy.c @@ -24,7 +24,7 @@ #include "video/img_fourcc.h" #include "tv.h" -static tvi_handle_t *tvi_init_dummy(tv_param_t* tv_param); +static tvi_handle_t *tvi_init_dummy(struct mp_log *log, tv_param_t* tv_param); /* information about this file */ const tvi_info_t tvi_info_dummy = { tvi_init_dummy, @@ -43,9 +43,9 @@ typedef struct priv { #include "tvi_def.h" /* handler creator - entry point ! */ -static tvi_handle_t *tvi_init_dummy(tv_param_t* tv_param) +static tvi_handle_t *tvi_init_dummy(struct mp_log *log, tv_param_t* tv_param) { - return tv_new_handle(sizeof(priv_t), &functions); + return tv_new_handle(sizeof(priv_t), log, &functions); } /* initialisation */ diff --git a/stream/tvi_v4l2.c b/stream/tvi_v4l2.c index 6132ad7708..b6f77edf31 100644 --- a/stream/tvi_v4l2.c +++ b/stream/tvi_v4l2.c @@ -72,7 +72,7 @@ known issues: #endif #define info tvi_info_v4l2 -static tvi_handle_t *tvi_init_v4l2(tv_param_t* tv_param); +static tvi_handle_t *tvi_init_v4l2(struct mp_log *log, tv_param_t* tv_param); /* information about this file */ const tvi_info_t tvi_info_v4l2 = { tvi_init_v4l2, @@ -100,6 +100,7 @@ typedef struct { /* private data */ typedef struct priv { /* video */ + struct mp_log *log; char *video_dev; int video_fd; int mp_format; @@ -395,7 +396,7 @@ static void setup_audio_buffer_sizes(priv_t *priv) *bytes_per_sample/priv->audio_in.blocksize; if (priv->aud_skew_cnt < 16) priv->aud_skew_cnt = 16; - mp_msg(MSGT_TV, MSGL_V, "Audio capture - buffer %d blocks of %d bytes, skew average from %d meas.\n", + MP_VERBOSE(priv, "Audio capture - buffer %d blocks of %d bytes, skew average from %d meas.\n", priv->audio_buffer_size, priv->audio_in.blocksize, priv->aud_skew_cnt); } @@ -406,11 +407,11 @@ static void init_audio(priv_t *priv) if (!priv->tv_param->noaudio) { #if HAVE_ALSA if (priv->tv_param->alsa) - audio_in_init(&priv->audio_in, AUDIO_IN_ALSA); + audio_in_init(&priv->audio_in, priv->log, AUDIO_IN_ALSA); else - audio_in_init(&priv->audio_in, AUDIO_IN_OSS); + audio_in_init(&priv->audio_in, priv->log, AUDIO_IN_OSS); #else - audio_in_init(&priv->audio_in, AUDIO_IN_OSS); + audio_in_init(&priv->audio_in, priv->log, AUDIO_IN_OSS); #endif if (priv->audio_dev) { @@ -458,7 +459,7 @@ static int getfmt(priv_t *priv) priv->format.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; if ((i = v4l2_ioctl(priv->video_fd, VIDIOC_G_FMT, &priv->format)) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl get format failed: %s\n", + MP_ERR(priv, "%s: ioctl get format failed: %s\n", info.short_name, strerror(errno)); } return i; @@ -478,7 +479,7 @@ static int getstd(priv_t *priv) parm.type=V4L2_BUF_TYPE_VIDEO_CAPTURE; if(v4l2_ioctl(priv->video_fd, VIDIOC_G_PARM, &parm) >= 0) { - mp_msg(MSGT_TV, MSGL_WARN, "%s: your device driver does not support VIDIOC_G_STD ioctl," + MP_WARN(priv, "%s: your device driver does not support VIDIOC_G_STD ioctl," " VIDIOC_G_PARM was used instead.\n", info.short_name); priv->standard.index=0; priv->standard.id=0; @@ -486,7 +487,7 @@ static int getstd(priv_t *priv) return 0; } - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl get standard failed: %s\n", + MP_ERR(priv, "%s: ioctl get standard failed: %s\n", info.short_name, strerror(errno)); return -1; } @@ -513,7 +514,7 @@ static int set_mute(priv_t *priv, int value) control.id = V4L2_CID_AUDIO_MUTE; control.value = value; if (v4l2_ioctl(priv->video_fd, VIDIOC_S_CTRL, &control) < 0) { - mp_msg(MSGT_TV,MSGL_ERR,"%s: ioctl set mute failed: %s\n", + MP_ERR(priv, "%s: ioctl set mute failed: %s\n", info.short_name, strerror(errno)); return 0; } @@ -528,7 +529,7 @@ static int set_control(priv_t *priv, struct v4l2_control *control, int val_signe struct v4l2_queryctrl qctrl; qctrl.id = control->id; if (v4l2_ioctl(priv->video_fd, VIDIOC_QUERYCTRL, &qctrl) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl query control failed: %s\n", + MP_ERR(priv, "%s: ioctl query control failed: %s\n", info.short_name, strerror(errno)); return TVI_CONTROL_FALSE; } @@ -553,11 +554,11 @@ static int set_control(priv_t *priv, struct v4l2_control *control, int val_signe if (v4l2_ioctl(priv->video_fd, VIDIOC_S_CTRL, control) < 0) { - mp_msg(MSGT_TV, MSGL_ERR,"%s: ioctl set %s %d failed: %s\n", + MP_ERR(priv, "%s: ioctl set %s %d failed: %s\n", info.short_name, qctrl.name, control->value, strerror(errno)); return TVI_CONTROL_FALSE; } - mp_msg(MSGT_TV, MSGL_V, "%s: set %s: %d [%d, %d]\n", info.short_name, + MP_VERBOSE(priv, "%s: set %s: %d [%d, %d]\n", info.short_name, qctrl.name, control->value, qctrl.minimum, qctrl.maximum); return TVI_CONTROL_TRUE; @@ -572,17 +573,17 @@ static int get_control(priv_t *priv, struct v4l2_control *control, int val_signe qctrl.id = control->id; if (v4l2_ioctl(priv->video_fd, VIDIOC_QUERYCTRL, &qctrl) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl query control failed: %s\n", + MP_ERR(priv, "%s: ioctl query control failed: %s\n", info.short_name, strerror(errno)); return TVI_CONTROL_FALSE; } if (v4l2_ioctl(priv->video_fd, VIDIOC_G_CTRL, control) < 0) { - mp_msg(MSGT_TV, MSGL_ERR,"%s: ioctl get %s failed: %s\n", + MP_ERR(priv, "%s: ioctl get %s failed: %s\n", info.short_name, qctrl.name, strerror(errno)); return TVI_CONTROL_FALSE; } - mp_msg(MSGT_TV, MSGL_V, "%s: get %s: %d [%d, %d]\n", info.short_name, + MP_VERBOSE(priv, "%s: get %s: %d [%d, %d]\n", info.short_name, qctrl.name, control->value, qctrl.minimum, qctrl.maximum); if (val_signed) { @@ -625,19 +626,19 @@ static int do_control(priv_t *priv, int cmd, void *arg) return TVI_CONTROL_TRUE; case TVI_CONTROL_VID_GET_FPS: *(float *)arg = getfps(priv); - mp_msg(MSGT_TV, MSGL_V, "%s: get fps: %f\n", info.short_name, + MP_VERBOSE(priv, "%s: get fps: %f\n", info.short_name, *(float *)arg); return TVI_CONTROL_TRUE; case TVI_CONTROL_VID_GET_BITS: if (getfmt(priv) < 0) return TVI_CONTROL_FALSE; *(int *)arg = pixfmt2depth(priv->format.fmt.pix.pixelformat); - mp_msg(MSGT_TV, MSGL_V, "%s: get depth: %d\n", info.short_name, + MP_VERBOSE(priv, "%s: get depth: %d\n", info.short_name, *(int *)arg); return TVI_CONTROL_TRUE; case TVI_CONTROL_VID_GET_FORMAT: if (getfmt(priv) < 0) return TVI_CONTROL_FALSE; *(int *)arg = fcc_vl2mp(priv->format.fmt.pix.pixelformat); - mp_msg(MSGT_TV, MSGL_V, "%s: get format: %s\n", info.short_name, + MP_VERBOSE(priv, "%s: get format: %s\n", info.short_name, pixfmt2name(priv->format.fmt.pix.pixelformat)); return TVI_CONTROL_TRUE; case TVI_CONTROL_VID_SET_FORMAT: @@ -646,10 +647,10 @@ static int do_control(priv_t *priv, int cmd, void *arg) priv->format.fmt.pix.field = V4L2_FIELD_ANY; priv->mp_format = *(int *)arg; - mp_msg(MSGT_TV, MSGL_V, "%s: set format: %s\n", info.short_name, + MP_VERBOSE(priv, "%s: set format: %s\n", info.short_name, pixfmt2name(priv->format.fmt.pix.pixelformat)); if (v4l2_ioctl(priv->video_fd, VIDIOC_S_FMT, &priv->format) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set format failed: %s\n", + MP_ERR(priv, "%s: ioctl set format failed: %s\n", info.short_name, strerror(errno)); return TVI_CONTROL_FALSE; } @@ -660,7 +661,7 @@ static int do_control(priv_t *priv, int cmd, void *arg) case TVI_CONTROL_VID_GET_WIDTH: if (getfmt(priv) < 0) return TVI_CONTROL_FALSE; *(int *)arg = priv->format.fmt.pix.width; - mp_msg(MSGT_TV, MSGL_V, "%s: get width: %d\n", info.short_name, + MP_VERBOSE(priv, "%s: get width: %d\n", info.short_name, *(int *)arg); return TVI_CONTROL_TRUE; case TVI_CONTROL_VID_CHK_WIDTH: @@ -676,10 +677,10 @@ static int do_control(priv_t *priv, int cmd, void *arg) case TVI_CONTROL_VID_SET_WIDTH: if (getfmt(priv) < 0) return TVI_CONTROL_FALSE; priv->format.fmt.pix.width = *(int *)arg; - mp_msg(MSGT_TV, MSGL_V, "%s: set width: %d\n", info.short_name, + MP_VERBOSE(priv, "%s: set width: %d\n", info.short_name, *(int *)arg); if (v4l2_ioctl(priv->video_fd, VIDIOC_S_FMT, &priv->format) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set width failed: %s\n", + MP_ERR(priv, "%s: ioctl set width failed: %s\n", info.short_name, strerror(errno)); return TVI_CONTROL_FALSE; } @@ -687,7 +688,7 @@ static int do_control(priv_t *priv, int cmd, void *arg) case TVI_CONTROL_VID_GET_HEIGHT: if (getfmt(priv) < 0) return TVI_CONTROL_FALSE; *(int *)arg = priv->format.fmt.pix.height; - mp_msg(MSGT_TV, MSGL_V, "%s: get height: %d\n", info.short_name, + MP_VERBOSE(priv, "%s: get height: %d\n", info.short_name, *(int *)arg); return TVI_CONTROL_TRUE; case TVI_CONTROL_VID_CHK_HEIGHT: @@ -696,10 +697,10 @@ static int do_control(priv_t *priv, int cmd, void *arg) if (getfmt(priv) < 0) return TVI_CONTROL_FALSE; priv->format.fmt.pix.height = *(int *)arg; priv->format.fmt.pix.field = V4L2_FIELD_ANY; - mp_msg(MSGT_TV, MSGL_V, "%s: set height: %d\n", info.short_name, + MP_VERBOSE(priv, "%s: set height: %d\n", info.short_name, *(int *)arg); if (v4l2_ioctl(priv->video_fd, VIDIOC_S_FMT, &priv->format) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set height failed: %s\n", + MP_ERR(priv, "%s: ioctl set height failed: %s\n", info.short_name, strerror(errno)); return TVI_CONTROL_FALSE; } @@ -786,7 +787,7 @@ static int do_control(priv_t *priv, int cmd, void *arg) frequency.tuner = 0; frequency.type = V4L2_TUNER_ANALOG_TV; if (v4l2_ioctl(priv->video_fd, VIDIOC_G_FREQUENCY, &frequency) < 0) { - mp_msg(MSGT_TV,MSGL_ERR,"%s: ioctl get frequency failed: %s\n", + MP_ERR(priv, "%s: ioctl get frequency failed: %s\n", info.short_name, strerror(errno)); return TVI_CONTROL_FALSE; } @@ -801,7 +802,7 @@ static int do_control(priv_t *priv, int cmd, void *arg) frequency.type = V4L2_TUNER_ANALOG_TV; frequency.frequency = *(int *)arg; if (v4l2_ioctl(priv->video_fd, VIDIOC_S_FREQUENCY, &frequency) < 0) { - mp_msg(MSGT_TV,MSGL_ERR,"%s: ioctl set frequency failed: %s\n", + MP_ERR(priv, "%s: ioctl set frequency failed: %s\n", info.short_name, strerror(errno)); return TVI_CONTROL_FALSE; } @@ -811,17 +812,17 @@ static int do_control(priv_t *priv, int cmd, void *arg) #endif return TVI_CONTROL_TRUE; case TVI_CONTROL_TUN_GET_TUNER: - mp_msg(MSGT_TV, MSGL_V, "%s: get tuner\n",info.short_name); + MP_VERBOSE(priv, "%s: get tuner\n",info.short_name); if (v4l2_ioctl(priv->video_fd, VIDIOC_G_TUNER, &priv->tuner) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl get tuner failed: %s\n", + MP_ERR(priv, "%s: ioctl get tuner failed: %s\n", info.short_name, strerror(errno)); return TVI_CONTROL_FALSE; } return TVI_CONTROL_TRUE; case TVI_CONTROL_TUN_SET_TUNER: - mp_msg(MSGT_TV, MSGL_V, "%s: set tuner\n",info.short_name); + MP_VERBOSE(priv, "%s: set tuner\n",info.short_name); if (v4l2_ioctl(priv->video_fd, VIDIOC_S_TUNER, &priv->tuner) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set tuner failed: %s\n", + MP_ERR(priv, "%s: ioctl set tuner failed: %s\n", info.short_name, strerror(errno)); return TVI_CONTROL_FALSE; } @@ -831,7 +832,7 @@ static int do_control(priv_t *priv, int cmd, void *arg) return TVI_CONTROL_TRUE; case TVI_CONTROL_TUN_GET_SIGNAL: if (v4l2_ioctl(priv->video_fd, VIDIOC_G_TUNER, &priv->tuner) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl get tuner failed: %s\n", + MP_ERR(priv, "%s: ioctl get tuner failed: %s\n", info.short_name, strerror(errno)); return TVI_CONTROL_FALSE; } @@ -840,13 +841,13 @@ static int do_control(priv_t *priv, int cmd, void *arg) case TVI_CONTROL_TUN_SET_NORM: priv->standard.index = *(int *)arg; if (v4l2_ioctl(priv->video_fd, VIDIOC_ENUMSTD, &priv->standard) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl enum norm failed: %s\n", + MP_ERR(priv, "%s: ioctl enum norm failed: %s\n", info.short_name, strerror(errno)); return TVI_CONTROL_FALSE; } - mp_msg(MSGT_TV, MSGL_V, "%s: set norm: %s\n", info.short_name, priv->standard.name); + MP_VERBOSE(priv, "%s: set norm: %s\n", info.short_name, priv->standard.name); if (v4l2_ioctl(priv->video_fd, VIDIOC_S_STD, &priv->standard.id) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set norm failed: %s\n", + MP_ERR(priv, "%s: ioctl set norm failed: %s\n", info.short_name, strerror(errno)); return TVI_CONTROL_FALSE; } @@ -869,21 +870,21 @@ static int do_control(priv_t *priv, int cmd, void *arg) } case TVI_CONTROL_SPC_GET_INPUT: if (v4l2_ioctl(priv->video_fd, VIDIOC_G_INPUT, (int *)arg) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl get input failed: %s\n", + MP_ERR(priv, "%s: ioctl get input failed: %s\n", info.short_name, strerror(errno)); return TVI_CONTROL_FALSE; } return TVI_CONTROL_TRUE; case TVI_CONTROL_SPC_SET_INPUT: - mp_msg(MSGT_TV, MSGL_V, "%s: set input: %d\n", info.short_name, *(int *)arg); + MP_VERBOSE(priv, "%s: set input: %d\n", info.short_name, *(int *)arg); priv->input.index = *(int *)arg; if (v4l2_ioctl(priv->video_fd, VIDIOC_ENUMINPUT, &priv->input) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl enum input failed: %s\n", + MP_ERR(priv, "%s: ioctl enum input failed: %s\n", info.short_name, strerror(errno)); return TVI_CONTROL_FALSE; } if (v4l2_ioctl(priv->video_fd, VIDIOC_S_INPUT, (int *)arg) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set input failed: %s\n", + MP_ERR(priv, "%s: ioctl set input failed: %s\n", info.short_name, strerror(errno)); return TVI_CONTROL_FALSE; } @@ -892,32 +893,32 @@ static int do_control(priv_t *priv, int cmd, void *arg) init_audio(priv); if (!priv->audio_initialized) return TVI_CONTROL_FALSE; *(int *)arg = AF_FORMAT_S16_LE; - mp_msg(MSGT_TV, MSGL_V, "%s: get audio format: %d\n", + MP_VERBOSE(priv, "%s: get audio format: %d\n", info.short_name, *(int *)arg); return TVI_CONTROL_TRUE; case TVI_CONTROL_AUD_GET_SAMPLERATE: init_audio(priv); if (!priv->audio_initialized) return TVI_CONTROL_FALSE; *(int *)arg = priv->audio_in.samplerate; - mp_msg(MSGT_TV, MSGL_V, "%s: get audio samplerate: %d\n", + MP_VERBOSE(priv, "%s: get audio samplerate: %d\n", info.short_name, *(int *)arg); return TVI_CONTROL_TRUE; case TVI_CONTROL_AUD_GET_CHANNELS: init_audio(priv); if (!priv->audio_initialized) return TVI_CONTROL_FALSE; *(int *)arg = priv->audio_in.channels; - mp_msg(MSGT_TV, MSGL_V, "%s: get audio channels: %d\n", + MP_VERBOSE(priv, "%s: get audio channels: %d\n", info.short_name, *(int *)arg); return TVI_CONTROL_TRUE; case TVI_CONTROL_AUD_SET_SAMPLERATE: init_audio(priv); - mp_msg(MSGT_TV, MSGL_V, "%s: set audio samplerate: %d\n", + MP_VERBOSE(priv, "%s: set audio samplerate: %d\n", info.short_name, *(int *)arg); if (audio_in_set_samplerate(&priv->audio_in, *(int*)arg) < 0) return TVI_CONTROL_FALSE; // setup_audio_buffer_sizes(priv); return TVI_CONTROL_TRUE; } - mp_msg(MSGT_TV, MSGL_V, "%s: unknown control: %d\n", info.short_name, cmd); + MP_VERBOSE(priv, "%s: unknown control: %d\n", info.short_name, cmd); return TVI_CONTROL_UNKNOWN; } @@ -925,14 +926,15 @@ static int do_control(priv_t *priv, int cmd, void *arg) #define PRIV ((priv_t *) (tvi_handle->priv)) /* handler creator - entry point ! */ -static tvi_handle_t *tvi_init_v4l2(tv_param_t* tv_param) +static tvi_handle_t *tvi_init_v4l2(struct mp_log *log, tv_param_t* tv_param) { tvi_handle_t *tvi_handle; - tvi_handle = tv_new_handle(sizeof(priv_t), &functions); + tvi_handle = tv_new_handle(sizeof(priv_t), log, &functions); if (!tvi_handle) { return NULL; } + PRIV->log = log; PRIV->video_fd = -1; PRIV->video_dev = strdup(tv_param->device? tv_param->device: "/dev/video0"); @@ -975,7 +977,7 @@ static int uninit(priv_t *priv) /* turn off streaming */ if (v4l2_ioctl(priv->video_fd, VIDIOC_STREAMOFF, &(priv->map[0].buf.type)) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl streamoff failed: %s\n", + MP_ERR(priv, "%s: ioctl streamoff failed: %s\n", info.short_name, strerror(errno)); } priv->streamon = 0; @@ -990,7 +992,7 @@ static int uninit(priv_t *priv) /* unmap all buffers */ for (i = 0; i < priv->mapcount; i++) { if (v4l2_munmap(priv->map[i].addr, priv->map[i].len) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: munmap capture buffer failed: %s\n", + MP_ERR(priv, "%s: munmap capture buffer failed: %s\n", info.short_name, strerror(errno)); } } @@ -1025,10 +1027,9 @@ static int uninit(priv_t *priv) } /* show some nice statistics ;-) */ - mp_msg(MSGT_TV, MSGL_INFO, - "%s: %d frames successfully processed, %d frames dropped.\n", + MP_INFO(priv, "%s: %d frames successfully processed, %d frames dropped.\n", info.short_name, priv->frames, dropped); - mp_msg(MSGT_TV, MSGL_V, "%s: up to %u video frames buffered.\n", + MP_VERBOSE(priv, "%s: up to %u video frames buffered.\n", info.short_name, priv->video_buffer_size_current); return 1; } @@ -1048,12 +1049,12 @@ static int init(priv_t *priv) /* Open the video device. */ priv->video_fd = v4l2_open(priv->video_dev, O_RDWR); if (priv->video_fd < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: unable to open '%s': %s\n", + MP_ERR(priv, "%s: unable to open '%s': %s\n", info.short_name, priv->video_dev, strerror(errno)); uninit(priv); return 0; } - mp_msg(MSGT_TV, MSGL_DBG2, "%s: video fd: %s: %d\n", + MP_DBG(priv, "%s: video fd: %s: %d\n", info.short_name, priv->video_dev, priv->video_fd); /* @@ -1061,7 +1062,7 @@ static int init(priv_t *priv) ** for further control calls. */ if (v4l2_ioctl(priv->video_fd, VIDIOC_QUERYCAP, &priv->capability) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl query capabilities failed: %s\n", + MP_ERR(priv, "%s: ioctl query capabilities failed: %s\n", info.short_name, strerror(errno)); uninit(priv); return 0; @@ -1069,7 +1070,7 @@ static int init(priv_t *priv) if (!(priv->capability.capabilities & V4L2_CAP_VIDEO_CAPTURE)) { - mp_msg(MSGT_TV, MSGL_ERR, "Device %s is not a video capture device.\n", + MP_ERR(priv, "Device %s is not a video capture device.\n", priv->video_dev); return 0; } @@ -1085,25 +1086,25 @@ static int init(priv_t *priv) */ if (priv->capability.capabilities & V4L2_CAP_TUNER) { if (v4l2_ioctl(priv->video_fd, VIDIOC_G_TUNER, &priv->tuner) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl get tuner failed: %s\n", + MP_ERR(priv, "%s: ioctl get tuner failed: %s\n", info.short_name, strerror(errno)); uninit(priv); return 0; } } - mp_msg(MSGT_TV, MSGL_INFO, "Selected device: %s\n", priv->capability.card); + MP_INFO(priv, "Selected device: %s\n", priv->capability.card); if (priv->capability.capabilities & V4L2_CAP_TUNER) { - mp_msg(MSGT_TV, MSGL_INFO, " Tuner cap:%s%s%s\n", + MP_INFO(priv, " Tuner cap:%s%s%s\n", (priv->tuner.capability & V4L2_TUNER_CAP_STEREO) ? " STEREO" : "", (priv->tuner.capability & V4L2_TUNER_CAP_LANG1) ? " LANG1" : "", (priv->tuner.capability & V4L2_TUNER_CAP_LANG2) ? " LANG2" : ""); - mp_msg(MSGT_TV, MSGL_INFO, " Tuner rxs:%s%s%s%s\n", + MP_INFO(priv, " Tuner rxs:%s%s%s%s\n", (priv->tuner.rxsubchans & V4L2_TUNER_SUB_MONO) ? " MONO" : "", (priv->tuner.rxsubchans & V4L2_TUNER_SUB_STEREO) ? " STEREO" : "", (priv->tuner.rxsubchans & V4L2_TUNER_SUB_LANG1) ? " LANG1" : "", (priv->tuner.rxsubchans & V4L2_TUNER_SUB_LANG2) ? " LANG2" : ""); } - mp_msg(MSGT_TV, MSGL_INFO, " Capabilities:%s%s%s%s%s%s%s%s%s%s%s\n", + MP_INFO(priv, " Capabilities:%s%s%s%s%s%s%s%s%s%s%s\n", priv->capability.capabilities & V4L2_CAP_VIDEO_CAPTURE? " video capture": "", priv->capability.capabilities & V4L2_CAP_VIDEO_OUTPUT? @@ -1126,16 +1127,16 @@ static int init(priv_t *priv) " async i/o": "", priv->capability.capabilities & V4L2_CAP_STREAMING? " streaming": ""); - mp_msg(MSGT_TV, MSGL_INFO, " supported norms:"); + MP_INFO(priv, " supported norms:"); for (i = 0;; i++) { struct v4l2_standard standard; memset(&standard, 0, sizeof(standard)); standard.index = i; if (-1 == v4l2_ioctl(priv->video_fd, VIDIOC_ENUMSTD, &standard)) break; - mp_msg(MSGT_TV, MSGL_INFO, " %d = %s;", i, standard.name); + MP_INFO(priv, " %d = %s;", i, standard.name); } - mp_msg(MSGT_TV, MSGL_INFO, "\n inputs:"); + MP_INFO(priv, "\n inputs:"); for (i = 0; 1; i++) { struct v4l2_input input; @@ -1143,14 +1144,14 @@ static int init(priv_t *priv) if (v4l2_ioctl(priv->video_fd, VIDIOC_ENUMINPUT, &input) < 0) { break; } - mp_msg(MSGT_TV, MSGL_INFO, " %d = %s;", i, input.name); + MP_INFO(priv, " %d = %s;", i, input.name); } i = -1; if (v4l2_ioctl(priv->video_fd, VIDIOC_G_INPUT, &i) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl get input failed: %s\n", + MP_ERR(priv, "%s: ioctl get input failed: %s\n", info.short_name, strerror(errno)); } - mp_msg(MSGT_TV, MSGL_INFO, "\n Current input: %d\n", i); + MP_INFO(priv, "\n Current input: %d\n", i); for (i = 0; ; i++) { struct v4l2_fmtdesc fmtdesc; @@ -1159,11 +1160,11 @@ static int init(priv_t *priv) if (v4l2_ioctl(priv->video_fd, VIDIOC_ENUM_FMT, &fmtdesc) < 0) { break; } - mp_msg(MSGT_TV, MSGL_V, " Format %-6s (%2d bits, %s)\n", + MP_VERBOSE(priv, " Format %-6s (%2d bits, %s)\n", pixfmt2name(fmtdesc.pixelformat), pixfmt2depth(fmtdesc.pixelformat), fmtdesc.description); } - mp_msg(MSGT_TV, MSGL_INFO, " Current format: %s\n", + MP_INFO(priv, " Current format: %s\n", pixfmt2name(priv->format.fmt.pix.pixelformat)); /* set some nice defaults */ @@ -1171,7 +1172,7 @@ static int init(priv_t *priv) priv->format.fmt.pix.width = 640; priv->format.fmt.pix.height = 480; if (v4l2_ioctl(priv->video_fd, VIDIOC_S_FMT, &priv->format) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set format failed: %s\n", + MP_ERR(priv, "%s: ioctl set format failed: %s\n", info.short_name, strerror(errno)); uninit(priv); return 0; @@ -1182,15 +1183,15 @@ static int init(priv_t *priv) if (priv->capability.capabilities & V4L2_CAP_TUNER) { struct v4l2_control control; if (priv->tv_param->amode >= 0) { - mp_msg(MSGT_TV, MSGL_V, "%s: setting audio mode\n", info.short_name); + MP_VERBOSE(priv, "%s: setting audio mode\n", info.short_name); priv->tuner.audmode = amode2v4l(priv->tv_param->amode); if (v4l2_ioctl(priv->video_fd, VIDIOC_S_TUNER, &priv->tuner) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl set tuner failed: %s\n", + MP_ERR(priv, "%s: ioctl set tuner failed: %s\n", info.short_name, strerror(errno)); return TVI_CONTROL_FALSE; } } - mp_msg(MSGT_TV, MSGL_INFO, "%s: current audio mode is :%s%s%s%s\n", info.short_name, + MP_INFO(priv, "%s: current audio mode is :%s%s%s%s\n", info.short_name, (priv->tuner.audmode == V4L2_TUNER_MODE_MONO) ? " MONO" : "", (priv->tuner.audmode == V4L2_TUNER_MODE_STEREO) ? " STEREO" : "", (priv->tuner.audmode == V4L2_TUNER_MODE_LANG1) ? " LANG1" : "", @@ -1267,18 +1268,18 @@ static int start(priv_t *priv) setup_audio_buffer_sizes(priv); priv->audio_skew_buffer = calloc(priv->aud_skew_cnt, sizeof(long long)); if (!priv->audio_skew_buffer) { - mp_msg(MSGT_TV, MSGL_ERR, "cannot allocate skew buffer: %s\n", strerror(errno)); + MP_ERR(priv, "cannot allocate skew buffer: %s\n", strerror(errno)); return 0; } priv->audio_skew_delta_buffer = calloc(priv->aud_skew_cnt, sizeof(long long)); if (!priv->audio_skew_delta_buffer) { - mp_msg(MSGT_TV, MSGL_ERR, "cannot allocate skew buffer: %s\n", strerror(errno)); + MP_ERR(priv, "cannot allocate skew buffer: %s\n", strerror(errno)); return 0; } priv->audio_ringbuffer = calloc(priv->audio_in.blocksize, priv->audio_buffer_size); if (!priv->audio_ringbuffer) { - mp_msg(MSGT_TV, MSGL_ERR, "cannot allocate audio buffer: %s\n", strerror(errno)); + MP_ERR(priv, "cannot allocate audio buffer: %s\n", strerror(errno)); return 0; } @@ -1307,7 +1308,7 @@ static int start(priv_t *priv) /* setup video parameters */ if (!priv->tv_param->noaudio) { if (priv->video_buffer_size_max < 3*getfps(priv)*priv->audio_secs_per_block) { - mp_msg(MSGT_TV, MSGL_ERR, "Video buffer shorter than 3 times audio frame duration.\n" + MP_ERR(priv, "Video buffer shorter than 3 times audio frame duration.\n" "You will probably experience heavy framedrops.\n"); } } @@ -1315,14 +1316,14 @@ static int start(priv_t *priv) { int bytesperline = priv->format.fmt.pix.width*pixfmt2depth(priv->format.fmt.pix.pixelformat)/8; - mp_msg(MSGT_TV, MSGL_V, "Using a ring buffer for maximum %d frames, %d MB total size.\n", + MP_VERBOSE(priv, "Using a ring buffer for maximum %d frames, %d MB total size.\n", priv->video_buffer_size_max, priv->video_buffer_size_max*priv->format.fmt.pix.height*bytesperline/(1024*1024)); } priv->video_ringbuffer = calloc(priv->video_buffer_size_max, sizeof(video_buffer_entry)); if (!priv->video_ringbuffer) { - mp_msg(MSGT_TV, MSGL_ERR, "cannot allocate video buffer: %s\n", strerror(errno)); + MP_ERR(priv, "cannot allocate video buffer: %s\n", strerror(errno)); return 0; } memset(priv->video_ringbuffer,0,priv->video_buffer_size_max * sizeof(video_buffer_entry)); @@ -1343,14 +1344,14 @@ static int start(priv_t *priv) request.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; request.memory = V4L2_MEMORY_MMAP; if (v4l2_ioctl(priv->video_fd, VIDIOC_REQBUFS, &request) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl request buffers failed: %s\n", + MP_ERR(priv, "%s: ioctl request buffers failed: %s\n", info.short_name, strerror(errno)); return 0; } /* query buffers */ if (!(priv->map = calloc(request.count, sizeof(struct map)))) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: malloc capture buffers failed: %s\n", + MP_ERR(priv, "%s: malloc capture buffers failed: %s\n", info.short_name, strerror(errno)); return 0; } @@ -1362,7 +1363,7 @@ static int start(priv_t *priv) priv->map[i].buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; priv->map[i].buf.memory = V4L2_MEMORY_MMAP; if (v4l2_ioctl(priv->video_fd, VIDIOC_QUERYBUF, &(priv->map[i].buf)) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl query buffer failed: %s\n", + MP_ERR(priv, "%s: ioctl query buffer failed: %s\n", info.short_name, strerror(errno)); free(priv->map); priv->map = NULL; @@ -1371,7 +1372,7 @@ static int start(priv_t *priv) priv->map[i].addr = v4l2_mmap (0, priv->map[i].buf.length, PROT_READ | PROT_WRITE, MAP_SHARED, priv->video_fd, priv->map[i].buf.m.offset); if (priv->map[i].addr == MAP_FAILED) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: mmap capture buffer failed: %s\n", + MP_ERR(priv, "%s: mmap capture buffer failed: %s\n", info.short_name, strerror(errno)); priv->map[i].len = 0; return 0; @@ -1381,7 +1382,7 @@ static int start(priv_t *priv) priv->mapcount++; if (v4l2_ioctl(priv->video_fd, VIDIOC_QBUF, &(priv->map[i].buf)) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl queue buffer failed: %s\n", + MP_ERR(priv, "%s: ioctl queue buffer failed: %s\n", info.short_name, strerror(errno)); return 0; } @@ -1434,9 +1435,9 @@ static void *video_grabber(void *data) prev_interval = 0; prev_skew = 0; - mp_msg(MSGT_TV, MSGL_V, "%s: going to capture\n", info.short_name); + MP_VERBOSE(priv, "%s: going to capture\n", info.short_name); if (v4l2_ioctl(priv->video_fd, VIDIOC_STREAMON, &(priv->format.type)) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl streamon failed: %s\n", + MP_ERR(priv, "%s: ioctl streamon failed: %s\n", info.short_name, strerror(errno)); return 0; } @@ -1467,12 +1468,12 @@ static void *video_grabber(void *data) i = select(priv->video_fd + 1, &rdset, NULL, NULL, &timeout); if (i < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: select failed: %s\n", + MP_ERR(priv, "%s: select failed: %s\n", info.short_name, strerror(errno)); continue; } else if (i == 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: select timeout\n", info.short_name); + MP_ERR(priv, "%s: select timeout\n", info.short_name); continue; } else if (!FD_ISSET(priv->video_fd, &rdset)) { @@ -1493,7 +1494,7 @@ static void *video_grabber(void *data) observed with saa7134 0.2.8 don't know if is it a bug or (mis)feature */ - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl dequeue buffer failed: %s, idx = %d\n", + MP_ERR(priv, "%s: ioctl dequeue buffer failed: %s, idx = %d\n", info.short_name, strerror(errno), buf.index); for (i = 0; i < priv->mapcount; i++) { memset(&buf,0,sizeof(buf)); @@ -1502,13 +1503,13 @@ static void *video_grabber(void *data) buf.index = i; ret = v4l2_ioctl(priv->video_fd, VIDIOC_QUERYBUF, &buf); if (ret < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl query buffer failed: %s, idx = %d\n", + MP_ERR(priv, "%s: ioctl query buffer failed: %s, idx = %d\n", info.short_name, strerror(errno), buf.index); return 0; } if ((buf.flags & (V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_MAPPED | V4L2_BUF_FLAG_DONE)) == V4L2_BUF_FLAG_MAPPED) { if (v4l2_ioctl(priv->video_fd, VIDIOC_QBUF, &(priv->map[i].buf)) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl queue buffer failed: %s\n", + MP_ERR(priv, "%s: ioctl queue buffer failed: %s\n", info.short_name, strerror(errno)); return 0; } @@ -1544,10 +1545,10 @@ static void *video_grabber(void *data) } } - mp_msg(MSGT_TV, MSGL_DBG3, "\nfps = %f, interval = %f, a_skew = %f, corr_skew = %f\n", + MP_TRACE(priv, "\nfps = %f, interval = %f, a_skew = %f, corr_skew = %f\n", delta ? (double)1e6/delta : -1, (double)1e-6*interval, (double)1e-6*xskew, (double)1e-6*skew); - mp_msg(MSGT_TV, MSGL_DBG3, "vcnt = %d, acnt = %d\n", priv->video_cnt, priv->audio_cnt); + MP_TRACE(priv, "vcnt = %d, acnt = %d\n", priv->video_cnt, priv->audio_cnt); prev_skew = skew; prev_interval = interval; @@ -1570,7 +1571,7 @@ static void *video_grabber(void *data) if (priv->video_cnt == priv->video_buffer_size_current) { if (!priv->immediate_mode) { - mp_msg(MSGT_TV, MSGL_ERR, "\nvideo buffer full - dropping frame\n"); + MP_ERR(priv, "\nvideo buffer full - dropping frame\n"); if (priv->audio_insert_null_samples) { pthread_mutex_lock(&priv->audio_mutex); priv->dropped_frames_timeshift += delta; @@ -1599,7 +1600,7 @@ static void *video_grabber(void *data) priv->video_cnt++; } if (v4l2_ioctl(priv->video_fd, VIDIOC_QBUF, &buf) < 0) { - mp_msg(MSGT_TV, MSGL_ERR, "%s: ioctl queue buffer failed: %s\n", + MP_ERR(priv, "%s: ioctl queue buffer failed: %s\n", info.short_name, strerror(errno)); return 0; } @@ -1746,7 +1747,7 @@ static void *audio_grabber(void *data) pthread_mutex_lock(&priv->audio_mutex); if ((priv->audio_tail+1) % priv->audio_buffer_size == priv->audio_head) { - mp_msg(MSGT_TV, MSGL_ERR, "\ntoo bad - dropping audio frame !\n"); + MP_ERR(priv, "\ntoo bad - dropping audio frame !\n"); priv->audio_drop++; } else { priv->audio_tail = (priv->audio_tail+1) % priv->audio_buffer_size; @@ -1759,7 +1760,7 @@ static void *audio_grabber(void *data) static double grab_audio_frame(priv_t *priv, char *buffer, int len) { - mp_msg(MSGT_TV, MSGL_DBG2, "grab_audio_frame(priv=%p, buffer=%p, len=%d)\n", + MP_DBG(priv, "grab_audio_frame(priv=%p, buffer=%p, len=%d)\n", priv, buffer, len); // hack: if grab_audio_frame is called first, it means we are used by mplayer |