Re: [FFmpeg-devel] [PATCH 1/2] avformat/dump: Use const where appropriate
On Tue, Jun 30, 2020 at 03:09:08PM +0200, Andreas Rheinhardt wrote: > Also switch to using a pointer to access stream side data instead of > copying the stream's AVPacketSideData. > > Signed-off-by: Andreas Rheinhardt > --- > libavformat/dump.c | 91 -- > 1 file changed, 48 insertions(+), 43 deletions(-) > > diff --git a/libavformat/dump.c b/libavformat/dump.c > index 117c68145c..3c76edfee4 100644 > --- a/libavformat/dump.c > +++ b/libavformat/dump.c > @@ -131,10 +131,10 @@ static void print_fps(double d, const char *postfix) > av_log(NULL, AV_LOG_INFO, "%1.0fk %s", d / 1000, postfix); > } > > -static void dump_metadata(void *ctx, AVDictionary *m, const char *indent) > +static void dump_metadata(void *ctx, const AVDictionary *m, const char > *indent) > { > if (m && !(av_dict_count(m) == 1 && av_dict_get(m, "language", NULL, > 0))) { > -AVDictionaryEntry *tag = NULL; > +const AVDictionaryEntry *tag = NULL; > > av_log(ctx, AV_LOG_INFO, "%sMetadata:\n", indent); > while ((tag = av_dict_get(m, "", tag, AV_DICT_IGNORE_SUFFIX))) > @@ -158,7 +158,7 @@ static void dump_metadata(void *ctx, AVDictionary *m, > const char *indent) > } > > /* param change side data*/ > -static void dump_paramchange(void *ctx, AVPacketSideData *sd) > +static void dump_paramchange(void *ctx, const AVPacketSideData *sd) > { > int size = sd->size; > const uint8_t *data = sd->data; > @@ -235,15 +235,15 @@ static void print_peak(void *ctx, const char *str, > uint32_t peak) > av_log(ctx, AV_LOG_INFO, ", "); > } > > -static void dump_replaygain(void *ctx, AVPacketSideData *sd) > +static void dump_replaygain(void *ctx, const AVPacketSideData *sd) > { > -AVReplayGain *rg; > +const AVReplayGain *rg; > > if (sd->size < sizeof(*rg)) { > av_log(ctx, AV_LOG_ERROR, "invalid data"); > return; > } > -rg = (AVReplayGain*)sd->data; > +rg = (const AVReplayGain *)sd->data; > > print_gain(ctx, "track gain", rg->track_gain); > print_peak(ctx, "track peak", rg->track_peak); > @@ -251,16 +251,16 @@ static void dump_replaygain(void *ctx, AVPacketSideData > *sd) > print_peak(ctx, "album peak", rg->album_peak); > } > > -static void dump_stereo3d(void *ctx, AVPacketSideData *sd) > +static void dump_stereo3d(void *ctx, const AVPacketSideData *sd) > { > -AVStereo3D *stereo; > +const AVStereo3D *stereo; > > if (sd->size < sizeof(*stereo)) { > av_log(ctx, AV_LOG_ERROR, "invalid data"); > return; > } > > -stereo = (AVStereo3D *)sd->data; > +stereo = (const AVStereo3D *)sd->data; > > av_log(ctx, AV_LOG_INFO, "%s", av_stereo3d_type_name(stereo->type)); > > @@ -268,9 +268,9 @@ static void dump_stereo3d(void *ctx, AVPacketSideData *sd) > av_log(ctx, AV_LOG_INFO, " (inverted)"); > } > > -static void dump_audioservicetype(void *ctx, AVPacketSideData *sd) > +static void dump_audioservicetype(void *ctx, const AVPacketSideData *sd) > { > -enum AVAudioServiceType *ast = (enum AVAudioServiceType *)sd->data; > +const enum AVAudioServiceType *ast = (const enum AVAudioServiceType > *)sd->data; > > if (sd->size < sizeof(*ast)) { > av_log(ctx, AV_LOG_ERROR, "invalid data"); > @@ -311,9 +311,9 @@ static void dump_audioservicetype(void *ctx, > AVPacketSideData *sd) > } > } > > -static void dump_cpb(void *ctx, AVPacketSideData *sd) > +static void dump_cpb(void *ctx, const AVPacketSideData *sd) > { > -AVCPBProperties *cpb = (AVCPBProperties *)sd->data; > +const AVCPBProperties *cpb = (const AVCPBProperties *)sd->data; > > if (sd->size < sizeof(*cpb)) { > av_log(ctx, AV_LOG_ERROR, "invalid data"); > @@ -334,8 +334,10 @@ static void dump_cpb(void *ctx, AVPacketSideData *sd) > av_log(ctx, AV_LOG_INFO, "vbv_delay: %"PRIu64"", cpb->vbv_delay); > } > > -static void dump_mastering_display_metadata(void *ctx, AVPacketSideData* sd) > { > -AVMasteringDisplayMetadata* metadata = > (AVMasteringDisplayMetadata*)sd->data; > +static void dump_mastering_display_metadata(void *ctx, const > AVPacketSideData *sd) > +{ > +const AVMasteringDisplayMetadata *metadata = > +(const AVMasteringDisplayMetadata *)sd->data; > av_log(ctx, AV_LOG_INFO, "Mastering Display Metadata, " > "has_primaries:%d has_luminance:%d " > "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f) " > @@ -351,17 +353,19 @@ static void dump_mastering_display_metadata(void *ctx, > AVPacketSideData* sd) { > av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance)); > } > > -static void dump_content_light_metadata(void *ctx, AVPacketSideData* sd) > +static void dump_content_light_metadata(void *ctx, const AVPacketSideData > *sd) > { > -AVContentLightMetadata* metadata = (AVContentLightMetadata*)sd->data; > +const AVContentLi
[FFmpeg-devel] [PATCH 1/2] avformat/dump: Use const where appropriate
Also switch to using a pointer to access stream side data instead of copying the stream's AVPacketSideData. Signed-off-by: Andreas Rheinhardt --- libavformat/dump.c | 91 -- 1 file changed, 48 insertions(+), 43 deletions(-) diff --git a/libavformat/dump.c b/libavformat/dump.c index 117c68145c..3c76edfee4 100644 --- a/libavformat/dump.c +++ b/libavformat/dump.c @@ -131,10 +131,10 @@ static void print_fps(double d, const char *postfix) av_log(NULL, AV_LOG_INFO, "%1.0fk %s", d / 1000, postfix); } -static void dump_metadata(void *ctx, AVDictionary *m, const char *indent) +static void dump_metadata(void *ctx, const AVDictionary *m, const char *indent) { if (m && !(av_dict_count(m) == 1 && av_dict_get(m, "language", NULL, 0))) { -AVDictionaryEntry *tag = NULL; +const AVDictionaryEntry *tag = NULL; av_log(ctx, AV_LOG_INFO, "%sMetadata:\n", indent); while ((tag = av_dict_get(m, "", tag, AV_DICT_IGNORE_SUFFIX))) @@ -158,7 +158,7 @@ static void dump_metadata(void *ctx, AVDictionary *m, const char *indent) } /* param change side data*/ -static void dump_paramchange(void *ctx, AVPacketSideData *sd) +static void dump_paramchange(void *ctx, const AVPacketSideData *sd) { int size = sd->size; const uint8_t *data = sd->data; @@ -235,15 +235,15 @@ static void print_peak(void *ctx, const char *str, uint32_t peak) av_log(ctx, AV_LOG_INFO, ", "); } -static void dump_replaygain(void *ctx, AVPacketSideData *sd) +static void dump_replaygain(void *ctx, const AVPacketSideData *sd) { -AVReplayGain *rg; +const AVReplayGain *rg; if (sd->size < sizeof(*rg)) { av_log(ctx, AV_LOG_ERROR, "invalid data"); return; } -rg = (AVReplayGain*)sd->data; +rg = (const AVReplayGain *)sd->data; print_gain(ctx, "track gain", rg->track_gain); print_peak(ctx, "track peak", rg->track_peak); @@ -251,16 +251,16 @@ static void dump_replaygain(void *ctx, AVPacketSideData *sd) print_peak(ctx, "album peak", rg->album_peak); } -static void dump_stereo3d(void *ctx, AVPacketSideData *sd) +static void dump_stereo3d(void *ctx, const AVPacketSideData *sd) { -AVStereo3D *stereo; +const AVStereo3D *stereo; if (sd->size < sizeof(*stereo)) { av_log(ctx, AV_LOG_ERROR, "invalid data"); return; } -stereo = (AVStereo3D *)sd->data; +stereo = (const AVStereo3D *)sd->data; av_log(ctx, AV_LOG_INFO, "%s", av_stereo3d_type_name(stereo->type)); @@ -268,9 +268,9 @@ static void dump_stereo3d(void *ctx, AVPacketSideData *sd) av_log(ctx, AV_LOG_INFO, " (inverted)"); } -static void dump_audioservicetype(void *ctx, AVPacketSideData *sd) +static void dump_audioservicetype(void *ctx, const AVPacketSideData *sd) { -enum AVAudioServiceType *ast = (enum AVAudioServiceType *)sd->data; +const enum AVAudioServiceType *ast = (const enum AVAudioServiceType *)sd->data; if (sd->size < sizeof(*ast)) { av_log(ctx, AV_LOG_ERROR, "invalid data"); @@ -311,9 +311,9 @@ static void dump_audioservicetype(void *ctx, AVPacketSideData *sd) } } -static void dump_cpb(void *ctx, AVPacketSideData *sd) +static void dump_cpb(void *ctx, const AVPacketSideData *sd) { -AVCPBProperties *cpb = (AVCPBProperties *)sd->data; +const AVCPBProperties *cpb = (const AVCPBProperties *)sd->data; if (sd->size < sizeof(*cpb)) { av_log(ctx, AV_LOG_ERROR, "invalid data"); @@ -334,8 +334,10 @@ static void dump_cpb(void *ctx, AVPacketSideData *sd) av_log(ctx, AV_LOG_INFO, "vbv_delay: %"PRIu64"", cpb->vbv_delay); } -static void dump_mastering_display_metadata(void *ctx, AVPacketSideData* sd) { -AVMasteringDisplayMetadata* metadata = (AVMasteringDisplayMetadata*)sd->data; +static void dump_mastering_display_metadata(void *ctx, const AVPacketSideData *sd) +{ +const AVMasteringDisplayMetadata *metadata = +(const AVMasteringDisplayMetadata *)sd->data; av_log(ctx, AV_LOG_INFO, "Mastering Display Metadata, " "has_primaries:%d has_luminance:%d " "r(%5.4f,%5.4f) g(%5.4f,%5.4f) b(%5.4f %5.4f) wp(%5.4f, %5.4f) " @@ -351,17 +353,19 @@ static void dump_mastering_display_metadata(void *ctx, AVPacketSideData* sd) { av_q2d(metadata->min_luminance), av_q2d(metadata->max_luminance)); } -static void dump_content_light_metadata(void *ctx, AVPacketSideData* sd) +static void dump_content_light_metadata(void *ctx, const AVPacketSideData *sd) { -AVContentLightMetadata* metadata = (AVContentLightMetadata*)sd->data; +const AVContentLightMetadata *metadata = +(const AVContentLightMetadata *)sd->data; av_log(ctx, AV_LOG_INFO, "Content Light Level Metadata, " "MaxCLL=%d, MaxFALL=%d", metadata->MaxCLL, metadata->MaxFALL); } -static void dump_spherical(void *ctx, AVCodecParameters *par, AVPacketSideData *sd) +static void dump_