Showing the changes to libavfilter (1 of 1 file). Show all
Unified · Split
| @@ -86,8 +86,7 @@ AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int per · 85 unmodified lines | ||
| 86 | 86 | { |
| 87 | 87 | AVFilterBuffer *samples = av_mallocz(sizeof(AVFilterBuffer)); |
| 88 | 88 | 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); | |
| 91 | 90 | |
| 92 | 91 | if (!samples || !(ref = av_mallocz(sizeof(AVFilterBufferRef)))) |
| 93 | 92 | goto fail; |
| @@ -109,41 +108,12 @@ AVFilterBufferRef *avfilter_default_get_audio_buffer(AVFilterLink *link, int per · 15 unmodified lines | ||
| 109 | 108 | samples->refcount = 1; |
| 110 | 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 | 111 | /* 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) | |
| 129 | 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 | 117 | memcpy(ref->data, samples->data, sizeof(ref->data)); |
| 148 | 118 | memcpy(ref->linesize, samples->linesize, sizeof(ref->linesize)); |
| 149 | 119 | |