| @@ -33,38 +33,6 @@ AVFilterBufferRef *ff_null_get_audio_buffer(AVFilterLink *link, int perms, · 32 unmodified lines |
| 33 | } | 33 | } |
| 34 | | 34 | |
| 35 | AVFilterBufferRef *ff_default_get_audio_buffer(AVFilterLink *link, int perms, | 35 | AVFilterBufferRef *ff_default_get_audio_buffer(AVFilterLink *link, int perms, |
| 36 | int nb_samples) | | |
| 37 | { | | |
| 38 | AVFilterBufferRef *samplesref = NULL; | | |
| 39 | int linesize[8] = {0}; | | |
| 40 | uint8_t *data[8] = {0}; | | |
| 41 | int ch, nb_channels = av_get_channel_layout_nb_channels(link->channel_layout); | | |
| 42 | | | |
| 43 | /* right now we don't support more than 8 channels */ | | |
| 44 | av_assert0(nb_channels <= 8); | | |
| 45 | | | |
| 46 | /* Calculate total buffer size, round to multiple of 16 to be SIMD friendly */ | | |
| 47 | if (av_samples_alloc(data, linesize, | | |
| 48 | nb_channels, nb_samples, | | |
| 49 | av_get_alt_sample_fmt(link->format, link->planar), | | |
| 50 | 16) < 0) | | |
| 51 | return NULL; | | |
| 52 | | | |
| 53 | for (ch = 1; link->planar && ch < nb_channels; ch++) | | |
| 54 | linesize[ch] = linesize[0]; | | |
| 55 | samplesref = | | |
| 56 | avfilter_get_audio_buffer_ref_from_arrays(data, linesize, perms, | | |
| 57 | nb_samples, link->format, | | |
| 58 | link->channel_layout, link->planar); | | |
| 59 | if (!samplesref) { | | |
| 60 | av_free(data[0]); | | |
| 61 | return NULL; | | |
| 62 | } | | |
| 63 | | | |
| 64 | return samplesref; | | |
| 65 | } | | |
| 66 | | | |
| 67 | static AVFilterBufferRef *ff_default_get_audio_buffer_alt(AVFilterLink *link, int perms, | | |
| 68 | int nb_samples) | 36 | int nb_samples) |
| 69 | { | 37 | { |
| 70 | AVFilterBufferRef *samplesref = NULL; | 38 | AVFilterBufferRef *samplesref = NULL; |
| @@ -80,7 +48,7 @@ static AVFilterBufferRef *ff_default_get_audio_buffer_alt(AVFilterLink *link, in · 9 unmodified lines |
| 80 | if (av_samples_alloc(data, &linesize, nb_channels, nb_samples, link->format, 0) < 0) | 48 | if (av_samples_alloc(data, &linesize, nb_channels, nb_samples, link->format, 0) < 0) |
| 81 | goto fail; | 49 | goto fail; |
| 82 | | 50 | |
| 83 | samplesref = avfilter_get_audio_buffer_ref_from_arrays_alt(data, linesize, perms, | 51 | samplesref = avfilter_get_audio_buffer_ref_from_arrays(data, linesize, perms, |
| 84 | nb_samples, link->format, | 52 | nb_samples, link->format, |
| 85 | link->channel_layout); | 53 | link->channel_layout); |
| 86 | if (!samplesref) | 54 | if (!samplesref) |
| @@ -112,49 +80,7 @@ AVFilterBufferRef *ff_get_audio_buffer(AVFilterLink *link, int perms, · 25 unmodified lines |
| 112 | return ret; | 80 | return ret; |
| 113 | } | 81 | } |
| 114 | | 82 | |
| 115 | AVFilterBufferRef * | 83 | AVFilterBufferRef* avfilter_get_audio_buffer_ref_from_arrays(uint8_t **data, |
| 116 | avfilter_get_audio_buffer_ref_from_arrays(uint8_t *data[8], int linesize[8], int perms, | | |
| 117 | int nb_samples, enum AVSampleFormat sample_fmt, | | |
| 118 | uint64_t channel_layout, int planar) | | |
| 119 | { | | |
| 120 | AVFilterBuffer *samples = av_mallocz(sizeof(AVFilterBuffer)); | | |
| 121 | AVFilterBufferRef *samplesref = av_mallocz(sizeof(AVFilterBufferRef)); | | |
| 122 | | | |
| 123 | if (!samples || !samplesref) | | |
| 124 | goto fail; | | |
| 125 | | | |
| 126 | samplesref->buf = samples; | | |
| 127 | samplesref->buf->free = ff_avfilter_default_free_buffer; | | |
| 128 | if (!(samplesref->audio = av_mallocz(sizeof(AVFilterBufferRefAudioProps)))) | | |
| 129 | goto fail; | | |
| 130 | | | |
| 131 | samplesref->audio->nb_samples = nb_samples; | | |
| 132 | samplesref->audio->channel_layout = channel_layout; | | |
| 133 | samplesref->audio->planar = planar; | | |
| 134 | | | |
| 135 | /* make sure the buffer gets read permission or it's useless for output */ | | |
| 136 | samplesref->perms = perms | AV_PERM_READ; | | |
| 137 | | | |
| 138 | samples->refcount = 1; | | |
| 139 | samplesref->type = AVMEDIA_TYPE_AUDIO; | | |
| 140 | samplesref->format = sample_fmt; | | |
| 141 | | | |
| 142 | memcpy(samples->data, data, sizeof(samples->data)); | | |
| 143 | memcpy(samples->linesize, linesize, sizeof(samples->linesize)); | | |
| 144 | memcpy(samplesref->data, data, sizeof(samplesref->data)); | | |
| 145 | memcpy(samplesref->linesize, linesize, sizeof(samplesref->linesize)); | | |
| 146 | | | |
| 147 | return samplesref; | | |
| 148 | | | |
| 149 | fail: | | |
| 150 | if (samplesref && samplesref->audio) | | |
| 151 | av_freep(&samplesref->audio); | | |
| 152 | av_freep(&samplesref); | | |
| 153 | av_freep(&samples); | | |
| 154 | return NULL; | | |
| 155 | } | | |
| 156 | | | |
| 157 | AVFilterBufferRef* avfilter_get_audio_buffer_ref_from_arrays_alt(uint8_t **data, | | |
| 158 | int linesize,int perms, | 84 | int linesize,int perms, |
| 159 | int nb_samples, | 85 | int nb_samples, |
| 160 | enum AVSampleFormat sample_fmt, | 86 | enum AVSampleFormat sample_fmt, |