From ae12963c6ee0ec04f92bb3e4dd71aa481d79c3b9 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Mon, 11 Apr 2022 13:52:46 +0200 Subject: [PATCH] Update logs --- device/buffer_list.c | 8 ++++---- device/buffer_lock.c | 6 +++--- device/buffer_queue.c | 16 ++++++++-------- device/camera/camera.c | 6 +++--- device/device.c | 20 +++++++++---------- device/libcamera/buffer.cc | 16 ++++++++-------- device/libcamera/buffer_list.cc | 16 ++++++++-------- device/libcamera/device.cc | 18 ++++++++--------- device/libcamera/libcamera.cc | 2 +- device/links.c | 22 ++++++++++----------- device/v4l2/buffer.c | 8 ++++---- device/v4l2/buffer_list.c | 34 ++++++++++++++++----------------- device/v4l2/debug.c | 4 ++-- device/v4l2/device.c | 22 ++++++++++----------- device/v4l2/device_media.c | 24 +++++++++++------------ device/v4l2/device_options.c | 22 ++++++++++----------- ffmpeg/remuxer.c | 8 ++++---- http/http.c | 4 ++-- http/http_ffmpeg.c | 4 ++-- http/http_h264.c | 4 ++-- opts/log.c | 31 +++++++++++++----------------- opts/log.h | 23 +++++++++------------- opts/opts.c | 6 +++--- 23 files changed, 157 insertions(+), 167 deletions(-) diff --git a/device/buffer_list.c b/device/buffer_list.c index 8aad509..737b813 100644 --- a/device/buffer_list.c +++ b/device/buffer_list.c @@ -18,7 +18,7 @@ buffer_list_t *buffer_list_open(const char *name, struct device_s *dev, unsigned goto error; } - E_LOG_INFO( + LOG_INFO( buf_list, "Using: %ux%u/%s, bytesperline=%d", buf_list->fmt_width, @@ -35,13 +35,13 @@ buffer_list_t *buffer_list_open(const char *name, struct device_s *dev, unsigned sprintf(name, "%s:buf%d", buf_list->name, i); buffer_t *buf = buffer_open(name, buf_list, i); if (!buf) { - E_LOG_ERROR(buf_list, "Cannot open buffer: %u", i); + LOG_ERROR(buf_list, "Cannot open buffer: %u", i); goto error; } buf_list->bufs[i] = buf; } - E_LOG_DEBUG(buf_list, "Opened %u buffers", buf_list->nbufs); + LOG_DEBUG(buf_list, "Opened %u buffers", buf_list->nbufs); return buf_list; @@ -86,7 +86,7 @@ int buffer_list_set_stream(buffer_list_t *buf_list, bool do_on) buf_list->streaming = do_on; int enqueued = buffer_list_count_enqueued(buf_list); - E_LOG_VERBOSE(buf_list, "Streaming %s... Was %d of %d enqueud", do_on ? "started" : "stopped", enqueued, buf_list->nbufs); + LOG_VERBOSE(buf_list, "Streaming %s... Was %d of %d enqueud", do_on ? "started" : "stopped", enqueued, buf_list->nbufs); return 0; error: diff --git a/device/buffer_lock.c b/device/buffer_lock.c index c67254c..0d8b051 100644 --- a/device/buffer_lock.c +++ b/device/buffer_lock.c @@ -51,7 +51,7 @@ void buffer_lock_capture(buffer_lock_t *buf_lock, buffer_t *buf) } else if (now - buf_lock->buf_time_us < buf_lock->frame_interval_ms * 1000) { buf_lock->dropped++; - E_LOG_DEBUG(buf_lock, "Dropped buffer %s (refs=%d), frame=%d/%d, frame_ms=%.1f", + LOG_DEBUG(buf_lock, "Dropped buffer %s (refs=%d), frame=%d/%d, frame_ms=%.1f", dev_name(buf), buf ? buf->mmap_reflinks : 0, buf_lock->counter, buf_lock->dropped, (now - buf->captured_time_us) / 1000.0f); @@ -60,7 +60,7 @@ void buffer_lock_capture(buffer_lock_t *buf_lock, buffer_t *buf) buffer_use(buf); buf_lock->buf = buf; buf_lock->counter++; - E_LOG_DEBUG(buf_lock, "Captured buffer %s (refs=%d), frame=%d/%d, processing_ms=%.1f, frame_ms=%.1f", + LOG_DEBUG(buf_lock, "Captured buffer %s (refs=%d), frame=%d/%d, processing_ms=%.1f, frame_ms=%.1f", dev_name(buf), buf ? buf->mmap_reflinks : 0, buf_lock->counter, buf_lock->dropped, (now - buf->captured_time_us) / 1000.0f, @@ -123,7 +123,7 @@ int buffer_lock_write_loop(buffer_lock_t *buf_lock, int nframes, buffer_write_fn } else if (ret < 0) { goto error; } else if(!frames && deadline_ms < get_monotonic_time_us(NULL, NULL)) { - E_LOG_DEBUG(buf_lock, "Deadline getting frame elapsed."); + LOG_DEBUG(buf_lock, "Deadline getting frame elapsed."); goto error; } } diff --git a/device/buffer_queue.c b/device/buffer_queue.c index c403d3b..a4a8ded 100644 --- a/device/buffer_queue.c +++ b/device/buffer_queue.c @@ -32,13 +32,13 @@ bool buffer_consumed(buffer_t *buf, const char *who) pthread_mutex_lock(&buffer_lock); if (buf->mmap_reflinks == 0) { - E_LOG_PERROR(buf, "Non symmetric reference counts"); + LOG_PERROR(buf, "Non symmetric reference counts"); } buf->mmap_reflinks--; if (!buf->enqueued && buf->mmap_reflinks == 0) { - E_LOG_DEBUG(buf, "Queuing buffer... used=%zu length=%zu (linked=%s) by %s", + LOG_DEBUG(buf, "Queuing buffer... used=%zu length=%zu (linked=%s) by %s", buf->used, buf->length, buf->dma_source ? buf->dma_source->name : NULL, @@ -105,7 +105,7 @@ int buffer_list_count_enqueued(buffer_list_t *buf_list) int buffer_list_enqueue(buffer_list_t *buf_list, buffer_t *dma_buf) { if (!buf_list->do_mmap && !dma_buf->buf_list->do_mmap) { - E_LOG_PERROR(buf_list, "Cannot enqueue non-mmap to non-mmap: %s.", dma_buf->name); + LOG_PERROR(buf_list, "Cannot enqueue non-mmap to non-mmap: %s.", dma_buf->name); } buffer_t *buf = buffer_list_find_slot(buf_list); @@ -118,7 +118,7 @@ int buffer_list_enqueue(buffer_list_t *buf_list, buffer_t *dma_buf) if (buf_list->do_mmap) { if (dma_buf->used > buf->length) { - E_LOG_INFO(buf_list, "The dma_buf (%s) is too long: %zu vs space=%zu", + LOG_INFO(buf_list, "The dma_buf (%s) is too long: %zu vs space=%zu", dma_buf->name, dma_buf->used, buf->length); dma_buf->used = buf->length; } @@ -127,10 +127,10 @@ int buffer_list_enqueue(buffer_list_t *buf_list, buffer_t *dma_buf) memcpy(buf->start, dma_buf->start, dma_buf->used); uint64_t after = get_monotonic_time_us(NULL, NULL); - E_LOG_DEBUG(buf, "mmap copy: dest=%p, src=%p (%s), size=%zu, space=%zu, time=%dllus", + LOG_DEBUG(buf, "mmap copy: dest=%p, src=%p (%s), size=%zu, space=%zu, time=%dllus", buf->start, dma_buf->start, dma_buf->name, dma_buf->used, buf->length, after-before); } else { - E_LOG_DEBUG(buf, "dmabuf copy: dest=%p, src=%p (%s, dma_fd=%d), size=%zu", + LOG_DEBUG(buf, "dmabuf copy: dest=%p, src=%p (%s, dma_fd=%d), size=%zu", buf->start, dma_buf->start, dma_buf->name, dma_buf->dma_fd, dma_buf->used); buf->dma_source = dma_buf; @@ -156,13 +156,13 @@ buffer_t *buffer_list_dequeue(buffer_list_t *buf_list) buf_list->last_dequeued_us = get_monotonic_time_us(NULL, NULL); if (buf->mmap_reflinks > 0) { - E_LOG_PERROR(buf, "Buffer appears to be enqueued? (links=%d)", buf->mmap_reflinks); + LOG_PERROR(buf, "Buffer appears to be enqueued? (links=%d)", buf->mmap_reflinks); } buf->enqueued = false; buf->mmap_reflinks = 1; - E_LOG_DEBUG(buf_list, "Grabbed mmap buffer=%u, bytes=%d, used=%d, frame=%d, linked=%s", + LOG_DEBUG(buf_list, "Grabbed mmap buffer=%u, bytes=%d, used=%d, frame=%d, linked=%s", buf->index, buf->length, buf->used, diff --git a/device/camera/camera.c b/device/camera/camera.c index 5ba0296..e90deba 100644 --- a/device/camera/camera.c +++ b/device/camera/camera.c @@ -50,7 +50,7 @@ camera_t *camera_open(camera_options_t *options) break; default: - E_LOG_ERROR(camera, "Unsupported camera type"); + LOG_ERROR(camera, "Unsupported camera type"); } if (!camera->camera) { @@ -60,7 +60,7 @@ camera_t *camera_open(camera_options_t *options) camera->camera->allow_dma = camera->options.allow_dma; if (strstr(camera->camera->bus_info, "usb")) { - E_LOG_INFO(camera, "Disabling DMA since device uses USB (which is likely not working properly)."); + LOG_INFO(camera, "Disabling DMA since device uses USB (which is likely not working properly)."); camera->camera->allow_dma = false; } @@ -103,7 +103,7 @@ camera_t *camera_open(camera_options_t *options) break; default: - E_LOG_ERROR(camera, "Unsupported camera format=%s", fourcc_to_string(camera->options.format).buf); + LOG_ERROR(camera, "Unsupported camera format=%s", fourcc_to_string(camera->options.format).buf); break; } diff --git a/device/device.c b/device/device.c index d5dea59..f326c91 100644 --- a/device/device.c +++ b/device/device.c @@ -12,7 +12,7 @@ device_t *device_open(const char *name, const char *path, device_hw_t *hw) { dev->allow_dma = true; if (dev->hw->device_open(dev) < 0) { - E_LOG_ERROR(dev, "Can't open device: %s", path); + LOG_ERROR(dev, "Can't open device: %s", path); } return dev; @@ -61,7 +61,7 @@ int device_open_buffer_list(device_t *dev, bool do_capture, unsigned width, unsi buf_list = &dev->capture_list; if (dev->capture_list) { - E_LOG_ERROR(dev, "The capture_list is already created."); + LOG_ERROR(dev, "The capture_list is already created."); } sprintf(name, "%s:capture", dev->name); @@ -69,7 +69,7 @@ int device_open_buffer_list(device_t *dev, bool do_capture, unsigned width, unsi buf_list = &dev->output_list; if (dev->output_list) { - E_LOG_ERROR(dev, "The output_list is already created."); + LOG_ERROR(dev, "The output_list is already created."); } sprintf(name, "%s:output", dev->name); @@ -118,8 +118,8 @@ int device_set_stream(device_t *dev, bool do_on) struct v4l2_event_subscription sub = {0}; sub.type = V4L2_EVENT_SOURCE_CHANGE; - E_LOG_DEBUG(dev, "Subscribing to DV-timings events ..."); - xioctl(dev_name(dev), dev->v4l2->dev_fd, do_on ? VIDIOC_SUBSCRIBE_EVENT : VIDIOC_UNSUBSCRIBE_EVENT, &sub); + LOG_DEBUG(dev, "Subscribing to DV-timings events ..."); + ioctl_retried(dev_name(dev), dev->v4l2->dev_fd, do_on ? VIDIOC_SUBSCRIBE_EVENT : VIDIOC_UNSUBSCRIBE_EVENT, &sub); #endif if (dev->capture_list) { @@ -148,15 +148,15 @@ int device_consume_event(device_t *dev) return -1; } - E_LOG_DEBUG(dev, "Consuming V4L2 event ..."); - E_XIOCTL(dev, dev->v4l2->dev_fd, VIDIOC_DQEVENT, &event, "Got some V4L2 device event, but where is it?"); + LOG_DEBUG(dev, "Consuming V4L2 event ..."); + ERR_IOCTL(dev, dev->v4l2->dev_fd, VIDIOC_DQEVENT, &event, "Got some V4L2 device event, but where is it?"); switch (event.type) { case V4L2_EVENT_SOURCE_CHANGE: - E_LOG_INFO(dev, "Got V4L2_EVENT_SOURCE_CHANGE: source changed"); + LOG_INFO(dev, "Got V4L2_EVENT_SOURCE_CHANGE: source changed"); return -1; case V4L2_EVENT_EOS: - E_LOG_INFO(dev, "Got V4L2_EVENT_EOS: end of stream (ignored)"); + LOG_INFO(dev, "Got V4L2_EVENT_EOS: end of stream (ignored)"); return 0; } @@ -219,7 +219,7 @@ void device_set_option_list(device_t *dev, const char *option_list) if (value) { device_set_option_string(dev, key, value); } else { - E_LOG_INFO(dev, "Missing 'key=value' for '%s'", option); + LOG_INFO(dev, "Missing 'key=value' for '%s'", option); continue; } diff --git a/device/libcamera/buffer.cc b/device/libcamera/buffer.cc index 8e2ce2f..1f954fb 100644 --- a/device/libcamera/buffer.cc +++ b/device/libcamera/buffer.cc @@ -6,7 +6,7 @@ int libcamera_buffer_open(buffer_t *buf) buf->libcamera = new buffer_libcamera_t{}; buf->libcamera->request = buf->buf_list->dev->libcamera->camera->createRequest(buf->index); if (!buf->libcamera->request) { - E_LOG_ERROR(buf, "Can't create request"); + LOG_ERROR(buf, "Can't create request"); } for (libcamera::StreamConfiguration &stream_cfg : *buf->buf_list->libcamera->configuration) { @@ -16,12 +16,12 @@ int libcamera_buffer_open(buffer_t *buf) auto const &buffer = buffers[buf->index]; if (buf->libcamera->request->addBuffer(stream, buffer.get()) < 0) { - E_LOG_ERROR(buf, "Can't set buffer for request"); + LOG_ERROR(buf, "Can't set buffer for request"); } for (auto const &plane : buffer->planes()) { if (buf->start) { - E_LOG_ERROR(buf, "Too many planes open."); + LOG_ERROR(buf, "Too many planes open."); } buf->start = mmap(NULL, plane.length, PROT_READ | PROT_WRITE, MAP_SHARED, plane.fd.get(), 0); @@ -30,10 +30,10 @@ int libcamera_buffer_open(buffer_t *buf) buf->dma_fd = plane.fd.get(); if (!buf->start) { - E_LOG_ERROR(buf, "Failed to mmap DMA buffer"); + LOG_ERROR(buf, "Failed to mmap DMA buffer"); } - E_LOG_DEBUG(buf, "Mapped buffer: start=%p, length=%d, fd=%d", + LOG_DEBUG(buf, "Mapped buffer: start=%p, length=%d, fd=%d", buf->start, buf->length, buf->dma_fd); } } @@ -66,7 +66,7 @@ int libcamera_buffer_enqueue(buffer_t *buf, const char *who) // } if (buf->buf_list->dev->libcamera->camera->queueRequest(buf->libcamera->request.get()) < 0) { - E_LOG_ERROR(buf, "Can't queue buffer."); + LOG_ERROR(buf, "Can't queue buffer."); } return 0; @@ -92,12 +92,12 @@ int libcamera_buffer_list_dequeue(buffer_list_t *buf_list, buffer_t **bufp) unsigned index = 0; int n = read(buf_list->libcamera->fds[0], &index, sizeof(index)); if (n != sizeof(index)) { - E_LOG_INFO(buf_list, "Received invalid result from `read`: %d", n); + LOG_INFO(buf_list, "Received invalid result from `read`: %d", n); return -1; } if (index >= buf_list->nbufs) { - E_LOG_INFO(buf_list, "Received invalid index from `read`: %d >= %d", index, buf_list->nbufs); + LOG_INFO(buf_list, "Received invalid index from `read`: %d >= %d", index, buf_list->nbufs); return -1; } diff --git a/device/libcamera/buffer_list.cc b/device/libcamera/buffer_list.cc index a6d93b3..4968f63 100644 --- a/device/libcamera/buffer_list.cc +++ b/device/libcamera/buffer_list.cc @@ -6,12 +6,12 @@ int libcamera_buffer_list_open(buffer_list_t *buf_list, unsigned width, unsigned int got_bufs = 0; if (!buf_list->do_capture) { - E_LOG_INFO(buf_list, "Only capture mode is supported."); + LOG_INFO(buf_list, "Only capture mode is supported."); return -1; } if (!buf_list->do_mmap) { - E_LOG_INFO(buf_list, "Only mmap buffers are supported."); + LOG_INFO(buf_list, "Only mmap buffers are supported."); return -1; } @@ -21,7 +21,7 @@ int libcamera_buffer_list_open(buffer_list_t *buf_list, unsigned width, unsigned buf_list->libcamera->fds[1] = -1; if (pipe2(buf_list->libcamera->fds, O_DIRECT|O_CLOEXEC) < 0) { - E_LOG_INFO(buf_list, "Cannot open `pipe2`."); + LOG_INFO(buf_list, "Cannot open `pipe2`."); return -1; } @@ -38,11 +38,11 @@ int libcamera_buffer_list_open(buffer_list_t *buf_list, unsigned width, unsigned configuration.bufferCount = nbufs; } if (buf_list->libcamera->configuration->validate() == libcamera::CameraConfiguration::Invalid) { - E_LOG_ERROR(buf_list, "Camera configuration invalid"); + LOG_ERROR(buf_list, "Camera configuration invalid"); } if (buf_list->dev->libcamera->camera->configure(buf_list->libcamera->configuration.get()) < 0) { - E_LOG_ERROR(buf_list, "Failed to configure camera"); + LOG_ERROR(buf_list, "Failed to configure camera"); } buf_list->fmt_width = configuration.size.width; @@ -57,7 +57,7 @@ int libcamera_buffer_list_open(buffer_list_t *buf_list, unsigned width, unsigned for (libcamera::StreamConfiguration &stream_config : *buf_list->libcamera->configuration) { if (buf_list->libcamera->allocator->allocate(stream_config.stream()) < 0) { - E_LOG_ERROR(buf_list, "Can't allocate buffers"); + LOG_ERROR(buf_list, "Can't allocate buffers"); } int allocated = buf_list->libcamera->allocator->buffers( @@ -89,14 +89,14 @@ int libcamera_buffer_list_set_stream(buffer_list_t *buf_list, bool do_on) buf_list->libcamera, &buffer_list_libcamera_t::libcamera_buffer_list_dequeued); if (buf_list->dev->libcamera->camera->start() < 0) { - E_LOG_ERROR(buf_list, "Failed to start camera."); + LOG_ERROR(buf_list, "Failed to start camera."); } } else { buf_list->dev->libcamera->camera->requestCompleted.disconnect( buf_list->libcamera, &buffer_list_libcamera_t::libcamera_buffer_list_dequeued); if (buf_list->dev->libcamera->camera->stop() < 0) { - E_LOG_ERROR(buf_list, "Failed to stop camera."); + LOG_ERROR(buf_list, "Failed to stop camera."); } } diff --git a/device/libcamera/device.cc b/device/libcamera/device.cc index ffa1bfe..42630cc 100644 --- a/device/libcamera/device.cc +++ b/device/libcamera/device.cc @@ -14,26 +14,26 @@ int libcamera_device_open(device_t *dev) dev->libcamera->camera_manager = std::make_shared(); int ret = dev->libcamera->camera_manager->start(); if (ret < 0) { - E_LOG_ERROR(dev, "Cannot start camera_manager."); + LOG_ERROR(dev, "Cannot start camera_manager."); } dev->libcamera->camera = dev->libcamera->camera_manager->get(dev->path); if (!dev->libcamera->camera) { if (dev->libcamera->camera_manager->cameras().size()) { for(auto const &camera : dev->libcamera->camera_manager->cameras()) { - E_LOG_INFO(dev, "Available Camera: %s", camera->id().c_str()); + LOG_INFO(dev, "Available Camera: %s", camera->id().c_str()); } } else { - E_LOG_INFO(dev, "No available cameras"); + LOG_INFO(dev, "No available cameras"); } - E_LOG_ERROR(dev, "Camera `%s` was not found.", dev->path); + LOG_ERROR(dev, "Camera `%s` was not found.", dev->path); } if (dev->libcamera->camera->acquire()) { - E_LOG_ERROR(dev, "Failed to acquire `%s` camera.", dev->path); + LOG_ERROR(dev, "Failed to acquire `%s` camera.", dev->path); } - E_LOG_INFO(dev, "Device path=%s opened", dev->path); + LOG_INFO(dev, "Device path=%s opened", dev->path); for (auto const &control : dev->libcamera->camera->controls()) { if (!control.first) @@ -42,7 +42,7 @@ int libcamera_device_open(device_t *dev) auto control_id = control.first; auto control_key = libcamera_device_option_normalize(control_id->name()); - E_LOG_VERBOSE(dev, "Available control: %s (%08x, type=%d)", + LOG_VERBOSE(dev, "Available control: %s (%08x, type=%d)", control_key.c_str(), control_id->id(), control_id->type()); } return 0; @@ -113,10 +113,10 @@ int libcamera_device_set_option(device_t *dev, const char *keyp, const char *val } if (control_value.isNone()) { - E_LOG_ERROR(dev, "The `%s` type `%d` is not supported.", control_key.c_str(), control_id->type()); + LOG_ERROR(dev, "The `%s` type `%d` is not supported.", control_key.c_str(), control_id->type()); } - E_LOG_INFO(dev, "Configuring option %s (%08x, type=%d) = %s", + LOG_INFO(dev, "Configuring option %s (%08x, type=%d) = %s", control_key.c_str(), control_id->id(), control_id->type(), control_value.toString().c_str()); dev->libcamera->controls.set(control_id->id(), control_value); diff --git a/device/libcamera/libcamera.cc b/device/libcamera/libcamera.cc index cd24f3c..6c43bcb 100644 --- a/device/libcamera/libcamera.cc +++ b/device/libcamera/libcamera.cc @@ -25,7 +25,7 @@ extern "C" device_t *device_libcamera_open(const char *name, const char *path) #else // USE_LIBCAMERA extern "C" device_t *device_libcamera_open(const char *name, const char *path) { - E_LOG_INFO(NULL, "libcamera is not supported"); + LOG_INFO(NULL, "libcamera is not supported"); return NULL; } #endif // USE_LIBCAMERA diff --git a/device/links.c b/device/links.c index 81feb16..242a94a 100644 --- a/device/links.c +++ b/device/links.c @@ -87,16 +87,16 @@ int _build_fds(link_t *all_links, struct pollfd *fds, link_t **links, buffer_lis int links_enqueue_from_source(buffer_list_t *buf_list, link_t *link) { if (!link) { - E_LOG_ERROR(buf_list, "Missing link for source"); + LOG_ERROR(buf_list, "Missing link for source"); } buffer_t *buf = buffer_list_dequeue(buf_list); if (!buf) { - E_LOG_ERROR(buf_list, "No buffer dequeued from source?"); + LOG_ERROR(buf_list, "No buffer dequeued from source?"); } if (link->callbacks.validate_buffer && !link->callbacks.validate_buffer(link, buf)) { - E_LOG_DEBUG(buf_list, "Buffer rejected by validation"); + LOG_DEBUG(buf_list, "Buffer rejected by validation"); return 0; } @@ -120,7 +120,7 @@ error: int links_dequeue_from_sink(buffer_list_t *buf_list) { buffer_t *buf = buffer_list_dequeue(buf_list); if (!buf) { - E_LOG_ERROR(buf, "No buffer dequeued from sink?"); + LOG_ERROR(buf, "No buffer dequeued from sink?"); } return 0; @@ -163,7 +163,7 @@ int links_step(link_t *all_links, int timeout_now_ms, int *timeout_next_ms) buffer_list_t *buf_list = buf_lists[i]; link_t *link = links[i]; - E_LOG_DEBUG(buf_list, "pool event=%s%s%s%s%s%08x streaming=%d enqueued=%d/%d paused=%d", + LOG_DEBUG(buf_list, "pool event=%s%s%s%s%s%08x streaming=%d enqueued=%d/%d paused=%d", !fds[i].revents ? "NONE/" : "", fds[i].revents & POLLIN ? "IN/" : "", fds[i].revents & POLLOUT ? "OUT/" : "", @@ -189,12 +189,12 @@ int links_step(link_t *all_links, int timeout_now_ms, int *timeout_next_ms) } if (fds[i].revents & POLLHUP) { - E_LOG_INFO(buf_list, "Device disconnected."); + LOG_INFO(buf_list, "Device disconnected."); return -1; } if (fds[i].revents & POLLERR) { - E_LOG_INFO(buf_list, "Got an error"); + LOG_INFO(buf_list, "Got an error"); return -1; } @@ -205,13 +205,13 @@ int links_step(link_t *all_links, int timeout_now_ms, int *timeout_next_ms) if (buf_list->fmt_interval_us > 0 && now_us - buf_list->last_enqueued_us < buf_list->fmt_interval_us) { *timeout_next_ms = MIN(*timeout_next_ms, (buf_list->last_enqueued_us + buf_list->fmt_interval_us - now_us) / 1000); - E_LOG_DEBUG(buf_list, "skipping dequeue: %.1f / %.1f. enqueued=%d", + LOG_DEBUG(buf_list, "skipping dequeue: %.1f / %.1f. enqueued=%d", (now_us - buf_list->last_enqueued_us) / 1000.0f, buf_list->fmt_interval_us / 1000.0f, buffer_list_count_enqueued(buf_list)); continue; } else if (buf_list->fmt_interval_us > 0) { - E_LOG_DEBUG(buf_list, "since last: %.1f / %.1f. enqueued=%d", + LOG_DEBUG(buf_list, "since last: %.1f / %.1f. enqueued=%d", (now_us - buf_list->last_enqueued_us) / 1000.0f, buf_list->fmt_interval_us / 1000.0f, buffer_list_count_enqueued(buf_list)); @@ -238,12 +238,12 @@ int links_stream(link_t *all_links, bool do_stream) link_t *link = &all_links[i]; if (buffer_list_set_stream(link->source, streaming) < 0) { - E_LOG_ERROR(link->source, "Failed to start streaming"); + LOG_ERROR(link->source, "Failed to start streaming"); } for (int j = 0; link->sinks[j]; j++) { if (buffer_list_set_stream(link->sinks[j], streaming) < 0) { - E_LOG_ERROR(link->sinks[j], "Failed to start streaming"); + LOG_ERROR(link->sinks[j], "Failed to start streaming"); } } } diff --git a/device/v4l2/buffer.c b/device/v4l2/buffer.c index 7641fb6..759311c 100644 --- a/device/v4l2/buffer.c +++ b/device/v4l2/buffer.c @@ -29,7 +29,7 @@ int v4l2_buffer_open(buffer_t *buf) v4l2_buf.memory = V4L2_MEMORY_DMABUF; } - E_XIOCTL(buf_list, dev->v4l2->dev_fd, VIDIOC_QUERYBUF, &v4l2_buf, "Cannot query buffer %d", index); + ERR_IOCTL(buf_list, dev->v4l2->dev_fd, VIDIOC_QUERYBUF, &v4l2_buf, "Cannot query buffer %d", index); uint64_t mem_offset = 0; @@ -51,7 +51,7 @@ int v4l2_buffer_open(buffer_t *buf) v4l2_exp.type = v4l2_buf.type; v4l2_exp.index = buf->index; v4l2_exp.plane = 0; - E_XIOCTL(buf_list, dev->v4l2->dev_fd, VIDIOC_EXPBUF, &v4l2_exp, "Can't export queue buffer=%u to DMA", index); + ERR_IOCTL(buf_list, dev->v4l2->dev_fd, VIDIOC_EXPBUF, &v4l2_exp, "Can't export queue buffer=%u to DMA", index); buf->dma_fd = v4l2_exp.fd; } @@ -120,7 +120,7 @@ int v4l2_buffer_enqueue(buffer_t *buf, const char *who) v4l2_buf.timestamp.tv_sec = buf->captured_time_us / (1000LL * 1000LL); v4l2_buf.timestamp.tv_usec = buf->captured_time_us % (1000LL * 1000LL); - E_XIOCTL(buf, buf->buf_list->dev->v4l2->dev_fd, VIDIOC_QBUF, &v4l2_buf, "Can't queue buffer."); + ERR_IOCTL(buf, buf->buf_list->dev->v4l2->dev_fd, VIDIOC_QBUF, &v4l2_buf, "Can't queue buffer."); return 0; @@ -141,7 +141,7 @@ int v4l2_buffer_list_dequeue(buffer_list_t *buf_list, buffer_t **bufp) v4l2_buf.m.planes = &v4l2_plane; } - E_XIOCTL(buf_list, buf_list->dev->v4l2->dev_fd, VIDIOC_DQBUF, &v4l2_buf, "Can't grab capture buffer (flags=%08x)", v4l2_buf.flags); + ERR_IOCTL(buf_list, buf_list->dev->v4l2->dev_fd, VIDIOC_DQBUF, &v4l2_buf, "Can't grab capture buffer (flags=%08x)", v4l2_buf.flags); buffer_t *buf = *bufp = buf_list->bufs[v4l2_buf.index]; if (buf_list->v4l2->do_mplanes) { diff --git a/device/v4l2/buffer_list.c b/device/v4l2/buffer_list.c index 2360b97..51a0d44 100644 --- a/device/v4l2/buffer_list.c +++ b/device/v4l2/buffer_list.c @@ -12,7 +12,7 @@ int v4l2_buffer_list_open(buffer_list_t *buf_list, unsigned width, unsigned heig buf_list->v4l2 = calloc(1, sizeof(buffer_list_v4l2_t)); struct v4l2_capability v4l2_cap; - E_XIOCTL(dev, dev->v4l2->dev_fd, VIDIOC_QUERYCAP, &v4l2_cap, "Can't query device capabilities"); + ERR_IOCTL(dev, dev->v4l2->dev_fd, VIDIOC_QUERYCAP, &v4l2_cap, "Can't query device capabilities"); if (buf_list->do_capture) { if (v4l2_cap.capabilities & V4L2_CAP_VIDEO_CAPTURE) { @@ -21,7 +21,7 @@ int v4l2_buffer_list_open(buffer_list_t *buf_list, unsigned width, unsigned heig buf_list->v4l2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; buf_list->v4l2->do_mplanes = true; } else { - E_LOG_ERROR(dev, "Video capture is not supported by device: %08x", v4l2_cap.capabilities); + LOG_ERROR(dev, "Video capture is not supported by device: %08x", v4l2_cap.capabilities); } } else { if (v4l2_cap.capabilities & V4L2_CAP_VIDEO_OUTPUT) { @@ -30,7 +30,7 @@ int v4l2_buffer_list_open(buffer_list_t *buf_list, unsigned width, unsigned heig buf_list->v4l2->type = V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE; buf_list->v4l2->do_mplanes = true; } else { - E_LOG_ERROR(dev, "Video output is not supported by device: %08x", v4l2_cap.capabilities); + LOG_ERROR(dev, "Video output is not supported by device: %08x", v4l2_cap.capabilities); } } @@ -52,15 +52,15 @@ int v4l2_buffer_list_open(buffer_list_t *buf_list, unsigned width, unsigned heig if (strstr(buf_list->name, "JPEG") || strstr(buf_list->name, "H264") || buf_list->do_capture && strstr(buf_list->name, "ISP")) { width = shrink_to_block(width, 32); height = shrink_to_block(height, 32); - E_LOG_VERBOSE(buf_list, "Adapting size to 32x32 block: %dx%d vs %dx%d", orig_width, orig_height, width, height); + LOG_VERBOSE(buf_list, "Adapting size to 32x32 block: %dx%d vs %dx%d", orig_width, orig_height, width, height); } if (format == V4L2_PIX_FMT_H264) { bytesperline = 0; } - E_LOG_DEBUG(buf_list, "Get current format ..."); - E_XIOCTL(buf_list, buf_list->dev->v4l2->dev_fd, VIDIOC_G_FMT, &fmt, "Can't set format"); + LOG_DEBUG(buf_list, "Get current format ..."); + ERR_IOCTL(buf_list, buf_list->dev->v4l2->dev_fd, VIDIOC_G_FMT, &fmt, "Can't set format"); if (buf_list->v4l2->do_mplanes) { fmt.fmt.pix_mp.colorspace = V4L2_COLORSPACE_JPEG; @@ -87,8 +87,8 @@ int v4l2_buffer_list_open(buffer_list_t *buf_list, unsigned width, unsigned heig //fmt.fmt.pix.sizeimage = bytesperline * orig_height; } - E_LOG_DEBUG(buf_list, "Configuring format (%s)...", fourcc_to_string(format).buf); - E_XIOCTL(buf_list, buf_list->dev->v4l2->dev_fd, VIDIOC_S_FMT, &fmt, "Can't set format"); + LOG_DEBUG(buf_list, "Configuring format (%s)...", fourcc_to_string(format).buf); + ERR_IOCTL(buf_list, buf_list->dev->v4l2->dev_fd, VIDIOC_S_FMT, &fmt, "Can't set format"); if (buf_list->v4l2->do_mplanes) { buf_list->fmt_width = fmt.fmt.pix_mp.width; @@ -103,22 +103,22 @@ int v4l2_buffer_list_open(buffer_list_t *buf_list, unsigned width, unsigned heig } if (bytesperline > 0 && buf_list->fmt_bytesperline != bytesperline) { - E_LOG_ERROR(buf_list, "Requested bytesperline=%u. Got %u.", + LOG_ERROR(buf_list, "Requested bytesperline=%u. Got %u.", bytesperline, buf_list->fmt_bytesperline); } if (buf_list->fmt_width != width || buf_list->fmt_height != height) { if (bytesperline) { - E_LOG_ERROR(buf_list, "Requested resolution=%ux%u is unavailable. Got %ux%u.", + LOG_ERROR(buf_list, "Requested resolution=%ux%u is unavailable. Got %ux%u.", width, height, buf_list->fmt_width, buf_list->fmt_height); } else { - E_LOG_INFO(buf_list, "Requested resolution=%ux%u is unavailable. Got %ux%u. Accepted", + LOG_INFO(buf_list, "Requested resolution=%ux%u is unavailable. Got %ux%u. Accepted", width, height, buf_list->fmt_width, buf_list->fmt_height); } } if (format && buf_list->fmt_format != format) { - E_LOG_ERROR(buf_list, "Could not obtain the requested format=%s; driver gave us %s", + LOG_ERROR(buf_list, "Could not obtain the requested format=%s; driver gave us %s", fourcc_to_string(format).buf, fourcc_to_string(buf_list->fmt_format).buf); } @@ -133,14 +133,14 @@ int v4l2_buffer_list_open(buffer_list_t *buf_list, unsigned width, unsigned heig v4l2_req.type = buf_list->v4l2->type; v4l2_req.memory = buf_list->do_mmap ? V4L2_MEMORY_MMAP : V4L2_MEMORY_DMABUF; - E_LOG_DEBUG(buf_list, "Requesting %u buffers", v4l2_req.count); + LOG_DEBUG(buf_list, "Requesting %u buffers", v4l2_req.count); - E_XIOCTL(buf_list, buf_list->dev->v4l2->dev_fd, VIDIOC_REQBUFS, &v4l2_req, "Can't request buffers"); + ERR_IOCTL(buf_list, buf_list->dev->v4l2->dev_fd, VIDIOC_REQBUFS, &v4l2_req, "Can't request buffers"); if (v4l2_req.count < 1) { - E_LOG_ERROR(buf_list, "Insufficient buffer memory: %u", v4l2_req.count); + LOG_ERROR(buf_list, "Insufficient buffer memory: %u", v4l2_req.count); } - E_LOG_DEBUG(buf_list, "Got %u buffers", v4l2_req.count); + LOG_DEBUG(buf_list, "Got %u buffers", v4l2_req.count); return v4l2_req.count; error: @@ -150,7 +150,7 @@ error: int v4l2_buffer_list_set_stream(buffer_list_t *buf_list, bool do_on) { enum v4l2_buf_type type = buf_list->v4l2->type; - E_XIOCTL(buf_list, buf_list->dev->v4l2->dev_fd, do_on ? VIDIOC_STREAMON : VIDIOC_STREAMOFF, &type, "Cannot set streaming state"); + ERR_IOCTL(buf_list, buf_list->dev->v4l2->dev_fd, do_on ? VIDIOC_STREAMON : VIDIOC_STREAMOFF, &type, "Cannot set streaming state"); return 0; error: diff --git a/device/v4l2/debug.c b/device/v4l2/debug.c index e54b58f..c040d02 100644 --- a/device/v4l2/debug.c +++ b/device/v4l2/debug.c @@ -28,8 +28,8 @@ int v4l2_buffer_list_refresh_states(buffer_list_t *buf_list) for (int i = 0; i < buf_list->nbufs; i++) { v4l2_buf.index = i; - E_XIOCTL(buf_list, buf_list->dev->v4l2->dev_fd, VIDIOC_QUERYBUF, &v4l2_buf, "Can't query buffer (flags=%08x)", i); - E_LOG_INFO(buf_list, "Buffer: %d, Flags: %08x. Offset: %d", i, v4l2_buf.flags, + ERR_IOCTL(buf_list, buf_list->dev->v4l2->dev_fd, VIDIOC_QUERYBUF, &v4l2_buf, "Can't query buffer (flags=%08x)", i); + LOG_INFO(buf_list, "Buffer: %d, Flags: %08x. Offset: %d", i, v4l2_buf.flags, buf_list->v4l2->do_mplanes ? v4l2_plane.m.mem_offset : v4l2_buf.m.offset); } diff --git a/device/v4l2/device.c b/device/v4l2/device.c index c0ebf8a..5f282ae 100644 --- a/device/v4l2/device.c +++ b/device/v4l2/device.c @@ -10,18 +10,18 @@ int v4l2_device_open(device_t *dev) dev->v4l2->dev_fd = open(dev->path, O_RDWR|O_NONBLOCK); if (dev->v4l2->dev_fd < 0) { - E_LOG_ERROR(dev, "Can't open device: %s", dev->path); + LOG_ERROR(dev, "Can't open device: %s", dev->path); goto error; } - E_LOG_INFO(dev, "Device path=%s fd=%d opened", dev->path, dev->v4l2->dev_fd); + LOG_INFO(dev, "Device path=%s fd=%d opened", dev->path, dev->v4l2->dev_fd); - E_LOG_DEBUG(dev, "Querying device capabilities ..."); + LOG_DEBUG(dev, "Querying device capabilities ..."); struct v4l2_capability v4l2_cap; - E_XIOCTL(dev, dev->v4l2->dev_fd, VIDIOC_QUERYCAP, &v4l2_cap, "Can't query device capabilities"); + ERR_IOCTL(dev, dev->v4l2->dev_fd, VIDIOC_QUERYCAP, &v4l2_cap, "Can't query device capabilities"); if (!(v4l2_cap.capabilities & V4L2_CAP_STREAMING)) { - E_LOG_ERROR(dev, "Device doesn't support streaming IO"); + LOG_ERROR(dev, "Device doesn't support streaming IO"); } strcpy(dev->bus_info, v4l2_cap.bus_info); @@ -55,8 +55,8 @@ int v4l2_device_set_decoder_start(device_t *dev, bool do_on) cmd.cmd = do_on ? V4L2_DEC_CMD_START : V4L2_DEC_CMD_STOP; - E_LOG_DEBUG(dev, "Setting decoder state %s...", do_on ? "Start" : "Stop"); - E_XIOCTL(dev, dev->v4l2->dev_fd, VIDIOC_DECODER_CMD, &cmd, "Cannot set decoder state"); + LOG_DEBUG(dev, "Setting decoder state %s...", do_on ? "Start" : "Stop"); + ERR_IOCTL(dev, dev->v4l2->dev_fd, VIDIOC_DECODER_CMD, &cmd, "Cannot set decoder state"); return 0; @@ -69,8 +69,8 @@ int v4l2_device_video_force_key(device_t *dev) struct v4l2_control ctl = {0}; ctl.id = V4L2_CID_MPEG_VIDEO_FORCE_KEY_FRAME; ctl.value = 1; - E_LOG_DEBUG(dev, "Forcing keyframe ..."); - E_XIOCTL(dev, dev->v4l2->dev_fd, VIDIOC_S_CTRL, &ctl, "Can't force keyframe"); + LOG_DEBUG(dev, "Forcing keyframe ..."); + ERR_IOCTL(dev, dev->v4l2->dev_fd, VIDIOC_S_CTRL, &ctl, "Can't force keyframe"); return 0; error: @@ -88,8 +88,8 @@ int v4l2_device_set_fps(device_t *dev, int desired_fps) setfps.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; setfps.parm.output.timeperframe.numerator = 1; setfps.parm.output.timeperframe.denominator = desired_fps; - E_LOG_DEBUG(dev, "Configuring FPS ..."); - E_XIOCTL(dev, dev->v4l2->dev_fd, VIDIOC_S_PARM, &setfps, "Can't set FPS"); + LOG_DEBUG(dev, "Configuring FPS ..."); + ERR_IOCTL(dev, dev->v4l2->dev_fd, VIDIOC_S_PARM, &setfps, "Can't set FPS"); return 0; error: return -1; diff --git a/device/v4l2/device_media.c b/device/v4l2/device_media.c index ae585ba..90680f9 100644 --- a/device/v4l2/device_media.c +++ b/device/v4l2/device_media.c @@ -14,11 +14,11 @@ int v4l2_device_open_media_device(device_t *dev) { struct stat st; if (fstat(dev->v4l2->dev_fd, &st) < 0) { - E_LOG_ERROR(dev, "Cannot get fstat"); + LOG_ERROR(dev, "Cannot get fstat"); return -1; } if (~st.st_mode & S_IFCHR) { - E_LOG_ERROR(dev, "FD is not char"); + LOG_ERROR(dev, "FD is not char"); return -1; } @@ -28,7 +28,7 @@ int v4l2_device_open_media_device(device_t *dev) struct dirent **namelist; int n = scandir(path, &namelist, NULL, NULL); if (n < 0) { - E_LOG_ERROR(dev, "Cannot scan: %s", path); + LOG_ERROR(dev, "Cannot scan: %s", path); return -1; } @@ -39,7 +39,7 @@ int v4l2_device_open_media_device(device_t *dev) sprintf(path, "/dev/%s", namelist[n]->d_name); ret = open(path, O_RDWR); if (ret >= 0) { - E_LOG_VERBOSE(dev, "Opened '%s' (fd=%d)", path, ret); + LOG_VERBOSE(dev, "Opened '%s' (fd=%d)", path, ret); } } @@ -59,7 +59,7 @@ int v4l2_device_open_v4l2_subdev(device_t *dev, int subdev) media_fd = v4l2_device_open_media_device(dev); if (media_fd < 0) { - E_LOG_ERROR(dev, "Cannot find media controller"); + LOG_ERROR(dev, "Cannot find media controller"); } for (;;) { @@ -82,26 +82,26 @@ int v4l2_device_open_v4l2_subdev(device_t *dev, int subdev) char link[256]; if ((rc = readlink(path, link, sizeof(link)-1)) < 0) { - E_LOG_ERROR(dev, "Cannot readlink '%s'", path); + LOG_ERROR(dev, "Cannot readlink '%s'", path); } link[rc] = 0; char *last = strrchr(link, '/'); if (!last) { - E_LOG_ERROR(dev, "Link '%s' for '%s' does not end with '/'", link, path); + LOG_ERROR(dev, "Link '%s' for '%s' does not end with '/'", link, path); } if (strstr(last, "/v4l-subdev") != last) { - E_LOG_ERROR(dev, "Link '%s' does not contain '/v4l-subdev'", link, path); + LOG_ERROR(dev, "Link '%s' does not contain '/v4l-subdev'", link, path); } sprintf(path, "/dev%s", last); ret = open(path, O_RDWR); if (ret < 0) { - E_LOG_ERROR(dev, "Cannot open '%s' (ret=%d)", path, ret); + LOG_ERROR(dev, "Cannot open '%s' (ret=%d)", path, ret); } - E_LOG_INFO(dev, "Opened '%s' (fd=%d)", path, ret); + LOG_INFO(dev, "Opened '%s' (fd=%d)", path, ret); break; } @@ -126,8 +126,8 @@ int v4l2_device_set_pad_format(device_t *dev, unsigned width, unsigned height, u fmt.format.colorspace = V4L2_COLORSPACE_RAW; fmt.format.field = V4L2_FIELD_ANY; - E_LOG_DEBUG(dev, "Configuring mpad %d (subdev_fd=%d)...", fmt.pad, dev->v4l2->subdev_fd); - E_XIOCTL(dev, dev->v4l2->subdev_fd, VIDIOC_SUBDEV_S_FMT, &fmt, "Can't configure mpad %d (subdev_fd=%d)", fmt.pad, dev->v4l2->subdev_fd); + LOG_DEBUG(dev, "Configuring mpad %d (subdev_fd=%d)...", fmt.pad, dev->v4l2->subdev_fd); + ERR_IOCTL(dev, dev->v4l2->subdev_fd, VIDIOC_SUBDEV_S_FMT, &fmt, "Can't configure mpad %d (subdev_fd=%d)", fmt.pad, dev->v4l2->subdev_fd); return 0; error: diff --git a/device/v4l2/device_options.c b/device/v4l2/device_options.c index 0c2c07b..c1636d4 100644 --- a/device/v4l2/device_options.c +++ b/device/v4l2/device_options.c @@ -13,8 +13,8 @@ int v4l2_device_set_option_by_id(device_t *dev, const char *name, uint32_t id, i ctl.id = id; ctl.value = value; - E_LOG_DEBUG(dev, "Configuring option %s (%08x) = %d", name, id, value); - E_XIOCTL(dev, dev->v4l2->subdev_fd >= 0 ? dev->v4l2->subdev_fd : dev->v4l2->dev_fd, VIDIOC_S_CTRL, &ctl, "Can't set option %s", name); + LOG_DEBUG(dev, "Configuring option %s (%08x) = %d", name, id, value); + ERR_IOCTL(dev, dev->v4l2->subdev_fd >= 0 ? dev->v4l2->subdev_fd : dev->v4l2->dev_fd, VIDIOC_S_CTRL, &ctl, "Can't set option %s", name); return 0; error: return -1; @@ -33,14 +33,14 @@ static int v4l2_device_query_control_iter_id(device_t *dev, int fd, uint32_t *id device_option_normalize_name(qctrl.name, qctrl.name); if (qctrl.flags & V4L2_CTRL_FLAG_DISABLED) { - E_LOG_VERBOSE(dev, "The '%s' is disabled", qctrl.name); + LOG_VERBOSE(dev, "The '%s' is disabled", qctrl.name); return 0; } else if (qctrl.flags & V4L2_CTRL_FLAG_READ_ONLY) { - E_LOG_VERBOSE(dev, "The '%s' is read-only", qctrl.name); + LOG_VERBOSE(dev, "The '%s' is read-only", qctrl.name); return 0; } - E_LOG_VERBOSE(dev, "Available control: %s (%08x, type=%d)", + LOG_VERBOSE(dev, "Available control: %s (%08x, type=%d)", qctrl.name, qctrl.id, qctrl.type); dev->v4l2->controls = reallocarray(dev->v4l2->controls, dev->v4l2->ncontrols+1, sizeof(device_v4l2_control_t)); @@ -83,7 +83,7 @@ int v4l2_device_set_option(device_t *dev, const char *key, const char *value) if (!control) { ret = 0; - E_LOG_ERROR(dev, "The '%s=%s' was failed to find.", key, value); + LOG_ERROR(dev, "The '%s=%s' was failed to find.", key, value); } switch(control->control.type) { @@ -95,8 +95,8 @@ int v4l2_device_set_option(device_t *dev, const char *key, const char *value) .id = control->control.id, .value = atoi(value) }; - E_LOG_INFO(dev, "Configuring option %s (%08x) = %d", control->control.name, ctl.id, ctl.value); - E_XIOCTL(dev, control->fd, VIDIOC_S_CTRL, &ctl, "Can't set option %s", control->control.name); + LOG_INFO(dev, "Configuring option %s (%08x) = %d", control->control.name, ctl.id, ctl.value); + ERR_IOCTL(dev, control->fd, VIDIOC_S_CTRL, &ctl, "Can't set option %s", control->control.name); ret = 1; } break; @@ -139,15 +139,15 @@ int v4l2_device_set_option(device_t *dev, const char *key, const char *value) } } - E_LOG_INFO(dev, "Configuring option %s (%08x) = [%d tokens, expected %d]", + LOG_INFO(dev, "Configuring option %s (%08x) = [%d tokens, expected %d]", control->control.name, ctl.id, tokens, control->control.elems); - E_XIOCTL(dev, control->fd, VIDIOC_S_EXT_CTRLS, &ctrls, "Can't set option %s", control->control.name); + ERR_IOCTL(dev, control->fd, VIDIOC_S_EXT_CTRLS, &ctrls, "Can't set option %s", control->control.name); ret = 1; } break; default: - E_LOG_ERROR(dev, "The '%s' control type '%d' is not supported", control->control.name, control->control.type); + LOG_ERROR(dev, "The '%s' control type '%d' is not supported", control->control.name, control->control.type); } error: diff --git a/ffmpeg/remuxer.c b/ffmpeg/remuxer.c index 74aa5d2..e718267 100644 --- a/ffmpeg/remuxer.c +++ b/ffmpeg/remuxer.c @@ -129,10 +129,10 @@ int ffmpeg_remuxer_feed(ffmpeg_remuxer_t *remuxer) ret = av_read_frame(remuxer->input_context, remuxer->packet); if (ret == AVERROR_EOF) { ret = 0; - E_LOG_DEBUG(remuxer, "av_read_frame: EOF", ret); + LOG_DEBUG(remuxer, "av_read_frame: EOF", ret); break; } else if (ret < 0) { - E_LOG_DEBUG(remuxer, "av_read_frame: %08x, pts: %d", ret, remuxer->packet->pts); + LOG_DEBUG(remuxer, "av_read_frame: %08x, pts: %d", ret, remuxer->packet->pts); break; } @@ -159,9 +159,9 @@ int ffmpeg_remuxer_feed(ffmpeg_remuxer_t *remuxer) av_packet_unref(remuxer->packet); if (ret == AVERROR_EOF) { - E_LOG_DEBUG(remuxer, "av_interleaved_write_frame: EOF, pts: %d, since_start: %d", ret, pts, since_start); + LOG_DEBUG(remuxer, "av_interleaved_write_frame: EOF, pts: %d, since_start: %d", ret, pts, since_start); } else { - E_LOG_DEBUG(remuxer, "av_interleaved_write_frame: %08x, pts: %d, since_start: %d", ret, pts, since_start); + LOG_DEBUG(remuxer, "av_interleaved_write_frame: %08x, pts: %d, since_start: %d", ret, pts, since_start); } } diff --git a/http/http.c b/http/http.c index 05e504a..c399f2f 100644 --- a/http/http.c +++ b/http/http.c @@ -95,7 +95,7 @@ static void http_process(http_worker_t *worker, FILE *stream) static void http_client(http_worker_t *worker) { worker->client_host = inet_ntoa(worker->client_addr.sin_addr); - E_LOG_INFO(worker, "Client connected %s.", worker->client_host); + LOG_INFO(worker, "Client connected %s.", worker->client_host); struct timeval tv; tv.tv_sec = 3; @@ -116,7 +116,7 @@ static void http_client(http_worker_t *worker) close(worker->client_fd); worker->client_fd = -1; - E_LOG_INFO(worker, "Client disconnected %s.", worker->client_host); + LOG_INFO(worker, "Client disconnected %s.", worker->client_host); worker->client_host = NULL; } diff --git a/http/http_ffmpeg.c b/http/http_ffmpeg.c index d930062..c9facd0 100644 --- a/http/http_ffmpeg.c +++ b/http/http_ffmpeg.c @@ -44,7 +44,7 @@ static int http_ffmpeg_read_from_buf(void *opaque, uint8_t *buf, int buf_size) if (!buf_size) return FFMPEG_DATA_PACKET_EOF; - E_LOG_DEBUG(status, "http_ffmpeg_read_from_buf: offset=%d, n=%d", status->buf_offset, buf_size); + LOG_DEBUG(status, "http_ffmpeg_read_from_buf: offset=%d, n=%d", status->buf_offset, buf_size); memcpy(buf, (char*)status->buf->start + status->buf_offset, buf_size); status->buf_offset += buf_size; return buf_size; @@ -64,7 +64,7 @@ static int http_ffmpeg_write_to_stream(void *opaque, uint8_t *buf, int buf_size) size_t n = fwrite(buf, 1, buf_size, status->stream); fflush(status->stream); - E_LOG_DEBUG(status, "http_ffmpeg_write_to_stream: offset=%d, n=%d, buf_size=%d, error=%d", + LOG_DEBUG(status, "http_ffmpeg_write_to_stream: offset=%d, n=%d, buf_size=%d, error=%d", status->stream_offset, n, buf_size, ferror(status->stream)); status->stream_offset += n; if (ferror(status->stream)) diff --git a/http/http_h264.c b/http/http_h264.c index d01be0a..f1f8668 100644 --- a/http/http_h264.c +++ b/http/http_h264.c @@ -53,10 +53,10 @@ bool h264_is_key_frame(buffer_t *buf) unsigned char *data = buf->start; if (buf->flags.is_keyframe) { - E_LOG_DEBUG(buf, "Got key frame (from V4L2)!"); + LOG_DEBUG(buf, "Got key frame (from V4L2)!"); return true; } else if (buf->used >= 5 && (data[4] & 0x1F) == 0x07) { - E_LOG_DEBUG(buf, "Got key frame (from buffer)!"); + LOG_DEBUG(buf, "Got key frame (from buffer)!"); return true; } diff --git a/opts/log.c b/opts/log.c index 5b442e2..d9c8c92 100644 --- a/opts/log.c +++ b/opts/log.c @@ -84,26 +84,21 @@ uint64_t get_monotonic_time_us(struct timespec *ts, struct timeval *tv) return get_time_us(CLOCK_MONOTONIC, ts, tv, 0); } -int xioctl(const char *name, int fd, int request, void *arg) +int ioctl_retried(const char *name, int fd, int request, void *arg) { - int retries = XIOCTL_RETRIES; - int retval = -1; +#define MAX_RETRIES 4 - do { - retval = ioctl(fd, request, arg); - } while ( - retval - && retries-- - && ( - errno == EINTR - || errno == EAGAIN - || errno == ETIMEDOUT - ) - ); + int retries = 4; + int ret = -1; - // cppcheck-suppress knownConditionTrueFalse - if (retval && retries <= 0) { - E_LOG_PERROR(NULL, "%s: ioctl(%08x) retried %u times; giving up", name, request, XIOCTL_RETRIES); + while (retries-- > 0) { + ret = ioctl(fd, request, arg); + if (errno != EINTR && errno != EAGAIN && errno != ETIMEDOUT) + break; } - return retval; + + if (ret && retries <= 0) { + LOG_PERROR(NULL, "%s: ioctl(%08x) retried %u times; giving up", name, request, MAX_RETRIES); + } + return ret; } diff --git a/opts/log.h b/opts/log.h index 575b620..2e91472 100644 --- a/opts/log.h +++ b/opts/log.h @@ -38,11 +38,11 @@ bool filter_log(const char *filename); // assumes that name is first item #define dev_name(dev) (dev ? *(const char**)dev : "?") -#define E_LOG_ERROR(dev, _msg, ...) do { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); goto error; } while(0) -#define E_LOG_PERROR(dev, _msg, ...) do { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); exit(-1); } while(0) -#define E_LOG_INFO(dev, _msg, ...) do { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); } while(0) -#define E_LOG_VERBOSE(dev, _msg, ...) do { if (log_options.debug || log_options.verbose || filter_log(__FILENAME__)) { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); } } while(0) -#define E_LOG_DEBUG(dev, _msg, ...) do { if (log_options.debug || filter_log(__FILENAME__)) { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); } } while(0) +#define LOG_ERROR(dev, _msg, ...) do { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); goto error; } while(0) +#define LOG_PERROR(dev, _msg, ...) do { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); exit(-1); } while(0) +#define LOG_INFO(dev, _msg, ...) do { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); } while(0) +#define LOG_VERBOSE(dev, _msg, ...) do { if (log_options.debug || log_options.verbose || filter_log(__FILENAME__)) { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); } } while(0) +#define LOG_DEBUG(dev, _msg, ...) do { if (log_options.debug || filter_log(__FILENAME__)) { fprintf(stderr, "%s: %s: " _msg "\n", __FILENAME__, dev_name(dev), ##__VA_ARGS__); } } while(0) #define CLOCK_FROM_PARAMS -1 @@ -50,16 +50,11 @@ uint64_t get_monotonic_time_us(struct timespec *ts, struct timeval *tv); uint64_t get_time_us(clockid_t clock, struct timespec *ts, struct timeval *tv, int64_t delays_us); int shrink_to_block(int size, int block); -#ifndef CFG_XIOCTL_RETRIES -# define CFG_XIOCTL_RETRIES 4 -#endif -#define XIOCTL_RETRIES ((unsigned)(CFG_XIOCTL_RETRIES)) +int ioctl_retried(const char *name, int fd, int request, void *arg); -int xioctl(const char *name, int fd, int request, void *arg); - -#define E_XIOCTL(dev, _fd, _request, _value, _msg, ...) do { \ +#define ERR_IOCTL(dev, _fd, _request, _value, _msg, ...) do { \ int ret; \ - if ((ret = xioctl(dev_name(dev), _fd, _request, _value)) < 0) { \ - E_LOG_ERROR(dev, "xioctl(ret=%d): " _msg, ret, ##__VA_ARGS__); \ + if ((ret = ioctl_retried(dev_name(dev), _fd, _request, _value)) < 0) { \ + LOG_ERROR(dev, "ioctl(ret=%d): " _msg, ret, ##__VA_ARGS__); \ } \ } while(0) diff --git a/opts/opts.c b/opts/opts.c index 523dbea..337afcc 100644 --- a/opts/opts.c +++ b/opts/opts.c @@ -70,7 +70,7 @@ static int parse_opt(option_t *options, const char *key) } } - E_LOG_DEBUG(NULL, "Parsing '%s'. Got value='%s', and option='%s'", key, value, option ? option->name : NULL); + LOG_DEBUG(NULL, "Parsing '%s'. Got value='%s', and option='%s'", key, value, option ? option->name : NULL); if (!option || !value) { return -EINVAL; @@ -115,7 +115,7 @@ int parse_opts(option_t *options, int argc, char *argv[]) if (key[0] == '-') key++; } else { - E_LOG_ERROR(NULL, "The '%s' is not option (should start with - or --).", key); + LOG_ERROR(NULL, "The '%s' is not option (should start with - or --).", key); } if (!strcmp(key, "help")) { @@ -125,7 +125,7 @@ int parse_opts(option_t *options, int argc, char *argv[]) int ret = parse_opt(options, key); if (ret <= 0) { - E_LOG_ERROR(NULL, "Parsing '%s' returned '%d'.", argv[arg], ret); + LOG_ERROR(NULL, "Parsing '%s' returned '%d'.", argv[arg], ret); } }