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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
/*
* Copyright (C) 2014 ~ 2018 Deepin Technology Co., Ltd.
*
* Author: jouyouyun <jouyouwen717@gmail.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package pulse
/*
#include "dde-pulse.h"
*/
import "C"
import "fmt"
import "unsafe"
const (
DirectionSink int = iota + 1
DirectionSource
)
type CardPortInfo struct {
PortInfo
Direction int
Profiles ProfileInfos2
}
type CardPortInfos []CardPortInfo
//typedef struct pa_card_info {
// uint32_t index; /**< Index of this card */
// const char *name; /**< Name of this card */
// uint32_t owner_module; /**< Index of the owning module, or PA_INVALID_INDEX. */
// const char *driver; /**< Driver name */
// uint32_t n_profiles; /**< Number of entries in profile array */
// pa_card_profile_info* profiles; /**< \deprecated Superseded by profiles2 */
// pa_card_profile_info* active_profile; /**< \deprecated Superseded by active_profile2 */
// pa_proplist *proplist; /**< Property list */
// uint32_t n_ports; /**< Number of entries in port array */
// pa_card_port_info **ports; /**< Array of pointers to ports, or NULL. Array is terminated by an entry set to NULL. */
// pa_card_profile_info2** profiles2; /**< Array of pointers to available profiles, or NULL. Array is terminated by an entry set to NULL. \since 5.0 */
// pa_card_profile_info2* active_profile2; /**< Pointer to active profile in the array, or NULL. \since 5.0 */
//} pa_card_info;
type Card struct {
Index uint32
Name string
OwnerModule uint32
Driver string
PropList map[string]string
Profiles ProfileInfos2
ActiveProfile ProfileInfo2
Ports CardPortInfos
}
func toCardInfo(info *C.pa_card_info) (c *Card) {
c = &Card{}
c.Index = uint32(info.index)
c.Name = C.GoString(info.name)
c.OwnerModule = uint32(info.owner_module)
c.Driver = C.GoString(info.driver)
c.PropList = toProplist(info.proplist)
c.Profiles = toProfiles(uint32(info.n_profiles), info.profiles2)
c.ActiveProfile = toProfile(info.active_profile2)
c.Ports = toCardPorts(uint32(info.n_ports), info.ports)
return
}
func (card *Card) SetProfile(name string) {
c := GetContext()
c.safeDo(func() {
cname := C.CString(fmt.Sprint(card.Index))
pname := C.CString(name)
op := C.pa_context_set_card_profile_by_name(c.ctx, cname, pname, C.get_success_cb(), nil)
C.free(unsafe.Pointer(cname))
C.free(unsafe.Pointer(pname))
C.pa_operation_unref(op)
})
}
func (infos CardPortInfos) TrySelectProfile(portName string) (string, error) {
for _, info := range infos {
if info.Name != portName {
continue
}
return info.Profiles.SelectProfile(), nil
}
return "", fmt.Errorf("Invalid card port name: %s", portName)
}
func (infos CardPortInfos) Get(name string, direction int) (CardPortInfo, error) {
for _, info := range infos {
if info.Name == name && info.Direction == direction {
return info, nil
}
}
return CardPortInfo{}, fmt.Errorf("Invalid card port name: %s", name)
}
|