History

replaygain: allow exporting already decoded replaygain values

This adds a function to export raw replaygain values (i.e. in the (u)int32_t form). It first checks whether AV_PKT_DATA_REPLAYGAIN side data is present, in which case it does nothing.

Alessandro Ghedini committed 12 years ago

Commit ae43c101 parent 21d8f4d2 files · +21 −15Browse files

Unified · Split

2 files
  1. libavformat/replaygain.c +14 −15
  2. libavformat/replaygain.h +7 −0
libavformat/replaygain.c+14−15
@@ -66,23 +66,22 @@ static int32_t parse_value(const char *value, int32_t min) · 65 unmodified lines
66 return db * 100000 + sign * mb;66 return db * 100000 + sign * mb;
67}67}
68 68
69static int replaygain_export(AVStream *st,69int ff_replaygain_export_raw(AVStream *st, int32_t tg, uint32_t tp,
70 const uint8_t *track_gain, const uint8_t *track_peak,70 int32_t ag, uint32_t ap)
71 const uint8_t *album_gain, const uint8_t *album_peak)
72{71{
73 AVPacketSideData *sd, *tmp;72 AVPacketSideData *sd, *tmp;
74 AVReplayGain *replaygain;73 AVReplayGain *replaygain;
75 int32_t tg, ag;
76 uint32_t tp, ap;
77
78 tg = parse_value(track_gain, INT32_MIN);
79 ag = parse_value(album_gain, INT32_MIN);
80 tp = parse_value(track_peak, 0);
81 ap = parse_value(album_peak, 0);
82 74
83 if (tg == INT32_MIN && ag == INT32_MIN)75 if (tg == INT32_MIN && ag == INT32_MIN)
84 return 0;76 return 0;
85 77
78 for (int i = 0; i < st->nb_side_data; i++) {
79 AVPacketSideData *src_sd = &st->side_data[i];
80
81 if (src_sd->type == AV_PKT_DATA_REPLAYGAIN)
82 return 0;
83 }
84
86 replaygain = av_mallocz(sizeof(*replaygain));85 replaygain = av_mallocz(sizeof(*replaygain));
87 if (!replaygain)86 if (!replaygain)
88 return AVERROR(ENOMEM);87 return AVERROR(ENOMEM);
@@ -117,9 +116,9 @@ int ff_replaygain_export(AVStream *st, AVDictionary *metadata) · 28 unmodified lines
117 ag = av_dict_get(metadata, "REPLAYGAIN_ALBUM_GAIN", NULL, 0);116 ag = av_dict_get(metadata, "REPLAYGAIN_ALBUM_GAIN", NULL, 0);
118 ap = av_dict_get(metadata, "REPLAYGAIN_ALBUM_PEAK", NULL, 0);117 ap = av_dict_get(metadata, "REPLAYGAIN_ALBUM_PEAK", NULL, 0);
119 118
120 return replaygain_export(st,119 return ff_replaygain_export_raw(st,
121 tg ? tg->value : NULL,120 parse_value(tg ? tg->value : NULL, INT32_MIN),
122 tp ? tp->value : NULL,121 parse_value(tp ? tp->value : NULL, 0),
123 ag ? ag->value : NULL,122 parse_value(ag ? ag->value : NULL, INT32_MIN),
124 ap ? ap->value : NULL);123 parse_value(ap ? ap->value : NULL, 0));
125}124}
libavformat/replaygain.h+7−0
@@ -28,4 +28,11 @@ · 27 unmodified lines
28 */28 */
29int ff_replaygain_export(AVStream *st, AVDictionary *metadata);29int ff_replaygain_export(AVStream *st, AVDictionary *metadata);
30 30
31
32/**
33 * Export already decoded replaygain values as per-stream side data.
34 */
35int ff_replaygain_export_raw(AVStream *st, int32_t tg, uint32_t tp,
36 int32_t ag, uint32_t ap);
37
31#endif /* AVFORMAT_REPLAYGAIN_H */38#endif /* AVFORMAT_REPLAYGAIN_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t