LCOV - code coverage report
Current view: top level - src/libavformat - dump.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 220 401 54.9 %
Date: 2017-09-22 00:04:37 Functions: 11 21 52.4 %

          Line data    Source code
       1             : /*
       2             :  * Various pretty-printing functions for use within FFmpeg
       3             :  * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
       4             :  *
       5             :  * This file is part of FFmpeg.
       6             :  *
       7             :  * FFmpeg is free software; you can redistribute it and/or
       8             :  * modify it under the terms of the GNU Lesser General Public
       9             :  * License as published by the Free Software Foundation; either
      10             :  * version 2.1 of the License, or (at your option) any later version.
      11             :  *
      12             :  * FFmpeg is distributed in the hope that it will be useful,
      13             :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15             :  * Lesser General Public License for more details.
      16             :  *
      17             :  * You should have received a copy of the GNU Lesser General Public
      18             :  * License along with FFmpeg; if not, write to the Free Software
      19             :  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
      20             :  */
      21             : 
      22             : #include <stdio.h>
      23             : #include <stdint.h>
      24             : 
      25             : #include "libavutil/channel_layout.h"
      26             : #include "libavutil/display.h"
      27             : #include "libavutil/intreadwrite.h"
      28             : #include "libavutil/log.h"
      29             : #include "libavutil/mastering_display_metadata.h"
      30             : #include "libavutil/mathematics.h"
      31             : #include "libavutil/opt.h"
      32             : #include "libavutil/avstring.h"
      33             : #include "libavutil/replaygain.h"
      34             : #include "libavutil/spherical.h"
      35             : #include "libavutil/stereo3d.h"
      36             : 
      37             : #include "avformat.h"
      38             : 
      39             : #define HEXDUMP_PRINT(...)                                                    \
      40             :     do {                                                                      \
      41             :         if (!f)                                                               \
      42             :             av_log(avcl, level, __VA_ARGS__);                                 \
      43             :         else                                                                  \
      44             :             fprintf(f, __VA_ARGS__);                                          \
      45             :     } while (0)
      46             : 
      47           1 : static void hex_dump_internal(void *avcl, FILE *f, int level,
      48             :                               const uint8_t *buf, int size)
      49             : {
      50             :     int len, i, j, c;
      51             : 
      52           3 :     for (i = 0; i < size; i += 16) {
      53           2 :         len = size - i;
      54           2 :         if (len > 16)
      55           1 :             len = 16;
      56           2 :         HEXDUMP_PRINT("%08x ", i);
      57          34 :         for (j = 0; j < 16; j++) {
      58          32 :             if (j < len)
      59          24 :                 HEXDUMP_PRINT(" %02x", buf[i + j]);
      60             :             else
      61           8 :                 HEXDUMP_PRINT("   ");
      62             :         }
      63           2 :         HEXDUMP_PRINT(" ");
      64          26 :         for (j = 0; j < len; j++) {
      65          24 :             c = buf[i + j];
      66          24 :             if (c < ' ' || c > '~')
      67          15 :                 c = '.';
      68          24 :             HEXDUMP_PRINT("%c", c);
      69             :         }
      70           2 :         HEXDUMP_PRINT("\n");
      71             :     }
      72           1 : }
      73             : 
      74           0 : void av_hex_dump(FILE *f, const uint8_t *buf, int size)
      75             : {
      76           0 :     hex_dump_internal(NULL, f, 0, buf, size);
      77           0 : }
      78             : 
      79           1 : void av_hex_dump_log(void *avcl, int level, const uint8_t *buf, int size)
      80             : {
      81           1 :     hex_dump_internal(avcl, NULL, level, buf, size);
      82           1 : }
      83             : 
      84           0 : static void pkt_dump_internal(void *avcl, FILE *f, int level, const AVPacket *pkt,
      85             :                               int dump_payload, AVRational time_base)
      86             : {
      87           0 :     HEXDUMP_PRINT("stream #%d:\n", pkt->stream_index);
      88           0 :     HEXDUMP_PRINT("  keyframe=%d\n", (pkt->flags & AV_PKT_FLAG_KEY) != 0);
      89           0 :     HEXDUMP_PRINT("  duration=%0.3f\n", pkt->duration * av_q2d(time_base));
      90             :     /* DTS is _always_ valid after av_read_frame() */
      91           0 :     HEXDUMP_PRINT("  dts=");
      92           0 :     if (pkt->dts == AV_NOPTS_VALUE)
      93           0 :         HEXDUMP_PRINT("N/A");
      94             :     else
      95           0 :         HEXDUMP_PRINT("%0.3f", pkt->dts * av_q2d(time_base));
      96             :     /* PTS may not be known if B-frames are present. */
      97           0 :     HEXDUMP_PRINT("  pts=");
      98           0 :     if (pkt->pts == AV_NOPTS_VALUE)
      99           0 :         HEXDUMP_PRINT("N/A");
     100             :     else
     101           0 :         HEXDUMP_PRINT("%0.3f", pkt->pts * av_q2d(time_base));
     102           0 :     HEXDUMP_PRINT("\n");
     103           0 :     HEXDUMP_PRINT("  size=%d\n", pkt->size);
     104           0 :     if (dump_payload)
     105           0 :         hex_dump_internal(avcl, f, level, pkt->data, pkt->size);
     106           0 : }
     107             : 
     108           0 : void av_pkt_dump2(FILE *f, const AVPacket *pkt, int dump_payload, const AVStream *st)
     109             : {
     110           0 :     pkt_dump_internal(NULL, f, 0, pkt, dump_payload, st->time_base);
     111           0 : }
     112             : 
     113           0 : void av_pkt_dump_log2(void *avcl, int level, const AVPacket *pkt, int dump_payload,
     114             :                       const AVStream *st)
     115             : {
     116           0 :     pkt_dump_internal(avcl, NULL, level, pkt, dump_payload, st->time_base);
     117           0 : }
     118             : 
     119             : 
     120       29122 : static void print_fps(double d, const char *postfix)
     121             : {
     122       29122 :     uint64_t v = lrintf(d * 100);
     123       29122 :     if (!v)
     124           0 :         av_log(NULL, AV_LOG_INFO, "%1.4f %s", d, postfix);
     125       29122 :     else if (v % 100)
     126        2317 :         av_log(NULL, AV_LOG_INFO, "%3.2f %s", d, postfix);
     127       26805 :     else if (v % (100 * 1000))
     128       25393 :         av_log(NULL, AV_LOG_INFO, "%1.0f %s", d, postfix);
     129             :     else
     130        1412 :         av_log(NULL, AV_LOG_INFO, "%1.0fk %s", d / 1000, postfix);
     131       29122 : }
     132             : 
     133       21886 : static void dump_metadata(void *ctx, AVDictionary *m, const char *indent)
     134             : {
     135       21886 :     if (m && !(av_dict_count(m) == 1 && av_dict_get(m, "language", NULL, 0))) {
     136        8064 :         AVDictionaryEntry *tag = NULL;
     137             : 
     138        8064 :         av_log(ctx, AV_LOG_INFO, "%sMetadata:\n", indent);
     139       29793 :         while ((tag = av_dict_get(m, "", tag, AV_DICT_IGNORE_SUFFIX)))
     140       13665 :             if (strcmp("language", tag->key)) {
     141       12669 :                 const char *p = tag->value;
     142       12669 :                 av_log(ctx, AV_LOG_INFO,
     143             :                        "%s  %-16s: ", indent, tag->key);
     144       38230 :                 while (*p) {
     145             :                     char tmp[256];
     146       12892 :                     size_t len = strcspn(p, "\x8\xa\xb\xc\xd");
     147       12892 :                     av_strlcpy(tmp, p, FFMIN(sizeof(tmp), len+1));
     148       12892 :                     av_log(ctx, AV_LOG_INFO, "%s", tmp);
     149       12892 :                     p += len;
     150       12892 :                     if (*p == 0xd) av_log(ctx, AV_LOG_INFO, " ");
     151       12892 :                     if (*p == 0xa) av_log(ctx, AV_LOG_INFO, "\n%s  %-16s: ", indent, "");
     152       12892 :                     if (*p) p++;
     153             :                 }
     154       12669 :                 av_log(ctx, AV_LOG_INFO, "\n");
     155             :             }
     156             :     }
     157       21886 : }
     158             : 
     159             : /* param change side data*/
     160           0 : static void dump_paramchange(void *ctx, AVPacketSideData *sd)
     161             : {
     162           0 :     int size = sd->size;
     163           0 :     const uint8_t *data = sd->data;
     164             :     uint32_t flags, channels, sample_rate, width, height;
     165             :     uint64_t layout;
     166             : 
     167           0 :     if (!data || sd->size < 4)
     168             :         goto fail;
     169             : 
     170           0 :     flags = AV_RL32(data);
     171           0 :     data += 4;
     172           0 :     size -= 4;
     173             : 
     174           0 :     if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) {
     175           0 :         if (size < 4)
     176           0 :             goto fail;
     177           0 :         channels = AV_RL32(data);
     178           0 :         data += 4;
     179           0 :         size -= 4;
     180           0 :         av_log(ctx, AV_LOG_INFO, "channel count %"PRIu32", ", channels);
     181             :     }
     182           0 :     if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT) {
     183           0 :         if (size < 8)
     184           0 :             goto fail;
     185           0 :         layout = AV_RL64(data);
     186           0 :         data += 8;
     187           0 :         size -= 8;
     188           0 :         av_log(ctx, AV_LOG_INFO,
     189             :                "channel layout: %s, ", av_get_channel_name(layout));
     190             :     }
     191           0 :     if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) {
     192           0 :         if (size < 4)
     193           0 :             goto fail;
     194           0 :         sample_rate = AV_RL32(data);
     195           0 :         data += 4;
     196           0 :         size -= 4;
     197           0 :         av_log(ctx, AV_LOG_INFO, "sample_rate %"PRIu32", ", sample_rate);
     198             :     }
     199           0 :     if (flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS) {
     200           0 :         if (size < 8)
     201           0 :             goto fail;
     202           0 :         width = AV_RL32(data);
     203           0 :         data += 4;
     204           0 :         size -= 4;
     205           0 :         height = AV_RL32(data);
     206           0 :         data += 4;
     207           0 :         size -= 4;
     208           0 :         av_log(ctx, AV_LOG_INFO, "width %"PRIu32" height %"PRIu32, width, height);
     209             :     }
     210             : 
     211           0 :     return;
     212           0 : fail:
     213           0 :     av_log(ctx, AV_LOG_INFO, "unknown param");
     214             : }
     215             : 
     216             : /* replaygain side data*/
     217           0 : static void print_gain(void *ctx, const char *str, int32_t gain)
     218             : {
     219           0 :     av_log(ctx, AV_LOG_INFO, "%s - ", str);
     220           0 :     if (gain == INT32_MIN)
     221           0 :         av_log(ctx, AV_LOG_INFO, "unknown");
     222             :     else
     223           0 :         av_log(ctx, AV_LOG_INFO, "%f", gain / 100000.0f);
     224           0 :     av_log(ctx, AV_LOG_INFO, ", ");
     225           0 : }
     226             : 
     227           0 : static void print_peak(void *ctx, const char *str, uint32_t peak)
     228             : {
     229           0 :     av_log(ctx, AV_LOG_INFO, "%s - ", str);
     230           0 :     if (!peak)
     231           0 :         av_log(ctx, AV_LOG_INFO, "unknown");
     232             :     else
     233           0 :         av_log(ctx, AV_LOG_INFO, "%f", (float) peak / UINT32_MAX);
     234           0 :     av_log(ctx, AV_LOG_INFO, ", ");
     235           0 : }
     236             : 
     237           0 : static void dump_replaygain(void *ctx, AVPacketSideData *sd)
     238             : {
     239             :     AVReplayGain *rg;
     240             : 
     241           0 :     if (sd->size < sizeof(*rg)) {
     242           0 :         av_log(ctx, AV_LOG_INFO, "invalid data");
     243           0 :         return;
     244             :     }
     245           0 :     rg = (AVReplayGain*)sd->data;
     246             : 
     247           0 :     print_gain(ctx, "track gain", rg->track_gain);
     248           0 :     print_peak(ctx, "track peak", rg->track_peak);
     249           0 :     print_gain(ctx, "album gain", rg->album_gain);
     250           0 :     print_peak(ctx, "album peak", rg->album_peak);
     251             : }
     252             : 
     253         424 : static void dump_stereo3d(void *ctx, AVPacketSideData *sd)
     254             : {
     255             :     AVStereo3D *stereo;
     256             : 
     257         424 :     if (sd->size < sizeof(*stereo)) {
     258           0 :         av_log(ctx, AV_LOG_INFO, "invalid data");
     259           0 :         return;
     260             :     }
     261             : 
     262         424 :     stereo = (AVStereo3D *)sd->data;
     263             : 
     264         424 :     av_log(ctx, AV_LOG_INFO, "%s", av_stereo3d_type_name(stereo->type));
     265             : 
     266         424 :     if (stereo->flags & AV_STEREO3D_FLAG_INVERT)
     267           0 :         av_log(ctx, AV_LOG_INFO, " (inverted)");
     268             : }
     269             : 
     270           2 : static void dump_audioservicetype(void *ctx, AVPacketSideData *sd)
     271             : {
     272           2 :     enum AVAudioServiceType *ast = (enum AVAudioServiceType *)sd->data;
     273             : 
     274           2 :     if (sd->size < sizeof(*ast)) {
     275           0 :         av_log(ctx, AV_LOG_INFO, "invalid data");
     276           0 :         return;
     277             :     }
     278             : 
     279           2 :     switch (*ast) {
     280           2 :     case AV_AUDIO_SERVICE_TYPE_MAIN:
     281           2 :         av_log(ctx, AV_LOG_INFO, "main");
     282           2 :         break;
     283           0 :     case AV_AUDIO_SERVICE_TYPE_EFFECTS:
     284           0 :         av_log(ctx, AV_LOG_INFO, "effects");
     285           0 :         break;
     286           0 :     case AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED:
     287           0 :         av_log(ctx, AV_LOG_INFO, "visually impaired");
     288           0 :         break;
     289           0 :     case AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED:
     290           0 :         av_log(ctx, AV_LOG_INFO, "hearing impaired");
     291           0 :         break;
     292           0 :     case AV_AUDIO_SERVICE_TYPE_DIALOGUE:
     293           0 :         av_log(ctx, AV_LOG_INFO, "dialogue");
     294           0 :         break;
     295           0 :     case AV_AUDIO_SERVICE_TYPE_COMMENTARY:
     296           0 :         av_log(ctx, AV_LOG_INFO, "comentary");
     297           0 :         break;
     298           0 :     case AV_AUDIO_SERVICE_TYPE_EMERGENCY:
     299           0 :         av_log(ctx, AV_LOG_INFO, "emergency");
     300           0 :         break;
     301           0 :     case AV_AUDIO_SERVICE_TYPE_VOICE_OVER:
     302           0 :         av_log(ctx, AV_LOG_INFO, "voice over");
     303           0 :         break;
     304           0 :     case AV_AUDIO_SERVICE_TYPE_KARAOKE:
     305           0 :         av_log(ctx, AV_LOG_INFO, "karaoke");
     306           0 :         break;
     307           0 :     default:
     308           0 :         av_log(ctx, AV_LOG_WARNING, "unknown");
     309           0 :         break;
     310             :     }
     311             : }
     312             : 
     313         183 : static void dump_cpb(void *ctx, AVPacketSideData *sd)
     314             : {
     315         183 :     AVCPBProperties *cpb = (AVCPBProperties *)sd->data;
     316             : 
     317         183 :     if (sd->size < sizeof(*cpb)) {
     318           0 :         av_log(ctx, AV_LOG_INFO, "invalid data");
     319           0 :         return;
     320             :     }
     321             : 
     322         183 :     av_log(ctx, AV_LOG_INFO,
     323             :            "bitrate max/min/avg: %d/%d/%d buffer size: %d vbv_delay: %"PRId64,
     324             :            cpb->max_bitrate, cpb->min_bitrate, cpb->avg_bitrate,
     325             :            cpb->buffer_size,
     326             :            cpb->vbv_delay);
     327             : }
     328             : 
     329           0 : static void dump_mastering_display_metadata(void *ctx, AVPacketSideData* sd) {
     330           0 :     AVMasteringDisplayMetadata* metadata = (AVMasteringDisplayMetadata*)sd->data;
     331           0 :     av_log(ctx, AV_LOG_INFO, "Mastering Display Metadata, "
     332             :            "has_primaries:%d has_luminance:%d "
     333             :            "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f) "
     334             :            "min_luminance=%f, max_luminance=%f",
     335             :            metadata->has_primaries, metadata->has_luminance,
     336             :            av_q2d(metadata->display_primaries[0][0]),
     337             :            av_q2d(metadata->display_primaries[0][1]),
     338             :            av_q2d(metadata->display_primaries[1][0]),
     339             :            av_q2d(metadata->display_primaries[1][1]),
     340             :            av_q2d(metadata->display_primaries[2][0]),
     341             :            av_q2d(metadata->display_primaries[2][1]),
     342             :            av_q2d(metadata->white_point[0]), av_q2d(metadata->white_point[1]),
     343             :            av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance));
     344           0 : }
     345             : 
     346           0 : static void dump_content_light_metadata(void *ctx, AVPacketSideData* sd)
     347             : {
     348           0 :     AVContentLightMetadata* metadata = (AVContentLightMetadata*)sd->data;
     349           0 :     av_log(ctx, AV_LOG_INFO, "Content Light Level Metadata, "
     350             :            "MaxCLL=%d, MaxFALL=%d",
     351             :            metadata->MaxCLL, metadata->MaxFALL);
     352           0 : }
     353             : 
     354           2 : static void dump_spherical(void *ctx, AVCodecParameters *par, AVPacketSideData *sd)
     355             : {
     356           2 :     AVSphericalMapping *spherical = (AVSphericalMapping *)sd->data;
     357             :     double yaw, pitch, roll;
     358             : 
     359           2 :     if (sd->size < sizeof(*spherical)) {
     360           0 :         av_log(ctx, AV_LOG_INFO, "invalid data");
     361           0 :         return;
     362             :     }
     363             : 
     364           2 :     av_log(ctx, AV_LOG_INFO, "%s ", av_spherical_projection_name(spherical->projection));
     365             : 
     366           2 :     yaw = ((double)spherical->yaw) / (1 << 16);
     367           2 :     pitch = ((double)spherical->pitch) / (1 << 16);
     368           2 :     roll = ((double)spherical->roll) / (1 << 16);
     369           2 :     av_log(ctx, AV_LOG_INFO, "(%f/%f/%f) ", yaw, pitch, roll);
     370             : 
     371           2 :     if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR_TILE) {
     372             :         size_t l, t, r, b;
     373           2 :         av_spherical_tile_bounds(spherical, par->width, par->height,
     374             :                                  &l, &t, &r, &b);
     375           2 :         av_log(ctx, AV_LOG_INFO, "[%zu, %zu, %zu, %zu] ", l, t, r, b);
     376           0 :     } else if (spherical->projection == AV_SPHERICAL_CUBEMAP) {
     377           0 :         av_log(ctx, AV_LOG_INFO, "[pad %"PRIu32"] ", spherical->padding);
     378             :     }
     379             : }
     380             : 
     381       11156 : static void dump_sidedata(void *ctx, AVStream *st, const char *indent)
     382             : {
     383             :     int i;
     384             : 
     385       11156 :     if (st->nb_side_data)
     386         613 :         av_log(ctx, AV_LOG_INFO, "%sSide data:\n", indent);
     387             : 
     388       11771 :     for (i = 0; i < st->nb_side_data; i++) {
     389         615 :         AVPacketSideData sd = st->side_data[i];
     390         615 :         av_log(ctx, AV_LOG_INFO, "%s  ", indent);
     391             : 
     392         615 :         switch (sd.type) {
     393           0 :         case AV_PKT_DATA_PALETTE:
     394           0 :             av_log(ctx, AV_LOG_INFO, "palette");
     395           0 :             break;
     396           0 :         case AV_PKT_DATA_NEW_EXTRADATA:
     397           0 :             av_log(ctx, AV_LOG_INFO, "new extradata");
     398           0 :             break;
     399           0 :         case AV_PKT_DATA_PARAM_CHANGE:
     400           0 :             av_log(ctx, AV_LOG_INFO, "paramchange: ");
     401           0 :             dump_paramchange(ctx, &sd);
     402           0 :             break;
     403           0 :         case AV_PKT_DATA_H263_MB_INFO:
     404           0 :             av_log(ctx, AV_LOG_INFO, "H.263 macroblock info");
     405           0 :             break;
     406           0 :         case AV_PKT_DATA_REPLAYGAIN:
     407           0 :             av_log(ctx, AV_LOG_INFO, "replaygain: ");
     408           0 :             dump_replaygain(ctx, &sd);
     409           0 :             break;
     410           4 :         case AV_PKT_DATA_DISPLAYMATRIX:
     411           4 :             av_log(ctx, AV_LOG_INFO, "displaymatrix: rotation of %.2f degrees",
     412           4 :                    av_display_rotation_get((int32_t *)sd.data));
     413           4 :             break;
     414         424 :         case AV_PKT_DATA_STEREO3D:
     415         424 :             av_log(ctx, AV_LOG_INFO, "stereo3d: ");
     416         424 :             dump_stereo3d(ctx, &sd);
     417         424 :             break;
     418           2 :         case AV_PKT_DATA_AUDIO_SERVICE_TYPE:
     419           2 :             av_log(ctx, AV_LOG_INFO, "audio service type: ");
     420           2 :             dump_audioservicetype(ctx, &sd);
     421           2 :             break;
     422           0 :         case AV_PKT_DATA_QUALITY_STATS:
     423           0 :             av_log(ctx, AV_LOG_INFO, "quality factor: %"PRId32", pict_type: %c",
     424           0 :                    AV_RL32(sd.data), av_get_picture_type_char(sd.data[4]));
     425           0 :             break;
     426         183 :         case AV_PKT_DATA_CPB_PROPERTIES:
     427         183 :             av_log(ctx, AV_LOG_INFO, "cpb: ");
     428         183 :             dump_cpb(ctx, &sd);
     429         183 :             break;
     430           0 :         case AV_PKT_DATA_MASTERING_DISPLAY_METADATA:
     431           0 :             dump_mastering_display_metadata(ctx, &sd);
     432           0 :             break;
     433           2 :         case AV_PKT_DATA_SPHERICAL:
     434           2 :             av_log(ctx, AV_LOG_INFO, "spherical: ");
     435           2 :             dump_spherical(ctx, st->codecpar, &sd);
     436           2 :             break;
     437           0 :         case AV_PKT_DATA_CONTENT_LIGHT_LEVEL:
     438           0 :             dump_content_light_metadata(ctx, &sd);
     439           0 :             break;
     440           0 :         default:
     441           0 :             av_log(ctx, AV_LOG_INFO,
     442           0 :                    "unknown side data type %d (%d bytes)", sd.type, sd.size);
     443           0 :             break;
     444             :         }
     445             : 
     446         615 :         av_log(ctx, AV_LOG_INFO, "\n");
     447             :     }
     448       11156 : }
     449             : 
     450             : /* "user interface" functions */
     451       11156 : static void dump_stream_format(AVFormatContext *ic, int i,
     452             :                                int index, int is_output)
     453             : {
     454             :     char buf[256];
     455       11156 :     int flags = (is_output ? ic->oformat->flags : ic->iformat->flags);
     456       11156 :     AVStream *st = ic->streams[i];
     457       11156 :     AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL, 0);
     458       11156 :     char *separator = ic->dump_separator;
     459             :     AVCodecContext *avctx;
     460             :     int ret;
     461             : 
     462       11156 :     avctx = avcodec_alloc_context3(NULL);
     463       11156 :     if (!avctx)
     464           0 :         return;
     465             : 
     466       11156 :     ret = avcodec_parameters_to_context(avctx, st->codecpar);
     467       11156 :     if (ret < 0) {
     468           0 :         avcodec_free_context(&avctx);
     469           0 :         return;
     470             :     }
     471             : 
     472             :     // Fields which are missing from AVCodecParameters need to be taken from the AVCodecContext
     473       11156 :     avctx->properties = st->codec->properties;
     474       11156 :     avctx->codec      = st->codec->codec;
     475       11156 :     avctx->qmin       = st->codec->qmin;
     476       11156 :     avctx->qmax       = st->codec->qmax;
     477       11156 :     avctx->coded_width  = st->codec->coded_width;
     478       11156 :     avctx->coded_height = st->codec->coded_height;
     479             : 
     480       11156 :     if (separator)
     481       11156 :         av_opt_set(avctx, "dump_separator", separator, 0);
     482       11156 :     avcodec_string(buf, sizeof(buf), avctx, is_output);
     483       11156 :     avcodec_free_context(&avctx);
     484             : 
     485       11156 :     av_log(NULL, AV_LOG_INFO, "    Stream #%d:%d", index, i);
     486             : 
     487             :     /* the pid is an important information, so we display it */
     488             :     /* XXX: add a generic system */
     489       11156 :     if (flags & AVFMT_SHOW_IDS)
     490          75 :         av_log(NULL, AV_LOG_INFO, "[0x%x]", st->id);
     491       11156 :     if (lang)
     492        1288 :         av_log(NULL, AV_LOG_INFO, "(%s)", lang->value);
     493       11156 :     av_log(NULL, AV_LOG_DEBUG, ", %d, %d/%d", st->codec_info_nb_frames,
     494             :            st->time_base.num, st->time_base.den);
     495       11156 :     av_log(NULL, AV_LOG_INFO, ": %s", buf);
     496             : 
     497       12164 :     if (st->sample_aspect_ratio.num &&
     498        1008 :         av_cmp_q(st->sample_aspect_ratio, st->codecpar->sample_aspect_ratio)) {
     499             :         AVRational display_aspect_ratio;
     500         594 :         av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
     501         297 :                   st->codecpar->width  * (int64_t)st->sample_aspect_ratio.num,
     502         297 :                   st->codecpar->height * (int64_t)st->sample_aspect_ratio.den,
     503             :                   1024 * 1024);
     504         297 :         av_log(NULL, AV_LOG_INFO, ", SAR %d:%d DAR %d:%d",
     505             :                st->sample_aspect_ratio.num, st->sample_aspect_ratio.den,
     506             :                display_aspect_ratio.num, display_aspect_ratio.den);
     507             :     }
     508             : 
     509       11156 :     if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
     510        8543 :         int fps = st->avg_frame_rate.den && st->avg_frame_rate.num;
     511        8543 :         int tbr = st->r_frame_rate.den && st->r_frame_rate.num;
     512        8543 :         int tbn = st->time_base.den && st->time_base.num;
     513        8543 :         int tbc = st->codec->time_base.den && st->codec->time_base.num;
     514             : 
     515        8543 :         if (fps || tbr || tbn || tbc)
     516        8543 :             av_log(NULL, AV_LOG_INFO, "%s", separator);
     517             : 
     518        8543 :         if (fps)
     519        7679 :             print_fps(av_q2d(st->avg_frame_rate), tbr || tbn || tbc ? "fps, " : "fps");
     520        8543 :         if (tbr)
     521        4392 :             print_fps(av_q2d(st->r_frame_rate), tbn || tbc ? "tbr, " : "tbr");
     522        8543 :         if (tbn)
     523        8543 :             print_fps(1 / av_q2d(st->time_base), tbc ? "tbn, " : "tbn");
     524        8543 :         if (tbc)
     525        8508 :             print_fps(1 / av_q2d(st->codec->time_base), "tbc");
     526             :     }
     527             : 
     528       11156 :     if (st->disposition & AV_DISPOSITION_DEFAULT)
     529        1293 :         av_log(NULL, AV_LOG_INFO, " (default)");
     530       11156 :     if (st->disposition & AV_DISPOSITION_DUB)
     531           0 :         av_log(NULL, AV_LOG_INFO, " (dub)");
     532       11156 :     if (st->disposition & AV_DISPOSITION_ORIGINAL)
     533           0 :         av_log(NULL, AV_LOG_INFO, " (original)");
     534       11156 :     if (st->disposition & AV_DISPOSITION_COMMENT)
     535           0 :         av_log(NULL, AV_LOG_INFO, " (comment)");
     536       11156 :     if (st->disposition & AV_DISPOSITION_LYRICS)
     537           0 :         av_log(NULL, AV_LOG_INFO, " (lyrics)");
     538       11156 :     if (st->disposition & AV_DISPOSITION_KARAOKE)
     539           0 :         av_log(NULL, AV_LOG_INFO, " (karaoke)");
     540       11156 :     if (st->disposition & AV_DISPOSITION_FORCED)
     541           0 :         av_log(NULL, AV_LOG_INFO, " (forced)");
     542       11156 :     if (st->disposition & AV_DISPOSITION_HEARING_IMPAIRED)
     543           1 :         av_log(NULL, AV_LOG_INFO, " (hearing impaired)");
     544       11156 :     if (st->disposition & AV_DISPOSITION_VISUAL_IMPAIRED)
     545           0 :         av_log(NULL, AV_LOG_INFO, " (visual impaired)");
     546       11156 :     if (st->disposition & AV_DISPOSITION_CLEAN_EFFECTS)
     547           0 :         av_log(NULL, AV_LOG_INFO, " (clean effects)");
     548       11156 :     av_log(NULL, AV_LOG_INFO, "\n");
     549             : 
     550       11156 :     dump_metadata(NULL, st->metadata, "    ");
     551             : 
     552       11156 :     dump_sidedata(NULL, st, "    ");
     553             : }
     554             : 
     555       10681 : void av_dump_format(AVFormatContext *ic, int index,
     556             :                     const char *url, int is_output)
     557             : {
     558             :     int i;
     559       10681 :     uint8_t *printed = ic->nb_streams ? av_mallocz(ic->nb_streams) : NULL;
     560       10681 :     if (ic->nb_streams && !printed)
     561           0 :         return;
     562             : 
     563       21362 :     av_log(NULL, AV_LOG_INFO, "%s #%d, %s, %s '%s':\n",
     564             :            is_output ? "Output" : "Input",
     565             :            index,
     566       10681 :            is_output ? ic->oformat->name : ic->iformat->name,
     567             :            is_output ? "to" : "from", url);
     568       10681 :     dump_metadata(NULL, ic->metadata, "  ");
     569             : 
     570       10681 :     if (!is_output) {
     571        5392 :         av_log(NULL, AV_LOG_INFO, "  Duration: ");
     572        5392 :         if (ic->duration != AV_NOPTS_VALUE) {
     573             :             int hours, mins, secs, us;
     574        4553 :             int64_t duration = ic->duration + (ic->duration <= INT64_MAX - 5000 ? 5000 : 0);
     575        4553 :             secs  = duration / AV_TIME_BASE;
     576        4553 :             us    = duration % AV_TIME_BASE;
     577        4553 :             mins  = secs / 60;
     578        4553 :             secs %= 60;
     579        4553 :             hours = mins / 60;
     580        4553 :             mins %= 60;
     581        4553 :             av_log(NULL, AV_LOG_INFO, "%02d:%02d:%02d.%02d", hours, mins, secs,
     582        4553 :                    (100 * us) / AV_TIME_BASE);
     583             :         } else {
     584         839 :             av_log(NULL, AV_LOG_INFO, "N/A");
     585             :         }
     586        5392 :         if (ic->start_time != AV_NOPTS_VALUE) {
     587             :             int secs, us;
     588        3982 :             av_log(NULL, AV_LOG_INFO, ", start: ");
     589        3982 :             secs = llabs(ic->start_time / AV_TIME_BASE);
     590        3982 :             us   = llabs(ic->start_time % AV_TIME_BASE);
     591        7964 :             av_log(NULL, AV_LOG_INFO, "%s%d.%06d",
     592        3982 :                    ic->start_time >= 0 ? "" : "-",
     593             :                    secs,
     594        3982 :                    (int) av_rescale(us, 1000000, AV_TIME_BASE));
     595             :         }
     596        5392 :         av_log(NULL, AV_LOG_INFO, ", bitrate: ");
     597        5392 :         if (ic->bit_rate)
     598        2586 :             av_log(NULL, AV_LOG_INFO, "%"PRId64" kb/s", ic->bit_rate / 1000);
     599             :         else
     600        2806 :             av_log(NULL, AV_LOG_INFO, "N/A");
     601        5392 :         av_log(NULL, AV_LOG_INFO, "\n");
     602             :     }
     603             : 
     604       10705 :     for (i = 0; i < ic->nb_chapters; i++) {
     605          24 :         AVChapter *ch = ic->chapters[i];
     606          24 :         av_log(NULL, AV_LOG_INFO, "    Chapter #%d:%d: ", index, i);
     607          48 :         av_log(NULL, AV_LOG_INFO,
     608          48 :                "start %f, ", ch->start * av_q2d(ch->time_base));
     609          48 :         av_log(NULL, AV_LOG_INFO,
     610          48 :                "end %f\n", ch->end * av_q2d(ch->time_base));
     611             : 
     612          24 :         dump_metadata(NULL, ch->metadata, "    ");
     613             :     }
     614             : 
     615       10681 :     if (ic->nb_programs) {
     616          25 :         int j, k, total = 0;
     617          50 :         for (j = 0; j < ic->nb_programs; j++) {
     618          25 :             AVDictionaryEntry *name = av_dict_get(ic->programs[j]->metadata,
     619             :                                                   "name", NULL, 0);
     620          25 :             av_log(NULL, AV_LOG_INFO, "  Program %d %s\n", ic->programs[j]->id,
     621             :                    name ? name->value : "");
     622          25 :             dump_metadata(NULL, ic->programs[j]->metadata, "    ");
     623          60 :             for (k = 0; k < ic->programs[j]->nb_stream_indexes; k++) {
     624          35 :                 dump_stream_format(ic, ic->programs[j]->stream_index[k],
     625             :                                    index, is_output);
     626          35 :                 printed[ic->programs[j]->stream_index[k]] = 1;
     627             :             }
     628          25 :             total += ic->programs[j]->nb_stream_indexes;
     629             :         }
     630          25 :         if (total < ic->nb_streams)
     631           0 :             av_log(NULL, AV_LOG_INFO, "  No Program\n");
     632             :     }
     633             : 
     634       21837 :     for (i = 0; i < ic->nb_streams; i++)
     635       11156 :         if (!printed[i])
     636       11121 :             dump_stream_format(ic, i, index, is_output);
     637             : 
     638       10681 :     av_free(printed);
     639             : }

Generated by: LCOV version 1.13