]> git.sesse.net Git - bmusb/commitdiff
Be less verbose on overflow.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 12 Oct 2015 20:10:42 +0000 (22:10 +0200)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Mon, 12 Oct 2015 20:10:42 +0000 (22:10 +0200)
bmusb.cpp
bmusb.h

index 6867805e719e4c6983af99063f343cbb2dd94b1f..ac02852cb2d4af37fd64f5a7d2454cc1d54a9f98 100644 (file)
--- a/bmusb.cpp
+++ b/bmusb.cpp
@@ -93,6 +93,9 @@ FrameAllocator::Frame MallocFrameAllocator::alloc_frame()
 
 void MallocFrameAllocator::release_frame(Frame frame)
 {
+       if (frame.overflow > 0) {
+               printf("%d bytes overflow after last (malloc) frame\n", int(frame.overflow));
+       }
        unique_lock<mutex> lock(freelist_mutex);
        freelist.push(unique_ptr<uint8_t[]>(frame.data));
 }
@@ -263,8 +266,13 @@ void add_to_frame(FrameAllocator::Frame *current_frame, const char *frame_type_n
 
        int bytes = end - start;
        if (current_frame->len + bytes > current_frame->size) {
-               printf("%d bytes overflow after last %s frame\n",
-                       int(current_frame->len + bytes - current_frame->size), frame_type_name);
+               current_frame->overflow = current_frame->len + bytes - current_frame->size;
+               current_frame->len = current_frame->size;
+               if (current_frame->overflow > 1048576) {
+                       printf("%d bytes overflow after last %s frame\n",
+                               int(current_frame->overflow), frame_type_name);
+                       current_frame->overflow = 0;
+               }
                //dump_frame();
        } else {
                if (current_frame->interleaved) {
diff --git a/bmusb.h b/bmusb.h
index 96a2257f8549279dc0000c7b31dfb2df8709e62a..b2725ab76dc5154e04a3b57797ed21c5182231f6 100644 (file)
--- a/bmusb.h
+++ b/bmusb.h
@@ -25,6 +25,7 @@ class FrameAllocator {
                uint8_t *data2 = nullptr;  // Only if interleaved == true.
                size_t len = 0;  // Number of bytes we actually have.
                size_t size = 0;  // Number of bytes we have room for.
+               size_t overflow = 0;
                void *userdata = nullptr;
                FrameAllocator *owner = nullptr;