Skip to content
Permalink
Browse files

added: drm files to autodetect physical ID. credits @PoppyPop

(+compilation fixes and changes to make it build in the newer tree)
  • Loading branch information...
opdenkamp committed Jul 3, 2015
1 parent bb7c850 commit 2ac430f0f2d68a338f4f08b774482741436f23ce
@@ -104,6 +104,7 @@ set(CEC_HEADERS devices/CECRecordingDevice.h
platform/adl/adl_defines.h
platform/adl/adl-edid.h
platform/adl/adl_sdk.h
platform/drm/drm-edid.cpp
platform/sockets/serialport.h
platform/X11/randr-edid.h
CECClient.h
@@ -44,6 +44,7 @@
#include "platform/util/edid.h"
#include "platform/adl/adl-edid.h"
#include "platform/nvidia/nv-edid.h"
#include "platform/drm/drm-edid.h"
#include "LibCEC.h"
#include "CECProcessor.h"

@@ -687,6 +688,17 @@ uint16_t CUSBCECAdapterCommunication::GetPhysicalAddress(void)
}
#endif

// try to get the PA from the intel driver
#if defined(HAS_DRM_EDID_PARSER)
if (iPA == 0)
{
LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - trying to get the physical address via drm files", __FUNCTION__);
CDRMEdidParser nv;
iPA = nv.GetPhysicalAddress();
LIB_CEC->AddLog(CEC_LOG_DEBUG, "%s - drm files returned physical address %04x", __FUNCTION__, iPA);
}
#endif

// try to get the PA from the OS
if (iPA == 0)
{
@@ -52,6 +52,9 @@ else()
set(LIB_DESTINATION "${CMAKE_INSTALL_LIBDIR}")
set(LIB_INFO "${LIB_INFO}, features: P8_USB")

# always try DRM on Linux if other methods fail
add_definitions(-DHAS_DRM_EDID_PARSER)

# lockdev
check_include_files(lockdev.h HAVE_LOCKDEV_HEADERS)
check_library_exists(lockdev dev_unlock "" HAVE_LOCKDEV_LIB)
@@ -0,0 +1,125 @@
/*
* This file is part of the libCEC(R) library.
*
* libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited. All rights reserved.
* libCEC(R) is an original work, containing original code.
*
* libCEC(R) is a trademark of Pulse-Eight Limited.
*
* This program is dual-licensed; 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
* Alternatively, you can license this library under a commercial license,
* please contact Pulse-Eight Licensing for more information.
*
* For more information contact:
* Pulse-Eight Licensing <license@pulse-eight.com>
* http://www.pulse-eight.com/
* http://www.pulse-eight.net/
*/

#include "env.h"
#ifdef HAS_DRM_EDID_PARSER

#include "platform/os.h"
#include "drm-edid.h"
#include <dirent.h>
#include <fstream>

using namespace PLATFORM;

uint16_t CDRMEdidParser::GetPhysicalAddress(void)
{
uint16_t iPA(0);

#if defined(HAS_DRM_EDID_PARSER)

// Fisrt we look for all DRM subfolder
std::string baseDir = "/sys/class/drm/";

DIR *dir = opendir(baseDir.c_str());

struct dirent *entry = readdir(dir);
std::string enablededid;
std::string line;

while (entry != NULL)
{
// We look if the element is a symlinl
if (entry->d_type == DT_LNK)
{
// We look for the file enable to find the active video card
std::string path, enabledPath, edidPath;
path = baseDir + entry->d_name;
enabledPath = path + "/enabled";
edidPath = path + "/edid";

std::ifstream f(enabledPath.c_str());
if (f.is_open())
{
if (f.good() && !f.eof())
{
getline(f, line);

// We look if the card is "Enabled"
if (line == "enabled")
{
// We look if the directory have an edid file
std::ifstream edid(edidPath.c_str());
if (edid.is_open())
{
if (edid.good()) {
enablededid = edidPath;
}
edid.close();
}
}
}
f.close();
}
}
entry = readdir(dir);
}

closedir(dir);

if (!enablededid.empty())
{
FILE *fp = fopen(enablededid.c_str(), "r");

if (fp)
{
char buf[4096];
memset(buf, 0, sizeof(buf));
int iPtr(0);
int c(0);
while (c != EOF)
{
c = fgetc(fp);
if (c != EOF)
buf[iPtr++] = c;
}

iPA = CEDIDParser::GetPhysicalAddressFromEDID(buf, iPtr);
fclose(fp);
}
}

#endif

return iPA;
}

#endif
@@ -0,0 +1,49 @@
#pragma once
/*
* This file is part of the libCEC(R) library.
*
* libCEC(R) is Copyright (C) 2011-2013 Pulse-Eight Limited. All rights reserved.
* libCEC(R) is an original work, containing original code.
*
* libCEC(R) is a trademark of Pulse-Eight Limited.
*
* This program is dual-licensed; 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*
* Alternatively, you can license this library under a commercial license,
* please contact Pulse-Eight Licensing for more information.
*
* For more information contact:
* Pulse-Eight Licensing <license@pulse-eight.com>
* http://www.pulse-eight.com/
* http://www.pulse-eight.net/
*/
#ifdef HAS_DRM_EDID_PARSER

#include "platform/util/edid.h"

namespace PLATFORM
{
class CDRMEdidParser
{
public:
CDRMEdidParser(void) {};
virtual ~CDRMEdidParser(void) {};

uint16_t GetPhysicalAddress(void);
};
}

#endif

0 comments on commit 2ac430f

Please sign in to comment.
You can’t perform that action at this time.