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

Unified · Split

libavfilter/defaults.c+4−34
@@ -86,8 +86,7 @@ AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int per · 85 unmodified lines
86{86{
87 AVFilterBuffer *samples = av_mallocz(sizeof(AVFilterBuffer));87 AVFilterBuffer *samples = av_mallocz(sizeof(AVFilterBuffer));
88 AVFilterBufferRef *ref = NULL;88 AVFilterBufferRef *ref = NULL;
89 int i, sample_size, chans_nb, bufsize, per_channel_size, step_size = 0;89 int nb_channels = av_get_channel_layout_nb_channels(channel_layout);
90 char *buf;
91 90
92 if (!samples || !(ref = av_mallocz(sizeof(AVFilterBufferRef))))91 if (!samples || !(ref = av_mallocz(sizeof(AVFilterBufferRef))))
93 goto fail;92 goto fail;
@@ -109,41 +108,12 @@ AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int per · 15 unmodified lines
109 samples->refcount = 1;108 samples->refcount = 1;
110 samples->free = ff_avfilter_default_free_buffer;109 samples->free = ff_avfilter_default_free_buffer;
111 110
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
125 /* Calculate total buffer size, round to multiple of 16 to be SIMD friendly */111 /* Calculate total buffer size, round to multiple of 16 to be SIMD friendly */
126 bufsize = (nb_samples * chans_nb * sample_size + 15)&~15;112 if (av_samples_alloc(samples->data, samples->linesize,
127 buf = av_malloc(bufsize);113 nb_channels, nb_samples, sample_fmt,
128 if (!buf)114 planar, 16) < 0)
129 goto fail;115 goto fail;
130 116
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
147 memcpy(ref->data, samples->data, sizeof(ref->data));117 memcpy(ref->data, samples->data, sizeof(ref->data));
148 memcpy(ref->linesize, samples->linesize, sizeof(ref->linesize));118 memcpy(ref->linesize, samples->linesize, sizeof(ref->linesize));
149 119

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