Ticket #1217: 1217-v1.patch
File 1217-v1.patch, 9.1 KB (added by , 20 years ago) |
---|
-
libs/libmyth/audiooutputbase.h
52 52 // Send output events showing current progress 53 53 virtual void Status(void); 54 54 55 QString GetError() { return lastError; };56 57 55 virtual void SetSourceBitrate(int rate); 58 56 59 57 // Only really used by the AudioOutputNULL object … … 116 114 bool buffer_output_data_for_use; // used by AudioOutputNULL 117 115 118 116 private: 119 QString lastError;120 121 117 // resampler 122 118 bool need_resampler; 123 119 SRC_STATE *src_ctx; -
libs/libmyth/audiooutputalsa.cpp
455 455 if (mixer_handle == NULL) 456 456 return 100; 457 457 458 snd_mixer_selem_id_t *sid; 458 459 snd_mixer_selem_id_alloca(&sid); 459 460 snd_mixer_selem_id_set_index(sid, 0); 460 461 snd_mixer_selem_id_set_name(sid, mixer_control.ascii()); 461 462 462 if ((elem = snd_mixer_find_selem(mixer_handle, sid)) == NULL) 463 snd_mixer_elem_t *elem = snd_mixer_find_selem(mixer_handle, sid); 464 if (!elem) 463 465 { 464 Error(QString("mixer unable to find control %1").arg(mixer_control));465 CloseMixer();466 return 0;466 VERBOSE(VB_IMPORTANT, QString("Mixer unable to find control %1") 467 .arg(mixer_control)); 468 return 100; 467 469 } 468 470 469 GetVolumeRange(); 471 snd_mixer_selem_channel_id_t chan = (snd_mixer_selem_channel_id_t) channel; 472 if (!snd_mixer_selem_has_playback_channel(elem, chan)) 473 { 474 snd_mixer_selem_id_set_index(sid, channel); 475 if ((elem = snd_mixer_find_selem(mixer_handle, sid)) == NULL) 476 { 477 VERBOSE(VB_IMPORTANT, QString("Mixer unable to find control %1 %2") 478 .arg(mixer_control).arg(channel)); 479 return 100; 480 } 481 } 470 482 483 GetVolumeRange(elem); 484 471 485 snd_mixer_selem_get_playback_volume(elem, (snd_mixer_selem_channel_id_t)channel, 472 486 &actual_volume); 473 487 volume = (int)((actual_volume - playback_vol_min) * … … 482 496 483 497 void AudioOutputALSA::SetCurrentVolume(QString control, int channel, int volume) 484 498 { 485 int err, set_vol;486 487 499 VERBOSE(VB_AUDIO, QString("Setting %1 volume to %2") 488 500 .arg(control).arg(volume)); 489 501 490 if (mixer_handle != NULL) 502 if (!mixer_handle) 503 return; // no mixer, nothing to do 504 505 snd_mixer_selem_id_t *sid; 506 snd_mixer_selem_id_alloca(&sid); 507 snd_mixer_selem_id_set_index(sid, 0); 508 snd_mixer_selem_id_set_name(sid, control.ascii()); 509 510 snd_mixer_elem_t *elem = snd_mixer_find_selem(mixer_handle, sid); 511 if (!elem) 491 512 { 492 snd_mixer_selem_id_alloca(&sid); 493 snd_mixer_selem_id_set_index(sid, 0); 494 snd_mixer_selem_id_set_name(sid, control.ascii()); 513 VERBOSE(VB_IMPORTANT, QString("Mixer unable to find control %1") 514 .arg(control)); 515 return; 516 } 495 517 518 snd_mixer_selem_channel_id_t chan = (snd_mixer_selem_channel_id_t) channel; 519 if (!snd_mixer_selem_has_playback_channel(elem, chan)) 520 { 521 snd_mixer_selem_id_set_index(sid, channel); 496 522 if ((elem = snd_mixer_find_selem(mixer_handle, sid)) == NULL) 497 523 { 498 Error(QString("mixer unable to find control %1").arg(control)); 524 VERBOSE(VB_IMPORTANT, 525 QString("mixer unable to find control %1 %2") 526 .arg(control).arg(channel)); 499 527 return; 500 528 } 529 } 501 530 502 GetVolumeRange();531 GetVolumeRange(elem); 503 532 504 533 int set_vol = (int)(volume / volume_range_multiplier + 505 534 playback_vol_min + 0.5); 506 535 507 if ((err = snd_mixer_selem_set_playback_volume(elem, 508 (snd_mixer_selem_channel_id_t)channel, set_vol)) < 0) 509 { 510 Error(QString("mixer set channel %1 err %2: %3") 511 .arg(channel).arg(err).arg(snd_strerror(err))); 512 return; 513 } 514 else 515 { 516 VERBOSE(VB_AUDIO, QString("channel %1 vol set to %2") 517 .arg(channel).arg(set_vol)); 518 } 536 int err = snd_mixer_selem_set_playback_volume(elem, chan, set_vol); 537 if (err < 0) 538 { 539 VERBOSE(VB_IMPORTANT, QString("mixer set channel %1 err %2: %3") 540 .arg(channel).arg(err).arg(snd_strerror(err))); 519 541 } 542 else 543 { 544 VERBOSE(VB_AUDIO, QString("channel %1 vol set to %2") 545 .arg(channel).arg(set_vol)); 546 } 520 547 } 521 548 522 549 void AudioOutputALSA::OpenMixer(bool setstartingvolume) … … 561 588 // TODO: This is opening card 0. Fix for case of multiple soundcards 562 589 if ((err = snd_mixer_open(&mixer_handle, 0)) < 0) 563 590 { 564 Error(QString("Mixer device open error %1: %2")565 591 Warn(QString("Mixer device open error %1: %2") 592 .arg(err).arg(snd_strerror(err))); 566 593 mixer_handle = NULL; 567 594 return; 568 595 } 569 596 570 597 if ((err = snd_mixer_attach(mixer_handle, device.ascii())) < 0) 571 598 { 572 Error(QString("Mixer attach error %1: %2\nCheck Mixer Name in Setup: %3") 573 .arg(err).arg(snd_strerror(err)).arg(device.ascii())); 599 Warn(QString("Mixer attach error %1: %2" 600 "\n\t\t\tCheck Mixer Name in Setup: '%3'") 601 .arg(err).arg(snd_strerror(err)).arg(device)); 574 602 CloseMixer(); 575 603 return; 576 604 } 577 605 578 606 if ((err = snd_mixer_selem_register(mixer_handle, NULL, NULL)) < 0) 579 607 { 580 Error(QString("Mixer register error %1: %2")581 608 Warn(QString("Mixer register error %1: %2") 609 .arg(err).arg(snd_strerror(err))); 582 610 CloseMixer(); 583 611 return; 584 612 } 585 613 586 614 if ((err = snd_mixer_load(mixer_handle)) < 0) 587 615 { 588 Error(QString("Mixer load error %1: %2")589 616 Warn(QString("Mixer load error %1: %2") 617 .arg(err).arg(snd_strerror(err))); 590 618 CloseMixer(); 591 619 return; 592 620 } 593 621 } 594 622 595 inline void AudioOutputALSA::GetVolumeRange(void)623 void AudioOutputALSA::GetVolumeRange(snd_mixer_elem_t *elem) 596 624 { 597 625 snd_mixer_selem_get_playback_volume_range(elem, &playback_vol_min, 598 626 &playback_vol_max); -
libs/libmyth/audiooutputbase.cpp
15 15 16 16 AudioOutputBase::AudioOutputBase(QString audiodevice, int, 17 17 int, int, 18 AudioOutputSource source, bool set_initial_vol) 18 AudioOutputSource source, 19 bool set_initial_vol) 19 20 { 20 21 pthread_mutex_init(&audio_buflock, NULL); 21 22 pthread_mutex_init(&avsync_lock, NULL); -
libs/libmyth/audiooutput.h
22 22 int audio_channels, int audio_samplerate, 23 23 AudioOutputSource source, bool set_initial_vol); 24 24 25 AudioOutput() : VolumeBase(), OutputListeners() { lastError = QString::null; }; 25 AudioOutput() : 26 VolumeBase(), OutputListeners(), 27 lastError(QString::null), lastWarn(QString::null) {} 28 26 29 virtual ~AudioOutput() { }; 27 30 28 31 // reconfigure sound out for new params … … 55 58 56 59 virtual void SetSourceBitrate(int ) { } 57 60 58 QString GetError() { return lastError; }; 61 QString GetError(void) const { return lastError; } 62 QString GetWarning(void) const { return lastWarn; } 59 63 60 64 // Only really used by the AudioOutputNULL object 61 65 62 66 virtual void bufferOutputData(bool y) = 0; 63 67 virtual int readOutputData(unsigned char *read_buffer, int max_length) = 0; 64 68 65 protected:69 protected: 66 70 void Error(QString msg) 67 { lastError = msg; VERBOSE(VB_IMPORTANT, lastError); }; 71 { lastError = msg; VERBOSE(VB_IMPORTANT, "Error: " + lastError); } 72 void Warn(QString msg) 73 { lastWarn = msg; VERBOSE(VB_IMPORTANT, "Warning: " + lastWarn); } 68 74 69 private:75 protected: 70 76 QString lastError; 77 QString lastWarn; 71 78 }; 72 79 73 80 #endif -
libs/libmyth/audiooutputalsa.h
53 53 void OpenMixer(bool setstartingvolume); 54 54 void CloseMixer(void); 55 55 void SetupMixer(void); 56 inline void GetVolumeRange(void);56 void GetVolumeRange(snd_mixer_elem_t *elem); 57 57 58 58 snd_mixer_t *mixer_handle; 59 snd_mixer_elem_t *elem;60 snd_mixer_selem_id_t *sid;61 59 62 60 QString mixer_control; // e.g. "PCM" 63 61