2 * PCM Plug-In shared (kernel/library) code
3 * Copyright (c) 1999 by Jaroslav Kysela <perex@perex.cz>
4 * Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
7 * This library is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Library General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include <linux/slab.h>
28 #include <linux/time.h>
29 #include <linux/vmalloc.h>
30 #include <sound/core.h>
31 #include <sound/pcm.h>
32 #include <sound/pcm_params.h>
33 #include "pcm_plugin.h"
35 #define snd_pcm_plug_first(plug) ((plug)->runtime->oss.plugin_first)
36 #define snd_pcm_plug_last(plug) ((plug)->runtime->oss.plugin_last)
39 * because some cards might have rates "very close", we ignore
40 * all "resampling" requests within +-5%
42 static int rate_match(unsigned int src_rate, unsigned int dst_rate)
44 unsigned int low = (src_rate * 95) / 100;
45 unsigned int high = (src_rate * 105) / 100;
46 return dst_rate >= low && dst_rate <= high;
49 static int snd_pcm_plugin_alloc(struct snd_pcm_plugin *plugin, snd_pcm_uframes_t frames)
51 struct snd_pcm_plugin_format *format;
55 struct snd_pcm_plugin_channel *c;
57 if (plugin->stream == SNDRV_PCM_STREAM_PLAYBACK) {
58 format = &plugin->src_format;
60 format = &plugin->dst_format;
62 if ((width = snd_pcm_format_physical_width(format->format)) < 0)
64 size = array3_size(frames, format->channels, width);
65 /* check for too large period size once again */
66 if (size > 1024 * 1024)
68 if (snd_BUG_ON(size % 8))
71 if (plugin->buf_frames < frames) {
73 plugin->buf = kvzalloc(size, GFP_KERNEL);
74 plugin->buf_frames = frames;
77 plugin->buf_frames = 0;
80 c = plugin->buf_channels;
81 if (plugin->access == SNDRV_PCM_ACCESS_RW_INTERLEAVED) {
82 for (channel = 0; channel < format->channels; channel++, c++) {
86 c->area.addr = plugin->buf;
87 c->area.first = channel * width;
88 c->area.step = format->channels * width;
90 } else if (plugin->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
91 if (snd_BUG_ON(size % format->channels))
93 size /= format->channels;
94 for (channel = 0; channel < format->channels; channel++, c++) {
98 c->area.addr = plugin->buf + (channel * size);
100 c->area.step = width;
107 int snd_pcm_plug_alloc(struct snd_pcm_substream *plug, snd_pcm_uframes_t frames)
110 if (snd_BUG_ON(!snd_pcm_plug_first(plug)))
112 if (snd_pcm_plug_stream(plug) == SNDRV_PCM_STREAM_PLAYBACK) {
113 struct snd_pcm_plugin *plugin = snd_pcm_plug_first(plug);
114 while (plugin->next) {
115 if (plugin->dst_frames)
116 frames = plugin->dst_frames(plugin, frames);
117 if ((snd_pcm_sframes_t)frames <= 0)
119 plugin = plugin->next;
120 err = snd_pcm_plugin_alloc(plugin, frames);
125 struct snd_pcm_plugin *plugin = snd_pcm_plug_last(plug);
126 while (plugin->prev) {
127 if (plugin->src_frames)
128 frames = plugin->src_frames(plugin, frames);
129 if ((snd_pcm_sframes_t)frames <= 0)
131 plugin = plugin->prev;
132 err = snd_pcm_plugin_alloc(plugin, frames);
141 snd_pcm_sframes_t snd_pcm_plugin_client_channels(struct snd_pcm_plugin *plugin,
142 snd_pcm_uframes_t frames,
143 struct snd_pcm_plugin_channel **channels)
145 *channels = plugin->buf_channels;
149 int snd_pcm_plugin_build(struct snd_pcm_substream *plug,
151 struct snd_pcm_plugin_format *src_format,
152 struct snd_pcm_plugin_format *dst_format,
154 struct snd_pcm_plugin **ret)
156 struct snd_pcm_plugin *plugin;
157 unsigned int channels;
159 if (snd_BUG_ON(!plug))
161 if (snd_BUG_ON(!src_format || !dst_format))
163 plugin = kzalloc(sizeof(*plugin) + extra, GFP_KERNEL);
168 plugin->stream = snd_pcm_plug_stream(plug);
169 plugin->access = SNDRV_PCM_ACCESS_RW_INTERLEAVED;
170 plugin->src_format = *src_format;
171 plugin->src_width = snd_pcm_format_physical_width(src_format->format);
172 snd_BUG_ON(plugin->src_width <= 0);
173 plugin->dst_format = *dst_format;
174 plugin->dst_width = snd_pcm_format_physical_width(dst_format->format);
175 snd_BUG_ON(plugin->dst_width <= 0);
176 if (plugin->stream == SNDRV_PCM_STREAM_PLAYBACK)
177 channels = src_format->channels;
179 channels = dst_format->channels;
180 plugin->buf_channels = kcalloc(channels, sizeof(*plugin->buf_channels), GFP_KERNEL);
181 if (plugin->buf_channels == NULL) {
182 snd_pcm_plugin_free(plugin);
185 plugin->client_channels = snd_pcm_plugin_client_channels;
190 int snd_pcm_plugin_free(struct snd_pcm_plugin *plugin)
194 if (plugin->private_free)
195 plugin->private_free(plugin);
196 kfree(plugin->buf_channels);
202 static snd_pcm_sframes_t plug_client_size(struct snd_pcm_substream *plug,
203 snd_pcm_uframes_t drv_frames,
206 struct snd_pcm_plugin *plugin, *plugin_prev, *plugin_next;
209 if (snd_BUG_ON(!plug))
213 stream = snd_pcm_plug_stream(plug);
214 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
215 plugin = snd_pcm_plug_last(plug);
216 while (plugin && drv_frames > 0) {
217 plugin_prev = plugin->prev;
218 if (plugin->src_frames)
219 drv_frames = plugin->src_frames(plugin, drv_frames);
220 if (check_size && plugin->buf_frames &&
221 drv_frames > plugin->buf_frames)
222 drv_frames = plugin->buf_frames;
223 plugin = plugin_prev;
225 } else if (stream == SNDRV_PCM_STREAM_CAPTURE) {
226 plugin = snd_pcm_plug_first(plug);
227 while (plugin && drv_frames > 0) {
228 plugin_next = plugin->next;
229 if (check_size && plugin->buf_frames &&
230 drv_frames > plugin->buf_frames)
231 drv_frames = plugin->buf_frames;
232 if (plugin->dst_frames)
233 drv_frames = plugin->dst_frames(plugin, drv_frames);
234 plugin = plugin_next;
241 static snd_pcm_sframes_t plug_slave_size(struct snd_pcm_substream *plug,
242 snd_pcm_uframes_t clt_frames,
245 struct snd_pcm_plugin *plugin, *plugin_prev, *plugin_next;
246 snd_pcm_sframes_t frames;
249 if (snd_BUG_ON(!plug))
254 stream = snd_pcm_plug_stream(plug);
255 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
256 plugin = snd_pcm_plug_first(plug);
257 while (plugin && frames > 0) {
258 plugin_next = plugin->next;
259 if (check_size && plugin->buf_frames &&
260 frames > plugin->buf_frames)
261 frames = plugin->buf_frames;
262 if (plugin->dst_frames) {
263 frames = plugin->dst_frames(plugin, frames);
267 plugin = plugin_next;
269 } else if (stream == SNDRV_PCM_STREAM_CAPTURE) {
270 plugin = snd_pcm_plug_last(plug);
272 plugin_prev = plugin->prev;
273 if (plugin->src_frames) {
274 frames = plugin->src_frames(plugin, frames);
278 if (check_size && plugin->buf_frames &&
279 frames > plugin->buf_frames)
280 frames = plugin->buf_frames;
281 plugin = plugin_prev;
288 snd_pcm_sframes_t snd_pcm_plug_client_size(struct snd_pcm_substream *plug,
289 snd_pcm_uframes_t drv_frames)
291 return plug_client_size(plug, drv_frames, false);
294 snd_pcm_sframes_t snd_pcm_plug_slave_size(struct snd_pcm_substream *plug,
295 snd_pcm_uframes_t clt_frames)
297 return plug_slave_size(plug, clt_frames, false);
300 static int snd_pcm_plug_formats(const struct snd_mask *mask,
301 snd_pcm_format_t format)
303 struct snd_mask formats = *mask;
304 u64 linfmts = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S8 |
305 SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_S16_LE |
306 SNDRV_PCM_FMTBIT_U16_BE | SNDRV_PCM_FMTBIT_S16_BE |
307 SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_S24_LE |
308 SNDRV_PCM_FMTBIT_U24_BE | SNDRV_PCM_FMTBIT_S24_BE |
309 SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_S24_3LE |
310 SNDRV_PCM_FMTBIT_U24_3BE | SNDRV_PCM_FMTBIT_S24_3BE |
311 SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_S32_LE |
312 SNDRV_PCM_FMTBIT_U32_BE | SNDRV_PCM_FMTBIT_S32_BE);
313 snd_mask_set(&formats, (__force int)SNDRV_PCM_FORMAT_MU_LAW);
315 if (formats.bits[0] & lower_32_bits(linfmts))
316 formats.bits[0] |= lower_32_bits(linfmts);
317 if (formats.bits[1] & upper_32_bits(linfmts))
318 formats.bits[1] |= upper_32_bits(linfmts);
319 return snd_mask_test(&formats, (__force int)format);
322 static snd_pcm_format_t preferred_formats[] = {
323 SNDRV_PCM_FORMAT_S16_LE,
324 SNDRV_PCM_FORMAT_S16_BE,
325 SNDRV_PCM_FORMAT_U16_LE,
326 SNDRV_PCM_FORMAT_U16_BE,
327 SNDRV_PCM_FORMAT_S24_3LE,
328 SNDRV_PCM_FORMAT_S24_3BE,
329 SNDRV_PCM_FORMAT_U24_3LE,
330 SNDRV_PCM_FORMAT_U24_3BE,
331 SNDRV_PCM_FORMAT_S24_LE,
332 SNDRV_PCM_FORMAT_S24_BE,
333 SNDRV_PCM_FORMAT_U24_LE,
334 SNDRV_PCM_FORMAT_U24_BE,
335 SNDRV_PCM_FORMAT_S32_LE,
336 SNDRV_PCM_FORMAT_S32_BE,
337 SNDRV_PCM_FORMAT_U32_LE,
338 SNDRV_PCM_FORMAT_U32_BE,
343 snd_pcm_format_t snd_pcm_plug_slave_format(snd_pcm_format_t format,
344 const struct snd_mask *format_mask)
348 if (snd_mask_test(format_mask, (__force int)format))
350 if (!snd_pcm_plug_formats(format_mask, format))
351 return (__force snd_pcm_format_t)-EINVAL;
352 if (snd_pcm_format_linear(format)) {
353 unsigned int width = snd_pcm_format_width(format);
354 int unsignd = snd_pcm_format_unsigned(format) > 0;
355 int big = snd_pcm_format_big_endian(format) > 0;
356 unsigned int badness, best = -1;
357 snd_pcm_format_t best_format = (__force snd_pcm_format_t)-1;
358 for (i = 0; i < ARRAY_SIZE(preferred_formats); i++) {
359 snd_pcm_format_t f = preferred_formats[i];
361 if (!snd_mask_test(format_mask, (__force int)f))
363 w = snd_pcm_format_width(f);
367 badness = width - w + 32;
368 badness += snd_pcm_format_unsigned(f) != unsignd;
369 badness += snd_pcm_format_big_endian(f) != big;
370 if (badness < best) {
375 if ((__force int)best_format >= 0)
378 return (__force snd_pcm_format_t)-EINVAL;
381 case SNDRV_PCM_FORMAT_MU_LAW:
382 for (i = 0; i < ARRAY_SIZE(preferred_formats); ++i) {
383 snd_pcm_format_t format1 = preferred_formats[i];
384 if (snd_mask_test(format_mask, (__force int)format1))
389 return (__force snd_pcm_format_t)-EINVAL;
394 int snd_pcm_plug_format_plugins(struct snd_pcm_substream *plug,
395 struct snd_pcm_hw_params *params,
396 struct snd_pcm_hw_params *slave_params)
398 struct snd_pcm_plugin_format tmpformat;
399 struct snd_pcm_plugin_format dstformat;
400 struct snd_pcm_plugin_format srcformat;
401 snd_pcm_access_t src_access, dst_access;
402 struct snd_pcm_plugin *plugin = NULL;
404 int stream = snd_pcm_plug_stream(plug);
405 int slave_interleaved = (params_channels(slave_params) == 1 ||
406 params_access(slave_params) == SNDRV_PCM_ACCESS_RW_INTERLEAVED);
409 case SNDRV_PCM_STREAM_PLAYBACK:
410 dstformat.format = params_format(slave_params);
411 dstformat.rate = params_rate(slave_params);
412 dstformat.channels = params_channels(slave_params);
413 srcformat.format = params_format(params);
414 srcformat.rate = params_rate(params);
415 srcformat.channels = params_channels(params);
416 src_access = SNDRV_PCM_ACCESS_RW_INTERLEAVED;
417 dst_access = (slave_interleaved ? SNDRV_PCM_ACCESS_RW_INTERLEAVED :
418 SNDRV_PCM_ACCESS_RW_NONINTERLEAVED);
420 case SNDRV_PCM_STREAM_CAPTURE:
421 dstformat.format = params_format(params);
422 dstformat.rate = params_rate(params);
423 dstformat.channels = params_channels(params);
424 srcformat.format = params_format(slave_params);
425 srcformat.rate = params_rate(slave_params);
426 srcformat.channels = params_channels(slave_params);
427 src_access = (slave_interleaved ? SNDRV_PCM_ACCESS_RW_INTERLEAVED :
428 SNDRV_PCM_ACCESS_RW_NONINTERLEAVED);
429 dst_access = SNDRV_PCM_ACCESS_RW_INTERLEAVED;
435 tmpformat = srcformat;
437 pdprintf("srcformat: format=%i, rate=%i, channels=%i\n",
441 pdprintf("dstformat: format=%i, rate=%i, channels=%i\n",
446 /* Format change (linearization) */
447 if (! rate_match(srcformat.rate, dstformat.rate) &&
448 ! snd_pcm_format_linear(srcformat.format)) {
449 if (srcformat.format != SNDRV_PCM_FORMAT_MU_LAW)
451 tmpformat.format = SNDRV_PCM_FORMAT_S16;
452 err = snd_pcm_plugin_build_mulaw(plug,
453 &srcformat, &tmpformat,
457 err = snd_pcm_plugin_append(plugin);
459 snd_pcm_plugin_free(plugin);
462 srcformat = tmpformat;
463 src_access = dst_access;
466 /* channels reduction */
467 if (srcformat.channels > dstformat.channels) {
468 tmpformat.channels = dstformat.channels;
469 err = snd_pcm_plugin_build_route(plug, &srcformat, &tmpformat, &plugin);
470 pdprintf("channels reduction: src=%i, dst=%i returns %i\n", srcformat.channels, tmpformat.channels, err);
473 err = snd_pcm_plugin_append(plugin);
475 snd_pcm_plugin_free(plugin);
478 srcformat = tmpformat;
479 src_access = dst_access;
482 /* rate resampling */
483 if (!rate_match(srcformat.rate, dstformat.rate)) {
484 if (srcformat.format != SNDRV_PCM_FORMAT_S16) {
485 /* convert to S16 for resampling */
486 tmpformat.format = SNDRV_PCM_FORMAT_S16;
487 err = snd_pcm_plugin_build_linear(plug,
488 &srcformat, &tmpformat,
492 err = snd_pcm_plugin_append(plugin);
494 snd_pcm_plugin_free(plugin);
497 srcformat = tmpformat;
498 src_access = dst_access;
500 tmpformat.rate = dstformat.rate;
501 err = snd_pcm_plugin_build_rate(plug,
502 &srcformat, &tmpformat,
504 pdprintf("rate down resampling: src=%i, dst=%i returns %i\n", srcformat.rate, tmpformat.rate, err);
507 err = snd_pcm_plugin_append(plugin);
509 snd_pcm_plugin_free(plugin);
512 srcformat = tmpformat;
513 src_access = dst_access;
517 if (srcformat.format != dstformat.format) {
518 tmpformat.format = dstformat.format;
519 if (srcformat.format == SNDRV_PCM_FORMAT_MU_LAW ||
520 tmpformat.format == SNDRV_PCM_FORMAT_MU_LAW) {
521 err = snd_pcm_plugin_build_mulaw(plug,
522 &srcformat, &tmpformat,
525 else if (snd_pcm_format_linear(srcformat.format) &&
526 snd_pcm_format_linear(tmpformat.format)) {
527 err = snd_pcm_plugin_build_linear(plug,
528 &srcformat, &tmpformat,
533 pdprintf("format change: src=%i, dst=%i returns %i\n", srcformat.format, tmpformat.format, err);
536 err = snd_pcm_plugin_append(plugin);
538 snd_pcm_plugin_free(plugin);
541 srcformat = tmpformat;
542 src_access = dst_access;
545 /* channels extension */
546 if (srcformat.channels < dstformat.channels) {
547 tmpformat.channels = dstformat.channels;
548 err = snd_pcm_plugin_build_route(plug, &srcformat, &tmpformat, &plugin);
549 pdprintf("channels extension: src=%i, dst=%i returns %i\n", srcformat.channels, tmpformat.channels, err);
552 err = snd_pcm_plugin_append(plugin);
554 snd_pcm_plugin_free(plugin);
557 srcformat = tmpformat;
558 src_access = dst_access;
562 if (src_access != dst_access) {
563 err = snd_pcm_plugin_build_copy(plug,
567 pdprintf("interleave change (copy: returns %i)\n", err);
570 err = snd_pcm_plugin_append(plugin);
572 snd_pcm_plugin_free(plugin);
580 snd_pcm_sframes_t snd_pcm_plug_client_channels_buf(struct snd_pcm_substream *plug,
582 snd_pcm_uframes_t count,
583 struct snd_pcm_plugin_channel **channels)
585 struct snd_pcm_plugin *plugin;
586 struct snd_pcm_plugin_channel *v;
587 struct snd_pcm_plugin_format *format;
588 int width, nchannels, channel;
589 int stream = snd_pcm_plug_stream(plug);
591 if (snd_BUG_ON(!buf))
593 if (stream == SNDRV_PCM_STREAM_PLAYBACK) {
594 plugin = snd_pcm_plug_first(plug);
595 format = &plugin->src_format;
597 plugin = snd_pcm_plug_last(plug);
598 format = &plugin->dst_format;
600 v = plugin->buf_channels;
602 if ((width = snd_pcm_format_physical_width(format->format)) < 0)
604 nchannels = format->channels;
605 if (snd_BUG_ON(plugin->access != SNDRV_PCM_ACCESS_RW_INTERLEAVED &&
606 format->channels > 1))
608 for (channel = 0; channel < nchannels; channel++, v++) {
611 v->wanted = (stream == SNDRV_PCM_STREAM_CAPTURE);
613 v->area.first = channel * width;
614 v->area.step = nchannels * width;
619 snd_pcm_sframes_t snd_pcm_plug_write_transfer(struct snd_pcm_substream *plug, struct snd_pcm_plugin_channel *src_channels, snd_pcm_uframes_t size)
621 struct snd_pcm_plugin *plugin, *next;
622 struct snd_pcm_plugin_channel *dst_channels;
624 snd_pcm_sframes_t frames = size;
626 plugin = snd_pcm_plug_first(plug);
630 if ((next = plugin->next) != NULL) {
631 snd_pcm_sframes_t frames1 = frames;
632 if (plugin->dst_frames) {
633 frames1 = plugin->dst_frames(plugin, frames);
637 if ((err = next->client_channels(next, frames1, &dst_channels)) < 0) {
640 if (err != frames1) {
642 if (plugin->src_frames) {
643 frames = plugin->src_frames(plugin, frames1);
650 pdprintf("write plugin: %s, %li\n", plugin->name, frames);
651 if ((frames = plugin->transfer(plugin, src_channels, dst_channels, frames)) < 0)
653 src_channels = dst_channels;
656 return plug_client_size(plug, frames, true);
659 snd_pcm_sframes_t snd_pcm_plug_read_transfer(struct snd_pcm_substream *plug, struct snd_pcm_plugin_channel *dst_channels_final, snd_pcm_uframes_t size)
661 struct snd_pcm_plugin *plugin, *next;
662 struct snd_pcm_plugin_channel *src_channels, *dst_channels;
663 snd_pcm_sframes_t frames = size;
666 frames = plug_slave_size(plug, frames, true);
671 plugin = snd_pcm_plug_first(plug);
672 while (plugin && frames > 0) {
673 if ((next = plugin->next) != NULL) {
674 if ((err = plugin->client_channels(plugin, frames, &dst_channels)) < 0) {
679 dst_channels = dst_channels_final;
681 pdprintf("read plugin: %s, %li\n", plugin->name, frames);
682 if ((frames = plugin->transfer(plugin, src_channels, dst_channels, frames)) < 0)
685 src_channels = dst_channels;
690 int snd_pcm_area_silence(const struct snd_pcm_channel_area *dst_area, size_t dst_offset,
691 size_t samples, snd_pcm_format_t format)
693 /* FIXME: sub byte resolution and odd dst_offset */
695 unsigned int dst_step;
697 const unsigned char *silence;
700 dst = dst_area->addr + (dst_area->first + dst_area->step * dst_offset) / 8;
701 width = snd_pcm_format_physical_width(format);
704 if (dst_area->step == (unsigned int) width && width >= 8)
705 return snd_pcm_format_set_silence(format, dst, samples);
706 silence = snd_pcm_format_silence_64(format);
709 dst_step = dst_area->step / 8;
712 int dstbit = dst_area->first % 8;
713 int dstbit_step = dst_area->step % 8;
714 while (samples-- > 0) {
720 dstbit += dstbit_step;
728 while (samples-- > 0) {
729 memcpy(dst, silence, width);
736 int snd_pcm_area_copy(const struct snd_pcm_channel_area *src_area, size_t src_offset,
737 const struct snd_pcm_channel_area *dst_area, size_t dst_offset,
738 size_t samples, snd_pcm_format_t format)
740 /* FIXME: sub byte resolution and odd dst_offset */
743 int src_step, dst_step;
744 src = src_area->addr + (src_area->first + src_area->step * src_offset) / 8;
746 return snd_pcm_area_silence(dst_area, dst_offset, samples, format);
747 dst = dst_area->addr + (dst_area->first + dst_area->step * dst_offset) / 8;
750 width = snd_pcm_format_physical_width(format);
753 if (src_area->step == (unsigned int) width &&
754 dst_area->step == (unsigned int) width && width >= 8) {
755 size_t bytes = samples * width / 8;
756 memcpy(dst, src, bytes);
759 src_step = src_area->step / 8;
760 dst_step = dst_area->step / 8;
763 int srcbit = src_area->first % 8;
764 int srcbit_step = src_area->step % 8;
765 int dstbit = dst_area->first % 8;
766 int dstbit_step = dst_area->step % 8;
767 while (samples-- > 0) {
768 unsigned char srcval;
770 srcval = *src & 0x0f;
772 srcval = (*src & 0xf0) >> 4;
774 *dst = (*dst & 0xf0) | srcval;
776 *dst = (*dst & 0x0f) | (srcval << 4);
778 srcbit += srcbit_step;
784 dstbit += dstbit_step;
792 while (samples-- > 0) {
793 memcpy(dst, src, width);