Ignore:
Timestamp:
Jan 24, 2017, 12:41:54 PM (8 years ago)
Author:
Silvan Scherrer
Message:

SMPlayer: update trunk to version 17.1.0

Location:
smplayer/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • smplayer/trunk

  • smplayer/trunk/src/deviceinfo.cpp

    r181 r188  
    11/*  smplayer, GUI front-end for mplayer.
    2     Copyright (C) 2006-2016 Ricardo Villalba <rvm@users.sourceforge.net>
     2    Copyright (C) 2006-2017 Ricardo Villalba <rvm@users.sourceforge.net>
    33
    44    This program is free software; you can redistribute it and/or modify
     
    2222#include <QFile>
    2323#include <QSettings>
     24#include <QDebug>
    2425
    2526#ifdef Q_OS_WIN
     27
     28#define USE_DIRECTX
     29
     30#ifdef USE_DIRECTX
     31#define DIRECTSOUND_VERSION 5
     32#include <dsound.h>
     33#include <ddraw.h>
     34
     35QStringList dsound_device_list;
     36QStringList ddraw_device_list;
     37
     38BOOL CALLBACK DirectSoundEnum(LPGUID guid, LPCSTR desc, LPCSTR module, LPVOID context)
     39{
     40        Q_UNUSED(guid);
     41        Q_UNUSED(module);
     42        Q_UNUSED(context);
     43
     44        dsound_device_list << QString(desc);
     45        return TRUE;
     46}
     47
     48BOOL WINAPI DirectDrawEnum(GUID FAR *lpGUID, LPSTR lpDriverDescription, LPSTR lpDriverName, LPVOID lpContext, HMONITOR hm)
     49{
     50        Q_UNUSED(lpDriverName);
     51        Q_UNUSED(lpContext);
     52        Q_UNUSED(hm);
     53
     54        if (!lpGUID) {
     55                ddraw_device_list << "Primary Display Adapter";
     56        } else {
     57                ddraw_device_list << QString(lpDriverDescription);
     58        }
     59        return TRUE;
     60}
     61
     62
     63DeviceList DeviceInfo::retrieveDevices(DeviceType type) {
     64        qDebug("DeviceInfo::retrieveDevices: %d", type);
     65
     66        DeviceList l;
     67
     68        dsound_device_list.clear();
     69        ddraw_device_list.clear();
     70
     71        if (type == Sound) {
     72                DirectSoundEnumerateA(DirectSoundEnum, NULL);
     73                for (int n = 0; n < dsound_device_list.count(); n++) {
     74                        QString desc = dsound_device_list[n];
     75                        qDebug() << "DeviceInfo::retrieveDevices: audio:" << n << desc;
     76                        l.append( DeviceData(n, desc) );
     77                }
     78        }
     79        else
     80        if (type == Display) {
     81                DirectDrawEnumerateExA(DirectDrawEnum, NULL, DDENUM_ATTACHEDSECONDARYDEVICES);
     82                for (int n = 0; n < ddraw_device_list.count(); n++) {
     83                        QString desc = ddraw_device_list[n];
     84                        qDebug() << "DeviceInfo::retrieveDevices: display:" << n << desc;
     85                        l.append( DeviceData(n, desc) );
     86                }
     87        }
     88
     89        return l;
     90}
     91
     92#else
    2693
    2794DeviceList DeviceInfo::retrieveDevices(DeviceType type) {
     
    71138        return l;
    72139}
     140#endif
    73141
    74142DeviceList DeviceInfo::dsoundDevices() {
     
    82150#else
    83151
     152// Linux
     153
     154#if USE_PULSEAUDIO_DEVICES
     155DeviceList DeviceInfo::paDevices() {
     156        qDebug("DeviceInfo::paDevices");
     157
     158        static DeviceList l;
     159        if (!l.isEmpty()) return l;
     160
     161        QRegExp rx_index("(.*)index: (\\d+)");
     162        QRegExp rx_name("(.*)name: (.*)");
     163
     164        QProcess p;
     165        p.setProcessChannelMode( QProcess::MergedChannels );
     166        QStringList env = QProcess::systemEnvironment();
     167        env << "LC_ALL=C";
     168        p.setEnvironment(env);
     169        p.start("pacmd list-sinks");
     170
     171        int index = -1;
     172        QString name;
     173
     174        if (p.waitForFinished()) {
     175                QByteArray line;
     176                while (p.canReadLine()) {
     177                        line = p.readLine().trimmed();
     178                        //qDebug() << "DeviceInfo::paDevices:" << line;
     179                        if (rx_index.indexIn(line) > -1 ) {
     180                                index = rx_index.cap(2).toInt();
     181                                qDebug() << "DeviceInfo::paDevices: index:" << index;
     182                        }
     183                        if (rx_name.indexIn(line) > -1 ) {
     184                                name = rx_name.cap(2);
     185                                if (name.startsWith('<') && name.endsWith('>')) { name = name.mid(1); name.chop(1); }
     186                                qDebug() << "DeviceInfo::paDevices: name:" << name;
     187                                if (index != -1) {
     188                                        l.append( DeviceData(index, name) );
     189                                        index = -1;
     190                                }
     191                        }
     192                }
     193        }
     194
     195        return l;
     196}
     197#endif // USE_PULSEAUDIO_DEVICES
     198
     199#if USE_ALSA_DEVICES
    84200DeviceList DeviceInfo::alsaDevices() {
    85201        qDebug("DeviceInfo::alsaDevices");
     
    127243        return l;
    128244}
    129 
     245#endif
     246
     247#ifdef USE_XV_ADAPTORS
    130248DeviceList DeviceInfo::xvAdaptors() {
    131249        qDebug("DeviceInfo::xvAdaptors");
     
    171289        return l;
    172290}
    173 
     291#endif
     292#endif
     293
     294#if MPV_AUDIO_DEVICES
     295QString DeviceInfo::mpv_bin;
     296
     297#if USE_MPV_ALSA_DEVICES
     298DeviceList DeviceInfo::mpvAlsaDevices() {
     299        static DeviceList l;
     300        if (!l.isEmpty()) return l;
     301        l = mpvAudioDevices("alsa");
     302        return l;
     303}
     304#endif
     305
     306#if USE_MPV_WASAPI_DEVICES
     307DeviceList DeviceInfo::mpvWasapiDevices() {
     308        static DeviceList l;
     309        if (!l.isEmpty()) return l;
     310        l = mpvAudioDevices("wasapi");
     311        return l;
     312}
     313#endif
     314       
     315DeviceList DeviceInfo::mpvAudioDevices(const QString & filter) {
     316        DeviceList l;
     317        if (!mpv_bin.isEmpty()) l = mpvAudioDevices(mpv_bin, filter);
     318        return l;
     319}
     320
     321DeviceList DeviceInfo::mpvAudioDevices(const QString & mpv_bin, const QString & filter) {
     322        qDebug("DeviceInfo::mpvAudioDevices");
     323
     324        DeviceList l;
     325
     326        QRegExp rx("'" + filter + "\\/(.*)'\\s+\\((.*)\\)");
     327
     328        QProcess p;
     329        p.setProcessChannelMode( QProcess::MergedChannels );
     330
     331        p.start(mpv_bin, QStringList() << "--audio-device=help");
     332
     333        QString device;
     334        QString name;
     335        //int index = 0;
     336
     337        if (p.waitForFinished()) {
     338                QString line;
     339                while (p.canReadLine()) {
     340                        line = QString::fromUtf8(p.readLine().trimmed());
     341                        qDebug() << "DeviceInfo::mpvAudioDevices:" << line;
     342
     343                        if (rx.indexIn(line) > -1 ) {
     344                                device = rx.cap(1);
     345                                name = rx.cap(2);
     346                                qDebug() << "DeviceInfo::mpvAudioDevices: device:" << device << "name:" << name;
     347                                l.append( DeviceData(device, name) );
     348                                //index++;
     349                        }
     350                }
     351        }
     352
     353        return l;
     354}
    174355#endif
    175356
     
    201382}
    202383#endif
     384
     385QString DeviceInfo::printableName(const QString & driver_name, const DeviceData & device) {
     386        return printableName(driver_name, device.ID().toString(), device.desc());
     387}
     388
     389QString DeviceInfo::internalName(const QString & driver_name, const DeviceData & device) {
     390        return internalName(driver_name, device.ID().toString(), device.desc());
     391}
     392
     393QString DeviceInfo::printableName(const QString & driver_name, const QString & id, const QString & desc) {
     394        Q_UNUSED(id);
     395        return driver_name +" (" + /* id + " - " + */ desc + ")";
     396}
     397
     398QString DeviceInfo::internalName(const QString & driver_name, const QString & id, const QString & desc) {
     399        return driver_name + ":::" + id + ":::" + desc;
     400}
     401
     402QStringList DeviceInfo::extractDevice(const QString & internal_name) {
     403        return internal_name.split(":::");
     404}
Note: See TracChangeset for help on using the changeset viewer.