[FFmpeg-cvslog] r25278 - in trunk: ffmpeg.c libavutil/Makefile libavutil/assert.h libavutil/avutil.h libavutil/rational.c
michael
subversion
Thu Sep 30 23:57:31 CEST 2010
Author: michael
Date: Thu Sep 30 23:57:31 2010
New Revision: 25278
Log:
av_assert() system.
With this the developer can now choose if he wants an assert always enabled or at which
compile time assert level. This can thus replace the #define NDEBUG hacks
Added:
trunk/libavutil/assert.h
Modified:
trunk/ffmpeg.c
trunk/libavutil/Makefile
trunk/libavutil/avutil.h
trunk/libavutil/rational.c
Modified: trunk/ffmpeg.c
==============================================================================
--- trunk/ffmpeg.c Thu Sep 30 22:40:10 2010 (r25277)
+++ trunk/ffmpeg.c Thu Sep 30 23:57:31 2010 (r25278)
@@ -79,8 +79,7 @@
#include "cmdutils.h"
-#undef NDEBUG
-#include <assert.h>
+#include "libavutil/assert.h"
const char program_name[] = "FFmpeg";
const int program_birth_year = 2000;
@@ -905,7 +904,7 @@ need_realloc:
}
}else if(audio_sync_method>1){
int comp= av_clip(delta, -audio_sync_method, audio_sync_method);
- assert(ost->audio_resample);
+ av_assert0(ost->audio_resample);
if(verbose > 2)
fprintf(stderr, "compensating audio timestamp drift:%f compensation:%d in:%d\n", delta, comp, enc->sample_rate);
// fprintf(stderr, "drift:%f len:%d opts:%"PRId64" ipts:%"PRId64" fifo:%d\n", delta, -1, ost->sync_opts, (int64_t)(get_sync_ipts(ost) * enc->sample_rate), av_fifo_size(ost->fifo)/(ost->st->codec->channels * 2));
@@ -1223,10 +1222,10 @@ static void do_video_out(AVFormatContext
rightBand = ((int64_t)ist->st->codec->width * ost->original_rightBand / ost->original_width) & ~1;
/* sanity check to ensure no bad band sizes sneak in */
- assert(topBand <= INT_MAX && topBand >= 0);
- assert(bottomBand <= INT_MAX && bottomBand >= 0);
- assert(leftBand <= INT_MAX && leftBand >= 0);
- assert(rightBand <= INT_MAX && rightBand >= 0);
+ av_assert0(topBand <= INT_MAX && topBand >= 0);
+ av_assert0(bottomBand <= INT_MAX && bottomBand >= 0);
+ av_assert0(leftBand <= INT_MAX && leftBand >= 0);
+ av_assert0(rightBand <= INT_MAX && rightBand >= 0);
ost->topBand = topBand;
ost->bottomBand = bottomBand;
@@ -1696,7 +1695,7 @@ static int output_packet(AVInputStream *
//ost->sync_ipts = (double)(ist->pts + input_files_ts_offset[ist->file_index] - start_time)/ AV_TIME_BASE;
if (ost->encoding_needed) {
- assert(ist->decoding_needed);
+ av_assert0(ist->decoding_needed);
switch(ost->st->codec->codec_type) {
case AVMEDIA_TYPE_AUDIO:
do_audio_out(os, ost, ist, decoded_data_buf, decoded_data_size);
@@ -3628,7 +3627,7 @@ static void opt_new_stream(const char *o
if (!strcmp(opt, "newvideo" )) new_video_stream (oc);
else if (!strcmp(opt, "newaudio" )) new_audio_stream (oc);
else if (!strcmp(opt, "newsubtitle")) new_subtitle_stream(oc);
- else assert(0);
+ else av_assert0(0);
}
/* arg format is "output-stream-index:streamid-value". */
Modified: trunk/libavutil/Makefile
==============================================================================
--- trunk/libavutil/Makefile Thu Sep 30 22:40:10 2010 (r25277)
+++ trunk/libavutil/Makefile Thu Sep 30 23:57:31 2010 (r25278)
@@ -3,6 +3,7 @@ include $(SUBDIR)../config.mak
NAME = avutil
HEADERS = adler32.h \
+ assert.h \
attributes.h \
avstring.h \
avutil.h \
Added: trunk/libavutil/assert.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libavutil/assert.h Thu Sep 30 23:57:31 2010 (r25278)
@@ -0,0 +1,59 @@
+/*
+ * copyright (c) 2010 Michael Niedermayer <michaelni at gmx.at>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+/**
+ * @file
+ * simple assert() macros that are a bit more flexible than ISO C assert().
+ * @author Michael Niedermayer <michaelni at gmx.at>
+ */
+
+#ifndef AVUTIL_ASSERT_H
+#define AVUTIL_ASSERT_H
+
+#include "avutil.h"
+#include "log.h"
+
+/**
+ * assert() equivalent, that is always enabled.
+ */
+#define av_assert0(cond) do {if(!(cond)) { av_log(NULL, AV_LOG_FATAL, "Assertion %s failed at %s:%d\n", AV_STRINGIFY(cond), __FILE__, __LINE__); abort(); }}while(0)
+
+
+/**
+ * assert() equivalent, that does not lie in speed critical code.
+ * These asserts() thus can be enabled without fearing speedloss.
+ */
+#if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 0
+#define av_assert1(cond) av_assert_always(cond)
+#else
+#define av_assert1(cond) ((void)0)
+#endif
+
+
+/**
+ * assert() equivalent, that does lie in speed critical code.
+ */
+#if defined(ASSERT_LEVEL) && ASSERT_LEVEL > 1
+#define av_assert2(cond) av_assert_always(cond)
+#else
+#define av_assert2(cond) ((void)0)
+#endif
+
+#endif
Modified: trunk/libavutil/avutil.h
==============================================================================
--- trunk/libavutil/avutil.h Thu Sep 30 22:40:10 2010 (r25277)
+++ trunk/libavutil/avutil.h Thu Sep 30 23:57:31 2010 (r25278)
@@ -40,7 +40,7 @@
#define AV_VERSION(a, b, c) AV_VERSION_DOT(a, b, c)
#define LIBAVUTIL_VERSION_MAJOR 50
-#define LIBAVUTIL_VERSION_MINOR 31
+#define LIBAVUTIL_VERSION_MINOR 32
#define LIBAVUTIL_VERSION_MICRO 0
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
Modified: trunk/libavutil/rational.c
==============================================================================
--- trunk/libavutil/rational.c Thu Sep 30 22:40:10 2010 (r25277)
+++ trunk/libavutil/rational.c Thu Sep 30 23:57:31 2010 (r25278)
@@ -25,7 +25,7 @@
* @author Michael Niedermayer <michaelni at gmx.at>
*/
-#include <assert.h>
+#include "assert.h"
//#include <math.h>
#include <limits.h>
@@ -67,7 +67,7 @@ int av_reduce(int *dst_num, int *dst_den
num= den;
den= next_den;
}
- assert(av_gcd(a1.num, a1.den) <= 1U);
+ av_assert2(av_gcd(a1.num, a1.den) <= 1U);
*dst_num = sign ? -a1.num : a1.num;
*dst_den = a1.den;
More information about the ffmpeg-cvslog
mailing list