History

lavfi: use av_samples_alloc() in avfilter_default_get_audio_buffer()

Stefano Sabatini committed 15 years ago

Commit ef28c7b1 parent 95a02421 file · +4 −34Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/defaults.c+4−34
@@ -86,8 +86,7 @@ AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int per · 85 unmodified lines
8686 {
8787 AVFilterBuffer *samples = av_mallocz(sizeof(AVFilterBuffer));
8888 AVFilterBufferRef *ref = NULL;
89− int i, sample_size, chans_nb, bufsize, per_channel_size, step_size = 0;
90− char *buf;
89+ int nb_channels = av_get_channel_layout_nb_channels(channel_layout);
9190
9291 if (!samples || !(ref = av_mallocz(sizeof(AVFilterBufferRef))))
9392 goto fail;
@@ -109,41 +108,12 @@ AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int per · 15 unmodified lines
109108 samples->refcount = 1;
110109 samples->free = ff_avfilter_default_free_buffer;
111110
112− sample_size = av_get_bits_per_sample_fmt(sample_fmt) >>3;
113− chans_nb = av_get_channel_layout_nb_channels(channel_layout);
114−
115− per_channel_size = nb_samples * sample_size;
116−
117− /* Set the number of bytes to traverse to reach next sample of a particular channel:
118− * For planar, this is simply the sample size.
119− * For packed, this is the number of samples * sample_size.
120− */
121− for (i = 0; i < chans_nb; i++)
122− samples->linesize[i] = planar > 0 ? per_channel_size : sample_size;
123− memset(&samples->linesize[chans_nb], 0, (8-chans_nb) * sizeof(samples->linesize[0]));
124−
125111 /* Calculate total buffer size, round to multiple of 16 to be SIMD friendly */
126− bufsize = (nb_samples * chans_nb * sample_size + 15)&~15;
127− buf = av_malloc(bufsize);
128− if (!buf)
112+ if (av_samples_alloc(samples->data, samples->linesize,
113+ nb_channels, nb_samples, sample_fmt,
114+ planar, 16) < 0)
129115 goto fail;
130116
131− /* For planar, set the start point of each channel's data within the buffer
132− * For packed, set the start point of the entire buffer only
133− */
134− samples->data[0] = buf;
135− if (buf && planar) {
136− for (i = 1; i < chans_nb; i++) {
137− step_size += per_channel_size;
138− samples->data[i] = buf + step_size;
139− }
140− } else {
141− for (i = 1; i < chans_nb; i++)
142− samples->data[i] = buf;
143− }
144−
145− memset(&samples->data[chans_nb], 0, (8-chans_nb) * sizeof(samples->data[0]));
146−
147117 memcpy(ref->data, samples->data, sizeof(ref->data));
148118 memcpy(ref->linesize, samples->linesize, sizeof(ref->linesize));
149119

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