Пример #1
0
    def errbackResult(failure):
        log.debug('check', 'returning failed Result, %r' % failure)
        m = None
        if failure.check(errors.GStreamerGstError):
            source, gerror, debug = failure.value.args
            log.debug('check', 'GStreamer GError: %s (debug: %s)' % (
                gerror.message, debug))
            if gerror.domain == "gst-resource-error-quark":
                if gerror.code == int(gst.RESOURCE_ERROR_NOT_FOUND):
                    # dv1394src was fixed after gst-plugins-good 0.10.2
                    # to distinguish NOT_FOUND and OPEN_READ
                    version = gstreamer.get_plugin_version('1394')
                    if version >= (0, 10, 0, 0) and version <= (0, 10, 2, 0):
                        m = messages.Error(T_(
                            N_("Could not find or open the Firewire device. "
                               "Check the device node and its permissions.")))
                    else:
                        m = messages.Error(T_(
                            N_("No Firewire device found.")))
                elif gerror.code == int(gst.RESOURCE_ERROR_OPEN_READ):
                    m = messages.Error(T_(
                        N_("Could not open Firewire device for reading. "
                           "Check permissions on the device.")))

            if not m:
                m = check.handleGStreamerDeviceError(failure, 'Firewire',
                    mid=mid)

        if not m:
            m = messages.Error(T_(N_("Could not probe Firewire device.")),
                debug=check.debugFailure(failure))

        m.id = mid
        result.add(m)
        return result
Пример #2
0
    def errbackResult(failure):
        log.debug('check', 'returning failed Result, %r' % failure)
        m = None
        if failure.check(errors.GStreamerGstError):
            source, gerror, debug = failure.value.args
            log.debug('check', 'GStreamer GError: %s (debug: %s)' % (
                gerror.message, debug))
            if gerror.domain == "gst-resource-error-quark":
                if gerror.code == int(gst.RESOURCE_ERROR_NOT_FOUND):
                    # dv1394src was fixed after gst-plugins-good 0.10.2
                    # to distinguish NOT_FOUND and OPEN_READ
                    version = gstreamer.get_plugin_version('1394')
                    if version >= (0, 10, 0, 0) and version <= (0, 10, 2, 0):
                        m = messages.Error(T_(
                            N_("Could not find or open the Firewire device. "
                               "Check the device node and its permissions.")))
                    else:
                        m = messages.Error(T_(
                            N_("No Firewire device found.")))
                elif gerror.code == int(gst.RESOURCE_ERROR_OPEN_READ):
                    m = messages.Error(T_(
                        N_("Could not open Firewire device for reading. "
                           "Check permissions on the device.")))

            if not m:
                m = check.handleGStreamerDeviceError(failure, 'Firewire',
                    mid=mid)

        if not m:
            m = messages.Error(T_(N_("Could not probe Firewire device.")),
                debug=check.debugFailure(failure))

        m.id = mid
        result.add(m)
        return result
Пример #3
0
def getAudioDevices(source_factory, mid=None):
    """
    Search the available devices in worker for the specified factory.
    Return a deferred firing a result.

    The result is either:
     - succesful, with an empty list: no device found
     - succesful, with the list of found devices
     - failed

    @rtype: L{twisted.internet.defer.Deferred}
    """
    result = messages.Result()
    devices = []

    def getOssDevices():
        bus = dbus.SystemBus()
        hal = dbus.Interface(
            bus.get_object('org.freedesktop.Hal',
                           '/org/freedesktop/Hal/Manager'),
            'org.freedesktop.Hal.Manager')
        udis = hal.FindDeviceStringMatch('oss.type', 'pcm')

        for udi in udis:
            dev = dbus.Interface(bus.get_object('org.freedesktop.Hal', udi),
                                 'org.freedesktop.Hal.Device')
            if not dev.PropertyExists('oss.device'):
                continue
            if dev.GetProperty('oss.device') != 0:
                continue

            devices.append((str(dev.GetProperty('info.product')),
                            str(dev.GetProperty('oss.device_file'))))

    def getAlsaDevices():
        source = gst.element_factory_make('alsasrc')
        pipeline = 'alsasrc name=source device=%s ! fakesink'

        for device in source.probe_get_values_name('device'):
            p = gst.parse_launch(pipeline % device)
            p.set_state(gst.STATE_READY)
            s = p.get_by_name('source')
            devices.append(
                (s.get_property('device-name'), device.split(',')[0]))
            p.set_state(gst.STATE_NULL)

    try:
        {'alsasrc': getAlsaDevices, 'osssrc': getOssDevices}[source_factory]()

    except dbus.DBusException:
        devices = [("/dev/dsp", "/dev/dsp"), ("/dev/dsp1", "/dev/dsp1"),
                   ("/dev/dsp2", "/dev/dsp2")]

        result.succeed(devices)

        failure = defer.failure.Failure()
        m = messages.Warning(T_(
            N_("There has been an error while fetching the OSS audio devices "
               "through Hal.\nThe listed devices have been guessed and may "
               "not work properly.")),
                             debug=check.debugFailure(failure))
        m.id = mid
        result.add(m)
        return defer.succeed(result)
    except:
        failure = defer.failure.Failure()
        log.debug(
            'check', 'unhandled failure: %r (%s)\nTraceback:\n%s' %
            (failure, failure.getErrorMessage(), failure.getTraceback()))
        m = messages.Error(T_(N_("Could not probe devices.")),
                           debug=check.debugFailure(failure))

        m.id = mid
        result.add(m)
        return defer.fail(result)
    else:
        result.succeed(devices)
        if not devices:
            m = messages.Error(
                T_(
                    N_("Could not find any device in the system.\n"
                       "Please check whether the device is correctly plugged "
                       "in and whether the modules are correctly loaded.")))

            m.id = mid
            result.add(m)

        return defer.succeed(result)
Пример #4
0
def getAudioDevices(source_factory, mid=None):
    """
    Search the available devices in worker for the specified factory.
    Return a deferred firing a result.

    The result is either:
     - succesful, with an empty list: no device found
     - succesful, with the list of found devices
     - failed

    @rtype: L{twisted.internet.defer.Deferred}
    """
    result = messages.Result()
    devices = []

    def getOssDevices():
        bus = dbus.SystemBus()
        hal = dbus.Interface(bus.get_object('org.freedesktop.Hal',
                                            '/org/freedesktop/Hal/Manager'),
                             'org.freedesktop.Hal.Manager')
        udis = hal.FindDeviceStringMatch('oss.type', 'pcm')

        for udi in udis:
            dev = dbus.Interface(bus.get_object('org.freedesktop.Hal', udi),
                                 'org.freedesktop.Hal.Device')
            if not dev.PropertyExists('oss.device'):
                continue
            if dev.GetProperty('oss.device') != 0:
                continue

            devices.append((str(dev.GetProperty('info.product')),
                            str(dev.GetProperty('oss.device_file'))))

    def getAlsaDevices():
        source = gst.element_factory_make('alsasrc')
        pipeline = 'alsasrc name=source device=%s ! fakesink'

        for device in source.probe_get_values_name('device'):
            p = gst.parse_launch(pipeline % device)
            p.set_state(gst.STATE_READY)
            s = p.get_by_name('source')
            devices.append((s.get_property('device-name'),
                            device.split(',')[0]))
            p.set_state(gst.STATE_NULL)

    try:
        {'alsasrc': getAlsaDevices,
         'osssrc': getOssDevices}[source_factory]()

    except dbus.DBusException, e:
        devices = [("/dev/dsp", "/dev/dsp"),
                   ("/dev/dsp1", "/dev/dsp1"),
                   ("/dev/dsp2", "/dev/dsp2")]

        result.succeed(devices)

        failure = defer.failure.Failure()
        m = messages.Warning(T_(
             N_("There has been an error while fetching the OSS audio devices "
                "through Hal.\nThe listed devices have been guessed and may "
                "not work properly.")), debug=check.debugFailure(failure))
        m.id = mid
        result.add(m)
        return defer.succeed(result)
Пример #5
0
        result.succeed(devices)

        failure = defer.failure.Failure()
        m = messages.Warning(T_(
             N_("There has been an error while fetching the OSS audio devices "
                "through Hal.\nThe listed devices have been guessed and may "
                "not work properly.")), debug=check.debugFailure(failure))
        m.id = mid
        result.add(m)
        return defer.succeed(result)
    except:
        failure = defer.failure.Failure()
        log.debug('check', 'unhandled failure: %r (%s)\nTraceback:\n%s' % (
                  failure, failure.getErrorMessage(), failure.getTraceback()))
        m = messages.Error(T_(N_("Could not probe devices.")),
                           debug=check.debugFailure(failure))

        m.id = mid
        result.add(m)
        return defer.fail(result)
    else:
        result.succeed(devices)
        if not devices:
            m = messages.Error(T_(
                    N_("Could not find any device in the system.\n"
                       "Please check whether the device is correctly plugged "
                       "in and whether the modules are correctly loaded.")))

            m.id = mid
            result.add(m)