Unified · Split
| @@ -311,9 +311,7 @@ static int output_frame(AVFilterLink *outlink, int nb_samples) · 310 unmodified lines | ||
| 311 | 311 | if (s->next_pts != AV_NOPTS_VALUE) |
| 312 | 312 | s->next_pts += nb_samples; |
| 313 | 313 | |
| 314 | − ff_filter_samples(outlink, out_buf); | |
| 315 | − | |
| 316 | − return 0; | |
| 314 | + return ff_filter_samples(outlink, out_buf); | |
| 317 | 315 | } |
| 318 | 316 | |
| 319 | 317 | /** |
| @@ -454,31 +452,37 @@ static int request_frame(AVFilterLink *outlink) · 134 unmodified lines | ||
| 454 | 452 | return output_frame(outlink, available_samples); |
| 455 | 453 | } |
| 456 | 454 | |
| 457 | −static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) | |
| 455 | +static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) | |
| 458 | 456 | { |
| 459 | 457 | AVFilterContext *ctx = inlink->dst; |
| 460 | 458 | MixContext *s = ctx->priv; |
| 461 | 459 | AVFilterLink *outlink = ctx->outputs[0]; |
| 462 | − int i; | |
| 460 | + int i, ret = 0; | |
| 463 | 461 | |
| 464 | 462 | for (i = 0; i < ctx->nb_inputs; i++) |
| 465 | 463 | if (ctx->inputs[i] == inlink) |
| 466 | 464 | break; |
| 467 | 465 | if (i >= ctx->nb_inputs) { |
| 468 | 466 | av_log(ctx, AV_LOG_ERROR, "unknown input link\n"); |
| 469 | − return; | |
| 467 | + ret = AVERROR(EINVAL); | |
| 468 | + goto fail; | |
| 470 | 469 | } |
| 471 | 470 | |
| 472 | 471 | if (i == 0) { |
| 473 | 472 | int64_t pts = av_rescale_q(buf->pts, inlink->time_base, |
| 474 | 473 | outlink->time_base); |
| 475 | − frame_list_add_frame(s->frame_list, buf->audio->nb_samples, pts); | |
| 474 | + ret = frame_list_add_frame(s->frame_list, buf->audio->nb_samples, pts); | |
| 475 | + if (ret < 0) | |
| 476 | + goto fail; | |
| 476 | 477 | } |
| 477 | 478 | |
| 478 | − av_audio_fifo_write(s->fifos[i], (void **)buf->extended_data, | |
| 479 | − buf->audio->nb_samples); | |
| 479 | + ret = av_audio_fifo_write(s->fifos[i], (void **)buf->extended_data, | |
| 480 | + buf->audio->nb_samples); | |
| 480 | 481 | |
| 482 | +fail: | |
| 481 | 483 | avfilter_unref_buffer(buf); |
| 484 | + | |
| 485 | + return ret; | |
| 482 | 486 | } |
| 483 | 487 | |
| 484 | 488 | static int init(AVFilterContext *ctx, const char *args) |
| @@ -136,18 +136,18 @@ static int request_frame(AVFilterLink *link) · 135 unmodified lines | ||
| 136 | 136 | avresample_convert(s->avr, (void**)buf->extended_data, buf->linesize[0], |
| 137 | 137 | nb_samples, NULL, 0, 0); |
| 138 | 138 | buf->pts = s->pts; |
| 139 | − ff_filter_samples(link, buf); | |
| 140 | − return 0; | |
| 139 | + return ff_filter_samples(link, buf); | |
| 141 | 140 | } |
| 142 | 141 | |
| 143 | 142 | return ret; |
| 144 | 143 | } |
| 145 | 144 | |
| 146 | −static void write_to_fifo(ASyncContext *s, AVFilterBufferRef *buf) | |
| 145 | +static int write_to_fifo(ASyncContext *s, AVFilterBufferRef *buf) | |
| 147 | 146 | { |
| 148 | − avresample_convert(s->avr, NULL, 0, 0, (void**)buf->extended_data, | |
| 149 | − buf->linesize[0], buf->audio->nb_samples); | |
| 147 | + int ret = avresample_convert(s->avr, NULL, 0, 0, (void**)buf->extended_data, | |
| 148 | + buf->linesize[0], buf->audio->nb_samples); | |
| 150 | 149 | avfilter_unref_buffer(buf); |
| 150 | + return ret; | |
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /* get amount of data currently buffered, in samples */ |
| @@ -156,7 +156,7 @@ static int64_t get_delay(ASyncContext *s) · 2 unmodified lines | ||
| 156 | 156 | return avresample_available(s->avr) + avresample_get_delay(s->avr); |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | −static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) | |
| 159 | +static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) | |
| 160 | 160 | { |
| 161 | 161 | AVFilterContext *ctx = inlink->dst; |
| 162 | 162 | ASyncContext *s = ctx->priv; |
| @@ -164,7 +164,7 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) · 1 unmodified line | ||
| 164 | 164 | int nb_channels = av_get_channel_layout_nb_channels(buf->audio->channel_layout); |
| 165 | 165 | int64_t pts = (buf->pts == AV_NOPTS_VALUE) ? buf->pts : |
| 166 | 166 | av_rescale_q(buf->pts, inlink->time_base, outlink->time_base); |
| 167 | − int out_size; | |
| 167 | + int out_size, ret; | |
| 168 | 168 | int64_t delta; |
| 169 | 169 | |
| 170 | 170 | /* buffer data until we get the first timestamp */ |
| @@ -172,14 +172,12 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) · 1 unmodified line | ||
| 172 | 172 | if (pts != AV_NOPTS_VALUE) { |
| 173 | 173 | s->pts = pts - get_delay(s); |
| 174 | 174 | } |
| 175 | − write_to_fifo(s, buf); | |
| 176 | − return; | |
| 175 | + return write_to_fifo(s, buf); | |
| 177 | 176 | } |
| 178 | 177 | |
| 179 | 178 | /* now wait for the next timestamp */ |
| 180 | 179 | if (pts == AV_NOPTS_VALUE) { |
| 181 | − write_to_fifo(s, buf); | |
| 182 | − return; | |
| 180 | + return write_to_fifo(s, buf); | |
| 183 | 181 | } |
| 184 | 182 | |
| 185 | 183 | /* when we have two timestamps, compute how many samples would we have |
| @@ -202,8 +200,10 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) · 16 unmodified lines | ||
| 202 | 200 | if (out_size > 0) { |
| 203 | 201 | AVFilterBufferRef *buf_out = ff_get_audio_buffer(outlink, AV_PERM_WRITE, |
| 204 | 202 | out_size); |
| 205 | − if (!buf_out) | |
| 206 | − return; | |
| 203 | + if (!buf_out) { | |
| 204 | + ret = AVERROR(ENOMEM); | |
| 205 | + goto fail; | |
| 206 | + } | |
| 207 | 207 | |
| 208 | 208 | avresample_read(s->avr, (void**)buf_out->extended_data, out_size); |
| 209 | 209 | buf_out->pts = s->pts; |
| @@ -212,7 +212,9 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) · 2 unmodified lines | ||
| 212 | 212 | av_samples_set_silence(buf_out->extended_data, out_size - delta, |
| 213 | 213 | delta, nb_channels, buf->format); |
| 214 | 214 | } |
| 215 | − ff_filter_samples(outlink, buf_out); | |
| 215 | + ret = ff_filter_samples(outlink, buf_out); | |
| 216 | + if (ret < 0) | |
| 217 | + goto fail; | |
| 216 | 218 | s->got_output = 1; |
| 217 | 219 | } else { |
| 218 | 220 | av_log(ctx, AV_LOG_WARNING, "Non-monotonous timestamps, dropping " |
| @@ -223,9 +225,13 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) · 4 unmodified lines | ||
| 223 | 225 | avresample_read(s->avr, NULL, avresample_available(s->avr)); |
| 224 | 226 | |
| 225 | 227 | s->pts = pts - avresample_get_delay(s->avr); |
| 226 | − avresample_convert(s->avr, NULL, 0, 0, (void**)buf->extended_data, | |
| 227 | − buf->linesize[0], buf->audio->nb_samples); | |
| 228 | + ret = avresample_convert(s->avr, NULL, 0, 0, (void**)buf->extended_data, | |
| 229 | + buf->linesize[0], buf->audio->nb_samples); | |
| 230 | + | |
| 231 | +fail: | |
| 228 | 232 | avfilter_unref_buffer(buf); |
| 233 | + | |
| 234 | + return ret; | |
| 229 | 235 | } |
| 230 | 236 | |
| 231 | 237 | AVFilter avfilter_af_asyncts = { |
| @@ -313,7 +313,7 @@ static int channelmap_query_formats(AVFilterContext *ctx) · 312 unmodified lines | ||
| 313 | 313 | return 0; |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | −static void channelmap_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) | |
| 316 | +static int channelmap_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) | |
| 317 | 317 | { |
| 318 | 318 | AVFilterContext *ctx = inlink->dst; |
| 319 | 319 | AVFilterLink *outlink = ctx->outputs[0]; |
| @@ -330,8 +330,10 @@ static void channelmap_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *b · 10 unmodified lines | ||
| 330 | 330 | if (nch_out > FF_ARRAY_ELEMS(buf->data)) { |
| 331 | 331 | uint8_t **new_extended_data = |
| 332 | 332 | av_mallocz(nch_out * sizeof(*buf->extended_data)); |
| 333 | − if (!new_extended_data) | |
| 334 | − return; | |
| 333 | + if (!new_extended_data) { | |
| 334 | + avfilter_unref_buffer(buf); | |
| 335 | + return AVERROR(ENOMEM); | |
| 336 | + } | |
| 335 | 337 | if (buf->extended_data == buf->data) { |
| 336 | 338 | buf->extended_data = new_extended_data; |
| 337 | 339 | } else { |
| @@ -353,7 +355,7 @@ static void channelmap_filter_samples(AVFilterLink *inlink, AVFilterBufferRef *b · 15 unmodified lines | ||
| 353 | 355 | memcpy(buf->data, buf->extended_data, |
| 354 | 356 | FFMIN(FF_ARRAY_ELEMS(buf->data), nch_out) * sizeof(buf->data[0])); |
| 355 | 357 | |
| 356 | − ff_filter_samples(outlink, buf); | |
| 358 | + return ff_filter_samples(outlink, buf); | |
| 357 | 359 | } |
| 358 | 360 | |
| 359 | 361 | static int channelmap_config_input(AVFilterLink *inlink) |
| @@ -110,24 +110,29 @@ static int query_formats(AVFilterContext *ctx) · 109 unmodified lines | ||
| 110 | 110 | return 0; |
| 111 | 111 | } |
| 112 | 112 | |
| 113 | −static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) | |
| 113 | +static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) | |
| 114 | 114 | { |
| 115 | 115 | AVFilterContext *ctx = inlink->dst; |
| 116 | − int i; | |
| 116 | + int i, ret = 0; | |
| 117 | 117 | |
| 118 | 118 | for (i = 0; i < ctx->nb_outputs; i++) { |
| 119 | 119 | AVFilterBufferRef *buf_out = avfilter_ref_buffer(buf, ~AV_PERM_WRITE); |
| 120 | 120 | |
| 121 | − if (!buf_out) | |
| 122 | − return; | |
| 121 | + if (!buf_out) { | |
| 122 | + ret = AVERROR(ENOMEM); | |
| 123 | + break; | |
| 124 | + } | |
| 123 | 125 | |
| 124 | 126 | buf_out->data[0] = buf_out->extended_data[0] = buf_out->extended_data[i]; |
| 125 | 127 | buf_out->audio->channel_layout = |
| 126 | 128 | av_channel_layout_extract_channel(buf->audio->channel_layout, i); |
| 127 | 129 | |
| 128 | − ff_filter_samples(ctx->outputs[i], buf_out); | |
| 130 | + ret = ff_filter_samples(ctx->outputs[i], buf_out); | |
| 131 | + if (ret < 0) | |
| 132 | + break; | |
| 129 | 133 | } |
| 130 | 134 | avfilter_unref_buffer(buf); |
| 135 | + return ret; | |
| 131 | 136 | } |
| 132 | 137 | |
| 133 | 138 | AVFilter avfilter_af_channelsplit = { |
| @@ -92,7 +92,7 @@ static const AVClass join_class = { · 91 unmodified lines | ||
| 92 | 92 | .version = LIBAVUTIL_VERSION_INT, |
| 93 | 93 | }; |
| 94 | 94 | |
| 95 | −static void filter_samples(AVFilterLink *link, AVFilterBufferRef *buf) | |
| 95 | +static int filter_samples(AVFilterLink *link, AVFilterBufferRef *buf) | |
| 96 | 96 | { |
| 97 | 97 | AVFilterContext *ctx = link->dst; |
| 98 | 98 | JoinContext *s = ctx->priv; |
| @@ -104,6 +104,8 @@ static void filter_samples(AVFilterLink *link, AVFilterBufferRef *buf) · 5 unmodified lines | ||
| 104 | 104 | av_assert0(i < ctx->nb_inputs); |
| 105 | 105 | av_assert0(!s->input_frames[i]); |
| 106 | 106 | s->input_frames[i] = buf; |
| 107 | + | |
| 108 | + return 0; | |
| 107 | 109 | } |
| 108 | 110 | |
| 109 | 111 | static int parse_maps(AVFilterContext *ctx) |
| @@ -468,11 +470,11 @@ static int join_request_frame(AVFilterLink *outlink) · 358 unmodified lines | ||
| 468 | 470 | priv->nb_in_buffers = ctx->nb_inputs; |
| 469 | 471 | buf->buf->priv = priv; |
| 470 | 472 | |
| 471 | − ff_filter_samples(outlink, buf); | |
| 473 | + ret = ff_filter_samples(outlink, buf); | |
| 472 | 474 | |
| 473 | 475 | memset(s->input_frames, 0, sizeof(*s->input_frames) * ctx->nb_inputs); |
| 474 | 476 | |
| 475 | − return 0; | |
| 477 | + return ret; | |
| 476 | 478 | |
| 477 | 479 | fail: |
| 478 | 480 | avfilter_unref_buffer(buf); |
| @@ -157,21 +157,21 @@ static int request_frame(AVFilterLink *outlink) · 156 unmodified lines | ||
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | buf->pts = s->next_pts; |
| 160 | − ff_filter_samples(outlink, buf); | |
| 161 | − return 0; | |
| 160 | + return ff_filter_samples(outlink, buf); | |
| 162 | 161 | } |
| 163 | 162 | return ret; |
| 164 | 163 | } |
| 165 | 164 | |
| 166 | −static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) | |
| 165 | +static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) | |
| 167 | 166 | { |
| 168 | 167 | AVFilterContext *ctx = inlink->dst; |
| 169 | 168 | ResampleContext *s = ctx->priv; |
| 170 | 169 | AVFilterLink *outlink = ctx->outputs[0]; |
| 170 | + int ret; | |
| 171 | 171 | |
| 172 | 172 | if (s->avr) { |
| 173 | 173 | AVFilterBufferRef *buf_out; |
| 174 | − int delay, nb_samples, ret; | |
| 174 | + int delay, nb_samples; | |
| 175 | 175 | |
| 176 | 176 | /* maximum possible samples lavr can output */ |
| 177 | 177 | delay = avresample_get_delay(s->avr); |
| @@ -180,10 +180,19 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) · 2 unmodified lines | ||
| 180 | 180 | AV_ROUND_UP); |
| 181 | 181 | |
| 182 | 182 | buf_out = ff_get_audio_buffer(outlink, AV_PERM_WRITE, nb_samples); |
| 183 | + if (!buf_out) { | |
| 184 | + ret = AVERROR(ENOMEM); | |
| 185 | + goto fail; | |
| 186 | + } | |
| 187 | + | |
| 183 | 188 | ret = avresample_convert(s->avr, (void**)buf_out->extended_data, |
| 184 | 189 | buf_out->linesize[0], nb_samples, |
| 185 | 190 | (void**)buf->extended_data, buf->linesize[0], |
| 186 | 191 | buf->audio->nb_samples); |
| 192 | + if (ret < 0) { | |
| 193 | + avfilter_unref_buffer(buf_out); | |
| 194 | + goto fail; | |
| 195 | + } | |
| 187 | 196 | |
| 188 | 197 | av_assert0(!avresample_available(s->avr)); |
| 189 | 198 | |
| @@ -209,14 +218,18 @@ static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *buf) · 19 unmodified lines | ||
| 209 | 218 | |
| 210 | 219 | s->next_pts = buf_out->pts + buf_out->audio->nb_samples; |
| 211 | 220 | |
| 212 | − ff_filter_samples(outlink, buf_out); | |
| 221 | + ret = ff_filter_samples(outlink, buf_out); | |
| 213 | 222 | s->got_output = 1; |
| 214 | 223 | } |
| 224 | + | |
| 225 | +fail: | |
| 215 | 226 | avfilter_unref_buffer(buf); |
| 216 | 227 | } else { |
| 217 | − ff_filter_samples(outlink, buf); | |
| 228 | + ret = ff_filter_samples(outlink, buf); | |
| 218 | 229 | s->got_output = 1; |
| 219 | 230 | } |
| 231 | + | |
| 232 | + return ret; | |
| 220 | 233 | } |
| 221 | 234 | |
| 222 | 235 | AVFilter avfilter_af_resample = { |
| @@ -19,7 +19,10 @@ · 18 unmodified lines | ||
| 19 | 19 | #include "avfilter.h" |
| 20 | 20 | #include "internal.h" |
| 21 | 21 | |
| 22 | −static void null_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) { } | |
| 22 | +static int null_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) | |
| 23 | +{ | |
| 24 | + return 0; | |
| 25 | +} | |
| 23 | 26 | |
| 24 | 27 | AVFilter avfilter_asink_anullsink = { |
| 25 | 28 | .name = "anullsink", |
| @@ -146,15 +146,15 @@ fail: · 145 unmodified lines | ||
| 146 | 146 | return NULL; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | −static void default_filter_samples(AVFilterLink *link, | |
| 150 | − AVFilterBufferRef *samplesref) | |
| 149 | +static int default_filter_samples(AVFilterLink *link, | |
| 150 | + AVFilterBufferRef *samplesref) | |
| 151 | 151 | { |
| 152 | − ff_filter_samples(link->dst->outputs[0], samplesref); | |
| 152 | + return ff_filter_samples(link->dst->outputs[0], samplesref); | |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | −void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) | |
| 155 | +int ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) | |
| 156 | 156 | { |
| 157 | − void (*filter_samples)(AVFilterLink *, AVFilterBufferRef *); | |
| 157 | + int (*filter_samples)(AVFilterLink *, AVFilterBufferRef *); | |
| 158 | 158 | AVFilterPad *dst = link->dstpad; |
| 159 | 159 | AVFilterBufferRef *buf_out; |
| 160 | 160 | |
| @@ -185,6 +185,6 @@ void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref) · 24 unmodified lines | ||
| 185 | 185 | } else |
| 186 | 186 | buf_out = samplesref; |
| 187 | 187 | |
| 188 | − filter_samples(link, buf_out); | |
| 188 | + return filter_samples(link, buf_out); | |
| 189 | 189 | } |
| 190 | 190 | |
| @@ -49,7 +49,10 @@ AVFilterBufferRef *ff_get_audio_buffer(AVFilterLink *link, int perms, · 48 unmodified lines | ||
| 49 | 49 | * @param samplesref a reference to the buffer of audio samples being sent. The |
| 50 | 50 | * receiving filter will free this reference when it no longer |
| 51 | 51 | * needs it or pass it on to the next filter. |
| 52 | + * | |
| 53 | + * @return >= 0 on success, a negative AVERROR on error. The receiving filter | |
| 54 | + * is responsible for unreferencing samplesref in case of error. | |
| 52 | 55 | */ |
| 53 | −void ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref); | |
| 56 | +int ff_filter_samples(AVFilterLink *link, AVFilterBufferRef *samplesref); | |
| 54 | 57 | |
| 55 | 58 | #endif /* AVFILTER_AUDIO_H */ |
| @@ -288,8 +288,12 @@ struct AVFilterPad { · 287 unmodified lines | ||
| 288 | 288 | * and should do its processing. |
| 289 | 289 | * |
| 290 | 290 | * Input audio pads only. |
| 291 | + * | |
| 292 | + * @return >= 0 on success, a negative AVERROR on error. This function | |
| 293 | + * must ensure that samplesref is properly unreferenced on error if it | |
| 294 | + * hasn't been passed on to another filter. | |
| 291 | 295 | */ |
| 292 | − void (*filter_samples)(AVFilterLink *link, AVFilterBufferRef *samplesref); | |
| 296 | + int (*filter_samples)(AVFilterLink *link, AVFilterBufferRef *samplesref); | |
| 293 | 297 | |
| 294 | 298 | /** |
| 295 | 299 | * Frame poll callback. This returns the number of immediately available |
| @@ -56,6 +56,12 @@ static void start_frame(AVFilterLink *link, AVFilterBufferRef *buf) · 55 unmodified lines | ||
| 56 | 56 | link->cur_buf = NULL; |
| 57 | 57 | }; |
| 58 | 58 | |
| 59 | +static int filter_samples(AVFilterLink *link, AVFilterBufferRef *buf) | |
| 60 | +{ | |
| 61 | + start_frame(link, buf); | |
| 62 | + return 0; | |
| 63 | +} | |
| 64 | + | |
| 59 | 65 | int av_buffersink_read(AVFilterContext *ctx, AVFilterBufferRef **buf) |
| 60 | 66 | { |
| 61 | 67 | BufferSinkContext *s = ctx->priv; |
| @@ -160,7 +166,7 @@ AVFilter avfilter_asink_abuffer = { · 98 unmodified lines | ||
| 160 | 166 | |
| 161 | 167 | .inputs = (AVFilterPad[]) {{ .name = "default", |
| 162 | 168 | .type = AVMEDIA_TYPE_AUDIO, |
| 163 | − .filter_samples = start_frame, | |
| 169 | + .filter_samples = filter_samples, | |
| 164 | 170 | .min_perms = AV_PERM_READ, |
| 165 | 171 | .needs_fifo = 1 }, |
| 166 | 172 | { .name = NULL }}, |
| @@ -312,6 +312,7 @@ static int request_frame(AVFilterLink *link) · 311 unmodified lines | ||
| 312 | 312 | { |
| 313 | 313 | BufferSourceContext *c = link->src->priv; |
| 314 | 314 | AVFilterBufferRef *buf; |
| 315 | + int ret = 0; | |
| 315 | 316 | |
| 316 | 317 | if (!av_fifo_size(c->fifo)) { |
| 317 | 318 | if (c->eof) |
| @@ -327,7 +328,7 @@ static int request_frame(AVFilterLink *link) · 9 unmodified lines | ||
| 327 | 328 | ff_end_frame(link); |
| 328 | 329 | break; |
| 329 | 330 | case AVMEDIA_TYPE_AUDIO: |
| 330 | − ff_filter_samples(link, avfilter_ref_buffer(buf, ~0)); | |
| 331 | + ret = ff_filter_samples(link, avfilter_ref_buffer(buf, ~0)); | |
| 331 | 332 | break; |
| 332 | 333 | default: |
| 333 | 334 | return AVERROR(EINVAL); |
| @@ -335,7 +336,7 @@ static int request_frame(AVFilterLink *link) · 1 unmodified line | ||
| 335 | 336 | |
| 336 | 337 | avfilter_unref_buffer(buf); |
| 337 | 338 | |
| 338 | − return 0; | |
| 339 | + return ret; | |
| 339 | 340 | } |
| 340 | 341 | |
| 341 | 342 | static int poll_frame(AVFilterLink *link) |
| @@ -72,13 +72,25 @@ static av_cold void uninit(AVFilterContext *ctx) · 71 unmodified lines | ||
| 72 | 72 | avfilter_unref_buffer(fifo->buf_out); |
| 73 | 73 | } |
| 74 | 74 | |
| 75 | −static void add_to_queue(AVFilterLink *inlink, AVFilterBufferRef *buf) | |
| 75 | +static int add_to_queue(AVFilterLink *inlink, AVFilterBufferRef *buf) | |
| 76 | 76 | { |
| 77 | 77 | FifoContext *fifo = inlink->dst->priv; |
| 78 | 78 | |
| 79 | 79 | fifo->last->next = av_mallocz(sizeof(Buf)); |
| 80 | + if (!fifo->last->next) { | |
| 81 | + avfilter_unref_buffer(buf); | |
| 82 | + return AVERROR(ENOMEM); | |
| 83 | + } | |
| 84 | + | |
| 80 | 85 | fifo->last = fifo->last->next; |
| 81 | 86 | fifo->last->buf = buf; |
| 87 | + | |
| 88 | + return 0; | |
| 89 | +} | |
| 90 | + | |
| 91 | +static void start_frame(AVFilterLink *inlink, AVFilterBufferRef *buf) | |
| 92 | +{ | |
| 93 | + add_to_queue(inlink, buf); | |
| 82 | 94 | } |
| 83 | 95 | |
| 84 | 96 | static void queue_pop(FifoContext *s) |
| @@ -210,15 +222,13 @@ static int return_audio_frame(AVFilterContext *ctx) · 125 unmodified lines | ||
| 210 | 222 | buf_out = s->buf_out; |
| 211 | 223 | s->buf_out = NULL; |
| 212 | 224 | } |
| 213 | − ff_filter_samples(link, buf_out); | |
| 214 | − | |
| 215 | − return 0; | |
| 225 | + return ff_filter_samples(link, buf_out); | |
| 216 | 226 | } |
| 217 | 227 | |
| 218 | 228 | static int request_frame(AVFilterLink *outlink) |
| 219 | 229 | { |
| 220 | 230 | FifoContext *fifo = outlink->src->priv; |
| 221 | − int ret; | |
| 231 | + int ret = 0; | |
| 222 | 232 | |
| 223 | 233 | if (!fifo->root.next) { |
| 224 | 234 | if ((ret = ff_request_frame(outlink->src->inputs[0])) < 0) |
| @@ -238,7 +248,7 @@ static int request_frame(AVFilterLink *outlink) · 13 unmodified lines | ||
| 238 | 248 | if (outlink->request_samples) { |
| 239 | 249 | return return_audio_frame(outlink->src); |
| 240 | 250 | } else { |
| 241 | − ff_filter_samples(outlink, fifo->root.next->buf); | |
| 251 | + ret = ff_filter_samples(outlink, fifo->root.next->buf); | |
| 242 | 252 | queue_pop(fifo); |
| 243 | 253 | } |
| 244 | 254 | break; |
| @@ -246,7 +256,7 @@ static int request_frame(AVFilterLink *outlink) · 1 unmodified line | ||
| 246 | 256 | return AVERROR(EINVAL); |
| 247 | 257 | } |
| 248 | 258 | |
| 249 | − return 0; | |
| 259 | + return ret; | |
| 250 | 260 | } |
| 251 | 261 | |
| 252 | 262 | AVFilter avfilter_vf_fifo = { |
| @@ -261,7 +271,7 @@ AVFilter avfilter_vf_fifo = { · 8 unmodified lines | ||
| 261 | 271 | .inputs = (AVFilterPad[]) {{ .name = "default", |
| 262 | 272 | .type = AVMEDIA_TYPE_VIDEO, |
| 263 | 273 | .get_video_buffer= ff_null_get_video_buffer, |
| 264 | − .start_frame = add_to_queue, | |
| 274 | + .start_frame = start_frame, | |
| 265 | 275 | .draw_slice = draw_slice, |
| 266 | 276 | .end_frame = end_frame, |
| 267 | 277 | .rej_perms = AV_PERM_REUSE2, }, |
| @@ -111,8 +111,12 @@ struct AVFilterPad { · 110 unmodified lines | ||
| 111 | 111 | * and should do its processing. |
| 112 | 112 | * |
| 113 | 113 | * Input audio pads only. |
| 114 | + * | |
| 115 | + * @return >= 0 on success, a negative AVERROR on error. This function | |
| 116 | + * must ensure that samplesref is properly unreferenced on error if it | |
| 117 | + * hasn't been passed on to another filter. | |
| 114 | 118 | */ |
| 115 | − void (*filter_samples)(AVFilterLink *link, AVFilterBufferRef *samplesref); | |
| 119 | + int (*filter_samples)(AVFilterLink *link, AVFilterBufferRef *samplesref); | |
| 116 | 120 | |
| 117 | 121 | /** |
| 118 | 122 | * Frame poll callback. This returns the number of immediately available |
| @@ -110,15 +110,19 @@ AVFilter avfilter_vf_split = { · 109 unmodified lines | ||
| 110 | 110 | .outputs = (AVFilterPad[]) {{ .name = NULL}}, |
| 111 | 111 | }; |
| 112 | 112 | |
| 113 | −static void filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref) | |
| 113 | +static int filter_samples(AVFilterLink *inlink, AVFilterBufferRef *samplesref) | |
| 114 | 114 | { |
| 115 | 115 | AVFilterContext *ctx = inlink->dst; |
| 116 | − int i; | |
| 116 | + int i, ret = 0; | |
| 117 | 117 | |
| 118 | − for (i = 0; i < ctx->nb_outputs; i++) | |
| 119 | − ff_filter_samples(inlink->dst->outputs[i], | |
| 120 | − avfilter_ref_buffer(samplesref, ~AV_PERM_WRITE)); | |
| 118 | + for (i = 0; i < ctx->nb_outputs; i++) { | |
| 119 | + ret = ff_filter_samples(inlink->dst->outputs[i], | |
| 120 | + avfilter_ref_buffer(samplesref, ~AV_PERM_WRITE)); | |
| 121 | + if (ret < 0) | |
| 122 | + break; | |
| 123 | + } | |
| 121 | 124 | avfilter_unref_buffer(samplesref); |
| 125 | + return ret; | |
| 122 | 126 | } |
| 123 | 127 | |
| 124 | 128 | AVFilter avfilter_af_asplit = { |