| | 219 | |
|---|
| | 220 | /***************************************************************************** |
|---|
| | 221 | * OpenFilter: |
|---|
| | 222 | *****************************************************************************/ |
|---|
| | 223 | static int OpenFilter( vlc_object_t *p_this ) |
|---|
| | 224 | { |
|---|
| | 225 | filter_t *p_filter = (filter_t *)p_this; |
|---|
| | 226 | |
|---|
| | 227 | if ( (p_filter->fmt_in.audio.i_physical_channels |
|---|
| | 228 | == p_filter->fmt_out.audio.i_physical_channels |
|---|
| | 229 | && p_filter->fmt_in.audio.i_original_channels |
|---|
| | 230 | == p_filter->fmt_out.audio.i_original_channels) |
|---|
| | 231 | || p_filter->fmt_in.i_codec != p_filter->fmt_out.i_codec |
|---|
| | 232 | || p_filter->fmt_in.audio.i_rate != p_filter->fmt_out.audio.i_rate |
|---|
| | 233 | || p_filter->fmt_in.i_codec != VLC_FOURCC('f','l','3','2') ) |
|---|
| | 234 | { |
|---|
| | 235 | return -1; |
|---|
| | 236 | } |
|---|
| | 237 | |
|---|
| | 238 | /* Only conversion to Mono, Stereo and 4.0 right now */ |
|---|
| | 239 | if( p_filter->fmt_out.audio.i_physical_channels != |
|---|
| | 240 | (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT) |
|---|
| | 241 | && p_filter->fmt_out.audio.i_physical_channels != |
|---|
| | 242 | ( AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | |
|---|
| | 243 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT) |
|---|
| | 244 | && p_filter->fmt_out.audio.i_physical_channels != AOUT_CHAN_CENTER ) |
|---|
| | 245 | { |
|---|
| | 246 | return -1; |
|---|
| | 247 | } |
|---|
| | 248 | |
|---|
| | 249 | /* Only from 7/7.1/5/5.1/2.0 */ |
|---|
| | 250 | if( (p_filter->fmt_in.audio.i_physical_channels & ~AOUT_CHAN_LFE) != |
|---|
| | 251 | (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER | |
|---|
| | 252 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT) && |
|---|
| | 253 | (p_filter->fmt_in.audio.i_physical_channels & ~AOUT_CHAN_LFE) != |
|---|
| | 254 | (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT | AOUT_CHAN_CENTER | |
|---|
| | 255 | AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT | |
|---|
| | 256 | AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT) && |
|---|
| | 257 | p_filter->fmt_in.audio.i_physical_channels != |
|---|
| | 258 | (AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT) ) |
|---|
| | 259 | { |
|---|
| | 260 | return -1; |
|---|
| | 261 | } |
|---|
| | 262 | |
|---|
| | 263 | p_filter->pf_audio_filter = Filter; |
|---|
| | 264 | |
|---|
| | 265 | return 0; |
|---|
| | 266 | } |
|---|
| | 267 | |
|---|
| | 268 | /***************************************************************************** |
|---|
| | 269 | * Filter: |
|---|
| | 270 | *****************************************************************************/ |
|---|
| | 271 | static block_t *Filter( filter_t *p_filter, block_t *p_block ) |
|---|
| | 272 | { |
|---|
| | 273 | aout_filter_t aout_filter; |
|---|
| | 274 | aout_buffer_t in_buf, out_buf; |
|---|
| | 275 | block_t *p_out; |
|---|
| | 276 | int i_out_size; |
|---|
| | 277 | |
|---|
| | 278 | if( !p_block || !p_block->i_samples ) |
|---|
| | 279 | { |
|---|
| | 280 | if( p_block ) p_block->pf_release( p_block ); |
|---|
| | 281 | return NULL; |
|---|
| | 282 | } |
|---|
| | 283 | |
|---|
| | 284 | i_out_size = p_block->i_samples * |
|---|
| | 285 | p_filter->fmt_out.audio.i_bitspersample * |
|---|
| | 286 | p_filter->fmt_out.audio.i_channels / 8; |
|---|
| | 287 | |
|---|
| | 288 | p_out = p_filter->pf_audio_buffer_new( p_filter, i_out_size ); |
|---|
| | 289 | if( !p_out ) |
|---|
| | 290 | { |
|---|
| | 291 | msg_Warn( p_filter, "can't get output buffer" ); |
|---|
| | 292 | p_block->pf_release( p_block ); |
|---|
| | 293 | return NULL; |
|---|
| | 294 | } |
|---|
| | 295 | |
|---|
| | 296 | p_out->i_samples = p_block->i_samples; |
|---|
| | 297 | p_out->i_dts = p_block->i_dts; |
|---|
| | 298 | p_out->i_pts = p_block->i_pts; |
|---|
| | 299 | p_out->i_length = p_block->i_length; |
|---|
| | 300 | |
|---|
| | 301 | aout_filter.p_sys = (struct aout_filter_sys_t *)p_filter->p_sys; |
|---|
| | 302 | aout_filter.input = p_filter->fmt_in.audio; |
|---|
| | 303 | aout_filter.input.i_format = p_filter->fmt_in.i_codec; |
|---|
| | 304 | aout_filter.output = p_filter->fmt_out.audio; |
|---|
| | 305 | aout_filter.output.i_format = p_filter->fmt_out.i_codec; |
|---|
| | 306 | |
|---|
| | 307 | in_buf.p_buffer = p_block->p_buffer; |
|---|
| | 308 | in_buf.i_nb_bytes = p_block->i_buffer; |
|---|
| | 309 | in_buf.i_nb_samples = p_block->i_samples; |
|---|
| | 310 | out_buf.p_buffer = p_out->p_buffer; |
|---|
| | 311 | out_buf.i_nb_bytes = p_out->i_buffer; |
|---|
| | 312 | out_buf.i_nb_samples = p_out->i_samples; |
|---|
| | 313 | |
|---|
| | 314 | DoWork( (aout_instance_t *)p_filter, &aout_filter, &in_buf, &out_buf ); |
|---|
| | 315 | |
|---|
| | 316 | p_block->pf_release( p_block ); |
|---|
| | 317 | |
|---|
| | 318 | p_out->i_buffer = out_buf.i_nb_bytes; |
|---|
| | 319 | p_out->i_samples = out_buf.i_nb_samples; |
|---|
| | 320 | |
|---|
| | 321 | return p_out; |
|---|
| | 322 | } |
|---|
| | 323 | |
|---|