| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 |
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
|
|---|
| 26 |
|
|---|
| 27 |
#ifdef HAVE_CONFIG_H |
|---|
| 28 |
# include "config.h" |
|---|
| 29 |
#endif |
|---|
| 30 |
|
|---|
| 31 |
#include <vlc_common.h> |
|---|
| 32 |
#include <vlc_interface.h> |
|---|
| 33 |
|
|---|
| 34 |
#ifdef HAVE_ALLOCA_H |
|---|
| 35 |
# include <alloca.h> |
|---|
| 36 |
#endif |
|---|
| 37 |
|
|---|
| 38 |
#include <vlc_aout.h> |
|---|
| 39 |
#include "aout_internal.h" |
|---|
| 40 |
#include <libvlc.h> |
|---|
| 41 |
|
|---|
| 42 |
|
|---|
| 43 |
|
|---|
| 44 |
|
|---|
| 45 |
static aout_filter_t * FindFilter( aout_instance_t * p_aout, |
|---|
| 46 |
const audio_sample_format_t * p_input_format, |
|---|
| 47 |
const audio_sample_format_t * p_output_format ) |
|---|
| 48 |
{ |
|---|
| 49 |
static const char typename[] = "audio output"; |
|---|
| 50 |
aout_filter_t * p_filter; |
|---|
| 51 |
|
|---|
| 52 |
p_filter = vlc_custom_create( p_aout, sizeof(*p_filter), |
|---|
| 53 |
VLC_OBJECT_GENERIC, typename ); |
|---|
| 54 |
|
|---|
| 55 |
if ( p_filter == NULL ) return NULL; |
|---|
| 56 |
vlc_object_attach( p_filter, p_aout ); |
|---|
| 57 |
|
|---|
| 58 |
memcpy( &p_filter->input, p_input_format, sizeof(audio_sample_format_t) ); |
|---|
| 59 |
memcpy( &p_filter->output, p_output_format, |
|---|
| 60 |
sizeof(audio_sample_format_t) ); |
|---|
| 61 |
p_filter->p_module = module_Need( p_filter, "audio filter", NULL, 0 ); |
|---|
| 62 |
if ( p_filter->p_module == NULL ) |
|---|
| 63 |
{ |
|---|
| 64 |
vlc_object_detach( p_filter ); |
|---|
| 65 |
vlc_object_release( p_filter ); |
|---|
| 66 |
return NULL; |
|---|
| 67 |
} |
|---|
| 68 |
|
|---|
| 69 |
p_filter->b_continuity = false; |
|---|
| 70 |
|
|---|
| 71 |
return p_filter; |
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
|
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
static int SplitConversion( const audio_sample_format_t * p_input_format, |
|---|
| 84 |
const audio_sample_format_t * p_output_format, |
|---|
| 85 |
audio_sample_format_t * p_middle_format ) |
|---|
| 86 |
{ |
|---|
| 87 |
bool b_format = |
|---|
| 88 |
(p_input_format->i_format != p_output_format->i_format); |
|---|
| 89 |
bool b_rate = (p_input_format->i_rate != p_output_format->i_rate); |
|---|
| 90 |
bool b_channels = |
|---|
| 91 |
(p_input_format->i_physical_channels |
|---|
| 92 |
!= p_output_format->i_physical_channels) |
|---|
| 93 |
|| (p_input_format->i_original_channels |
|---|
| 94 |
!= p_output_format->i_original_channels); |
|---|
| 95 |
int i_nb_conversions = b_format + b_rate + b_channels; |
|---|
| 96 |
|
|---|
| 97 |
if ( i_nb_conversions <= 1 ) return 0; |
|---|
| 98 |
|
|---|
| 99 |
memcpy( p_middle_format, p_output_format, sizeof(audio_sample_format_t) ); |
|---|
| 100 |
|
|---|
| 101 |
if ( i_nb_conversions == 2 ) |
|---|
| 102 |
{ |
|---|
| 103 |
if ( !b_format || !b_channels ) |
|---|
| 104 |
{ |
|---|
| 105 |
p_middle_format->i_rate = p_input_format->i_rate; |
|---|
| 106 |
aout_FormatPrepare( p_middle_format ); |
|---|
| 107 |
return 1; |
|---|
| 108 |
} |
|---|
| 109 |
|
|---|
| 110 |
|
|---|
| 111 |
p_middle_format->i_physical_channels |
|---|
| 112 |
= p_input_format->i_physical_channels; |
|---|
| 113 |
p_middle_format->i_original_channels |
|---|
| 114 |
= p_input_format->i_original_channels; |
|---|
| 115 |
aout_FormatPrepare( p_middle_format ); |
|---|
| 116 |
return 1; |
|---|
| 117 |
} |
|---|
| 118 |
|
|---|
| 119 |
|
|---|
| 120 |
p_middle_format->i_rate = p_input_format->i_rate; |
|---|
| 121 |
aout_FormatPrepare( p_middle_format ); |
|---|
| 122 |
return 2; |
|---|
| 123 |
} |
|---|
| 124 |
|
|---|
| 125 |
static void ReleaseFilter( aout_filter_t * p_filter ) |
|---|
| 126 |
{ |
|---|
| 127 |
module_Unneed( p_filter, p_filter->p_module ); |
|---|
| 128 |
vlc_object_detach( p_filter ); |
|---|
| 129 |
vlc_object_release( p_filter ); |
|---|
| 130 |
} |
|---|
| 131 |
|
|---|
| 132 |
|
|---|
| 133 |
|
|---|
| 134 |
|
|---|
| 135 |
|
|---|
| 136 |
|
|---|
| 137 |
|
|---|
| 138 |
int aout_FiltersCreatePipeline( aout_instance_t * p_aout, |
|---|
| 139 |
aout_filter_t ** pp_filters_start, |
|---|
| 140 |
int * pi_nb_filters, |
|---|
| 141 |
const audio_sample_format_t * p_input_format, |
|---|
| 142 |
const audio_sample_format_t * p_output_format ) |
|---|
| 143 |
{ |
|---|
| 144 |
aout_filter_t** pp_filters = pp_filters_start + *pi_nb_filters; |
|---|
| 145 |
audio_sample_format_t temp_format; |
|---|
| 146 |
int i_nb_conversions; |
|---|
| 147 |
|
|---|
| 148 |
if ( AOUT_FMTS_IDENTICAL( p_input_format, p_output_format ) ) |
|---|
| 149 |
{ |
|---|
| 150 |
msg_Dbg( p_aout, "no need for any filter" ); |
|---|
| 151 |
return 0; |
|---|
| 152 |
} |
|---|
| 153 |
|
|---|
| 154 |
aout_FormatsPrint( p_aout, "filter(s)", p_input_format, p_output_format ); |
|---|
| 155 |
|
|---|
| 156 |
if( *pi_nb_filters + 1 > AOUT_MAX_FILTERS ) |
|---|
| 157 |
{ |
|---|
| 158 |
msg_Err( p_aout, "max filter reached (%d)", AOUT_MAX_FILTERS ); |
|---|
| 159 |
intf_UserFatal( p_aout, false, _("Audio filtering failed"), |
|---|
| 160 |
_("The maximum number of filters (%d) was reached."), |
|---|
| 161 |
AOUT_MAX_FILTERS ); |
|---|
| 162 |
return -1; |
|---|
| 163 |
} |
|---|
| 164 |
|
|---|
| 165 |
|
|---|
| 166 |
pp_filters[0] = FindFilter( p_aout, p_input_format, p_output_format ); |
|---|
| 167 |
if ( pp_filters[0] != NULL ) |
|---|
| 168 |
{ |
|---|
| 169 |
msg_Dbg( p_aout, "found a filter for the whole conversion" ); |
|---|
| 170 |
++*pi_nb_filters; |
|---|
| 171 |
return 0; |
|---|
| 172 |
} |
|---|
| 173 |
|
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 |
|
|---|
| 177 |
i_nb_conversions = SplitConversion( p_input_format, |
|---|
| 178 |
p_output_format, &temp_format ); |
|---|
| 179 |
if ( !i_nb_conversions ) |
|---|
| 180 |
{ |
|---|
| 181 |
|
|---|
| 182 |
msg_Err( p_aout, "couldn't find a filter for the conversion" ); |
|---|
| 183 |
return -1; |
|---|
| 184 |
} |
|---|
| 185 |
|
|---|
| 186 |
pp_filters[0] = FindFilter( p_aout, p_input_format, &temp_format ); |
|---|
| 187 |
if ( pp_filters[0] == NULL && i_nb_conversions == 2 ) |
|---|
| 188 |
{ |
|---|
| 189 |
|
|---|
| 190 |
SplitConversion( p_input_format, &temp_format, &temp_format ); |
|---|
| 191 |
pp_filters[0] = FindFilter( p_aout, p_input_format, &temp_format ); |
|---|
| 192 |
} |
|---|
| 193 |
if ( pp_filters[0] == NULL ) |
|---|
| 194 |
{ |
|---|
| 195 |
msg_Err( p_aout, |
|---|
| 196 |
"couldn't find a filter for the first part of the conversion" ); |
|---|
| 197 |
return -1; |
|---|
| 198 |
} |
|---|
| 199 |
|
|---|
| 200 |
|
|---|
| 201 |
|
|---|
| 202 |
if( *pi_nb_filters + 2 > AOUT_MAX_FILTERS ) |
|---|
| 203 |
{ |
|---|
| 204 |
ReleaseFilter( pp_filters[0] ); |
|---|
| 205 |
msg_Err( p_aout, "max filter reached (%d)", AOUT_MAX_FILTERS ); |
|---|
| 206 |
intf_UserFatal( p_aout, false, _("Audio filtering failed"), |
|---|
| 207 |
_("The maximum number of filters (%d) was reached."), |
|---|
| 208 |
AOUT_MAX_FILTERS ); |
|---|
| 209 |
return -1; |
|---|
| 210 |
} |
|---|
| 211 |
pp_filters[1] = FindFilter( p_aout, &pp_filters[0]->output, |
|---|
| 212 |
p_output_format ); |
|---|
| 213 |
if ( pp_filters[1] == NULL ) |
|---|
| 214 |
{ |
|---|
| 215 |
|
|---|
| 216 |
i_nb_conversions = SplitConversion( &pp_filters[0]->output, |
|---|
| 217 |
p_output_format, &temp_format ); |
|---|
| 218 |
if ( !i_nb_conversions ) |
|---|
| 219 |
{ |
|---|
| 220 |
ReleaseFilter( pp_filters[0] ); |
|---|
| 221 |
msg_Err( p_aout, |
|---|
| 222 |
"couldn't find a filter for the second part of the conversion" ); |
|---|
| 223 |
return -1; |
|---|
| 224 |
} |
|---|
| 225 |
if( *pi_nb_filters + 3 > AOUT_MAX_FILTERS ) |
|---|
| 226 |
{ |
|---|
| 227 |
ReleaseFilter( pp_filters[0] ); |
|---|
| 228 |
msg_Err( p_aout, "max filter reached (%d)", AOUT_MAX_FILTERS ); |
|---|
| 229 |
intf_UserFatal( p_aout, false, _("Audio filtering failed"), |
|---|
| 230 |
_("The maximum number of filters (%d) was reached."), |
|---|
| 231 |
AOUT_MAX_FILTERS ); |
|---|
| 232 |
return -1; |
|---|
| 233 |
} |
|---|
| 234 |
pp_filters[1] = FindFilter( p_aout, &pp_filters[0]->output, |
|---|
| 235 |
&temp_format ); |
|---|
| 236 |
pp_filters[2] = FindFilter( p_aout, &temp_format, |
|---|
| 237 |
p_output_format ); |
|---|
| 238 |
|
|---|
| 239 |
if ( pp_filters[1] == NULL || pp_filters[2] == NULL ) |
|---|
| 240 |
{ |
|---|
| 241 |
ReleaseFilter( pp_filters[0] ); |
|---|
| 242 |
if ( pp_filters[1] != NULL ) |
|---|
| 243 |
{ |
|---|
| 244 |
ReleaseFilter( pp_filters[1] ); |
|---|
| 245 |
} |
|---|
| 246 |
if ( pp_filters[2] != NULL ) |
|---|
| 247 |
{ |
|---|
| 248 |
ReleaseFilter( pp_filters[2] ); |
|---|
| 249 |
} |
|---|
| 250 |
msg_Err( p_aout, |
|---|
| 251 |
"couldn't find filters for the second part of the conversion" ); |
|---|
| 252 |
return -1; |
|---|
| 253 |
} |
|---|
| 254 |
*pi_nb_filters += 3; |
|---|
| 255 |
msg_Dbg( p_aout, "found 3 filters for the whole conversion" ); |
|---|
| 256 |
} |
|---|
| 257 |
else |
|---|
| 258 |
{ |
|---|
| 259 |
*pi_nb_filters += 2; |
|---|
| 260 |
msg_Dbg( p_aout, "found 2 filters for the whole conversion" ); |
|---|
| 261 |
} |
|---|
| 262 |
|
|---|
| 263 |
return 0; |
|---|
| 264 |
} |
|---|
| 265 |
|
|---|
| 266 |
|
|---|
| 267 |
|
|---|
| 268 |
|
|---|
| 269 |
void aout_FiltersDestroyPipeline( aout_instance_t * p_aout, |
|---|
| 270 |
aout_filter_t ** pp_filters, |
|---|
| 271 |
int i_nb_filters ) |
|---|
| 272 |
{ |
|---|
| 273 |
int i; |
|---|
| 274 |
(void)p_aout; |
|---|
| 275 |
|
|---|
| 276 |
for ( i = 0; i < i_nb_filters; i++ ) |
|---|
| 277 |
{ |
|---|
| 278 |
module_Unneed( pp_filters[i], pp_filters[i]->p_module ); |
|---|
| 279 |
vlc_object_detach( pp_filters[i] ); |
|---|
| 280 |
vlc_object_release( pp_filters[i] ); |
|---|
| 281 |
} |
|---|
| 282 |
} |
|---|
| 283 |
|
|---|
| 284 |
|
|---|
| 285 |
|
|---|
| 286 |
|
|---|
| 287 |
|
|---|
| 288 |
void aout_FiltersHintBuffers( aout_instance_t * p_aout, |
|---|
| 289 |
aout_filter_t ** pp_filters, |
|---|
| 290 |
int i_nb_filters, aout_alloc_t * p_first_alloc ) |
|---|
| 291 |
{ |
|---|
| 292 |
int i; |
|---|
| 293 |
|
|---|
| 294 |
(void)p_aout; |
|---|
| 295 |
|
|---|
| 296 |
for ( i = i_nb_filters - 1; i >= 0; i-- ) |
|---|
| 297 |
{ |
|---|
| 298 |
aout_filter_t * p_filter = pp_filters[i]; |
|---|
| 299 |
|
|---|
| 300 |
int i_output_size = p_filter->output.i_bytes_per_frame |
|---|
| 301 |
* p_filter->output.i_rate * AOUT_MAX_INPUT_RATE |
|---|
| 302 |
/ p_filter->output.i_frame_length; |
|---|
| 303 |
int i_input_size = p_filter->input.i_bytes_per_frame |
|---|
| 304 |
* p_filter->input.i_rate * AOUT_MAX_INPUT_RATE |
|---|
| 305 |
/ p_filter->input.i_frame_length; |
|---|
| 306 |
|
|---|
| 307 |
p_first_alloc->i_bytes_per_sec = __MAX( p_first_alloc->i_bytes_per_sec, |
|---|
| 308 |
i_output_size ); |
|---|
| 309 |
|
|---|
| 310 |
if ( p_filter->b_in_place ) |
|---|
| 311 |
{ |
|---|
| 312 |
p_first_alloc->i_bytes_per_sec = __MAX( |
|---|
| 313 |
p_first_alloc->i_bytes_per_sec, |
|---|
| 314 |
i_input_size ); |
|---|
| 315 |
p_filter->output_alloc.i_alloc_type = AOUT_ALLOC_NONE; |
|---|
| 316 |
} |
|---|
| 317 |
else |
|---|
| 318 |
{ |
|---|
| 319 |
|
|---|
| 320 |
memcpy( &p_filter->output_alloc, p_first_alloc, |
|---|
| 321 |
sizeof(aout_alloc_t) ); |
|---|
| 322 |
p_first_alloc->i_alloc_type = AOUT_ALLOC_STACK; |
|---|
| 323 |
p_first_alloc->i_bytes_per_sec = i_input_size; |
|---|
| 324 |
} |
|---|
| 325 |
} |
|---|
| 326 |
} |
|---|
| 327 |
|
|---|
| 328 |
|
|---|
| 329 |
|
|---|
| 330 |
|
|---|
| 331 |
void aout_FiltersPlay( aout_instance_t * p_aout, |
|---|
| 332 |
aout_filter_t ** pp_filters, |
|---|
| 333 |
int i_nb_filters, aout_buffer_t ** pp_input_buffer ) |
|---|
| 334 |
{ |
|---|
| 335 |
int i; |
|---|
| 336 |
|
|---|
| 337 |
for( i = 0; i < i_nb_filters; i++ ) |
|---|
| 338 |
{ |
|---|
| 339 |
aout_filter_t * p_filter = pp_filters[i]; |
|---|
| 340 |
aout_buffer_t * p_output_buffer; |
|---|
| 341 |
|
|---|
| 342 |
|
|---|
| 343 |
|
|---|
| 344 |
|
|---|
| 345 |
aout_BufferAlloc( &p_filter->output_alloc, |
|---|
| 346 |
((mtime_t)(*pp_input_buffer)->i_nb_samples + 2) |
|---|
| 347 |
* 1000000 / p_filter->input.i_rate, |
|---|
| 348 |
*pp_input_buffer, p_output_buffer ); |
|---|
| 349 |
if( p_output_buffer == NULL ) |
|---|
| 350 |
return; |
|---|
| 351 |
|
|---|
| 352 |
|
|---|
| 353 |
|
|---|
| 354 |
if( (*pp_input_buffer)->i_nb_samples > 0 ) |
|---|
| 355 |
{ |
|---|
| 356 |
p_filter->pf_do_work( p_aout, p_filter, *pp_input_buffer, |
|---|
| 357 |
p_output_buffer ); |
|---|
| 358 |
} |
|---|
| 359 |
else |
|---|
| 360 |
{ |
|---|
| 361 |
p_output_buffer->i_nb_bytes = 0; |
|---|
| 362 |
p_output_buffer->i_nb_samples = 0; |
|---|
| 363 |
} |
|---|
| 364 |
|
|---|
| 365 |
if( !p_filter->b_in_place ) |
|---|
| 366 |
{ |
|---|
| 367 |
aout_BufferFree( *pp_input_buffer ); |
|---|
| 368 |
*pp_input_buffer = p_output_buffer; |
|---|
| 369 |
} |
|---|
| 370 |
} |
|---|
| 371 |
|
|---|
| 372 |
assert( (*pp_input_buffer) == NULL || (*pp_input_buffer)->i_alloc_type != AOUT_ALLOC_STACK ); |
|---|
| 373 |
} |
|---|
| 374 |
|
|---|