Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Libav Instrumentations
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.
*
/**
* Instrumentation for Libav AVIO - used to debug the new ASF decoder
*/
#define avio_seek(s, o, w) ({ \
int64_t _ret = avio_seek(s, o, w); \
int64_t _pos = avio_tell(s); \
av_log(NULL, AV_LOG_VERBOSE|AV_LOG_C(154), "0x%08"PRIx64" - %s:%d seek %p %"PRId64" %d -> %"PRId64"\n", \
_pos, __FUNCTION__, __LINE__, s, o, w, _ret); \
_ret; \
})
#define avio_skip(s, o) ({ \
int64_t _ret = avio_skip(s, o); \
int64_t _pos = avio_tell(s); \
av_log(NULL, AV_LOG_VERBOSE|AV_LOG_C(134), "0x%08"PRIx64" - %s:%d skip %p %d -> %"PRId64"\n", \
_pos, __FUNCTION__, __LINE__, s, (int)o, _ret); \
_ret; \
})
#define avio_r8(s) ({ \
int _ret = avio_r8(s); \
int64_t _pos = avio_tell(s); \
av_log(NULL, AV_LOG_VERBOSE|AV_LOG_C(124), "0x%08"PRIx64" - %s:%d avio_r8 %p -> %d\n", \
_pos, __FUNCTION__, __LINE__, s, _ret); \
_ret; \
})
#define avio_rl16(s) ({ \
unsigned int _ret = avio_rl16(s); \
int64_t _pos = avio_tell(s); \
av_log(NULL, AV_LOG_VERBOSE, "0x%08"PRIx64" - %s:%d avio_rl16 %p -> %d\n", \
_pos, __FUNCTION__, __LINE__, s, _ret); \
_ret; \
})
#define avio_rl24(s) ({ \
unsigned int _ret = avio_rl24(s); \
int64_t _pos = avio_tell(s); \
av_log(s, AV_LOG_VERBOSE, "0x%08"PRIx64" - %s:%d avio_rl24 %p -> %d\n", \
_pos, __FUNCTION__, __LINE__, s, _ret); \
_ret; \
})
#define avio_rl32(s) ({ \
unsigned int _ret = avio_rl32(s); \
int64_t _pos = avio_tell(s); \
av_log(NULL, AV_LOG_VERBOSE, "0x%08"PRIx64" - %s:%d avio_rl32 %p -> %d\n", \
_pos, __FUNCTION__, __LINE__, s, _ret); \
_ret; \
})
#define avio_rl64(s) ({ \
uint64_t _ret = avio_rl64(s); \
int64_t _pos = avio_tell(s); \
av_log(NULL, AV_LOG_VERBOSE, "0x%08"PRIx64" - %s:%d avio_rl64 %p -> %"PRId64"\n", \
_pos, __FUNCTION__, __LINE__, s, _ret); \
_ret; \
})
#define avio_rb16(s) ({ \
unsigned int _ret = avio_rb16(s); \
int64_t _pos = avio_tell(s); \
av_log(NULL, AV_LOG_VERBOSE, "0x%08"PRIx64" - %s:%d avio_rb16 %p -> %d\n", \
_pos, __FUNCTION__, __LINE__, s, _ret); \
_ret; \
})
#define avio_rb24(s) ({ \
unsigned int _ret = avio_rb24(s); \
int64_t _pos = avio_tell(s); \
av_log(s, AV_LOG_VERBOSE, "0x%08"PRIx64" - %s:%d avio_rb24 %p -> %d\n", \
_pos, __FUNCTION__, __LINE__, s, _ret); \
_ret; \
})
#define avio_rb32(s) ({ \
unsigned int _ret = avio_rb32(s); \
int64_t _pos = avio_tell(s); \
av_log(NULL, AV_LOG_VERBOSE, "0x%08"PRIx64" - %s:%d avio_rb32 %p -> %d\n", \
_pos, __FUNCTION__, __LINE__, s, _ret); \
_ret; \
})
#define avio_rb64(s) ({ \
uint64_t _ret = avio_rb64(s); \
int64_t _pos = avio_tell(s); \
av_log(NULL, AV_LOG_VERBOSE, "0x%08"PRIx64" - %s:%d avio_rb64 %p -> %"PRId64"\n", \
_pos, __FUNCTION__, __LINE__, s, _ret); \
_ret; \
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.