---
As previously mentioned on this mailing list, this patch allows dumping
avstream side data (replaygain and rotation and stereo3d in the future) when
probing.
Format suggestions is welcome.
Vittorio
libavformat/dumputils.c | 164 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 164 insertions(+)
diff --git a/libavformat/dumputils.c b/libavformat/dumputils.c
index 9762d2a..2293d8c 100644
--- a/libavformat/dumputils.c
+++ b/libavformat/dumputils.c
@@ -21,8 +21,12 @@
#include <stdio.h>
#include <stdint.h>
+#include "libavutil/channel_layout.h"
+#include "libavutil/display.h"
+#include "libavutil/intreadwrite.h"
#include "libavutil/log.h"
#include "libavutil/mathematics.h"
+#include "libavutil/replaygain.h"
#include "avformat.h"
@@ -131,6 +135,164 @@ static void dump_metadata(void *ctx, AVDictionary *m,
const char *indent)
}
}
+/* param change side data*/
+static void dump_paramchange(void *ctx, AVPacketSideData *sd)
+{
+ int size = sd->size;
+ const uint8_t *data = sd->data;
+ uint32_t flags, channels, sample_rate, width, height;
+ uint64_t layout;
+
+ if (!data || sd->size < 4)
+ goto fail;
+
+ flags = AV_RL32(data);
+ data += 4;
+ size -= 4;
+
+ if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_COUNT) {
+ if (size < 4)
+ goto fail;
+ channels = AV_RL32(data);
+ data += 4;
+ size -= 4;
+ av_log(ctx, AV_LOG_INFO, "[channel count %d]", channels);
+ }
+ if (flags & AV_SIDE_DATA_PARAM_CHANGE_CHANNEL_LAYOUT) {
+ if (size < 8)
+ goto fail;
+ layout = AV_RL64(data);
+ data += 8;
+ size -= 8;
+ av_log(ctx, AV_LOG_INFO,
+ "[channel layout: %s]", av_get_channel_name(layout));
+ }
+ if (flags & AV_SIDE_DATA_PARAM_CHANGE_SAMPLE_RATE) {
+ if (size < 4)
+ goto fail;
+ sample_rate = AV_RL32(data);
+ data += 4;
+ size -= 4;
+ av_log(ctx, AV_LOG_INFO, "[sample_rate %d]", sample_rate);
+ }
+ if (flags & AV_SIDE_DATA_PARAM_CHANGE_DIMENSIONS) {
+ if (size < 8)
+ goto fail;
+ width = AV_RL32(data);
+ data += 4;
+ size -= 4;
+ height = AV_RL32(data);
+ data += 4;
+ size -= 4;
+ av_log(ctx, AV_LOG_INFO, "[width %d height %d]", width, height);
+ }
+
+ return;
+fail:
+ av_log(ctx, AV_LOG_INFO, "[unknown param]");
+}
+
+/* replaygain side data*/
+static void print_gain(void *ctx, const char *str, int32_t gain)
+{
+ av_log(ctx, AV_LOG_INFO, "%s - ", str);
+ if (gain == INT32_MIN)
+ av_log(ctx, AV_LOG_INFO, "unknown");
+ else
+ av_log(ctx, AV_LOG_INFO, "%f", gain / 100000.0f);
+ av_log(ctx, AV_LOG_INFO, ", ");
+}
+
+static void print_peak(void *ctx, const char *str, uint32_t peak)
+{
+ av_log(ctx, AV_LOG_INFO, "%s - ", str);
+ if (!peak)
+ av_log(ctx, AV_LOG_INFO, "unknown");
+ else
+ av_log(ctx, AV_LOG_INFO, "%f", (float) peak / UINT32_MAX);
+ av_log(ctx, AV_LOG_INFO, ", ");
+}
+
+static void dump_replaygain(void *ctx, AVPacketSideData *sd)
+{
+ AVReplayGain *rg;
+
+ if (sd->size < sizeof(*rg)) {
+ av_log(ctx, AV_LOG_INFO, "invalid data");
+ return;
+ }
+ rg = (AVReplayGain*)sd->data;
+
+ print_gain(ctx, "track gain", rg->track_gain);
+ print_peak(ctx, "track peak", rg->track_peak);
+ print_gain(ctx, "album gain", rg->album_gain);
+ print_peak(ctx, "album peak", rg->album_peak);
+}
+
+/* display matrix side data*/
+static void dump_transformation(void *ctx, AVPacketSideData *sd)
+{
+ int rotation, hflip, vflip;
+
+ rotation = av_display_rotation_angle(sd->data);
+ if (rotation)
+ av_log(ctx, AV_LOG_INFO, "rotation of %d degrees ", rotation);
+
+ hflip = av_display_hflip(sd->data);
+ if (hflip)
+ av_log(ctx, AV_LOG_INFO, "horizontal flip ");
+
+ vflip = av_display_vflip(sd->data);
+ if (vflip)
+ av_log(ctx, AV_LOG_INFO, "vertical flip ");
+
+ if (!rotation && !hflip && !vflip)
+ av_log(ctx, AV_LOG_INFO, "unknown transformation");
+}
+
+static void dump_sidedata(void *ctx, AVStream *st, const char *indent)
+{
+ int i;
+
+ if (st->nb_side_data)
+ av_log(ctx, AV_LOG_INFO, "%sSide data:\n", indent);
+
+ for (i = 0; i < st->nb_side_data; i++) {
+ AVPacketSideData sd = st->side_data[i];
+ av_log(ctx, AV_LOG_INFO, "%s ", indent);
+
+ switch (sd.type) {
+ case AV_PKT_DATA_PALETTE:
+ av_log(ctx, AV_LOG_INFO, "palette");
+ break;
+ case AV_PKT_DATA_NEW_EXTRADATA:
+ av_log(ctx, AV_LOG_INFO, "new extradata");
+ break;
+ case AV_PKT_DATA_PARAM_CHANGE:
+ av_log(ctx, AV_LOG_INFO, "paramchange: ");
+ dump_paramchange(ctx, &sd);
+ break;
+ case AV_PKT_DATA_H263_MB_INFO:
+ av_log(ctx, AV_LOG_INFO, "h263 macroblock info");
+ break;
+ case AV_PKT_DATA_REPLAYGAIN:
+ av_log(ctx, AV_LOG_INFO, "replaygain: ");
+ dump_replaygain(ctx, &sd);
+ break;
+ case AV_PKT_DATA_DISPLAYMATRIX:
+ av_log(ctx, AV_LOG_INFO, "displaymatrix: ");
+ dump_transformation(ctx, &sd);
+ break;
+ default:
+ av_log(ctx, AV_LOG_WARNING,
+ "unknown side data type %d (%d bytes)", sd.type, sd.size);
+ break;
+ }
+
+ av_log(ctx, AV_LOG_INFO, "\n");
+ }
+}
+
/* "user interface" functions */
static void dump_stream_format(AVFormatContext *ic, int i,
int index, int is_output)
@@ -198,6 +360,8 @@ static void dump_stream_format(AVFormatContext *ic, int i,
av_log(NULL, AV_LOG_INFO, "\n");
dump_metadata(NULL, st->metadata, " ");
+
+ dump_sidedata(NULL, st, " ");
}
void av_dump_format(AVFormatContext *ic, int index,
--
1.8.3.4 (Apple Git-47)
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel