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
6666 return db * 100000 + sign * mb;
6767 }
6868
69−static int replaygain_export(AVStream *st,
70− const uint8_t *track_gain, const uint8_t *track_peak,
71− const uint8_t *album_gain, const uint8_t *album_peak)
69+int ff_replaygain_export_raw(AVStream *st, int32_t tg, uint32_t tp,
70+ int32_t ag, uint32_t ap)
7271 {
7372 AVPacketSideData *sd, *tmp;
7473 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);
8274
8375 if (tg == INT32_MIN && ag == INT32_MIN)
8476 return 0;
8577
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+
8685 replaygain = av_mallocz(sizeof(*replaygain));
8786 if (!replaygain)
8887 return AVERROR(ENOMEM);
@@ -117,9 +116,9 @@ int ff_replaygain_export(AVStream *st, AVDictionary *metadata) · 28 unmodified lines
117116 ag = av_dict_get(metadata, "REPLAYGAIN_ALBUM_GAIN", NULL, 0);
118117 ap = av_dict_get(metadata, "REPLAYGAIN_ALBUM_PEAK", NULL, 0);
119118
120− return replaygain_export(st,
121− tg ? tg->value : NULL,
122− tp ? tp->value : NULL,
123− ag ? ag->value : NULL,
124− ap ? ap->value : NULL);
119+ return ff_replaygain_export_raw(st,
120+ parse_value(tg ? tg->value : NULL, INT32_MIN),
121+ parse_value(tp ? tp->value : NULL, 0),
122+ parse_value(ag ? ag->value : NULL, INT32_MIN),
123+ parse_value(ap ? ap->value : NULL, 0));
125124 }
libavformat/replaygain.h+7−0
@@ -28,4 +28,11 @@ · 27 unmodified lines
2828 */
2929 int ff_replaygain_export(AVStream *st, AVDictionary *metadata);
3030
31+
32+/**
33+ * Export already decoded replaygain values as per-stream side data.
34+ */
35+int ff_replaygain_export_raw(AVStream *st, int32_t tg, uint32_t tp,
36+ int32_t ag, uint32_t ap);
37+
3138 #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