av_log() cleanup
null pointer segfaults dont print redundant spam dont print prefix if reference==NULL class -> av_class dont copy AVClass to every object, its a waste of memory and not a good idea at all Originally committed as revision 2841 to svn://svn.ffmpeg.org/ffmpeg/trunk
This commit is contained in:
parent
bc874daea8
commit
4346539522
@ -589,7 +589,7 @@ typedef struct AVCodecContext {
|
|||||||
* Info on struct for av_log
|
* Info on struct for av_log
|
||||||
* - set by avcodec_alloc_context
|
* - set by avcodec_alloc_context
|
||||||
*/
|
*/
|
||||||
AVClass class;
|
AVClass *av_class;
|
||||||
/**
|
/**
|
||||||
* the average bitrate.
|
* the average bitrate.
|
||||||
* - encoding: set by user. unused for constant quantizer encoding
|
* - encoding: set by user. unused for constant quantizer encoding
|
||||||
|
@ -342,9 +342,21 @@ enum PixelFormat avcodec_default_get_format(struct AVCodecContext *s, enum Pixel
|
|||||||
return fmt[0];
|
return fmt[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static const char* context_to_name(void* ptr) {
|
||||||
|
AVCodecContext *avc= ptr;
|
||||||
|
|
||||||
|
if(avc && avc->codec && avc->codec->name)
|
||||||
|
return avc->codec->name;
|
||||||
|
else
|
||||||
|
return "NULL";
|
||||||
|
}
|
||||||
|
|
||||||
|
static AVClass av_codec_context_class = { "AVCodecContext", context_to_name };
|
||||||
|
|
||||||
void avcodec_get_context_defaults(AVCodecContext *s){
|
void avcodec_get_context_defaults(AVCodecContext *s){
|
||||||
memset(s, 0, sizeof(AVCodecContext));
|
memset(s, 0, sizeof(AVCodecContext));
|
||||||
|
|
||||||
|
s->av_class= &av_codec_context_class;
|
||||||
s->bit_rate= 800*1000;
|
s->bit_rate= 800*1000;
|
||||||
s->bit_rate_tolerance= s->bit_rate*10;
|
s->bit_rate_tolerance= s->bit_rate*10;
|
||||||
s->qmin= 2;
|
s->qmin= 2;
|
||||||
@ -386,16 +398,11 @@ void avcodec_get_context_defaults(AVCodecContext *s){
|
|||||||
* allocates a AVCodecContext and set it to defaults.
|
* allocates a AVCodecContext and set it to defaults.
|
||||||
* this can be deallocated by simply calling free()
|
* this can be deallocated by simply calling free()
|
||||||
*/
|
*/
|
||||||
static const char* context_to_name(void* class_ptr) { return ((AVCodecContext*) class_ptr)->codec->name; }
|
|
||||||
|
|
||||||
static AVClass av_codec_context_class = { "AVCodecContext", context_to_name };
|
|
||||||
|
|
||||||
AVCodecContext *avcodec_alloc_context(void){
|
AVCodecContext *avcodec_alloc_context(void){
|
||||||
AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));
|
AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));
|
||||||
|
|
||||||
if(avctx==NULL) return NULL;
|
if(avctx==NULL) return NULL;
|
||||||
|
|
||||||
avctx->class = av_codec_context_class;
|
|
||||||
avcodec_get_context_defaults(avctx);
|
avcodec_get_context_defaults(avctx);
|
||||||
|
|
||||||
return avctx;
|
return avctx;
|
||||||
@ -840,23 +847,17 @@ int64_t av_rescale(int64_t a, int b, int c){
|
|||||||
|
|
||||||
/* av_log API */
|
/* av_log API */
|
||||||
|
|
||||||
static const char* null_to_name(void* class_ptr) { return "NULL"; }
|
|
||||||
|
|
||||||
static AVClass av_null_class = { "NULL", null_to_name };
|
|
||||||
|
|
||||||
static int av_log_level = AV_LOG_DEBUG;
|
static int av_log_level = AV_LOG_DEBUG;
|
||||||
|
|
||||||
static void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
|
static void av_log_default_callback(void* ptr, int level, const char* fmt, va_list vl)
|
||||||
{
|
{
|
||||||
static int print_prefix=1;
|
static int print_prefix=1;
|
||||||
AVClass* avcl = ptr;
|
AVClass* avc= ptr ? *(AVClass**)ptr : NULL;
|
||||||
if(!avcl || !avcl->class_name)
|
|
||||||
avcl = &av_null_class;
|
|
||||||
if(level>av_log_level)
|
if(level>av_log_level)
|
||||||
return;
|
return;
|
||||||
#undef fprintf
|
#undef fprintf
|
||||||
if(print_prefix) {
|
if(print_prefix && avc) {
|
||||||
fprintf(stderr, "[%s:%s @ %p]", avcl->class_name, avcl->item_name(avcl), avcl);
|
fprintf(stderr, "[%s @ %p]", avc->item_name(ptr), avc);
|
||||||
}
|
}
|
||||||
#define fprintf please_use_av_log
|
#define fprintf please_use_av_log
|
||||||
|
|
||||||
|
@ -241,7 +241,7 @@ typedef struct AVStream {
|
|||||||
|
|
||||||
/* format I/O context */
|
/* format I/O context */
|
||||||
typedef struct AVFormatContext {
|
typedef struct AVFormatContext {
|
||||||
AVClass class; /* set by av_alloc_format_context */
|
AVClass *av_class; /* set by av_alloc_format_context */
|
||||||
/* can only be iformat or oformat, not both at the same time */
|
/* can only be iformat or oformat, not both at the same time */
|
||||||
struct AVInputFormat *iformat;
|
struct AVInputFormat *iformat;
|
||||||
struct AVOutputFormat *oformat;
|
struct AVOutputFormat *oformat;
|
||||||
|
@ -301,9 +301,9 @@ AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened)
|
|||||||
* open a media file from an IO stream. 'fmt' must be specified.
|
* open a media file from an IO stream. 'fmt' must be specified.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static const char* format_to_name(void* class_ptr)
|
static const char* format_to_name(void* ptr)
|
||||||
{
|
{
|
||||||
AVFormatContext* fc = (AVFormatContext*) class_ptr;
|
AVFormatContext* fc = (AVFormatContext*) ptr;
|
||||||
if(fc->iformat) return fc->iformat->name;
|
if(fc->iformat) return fc->iformat->name;
|
||||||
else if(fc->oformat) return fc->oformat->name;
|
else if(fc->oformat) return fc->oformat->name;
|
||||||
else return "NULL";
|
else return "NULL";
|
||||||
@ -316,7 +316,7 @@ AVFormatContext *av_alloc_format_context(void)
|
|||||||
AVFormatContext *ic;
|
AVFormatContext *ic;
|
||||||
ic = av_mallocz(sizeof(AVFormatContext));
|
ic = av_mallocz(sizeof(AVFormatContext));
|
||||||
if (!ic) return ic;
|
if (!ic) return ic;
|
||||||
ic->class = av_format_context_class;
|
ic->av_class = &av_format_context_class;
|
||||||
return ic;
|
return ic;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1745,13 +1745,13 @@ void dump_format(AVFormatContext *ic,
|
|||||||
int i, flags;
|
int i, flags;
|
||||||
char buf[256];
|
char buf[256];
|
||||||
|
|
||||||
av_log(ic, AV_LOG_DEBUG, "%s #%d, %s, %s '%s':\n",
|
av_log(NULL, AV_LOG_DEBUG, "%s #%d, %s, %s '%s':\n",
|
||||||
is_output ? "Output" : "Input",
|
is_output ? "Output" : "Input",
|
||||||
index,
|
index,
|
||||||
is_output ? ic->oformat->name : ic->iformat->name,
|
is_output ? ic->oformat->name : ic->iformat->name,
|
||||||
is_output ? "to" : "from", url);
|
is_output ? "to" : "from", url);
|
||||||
if (!is_output) {
|
if (!is_output) {
|
||||||
av_log(ic, AV_LOG_DEBUG, " Duration: ");
|
av_log(NULL, AV_LOG_DEBUG, " Duration: ");
|
||||||
if (ic->duration != AV_NOPTS_VALUE) {
|
if (ic->duration != AV_NOPTS_VALUE) {
|
||||||
int hours, mins, secs, us;
|
int hours, mins, secs, us;
|
||||||
secs = ic->duration / AV_TIME_BASE;
|
secs = ic->duration / AV_TIME_BASE;
|
||||||
@ -1760,23 +1760,23 @@ void dump_format(AVFormatContext *ic,
|
|||||||
secs %= 60;
|
secs %= 60;
|
||||||
hours = mins / 60;
|
hours = mins / 60;
|
||||||
mins %= 60;
|
mins %= 60;
|
||||||
av_log(ic, AV_LOG_DEBUG, "%02d:%02d:%02d.%01d", hours, mins, secs,
|
av_log(NULL, AV_LOG_DEBUG, "%02d:%02d:%02d.%01d", hours, mins, secs,
|
||||||
(10 * us) / AV_TIME_BASE);
|
(10 * us) / AV_TIME_BASE);
|
||||||
} else {
|
} else {
|
||||||
av_log(ic, AV_LOG_DEBUG, "N/A");
|
av_log(NULL, AV_LOG_DEBUG, "N/A");
|
||||||
}
|
}
|
||||||
av_log(ic, AV_LOG_DEBUG, ", bitrate: ");
|
av_log(NULL, AV_LOG_DEBUG, ", bitrate: ");
|
||||||
if (ic->bit_rate) {
|
if (ic->bit_rate) {
|
||||||
av_log(ic, AV_LOG_DEBUG,"%d kb/s", ic->bit_rate / 1000);
|
av_log(NULL, AV_LOG_DEBUG,"%d kb/s", ic->bit_rate / 1000);
|
||||||
} else {
|
} else {
|
||||||
av_log(ic, AV_LOG_DEBUG, "N/A");
|
av_log(NULL, AV_LOG_DEBUG, "N/A");
|
||||||
}
|
}
|
||||||
av_log(ic, AV_LOG_DEBUG, "\n");
|
av_log(NULL, AV_LOG_DEBUG, "\n");
|
||||||
}
|
}
|
||||||
for(i=0;i<ic->nb_streams;i++) {
|
for(i=0;i<ic->nb_streams;i++) {
|
||||||
AVStream *st = ic->streams[i];
|
AVStream *st = ic->streams[i];
|
||||||
avcodec_string(buf, sizeof(buf), &st->codec, is_output);
|
avcodec_string(buf, sizeof(buf), &st->codec, is_output);
|
||||||
av_log(ic, AV_LOG_DEBUG, " Stream #%d.%d", index, i);
|
av_log(NULL, AV_LOG_DEBUG, " Stream #%d.%d", index, i);
|
||||||
/* the pid is an important information, so we display it */
|
/* the pid is an important information, so we display it */
|
||||||
/* XXX: add a generic system */
|
/* XXX: add a generic system */
|
||||||
if (is_output)
|
if (is_output)
|
||||||
@ -1784,9 +1784,9 @@ void dump_format(AVFormatContext *ic,
|
|||||||
else
|
else
|
||||||
flags = ic->iformat->flags;
|
flags = ic->iformat->flags;
|
||||||
if (flags & AVFMT_SHOW_IDS) {
|
if (flags & AVFMT_SHOW_IDS) {
|
||||||
av_log(ic, AV_LOG_DEBUG, "[0x%x]", st->id);
|
av_log(NULL, AV_LOG_DEBUG, "[0x%x]", st->id);
|
||||||
}
|
}
|
||||||
av_log(ic, AV_LOG_DEBUG, ": %s\n", buf);
|
av_log(NULL, AV_LOG_DEBUG, ": %s\n", buf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user