Mercurial > libavformat.hg
changeset 1908:174083eafc6c libavformat
Introduce two new logging functions av_hex_dump_log() and av_pkt_dump_log()
which use av_log() for logging instead of fprintf().
author | takis |
---|---|
date | Mon, 12 Mar 2007 14:17:26 +0000 |
parents | b33db97089ba |
children | 663139d56669 |
files | avformat.h mpegts.c utils.c |
diffstat | 3 files changed, 89 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/avformat.h Mon Mar 12 12:36:41 2007 +0000 +++ b/avformat.h Mon Mar 12 14:17:26 2007 +0000 @@ -444,21 +444,51 @@ const char *filename, const char *mime_type, enum CodecType type); /** - * Print nice hexa dump of a buffer - * @param f stream for output + * Send a nice hexadecimal dump of a buffer to the specified file stream. + * + * @param f The file stream pointer where the dump should be sent to. * @param buf buffer * @param size buffer size + * + * @see av_hex_dump_log, av_pkt_dump, av_pkt_dump_log */ void av_hex_dump(FILE *f, uint8_t *buf, int size); /** - * Print on 'f' a nice dump of a packet - * @param f stream for output + * Send a nice hexadecimal dump of a buffer to the log. + * + * @param avcl A pointer to an arbitrary struct of which the first field is a + * pointer to an AVClass struct. + * @param level The importance level of the message, lower values signifying + * higher importance. + * @param buf buffer + * @param size buffer size + * + * @see av_hex_dump, av_pkt_dump, av_pkt_dump_log + */ +void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size); + +/** + * Send a nice dump of a packet to the specified file stream. + * + * @param f The file stream pointer where the dump should be sent to. * @param pkt packet to dump * @param dump_payload true if the payload must be displayed too */ void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload); +/** + * Send a nice dump of a packet to the log. + * + * @param avcl A pointer to an arbitrary struct of which the first field is a + * pointer to an AVClass struct. + * @param level The importance level of the message, lower values signifying + * higher importance. + * @param pkt packet to dump + * @param dump_payload true if the payload must be displayed too + */ +void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload); + void av_register_all(void); /** codec tag <-> codec id */
--- a/mpegts.c Mon Mar 12 12:36:41 2007 +0000 +++ b/mpegts.c Mon Mar 12 14:17:26 2007 +0000 @@ -401,7 +401,7 @@ #ifdef DEBUG_SI av_log(ts->stream, AV_LOG_DEBUG, "PMT: len %i\n", section_len); - av_hex_dump(stdout, (uint8_t *)section, section_len); + av_hex_dump_log(ts->stream, AV_LOG_DEBUG, (uint8_t *)section, section_len); #endif p_end = section + section_len - 4; p = section; @@ -545,7 +545,7 @@ #ifdef DEBUG_SI av_log(ts->stream, AV_LOG_DEBUG, "PAT:\n"); - av_hex_dump(stdout, (uint8_t *)section, section_len); + av_hex_dump_log(ts->stream, AV_LOG_DEBUG, (uint8_t *)section, section_len); #endif p_end = section + section_len - 4; p = section; @@ -594,7 +594,7 @@ #ifdef DEBUG_SI av_log(ts->stream, AV_LOG_DEBUG, "PAT:\n"); - av_hex_dump(stdout, (uint8_t *)section, section_len); + av_hex_dump_log(ts->stream, AV_LOG_DEBUG, (uint8_t *)section, section_len); #endif p_end = section + section_len - 4; p = section; @@ -655,7 +655,7 @@ #ifdef DEBUG_SI av_log(ts->stream, AV_LOG_DEBUG, "SDT:\n"); - av_hex_dump(stdout, (uint8_t *)section, section_len); + av_hex_dump_log(ts->stream, AV_LOG_DEBUG, (uint8_t *)section, section_len); #endif p_end = section + section_len - 4; @@ -806,7 +806,7 @@ /* we got all the PES or section header. We can now decide */ #if 0 - av_hex_dump(pes->header, pes->data_index); + av_hex_dump_log(pes->stream, AV_LOG_DEBUG, pes->header, pes->data_index); #endif if (pes->header[0] == 0x00 && pes->header[1] == 0x00 && pes->header[2] == 0x01) {
--- a/utils.c Mon Mar 12 12:36:41 2007 +0000 +++ b/utils.c Mon Mar 12 14:17:26 2007 +0000 @@ -2702,54 +2702,78 @@ return -1; } -void av_hex_dump(FILE *f, uint8_t *buf, int size) +static void hex_dump_internal(void *avcl, FILE *f, int level, uint8_t *buf, int size) { int len, i, j, c; +#define PRINT(...) do { if (!f) av_log(avcl, level, __VA_ARGS__); else fprintf(f, __VA_ARGS__); } while(0) for(i=0;i<size;i+=16) { len = size - i; if (len > 16) len = 16; - fprintf(f, "%08x ", i); + PRINT("%08x ", i); for(j=0;j<16;j++) { if (j < len) - fprintf(f, " %02x", buf[i+j]); + PRINT(" %02x", buf[i+j]); else - fprintf(f, " "); + PRINT(" "); } - fprintf(f, " "); + PRINT(" "); for(j=0;j<len;j++) { c = buf[i+j]; if (c < ' ' || c > '~') c = '.'; - fprintf(f, "%c", c); + PRINT("%c", c); } - fprintf(f, "\n"); + PRINT("\n"); } +#undef PRINT +} + +void av_hex_dump(FILE *f, uint8_t *buf, int size) +{ + hex_dump_internal(NULL, f, 0, buf, size); +} + +void av_hex_dump_log(void *avcl, int level, uint8_t *buf, int size) +{ + hex_dump_internal(avcl, NULL, level, buf, size); } //FIXME needs to know the time_base +static void pkt_dump_internal(void *avcl, FILE *f, int level, AVPacket *pkt, int dump_payload) +{ +#define PRINT(...) do { if (!f) av_log(avcl, level, __VA_ARGS__); else fprintf(f, __VA_ARGS__); } while(0) + PRINT("stream #%d:\n", pkt->stream_index); + PRINT(" keyframe=%d\n", ((pkt->flags & PKT_FLAG_KEY) != 0)); + PRINT(" duration=%0.3f\n", (double)pkt->duration / AV_TIME_BASE); + /* DTS is _always_ valid after av_read_frame() */ + PRINT(" dts="); + if (pkt->dts == AV_NOPTS_VALUE) + PRINT("N/A"); + else + PRINT("%0.3f", (double)pkt->dts / AV_TIME_BASE); + /* PTS may be not known if B frames are present */ + PRINT(" pts="); + if (pkt->pts == AV_NOPTS_VALUE) + PRINT("N/A"); + else + PRINT("%0.3f", (double)pkt->pts / AV_TIME_BASE); + PRINT("\n"); + PRINT(" size=%d\n", pkt->size); +#undef PRINT + if (dump_payload) + av_hex_dump(f, pkt->data, pkt->size); +} + void av_pkt_dump(FILE *f, AVPacket *pkt, int dump_payload) { - fprintf(f, "stream #%d:\n", pkt->stream_index); - fprintf(f, " keyframe=%d\n", ((pkt->flags & PKT_FLAG_KEY) != 0)); - fprintf(f, " duration=%0.3f\n", (double)pkt->duration / AV_TIME_BASE); - /* DTS is _always_ valid after av_read_frame() */ - fprintf(f, " dts="); - if (pkt->dts == AV_NOPTS_VALUE) - fprintf(f, "N/A"); - else - fprintf(f, "%0.3f", (double)pkt->dts / AV_TIME_BASE); - /* PTS may be not known if B frames are present */ - fprintf(f, " pts="); - if (pkt->pts == AV_NOPTS_VALUE) - fprintf(f, "N/A"); - else - fprintf(f, "%0.3f", (double)pkt->pts / AV_TIME_BASE); - fprintf(f, "\n"); - fprintf(f, " size=%d\n", pkt->size); - if (dump_payload) - av_hex_dump(f, pkt->data, pkt->size); + pkt_dump_internal(NULL, f, 0, pkt, dump_payload); +} + +void av_pkt_dump_log(void *avcl, int level, AVPacket *pkt, int dump_payload) +{ + pkt_dump_internal(avcl, NULL, level, pkt, dump_payload); } void url_split(char *proto, int proto_size,