summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ffmpeg.c2
-rw-r--r--ffserver.c2
-rw-r--r--libavcodec/avcodec.h31
-rw-r--r--libavcodec/utils.c37
-rw-r--r--libavformat/asf.c12
-rw-r--r--libavformat/audio.c2
-rw-r--r--libavformat/avformat.h3
-rw-r--r--libavformat/dv.c6
-rw-r--r--libavformat/dv1394.c4
-rw-r--r--libavformat/flvdec.c2
-rw-r--r--libavformat/grab.c12
-rw-r--r--libavformat/idroq.c4
-rw-r--r--libavformat/mov.c2
-rw-r--r--libavformat/mpeg.c2
-rw-r--r--libavformat/nut.c16
-rw-r--r--libavformat/psxstr.c12
-rw-r--r--libavformat/rm.c2
-rw-r--r--libavformat/rtp.c2
-rw-r--r--libavformat/rtsp.c2
-rw-r--r--libavformat/swf.c8
-rw-r--r--libavformat/utils.c44
-rw-r--r--libavformat/wc3movie.c12
-rw-r--r--libavformat/westwood.c2
-rw-r--r--libavformat/yuv4mpeg.c6
-rw-r--r--output_example.c2
25 files changed, 134 insertions, 95 deletions
diff --git a/ffmpeg.c b/ffmpeg.c
index 622e03aa0b..86fbf3d5b4 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -2352,7 +2352,7 @@ static void opt_output_file(const char *filename)
if (!strcmp(filename, "-"))
filename = "pipe:";
- oc = av_mallocz(sizeof(AVFormatContext));
+ oc = av_alloc_format_context();
if (!file_oformat) {
file_oformat = guess_format(NULL, filename, NULL);
diff --git a/ffserver.c b/ffserver.c
index e550d00c25..4fb1fdeebf 100644
--- a/ffserver.c
+++ b/ffserver.c
@@ -3124,7 +3124,7 @@ static int rtp_new_av_stream(HTTPContext *c,
int max_packet_size;
/* now we can open the relevant output stream */
- ctx = av_mallocz(sizeof(AVFormatContext));
+ ctx = av_alloc_format_context();
if (!ctx)
return -1;
ctx->oformat = &rtp_mux;
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 956a2ef74a..772fbd7ae8 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -570,10 +570,27 @@ typedef struct AVFrame {
#define DEFAULT_FRAME_RATE_BASE 1001000
/**
+ * Used by av_log
+ */
+typedef struct AVCLASS AVClass;
+struct AVCLASS {
+ const char* class_name;
+ const char* (*item_name)(void*); /* actually passing a pointer to an AVCodecContext
+ or AVFormatContext, which begin with an AVClass.
+ Needed because av_log is in libavcodec and has no visibility
+ of AVIn/OutputFormat */
+};
+
+/**
* main external api structure.
*/
typedef struct AVCodecContext {
/**
+ * Info on struct for av_log
+ * - set by avcodec_alloc_context
+ */
+ AVClass class;
+ /**
* the average bitrate.
* - encoding: set by user. unused for constant quantizer encoding
* - decoding: set by lavc. 0 or some bitrate if this info is available in the stream
@@ -2095,19 +2112,11 @@ void img_copy(AVPicture *dst, const AVPicture *src,
#define AV_LOG_INFO 1
#define AV_LOG_DEBUG 2
-extern void av_log(AVCodecContext*, int level, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4)));
-extern void av_vlog(AVCodecContext*, int level, const char *fmt, va_list);
+extern void av_log(void*, int level, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4)));
+extern void av_vlog(void*, int level, const char *fmt, va_list);
extern int av_log_get_level(void);
extern void av_log_set_level(int);
-extern void av_log_set_callback(void (*)(AVCodecContext*, int, const char*, va_list));
-
-#undef AV_LOG_TRAP_PRINTF
-#ifdef AV_LOG_TRAP_PRINTF
-#define printf DO NOT USE
-#define fprintf DO NOT USE
-#undef stderr
-#define stderr DO NOT USE
-#endif
+extern void av_log_set_callback(void (*)(void*, int, const char*, va_list));
#ifdef __cplusplus
}
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 9fadfcd969..7f20d03c37 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -386,11 +386,16 @@ void avcodec_get_context_defaults(AVCodecContext *s){
* allocates a AVCodecContext and set it to defaults.
* 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 *avctx= av_malloc(sizeof(AVCodecContext));
if(avctx==NULL) return NULL;
+ avctx->class = av_codec_context_class;
avcodec_get_context_defaults(avctx);
return avctx;
@@ -835,22 +840,24 @@ int64_t av_rescale(int64_t a, int b, int c){
/* av_log API */
-#ifdef AV_LOG_TRAP_PRINTF
-#undef stderr
-#undef fprintf
-#endif
+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 void av_log_default_callback(AVCodecContext* avctx, 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;
-
+ AVClass* avcl = ptr;
+ if(!avcl || !avcl->class_name)
+ avcl = &av_null_class;
if(level>av_log_level)
- return;
+ return;
#undef fprintf
- if(avctx && print_prefix)
- fprintf(stderr, "[%s @ %p]", avctx->codec ? avctx->codec->name : "?", avctx);
+ if(print_prefix) {
+ fprintf(stderr, "[%s:%s @ %p]", avcl->class_name, avcl->item_name(avcl), avcl);
+ }
#define fprintf please_use_av_log
print_prefix= strstr(fmt, "\n") != NULL;
@@ -858,19 +865,19 @@ static void av_log_default_callback(AVCodecContext* avctx, int level, const char
vfprintf(stderr, fmt, vl);
}
-static void (*av_log_callback)(AVCodecContext*, int, const char*, va_list) = av_log_default_callback;
+static void (*av_log_callback)(void*, int, const char*, va_list) = av_log_default_callback;
-void av_log(AVCodecContext* avctx, int level, const char *fmt, ...)
+void av_log(void* avcl, int level, const char *fmt, ...)
{
va_list vl;
va_start(vl, fmt);
- av_vlog(avctx, level, fmt, vl);
+ av_vlog(avcl, level, fmt, vl);
va_end(vl);
}
-void av_vlog(AVCodecContext* avctx, int level, const char *fmt, va_list vl)
+void av_vlog(void* avcl, int level, const char *fmt, va_list vl)
{
- av_log_callback(avctx, level, fmt, vl);
+ av_log_callback(avcl, level, fmt, vl);
}
int av_log_get_level(void)
@@ -883,7 +890,7 @@ void av_log_set_level(int level)
av_log_level = level;
}
-void av_log_set_callback(void (*callback)(AVCodecContext*, int, const char*, va_list))
+void av_log_set_callback(void (*callback)(void*, int, const char*, va_list))
{
av_log_callback = callback;
}
diff --git a/libavformat/asf.c b/libavformat/asf.c
index f9ca75b709..bcc0f1a26a 100644
--- a/libavformat/asf.c
+++ b/libavformat/asf.c
@@ -1070,12 +1070,12 @@ static int asf_get_packet(AVFormatContext *s)
c = get_byte(pb);
if (c != 0x82) {
if (!url_feof(pb))
- printf("ff asf bad header %x at:%lld\n", c, url_ftell(pb));
+ av_log(s, AV_LOG_ERROR, "ff asf bad header %x at:%lld\n", c, url_ftell(pb));
}
if ((c & 0x0f) == 2) { // always true for now
if (get_le16(pb) != 0) {
if (!url_feof(pb))
- printf("ff asf bad non zero\n");
+ av_log(s, AV_LOG_ERROR, "ff asf bad non zero\n");
return -EIO;
}
rsize+=2;
@@ -1190,7 +1190,7 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
/* unhandled packet (should not happen) */
url_fskip(pb, asf->packet_frag_size);
asf->packet_size_left -= asf->packet_frag_size;
- printf("ff asf skip %d %d\n", asf->packet_frag_size, num & 0x7f);
+ av_log(s, AV_LOG_ERROR, "ff asf skip %d %d\n", asf->packet_frag_size, num & 0x7f);
continue;
}
asf->asf_st = s->streams[asf->stream_index]->priv_data;
@@ -1203,7 +1203,7 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
) {
/* cannot continue current packet: free it */
// FIXME better check if packet was already allocated
- printf("ff asf parser skips: %d - %d o:%d - %d %d %d fl:%d\n",
+ av_log(s, AV_LOG_INFO, "ff asf parser skips: %d - %d o:%d - %d %d %d fl:%d\n",
asf_st->pkt.size,
asf->packet_obj_size,
asf->packet_frag_offset, asf_st->frag_offset,
@@ -1213,7 +1213,7 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
asf_st->frag_offset = 0;
if (asf->packet_frag_offset != 0) {
url_fskip(pb, asf->packet_frag_size);
- printf("ff asf parser skiping %db\n", asf->packet_frag_size);
+ av_log(s, AV_LOG_INFO, "ff asf parser skiping %db\n", asf->packet_frag_size);
asf->packet_size_left -= asf->packet_frag_size;
continue;
}
@@ -1367,7 +1367,7 @@ static int64_t asf_read_pts(AVFormatContext *s, int64_t *ppos, int stream_index)
asf_reset_header(s);
for(;;){
if (av_read_frame(s, pkt) < 0){
- printf("seek failed\n");
+ av_log(s, AV_LOG_INFO, "seek failed\n");
return AV_NOPTS_VALUE;
}
pts= pkt->pts;
diff --git a/libavformat/audio.c b/libavformat/audio.c
index 3662e458ff..d40f0f9bc2 100644
--- a/libavformat/audio.c
+++ b/libavformat/audio.c
@@ -106,7 +106,7 @@ static int audio_open(AudioData *s, int is_output, const char *audio_device)
s->codec_id = CODEC_ID_PCM_S16BE;
break;
default:
- fprintf(stderr, "Soundcard does not support 16 bit sample format\n");
+ av_log(NULL, AV_LOG_ERROR, "Soundcard does not support 16 bit sample format\n");
close(audio_fd);
return -EIO;
}
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 432d2e57bc..153c2ddfb5 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -241,6 +241,7 @@ typedef struct AVStream {
/* format I/O context */
typedef struct AVFormatContext {
+ AVClass class; /* set by av_alloc_format_context */
/* can only be iformat or oformat, not both at the same time */
struct AVInputFormat *iformat;
struct AVOutputFormat *oformat;
@@ -523,6 +524,8 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
AVInputFormat *fmt,
int buf_size,
AVFormatParameters *ap);
+/* no av_open for output, so applications will need this: */
+AVFormatContext *av_alloc_format_context(void);
#define AVERROR_UNKNOWN (-1) /* unknown error */
#define AVERROR_IO (-2) /* i/o error */
diff --git a/libavformat/dv.c b/libavformat/dv.c
index dacf4e2db8..65e81579ce 100644
--- a/libavformat/dv.c
+++ b/libavformat/dv.c
@@ -610,7 +610,7 @@ int dv_assemble_frame(DVMuxContext *c, AVStream* st,
if (st->codec.codec_type == CODEC_TYPE_VIDEO) {
/* FIXME: we have to have more sensible approach than this one */
if (c->has_video)
- fprintf(stderr, "Can't process DV frame #%d. Insufficient audio data or severe sync problem.\n", c->frames);
+ av_log(&st->codec, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient audio data or severe sync problem.\n", c->frames);
dv_inject_video(c, data, *frame);
c->has_video = 1;
@@ -635,7 +635,7 @@ int dv_assemble_frame(DVMuxContext *c, AVStream* st,
/* FIXME: we have to have more sensible approach than this one */
if (fifo_size(&c->audio_data, c->audio_data.rptr) + data_size >= 100*AVCODEC_MAX_AUDIO_FRAME_SIZE)
- fprintf(stderr, "Can't process DV frame #%d. Insufficient video data or severe sync problem.\n", c->frames);
+ av_log(&st->codec, AV_LOG_ERROR, "Can't process DV frame #%d. Insufficient video data or severe sync problem.\n", c->frames);
fifo_write(&c->audio_data, (uint8_t *)data, data_size, &c->audio_data.wptr);
}
@@ -848,7 +848,7 @@ static int dv_write_header(AVFormatContext *s)
{
s->priv_data = dv_init_mux(s);
if (!s->priv_data) {
- fprintf(stderr, "Can't initialize DV format!\n"
+ av_log(s, AV_LOG_ERROR, "Can't initialize DV format!\n"
"Make sure that you supply exactly two streams:\n"
" video: 25fps or 29.97fps, audio: 2ch/48Khz/PCM\n");
return -1;
diff --git a/libavformat/dv1394.c b/libavformat/dv1394.c
index 1cbb0e7eb1..94c62f65b6 100644
--- a/libavformat/dv1394.c
+++ b/libavformat/dv1394.c
@@ -153,7 +153,7 @@ static int dv1394_read_packet(AVFormatContext *context, AVPacket *pkt)
* We have to reset :(.
*/
- fprintf(stderr, "DV1394: Ring buffer overflow. Reseting ..\n");
+ av_log(context, AV_LOG_ERROR, "DV1394: Ring buffer overflow. Reseting ..\n");
dv1394_reset(dv);
dv1394_start(dv);
@@ -191,7 +191,7 @@ restart_poll:
dv->done = 0;
if (s.dropped_frames) {
- fprintf(stderr, "DV1394: Frame drop detected (%d). Reseting ..\n",
+ av_log(context, AV_LOG_ERROR, "DV1394: Frame drop detected (%d). Reseting ..\n",
s.dropped_frames);
dv1394_reset(dv);
diff --git a/libavformat/flvdec.c b/libavformat/flvdec.c
index e443fd523a..8b55e6b324 100644
--- a/libavformat/flvdec.c
+++ b/libavformat/flvdec.c
@@ -102,7 +102,7 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
} else {
skip:
/* skip packet */
- printf("skipping flv packet: type %d, size %d, flags %d\n", type, size, flags);
+ av_log(s, AV_LOG_ERROR, "skipping flv packet: type %d, size %d, flags %d\n", type, size, flags);
url_fskip(&s->pb, size);
goto redo;
}
diff --git a/libavformat/grab.c b/libavformat/grab.c
index d2b2cc9a41..d8a1ce6fcb 100644
--- a/libavformat/grab.c
+++ b/libavformat/grab.c
@@ -99,7 +99,7 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
}
if (!(s->video_cap.type & VID_TYPE_CAPTURE)) {
- fprintf(stderr, "Fatal: grab device does not handle capture\n");
+ av_log(s1, AV_LOG_ERROR, "Fatal: grab device does not handle capture\n");
goto fail;
}
@@ -223,9 +223,9 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
if (ret < 0) {
if (errno != EAGAIN) {
fail1:
- fprintf(stderr, "Fatal: grab device does not support suitable format\n");
+ av_log(s1, AV_LOG_ERROR, "Fatal: grab device does not support suitable format\n");
} else {
- fprintf(stderr,"Fatal: grab device does not receive any video signal\n");
+ av_log(s1, AV_LOG_ERROR,"Fatal: grab device does not receive any video signal\n");
}
goto fail;
}
@@ -277,7 +277,7 @@ static int v4l_mm_read_picture(VideoData *s, uint8_t *buf)
s->gb_buf.frame = (s->gb_frame + 1) % s->gb_buffers.frames;
if (ioctl(s->fd, VIDIOCMCAPTURE, &s->gb_buf) < 0) {
if (errno == EAGAIN)
- fprintf(stderr,"Cannot Sync\n");
+ av_log(NULL, AV_LOG_ERROR, "Cannot Sync\n");
else
perror("VIDIOCMCAPTURE");
return -EIO;
@@ -387,8 +387,8 @@ static int aiw_init(VideoData *s)
if (height == s->video_cap.maxheight*2) s->deint=1;
if (width == s->video_cap.maxwidth/2) s->halfw=1;
} else {
- fprintf(stderr,"\nIncorrect Grab Size Supplied - Supported Sizes Are:\n");
- fprintf(stderr," %dx%d %dx%d %dx%d\n\n",
+ av_log(NULL, AV_LOG_ERROR, "\nIncorrect Grab Size Supplied - Supported Sizes Are:\n");
+ av_log(NULL, AV_LOG_ERROR, " %dx%d %dx%d %dx%d\n\n",
s->video_cap.maxwidth,s->video_cap.maxheight,
s->video_cap.maxwidth,s->video_cap.maxheight*2,
s->video_cap.maxwidth/2,s->video_cap.maxheight);
diff --git a/libavformat/idroq.c b/libavformat/idroq.c
index c2af12f918..d87cfb3080 100644
--- a/libavformat/idroq.c
+++ b/libavformat/idroq.c
@@ -135,7 +135,7 @@ static int roq_read_header(AVFormatContext *s,
break;
default:
- printf (" unknown RoQ chunk type (%04X)\n", LE_16(&preamble[0]));
+ av_log(s, AV_LOG_ERROR, " unknown RoQ chunk type (%04X)\n", LE_16(&preamble[0]));
return AVERROR_INVALIDDATA;
break;
}
@@ -268,7 +268,7 @@ static int roq_read_packet(AVFormatContext *s,
break;
default:
- printf (" unknown RoQ chunk (%04X)\n", chunk_type);
+ av_log(s, AV_LOG_ERROR, " unknown RoQ chunk (%04X)\n", chunk_type);
return AVERROR_INVALIDDATA;
break;
}
diff --git a/libavformat/mov.c b/libavformat/mov.c
index 707a49c489..0e9e803bd2 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -1531,7 +1531,7 @@ static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap)
/* check MOV header */
err = mov_read_default(mov, pb, atom);
if (err<0 || (!mov->found_moov && !mov->found_mdat)) {
- fprintf(stderr, "mov: header not found !!! (err:%d, moov:%d, mdat:%d) pos:%lld\n",
+ av_log(s, AV_LOG_ERROR, "mov: header not found !!! (err:%d, moov:%d, mdat:%d) pos:%lld\n",
err, mov->found_moov, mov->found_mdat, url_ftell(pb));
return -1;
}
diff --git a/libavformat/mpeg.c b/libavformat/mpeg.c
index 6ba516370f..a5cd8dfae1 100644
--- a/libavformat/mpeg.c
+++ b/libavformat/mpeg.c
@@ -773,7 +773,7 @@ static void compute_pts_dts(AVStream *st, int64_t *ppts, int64_t *pdts,
}
}
#if 1
- printf("pts=%0.3f dts=%0.3f pict_type=%c\n",
+ av_log(&st->codec, AV_LOG_DEBUG, "pts=%0.3f dts=%0.3f pict_type=%c\n",
pts / 90000.0, dts / 90000.0,
av_get_pict_type_char(st->codec.coded_frame->pict_type));
#endif
diff --git a/libavformat/nut.c b/libavformat/nut.c
index 09475946f3..f905410d88 100644
--- a/libavformat/nut.c
+++ b/libavformat/nut.c
@@ -456,12 +456,12 @@ static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap)
/* main header */
tmp = get_be64(bc);
if (tmp != MAIN_STARTCODE)
- fprintf(stderr, "damaged? startcode!=1 (%Ld)\n", tmp);
+ av_log(s, AV_LOG_ERROR, "damaged? startcode!=1 (%Ld)\n", tmp);
get_packetheader(nut, bc);
tmp = get_v(bc);
if (tmp != 0)
- fprintf(stderr, "bad version (%Ld)\n", tmp);
+ av_log(s, AV_LOG_ERROR, "bad version (%Ld)\n", tmp);
nb_streams = get_v(bc);
get_be32(bc); /* checkusm */
@@ -481,7 +481,7 @@ static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap)
tmp = get_be64(bc);
if (tmp != STREAM_STARTCODE)
- fprintf(stderr, "damaged? startcode!=1 (%Ld)\n", tmp);
+ av_log(s, AV_LOG_ERROR, "damaged? startcode!=1 (%Ld)\n", tmp);
get_packetheader(nut, bc);
st = av_new_stream(s, get_v(bc));
if (!st)
@@ -494,16 +494,16 @@ static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap)
st->codec.codec_type = CODEC_TYPE_VIDEO;
st->codec.codec_id = codec_get_bmp_id(tmp);
if (st->codec.codec_id == CODEC_ID_NONE)
- fprintf(stderr, "Unknown codec?!\n");
+ av_log(s, AV_LOG_ERROR, "Unknown codec?!\n");
break;
case 32:
st->codec.codec_type = CODEC_TYPE_AUDIO;
st->codec.codec_id = codec_get_wav_id(tmp);
if (st->codec.codec_id == CODEC_ID_NONE)
- fprintf(stderr, "Unknown codec?!\n");
+ av_log(s, AV_LOG_ERROR, "Unknown codec?!\n");
break;
default:
- fprintf(stderr, "Unknown stream class (%d)\n", class);
+ av_log(s, AV_LOG_ERROR, "Unknown stream class (%d)\n", class);
return -1;
}
s->bit_rate += get_v(bc);
@@ -565,12 +565,12 @@ static int nut_read_packet(AVFormatContext *s, AVPacket *pkt)
tmp = get_byte(bc); /* flags */
}
else
- fprintf(stderr, "error in zero bit / startcode %LX\n", tmp);
+ av_log(s, AV_LOG_ERROR, "error in zero bit / startcode %LX\n", tmp);
}
get_packetheader(nut, bc);
#if 0
if (((tmp & 0x60)>>5) > 3) /* priority <= 3 */
- fprintf(stderr, "sanity check failed!\n");
+ av_log(s, AV_LOG_ERROR, "sanity check failed!\n");
#endif
id = get_v(bc);
if ((tmp & 0x8) >> 3)
diff --git a/libavformat/psxstr.c b/libavformat/psxstr.c
index f0159c6339..9b5140787e 100644
--- a/libavformat/psxstr.c
+++ b/libavformat/psxstr.c
@@ -123,11 +123,11 @@ static void dump(unsigned char *buf,size_t len)
{
int i;
for(i=0;i<len;i++) {
- if ((i&15)==0) printf("%04x ",i);
- printf("%02x ",buf[i]);
- if ((i&15)==15) printf("\n");
+ if ((i&15)==0) av_log(NULL, AV_LOG_DEBUG, "%04x ",i);
+ av_log(NULL, AV_LOG_DEBUG, "%02x ",buf[i]);
+ if ((i&15)==15) av_log(NULL, AV_LOG_DEBUG, "\n");
}
- printf("\n");
+ av_log(NULL, AV_LOG_DEBUG, "\n");
}
static int str_read_header(AVFormatContext *s,
@@ -239,11 +239,11 @@ static int str_read_header(AVFormatContext *s,
}
if (str->video_channel != -1)
- printf (" video channel = %d, %d x %d %d\n", str->video_channel,
+ av_log (s, AV_LOG_DEBUG, " video channel = %d, %d x %d %d\n", str->video_channel,
str->channels[str->video_channel].width,
str->channels[str->video_channel].height,str->channels[str->video_channel].video_stream_index);
if (str->audio_channel != -1)
- printf (" audio channel = %d, %d Hz, %d channels, %d bits/sample %d\n",
+ av_log (s, AV_LOG_DEBUG, " audio channel = %d, %d Hz, %d channels, %d bits/sample %d\n",
str->audio_channel,
str->channels[str->audio_channel].sample_rate,
str->channels[str->audio_channel].channels,
diff --git a/libavformat/rm.c b/libavformat/rm.c
index 6cec714ff8..7942337541 100644
--- a/libavformat/rm.c
+++ b/libavformat/rm.c
@@ -636,7 +636,7 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
} else {
if (get_le32(pb) != MKTAG('V', 'I', 'D', 'O')) {
fail1:
- fprintf(stderr, "Unsupported video codec\n");
+ av_log(&st->codec, AV_LOG_ERROR, "Unsupported video codec\n");
goto fail;
}
st->codec.codec_tag = get_le32(pb);
diff --git a/libavformat/rtp.c b/libavformat/rtp.c
index 60fa0d1842..5d4884d8f7 100644
--- a/libavformat/rtp.c
+++ b/libavformat/rtp.c
@@ -301,7 +301,7 @@ int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
return -1;
#if defined(DEBUG) || 1
if (seq != ((s->seq + 1) & 0xffff)) {
- printf("RTP: PT=%02x: bad cseq %04x expected=%04x\n",
+ av_log(&s->st->codec, AV_LOG_ERROR, "RTP: PT=%02x: bad cseq %04x expected=%04x\n",
payload_type, seq, ((s->seq + 1) & 0xffff));
}
s->seq = seq;
diff --git a/libavformat/rtsp.c b/libavformat/rtsp.c
index 54ae6c1c3e..3d5469616f 100644
--- a/libavformat/rtsp.c
+++ b/libavformat/rtsp.c
@@ -1050,7 +1050,7 @@ static int rtsp_read_play(AVFormatContext *s)
RTSPHeader reply1, *reply = &reply1;
char cmd[1024];
- printf("hello state=%d\n", rt->state);
+ av_log(s, AV_LOG_DEBUG, "hello state=%d\n", rt->state);
if (rt->state == RTSP_STATE_PAUSED) {
snprintf(cmd, sizeof(cmd),
diff --git a/libavformat/swf.c b/libavformat/swf.c
index fd70e54521..a4f199ef3b 100644
--- a/libavformat/swf.c
+++ b/libavformat/swf.c
@@ -341,7 +341,7 @@ static int swf_write_header(AVFormatContext *s)
if ( enc->codec_id == CODEC_ID_FLV1 || enc->codec_id == CODEC_ID_MJPEG ) {
video_enc = enc;
} else {
- fprintf(stderr, "SWF only supports FLV1 and MJPEG\n");
+ av_log(enc, AV_LOG_ERROR, "SWF only supports FLV1 and MJPEG\n");
return -1;
}
}
@@ -479,7 +479,7 @@ static int swf_write_video(AVFormatContext *s,
/* Flash Player limit */
if ( swf->swf_frame_number == 16000 ) {
- fprintf(stderr, "warning: Flash Player limit of 16000 frames reached\n");
+ av_log(enc, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames reached\n");
}
/* Store video data in queue */
@@ -680,7 +680,7 @@ static int swf_write_audio(AVFormatContext *s,
/* Flash Player limit */
if ( swf->swf_frame_number == 16000 ) {
- fprintf(stderr, "warning: Flash Player limit of 16000 frames reached\n");
+ av_log(enc, AV_LOG_INFO, "warning: Flash Player limit of 16000 frames reached\n");
}
if (enc->codec_id == CODEC_ID_MP3 ) {
@@ -825,7 +825,7 @@ static int swf_read_header(AVFormatContext *s, AVFormatParameters *ap)
}
break;
}
- fprintf(stderr, "No media found in SWF\n");
+ av_log(s, AV_LOG_ERROR, "No media found in SWF\n");
return -EIO;
}
if ( tag == TAG_VIDEOSTREAM && !vst) {
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 8f9b97e7b0..29a8fbea76 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -300,6 +300,26 @@ AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened)
/**
* open a media file from an IO stream. 'fmt' must be specified.
*/
+
+static const char* format_to_name(void* class_ptr)
+{
+ AVFormatContext* fc = (AVFormatContext*) class_ptr;
+ if(fc->iformat) return fc->iformat->name;
+ else if(fc->oformat) return fc->oformat->name;
+ else return "NULL";
+}
+
+static const AVClass av_format_context_class = { "AVFormatContext", format_to_name };
+
+AVFormatContext *av_alloc_format_context(void)
+{
+ AVFormatContext *ic;
+ ic = av_mallocz(sizeof(AVFormatContext));
+ if (!ic) return ic;
+ ic->class = av_format_context_class;
+ return ic;
+}
+
int av_open_input_stream(AVFormatContext **ic_ptr,
ByteIOContext *pb, const char *filename,
AVInputFormat *fmt, AVFormatParameters *ap)
@@ -307,7 +327,7 @@ int av_open_input_stream(AVFormatContext **ic_ptr,
int err;
AVFormatContext *ic;
- ic = av_mallocz(sizeof(AVFormatContext));
+ ic = av_alloc_format_context();
if (!ic) {
err = AVERROR_NOMEM;
goto fail;
@@ -1725,13 +1745,13 @@ void dump_format(AVFormatContext *ic,
int i, flags;
char buf[256];
- fprintf(stderr, "%s #%d, %s, %s '%s':\n",
+ av_log(ic, AV_LOG_DEBUG, "%s #%d, %s, %s '%s':\n",
is_output ? "Output" : "Input",
index,
is_output ? ic->oformat->name : ic->iformat->name,
is_output ? "to" : "from", url);
if (!is_output) {
- fprintf(stderr, " Duration: ");
+ av_log(ic, AV_LOG_DEBUG, " Duration: ");
if (ic->duration != AV_NOPTS_VALUE) {
int hours, mins, secs, us;
secs = ic->duration / AV_TIME_BASE;
@@ -1740,23 +1760,23 @@ void dump_format(AVFormatContext *ic,
secs %= 60;
hours = mins / 60;
mins %= 60;
- fprintf(stderr, "%02d:%02d:%02d.%01d", hours, mins, secs,
+ av_log(ic, AV_LOG_DEBUG, "%02d:%02d:%02d.%01d", hours, mins, secs,
(10 * us) / AV_TIME_BASE);
} else {
- fprintf(stderr, "N/A");
+ av_log(ic, AV_LOG_DEBUG, "N/A");
}
- fprintf(stderr, ", bitrate: ");
+ av_log(ic, AV_LOG_DEBUG, ", bitrate: ");
if (ic->bit_rate) {
- fprintf(stderr,"%d kb/s", ic->bit_rate / 1000);
+ av_log(ic, AV_LOG_DEBUG,"%d kb/s", ic->bit_rate / 1000);
} else {
- fprintf(stderr, "N/A");
+ av_log(ic, AV_LOG_DEBUG, "N/A");
}
- fprintf(stderr, "\n");
+ av_log(ic, AV_LOG_DEBUG, "\n");
}
for(i=0;i<ic->nb_streams;i++) {
AVStream *st = ic->streams[i];
avcodec_string(buf, sizeof(buf), &st->codec, is_output);
- fprintf(stderr, " Stream #%d.%d", index, i);
+ av_log(ic, AV_LOG_DEBUG, " Stream #%d.%d", index, i);
/* the pid is an important information, so we display it */
/* XXX: add a generic system */
if (is_output)
@@ -1764,9 +1784,9 @@ void dump_format(AVFormatContext *ic,
else
flags = ic->iformat->flags;
if (flags & AVFMT_SHOW_IDS) {
- fprintf(stderr, "[0x%x]", st->id);
+ av_log(ic, AV_LOG_DEBUG, "[0x%x]", st->id);
}
- fprintf(stderr, ": %s\n", buf);
+ av_log(ic, AV_LOG_DEBUG, ": %s\n", buf);
}
}
diff --git a/libavformat/wc3movie.c b/libavformat/wc3movie.c
index cedb904231..fc4f37e5a0 100644
--- a/libavformat/wc3movie.c
+++ b/libavformat/wc3movie.c
@@ -230,7 +230,7 @@ static int wc3_read_header(AVFormatContext *s,
break;
default:
- printf (" unrecognized WC3 chunk: %c%c%c%c (0x%02X%02X%02X%02X)\n",
+ av_log(s, AV_LOG_ERROR, " unrecognized WC3 chunk: %c%c%c%c (0x%02X%02X%02X%02X)\n",
preamble[0], preamble[1], preamble[2], preamble[3],
preamble[0], preamble[1], preamble[2], preamble[3]);
return AVERROR_INVALIDDATA;
@@ -352,12 +352,12 @@ static int wc3_read_packet(AVFormatContext *s,
ret = -EIO;
else {
int i = 0;
- printf ("Subtitle time!\n");
- printf (" inglish: %s\n", &text[i + 1]);
+ av_log (s, AV_LOG_DEBUG, "Subtitle time!\n");
+ av_log (s, AV_LOG_DEBUG, " inglish: %s\n", &text[i + 1]);
i += text[i] + 1;
- printf (" doytsch: %s\n", &text[i + 1]);
+ av_log (s, AV_LOG_DEBUG, " doytsch: %s\n", &text[i + 1]);
i += text[i] + 1;
- printf (" fronsay: %s\n", &text[i + 1]);
+ av_log (s, AV_LOG_DEBUG, " fronsay: %s\n", &text[i + 1]);
}
#endif
break;
@@ -379,7 +379,7 @@ static int wc3_read_packet(AVFormatContext *s,
break;
default:
- printf (" unrecognized WC3 chunk: %c%c%c%c (0x%02X%02X%02X%02X)\n",
+ av_log (s, AV_LOG_ERROR, " unrecognized WC3 chunk: %c%c%c%c (0x%02X%02X%02X%02X)\n",
preamble[0], preamble[1], preamble[2], preamble[3],
preamble[0], preamble[1], preamble[2], preamble[3]);
ret = AVERROR_INVALIDDATA;
diff --git a/libavformat/westwood.c b/libavformat/westwood.c
index 55dd61bfb9..af0777f644 100644
--- a/libavformat/westwood.c
+++ b/libavformat/westwood.c
@@ -309,7 +309,7 @@ static int wsvqa_read_header(AVFormatContext *s,
break;
default:
- printf (" note: unknown chunk seen (%c%c%c%c)\n",
+ av_log (s, AV_LOG_ERROR, " note: unknown chunk seen (%c%c%c%c)\n",
scratch[0], scratch[1],
scratch[2], scratch[3]);
break;
diff --git a/libavformat/yuv4mpeg.c b/libavformat/yuv4mpeg.c
index 25eef070fe..54fbff57f8 100644
--- a/libavformat/yuv4mpeg.c
+++ b/libavformat/yuv4mpeg.c
@@ -77,7 +77,7 @@ static int yuv4_write_packet(AVFormatContext *s, int stream_index,
if (*first_pkt) {
*first_pkt = 0;
if (yuv4_generate_header(s, buf2) < 0) {
- fprintf(stderr, "Error. YUV4MPEG stream header write failed.\n");
+ av_log(s, AV_LOG_ERROR, "Error. YUV4MPEG stream header write failed.\n");
return -EIO;
} else {
put_buffer(pb, buf2, strlen(buf2));
@@ -122,10 +122,10 @@ static int yuv4_write_header(AVFormatContext *s)
return -EIO;
if (s->streams[0]->codec.pix_fmt == PIX_FMT_YUV411P) {
- fprintf(stderr, "Warning: generating non-standard 4:1:1 YUV stream, some mjpegtools might not work.\n");
+ av_log(s, AV_LOG_ERROR, "Warning: generating non-standard 4:1:1 YUV stream, some mjpegtools might not work.\n");
}
else if (s->streams[0]->codec.pix_fmt != PIX_FMT_YUV420P) {
- fprintf(stderr, "ERROR: yuv4mpeg only handles 4:2:0, 4:1:1 YUV data. Use -pix_fmt to select one.\n");
+ av_log(s, AV_LOG_ERROR, "ERROR: yuv4mpeg only handles 4:2:0, 4:1:1 YUV data. Use -pix_fmt to select one.\n");
return -EIO;
}
diff --git a/output_example.c b/output_example.c
index 2fba8fc6a8..45f6a0645b 100644
--- a/output_example.c
+++ b/output_example.c
@@ -408,7 +408,7 @@ int main(int argc, char **argv)
}
/* allocate the output media context */
- oc = av_mallocz(sizeof(AVFormatContext));
+ oc = av_alloc_format_context();
if (!oc) {
fprintf(stderr, "Memory error\n");
exit(1);