]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/dump.c
configure: Add check_x86asm() helper function to simplify some expressions
[ffmpeg] / libavformat / dump.c
index 1e385ab307bdc0e3e851f880f3213ba6c7ea4da5..261e21efd3536ee0e8ac9fe8e633e4904c61490f 100644 (file)
@@ -27,6 +27,8 @@
 #include "libavutil/log.h"
 #include "libavutil/mathematics.h"
 #include "libavutil/replaygain.h"
+#include "libavutil/spherical.h"
+#include "libavutil/stereo3d.h"
 
 #include "avformat.h"
 
@@ -115,11 +117,11 @@ static void print_fps(double d, const char *postfix)
 {
     uint64_t v = lrintf(d * 100);
     if (v % 100)
-        av_log(NULL, AV_LOG_INFO, "%3.2f %s", d, postfix);
+        av_log(NULL, AV_LOG_INFO, "%3.2f %s", d, postfix);
     else if (v % (100 * 1000))
-        av_log(NULL, AV_LOG_INFO, "%1.0f %s", d, postfix);
+        av_log(NULL, AV_LOG_INFO, "%1.0f %s", d, postfix);
     else
-        av_log(NULL, AV_LOG_INFO, "%1.0fk %s", d / 1000, postfix);
+        av_log(NULL, AV_LOG_INFO, "%1.0fk %s", d / 1000, postfix);
 }
 
 static void dump_metadata(void *ctx, AVDictionary *m, const char *indent)
@@ -156,7 +158,7 @@ static void dump_paramchange(void *ctx, AVPacketSideData *sd)
         channels = AV_RL32(data);
         data += 4;
         size -= 4;
-        av_log(ctx, AV_LOG_INFO, "channel count %d, ", channels);
+        av_log(ctx, AV_LOG_INFO, "channel count %"PRIu32", ", channels);
     }
     if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT) {
         if (size < 8)
@@ -173,7 +175,7 @@ static void dump_paramchange(void *ctx, AVPacketSideData *sd)
         sample_rate = AV_RL32(data);
         data += 4;
         size -= 4;
-        av_log(ctx, AV_LOG_INFO, "sample_rate %d, ", sample_rate);
+        av_log(ctx, AV_LOG_INFO, "sample_rate %"PRIu32", ", sample_rate);
     }
     if (flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS) {
         if (size < 8)
@@ -184,7 +186,7 @@ static void dump_paramchange(void *ctx, AVPacketSideData *sd)
         height = AV_RL32(data);
         data += 4;
         size -= 4;
-        av_log(ctx, AV_LOG_INFO, "width %d height %d", width, height);
+        av_log(ctx, AV_LOG_INFO, "width %"PRIu32" height %"PRIu32, width, height);
     }
 
     return;
@@ -229,6 +231,109 @@ static void dump_replaygain(void *ctx, AVPacketSideData *sd)
     print_peak(ctx, "album peak", rg->album_peak);
 }
 
+static void dump_stereo3d(void *ctx, AVPacketSideData *sd)
+{
+    AVStereo3D *stereo;
+
+    if (sd->size < sizeof(*stereo)) {
+        av_log(ctx, AV_LOG_INFO, "invalid data");
+        return;
+    }
+
+    stereo = (AVStereo3D *)sd->data;
+
+    av_log(ctx, AV_LOG_INFO, "%s", av_stereo3d_type_name(stereo->type));
+
+    if (stereo->flags & AV_STEREO3D_FLAG_INVERT)
+        av_log(ctx, AV_LOG_INFO, " (inverted)");
+}
+
+static void dump_audioservicetype(void *ctx, AVPacketSideData *sd)
+{
+    enum AVAudioServiceType *ast = (enum AVAudioServiceType *)sd->data;
+
+    if (sd->size < sizeof(*ast)) {
+        av_log(ctx, AV_LOG_INFO, "invalid data");
+        return;
+    }
+
+    switch (*ast) {
+    case AV_AUDIO_SERVICE_TYPE_MAIN:
+        av_log(ctx, AV_LOG_INFO, "main");
+        break;
+    case AV_AUDIO_SERVICE_TYPE_EFFECTS:
+        av_log(ctx, AV_LOG_INFO, "effects");
+        break;
+    case AV_AUDIO_SERVICE_TYPE_VISUALLY_IMPAIRED:
+        av_log(ctx, AV_LOG_INFO, "visually impaired");
+        break;
+    case AV_AUDIO_SERVICE_TYPE_HEARING_IMPAIRED:
+        av_log(ctx, AV_LOG_INFO, "hearing impaired");
+        break;
+    case AV_AUDIO_SERVICE_TYPE_DIALOGUE:
+        av_log(ctx, AV_LOG_INFO, "dialogue");
+        break;
+    case AV_AUDIO_SERVICE_TYPE_COMMENTARY:
+        av_log(ctx, AV_LOG_INFO, "comentary");
+        break;
+    case AV_AUDIO_SERVICE_TYPE_EMERGENCY:
+        av_log(ctx, AV_LOG_INFO, "emergency");
+        break;
+    case AV_AUDIO_SERVICE_TYPE_VOICE_OVER:
+        av_log(ctx, AV_LOG_INFO, "voice over");
+        break;
+    case AV_AUDIO_SERVICE_TYPE_KARAOKE:
+        av_log(ctx, AV_LOG_INFO, "karaoke");
+        break;
+    default:
+        av_log(ctx, AV_LOG_WARNING, "unknown");
+        break;
+    }
+}
+
+static void dump_cpb(void *ctx, AVPacketSideData *sd)
+{
+    AVCPBProperties *cpb = (AVCPBProperties *)sd->data;
+
+    if (sd->size < sizeof(*cpb)) {
+        av_log(ctx, AV_LOG_INFO, "invalid data");
+        return;
+    }
+
+    av_log(ctx, AV_LOG_INFO,
+           "bitrate max/min/avg: %d/%d/%d buffer size: %d vbv_delay: %"PRId64,
+           cpb->max_bitrate, cpb->min_bitrate, cpb->avg_bitrate,
+           cpb->buffer_size,
+           cpb->vbv_delay);
+}
+
+static void dump_spherical(void *ctx, AVCodecParameters *par, AVPacketSideData *sd)
+{
+    AVSphericalMapping *spherical = (AVSphericalMapping *)sd->data;
+    double yaw, pitch, roll;
+
+    if (sd->size < sizeof(*spherical)) {
+        av_log(ctx, AV_LOG_INFO, "invalid data");
+        return;
+    }
+
+    av_log(ctx, AV_LOG_INFO, "%s ", av_spherical_projection_name(spherical->projection));
+
+    yaw = ((double)spherical->yaw) / (1 << 16);
+    pitch = ((double)spherical->pitch) / (1 << 16);
+    roll = ((double)spherical->roll) / (1 << 16);
+    av_log(ctx, AV_LOG_INFO, "(%f/%f/%f) ", yaw, pitch, roll);
+
+    if (spherical->projection == AV_SPHERICAL_EQUIRECTANGULAR_TILE) {
+        size_t l, t, r, b;
+        av_spherical_tile_bounds(spherical, par->width, par->height,
+                                 &l, &t, &r, &b);
+        av_log(ctx, AV_LOG_INFO, "[%zu, %zu, %zu, %zu] ", l, t, r, b);
+    } else if (spherical->projection == AV_SPHERICAL_CUBEMAP) {
+        av_log(ctx, AV_LOG_INFO, "[pad %"PRIu32"] ", spherical->padding);
+    }
+}
+
 static void dump_sidedata(void *ctx, AVStream *st, const char *indent)
 {
     int i;
@@ -252,7 +357,7 @@ static void dump_sidedata(void *ctx, AVStream *st, const char *indent)
             dump_paramchange(ctx, &sd);
             break;
         case AV_PKT_DATA_H263_MB_INFO:
-            av_log(ctx, AV_LOG_INFO, "h263 macroblock info");
+            av_log(ctx, AV_LOG_INFO, "H.263 macroblock info");
             break;
         case AV_PKT_DATA_REPLAYGAIN:
             av_log(ctx, AV_LOG_INFO, "replaygain: ");
@@ -262,6 +367,25 @@ static void dump_sidedata(void *ctx, AVStream *st, const char *indent)
             av_log(ctx, AV_LOG_INFO, "displaymatrix: rotation of %.2f degrees",
                    av_display_rotation_get((int32_t *)sd.data));
             break;
+        case AV_PKT_DATA_STEREO3D:
+            av_log(ctx, AV_LOG_INFO, "stereo3d: ");
+            dump_stereo3d(ctx, &sd);
+            break;
+        case AV_PKT_DATA_AUDIO_SERVICE_TYPE:
+            av_log(ctx, AV_LOG_INFO, "audio service type: ");
+            dump_audioservicetype(ctx, &sd);
+            break;
+        case AV_PKT_DATA_QUALITY_FACTOR:
+            av_log(ctx, AV_LOG_INFO, "quality factor: %d", *(int *)sd.data);
+            break;
+        case AV_PKT_DATA_CPB_PROPERTIES:
+            av_log(ctx, AV_LOG_INFO, "cpb: ");
+            dump_cpb(ctx, &sd);
+            break;
+        case AV_PKT_DATA_SPHERICAL:
+            av_log(ctx, AV_LOG_INFO, "spherical: ");
+            dump_spherical(ctx, st->codecpar, &sd);
+            break;
         default:
             av_log(ctx, AV_LOG_WARNING,
                    "unknown side data type %d (%d bytes)", sd.type, sd.size);
@@ -279,11 +403,24 @@ static void dump_stream_format(AVFormatContext *ic, int i,
     char buf[256];
     int flags = (is_output ? ic->oformat->flags : ic->iformat->flags);
     AVStream *st = ic->streams[i];
-    int g = av_gcd(st->time_base.num, st->time_base.den);
     AVDictionaryEntry *lang = av_dict_get(st->metadata, "language", NULL, 0);
+    AVCodecContext *avctx;
+    int ret;
+
+    avctx = avcodec_alloc_context3(NULL);
+    if (!avctx)
+        return;
+
+    ret = avcodec_parameters_to_context(avctx, st->codecpar);
+    if (ret < 0) {
+        avcodec_free_context(&avctx);
+        return;
+    }
+
+    avcodec_string(buf, sizeof(buf), avctx, is_output);
+    avcodec_free_context(&avctx);
 
-    avcodec_string(buf, sizeof(buf), st->codec, is_output);
-    av_log(NULL, AV_LOG_INFO, "    Stream #%d.%d", index, i);
+    av_log(NULL, AV_LOG_INFO, "    Stream #%d:%d", index, i);
 
     /* the pid is an important information, so we display it */
     /* XXX: add a generic system */
@@ -292,28 +429,30 @@ static void dump_stream_format(AVFormatContext *ic, int i,
     if (lang)
         av_log(NULL, AV_LOG_INFO, "(%s)", lang->value);
     av_log(NULL, AV_LOG_DEBUG, ", %d, %d/%d", st->codec_info_nb_frames,
-           st->time_base.num / g, st->time_base.den / g);
+           st->time_base.num, st->time_base.den);
     av_log(NULL, AV_LOG_INFO, ": %s", buf);
 
-    if (st->sample_aspect_ratio.num && // default
-        av_cmp_q(st->sample_aspect_ratio, st->codec->sample_aspect_ratio)) {
+    if (st->sample_aspect_ratio.num) {
         AVRational display_aspect_ratio;
         av_reduce(&display_aspect_ratio.num, &display_aspect_ratio.den,
-                  st->codec->width  * st->sample_aspect_ratio.num,
-                  st->codec->height * st->sample_aspect_ratio.den,
+                  st->codecpar->width  * st->sample_aspect_ratio.num,
+                  st->codecpar->height * st->sample_aspect_ratio.den,
                   1024 * 1024);
         av_log(NULL, AV_LOG_INFO, ", PAR %d:%d DAR %d:%d",
                st->sample_aspect_ratio.num, st->sample_aspect_ratio.den,
                display_aspect_ratio.num, display_aspect_ratio.den);
     }
 
-    if (st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
-        if (st->avg_frame_rate.den && st->avg_frame_rate.num)
-            print_fps(av_q2d(st->avg_frame_rate), "fps");
-        if (st->time_base.den && st->time_base.num)
+    if (st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
+        int fps = st->avg_frame_rate.den && st->avg_frame_rate.num;
+        int tbn = st->time_base.den && st->time_base.num;
+
+        if (fps || tbn)
+            av_log(NULL, AV_LOG_INFO, "\n      ");
+        if (fps)
+            print_fps(av_q2d(st->avg_frame_rate), tbn ? "fps, " : "fps");
+        if (tbn)
             print_fps(1 / av_q2d(st->time_base), "tbn");
-        if (st->codec->time_base.den && st->codec->time_base.num)
-            print_fps(1 / av_q2d(st->codec->time_base), "tbc");
     }
 
     if (st->disposition & AV_DISPOSITION_DEFAULT)
@@ -377,7 +516,7 @@ void av_dump_format(AVFormatContext *ic, int index,
             int secs, us;
             av_log(NULL, AV_LOG_INFO, ", start: ");
             secs = ic->start_time / AV_TIME_BASE;
-            us   = abs(ic->start_time % AV_TIME_BASE);
+            us   = llabs(ic->start_time % AV_TIME_BASE);
             av_log(NULL, AV_LOG_INFO, "%d.%06d",
                    secs, (int) av_rescale(us, 1000000, AV_TIME_BASE));
         }
@@ -391,7 +530,7 @@ void av_dump_format(AVFormatContext *ic, int index,
 
     for (i = 0; i < ic->nb_chapters; i++) {
         AVChapter *ch = ic->chapters[i];
-        av_log(NULL, AV_LOG_INFO, "    Chapter #%d.%d: ", index, i);
+        av_log(NULL, AV_LOG_INFO, "    Chapter #%d:%d: ", index, i);
         av_log(NULL, AV_LOG_INFO,
                "start %f, ", ch->start * av_q2d(ch->time_base));
         av_log(NULL, AV_LOG_INFO,