Mercurial > libavformat.hg
comparison utils.c @ 370:845f9de2c883 libavformat
av_log() patch by (Michel Bardiaux <mbardiaux at peaktime dot be>)
| author | michael |
|---|---|
| date | Wed, 03 Mar 2004 15:41:21 +0000 |
| parents | 3fca8e9142a4 |
| children | b0e50e10472c |
comparison
equal
deleted
inserted
replaced
| 369:b2a0f47067ed | 370:845f9de2c883 |
|---|---|
| 298 /* input media file */ | 298 /* input media file */ |
| 299 | 299 |
| 300 /** | 300 /** |
| 301 * open a media file from an IO stream. 'fmt' must be specified. | 301 * open a media file from an IO stream. 'fmt' must be specified. |
| 302 */ | 302 */ |
| 303 | |
| 304 static const char* format_to_name(void* class_ptr) | |
| 305 { | |
| 306 AVFormatContext* fc = (AVFormatContext*) class_ptr; | |
| 307 if(fc->iformat) return fc->iformat->name; | |
| 308 else if(fc->oformat) return fc->oformat->name; | |
| 309 else return "NULL"; | |
| 310 } | |
| 311 | |
| 312 static const AVClass av_format_context_class = { "AVFormatContext", format_to_name }; | |
| 313 | |
| 314 AVFormatContext *av_alloc_format_context(void) | |
| 315 { | |
| 316 AVFormatContext *ic; | |
| 317 ic = av_mallocz(sizeof(AVFormatContext)); | |
| 318 if (!ic) return ic; | |
| 319 ic->class = av_format_context_class; | |
| 320 return ic; | |
| 321 } | |
| 322 | |
| 303 int av_open_input_stream(AVFormatContext **ic_ptr, | 323 int av_open_input_stream(AVFormatContext **ic_ptr, |
| 304 ByteIOContext *pb, const char *filename, | 324 ByteIOContext *pb, const char *filename, |
| 305 AVInputFormat *fmt, AVFormatParameters *ap) | 325 AVInputFormat *fmt, AVFormatParameters *ap) |
| 306 { | 326 { |
| 307 int err; | 327 int err; |
| 308 AVFormatContext *ic; | 328 AVFormatContext *ic; |
| 309 | 329 |
| 310 ic = av_mallocz(sizeof(AVFormatContext)); | 330 ic = av_alloc_format_context(); |
| 311 if (!ic) { | 331 if (!ic) { |
| 312 err = AVERROR_NOMEM; | 332 err = AVERROR_NOMEM; |
| 313 goto fail; | 333 goto fail; |
| 314 } | 334 } |
| 315 ic->iformat = fmt; | 335 ic->iformat = fmt; |
| 1723 int is_output) | 1743 int is_output) |
| 1724 { | 1744 { |
| 1725 int i, flags; | 1745 int i, flags; |
| 1726 char buf[256]; | 1746 char buf[256]; |
| 1727 | 1747 |
| 1728 fprintf(stderr, "%s #%d, %s, %s '%s':\n", | 1748 av_log(ic, AV_LOG_DEBUG, "%s #%d, %s, %s '%s':\n", |
| 1729 is_output ? "Output" : "Input", | 1749 is_output ? "Output" : "Input", |
| 1730 index, | 1750 index, |
| 1731 is_output ? ic->oformat->name : ic->iformat->name, | 1751 is_output ? ic->oformat->name : ic->iformat->name, |
| 1732 is_output ? "to" : "from", url); | 1752 is_output ? "to" : "from", url); |
| 1733 if (!is_output) { | 1753 if (!is_output) { |
| 1734 fprintf(stderr, " Duration: "); | 1754 av_log(ic, AV_LOG_DEBUG, " Duration: "); |
| 1735 if (ic->duration != AV_NOPTS_VALUE) { | 1755 if (ic->duration != AV_NOPTS_VALUE) { |
| 1736 int hours, mins, secs, us; | 1756 int hours, mins, secs, us; |
| 1737 secs = ic->duration / AV_TIME_BASE; | 1757 secs = ic->duration / AV_TIME_BASE; |
| 1738 us = ic->duration % AV_TIME_BASE; | 1758 us = ic->duration % AV_TIME_BASE; |
| 1739 mins = secs / 60; | 1759 mins = secs / 60; |
| 1740 secs %= 60; | 1760 secs %= 60; |
| 1741 hours = mins / 60; | 1761 hours = mins / 60; |
| 1742 mins %= 60; | 1762 mins %= 60; |
| 1743 fprintf(stderr, "%02d:%02d:%02d.%01d", hours, mins, secs, | 1763 av_log(ic, AV_LOG_DEBUG, "%02d:%02d:%02d.%01d", hours, mins, secs, |
| 1744 (10 * us) / AV_TIME_BASE); | 1764 (10 * us) / AV_TIME_BASE); |
| 1745 } else { | 1765 } else { |
| 1746 fprintf(stderr, "N/A"); | 1766 av_log(ic, AV_LOG_DEBUG, "N/A"); |
| 1747 } | 1767 } |
| 1748 fprintf(stderr, ", bitrate: "); | 1768 av_log(ic, AV_LOG_DEBUG, ", bitrate: "); |
| 1749 if (ic->bit_rate) { | 1769 if (ic->bit_rate) { |
| 1750 fprintf(stderr,"%d kb/s", ic->bit_rate / 1000); | 1770 av_log(ic, AV_LOG_DEBUG,"%d kb/s", ic->bit_rate / 1000); |
| 1751 } else { | 1771 } else { |
| 1752 fprintf(stderr, "N/A"); | 1772 av_log(ic, AV_LOG_DEBUG, "N/A"); |
| 1753 } | 1773 } |
| 1754 fprintf(stderr, "\n"); | 1774 av_log(ic, AV_LOG_DEBUG, "\n"); |
| 1755 } | 1775 } |
| 1756 for(i=0;i<ic->nb_streams;i++) { | 1776 for(i=0;i<ic->nb_streams;i++) { |
| 1757 AVStream *st = ic->streams[i]; | 1777 AVStream *st = ic->streams[i]; |
| 1758 avcodec_string(buf, sizeof(buf), &st->codec, is_output); | 1778 avcodec_string(buf, sizeof(buf), &st->codec, is_output); |
| 1759 fprintf(stderr, " Stream #%d.%d", index, i); | 1779 av_log(ic, AV_LOG_DEBUG, " Stream #%d.%d", index, i); |
| 1760 /* the pid is an important information, so we display it */ | 1780 /* the pid is an important information, so we display it */ |
| 1761 /* XXX: add a generic system */ | 1781 /* XXX: add a generic system */ |
| 1762 if (is_output) | 1782 if (is_output) |
| 1763 flags = ic->oformat->flags; | 1783 flags = ic->oformat->flags; |
| 1764 else | 1784 else |
| 1765 flags = ic->iformat->flags; | 1785 flags = ic->iformat->flags; |
| 1766 if (flags & AVFMT_SHOW_IDS) { | 1786 if (flags & AVFMT_SHOW_IDS) { |
| 1767 fprintf(stderr, "[0x%x]", st->id); | 1787 av_log(ic, AV_LOG_DEBUG, "[0x%x]", st->id); |
| 1768 } | 1788 } |
| 1769 fprintf(stderr, ": %s\n", buf); | 1789 av_log(ic, AV_LOG_DEBUG, ": %s\n", buf); |
| 1770 } | 1790 } |
| 1771 } | 1791 } |
| 1772 | 1792 |
| 1773 typedef struct { | 1793 typedef struct { |
| 1774 const char *abv; | 1794 const char *abv; |
