From a48979d7155934153d0647e18c63c8993b18b026 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reimar=20D=C3=B6ffinger?= Date: Thu, 8 Aug 2013 20:02:46 +0200 Subject: [PATCH] Reduce MAKE_ACCESSORS code duplication via a new header. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Reimar Döffinger --- libavcodec/utils.c | 5 +---- libavformat/utils.c | 5 +---- libavutil/accessors.h | 3 +++ libavutil/frame.c | 4 +--- 4 files changed, 6 insertions(+), 11 deletions(-) create mode 100644 libavutil/accessors.h diff --git a/libavcodec/utils.c b/libavcodec/utils.c index fd08becc75..063105a3f3 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -26,6 +26,7 @@ */ #include "config.h" +#include "libavutil/accessors.h" #include "libavutil/atomic.h" #include "libavutil/attributes.h" #include "libavutil/avassert.h" @@ -1029,10 +1030,6 @@ void avcodec_free_frame(AVFrame **frame) av_freep(frame); } -#define MAKE_ACCESSORS(str, name, type, field) \ - type av_##name##_get_##field(const str *s) { return s->field; } \ - void av_##name##_set_##field(str *s, type v) { s->field = v; } - MAKE_ACCESSORS(AVCodecContext, codec, AVRational, pkt_timebase) MAKE_ACCESSORS(AVCodecContext, codec, const AVCodecDescriptor *, codec_descriptor) MAKE_ACCESSORS(AVCodecContext, codec, int, lowres) diff --git a/libavformat/utils.c b/libavformat/utils.c index 727711b529..e44f7165d3 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -25,6 +25,7 @@ #include "libavcodec/internal.h" #include "libavcodec/raw.h" #include "libavcodec/bytestream.h" +#include "libavutil/accessors.h" #include "libavutil/avassert.h" #include "libavutil/opt.h" #include "libavutil/dict.h" @@ -98,10 +99,6 @@ static int64_t wrap_timestamp(AVStream *st, int64_t timestamp) return timestamp; } -#define MAKE_ACCESSORS(str, name, type, field) \ - type av_##name##_get_##field(const str *s) { return s->field; } \ - void av_##name##_set_##field(str *s, type v) { s->field = v; } - MAKE_ACCESSORS(AVStream, stream, AVRational, r_frame_rate) /* an arbitrarily chosen "sane" max packet size -- 50M */ diff --git a/libavutil/accessors.h b/libavutil/accessors.h new file mode 100644 index 0000000000..471cdff7f6 --- /dev/null +++ b/libavutil/accessors.h @@ -0,0 +1,3 @@ +#define MAKE_ACCESSORS(str, name, type, field) \ + type av_##name##_get_##field(const str *s) { return s->field; } \ + void av_##name##_set_##field(str *s, type v) { s->field = v; } diff --git a/libavutil/frame.c b/libavutil/frame.c index 5021d0774e..df03e258db 100644 --- a/libavutil/frame.c +++ b/libavutil/frame.c @@ -27,9 +27,7 @@ #include "mem.h" #include "samplefmt.h" -#define MAKE_ACCESSORS(str, name, type, field) \ - type av_##name##_get_##field(const str *s) { return s->field; } \ - void av_##name##_set_##field(str *s, type v) { s->field = v; } +#include "accessors.h" MAKE_ACCESSORS(AVFrame, frame, int64_t, best_effort_timestamp) MAKE_ACCESSORS(AVFrame, frame, int64_t, pkt_duration)