You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

610 lines
19KB

  1. /*
  2. * Copyright (c) 2011 Stefano Sabatini
  3. *
  4. * This file is part of FFmpeg.
  5. *
  6. * FFmpeg is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * FFmpeg is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with FFmpeg; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. /**
  21. * @file
  22. * buffer sink
  23. */
  24. #include "libavutil/audio_fifo.h"
  25. #include "libavutil/avassert.h"
  26. #include "libavutil/channel_layout.h"
  27. #include "libavutil/common.h"
  28. #include "libavutil/internal.h"
  29. #include "libavutil/mathematics.h"
  30. #include "libavutil/opt.h"
  31. #include "audio.h"
  32. #include "avfilter.h"
  33. #include "buffersink.h"
  34. #include "internal.h"
  35. typedef struct {
  36. const AVClass *class;
  37. AVFifoBuffer *fifo; ///< FIFO buffer of video frame references
  38. unsigned warning_limit;
  39. /* only used for video */
  40. enum AVPixelFormat *pixel_fmts; ///< list of accepted pixel formats, must be terminated with -1
  41. int pixel_fmts_size;
  42. /* only used for audio */
  43. enum AVSampleFormat *sample_fmts; ///< list of accepted sample formats, terminated by AV_SAMPLE_FMT_NONE
  44. int sample_fmts_size;
  45. int64_t *channel_layouts; ///< list of accepted channel layouts, terminated by -1
  46. int channel_layouts_size;
  47. int *channel_counts; ///< list of accepted channel counts, terminated by -1
  48. int channel_counts_size;
  49. int all_channel_counts;
  50. int *sample_rates; ///< list of accepted sample rates, terminated by -1
  51. int sample_rates_size;
  52. /* only used for compat API */
  53. AVAudioFifo *audio_fifo; ///< FIFO for audio samples
  54. int64_t next_pts; ///< interpolating audio pts
  55. } BufferSinkContext;
  56. #define NB_ITEMS(list) (list ## _size / sizeof(*list))
  57. static av_cold void uninit(AVFilterContext *ctx)
  58. {
  59. BufferSinkContext *sink = ctx->priv;
  60. AVFrame *frame;
  61. if (sink->audio_fifo)
  62. av_audio_fifo_free(sink->audio_fifo);
  63. if (sink->fifo) {
  64. while (av_fifo_size(sink->fifo) >= sizeof(AVFilterBufferRef *)) {
  65. av_fifo_generic_read(sink->fifo, &frame, sizeof(frame), NULL);
  66. av_frame_free(&frame);
  67. }
  68. av_fifo_free(sink->fifo);
  69. sink->fifo = NULL;
  70. }
  71. }
  72. static int add_buffer_ref(AVFilterContext *ctx, AVFrame *ref)
  73. {
  74. BufferSinkContext *buf = ctx->priv;
  75. if (av_fifo_space(buf->fifo) < sizeof(AVFilterBufferRef *)) {
  76. /* realloc fifo size */
  77. if (av_fifo_realloc2(buf->fifo, av_fifo_size(buf->fifo) * 2) < 0) {
  78. av_log(ctx, AV_LOG_ERROR,
  79. "Cannot buffer more frames. Consume some available frames "
  80. "before adding new ones.\n");
  81. return AVERROR(ENOMEM);
  82. }
  83. }
  84. /* cache frame */
  85. av_fifo_generic_write(buf->fifo, &ref, sizeof(AVFilterBufferRef *), NULL);
  86. return 0;
  87. }
  88. static int filter_frame(AVFilterLink *link, AVFrame *frame)
  89. {
  90. AVFilterContext *ctx = link->dst;
  91. BufferSinkContext *buf = link->dst->priv;
  92. int ret;
  93. if ((ret = add_buffer_ref(ctx, frame)) < 0)
  94. return ret;
  95. if (buf->warning_limit &&
  96. av_fifo_size(buf->fifo) / sizeof(AVFilterBufferRef *) >= buf->warning_limit) {
  97. av_log(ctx, AV_LOG_WARNING,
  98. "%d buffers queued in %s, something may be wrong.\n",
  99. buf->warning_limit,
  100. (char *)av_x_if_null(ctx->name, ctx->filter->name));
  101. buf->warning_limit *= 10;
  102. }
  103. return 0;
  104. }
  105. int attribute_align_arg av_buffersink_get_frame(AVFilterContext *ctx, AVFrame *frame)
  106. {
  107. return av_buffersink_get_frame_flags(ctx, frame, 0);
  108. }
  109. int attribute_align_arg av_buffersink_get_frame_flags(AVFilterContext *ctx, AVFrame *frame, int flags)
  110. {
  111. BufferSinkContext *buf = ctx->priv;
  112. AVFilterLink *inlink = ctx->inputs[0];
  113. int ret;
  114. AVFrame *cur_frame;
  115. /* no picref available, fetch it from the filterchain */
  116. if (!av_fifo_size(buf->fifo)) {
  117. if (flags & AV_BUFFERSINK_FLAG_NO_REQUEST)
  118. return AVERROR(EAGAIN);
  119. if ((ret = ff_request_frame(inlink)) < 0)
  120. return ret;
  121. }
  122. if (!av_fifo_size(buf->fifo))
  123. return AVERROR(EINVAL);
  124. if (flags & AV_BUFFERSINK_FLAG_PEEK) {
  125. cur_frame = *((AVFrame **)av_fifo_peek2(buf->fifo, 0));
  126. if ((ret = av_frame_ref(frame, cur_frame)) < 0)
  127. return ret;
  128. } else {
  129. av_fifo_generic_read(buf->fifo, &cur_frame, sizeof(cur_frame), NULL);
  130. av_frame_move_ref(frame, cur_frame);
  131. av_frame_free(&cur_frame);
  132. }
  133. return 0;
  134. }
  135. static int read_from_fifo(AVFilterContext *ctx, AVFrame *frame,
  136. int nb_samples)
  137. {
  138. BufferSinkContext *s = ctx->priv;
  139. AVFilterLink *link = ctx->inputs[0];
  140. AVFrame *tmp;
  141. if (!(tmp = ff_get_audio_buffer(link, nb_samples)))
  142. return AVERROR(ENOMEM);
  143. av_audio_fifo_read(s->audio_fifo, (void**)tmp->extended_data, nb_samples);
  144. tmp->pts = s->next_pts;
  145. if (s->next_pts != AV_NOPTS_VALUE)
  146. s->next_pts += av_rescale_q(nb_samples, (AVRational){1, link->sample_rate},
  147. link->time_base);
  148. av_frame_move_ref(frame, tmp);
  149. av_frame_free(&tmp);
  150. return 0;
  151. }
  152. int attribute_align_arg av_buffersink_get_samples(AVFilterContext *ctx,
  153. AVFrame *frame, int nb_samples)
  154. {
  155. BufferSinkContext *s = ctx->priv;
  156. AVFilterLink *link = ctx->inputs[0];
  157. AVFrame *cur_frame;
  158. int ret = 0;
  159. if (!s->audio_fifo) {
  160. int nb_channels = link->channels;
  161. if (!(s->audio_fifo = av_audio_fifo_alloc(link->format, nb_channels, nb_samples)))
  162. return AVERROR(ENOMEM);
  163. }
  164. while (ret >= 0) {
  165. if (av_audio_fifo_size(s->audio_fifo) >= nb_samples)
  166. return read_from_fifo(ctx, frame, nb_samples);
  167. if (!(cur_frame = av_frame_alloc()))
  168. return AVERROR(ENOMEM);
  169. ret = av_buffersink_get_frame_flags(ctx, cur_frame, 0);
  170. if (ret == AVERROR_EOF && av_audio_fifo_size(s->audio_fifo)) {
  171. av_frame_free(&cur_frame);
  172. return read_from_fifo(ctx, frame, av_audio_fifo_size(s->audio_fifo));
  173. } else if (ret < 0) {
  174. av_frame_free(&cur_frame);
  175. return ret;
  176. }
  177. if (cur_frame->pts != AV_NOPTS_VALUE) {
  178. s->next_pts = cur_frame->pts -
  179. av_rescale_q(av_audio_fifo_size(s->audio_fifo),
  180. (AVRational){ 1, link->sample_rate },
  181. link->time_base);
  182. }
  183. ret = av_audio_fifo_write(s->audio_fifo, (void**)cur_frame->extended_data,
  184. cur_frame->nb_samples);
  185. av_frame_free(&cur_frame);
  186. }
  187. return ret;
  188. }
  189. AVBufferSinkParams *av_buffersink_params_alloc(void)
  190. {
  191. static const int pixel_fmts[] = { AV_PIX_FMT_NONE };
  192. AVBufferSinkParams *params = av_malloc(sizeof(AVBufferSinkParams));
  193. if (!params)
  194. return NULL;
  195. params->pixel_fmts = pixel_fmts;
  196. return params;
  197. }
  198. AVABufferSinkParams *av_abuffersink_params_alloc(void)
  199. {
  200. AVABufferSinkParams *params = av_mallocz(sizeof(AVABufferSinkParams));
  201. if (!params)
  202. return NULL;
  203. return params;
  204. }
  205. #define FIFO_INIT_SIZE 8
  206. static av_cold int common_init(AVFilterContext *ctx)
  207. {
  208. BufferSinkContext *buf = ctx->priv;
  209. buf->fifo = av_fifo_alloc(FIFO_INIT_SIZE*sizeof(AVFilterBufferRef *));
  210. if (!buf->fifo) {
  211. av_log(ctx, AV_LOG_ERROR, "Failed to allocate fifo\n");
  212. return AVERROR(ENOMEM);
  213. }
  214. buf->warning_limit = 100;
  215. buf->next_pts = AV_NOPTS_VALUE;
  216. return 0;
  217. }
  218. void av_buffersink_set_frame_size(AVFilterContext *ctx, unsigned frame_size)
  219. {
  220. AVFilterLink *inlink = ctx->inputs[0];
  221. inlink->min_samples = inlink->max_samples =
  222. inlink->partial_buf_size = frame_size;
  223. }
  224. #if FF_API_AVFILTERBUFFER
  225. FF_DISABLE_DEPRECATION_WARNINGS
  226. static void compat_free_buffer(AVFilterBuffer *buf)
  227. {
  228. AVFrame *frame = buf->priv;
  229. av_frame_free(&frame);
  230. av_free(buf);
  231. }
  232. static int compat_read(AVFilterContext *ctx,
  233. AVFilterBufferRef **pbuf, int nb_samples, int flags)
  234. {
  235. AVFilterBufferRef *buf;
  236. AVFrame *frame;
  237. int ret;
  238. if (!pbuf)
  239. return ff_poll_frame(ctx->inputs[0]);
  240. frame = av_frame_alloc();
  241. if (!frame)
  242. return AVERROR(ENOMEM);
  243. if (!nb_samples)
  244. ret = av_buffersink_get_frame_flags(ctx, frame, flags);
  245. else
  246. ret = av_buffersink_get_samples(ctx, frame, nb_samples);
  247. if (ret < 0)
  248. goto fail;
  249. AV_NOWARN_DEPRECATED(
  250. if (ctx->inputs[0]->type == AVMEDIA_TYPE_VIDEO) {
  251. buf = avfilter_get_video_buffer_ref_from_arrays(frame->data, frame->linesize,
  252. AV_PERM_READ,
  253. frame->width, frame->height,
  254. frame->format);
  255. } else {
  256. buf = avfilter_get_audio_buffer_ref_from_arrays(frame->extended_data,
  257. frame->linesize[0], AV_PERM_READ,
  258. frame->nb_samples,
  259. frame->format,
  260. frame->channel_layout);
  261. }
  262. if (!buf) {
  263. ret = AVERROR(ENOMEM);
  264. goto fail;
  265. }
  266. avfilter_copy_frame_props(buf, frame);
  267. )
  268. buf->buf->priv = frame;
  269. buf->buf->free = compat_free_buffer;
  270. *pbuf = buf;
  271. return 0;
  272. fail:
  273. av_frame_free(&frame);
  274. return ret;
  275. }
  276. int attribute_align_arg av_buffersink_read(AVFilterContext *ctx, AVFilterBufferRef **buf)
  277. {
  278. return compat_read(ctx, buf, 0, 0);
  279. }
  280. int attribute_align_arg av_buffersink_read_samples(AVFilterContext *ctx, AVFilterBufferRef **buf,
  281. int nb_samples)
  282. {
  283. return compat_read(ctx, buf, nb_samples, 0);
  284. }
  285. int attribute_align_arg av_buffersink_get_buffer_ref(AVFilterContext *ctx,
  286. AVFilterBufferRef **bufref, int flags)
  287. {
  288. *bufref = NULL;
  289. av_assert0( !strcmp(ctx->filter->name, "buffersink")
  290. || !strcmp(ctx->filter->name, "abuffersink")
  291. || !strcmp(ctx->filter->name, "ffbuffersink")
  292. || !strcmp(ctx->filter->name, "ffabuffersink"));
  293. return compat_read(ctx, bufref, 0, flags);
  294. }
  295. FF_ENABLE_DEPRECATION_WARNINGS
  296. #endif
  297. AVRational av_buffersink_get_frame_rate(AVFilterContext *ctx)
  298. {
  299. av_assert0( !strcmp(ctx->filter->name, "buffersink")
  300. || !strcmp(ctx->filter->name, "ffbuffersink"));
  301. return ctx->inputs[0]->frame_rate;
  302. }
  303. int attribute_align_arg av_buffersink_poll_frame(AVFilterContext *ctx)
  304. {
  305. BufferSinkContext *buf = ctx->priv;
  306. AVFilterLink *inlink = ctx->inputs[0];
  307. av_assert0( !strcmp(ctx->filter->name, "buffersink")
  308. || !strcmp(ctx->filter->name, "abuffersink")
  309. || !strcmp(ctx->filter->name, "ffbuffersink")
  310. || !strcmp(ctx->filter->name, "ffabuffersink"));
  311. return av_fifo_size(buf->fifo)/sizeof(AVFilterBufferRef *) + ff_poll_frame(inlink);
  312. }
  313. static av_cold int vsink_init(AVFilterContext *ctx, void *opaque)
  314. {
  315. BufferSinkContext *buf = ctx->priv;
  316. AVBufferSinkParams *params = opaque;
  317. int ret;
  318. if (params) {
  319. if ((ret = av_opt_set_int_list(buf, "pix_fmts", params->pixel_fmts, AV_PIX_FMT_NONE, 0)) < 0)
  320. return ret;
  321. }
  322. return common_init(ctx);
  323. }
  324. #define CHECK_LIST_SIZE(field) \
  325. if (buf->field ## _size % sizeof(*buf->field)) { \
  326. av_log(ctx, AV_LOG_ERROR, "Invalid size for " #field ": %d, " \
  327. "should be multiple of %d\n", \
  328. buf->field ## _size, (int)sizeof(*buf->field)); \
  329. return AVERROR(EINVAL); \
  330. }
  331. static int vsink_query_formats(AVFilterContext *ctx)
  332. {
  333. BufferSinkContext *buf = ctx->priv;
  334. AVFilterFormats *formats = NULL;
  335. unsigned i;
  336. int ret;
  337. CHECK_LIST_SIZE(pixel_fmts)
  338. if (buf->pixel_fmts_size) {
  339. for (i = 0; i < NB_ITEMS(buf->pixel_fmts); i++)
  340. if ((ret = ff_add_format(&formats, buf->pixel_fmts[i])) < 0) {
  341. ff_formats_unref(&formats);
  342. return ret;
  343. }
  344. ff_set_common_formats(ctx, formats);
  345. } else {
  346. ff_default_query_formats(ctx);
  347. }
  348. return 0;
  349. }
  350. static av_cold int asink_init(AVFilterContext *ctx, void *opaque)
  351. {
  352. BufferSinkContext *buf = ctx->priv;
  353. AVABufferSinkParams *params = opaque;
  354. int ret;
  355. if (params) {
  356. if ((ret = av_opt_set_int_list(buf, "sample_fmts", params->sample_fmts, AV_SAMPLE_FMT_NONE, 0)) < 0 ||
  357. (ret = av_opt_set_int_list(buf, "sample_rates", params->sample_rates, -1, 0)) < 0 ||
  358. (ret = av_opt_set_int_list(buf, "channel_layouts", params->channel_layouts, -1, 0)) < 0 ||
  359. (ret = av_opt_set_int_list(buf, "channel_counts", params->channel_counts, -1, 0)) < 0 ||
  360. (ret = av_opt_set_int(buf, "all_channel_counts", params->all_channel_counts, 0)) < 0)
  361. return ret;
  362. }
  363. return common_init(ctx);
  364. }
  365. static int asink_query_formats(AVFilterContext *ctx)
  366. {
  367. BufferSinkContext *buf = ctx->priv;
  368. AVFilterFormats *formats = NULL;
  369. AVFilterChannelLayouts *layouts = NULL;
  370. unsigned i;
  371. int ret;
  372. CHECK_LIST_SIZE(sample_fmts)
  373. CHECK_LIST_SIZE(sample_rates)
  374. CHECK_LIST_SIZE(channel_layouts)
  375. CHECK_LIST_SIZE(channel_counts)
  376. if (buf->sample_fmts_size) {
  377. for (i = 0; i < NB_ITEMS(buf->sample_fmts); i++)
  378. if ((ret = ff_add_format(&formats, buf->sample_fmts[i])) < 0) {
  379. ff_formats_unref(&formats);
  380. return ret;
  381. }
  382. ff_set_common_formats(ctx, formats);
  383. }
  384. if (buf->channel_layouts_size || buf->channel_counts_size ||
  385. buf->all_channel_counts) {
  386. for (i = 0; i < NB_ITEMS(buf->channel_layouts); i++)
  387. if ((ret = ff_add_channel_layout(&layouts, buf->channel_layouts[i])) < 0) {
  388. ff_channel_layouts_unref(&layouts);
  389. return ret;
  390. }
  391. for (i = 0; i < NB_ITEMS(buf->channel_counts); i++)
  392. if ((ret = ff_add_channel_layout(&layouts, FF_COUNT2LAYOUT(buf->channel_counts[i]))) < 0) {
  393. ff_channel_layouts_unref(&layouts);
  394. return ret;
  395. }
  396. if (buf->all_channel_counts) {
  397. if (layouts)
  398. av_log(ctx, AV_LOG_WARNING,
  399. "Conflicting all_channel_counts and list in options\n");
  400. else if (!(layouts = ff_all_channel_counts()))
  401. return AVERROR(ENOMEM);
  402. }
  403. ff_set_common_channel_layouts(ctx, layouts);
  404. }
  405. if (buf->sample_rates_size) {
  406. formats = NULL;
  407. for (i = 0; i < NB_ITEMS(buf->sample_rates); i++)
  408. if ((ret = ff_add_format(&formats, buf->sample_rates[i])) < 0) {
  409. ff_formats_unref(&formats);
  410. return ret;
  411. }
  412. ff_set_common_samplerates(ctx, formats);
  413. }
  414. return 0;
  415. }
  416. #define OFFSET(x) offsetof(BufferSinkContext, x)
  417. #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
  418. static const AVOption buffersink_options[] = {
  419. { "pix_fmts", "set the supported pixel formats", OFFSET(pixel_fmts), AV_OPT_TYPE_BINARY, .flags = FLAGS },
  420. { NULL },
  421. };
  422. #undef FLAGS
  423. #define FLAGS AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_VIDEO_PARAM
  424. static const AVOption abuffersink_options[] = {
  425. { "sample_fmts", "set the supported sample formats", OFFSET(sample_fmts), AV_OPT_TYPE_BINARY, .flags = FLAGS },
  426. { "sample_rates", "set the supported sample rates", OFFSET(sample_rates), AV_OPT_TYPE_BINARY, .flags = FLAGS },
  427. { "channel_layouts", "set the supported channel layouts", OFFSET(channel_layouts), AV_OPT_TYPE_BINARY, .flags = FLAGS },
  428. { "channel_counts", "set the supported channel counts", OFFSET(channel_counts), AV_OPT_TYPE_BINARY, .flags = FLAGS },
  429. { "all_channel_counts", "accept all channel counts", OFFSET(all_channel_counts), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, FLAGS },
  430. { NULL },
  431. };
  432. #undef FLAGS
  433. AVFILTER_DEFINE_CLASS(buffersink);
  434. AVFILTER_DEFINE_CLASS(abuffersink);
  435. #if FF_API_AVFILTERBUFFER
  436. #define ffbuffersink_options buffersink_options
  437. #define ffabuffersink_options abuffersink_options
  438. AVFILTER_DEFINE_CLASS(ffbuffersink);
  439. AVFILTER_DEFINE_CLASS(ffabuffersink);
  440. static const AVFilterPad ffbuffersink_inputs[] = {
  441. {
  442. .name = "default",
  443. .type = AVMEDIA_TYPE_VIDEO,
  444. .filter_frame = filter_frame,
  445. },
  446. { NULL },
  447. };
  448. AVFilter ff_vsink_ffbuffersink = {
  449. .name = "ffbuffersink",
  450. .description = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them available to the end of the filter graph."),
  451. .priv_size = sizeof(BufferSinkContext),
  452. .priv_class = &ffbuffersink_class,
  453. .init_opaque = vsink_init,
  454. .uninit = uninit,
  455. .query_formats = vsink_query_formats,
  456. .inputs = ffbuffersink_inputs,
  457. .outputs = NULL,
  458. };
  459. static const AVFilterPad ffabuffersink_inputs[] = {
  460. {
  461. .name = "default",
  462. .type = AVMEDIA_TYPE_AUDIO,
  463. .filter_frame = filter_frame,
  464. },
  465. { NULL },
  466. };
  467. AVFilter ff_asink_ffabuffersink = {
  468. .name = "ffabuffersink",
  469. .description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them available to the end of the filter graph."),
  470. .init_opaque = asink_init,
  471. .uninit = uninit,
  472. .priv_size = sizeof(BufferSinkContext),
  473. .priv_class = &ffabuffersink_class,
  474. .query_formats = asink_query_formats,
  475. .inputs = ffabuffersink_inputs,
  476. .outputs = NULL,
  477. };
  478. #endif /* FF_API_AVFILTERBUFFER */
  479. static const AVFilterPad avfilter_vsink_buffer_inputs[] = {
  480. {
  481. .name = "default",
  482. .type = AVMEDIA_TYPE_VIDEO,
  483. .filter_frame = filter_frame,
  484. },
  485. { NULL }
  486. };
  487. AVFilter ff_vsink_buffer = {
  488. .name = "buffersink",
  489. .description = NULL_IF_CONFIG_SMALL("Buffer video frames, and make them available to the end of the filter graph."),
  490. .priv_size = sizeof(BufferSinkContext),
  491. .priv_class = &buffersink_class,
  492. .init_opaque = vsink_init,
  493. .uninit = uninit,
  494. .query_formats = vsink_query_formats,
  495. .inputs = avfilter_vsink_buffer_inputs,
  496. .outputs = NULL,
  497. };
  498. static const AVFilterPad avfilter_asink_abuffer_inputs[] = {
  499. {
  500. .name = "default",
  501. .type = AVMEDIA_TYPE_AUDIO,
  502. .filter_frame = filter_frame,
  503. },
  504. { NULL }
  505. };
  506. AVFilter ff_asink_abuffer = {
  507. .name = "abuffersink",
  508. .description = NULL_IF_CONFIG_SMALL("Buffer audio frames, and make them available to the end of the filter graph."),
  509. .priv_class = &abuffersink_class,
  510. .priv_size = sizeof(BufferSinkContext),
  511. .init_opaque = asink_init,
  512. .uninit = uninit,
  513. .query_formats = asink_query_formats,
  514. .inputs = avfilter_asink_abuffer_inputs,
  515. .outputs = NULL,
  516. };