KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache/2.2.17 (Unix) mod_ssl/2.2.17 OpenSSL/0.9.8e-fips-rhel5 DAV/2 PHP/5.2.17
System : Linux localhost 2.6.18-419.el5 #1 SMP Fri Feb 24 22:47:42 UTC 2017 x86_64
User : nobody ( 99)
PHP Version : 5.2.17
Disable Function : NONE
Directory :  /proc/21572/root/usr/share/system-config-soundcard/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //proc/21572/root/usr/share/system-config-soundcard/soundcardBackendSoundCard.py
## soundcardBackendSoundCard.py
## Copyright (C) 2002, 2003 Red Hat, Inc.
## Copyright (C) 2002, 2003 Brent Fox <bfox@redhat.com>
## Copyright (C) 2004, 2005 Bastien Nocera <hadess@hadess.net>

## 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 2 of the License, or
## (at your option) 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, write to the Free Software
## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

import string
import os
import sys

##
## Sort for cards devices
##
def soundCardDevice_sort(device1, device2):
    return cmp(device1[0], device2[0])

##
## cards devices class
##
class soundCardDevice:
    def __init__(self):
        self.description = ""
        self.device_index = 0


# Sound card description & configuration structure
#
# Card description
#   .driver         - driver used by this card
#   .maker          - vendor
#   .model          - card type
#
# Card configuration
#   .inxed          - ALSA index of card
#   .volume         - volume of card
#   .default_device - selected PCM device
#   .devices        - list of PCM devices

class soundCard:
    def __init__(self, index):
        # Card description
        self.driver = ""
        self.maker = None
        self.type = None
        self.bus = None
        self.model = ""
        
        # Card configuration
        self.active = 0
        self.index = index
        self.volume = 75
        self.device_list = []
        self.default_device = 0

        # Test sound
        self.test_sound_device = 0
        self.test_sound_play_end = 0
        self.test_sound_aplay_pid = 0

    def dump(self):
        print "------- Card dump ---------"
        print "Index: ",self.index
        print "Vendor: ",self.maker
        print "Model: ",self.model
        print "Type: ",self.type
        print "Driver: ",self.driver
        print "Bus: ",self.bus

    def clear(self):
        self.active = 0

    def getName(self):
        if self.maker != None:
            return self.maker+" "+self.model
        else:
            return self.model
            
    def getDescription(self):        
        return self.type

    def setVolume(self, volume):

        #alsa drivers load muted. we need to set the volume for them.
        self.volume = volume
        
        amixer_path = "/bin/alsaunmute"
        amixer_args = [amixer_path, `self.index`, "-s", `self.volume`]
        amixer_pid = os.fork()
        
        if (not amixer_pid):
            try:
                os.execv(amixer_path, amixer_args)
            except:
                sys.exit(0)
        else:
            os.waitpid(amixer_pid,0)
           
    def getVolume(self):
        return self.volume

    def playTestSound(self):
        if self.test_sound_aplay_pid != 0:
           return

        # set volume before playing test sound
        self.setVolume(self.volume)

        device = "plughw:%d,%d" % (self.index, self.test_sound_device)
        path = "/usr/share/system-config-soundcard/system-config-soundcard.play"

        self.test_sound_aplay_pid = os.fork()
        if (not self.test_sound_aplay_pid):
           try:
             os.execv(path, [path, device])
           except:
             sys.exit(0)

    def stopTestSound(self):
        # Kill the child process
        if self.test_sound_aplay_pid != 0:
           os.kill(self.test_sound_aplay_pid,15)

    def checkTestSound(self):
        # Check if test sound is being played
        finished = False
                
        if (self.test_sound_aplay_pid != 0):
           status = os.waitpid(self.test_sound_aplay_pid, os.WNOHANG)
           if (status[0] != 0):
              self.test_sound_aplay_pid = 0
              finished = True
        
        return (self.test_sound_aplay_pid, finished)

    def loadCardDevices(self):
        # Get line from /etc/asound/pcm
        # Example
        # 00-00: emu10k1 : ADC Capture/Standard PCM Playback : playback 32 : capture 1

        try:
            fd = open('/proc/asound/pcm', 'r')
            devices = fd.readlines()
            fd.close()
        except:
            return []
        
        card_devices = []
        for device in devices:
            # the first two letters are card number
            if(string.atoi(device[:2]) == self.index):
                card_devices.append(device[3:])

        #Process line with device number
        #00: emu10k1 : ADC Capture/Standard PCM Playback : playback 32 : capture 1
        device_list = []
        for device in card_devices:
            tmp = string.split(device,':',4)
            device_list.append([int(tmp[0],10),tmp[2]])
    
        device_list.sort(soundCardDevice_sort)
        return device_list

Anon7 - 2021