Skip to content

Commit 5e2d739

Browse files
committed
cmpto_j2k: silence logging in video_frame_pool
the exception is caught so it doesn't need to be print twice
1 parent 4fb2f8e commit 5e2d739

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

src/utils/video_frame_pool.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
#include <stdexcept>
5252
#include <utility>
5353

54-
#include "debug.h" // for MSG
54+
#include "debug.h" // for log_msg
5555
#include "video_codec.h"
5656
#include "video_frame.h"
5757

@@ -73,6 +73,7 @@ struct video_frame_pool::impl {
7373
void deallocate_frame(struct video_frame *frame);
7474

7575
std::unique_ptr<video_frame_pool_allocator> m_allocator = std::unique_ptr<video_frame_pool_allocator>(new default_data_allocator);
76+
bool m_quiet;
7677
std::queue<struct video_frame *> m_free_frames;
7778
std::mutex m_lock;
7879
std::condition_variable m_frame_returned;
@@ -144,7 +145,8 @@ struct video_frame_pool_allocator *default_data_allocator::clone() const {
144145
// \/ | (_| (- (_) __ | | (_| ||| (- __ |_) (_) (_) | . . | ||| |_) |
145146
// | |
146147
video_frame_pool::impl::impl(const video_frame_pool_params &params)
147-
: m_allocator(params.alloc.clone()), m_max_used_frames(params.max_used_frames)
148+
: m_allocator(params.alloc.clone()), m_quiet(params.quiet),
149+
m_max_used_frames(params.max_used_frames)
148150
{
149151
}
150152

@@ -188,7 +190,8 @@ std::shared_ptr<video_frame> video_frame_pool::impl::get_frame() {
188190
ret->tiles[i].data_len = m_max_data_len;
189191
}
190192
} catch (std::exception &e) {
191-
MSG(ERROR, "%s\n", e.what());
193+
log_msg(m_quiet ? LOG_LEVEL_DEBUG : LOG_LEVEL_ERROR,
194+
MOD_NAME "%s\n", e.what());
192195
deallocate_frame(ret);
193196
throw;
194197
}

src/utils/video_frame_pool.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ struct default_data_allocator : public video_frame_pool_allocator {
6262
struct video_frame_pool_params {
6363
unsigned int max_used_frames = 0;
6464
video_frame_pool_allocator const &alloc = default_data_allocator();
65+
bool quiet =
66+
false; ///< if exception thrown, do not print e.what() - the caller
67+
///< is catching the error and will handle the message
6568
};
6669

6770
struct video_frame_pool {

src/video_compress/cmpto_j2k.cpp

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,9 @@ static struct {
368368
static void
369369
set_cpu_pool(struct state_video_compress_j2k *s, bool /*have_cuda_preprocess*/)
370370
{
371-
s->pool = video_frame_pool(s->max_in_frames, default_data_allocator());
371+
s->pool = video_frame_pool({ .max_used_frames = s->max_in_frames,
372+
.alloc = default_data_allocator(),
373+
.quiet = true });
372374
}
373375
#define CPU_CONV_PARAM "j2k-enc-cpu-conv"
374376
ADD_TO_PARAM(
@@ -385,19 +387,23 @@ set_cuda_pool(struct state_video_compress_j2k *s, bool have_cuda_preprocess)
385387
"conversion...\n");
386388
} else if (s->precompress_codec == VC_NONE || have_cuda_preprocess) {
387389
s->pool_in_cuda_memory = true;
388-
s->pool = video_frame_pool(
389-
s->max_in_frames,
390-
cmpto_j2k_enc_cuda_buffer_data_allocator<
391-
cuda_wrapper_malloc, cuda_wrapper_free>());
390+
s->pool = video_frame_pool(
391+
{ .max_used_frames = s->max_in_frames,
392+
.alloc = cmpto_j2k_enc_cuda_buffer_data_allocator<
393+
cuda_wrapper_malloc, cuda_wrapper_free>(),
394+
.quiet = true });
392395
return;
393396
}
394397
s->pool = video_frame_pool(
395-
s->max_in_frames,
396-
cmpto_j2k_enc_cuda_buffer_data_allocator<cuda_wrapper_malloc_host,
397-
cuda_wrapper_free_host>());
398+
{ .max_used_frames = s->max_in_frames,
399+
.alloc = cmpto_j2k_enc_cuda_buffer_data_allocator<
400+
cuda_wrapper_malloc_host, cuda_wrapper_free_host>(),
401+
.quiet = true });
398402
#else
399403
assert(!have_cuda_preprocess); // if CUDA not found, we shouldn't have
400-
s->pool = video_frame_pool(s->max_in_frames, default_data_allocator());
404+
s->pool = video_frame_pool({ .max_used_frames = s->max_in_frames,
405+
.alloc = default_data_allocator(),
406+
.quiet = true });
401407
#endif
402408
}
403409

0 commit comments

Comments
 (0)