• Home
  • History
  • Annotate
  • Raw
  • Download
  • only in /netgear-R7000-V1.0.7.12_1.2.5/ap/gpl/minidlna/ffmpeg-2.3.4/libavresample/

Lines Matching defs:avr

35 int avresample_open(AVAudioResampleContext *avr)
39 if (avresample_is_open(avr)) {
40 av_log(avr, AV_LOG_ERROR, "The resampling context is already open.\n");
45 avr->in_channels = av_get_channel_layout_nb_channels(avr->in_channel_layout);
46 if (avr->in_channels <= 0 || avr->in_channels > AVRESAMPLE_MAX_CHANNELS) {
47 av_log(avr, AV_LOG_ERROR, "Invalid input channel layout: %"PRIu64"\n",
48 avr->in_channel_layout);
51 avr->out_channels = av_get_channel_layout_nb_channels(avr->out_channel_layout);
52 if (avr->out_channels <= 0 || avr->out_channels > AVRESAMPLE_MAX_CHANNELS) {
53 av_log(avr, AV_LOG_ERROR, "Invalid output channel layout: %"PRIu64"\n",
54 avr->out_channel_layout);
57 avr->resample_channels = FFMIN(avr->in_channels, avr->out_channels);
58 avr->downmix_needed = avr->in_channels > avr->out_channels;
59 avr->upmix_needed = avr->out_channels > avr->in_channels ||
60 (!avr->downmix_needed && (avr->mix_matrix ||
61 avr->in_channel_layout != avr->out_channel_layout));
62 avr->mixing_needed = avr->downmix_needed || avr->upmix_needed;
65 avr->resample_needed = avr->in_sample_rate != avr->out_sample_rate ||
66 avr->force_resampling;
69 if (avr->internal_sample_fmt == AV_SAMPLE_FMT_NONE &&
70 (avr->mixing_needed || avr->resample_needed)) {
71 enum AVSampleFormat in_fmt = av_get_planar_sample_fmt(avr->in_sample_fmt);
72 enum AVSampleFormat out_fmt = av_get_planar_sample_fmt(avr->out_sample_fmt);
76 avr->internal_sample_fmt = AV_SAMPLE_FMT_S16P;
77 } else if (avr->mixing_needed) {
78 avr->internal_sample_fmt = AV_SAMPLE_FMT_FLTP;
86 avr->internal_sample_fmt = AV_SAMPLE_FMT_DBLP;
89 avr->internal_sample_fmt = AV_SAMPLE_FMT_S32P;
93 avr->internal_sample_fmt = AV_SAMPLE_FMT_FLTP;
97 avr->internal_sample_fmt = AV_SAMPLE_FMT_DBLP;
100 av_log(avr, AV_LOG_DEBUG, "Using %s as internal sample format\n",
101 av_get_sample_fmt_name(avr->internal_sample_fmt));
105 if (avr->in_channels == 1)
106 avr->in_sample_fmt = av_get_planar_sample_fmt(avr->in_sample_fmt);
107 if (avr->out_channels == 1)
108 avr->out_sample_fmt = av_get_planar_sample_fmt(avr->out_sample_fmt);
112 if (avr->use_channel_map && !avr->mixing_needed && !avr->resample_needed &&
113 !av_sample_fmt_is_planar(avr->out_sample_fmt)) {
114 avr->internal_sample_fmt = av_get_planar_sample_fmt(avr->out_sample_fmt);
118 if (avr->resample_needed || avr->mixing_needed)
119 avr->in_convert_needed = avr->in_sample_fmt != avr->internal_sample_fmt;
121 avr->in_convert_needed = avr->use_channel_map &&
122 !av_sample_fmt_is_planar(avr->out_sample_fmt);
124 if (avr->resample_needed || avr->mixing_needed || avr->in_convert_needed)
125 avr->out_convert_needed = avr->internal_sample_fmt != avr->out_sample_fmt;
127 avr->out_convert_needed = avr->in_sample_fmt != avr->out_sample_fmt;
129 avr->in_copy_needed = !avr->in_convert_needed && (avr->mixing_needed ||
130 (avr->use_channel_map && avr->resample_needed));
132 if (avr->use_channel_map) {
133 if (avr->in_copy_needed) {
134 avr->remap_point = REMAP_IN_COPY;
135 av_dlog(avr, "remap channels during in_copy\n");
136 } else if (avr->in_convert_needed) {
137 avr->remap_point = REMAP_IN_CONVERT;
138 av_dlog(avr, "remap channels during in_convert\n");
139 } else if (avr->out_convert_needed) {
140 avr->remap_point = REMAP_OUT_CONVERT;
141 av_dlog(avr, "remap channels during out_convert\n");
143 avr->remap_point = REMAP_OUT_COPY;
144 av_dlog(avr, "remap channels during out_copy\n");
150 av_dlog(avr, "output map: ");
151 if (avr->ch_map_info.do_remap)
152 for (ch = 0; ch < avr->in_channels; ch++)
153 av_dlog(avr, " % 2d", avr->ch_map_info.channel_map[ch]);
155 av_dlog(avr, "n/a");
156 av_dlog(avr, "\n");
157 av_dlog(avr, "copy map: ");
158 if (avr->ch_map_info.do_copy)
159 for (ch = 0; ch < avr->in_channels; ch++)
160 av_dlog(avr, " % 2d", avr->ch_map_info.channel_copy[ch]);
162 av_dlog(avr, "n/a");
163 av_dlog(avr, "\n");
164 av_dlog(avr, "zero map: ");
165 if (avr->ch_map_info.do_zero)
166 for (ch = 0; ch < avr->in_channels; ch++)
167 av_dlog(avr, " % 2d", avr->ch_map_info.channel_zero[ch]);
169 av_dlog(avr, "n/a");
170 av_dlog(avr, "\n");
171 av_dlog(avr, "input map: ");
172 for (ch = 0; ch < avr->in_channels; ch++)
173 av_dlog(avr, " % 2d", avr->ch_map_info.input_map[ch]);
174 av_dlog(avr, "\n");
178 avr->remap_point = REMAP_NONE;
181 if (avr->in_copy_needed || avr->in_convert_needed) {
182 avr->in_buffer = ff_audio_data_alloc(FFMAX(avr->in_channels, avr->out_channels),
183 0, avr->internal_sample_fmt,
185 if (!avr->in_buffer) {
190 if (avr->resample_needed) {
191 avr->resample_out_buffer = ff_audio_data_alloc(avr->out_channels,
192 1024, avr->internal_sample_fmt,
194 if (!avr->resample_out_buffer) {
199 if (avr->out_convert_needed) {
200 avr->out_buffer = ff_audio_data_alloc(avr->out_channels, 0,
201 avr->out_sample_fmt, "out_buffer");
202 if (!avr->out_buffer) {
207 avr->out_fifo = av_audio_fifo_alloc(avr->out_sample_fmt, avr->out_channels,
209 if (!avr->out_fifo) {
215 if (avr->in_convert_needed) {
216 avr->ac_in = ff_audio_convert_alloc(avr, avr->internal_sample_fmt,
217 avr->in_sample_fmt, avr->in_channels,
218 avr->in_sample_rate,
219 avr->remap_point == REMAP_IN_CONVERT);
220 if (!avr->ac_in) {
225 if (avr->out_convert_needed) {
227 if (avr->in_convert_needed)
228 src_fmt = avr->internal_sample_fmt;
230 src_fmt = avr->in_sample_fmt;
231 avr->ac_out = ff_audio_convert_alloc(avr, avr->out_sample_fmt, src_fmt,
232 avr->out_channels,
233 avr->out_sample_rate,
234 avr->remap_point == REMAP_OUT_CONVERT);
235 if (!avr->ac_out) {
240 if (avr->resample_needed) {
241 avr->resample = ff_audio_resample_init(avr);
242 if (!avr->resample) {
247 if (avr->mixing_needed) {
248 avr->am = ff_audio_mix_alloc(avr);
249 if (!avr->am) {
258 avresample_close(avr);
262 int avresample_is_open(AVAudioResampleContext *avr)
264 return !!avr->out_fifo;
267 void avresample_close(AVAudioResampleContext *avr)
269 ff_audio_data_free(&avr->in_buffer);
270 ff_audio_data_free(&avr->resample_out_buffer);
271 ff_audio_data_free(&avr->out_buffer);
272 av_audio_fifo_free(avr->out_fifo);
273 avr->out_fifo = NULL;
274 ff_audio_convert_free(&avr->ac_in);
275 ff_audio_convert_free(&avr->ac_out);
276 ff_audio_resample_free(&avr->resample);
277 ff_audio_mix_free(&avr->am);
278 av_freep(&avr->mix_matrix);
280 avr->use_channel_map = 0;
283 void avresample_free(AVAudioResampleContext **avr)
285 if (!*avr)
287 avresample_close(*avr);
288 av_opt_free(*avr);
289 av_freep(avr);
292 static int handle_buffered_output(AVAudioResampleContext *avr,
297 if (!output || av_audio_fifo_size(avr->out_fifo) > 0 ||
303 av_dlog(avr, "[FIFO] add %s to out_fifo\n", converted->name);
304 ret = ff_audio_data_add_to_fifo(avr->out_fifo, converted, 0,
313 av_dlog(avr, "[FIFO] read from out_fifo to output\n");
314 av_dlog(avr, "[end conversion]\n");
315 return ff_audio_data_read_from_fifo(avr->out_fifo, output,
321 av_dlog(avr, "[copy] %s to output\n", converted->name);
324 avr->remap_point == REMAP_OUT_COPY ?
325 &avr->ch_map_info : NULL);
328 av_dlog(avr, "[end conversion]\n");
331 av_dlog(avr, "[end conversion]\n");
335 int attribute_align_arg avresample_convert(AVAudioResampleContext *avr,
346 if (avr->in_buffer) {
347 avr->in_buffer->nb_samples = 0;
348 ff_audio_data_set_channels(avr->in_buffer,
349 avr->in_buffer->allocated_channels);
351 if (avr->resample_out_buffer) {
352 avr->resample_out_buffer->nb_samples = 0;
353 ff_audio_data_set_channels(avr->resample_out_buffer,
354 avr->resample_out_buffer->allocated_channels);
356 if (avr->out_buffer) {
357 avr->out_buffer->nb_samples = 0;
358 ff_audio_data_set_channels(avr->out_buffer,
359 avr->out_buffer->allocated_channels);
362 av_dlog(avr, "[start conversion]\n");
365 direct_output = output && av_audio_fifo_size(avr->out_fifo) == 0;
368 avr->out_channels, out_samples,
369 avr->out_sample_fmt, 0, "output");
378 avr->in_channels, in_samples,
379 avr->in_sample_fmt, 1, "input");
384 if (avr->upmix_needed && !avr->in_convert_needed && !avr->resample_needed &&
385 !avr->out_convert_needed && direct_output && out_samples >= in_samples) {
388 av_dlog(avr, "[copy] %s to output\n", current_buffer->name);
390 avr->remap_point == REMAP_OUT_COPY ?
391 &avr->ch_map_info : NULL);
395 } else if (avr->remap_point == REMAP_OUT_COPY &&
400 av_dlog(avr, "[copy] %s to out_buffer\n", current_buffer->name);
401 ret = ff_audio_data_copy(avr->out_buffer, current_buffer,
402 &avr->ch_map_info);
405 current_buffer = avr->out_buffer;
406 } else if (avr->in_copy_needed || avr->in_convert_needed) {
409 if (avr->in_convert_needed) {
410 ret = ff_audio_data_realloc(avr->in_buffer,
414 av_dlog(avr, "[convert] %s to in_buffer\n", current_buffer->name);
415 ret = ff_audio_convert(avr->ac_in, avr->in_buffer,
420 av_dlog(avr, "[copy] %s to in_buffer\n", current_buffer->name);
421 ret = ff_audio_data_copy(avr->in_buffer, current_buffer,
422 avr->remap_point == REMAP_IN_COPY ?
423 &avr->ch_map_info : NULL);
427 ff_audio_data_set_channels(avr->in_buffer, avr->in_channels);
428 if (avr->downmix_needed) {
429 av_dlog(avr, "[downmix] in_buffer\n");
430 ret = ff_audio_mix(avr->am, avr->in_buffer);
434 current_buffer = avr->in_buffer;
438 if (!avr->resample_needed)
439 return handle_buffered_output(avr, output ? &output_buffer : NULL,
444 if (avr->resample_needed) {
447 if (!avr->out_convert_needed && direct_output && out_samples > 0)
450 resample_out = avr->resample_out_buffer;
451 av_dlog(avr, "[resample] %s to %s\n",
454 ret = ff_audio_resample(avr->resample, resample_out,
461 av_dlog(avr, "[end conversion]\n");
468 if (avr->upmix_needed) {
469 av_dlog(avr, "[upmix] %s\n", current_buffer->name);
470 ret = ff_audio_mix(avr->am, current_buffer);
477 av_dlog(avr, "[end conversion]\n");
481 if (avr->out_convert_needed) {
484 av_dlog(avr, "[convert] %s to output\n", current_buffer->name);
485 ret = ff_audio_convert(avr->ac_out, &output_buffer, current_buffer);
489 av_dlog(avr, "[end conversion]\n");
492 ret = ff_audio_data_realloc(avr->out_buffer,
496 av_dlog(avr, "[convert] %s to out_buffer\n", current_buffer->name);
497 ret = ff_audio_convert(avr->ac_out, avr->out_buffer,
501 current_buffer = avr->out_buffer;
505 return handle_buffered_output(avr, output ? &output_buffer : NULL,
509 int avresample_get_matrix(AVAudioResampleContext *avr, double *matrix,
514 if (avr->am)
515 return ff_audio_mix_get_matrix(avr->am, matrix, stride);
517 in_channels = av_get_channel_layout_nb_channels(avr->in_channel_layout);
518 out_channels = av_get_channel_layout_nb_channels(avr->out_channel_layout);
522 av_log(avr, AV_LOG_ERROR, "Invalid channel layouts\n");
526 if (!avr->mix_matrix) {
527 av_log(avr, AV_LOG_ERROR, "matrix is not set\n");
533 matrix[o * stride + i] = avr->mix_matrix[o * in_channels + i];
538 int avresample_set_matrix(AVAudioResampleContext *avr, const double *matrix,
543 if (avr->am)
544 return ff_audio_mix_set_matrix(avr->am, matrix, stride);
546 in_channels = av_get_channel_layout_nb_channels(avr->in_channel_layout);
547 out_channels = av_get_channel_layout_nb_channels(avr->out_channel_layout);
551 av_log(avr, AV_LOG_ERROR, "Invalid channel layouts\n");
555 if (avr->mix_matrix)
556 av_freep(&avr->mix_matrix);
557 avr->mix_matrix = av_malloc(in_channels * out_channels *
558 sizeof(*avr->mix_matrix));
559 if (!avr->mix_matrix)
564 avr->mix_matrix[o * in_channels + i] = matrix[o * stride + i];
569 int avresample_set_channel_mapping(AVAudioResampleContext *avr,
572 ChannelMapInfo *info = &avr->ch_map_info;
575 in_channels = av_get_channel_layout_nb_channels(avr->in_channel_layout);
577 av_log(avr, AV_LOG_ERROR, "Invalid input channel layout\n");
586 av_log(avr, AV_LOG_ERROR, "Invalid channel map\n");
616 avr->use_channel_map = 1;
620 int avresample_available(AVAudioResampleContext *avr)
622 return av_audio_fifo_size(avr->out_fifo);
625 int avresample_get_out_samples(AVAudioResampleContext *avr, int in_nb_samples)
627 int64_t samples = avresample_get_delay(avr) + (int64_t)in_nb_samples;
629 if (avr->resample_needed) {
631 avr->out_sample_rate,
632 avr->in_sample_rate,
636 samples += avresample_available(avr);
644 int avresample_read(AVAudioResampleContext *avr, uint8_t **output, int nb_samples)
647 return av_audio_fifo_drain(avr->out_fifo, nb_samples);
648 return av_audio_fifo_read(avr->out_fifo, (void**)output, nb_samples);