From 0335011f11d9d13f70db6c46ed6189a74d48ec67 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 21 Dec 2013 20:36:45 +0100 Subject: stream: mp_msg conversions We also drop some slave mode stuff from stream_vcd. --- stream/cache.c | 43 +++++++++++++++++++++---------------------- 1 file changed, 21 insertions(+), 22 deletions(-) (limited to 'stream/cache.c') diff --git a/stream/cache.c b/stream/cache.c index 5f01275674..e622ae9af8 100644 --- a/stream/cache.c +++ b/stream/cache.c @@ -73,6 +73,8 @@ struct priv { int64_t seek_limit; // keep filling cache if distance is less that seek limit struct byte_meta *bm; // additional per-byte metadata + struct mp_log *log; + // Owned by the main thread stream_t *cache; // wrapper stream, used by demuxer etc. @@ -142,10 +144,9 @@ static int cache_wakeup_and_wait(struct priv *s, double *retry_time) // Print a "more severe" warning after waiting 1 second and no new data if ((*retry_time) >= 1.0) { - mp_msg(MSGT_CACHE, MSGL_ERR, "Cache keeps not responding.\n"); + MP_ERR(s, "Cache keeps not responding.\n"); } else if (*retry_time > 0.1) { - mp_msg(MSGT_CACHE, MSGL_WARN, - "Cache is not responding - slow/stuck network connection?\n"); + MP_WARN(s, "Cache is not responding - slow/stuck network connection?\n"); } double start = mp_time_sec(); @@ -211,14 +212,13 @@ static bool cache_fill(struct priv *s) if (read < s->min_filepos || read > s->max_filepos) { // seek... - mp_msg(MSGT_CACHE, MSGL_DBG2, - "Out of boundaries... seeking to %" PRId64 " \n", read); + MP_DBG(s, "Out of boundaries... seeking to %" PRId64 " \n", read); // drop cache contents only if seeking backward or too much fwd. // This is also done for on-disk files, since it loses the backseek cache. // That in turn can cause major bandwidth increase and performance // issues with e.g. mov or badly interleaved files if (read < s->min_filepos || read >= s->max_filepos + s->seek_limit) { - mp_msg(MSGT_CACHE, MSGL_V, "Dropping cache at pos %"PRId64", " + MP_VERBOSE(s, "Dropping cache at pos %"PRId64", " "cached range: %"PRId64"-%"PRId64".\n", read, s->min_filepos, s->max_filepos); cache_drop_contents(s); @@ -280,7 +280,7 @@ static bool cache_fill(struct priv *s) s->idle = s->eof; s->reads++; if (s->eof) - mp_msg(MSGT_CACHE, MSGL_V, "EOF reached.\n"); + MP_VERBOSE(s, "EOF reached.\n"); pthread_cond_signal(&s->wakeup); @@ -404,10 +404,10 @@ static void cache_execute_control(struct priv *s) bool pos_changed = old_pos != stream_tell(s->stream); bool ok = s->control_res == STREAM_OK; if (pos_changed && !ok) { - mp_msg(MSGT_STREAM, MSGL_ERR, "STREAM_CTRL changed stream pos but " + MP_ERR(s, "STREAM_CTRL changed stream pos but " "returned error, this is not allowed!\n"); } else if (pos_changed || (ok && control_needs_flush(s->control))) { - mp_msg(MSGT_CACHE, MSGL_V, "Dropping cache due to control()\n"); + MP_VERBOSE(s, "Dropping cache due to control()\n"); s->read_filepos = stream_tell(s->stream); s->control_flush = true; cache_drop_contents(s); @@ -442,7 +442,7 @@ static void *cache_thread(void *arg) } pthread_cond_signal(&s->wakeup); pthread_mutex_unlock(&s->mutex); - mp_msg(MSGT_CACHE, MSGL_V, "Cache exiting...\n"); + MP_VERBOSE(s, "Cache exiting...\n"); return NULL; } @@ -454,8 +454,7 @@ static int cache_fill_buffer(struct stream *cache, char *buffer, int max_len) pthread_mutex_lock(&s->mutex); if (cache->pos != s->read_filepos) - mp_msg(MSGT_CACHE, MSGL_ERR, - "!!! read_filepos differs !!! report this bug...\n"); + MP_ERR(s, "!!! read_filepos differs !!! report this bug...\n"); int t = cache_read(s, buffer, max_len); // wakeup the cache thread, possibly make it read more data ahead @@ -471,7 +470,7 @@ static int cache_seek(stream_t *cache, int64_t pos) pthread_mutex_lock(&s->mutex); - mp_msg(MSGT_CACHE, MSGL_DBG2, "request seek: %" PRId64 " <= to=%" PRId64 + MP_DBG(s, "request seek: %" PRId64 " <= to=%" PRId64 " (cur=%" PRId64 ") <= %" PRId64 " \n", s->min_filepos, pos, s->read_filepos, s->max_filepos); @@ -496,7 +495,7 @@ static int cache_control(stream_t *cache, int cmd, void *arg) if (r != STREAM_ERROR) goto done; - mp_msg(MSGT_CACHE, MSGL_V, "[cache] blocking for STREAM_CTRL %d\n", cmd); + MP_VERBOSE(s, "[cache] blocking for STREAM_CTRL %d\n", cmd); s->control = cmd; s->control_arg = arg; @@ -524,7 +523,7 @@ static void cache_uninit(stream_t *cache) { struct priv *s = cache->priv; if (s->cache_thread_running) { - mp_msg(MSGT_CACHE, MSGL_V, "Terminating cache...\n"); + MP_VERBOSE(s, "Terminating cache...\n"); pthread_mutex_lock(&s->mutex); s->control = CACHE_CTRL_QUIT; pthread_cond_signal(&s->wakeup); @@ -546,16 +545,16 @@ int stream_cache_init(stream_t *cache, stream_t *stream, int64_t size, if (size < 1) return -1; - mp_msg(MSGT_NETWORK, MSGL_INFO, "Cache size set to %" PRId64 " KiB\n", + MP_INFO(cache, "Cache size set to %" PRId64 " KiB\n", size / 1024); if (size > SIZE_MAX) { - mp_msg(MSGT_CACHE, MSGL_FATAL, - "Cache size larger than max. allocation size\n"); + MP_FATAL(cache, "Cache size larger than max. allocation size\n"); return -1; } struct priv *s = talloc_zero(NULL, struct priv); + s->log = cache->log; //64kb min_size s->fill_limit = FFMAX(16 * 1024, BYTE_META_CHUNK_SIZE * 2); @@ -566,7 +565,7 @@ int stream_cache_init(stream_t *cache, stream_t *stream, int64_t size, s->bm = malloc((s->buffer_size / BYTE_META_CHUNK_SIZE + 2) * sizeof(struct byte_meta)); if (!s->buffer || !s->bm) { - mp_msg(MSGT_CACHE, MSGL_ERR, "Failed to allocate cache buffer.\n"); + MP_ERR(s, "Failed to allocate cache buffer.\n"); free(s->buffer); free(s->bm); talloc_free(s); @@ -594,7 +593,7 @@ int stream_cache_init(stream_t *cache, stream_t *stream, int64_t size, min = s->buffer_size - s->fill_limit; if (pthread_create(&s->cache_thread, NULL, cache_thread, s) != 0) { - mp_msg(MSGT_CACHE, MSGL_ERR, "Starting cache process/thread failed: %s.\n", + MP_ERR(s, "Starting cache process/thread failed: %s.\n", strerror(errno)); return -1; } @@ -610,7 +609,7 @@ int stream_cache_init(stream_t *cache, stream_t *stream, int64_t size, break; if (stream_control(s->cache, STREAM_CTRL_GET_CACHE_IDLE, &idle) < 0) break; - mp_msg(MSGT_CACHE, MSGL_STATUS, "\rCache fill: %5.2f%% " + MP_INFO(s, "\rCache fill: %5.2f%% " "(%" PRId64 " bytes) ", 100.0 * fill / s->buffer_size, fill); if (fill >= min) break; @@ -623,6 +622,6 @@ int stream_cache_init(stream_t *cache, stream_t *stream, int64_t size, cache_wakeup_and_wait(s, &(double){0}); pthread_mutex_unlock(&s->mutex); } - mp_msg(MSGT_CACHE, MSGL_STATUS, "\n"); + MP_INFO(s, "\n"); return 1; } -- cgit v1.2.3