aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil/samplefmt.c
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2012-05-06 14:10:38 +0200
committerAnton Khirnov <anton@khirnov.net>2012-05-09 17:43:26 +0200
commit142e740d1ecc6059556f2748a18757d399ee061f (patch)
tree556cb9a5adaf71e1dec853849c54615ecfff9328 /libavutil/samplefmt.c
parent9684341346fd5aad436325529cade47966c4731b (diff)
downloadffmpeg-142e740d1ecc6059556f2748a18757d399ee061f.tar.gz
samplefmt: add a function for copying audio samples.
Diffstat (limited to 'libavutil/samplefmt.c')
-rw-r--r--libavutil/samplefmt.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/libavutil/samplefmt.c b/libavutil/samplefmt.c
index 711afac287..4d94fa69be 100644
--- a/libavutil/samplefmt.c
+++ b/libavutil/samplefmt.c
@@ -185,3 +185,22 @@ int av_samples_alloc(uint8_t **audio_data, int *linesize, int nb_channels,
}
return 0;
}
+
+int av_samples_copy(uint8_t **dst, uint8_t * const *src, int dst_offset,
+ int src_offset, int nb_samples, int nb_channels,
+ enum AVSampleFormat sample_fmt)
+{
+ int planar = av_sample_fmt_is_planar(sample_fmt);
+ int planes = planar ? nb_channels : 1;
+ int block_align = av_get_bytes_per_sample(sample_fmt) * (planar ? 1 : nb_channels);
+ int data_size = nb_samples * block_align;
+ int i;
+
+ dst_offset *= block_align;
+ src_offset *= block_align;
+
+ for (i = 0; i < planes; i++)
+ memcpy(dst[i] + dst_offset, src[i] + src_offset, data_size);
+
+ return 0;
+}