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 Originally committed as revision 25278 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
59b4e5ba49
commit
b926b6282d
17
ffmpeg.c
17
ffmpeg.c
@ -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 *s,
|
||||
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 *ist, int ist_index,
|
||||
//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 *opt, const char *arg)
|
||||
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". */
|
||||
|
@ -3,6 +3,7 @@ include $(SUBDIR)../config.mak
|
||||
NAME = avutil
|
||||
|
||||
HEADERS = adler32.h \
|
||||
assert.h \
|
||||
attributes.h \
|
||||
avstring.h \
|
||||
avutil.h \
|
||||
|
59
libavutil/assert.h
Normal file
59
libavutil/assert.h
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* copyright (c) 2010 Michael Niedermayer <michaelni@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@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
|
@ -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, \
|
||||
|
@ -25,7 +25,7 @@
|
||||
* @author Michael Niedermayer <michaelni@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, int64_t num, int64_t den, int64_t max)
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user