Commit bc874dae authored by Michel Bardiaux's avatar Michel Bardiaux Committed by Michael Niedermayer

av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)

Originally committed as revision 2840 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 81c5f887
...@@ -2352,7 +2352,7 @@ static void opt_output_file(const char *filename) ...@@ -2352,7 +2352,7 @@ static void opt_output_file(const char *filename)
if (!strcmp(filename, "-")) if (!strcmp(filename, "-"))
filename = "pipe:"; filename = "pipe:";
oc = av_mallocz(sizeof(AVFormatContext)); oc = av_alloc_format_context();
if (!file_oformat) { if (!file_oformat) {
file_oformat = guess_format(NULL, filename, NULL); file_oformat = guess_format(NULL, filename, NULL);
......
...@@ -3124,7 +3124,7 @@ static int rtp_new_av_stream(HTTPContext *c, ...@@ -3124,7 +3124,7 @@ static int rtp_new_av_stream(HTTPContext *c,
int max_packet_size; int max_packet_size;
/* now we can open the relevant output stream */ /* now we can open the relevant output stream */
ctx = av_mallocz(sizeof(AVFormatContext)); ctx = av_alloc_format_context();
if (!ctx) if (!ctx)
return -1; return -1;
ctx->oformat = &rtp_mux; ctx->oformat = &rtp_mux;
......
...@@ -569,10 +569,27 @@ typedef struct AVFrame { ...@@ -569,10 +569,27 @@ typedef struct AVFrame {
#define DEFAULT_FRAME_RATE_BASE 1001000 #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. * main external api structure.
*/ */
typedef struct AVCodecContext { typedef struct AVCodecContext {
/**
* Info on struct for av_log
* - set by avcodec_alloc_context
*/
AVClass 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
...@@ -2095,19 +2112,11 @@ void img_copy(AVPicture *dst, const AVPicture *src, ...@@ -2095,19 +2112,11 @@ void img_copy(AVPicture *dst, const AVPicture *src,
#define AV_LOG_INFO 1 #define AV_LOG_INFO 1
#define AV_LOG_DEBUG 2 #define AV_LOG_DEBUG 2
extern void av_log(AVCodecContext*, int level, const char *fmt, ...) __attribute__ ((__format__ (__printf__, 3, 4))); extern void av_log(void*, 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_vlog(void*, int level, const char *fmt, va_list);
extern int av_log_get_level(void); extern int av_log_get_level(void);
extern void av_log_set_level(int); extern void av_log_set_level(int);
extern void av_log_set_callback(void (*)(AVCodecContext*, int, const char*, va_list)); extern void av_log_set_callback(void (*)(void*, 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
#ifdef __cplusplus #ifdef __cplusplus
} }
......
...@@ -386,11 +386,16 @@ void avcodec_get_context_defaults(AVCodecContext *s){ ...@@ -386,11 +386,16 @@ 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;
...@@ -835,22 +840,24 @@ int64_t av_rescale(int64_t a, int b, int c){ ...@@ -835,22 +840,24 @@ int64_t av_rescale(int64_t a, int b, int c){
/* av_log API */ /* av_log API */
#ifdef AV_LOG_TRAP_PRINTF static const char* null_to_name(void* class_ptr) { return "NULL"; }
#undef stderr
#undef fprintf static AVClass av_null_class = { "NULL", null_to_name };
#endif
static int av_log_level = AV_LOG_DEBUG; 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; static int print_prefix=1;
AVClass* avcl = ptr;
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(avctx && print_prefix) if(print_prefix) {
fprintf(stderr, "[%s @ %p]", avctx->codec ? avctx->codec->name : "?", avctx); fprintf(stderr, "[%s:%s @ %p]", avcl->class_name, avcl->item_name(avcl), avcl);
}
#define fprintf please_use_av_log #define fprintf please_use_av_log
print_prefix= strstr(fmt, "\n") != NULL; print_prefix= strstr(fmt, "\n") != NULL;
...@@ -858,19 +865,19 @@ static void av_log_default_callback(AVCodecContext* avctx, int level, const char ...@@ -858,19 +865,19 @@ static void av_log_default_callback(AVCodecContext* avctx, int level, const char
vfprintf(stderr, fmt, vl); 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_list vl;
va_start(vl, fmt); va_start(vl, fmt);
av_vlog(avctx, level, fmt, vl); av_vlog(avcl, level, fmt, vl);
va_end(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) int av_log_get_level(void)
...@@ -883,7 +890,7 @@ void av_log_set_level(int level) ...@@ -883,7 +890,7 @@ void av_log_set_level(int level)
av_log_level = 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; av_log_callback = callback;
} }
......
...@@ -1070,12 +1070,12 @@ static int asf_get_packet(AVFormatContext *s) ...@@ -1070,12 +1070,12 @@ static int asf_get_packet(AVFormatContext *s)
c = get_byte(pb); c = get_byte(pb);
if (c != 0x82) { if (c != 0x82) {
if (!url_feof(pb)) 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 ((c & 0x0f) == 2) { // always true for now
if (get_le16(pb) != 0) { if (get_le16(pb) != 0) {
if (!url_feof(pb)) 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; return -EIO;
} }
rsize+=2; rsize+=2;
...@@ -1190,7 +1190,7 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -1190,7 +1190,7 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
/* unhandled packet (should not happen) */ /* unhandled packet (should not happen) */
url_fskip(pb, asf->packet_frag_size); url_fskip(pb, asf->packet_frag_size);
asf->packet_size_left -= 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; continue;
} }
asf->asf_st = s->streams[asf->stream_index]->priv_data; asf->asf_st = s->streams[asf->stream_index]->priv_data;
...@@ -1203,7 +1203,7 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -1203,7 +1203,7 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
) { ) {
/* cannot continue current packet: free it */ /* cannot continue current packet: free it */
// FIXME better check if packet was already allocated // 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_st->pkt.size,
asf->packet_obj_size, asf->packet_obj_size,
asf->packet_frag_offset, asf_st->frag_offset, asf->packet_frag_offset, asf_st->frag_offset,
...@@ -1213,7 +1213,7 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -1213,7 +1213,7 @@ static int asf_read_packet(AVFormatContext *s, AVPacket *pkt)
asf_st->frag_offset = 0; asf_st->frag_offset = 0;
if (asf->packet_frag_offset != 0) { if (asf->packet_frag_offset != 0) {
url_fskip(pb, asf->packet_frag_size); 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; asf->packet_size_left -= asf->packet_frag_size;
continue; continue;
} }
...@@ -1367,7 +1367,7 @@ static int64_t asf_read_pts(AVFormatContext *s, int64_t *ppos, int stream_index) ...@@ -1367,7 +1367,7 @@ static int64_t asf_read_pts(AVFormatContext *s, int64_t *ppos, int stream_index)
asf_reset_header(s); asf_reset_header(s);
for(;;){ for(;;){
if (av_read_frame(s, pkt) < 0){ if (av_read_frame(s, pkt) < 0){
printf("seek failed\n"); av_log(s, AV_LOG_INFO, "seek failed\n");
return AV_NOPTS_VALUE; return AV_NOPTS_VALUE;
} }
pts= pkt->pts; pts= pkt->pts;
......
...@@ -106,7 +106,7 @@ static int audio_open(AudioData *s, int is_output, const char *audio_device) ...@@ -106,7 +106,7 @@ static int audio_open(AudioData *s, int is_output, const char *audio_device)
s->codec_id = CODEC_ID_PCM_S16BE; s->codec_id = CODEC_ID_PCM_S16BE;
break; break;
default: 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); close(audio_fd);
return -EIO; return -EIO;
} }
......
...@@ -241,6 +241,7 @@ typedef struct AVStream { ...@@ -241,6 +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 */
/* 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;
...@@ -523,6 +524,8 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename, ...@@ -523,6 +524,8 @@ int av_open_input_file(AVFormatContext **ic_ptr, const char *filename,
AVInputFormat *fmt, AVInputFormat *fmt,
int buf_size, int buf_size,
AVFormatParameters *ap); 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_UNKNOWN (-1) /* unknown error */
#define AVERROR_IO (-2) /* i/o error */ #define AVERROR_IO (-2) /* i/o error */
......
...@@ -610,7 +610,7 @@ int dv_assemble_frame(DVMuxContext *c, AVStream* st, ...@@ -610,7 +610,7 @@ int dv_assemble_frame(DVMuxContext *c, AVStream* st,
if (st->codec.codec_type == CODEC_TYPE_VIDEO) { if (st->codec.codec_type == CODEC_TYPE_VIDEO) {
/* FIXME: we have to have more sensible approach than this one */ /* FIXME: we have to have more sensible approach than this one */
if (c->has_video) 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); dv_inject_video(c, data, *frame);
c->has_video = 1; c->has_video = 1;
...@@ -635,7 +635,7 @@ int dv_assemble_frame(DVMuxContext *c, AVStream* st, ...@@ -635,7 +635,7 @@ int dv_assemble_frame(DVMuxContext *c, AVStream* st,
/* FIXME: we have to have more sensible approach than this one */ /* 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) 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); 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) ...@@ -848,7 +848,7 @@ static int dv_write_header(AVFormatContext *s)
{ {
s->priv_data = dv_init_mux(s); s->priv_data = dv_init_mux(s);
if (!s->priv_data) { 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" "Make sure that you supply exactly two streams:\n"
" video: 25fps or 29.97fps, audio: 2ch/48Khz/PCM\n"); " video: 25fps or 29.97fps, audio: 2ch/48Khz/PCM\n");
return -1; return -1;
......
...@@ -153,7 +153,7 @@ static int dv1394_read_packet(AVFormatContext *context, AVPacket *pkt) ...@@ -153,7 +153,7 @@ static int dv1394_read_packet(AVFormatContext *context, AVPacket *pkt)
* We have to reset :(. * 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_reset(dv);
dv1394_start(dv); dv1394_start(dv);
...@@ -191,7 +191,7 @@ restart_poll: ...@@ -191,7 +191,7 @@ restart_poll:
dv->done = 0; dv->done = 0;
if (s.dropped_frames) { 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); s.dropped_frames);
dv1394_reset(dv); dv1394_reset(dv);
......
...@@ -102,7 +102,7 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -102,7 +102,7 @@ static int flv_read_packet(AVFormatContext *s, AVPacket *pkt)
} else { } else {
skip: skip:
/* skip packet */ /* 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); url_fskip(&s->pb, size);
goto redo; goto redo;
} }
......
...@@ -99,7 +99,7 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) ...@@ -99,7 +99,7 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
} }
if (!(s->video_cap.type & VID_TYPE_CAPTURE)) { 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; goto fail;
} }
...@@ -223,9 +223,9 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap) ...@@ -223,9 +223,9 @@ static int grab_read_header(AVFormatContext *s1, AVFormatParameters *ap)
if (ret < 0) { if (ret < 0) {
if (errno != EAGAIN) { if (errno != EAGAIN) {
fail1: 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 { } 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; goto fail;
} }
...@@ -277,7 +277,7 @@ static int v4l_mm_read_picture(VideoData *s, uint8_t *buf) ...@@ -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; s->gb_buf.frame = (s->gb_frame + 1) % s->gb_buffers.frames;
if (ioctl(s->fd, VIDIOCMCAPTURE, &s->gb_buf) < 0) { if (ioctl(s->fd, VIDIOCMCAPTURE, &s->gb_buf) < 0) {
if (errno == EAGAIN) if (errno == EAGAIN)
fprintf(stderr,"Cannot Sync\n"); av_log(NULL, AV_LOG_ERROR, "Cannot Sync\n");
else else
perror("VIDIOCMCAPTURE"); perror("VIDIOCMCAPTURE");
return -EIO; return -EIO;
...@@ -387,8 +387,8 @@ static int aiw_init(VideoData *s) ...@@ -387,8 +387,8 @@ static int aiw_init(VideoData *s)
if (height == s->video_cap.maxheight*2) s->deint=1; if (height == s->video_cap.maxheight*2) s->deint=1;
if (width == s->video_cap.maxwidth/2) s->halfw=1; if (width == s->video_cap.maxwidth/2) s->halfw=1;
} else { } else {
fprintf(stderr,"\nIncorrect Grab Size Supplied - Supported Sizes Are:\n"); av_log(NULL, AV_LOG_ERROR, "\nIncorrect Grab Size Supplied - Supported Sizes Are:\n");
fprintf(stderr," %dx%d %dx%d %dx%d\n\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,
s->video_cap.maxwidth,s->video_cap.maxheight*2, s->video_cap.maxwidth,s->video_cap.maxheight*2,
s->video_cap.maxwidth/2,s->video_cap.maxheight); s->video_cap.maxwidth/2,s->video_cap.maxheight);
......
...@@ -135,7 +135,7 @@ static int roq_read_header(AVFormatContext *s, ...@@ -135,7 +135,7 @@ static int roq_read_header(AVFormatContext *s,
break; break;
default: 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; return AVERROR_INVALIDDATA;
break; break;
} }
...@@ -268,7 +268,7 @@ static int roq_read_packet(AVFormatContext *s, ...@@ -268,7 +268,7 @@ static int roq_read_packet(AVFormatContext *s,
break; break;
default: 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; return AVERROR_INVALIDDATA;
break; break;
} }
......
...@@ -1531,7 +1531,7 @@ static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -1531,7 +1531,7 @@ static int mov_read_header(AVFormatContext *s, AVFormatParameters *ap)
/* check MOV header */ /* check MOV header */
err = mov_read_default(mov, pb, atom); err = mov_read_default(mov, pb, atom);
if (err<0 || (!mov->found_moov && !mov->found_mdat)) { 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)); err, mov->found_moov, mov->found_mdat, url_ftell(pb));
return -1; return -1;
} }
......
...@@ -773,7 +773,7 @@ static void compute_pts_dts(AVStream *st, int64_t *ppts, int64_t *pdts, ...@@ -773,7 +773,7 @@ static void compute_pts_dts(AVStream *st, int64_t *ppts, int64_t *pdts,
} }
} }
#if 1 #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, pts / 90000.0, dts / 90000.0,
av_get_pict_type_char(st->codec.coded_frame->pict_type)); av_get_pict_type_char(st->codec.coded_frame->pict_type));
#endif #endif
......
...@@ -456,12 +456,12 @@ static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -456,12 +456,12 @@ static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap)
/* main header */ /* main header */
tmp = get_be64(bc); tmp = get_be64(bc);
if (tmp != MAIN_STARTCODE) 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); get_packetheader(nut, bc);
tmp = get_v(bc); tmp = get_v(bc);
if (tmp != 0) 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); nb_streams = get_v(bc);
get_be32(bc); /* checkusm */ get_be32(bc); /* checkusm */
...@@ -481,7 +481,7 @@ static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -481,7 +481,7 @@ static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap)
tmp = get_be64(bc); tmp = get_be64(bc);
if (tmp != STREAM_STARTCODE) 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); get_packetheader(nut, bc);
st = av_new_stream(s, get_v(bc)); st = av_new_stream(s, get_v(bc));
if (!st) if (!st)
...@@ -494,16 +494,16 @@ static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -494,16 +494,16 @@ static int nut_read_header(AVFormatContext *s, AVFormatParameters *ap)
st->codec.codec_type = CODEC_TYPE_VIDEO; st->codec.codec_type = CODEC_TYPE_VIDEO;
st->codec.codec_id = codec_get_bmp_id(tmp); st->codec.codec_id = codec_get_bmp_id(tmp);
if (st->codec.codec_id == CODEC_ID_NONE) if (st->codec.codec_id == CODEC_ID_NONE)
fprintf(stderr, "Unknown codec?!\n"); av_log(s, AV_LOG_ERROR, "Unknown codec?!\n");
break; break;
case 32: case 32:
st->codec.codec_type = CODEC_TYPE_AUDIO; st->codec.codec_type = CODEC_TYPE_AUDIO;
st->codec.codec_id = codec_get_wav_id(tmp); st->codec.codec_id = codec_get_wav_id(tmp);
if (st->codec.codec_id == CODEC_ID_NONE) if (st->codec.codec_id == CODEC_ID_NONE)
fprintf(stderr, "Unknown codec?!\n"); av_log(s, AV_LOG_ERROR, "Unknown codec?!\n");
break; break;
default: default:
fprintf(stderr, "Unknown stream class (%d)\n", class); av_log(s, AV_LOG_ERROR, "Unknown stream class (%d)\n", class);
return -1; return -1;
} }
s->bit_rate += get_v(bc); s->bit_rate += get_v(bc);
...@@ -565,12 +565,12 @@ static int nut_read_packet(AVFormatContext *s, AVPacket *pkt) ...@@ -565,12 +565,12 @@ static int nut_read_packet(AVFormatContext *s, AVPacket *pkt)
tmp = get_byte(bc); /* flags */ tmp = get_byte(bc); /* flags */
} }
else 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); get_packetheader(nut, bc);
#if 0 #if 0
if (((tmp & 0x60)>>5) > 3) /* priority <= 3 */ if (((tmp & 0x60)>>5) > 3) /* priority <= 3 */
fprintf(stderr, "sanity check failed!\n"); av_log(s, AV_LOG_ERROR, "sanity check failed!\n");
#endif #endif
id = get_v(bc); id = get_v(bc);
if ((tmp & 0x8) >> 3) if ((tmp & 0x8) >> 3)
......
...@@ -123,11 +123,11 @@ static void dump(unsigned char *buf,size_t len) ...@@ -123,11 +123,11 @@ static void dump(unsigned char *buf,size_t len)
{ {
int i; int i;
for(i=0;i<len;i++) { for(i=0;i<len;i++) {
if ((i&15)==0) printf("%04x ",i); if ((i&15)==0) av_log(NULL, AV_LOG_DEBUG, "%04x ",i);
printf("%02x ",buf[i]); av_log(NULL, AV_LOG_DEBUG, "%02x ",buf[i]);
if ((i&15)==15) printf("\n"); 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, static int str_read_header(AVFormatContext *s,
...@@ -239,11 +239,11 @@ static int str_read_header(AVFormatContext *s, ...@@ -239,11 +239,11 @@ static int str_read_header(AVFormatContext *s,
} }
if (str->video_channel != -1) 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].width,
str->channels[str->video_channel].height,str->channels[str->video_channel].video_stream_index); str->channels[str->video_channel].height,str->channels[str->video_channel].video_stream_index);
if (str->audio_channel != -1) 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->audio_channel,
str->channels[str->audio_channel].sample_rate, str->channels[str->audio_channel].sample_rate,
str->channels[str->audio_channel].channels, str->channels[str->audio_channel].channels,
......
...@@ -636,7 +636,7 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -636,7 +636,7 @@ static int rm_read_header(AVFormatContext *s, AVFormatParameters *ap)
} else { } else {
if (get_le32(pb) != MKTAG('V', 'I', 'D', 'O')) { if (get_le32(pb) != MKTAG('V', 'I', 'D', 'O')) {
fail1: fail1:
fprintf(stderr, "Unsupported video codec\n"); av_log(&st->codec, AV_LOG_ERROR, "Unsupported video codec\n");
goto fail; goto fail;
} }
st->codec.codec_tag = get_le32(pb); st->codec.codec_tag = get_le32(pb);
......
...@@ -301,7 +301,7 @@ int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt, ...@@ -301,7 +301,7 @@ int rtp_parse_packet(RTPDemuxContext *s, AVPacket *pkt,
return -1; return -1;
#if defined(DEBUG) || 1 #if defined(DEBUG) || 1
if (seq != ((s->seq + 1) & 0xffff)) { 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)); payload_type, seq, ((s->seq + 1) & 0xffff));
} }
s->seq = seq; s->seq = seq;
......
...@@ -1050,7 +1050,7 @@ static int rtsp_read_play(AVFormatContext *s) ...@@ -1050,7 +1050,7 @@ static int rtsp_read_play(AVFormatContext *s)
RTSPHeader reply1, *reply = &reply1; RTSPHeader reply1, *reply = &reply1;
char cmd[1024]; 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) { if (rt->state == RTSP_STATE_PAUSED) {
snprintf(cmd, sizeof(cmd), snprintf(cmd, sizeof(cmd),
......
...@@ -341,7 +341,7 @@ static int swf_write_header(AVFormatContext *s) ...@@ -341,7 +341,7 @@ static int swf_write_header(AVFormatContext *s)
if ( enc->codec_id == CODEC_ID_FLV1 || enc->codec_id == CODEC_ID_MJPEG ) { if ( enc->codec_id == CODEC_ID_FLV1 || enc->codec_id == CODEC_ID_MJPEG ) {
video_enc = enc; video_enc = enc;
} else { } 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; return -1;
} }
} }
...@@ -479,7 +479,7 @@ static int swf_write_video(AVFormatContext *s, ...@@ -479,7 +479,7 @@ static int swf_write_video(AVFormatContext *s,
/* Flash Player limit */ /* Flash Player limit */
if ( swf->swf_frame_number == 16000 ) { 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 */ /* Store video data in queue */
...@@ -680,7 +680,7 @@ static int swf_write_audio(AVFormatContext *s, ...@@ -680,7 +680,7 @@ static int swf_write_audio(AVFormatContext *s,
/* Flash Player limit */ /* Flash Player limit */
if ( swf->swf_frame_number == 16000 ) { 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 ) { if (enc->codec_id == CODEC_ID_MP3 ) {
...@@ -825,7 +825,7 @@ static int swf_read_header(AVFormatContext *s, AVFormatParameters *ap) ...@@ -825,7 +825,7 @@ static int swf_read_header(AVFormatContext *s, AVFormatParameters *ap)
} }
break; break;
} }
fprintf(stderr, "No media found in SWF\n"); av_log(s, AV_LOG_ERROR, "No media found in SWF\n");
return -EIO; return -EIO;
} }
if ( tag == TAG_VIDEOSTREAM && !vst) { if ( tag == TAG_VIDEOSTREAM && !vst) {
......
...@@ -300,6 +300,26 @@ AVInputFormat *av_probe_input_format(AVProbeData *pd, int is_opened) ...@@ -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. * 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, int av_open_input_stream(AVFormatContext **ic_ptr,
ByteIOContext *pb, const char *filename, ByteIOContext *pb, const char *filename,
AVInputFormat *fmt, AVFormatParameters *ap) AVInputFormat *fmt, AVFormatParameters *ap)
...@@ -307,7 +327,7 @@ int av_open_input_stream(AVFormatContext **ic_ptr, ...@@ -307,7 +327,7 @@ int av_open_input_stream(AVFormatContext **ic_ptr,
int err; int err;
AVFormatContext *ic; AVFormatContext *ic;
ic = av_mallocz(sizeof(AVFormatContext)); ic = av_alloc_format_context();
if (!ic) { if (!ic) {
err = AVERROR_NOMEM; err = AVERROR_NOMEM;
goto fail; goto fail;
...@@ -1725,13 +1745,13 @@ void dump_format(AVFormatContext *ic, ...@@ -1725,13 +1745,13 @@ void dump_format(AVFormatContext *ic,
int i, flags; int i, flags;
char buf[256]; 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", 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) {
fprintf(stderr, " Duration: "); av_log(ic, 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;
...@@ -1740,23 +1760,23 @@ void dump_format(AVFormatContext *ic, ...@@ -1740,23 +1760,23 @@ void dump_format(AVFormatContext *ic,
secs %= 60; secs %= 60;
hours = mins / 60; hours = mins / 60;
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); (10 * us) / AV_TIME_BASE);
} else { } 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) { 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 { } 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++) { 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);
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 */ /* 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)
...@@ -1764,9 +1784,9 @@ void dump_format(AVFormatContext *ic, ...@@ -1764,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) {
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);
} }
} }
......
...@@ -230,7 +230,7 @@ static int wc3_read_header(AVFormatContext *s, ...@@ -230,7 +230,7 @@ static int wc3_read_header(AVFormatContext *s,
break; break;
default: 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],
preamble[0], preamble[1], preamble[2], preamble[3]); preamble[0], preamble[1], preamble[2], preamble[3]);
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
...@@ -352,12 +352,12 @@ static int wc3_read_packet(AVFormatContext *s, ...@@ -352,12 +352,12 @@ static int wc3_read_packet(AVFormatContext *s,
ret = -EIO; ret = -EIO;
else { else {
int i = 0; int i = 0;
printf ("Subtitle time!\n"); av_log (s, AV_LOG_DEBUG, "Subtitle time!\n");
printf (" inglish: %s\n", &text[i + 1]); av_log (s, AV_LOG_DEBUG, " inglish: %s\n", &text[i + 1]);
i += 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; i += text[i] + 1;
printf (" fronsay: %s\n", &text[i + 1]); av_log (s, AV_LOG_DEBUG, " fronsay: %s\n", &text[i + 1]);
} }
#endif #endif
break; break;
...@@ -379,7 +379,7 @@ static int wc3_read_packet(AVFormatContext *s, ...@@ -379,7 +379,7 @@ static int wc3_read_packet(AVFormatContext *s,
break; break;
default: 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],
preamble[0], preamble[1], preamble[2], preamble[3]); preamble[0], preamble[1], preamble[2], preamble[3]);
ret = AVERROR_INVALIDDATA; ret = AVERROR_INVALIDDATA;
......
...@@ -309,7 +309,7 @@ static int wsvqa_read_header(AVFormatContext *s, ...@@ -309,7 +309,7 @@ static int wsvqa_read_header(AVFormatContext *s,
break; break;
default: 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[0], scratch[1],
scratch[2], scratch[3]); scratch[2], scratch[3]);
break; break;
......
...@@ -77,7 +77,7 @@ static int yuv4_write_packet(AVFormatContext *s, int stream_index, ...@@ -77,7 +77,7 @@ static int yuv4_write_packet(AVFormatContext *s, int stream_index,
if (*first_pkt) { if (*first_pkt) {
*first_pkt = 0; *first_pkt = 0;
if (yuv4_generate_header(s, buf2) < 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; return -EIO;
} else { } else {
put_buffer(pb, buf2, strlen(buf2)); put_buffer(pb, buf2, strlen(buf2));
...@@ -122,10 +122,10 @@ static int yuv4_write_header(AVFormatContext *s) ...@@ -122,10 +122,10 @@ static int yuv4_write_header(AVFormatContext *s)
return -EIO; return -EIO;
if (s->streams[0]->codec.pix_fmt == PIX_FMT_YUV411P) { 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) { 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; return -EIO;
} }
......
...@@ -408,7 +408,7 @@ int main(int argc, char **argv) ...@@ -408,7 +408,7 @@ int main(int argc, char **argv)
} }
/* allocate the output media context */ /* allocate the output media context */
oc = av_mallocz(sizeof(AVFormatContext)); oc = av_alloc_format_context();
if (!oc) { if (!oc) {
fprintf(stderr, "Memory error\n"); fprintf(stderr, "Memory error\n");
exit(1); exit(1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment