swresample.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527
  1. /*
  2. * Copyright (C) 2011 Michael Niedermayer (michaelni@gmx.at)
  3. *
  4. * This file is part of libswresample
  5. *
  6. * libswresample 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. * libswresample 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 libswresample; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "libavutil/opt.h"
  21. #include "swresample_internal.h"
  22. #include "audioconvert.h"
  23. #include "libavutil/avassert.h"
  24. #include "libavutil/audioconvert.h"
  25. #define C30DB M_SQRT2
  26. #define C15DB 1.189207115
  27. #define C__0DB 1.0
  28. #define C_15DB 0.840896415
  29. #define C_30DB M_SQRT1_2
  30. #define C_45DB 0.594603558
  31. #define C_60DB 0.5
  32. //TODO split options array out?
  33. #define OFFSET(x) offsetof(SwrContext,x)
  34. static const AVOption options[]={
  35. {"ich", "input channel count", OFFSET( in.ch_count ), AV_OPT_TYPE_INT, {.dbl=2}, 0, SWR_CH_MAX, 0},
  36. {"och", "output channel count", OFFSET(out.ch_count ), AV_OPT_TYPE_INT, {.dbl=2}, 0, SWR_CH_MAX, 0},
  37. {"uch", "used channel count", OFFSET(used_ch_count ), AV_OPT_TYPE_INT, {.dbl=0}, 0, SWR_CH_MAX, 0},
  38. {"isr", "input sample rate" , OFFSET( in_sample_rate), AV_OPT_TYPE_INT, {.dbl=48000}, 1, INT_MAX, 0},
  39. {"osr", "output sample rate" , OFFSET(out_sample_rate), AV_OPT_TYPE_INT, {.dbl=48000}, 1, INT_MAX, 0},
  40. //{"ip" , "input planar" , OFFSET( in.planar ), AV_OPT_TYPE_INT, {.dbl=0}, 0, 1, 0},
  41. //{"op" , "output planar" , OFFSET(out.planar ), AV_OPT_TYPE_INT, {.dbl=0}, 0, 1, 0},
  42. {"isf", "input sample format", OFFSET( in_sample_fmt ), AV_OPT_TYPE_INT, {.dbl=AV_SAMPLE_FMT_S16}, 0, AV_SAMPLE_FMT_NB-1+256, 0},
  43. {"osf", "output sample format", OFFSET(out_sample_fmt ), AV_OPT_TYPE_INT, {.dbl=AV_SAMPLE_FMT_S16}, 0, AV_SAMPLE_FMT_NB-1+256, 0},
  44. {"tsf", "internal sample format", OFFSET(int_sample_fmt ), AV_OPT_TYPE_INT, {.dbl=AV_SAMPLE_FMT_NONE}, -1, AV_SAMPLE_FMT_FLT, 0},
  45. {"icl", "input channel layout" , OFFSET( in_ch_layout), AV_OPT_TYPE_INT64, {.dbl=0}, 0, INT64_MAX, 0, "channel_layout"},
  46. {"ocl", "output channel layout", OFFSET(out_ch_layout), AV_OPT_TYPE_INT64, {.dbl=0}, 0, INT64_MAX, 0, "channel_layout"},
  47. {"clev", "center mix level" , OFFSET(clev) , AV_OPT_TYPE_FLOAT, {.dbl=C_30DB}, 0, 4, 0},
  48. {"slev", "sourround mix level" , OFFSET(slev) , AV_OPT_TYPE_FLOAT, {.dbl=C_30DB}, 0, 4, 0},
  49. {"rmvol", "rematrix volume" , OFFSET(rematrix_volume), AV_OPT_TYPE_FLOAT, {.dbl=1.0}, -1000, 1000, 0},
  50. {"flags", NULL , OFFSET(flags) , AV_OPT_TYPE_FLAGS, {.dbl=0}, 0, UINT_MAX, 0, "flags"},
  51. {"res", "force resampling", 0, AV_OPT_TYPE_CONST, {.dbl=SWR_FLAG_RESAMPLE}, INT_MIN, INT_MAX, 0, "flags"},
  52. {0}
  53. };
  54. static const char* context_to_name(void* ptr) {
  55. return "SWR";
  56. }
  57. static const AVClass av_class = {
  58. .class_name = "SwrContext",
  59. .item_name = context_to_name,
  60. .option = options,
  61. .version = LIBAVUTIL_VERSION_INT,
  62. .log_level_offset_offset = OFFSET(log_level_offset),
  63. .parent_log_context_offset = OFFSET(log_ctx),
  64. };
  65. unsigned swresample_version(void)
  66. {
  67. av_assert0(LIBSWRESAMPLE_VERSION_MICRO >= 100);
  68. return LIBSWRESAMPLE_VERSION_INT;
  69. }
  70. const char *swresample_configuration(void)
  71. {
  72. return FFMPEG_CONFIGURATION;
  73. }
  74. const char *swresample_license(void)
  75. {
  76. #define LICENSE_PREFIX "libswresample license: "
  77. return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1;
  78. }
  79. int swr_set_channel_mapping(struct SwrContext *s, const int *channel_map){
  80. if(!s || s->in_convert) // s needs to be allocated but not initialized
  81. return AVERROR(EINVAL);
  82. s->channel_map = channel_map;
  83. return 0;
  84. }
  85. struct SwrContext *swr_alloc(void){
  86. SwrContext *s= av_mallocz(sizeof(SwrContext));
  87. if(s){
  88. s->av_class= &av_class;
  89. av_opt_set_defaults(s);
  90. }
  91. return s;
  92. }
  93. struct SwrContext *swr_alloc_set_opts(struct SwrContext *s,
  94. int64_t out_ch_layout, enum AVSampleFormat out_sample_fmt, int out_sample_rate,
  95. int64_t in_ch_layout, enum AVSampleFormat in_sample_fmt, int in_sample_rate,
  96. int log_offset, void *log_ctx){
  97. if(!s) s= swr_alloc();
  98. if(!s) return NULL;
  99. s->log_level_offset= log_offset;
  100. s->log_ctx= log_ctx;
  101. av_opt_set_int(s, "ocl", out_ch_layout, 0);
  102. av_opt_set_int(s, "osf", out_sample_fmt, 0);
  103. av_opt_set_int(s, "osr", out_sample_rate, 0);
  104. av_opt_set_int(s, "icl", in_ch_layout, 0);
  105. av_opt_set_int(s, "isf", in_sample_fmt, 0);
  106. av_opt_set_int(s, "isr", in_sample_rate, 0);
  107. av_opt_set_int(s, "tsf", AV_SAMPLE_FMT_S16, 0);
  108. av_opt_set_int(s, "ich", av_get_channel_layout_nb_channels(s-> in_ch_layout), 0);
  109. av_opt_set_int(s, "och", av_get_channel_layout_nb_channels(s->out_ch_layout), 0);
  110. av_opt_set_int(s, "uch", 0, 0);
  111. return s;
  112. }
  113. static void free_temp(AudioData *a){
  114. av_free(a->data);
  115. memset(a, 0, sizeof(*a));
  116. }
  117. void swr_free(SwrContext **ss){
  118. SwrContext *s= *ss;
  119. if(s){
  120. free_temp(&s->postin);
  121. free_temp(&s->midbuf);
  122. free_temp(&s->preout);
  123. free_temp(&s->in_buffer);
  124. swri_audio_convert_free(&s-> in_convert);
  125. swri_audio_convert_free(&s->out_convert);
  126. swri_audio_convert_free(&s->full_convert);
  127. swri_resample_free(&s->resample);
  128. }
  129. av_freep(ss);
  130. }
  131. int swr_init(struct SwrContext *s){
  132. s->in_buffer_index= 0;
  133. s->in_buffer_count= 0;
  134. s->resample_in_constraint= 0;
  135. free_temp(&s->postin);
  136. free_temp(&s->midbuf);
  137. free_temp(&s->preout);
  138. free_temp(&s->in_buffer);
  139. swri_audio_convert_free(&s-> in_convert);
  140. swri_audio_convert_free(&s->out_convert);
  141. swri_audio_convert_free(&s->full_convert);
  142. s-> in.planar= av_sample_fmt_is_planar(s-> in_sample_fmt);
  143. s->out.planar= av_sample_fmt_is_planar(s->out_sample_fmt);
  144. s-> in_sample_fmt= av_get_alt_sample_fmt(s-> in_sample_fmt, 0);
  145. s->out_sample_fmt= av_get_alt_sample_fmt(s->out_sample_fmt, 0);
  146. if(s-> in_sample_fmt >= AV_SAMPLE_FMT_NB){
  147. av_log(s, AV_LOG_ERROR, "Requested input sample format %d is invalid\n", s->in_sample_fmt);
  148. return AVERROR(EINVAL);
  149. }
  150. if(s->out_sample_fmt >= AV_SAMPLE_FMT_NB){
  151. av_log(s, AV_LOG_ERROR, "Requested output sample format %d is invalid\n", s->out_sample_fmt);
  152. return AVERROR(EINVAL);
  153. }
  154. if( s->int_sample_fmt != AV_SAMPLE_FMT_S16
  155. &&s->int_sample_fmt != AV_SAMPLE_FMT_FLT){
  156. av_log(s, AV_LOG_ERROR, "Requested sample format %s is not supported internally, only float & S16 is supported\n", av_get_sample_fmt_name(s->int_sample_fmt));
  157. return AVERROR(EINVAL);
  158. }
  159. //FIXME should we allow/support using FLT on material that doesnt need it ?
  160. if(s->in_sample_fmt <= AV_SAMPLE_FMT_S16 || s->int_sample_fmt==AV_SAMPLE_FMT_S16){
  161. s->int_sample_fmt= AV_SAMPLE_FMT_S16;
  162. }else
  163. s->int_sample_fmt= AV_SAMPLE_FMT_FLT;
  164. if (s->out_sample_rate!=s->in_sample_rate || (s->flags & SWR_FLAG_RESAMPLE)){
  165. s->resample = swri_resample_init(s->resample, s->out_sample_rate, s->in_sample_rate, 16, 10, 0, 0.8);
  166. }else
  167. swri_resample_free(&s->resample);
  168. if(s->int_sample_fmt != AV_SAMPLE_FMT_S16 && s->resample){
  169. av_log(s, AV_LOG_ERROR, "Resampling only supported with internal s16 currently\n"); //FIXME
  170. return -1;
  171. }
  172. if(!s->used_ch_count)
  173. s->used_ch_count= s->in.ch_count;
  174. if(s->used_ch_count && s-> in_ch_layout && s->used_ch_count != av_get_channel_layout_nb_channels(s-> in_ch_layout)){
  175. av_log(s, AV_LOG_WARNING, "Input channel layout has a different number of channels than the number of used channels, ignoring layout\n");
  176. s-> in_ch_layout= 0;
  177. }
  178. if(!s-> in_ch_layout)
  179. s-> in_ch_layout= av_get_default_channel_layout(s->used_ch_count);
  180. if(!s->out_ch_layout)
  181. s->out_ch_layout= av_get_default_channel_layout(s->out.ch_count);
  182. s->rematrix= s->out_ch_layout !=s->in_ch_layout || s->rematrix_volume!=1.0;
  183. #define RSC 1 //FIXME finetune
  184. if(!s-> in.ch_count)
  185. s-> in.ch_count= av_get_channel_layout_nb_channels(s-> in_ch_layout);
  186. if(!s->used_ch_count)
  187. s->used_ch_count= s->in.ch_count;
  188. if(!s->out.ch_count)
  189. s->out.ch_count= av_get_channel_layout_nb_channels(s->out_ch_layout);
  190. if(!s-> in.ch_count){
  191. av_assert0(!s->in_ch_layout);
  192. av_log(s, AV_LOG_ERROR, "Input channel count and layout are unset\n");
  193. return -1;
  194. }
  195. av_assert0(s->used_ch_count);
  196. av_assert0(s->out.ch_count);
  197. s->resample_first= RSC*s->out.ch_count/s->in.ch_count - RSC < s->out_sample_rate/(float)s-> in_sample_rate - 1.0;
  198. s-> in.bps= av_get_bytes_per_sample(s-> in_sample_fmt);
  199. s->int_bps= av_get_bytes_per_sample(s->int_sample_fmt);
  200. s->out.bps= av_get_bytes_per_sample(s->out_sample_fmt);
  201. if(!s->resample && !s->rematrix && !s->channel_map){
  202. s->full_convert = swri_audio_convert_alloc(s->out_sample_fmt,
  203. s-> in_sample_fmt, s-> in.ch_count, NULL, 0);
  204. return 0;
  205. }
  206. s->in_convert = swri_audio_convert_alloc(s->int_sample_fmt,
  207. s-> in_sample_fmt, s->used_ch_count, s->channel_map, 0);
  208. s->out_convert= swri_audio_convert_alloc(s->out_sample_fmt,
  209. s->int_sample_fmt, s->out.ch_count, NULL, 0);
  210. s->postin= s->in;
  211. s->preout= s->out;
  212. s->midbuf= s->in;
  213. s->in_buffer= s->in;
  214. if(s->channel_map){
  215. s->postin.ch_count=
  216. s->midbuf.ch_count=
  217. s->in_buffer.ch_count= s->used_ch_count;
  218. }
  219. if(!s->resample_first){
  220. s->midbuf.ch_count= s->out.ch_count;
  221. s->in_buffer.ch_count = s->out.ch_count;
  222. }
  223. s->in_buffer.bps = s->postin.bps = s->midbuf.bps = s->preout.bps = s->int_bps;
  224. s->in_buffer.planar = s->postin.planar = s->midbuf.planar = s->preout.planar = 1;
  225. if(s->rematrix)
  226. return swri_rematrix_init(s);
  227. return 0;
  228. }
  229. static int realloc_audio(AudioData *a, int count){
  230. int i, countb;
  231. AudioData old;
  232. if(a->count >= count)
  233. return 0;
  234. count*=2;
  235. countb= FFALIGN(count*a->bps, 32);
  236. old= *a;
  237. av_assert0(a->planar);
  238. av_assert0(a->bps);
  239. av_assert0(a->ch_count);
  240. a->data= av_malloc(countb*a->ch_count);
  241. if(!a->data)
  242. return AVERROR(ENOMEM);
  243. for(i=0; i<a->ch_count; i++){
  244. a->ch[i]= a->data + i*(a->planar ? countb : a->bps);
  245. if(a->planar) memcpy(a->ch[i], old.ch[i], a->count*a->bps);
  246. }
  247. av_free(old.data);
  248. a->count= count;
  249. return 1;
  250. }
  251. static void copy(AudioData *out, AudioData *in,
  252. int count){
  253. av_assert0(out->planar == in->planar);
  254. av_assert0(out->bps == in->bps);
  255. av_assert0(out->ch_count == in->ch_count);
  256. if(out->planar){
  257. int ch;
  258. for(ch=0; ch<out->ch_count; ch++)
  259. memcpy(out->ch[ch], in->ch[ch], count*out->bps);
  260. }else
  261. memcpy(out->ch[0], in->ch[0], count*out->ch_count*out->bps);
  262. }
  263. static void fill_audiodata(AudioData *out, uint8_t *in_arg [SWR_CH_MAX]){
  264. int i;
  265. if(out->planar){
  266. for(i=0; i<out->ch_count; i++)
  267. out->ch[i]= in_arg[i];
  268. }else{
  269. for(i=0; i<out->ch_count; i++)
  270. out->ch[i]= in_arg[0] + i*out->bps;
  271. }
  272. }
  273. /**
  274. *
  275. * out may be equal in.
  276. */
  277. static void buf_set(AudioData *out, AudioData *in, int count){
  278. if(in->planar){
  279. int ch;
  280. for(ch=0; ch<out->ch_count; ch++)
  281. out->ch[ch]= in->ch[ch] + count*out->bps;
  282. }else
  283. out->ch[0]= in->ch[0] + count*out->ch_count*out->bps;
  284. }
  285. /**
  286. *
  287. * @return number of samples output per channel
  288. */
  289. static int resample(SwrContext *s, AudioData *out_param, int out_count,
  290. const AudioData * in_param, int in_count){
  291. AudioData in, out, tmp;
  292. int ret_sum=0;
  293. int border=0;
  294. tmp=out=*out_param;
  295. in = *in_param;
  296. do{
  297. int ret, size, consumed;
  298. if(!s->resample_in_constraint && s->in_buffer_count){
  299. buf_set(&tmp, &s->in_buffer, s->in_buffer_index);
  300. ret= swri_multiple_resample(s->resample, &out, out_count, &tmp, s->in_buffer_count, &consumed);
  301. out_count -= ret;
  302. ret_sum += ret;
  303. buf_set(&out, &out, ret);
  304. s->in_buffer_count -= consumed;
  305. s->in_buffer_index += consumed;
  306. if(!in_count)
  307. break;
  308. if(s->in_buffer_count <= border){
  309. buf_set(&in, &in, -s->in_buffer_count);
  310. in_count += s->in_buffer_count;
  311. s->in_buffer_count=0;
  312. s->in_buffer_index=0;
  313. border = 0;
  314. }
  315. }
  316. if(in_count && !s->in_buffer_count){
  317. s->in_buffer_index=0;
  318. ret= swri_multiple_resample(s->resample, &out, out_count, &in, in_count, &consumed);
  319. out_count -= ret;
  320. ret_sum += ret;
  321. buf_set(&out, &out, ret);
  322. in_count -= consumed;
  323. buf_set(&in, &in, consumed);
  324. }
  325. //TODO is this check sane considering the advanced copy avoidance below
  326. size= s->in_buffer_index + s->in_buffer_count + in_count;
  327. if( size > s->in_buffer.count
  328. && s->in_buffer_count + in_count <= s->in_buffer_index){
  329. buf_set(&tmp, &s->in_buffer, s->in_buffer_index);
  330. copy(&s->in_buffer, &tmp, s->in_buffer_count);
  331. s->in_buffer_index=0;
  332. }else
  333. if((ret=realloc_audio(&s->in_buffer, size)) < 0)
  334. return ret;
  335. if(in_count){
  336. int count= in_count;
  337. if(s->in_buffer_count && s->in_buffer_count+2 < count && out_count) count= s->in_buffer_count+2;
  338. buf_set(&tmp, &s->in_buffer, s->in_buffer_index + s->in_buffer_count);
  339. copy(&tmp, &in, /*in_*/count);
  340. s->in_buffer_count += count;
  341. in_count -= count;
  342. border += count;
  343. buf_set(&in, &in, count);
  344. s->resample_in_constraint= 0;
  345. if(s->in_buffer_count != count || in_count)
  346. continue;
  347. }
  348. break;
  349. }while(1);
  350. s->resample_in_constraint= !!out_count;
  351. return ret_sum;
  352. }
  353. int swr_convert(struct SwrContext *s, uint8_t *out_arg[SWR_CH_MAX], int out_count,
  354. const uint8_t *in_arg [SWR_CH_MAX], int in_count){
  355. AudioData *postin, *midbuf, *preout;
  356. int ret/*, in_max*/;
  357. AudioData * in= &s->in;
  358. AudioData *out= &s->out;
  359. AudioData preout_tmp, midbuf_tmp;
  360. if(!s->resample){
  361. if(in_count > out_count)
  362. return -1;
  363. out_count = in_count;
  364. }
  365. if(!in_arg){
  366. if(s->in_buffer_count){
  367. AudioData *a= &s->in_buffer;
  368. int i, j, ret;
  369. if((ret=realloc_audio(a, s->in_buffer_index + 2*s->in_buffer_count)) < 0)
  370. return ret;
  371. av_assert0(a->planar);
  372. for(i=0; i<a->ch_count; i++){
  373. for(j=0; j<s->in_buffer_count; j++){
  374. memcpy(a->ch[i] + (s->in_buffer_index+s->in_buffer_count+j )*a->bps,
  375. a->ch[i] + (s->in_buffer_index+s->in_buffer_count-j-1)*a->bps, a->bps);
  376. }
  377. }
  378. s->in_buffer_count += (s->in_buffer_count+1)/2;
  379. s->resample_in_constraint = 0;
  380. }else{
  381. return 0;
  382. }
  383. }else
  384. fill_audiodata(in , (void*)in_arg);
  385. fill_audiodata(out, out_arg);
  386. if(s->full_convert){
  387. av_assert0(!s->resample);
  388. swri_audio_convert(s->full_convert, out, in, in_count);
  389. return out_count;
  390. }
  391. // in_max= out_count*(int64_t)s->in_sample_rate / s->out_sample_rate + resample_filter_taps;
  392. // in_count= FFMIN(in_count, in_in + 2 - s->hist_buffer_count);
  393. if((ret=realloc_audio(&s->postin, in_count))<0)
  394. return ret;
  395. if(s->resample_first){
  396. av_assert0(s->midbuf.ch_count == s->used_ch_count);
  397. if((ret=realloc_audio(&s->midbuf, out_count))<0)
  398. return ret;
  399. }else{
  400. av_assert0(s->midbuf.ch_count == s->out.ch_count);
  401. if((ret=realloc_audio(&s->midbuf, in_count))<0)
  402. return ret;
  403. }
  404. if((ret=realloc_audio(&s->preout, out_count))<0)
  405. return ret;
  406. postin= &s->postin;
  407. midbuf_tmp= s->midbuf;
  408. midbuf= &midbuf_tmp;
  409. preout_tmp= s->preout;
  410. preout= &preout_tmp;
  411. if(s->int_sample_fmt == s-> in_sample_fmt && s->in.planar)
  412. postin= in;
  413. if(s->resample_first ? !s->resample : !s->rematrix)
  414. midbuf= postin;
  415. if(s->resample_first ? !s->rematrix : !s->resample)
  416. preout= midbuf;
  417. if(s->int_sample_fmt == s->out_sample_fmt && s->out.planar){
  418. if(preout==in){
  419. out_count= FFMIN(out_count, in_count); //TODO check at teh end if this is needed or redundant
  420. av_assert0(s->in.planar); //we only support planar internally so it has to be, we support copying non planar though
  421. copy(out, in, out_count);
  422. return out_count;
  423. }
  424. else if(preout==postin) preout= midbuf= postin= out;
  425. else if(preout==midbuf) preout= midbuf= out;
  426. else preout= out;
  427. }
  428. if(in != postin){
  429. swri_audio_convert(s->in_convert, postin, in, in_count);
  430. }
  431. if(s->resample_first){
  432. if(postin != midbuf)
  433. out_count= resample(s, midbuf, out_count, postin, in_count);
  434. if(midbuf != preout)
  435. swri_rematrix(s, preout, midbuf, out_count, preout==out);
  436. }else{
  437. if(postin != midbuf)
  438. swri_rematrix(s, midbuf, postin, in_count, midbuf==out);
  439. if(midbuf != preout)
  440. out_count= resample(s, preout, out_count, midbuf, in_count);
  441. }
  442. if(preout != out){
  443. //FIXME packed doesnt need more than 1 chan here!
  444. swri_audio_convert(s->out_convert, out, preout, out_count);
  445. }
  446. if(!in_arg)
  447. s->in_buffer_count = 0;
  448. return out_count;
  449. }