aboutsummaryrefslogtreecommitdiffstats
path: root/libavformat
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2015-01-27 18:16:42 +0100
committerMichael Niedermayer <michaelni@gmx.at>2015-01-27 18:16:42 +0100
commit0bdcc27d9598254e79a80f1e016227778b428dbb (patch)
tree87c268fd30634dcb7323ebe0f9c2fcb54b3776f3 /libavformat
parent62a82c66cd3f03e045867471c5edcc84b4d2b54e (diff)
parent4227e4fe7443733fb906f6fb6c265105e8269c74 (diff)
downloadffmpeg-0bdcc27d9598254e79a80f1e016227778b428dbb.tar.gz
Merge commit '4227e4fe7443733fb906f6fb6c265105e8269c74'
* commit '4227e4fe7443733fb906f6fb6c265105e8269c74': lavf: add a convenience function for adding side data to a stream Conflicts: libavformat/internal.h libavformat/replaygain.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat')
-rw-r--r--libavformat/internal.h7
-rw-r--r--libavformat/replaygain.c26
-rw-r--r--libavformat/utils.c37
3 files changed, 47 insertions, 23 deletions
diff --git a/libavformat/internal.h b/libavformat/internal.h
index ce03dac3dd..d56644b8cf 100644
--- a/libavformat/internal.h
+++ b/libavformat/internal.h
@@ -391,6 +391,13 @@ static inline int ff_rename(const char *oldpath, const char *newpath, void *logc
}
/**
+ * Add new side data to a stream. If a side data of this type already exists, it
+ * is replaced.
+ */
+uint8_t *ff_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type,
+ int size);
+
+/**
* Allocate extradata with additional FF_INPUT_BUFFER_PADDING_SIZE at end
* which is always set to 0.
*
diff --git a/libavformat/replaygain.c b/libavformat/replaygain.c
index 8b8c81a0c3..807f851542 100644
--- a/libavformat/replaygain.c
+++ b/libavformat/replaygain.c
@@ -33,6 +33,7 @@
#include "libavutil/replaygain.h"
#include "avformat.h"
+#include "internal.h"
#include "replaygain.h"
static int32_t parse_value(const char *value, int32_t min)
@@ -69,37 +70,16 @@ static int32_t parse_value(const char *value, int32_t min)
int ff_replaygain_export_raw(AVStream *st, int32_t tg, uint32_t tp,
int32_t ag, uint32_t ap)
{
- AVPacketSideData *sd, *tmp;
AVReplayGain *replaygain;
- int i;
if (tg == INT32_MIN && ag == INT32_MIN)
return 0;
- for (i = 0; i < st->nb_side_data; i++) {
- AVPacketSideData *src_sd = &st->side_data[i];
-
- if (src_sd->type == AV_PKT_DATA_REPLAYGAIN)
- return 0;
- }
-
- replaygain = av_mallocz(sizeof(*replaygain));
+ replaygain = (AVReplayGain*)ff_stream_new_side_data(st, AV_PKT_DATA_REPLAYGAIN,
+ sizeof(*replaygain));
if (!replaygain)
return AVERROR(ENOMEM);
- tmp = av_realloc_array(st->side_data, st->nb_side_data + 1, sizeof(*tmp));
- if (!tmp) {
- av_freep(&replaygain);
- return AVERROR(ENOMEM);
- }
- st->side_data = tmp;
- st->nb_side_data++;
-
- sd = &st->side_data[st->nb_side_data - 1];
- sd->type = AV_PKT_DATA_REPLAYGAIN;
- sd->data = (uint8_t*)replaygain;
- sd->size = sizeof(*replaygain);
-
replaygain->track_gain = tg;
replaygain->track_peak = tp;
replaygain->album_gain = ag;
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 11247838ea..f6df49bf0f 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -4433,3 +4433,40 @@ uint8_t *av_stream_get_side_data(AVStream *st, enum AVPacketSideDataType type,
}
return NULL;
}
+
+uint8_t *ff_stream_new_side_data(AVStream *st, enum AVPacketSideDataType type,
+ int size)
+{
+ AVPacketSideData *sd, *tmp;
+ int i;
+ uint8_t *data = av_malloc(size);
+
+ if (!data)
+ return NULL;
+
+ for (i = 0; i < st->nb_side_data; i++) {
+ sd = &st->side_data[i];
+
+ if (sd->type == type) {
+ av_freep(&sd->data);
+ sd->data = data;
+ sd->size = size;
+ return sd->data;
+ }
+ }
+
+ tmp = av_realloc_array(st->side_data, st->nb_side_data + 1, sizeof(*tmp));
+ if (!tmp) {
+ av_freep(&data);
+ return NULL;
+ }
+
+ st->side_data = tmp;
+ st->nb_side_data++;
+
+ sd = &st->side_data[st->nb_side_data - 1];
+ sd->type = type;
+ sd->data = data;
+ sd->size = size;
+ return data;
+}