Skip to content

Instantly share code, notes, and snippets.

@lu-zero
Last active November 26, 2015 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lu-zero/d785cca01f6cd71769ab to your computer and use it in GitHub Desktop.
Save lu-zero/d785cca01f6cd71769ab to your computer and use it in GitHub Desktop.
Libav instrumentation
diff --git a/libavutil/buffer.c b/libavutil/buffer.c
index 1bc4a93..c277e94 100644
--- a/libavutil/buffer.c
+++ b/libavutil/buffer.c
@@ -22,6 +22,7 @@
#include "atomic.h"
#include "buffer_internal.h"
#include "common.h"
+#include "log.h"
#include "mem.h"
#include "thread.h"
@@ -55,6 +56,11 @@ AVBufferRef *av_buffer_create(uint8_t *data, int size,
ref->data = data;
ref->size = size;
+ av_log(NULL, AV_LOG_INFO, "%s/%p %p->%p %d",
+ __PRETTY_FUNCTION__,
+ (intptr_t)pthread_self(),
+ ref, ref->buffer, buf->refcount);
+
return ref;
}
@@ -100,6 +106,11 @@ AVBufferRef *av_buffer_ref(AVBufferRef *buf)
avpriv_atomic_int_add_and_fetch(&buf->buffer->refcount, 1);
+ av_log(NULL, AV_LOG_INFO, "%s/%p %p->%p %d",
+ __PRETTY_FUNCTION__,
+ (intptr_t)pthread_self(),
+ buf, buf->buffer, buf->buffer->refcount);
+
return ret;
}
@@ -109,6 +120,11 @@ void av_buffer_unref(AVBufferRef **buf)
if (!buf || !*buf)
return;
+ av_log(NULL, AV_LOG_INFO, "%s/%p %p->%p %d",
+ __PRETTY_FUNCTION__,
+ (intptr_t)pthread_self(),
+ *buf, (*buf)->buffer, (*buf)->buffer->refcount);
+
b = (*buf)->buffer;
av_freep(buf);
diff --git a/libavutil/frame.c b/libavutil/frame.c
index e4f6ab3..f6ad496 100644
--- a/libavutil/frame.c
+++ b/libavutil/frame.c
@@ -26,6 +26,10 @@
#include "mem.h"
#include "samplefmt.h"
+#undef av_frame_free
+#undef av_frame_ref
+#undef av_frame_unref
+
static void get_frame_defaults(AVFrame *frame)
{
if (frame->extended_data != frame->data)
diff --git a/libavutil/frame.h b/libavutil/frame.h
index c723cb0..2366a24 100644
--- a/libavutil/frame.h
+++ b/libavutil/frame.h
@@ -31,6 +31,7 @@
#include "avutil.h"
#include "buffer.h"
#include "dict.h"
+#include "log.h"
#include "rational.h"
#include "samplefmt.h"
#include "pixfmt.h"
@@ -409,6 +410,43 @@ void av_frame_unref(AVFrame *frame);
*/
void av_frame_move_ref(AVFrame *dst, AVFrame *src);
+#define av_frame_free(frame) \
+ do { \
+ av_log(NULL, AV_LOG_INFO|AV_LOG_C(122), \
+ "%s:%s frame %p buffer %p\n", \
+ __PRETTY_FUNCTION__, \
+ "av_frame_free", \
+ *frame, \
+ *frame ? (*frame)->buf[0] : NULL); \
+ av_frame_free(frame); \
+ } while(0)
+
+#define av_frame_ref(dst, src) \
+ ({ \
+ int _ret; \
+ av_log(NULL, AV_LOG_INFO|AV_LOG_C(122), \
+ "%s:%s dst %p buffer %p src %p buffer %p\n", \
+ __PRETTY_FUNCTION__, \
+ "av_frame_ref", \
+ ((AVFrame *)dst), \
+ ((AVFrame *)dst)->buf[0], \
+ ((AVFrame *)src), \
+ ((AVFrame *)src)->buf[0]); \
+ _ret = av_frame_ref((dst), (src)); \
+ _ret; \
+ })
+
+#define av_frame_unref(frame) \
+ do { \
+ av_log(NULL, AV_LOG_INFO|AV_LOG_C(122), \
+ "%s:%s frame %p buffer %p\n", \
+ __PRETTY_FUNCTION__, \
+ "av_frame_unref", \
+ frame, \
+ frame ? frame->buf[0] : NULL); \
+ av_frame_unref(frame); \
+ } while (0)
+
/**
* Allocate new buffer(s) for audio or video data.
*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment