forked from rdkcentral/rdkservices
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
250 changed files
with
24,434 additions
and
6,040 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[AVInput Docs](https://wiki.rdkcentral.com/display/RDK/AV+Input) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[Activity Monitor docs](https://wiki.rdkcentral.com/display/RDK/ActivityMonitor) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[Bluetooth](https://wiki.rdkcentral.com/display/RDK/Bluetooth) | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# If not stated otherwise in this file or this component's license file the | ||
# following copyright and licenses apply: | ||
# | ||
# Copyright 2020 RDK Management | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
set(PLUGIN_NAME CompositeInput) | ||
set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME}) | ||
|
||
find_package(${NAMESPACE}Plugins REQUIRED) | ||
|
||
add_library(${MODULE_NAME} SHARED | ||
CompositeInput.cpp | ||
Module.cpp | ||
../helpers/utils.cpp) | ||
|
||
set_target_properties(${MODULE_NAME} PROPERTIES | ||
CXX_STANDARD 11 | ||
CXX_STANDARD_REQUIRED YES) | ||
|
||
list(APPEND CMAKE_MODULE_PATH | ||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/") | ||
|
||
find_package(DS) | ||
find_package(IARMBus) | ||
|
||
target_include_directories(${MODULE_NAME} PRIVATE ${DS_INCLUDE_DIRS}) | ||
target_include_directories(${MODULE_NAME} PRIVATE ${IARMBUS_INCLUDE_DIRS}) | ||
target_include_directories(${MODULE_NAME} PRIVATE ../helpers) | ||
|
||
target_link_libraries(${MODULE_NAME} PUBLIC ${NAMESPACE}Plugins::${NAMESPACE}Plugins ${IARMBUS_LIBRARIES} ${DS_LIBRARIES} ) | ||
|
||
install(TARGETS ${MODULE_NAME} | ||
DESTINATION lib/${STORAGE_DIRECTORY}/plugins) | ||
|
||
write_config(${PLUGIN_NAME}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
set (autostart false) | ||
set (preconditions Platform) | ||
set (callsign "org.rdk.CompositeInput") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,286 @@ | ||
/** | ||
* If not stated otherwise in this file or this component's LICENSE | ||
* file the following copyright and licenses apply: | ||
* | ||
* Copyright 2019 RDK Management | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
**/ | ||
|
||
#include "CompositeInput.h" | ||
#include "utils.h" | ||
|
||
#include "compositeIn.hpp" | ||
#include "exception.hpp" | ||
#include "dsUtl.h" | ||
#include "dsError.h" | ||
#include "dsMgr.h" | ||
|
||
#define COMPOSITE_HOT_PLUG_EVENT_CONNECTED 1 | ||
#define COMPOSITE_HOT_PLUG_EVENT_DISCONNECTED 0 | ||
|
||
#define COMPOSITEINPUT_METHOD_GET_COMPOSITE_INPUT_DEVICES "getCompositeInputDevices" | ||
#define COMPOSITEINPUT_METHOD_START_COMPOSITE_INPUT "startCompositeInput" | ||
#define COMPOSITEINPUT_METHOD_STOP_COMPOSITE_INPUT "stopCompositeInput" | ||
#define COMPOSITEINPUT_METHOD_SCALE_COMPOSITE_INPUT "setVideoRectangle" | ||
|
||
#define COMPOSITEINPUT_EVENT_ON_DEVICES_CHANGED "onDevicesChanged" | ||
|
||
namespace WPEFramework | ||
{ | ||
namespace Plugin | ||
{ | ||
SERVICE_REGISTRATION(CompositeInput, 1, 0); | ||
|
||
CompositeInput* CompositeInput::_instance = nullptr; | ||
|
||
CompositeInput::CompositeInput() | ||
: AbstractPlugin() | ||
{ | ||
LOGINFO(); | ||
CompositeInput::_instance = this; | ||
|
||
InitializeIARM(); | ||
|
||
registerMethod(COMPOSITEINPUT_METHOD_GET_COMPOSITE_INPUT_DEVICES, &CompositeInput::getCompositeInputDevicesWrapper, this); | ||
registerMethod(COMPOSITEINPUT_METHOD_START_COMPOSITE_INPUT, &CompositeInput::startCompositeInput, this); | ||
registerMethod(COMPOSITEINPUT_METHOD_STOP_COMPOSITE_INPUT, &CompositeInput::stopCompositeInput, this); | ||
registerMethod(COMPOSITEINPUT_METHOD_SCALE_COMPOSITE_INPUT, &CompositeInput::setVideoRectangleWrapper, this); | ||
} | ||
|
||
CompositeInput::~CompositeInput() | ||
{ | ||
LOGINFO(); | ||
CompositeInput::_instance = nullptr; | ||
|
||
DeinitializeIARM(); | ||
} | ||
|
||
void CompositeInput::InitializeIARM() | ||
{ | ||
LOGINFO(); | ||
|
||
if (Utils::IARM::init()) | ||
{ | ||
IARM_Result_t res; | ||
IARM_CHECK( IARM_Bus_RegisterEventHandler(IARM_BUS_DSMGR_NAME,IARM_BUS_DSMGR_EVENT_COMPOSITE_IN_HOTPLUG, dsCompositeEventHandler) ); | ||
} | ||
} | ||
|
||
void CompositeInput::DeinitializeIARM() | ||
{ | ||
LOGINFO(); | ||
|
||
if (Utils::IARM::isConnected()) | ||
{ | ||
IARM_Result_t res; | ||
IARM_CHECK( IARM_Bus_UnRegisterEventHandler(IARM_BUS_DSMGR_NAME,IARM_BUS_DSMGR_EVENT_COMPOSITE_IN_HOTPLUG) ); | ||
} | ||
} | ||
|
||
uint32_t CompositeInput::startCompositeInput(const JsonObject& parameters, JsonObject& response) | ||
{ | ||
LOGINFO(); | ||
returnIfParamNotFound(parameters, "portId"); | ||
|
||
string sPortId = parameters["portId"].String(); | ||
int portId = 0; | ||
try { | ||
portId = stoi(sPortId); | ||
}catch (const device::Exception& err) { | ||
LOG_DEVICE_EXCEPTION1(sPortId); | ||
returnResponse(false); | ||
} | ||
|
||
bool success = true; | ||
try | ||
{ | ||
device::CompositeInput::getInstance().selectPort(portId); | ||
} | ||
catch (const device::Exception& err) | ||
{ | ||
LOG_DEVICE_EXCEPTION1(sPortId); | ||
success = false; | ||
} | ||
returnResponse(success); | ||
|
||
} | ||
|
||
uint32_t CompositeInput::stopCompositeInput(const JsonObject& parameters, JsonObject& response) | ||
{ | ||
LOGINFO(); | ||
|
||
bool success = true; | ||
try | ||
{ | ||
device::CompositeInput::getInstance().selectPort(-1); | ||
} | ||
catch (const device::Exception& err) | ||
{ | ||
LOGWARN("CompositeInputService::stopCompositeInput Failed"); | ||
success = false; | ||
} | ||
returnResponse(success); | ||
|
||
} | ||
|
||
uint32_t CompositeInput::setVideoRectangleWrapper(const JsonObject& parameters, JsonObject& response) | ||
{ | ||
LOGINFO(); | ||
|
||
bool result = true; | ||
if (!parameters.HasLabel("x") && !parameters.HasLabel("y")) | ||
{ | ||
result = false; | ||
response["message"] = "please specif coordinates (x,y)"; | ||
} | ||
|
||
if (!parameters.HasLabel("w") && !parameters.HasLabel("h")) | ||
{ | ||
result = false; | ||
response["message"] = "please specify window width and height (w,h)"; | ||
} | ||
|
||
if (result) | ||
{ | ||
int x = 0; | ||
int y = 0; | ||
int w = 0; | ||
int h = 0; | ||
|
||
try | ||
{ | ||
if (parameters.HasLabel("x")) | ||
{ | ||
x = std::stoi(parameters["x"].String()); | ||
} | ||
if (parameters.HasLabel("y")) | ||
{ | ||
y = std::stoi(parameters["y"].String()); | ||
} | ||
if (parameters.HasLabel("w")) | ||
{ | ||
w = std::stoi(parameters["w"].String()); | ||
} | ||
if (parameters.HasLabel("h")) | ||
{ | ||
h = std::stoi(parameters["h"].String()); | ||
} | ||
} | ||
catch (...) { | ||
LOGWARN("Invalid Arguments"); | ||
response["message"] = "Invalid Arguments"; | ||
returnResponse(false); | ||
} | ||
|
||
result = setVideoRectangle(x, y, w, h); | ||
if (false == result) { | ||
LOGWARN("CompositeInputService::setVideoRectangle Failed"); | ||
response["message"] = "failed to set scale"; | ||
} | ||
} | ||
|
||
returnResponse(result); | ||
|
||
} | ||
|
||
bool CompositeInput::setVideoRectangle(int x, int y, int width, int height) | ||
{ | ||
bool ret = true; | ||
|
||
try | ||
{ | ||
device::CompositeInput::getInstance().scaleVideo(x, y, width, height); | ||
} | ||
catch (const device::Exception& err) | ||
{ | ||
ret = false; | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
uint32_t CompositeInput::getCompositeInputDevicesWrapper(const JsonObject& parameters, JsonObject& response) | ||
{ | ||
LOGINFO(); | ||
|
||
response["devices"] = getCompositeInputDevices(); | ||
|
||
returnResponse(true); | ||
} | ||
|
||
JsonArray CompositeInput::getCompositeInputDevices() | ||
{ | ||
JsonArray list; | ||
try | ||
{ | ||
int num = device::CompositeInput::getInstance().getNumberOfInputs(); | ||
if (num > 0) { | ||
int i = 0; | ||
for (i = 0; i < num; i++) { | ||
//Input ID is aleays 0-indexed, continuous number starting 0 | ||
JsonObject hash; | ||
hash["id"] = i; | ||
std::stringstream locator; | ||
locator << "cvbsin://localhost/deviceid/" << i; | ||
hash["locator"] = locator.str(); | ||
hash["connected"] = device::CompositeInput::getInstance().isPortConnected(i) ? "true" : "false"; | ||
LOGWARN("CompositeInputService::getCompositeInputDevices id %d, locator=[%s], connected=[%s]", i, hash["locator"].String().c_str(), hash["connected"].String().c_str()); | ||
list.Add(hash); | ||
} | ||
} | ||
} | ||
catch (const std::exception e) { | ||
LOGWARN("CompositeInputService::getCompositeInputDevices Failed"); | ||
} | ||
|
||
return list; | ||
} | ||
|
||
|
||
/** | ||
* @brief This function is used to translate COMPOSITE input hotplug to | ||
* deviceChanged event. | ||
* | ||
* @param[in] input Number of input port integer. | ||
* @param[in] connection status of input port integer. | ||
*/ | ||
void CompositeInput::compositeInputHotplug( int input , int connect) | ||
{ | ||
LOGWARN("compositeInputHotplug [%d, %d]", input, connect); | ||
|
||
JsonObject params; | ||
params["devices"] = getCompositeInputDevices(); | ||
sendNotify(COMPOSITEINPUT_EVENT_ON_DEVICES_CHANGED, params); | ||
} | ||
|
||
void CompositeInput::dsCompositeEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len) | ||
{ | ||
LOGINFO(); | ||
|
||
if(!CompositeInput::_instance) | ||
return; | ||
|
||
if (IARM_BUS_DSMGR_EVENT_COMPOSITE_IN_HOTPLUG == eventId) | ||
{ | ||
IARM_Bus_DSMgr_EventData_t *eventData = (IARM_Bus_DSMgr_EventData_t *)data; | ||
int compositein_hotplug_port = eventData->data.composite_in_connect.port; | ||
int compositein_hotplug_conn = eventData->data.composite_in_connect.isPortConnected; | ||
LOGWARN("Received IARM_BUS_DSMGR_EVENT_COMPOSITE_IN_HOTPLUG event data:%d", compositein_hotplug_port); | ||
|
||
CompositeInput::_instance->compositeInputHotplug(compositein_hotplug_port, compositein_hotplug_conn ? COMPOSITE_HOT_PLUG_EVENT_CONNECTED : COMPOSITE_HOT_PLUG_EVENT_DISCONNECTED); | ||
} | ||
} | ||
|
||
} // namespace Plugin | ||
} // namespace WPEFramework |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/** | ||
* If not stated otherwise in this file or this component's LICENSE | ||
* file the following copyright and licenses apply: | ||
* | ||
* Copyright 2019 RDK Management | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
**/ | ||
|
||
#pragma once | ||
|
||
#include "libIBus.h" | ||
|
||
#include "Module.h" | ||
#include "utils.h" | ||
#include "AbstractPlugin.h" | ||
|
||
namespace WPEFramework { | ||
|
||
namespace Plugin { | ||
|
||
// This is a server for a JSONRPC communication channel. | ||
// For a plugin to be capable to handle JSONRPC, inherit from PluginHost::JSONRPC. | ||
// By inheriting from this class, the plugin realizes the interface PluginHost::IDispatcher. | ||
// This realization of this interface implements, by default, the following methods on this plugin | ||
// - exists | ||
// - register | ||
// - unregister | ||
// Any other methood to be handled by this plugin can be added can be added by using the | ||
// templated methods Register on the PluginHost::JSONRPC class. | ||
// As the registration/unregistration of notifications is realized by the class PluginHost::JSONRPC, | ||
// this class exposes a public method called, Notify(), using this methods, all subscribed clients | ||
// will receive a JSONRPC message as a notification, in case this method is called. | ||
class CompositeInput : public AbstractPlugin { | ||
private: | ||
|
||
// We do not allow this plugin to be copied !! | ||
CompositeInput(const CompositeInput&) = delete; | ||
CompositeInput& operator=(const CompositeInput&) = delete; | ||
|
||
void InitializeIARM(); | ||
void DeinitializeIARM(); | ||
|
||
//Begin methods | ||
uint32_t getCompositeInputDevicesWrapper(const JsonObject& parameters, JsonObject& response); | ||
uint32_t startCompositeInput(const JsonObject& parameters, JsonObject& response); | ||
uint32_t stopCompositeInput(const JsonObject& parameters, JsonObject& response); | ||
|
||
uint32_t setVideoRectangleWrapper(const JsonObject& parameters, JsonObject& response); | ||
//End methods | ||
|
||
JsonArray getCompositeInputDevices(); | ||
|
||
bool setVideoRectangle(int x, int y, int width, int height); | ||
|
||
void compositeInputHotplug( int input , int connect); | ||
static void dsCompositeEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len); | ||
|
||
public: | ||
CompositeInput(); | ||
virtual ~CompositeInput(); | ||
|
||
void terminate(); | ||
|
||
public: | ||
static CompositeInput* _instance; | ||
}; | ||
} // namespace Plugin | ||
} // namespace WPEFramework |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"locator":"libWPEFrameworkCompositeInput.so", | ||
"classname":"CompositeInput", | ||
"precondition":[ | ||
"Platform" | ||
], | ||
"callsign":"org.rdk.CompositeInput", | ||
"autostart":false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/** | ||
* If not stated otherwise in this file or this component's LICENSE | ||
* file the following copyright and licenses apply: | ||
* | ||
* Copyright 2019 RDK Management | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
**/ | ||
|
||
#include "Module.h" | ||
|
||
MODULE_NAME_DECLARATION(BUILD_REFERENCE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* If not stated otherwise in this file or this component's LICENSE | ||
* file the following copyright and licenses apply: | ||
* | ||
* Copyright 2019 RDK Management | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
**/ | ||
|
||
#pragma once | ||
#ifndef MODULE_NAME | ||
#define MODULE_NAME CompositeInput | ||
#endif | ||
|
||
#include <plugins/plugins.h> | ||
#include <tracing/tracing.h> | ||
|
||
#undef EXTERNAL | ||
#define EXTERNAL |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
----------------- | ||
Build: | ||
|
||
bitbake wpeframework-service-plugins | ||
|
||
----------------- | ||
Test: | ||
|
||
curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","id":"3","method": "CompositeInput.1."}' http://127.0.0.1:9998/jsonrpc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# If not stated otherwise in this file or this component's license file the | ||
# following copyright and licenses apply: | ||
# | ||
# Copyright 2020 RDK Management | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# - Try to find Display Settings library | ||
# Once done this will define | ||
# DS_FOUND - System has DS | ||
# DS_INCLUDE_DIRS - The DS include directories | ||
# DS_LIBRARIES - The libraries needed to use DS | ||
# DS_FLAGS - The flags needed to use DS | ||
# | ||
|
||
find_package(PkgConfig) | ||
|
||
find_library(DS_LIBRARIES NAMES ds) | ||
find_path(DS_INCLUDE_DIRS NAMES hdmiIn.hpp PATH_SUFFIXES rdk/ds) | ||
|
||
set(DS_LIBRARIES ${DS_LIBRARIES}) | ||
set(DS_LIBRARIES ${DS_LIBRARIES} CACHE PATH "Path to DS library") | ||
set(DS_INCLUDE_DIRS ${DS_INCLUDE_DIRS}) | ||
set(DS_INCLUDE_DIRS ${DS_INCLUDE_DIRS} CACHE PATH "Path to DS include") | ||
|
||
|
||
find_library(DS_LIBRARIES NAMES ds) | ||
#find_library(DSHAL_LIBRARIES NAMES dshalcli) | ||
#find_path(DS_INCLUDE_DIRS NAMES manager.hpp PATH_SUFFIXES rdk/ds) | ||
find_path(DSHAL_INCLUDE_DIRS NAMES dsTypes.h PATH_SUFFIXES rdk/ds-hal) | ||
find_path(DSRPC_INCLUDE_DIRS NAMES dsMgr.h PATH_SUFFIXES rdk/ds-rpc) | ||
|
||
#set(DS_LIBRARIES ${DS_LIBRARIES} ${DSHAL_LIBRARIES}) | ||
#set(DS_LIBRARIES ${DS_LIBRARIES} CACHE PATH "Path to DS library") | ||
set(DS_INCLUDE_DIRS ${DS_INCLUDE_DIRS} ${DSHAL_INCLUDE_DIRS} ${DSRPC_INCLUDE_DIRS}) | ||
#set(DS_INCLUDE_DIRS ${DS_INCLUDE_DIRS} CACHE PATH "Path to DS include") | ||
|
||
|
||
include(FindPackageHandleStandardArgs) | ||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(DS DEFAULT_MSG DS_INCLUDE_DIRS DS_LIBRARIES) | ||
|
||
mark_as_advanced( | ||
DS_FOUND | ||
DS_INCLUDE_DIRS | ||
DS_LIBRARIES | ||
DS_LIBRARY_DIRS | ||
DS_FLAGS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# If not stated otherwise in this file or this component's license file the | ||
# following copyright and licenses apply: | ||
# | ||
# Copyright 2020 RDK Management | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
# - Try to find IARMBus | ||
# Once done this will define | ||
# IARMBUS_FOUND - System has IARMBus | ||
# IARMBUS_INCLUDE_DIRS - The IARMBus include directories | ||
# IARMBUS_LIBRARIES - The libraries needed to use IARMBus | ||
# IARMBUS_FLAGS - The flags needed to use IARMBus | ||
# | ||
|
||
find_package(PkgConfig) | ||
|
||
find_library(IARMBUS_LIBRARIES NAMES IARMBus) | ||
find_path(IARMIR_INCLUDE_DIRS NAMES sysMgr.h PATH_SUFFIXES rdk/iarmmgrs/sysmgr) | ||
|
||
set(IARMBUS_LIBRARIES ${IARMBUS_LIBRARIES} CACHE PATH "Path to IARMBus library") | ||
set(IARMBUS_INCLUDE_DIRS ${IARMBUS_INCLUDE_DIRS} ${IARMIR_INCLUDE_DIRS} ${SYSMGR_INCLUDE_DIRS} ${IARMIR_INCLUDE_DIRS../sysmgr} ) | ||
set(IARMBUS_INCLUDE_DIRS ${IARMBUS_INCLUDE_DIRS} ${IARMIR_INCLUDE_DIRS} ${SYSMGR_INCLUDE_DIRS} ${IARMIR_INCLUDE_DIRS../sysmgr} CACHE PATH "Path to IARMBus include") | ||
|
||
|
||
include(FindPackageHandleStandardArgs) | ||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(IARMBUS DEFAULT_MSG IARMBUS_INCLUDE_DIRS IARMBUS_LIBRARIES) | ||
|
||
mark_as_advanced( | ||
IARMBUS_FOUND | ||
IARMBUS_INCLUDE_DIRS | ||
IARMBUS_LIBRARIES | ||
IARMBUS_LIBRARY_DIRS | ||
IARMBUS_FLAGS) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
|
||
Versions | ||
org.rdk.CompositeInput.1 - initial version of Composite Input API. | ||
|
||
------------------------------ | ||
|
||
Methods | ||
|
||
----------------------------- | ||
|
||
getCompositeInputDevices (v1) | ||
Description: returns an array of composite input devices. | ||
|
||
Arguments: none | ||
|
||
Returns: | ||
|
||
devices : array - an array of compositeInputDevice object (based on number of Composite Input ports on the device), where compositeInputDevice is: | ||
|
||
{ | ||
id: number, | ||
location: string, | ||
connected: boolean | ||
} | ||
|
||
|
||
|
||
Request : {"jsonrpc":"2.0", "id":3, "method":"org.rdk.CompositeInput.1.getCompositeInputDevices"} | ||
|
||
Response: {"jsonrpc":"2.0","id":3,"result":{"devices":[{"id":0,"locator":"cvbsin://localhost/deviceid/0","connected":"true"},{"id":1,"locator":"cvbsin://localhost/deviceid/1","connected":"false"}],"success":true}} | ||
|
||
|
||
--------------------------------- | ||
|
||
startCompositeInput (v1) | ||
Description: Activates selected Composite In Port as primary video source. | ||
|
||
Arguments | ||
|
||
portId : number - an id of Composite In source. (getCompositeInputDevices (v1) will list available Composite Input devices and portIds) | ||
Returns: | ||
|
||
success : bool - result of activating Composite Input | ||
Request : {"jsonrpc":"2.0", "id":3, "method":"org.rdk.CompositeInput.1.startCompositeInput", "params": {"portId":"1"}} | ||
|
||
Response: {"jsonrpc":"2.0","id":3,"result":{"success":true}} | ||
|
||
--------------------------------- | ||
|
||
stopCompositeInput (v1) | ||
Description: Deactivates current Composite In Port selected as primary video source. | ||
|
||
Returns: | ||
|
||
success : bool - result of deactivating Composite Input | ||
Request : {"jsonrpc":"2.0", "id":3, "method":"org.rdk.CompositeInput.1.stopCompositeInput"} | ||
|
||
Response: {"jsonrpc":"2.0","id":3,"result":{"success":true}} | ||
|
||
-------------------------------- | ||
|
||
setVideoRectangle (v1) | ||
Description: Sets Composite Input video window | ||
|
||
Arguments | ||
|
||
x: int - The x-coordinate of the video rectangle. | ||
y: int - The y-coordinate of the video rectangle. | ||
w: int - The width of the video rectangle. | ||
h: int - The height of the video rectangle. | ||
Returns: | ||
|
||
success : bool - result of setting Composite Input video window | ||
Request : {"jsonrpc":"2.0","id":"3","method": "org.rdk.CompositeInput.1.setVideoRectangle", "params":{"x":"0","y":"0","w":"1920","h":"1080"}} | ||
|
||
Response: {"jsonrpc":"2.0","id":3,"result":{"success":true}} | ||
|
||
-------------------------------- | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[Continue Watching](https://wiki.rdkcentral.com/display/RDK/Continue+Watching) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[Control Service](https://wiki.rdkcentral.com/display/RDK/Control+Service) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[DataCapture](https://wiki.rdkcentral.com/display/RDK/DataCapture) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[DeviceDiagnostics](https://wiki.rdkcentral.com/display/RDK/Device+Diagnostics) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
135 changes: 135 additions & 0 deletions
135
DeviceIdentification/Implementation/Realtek/Realtek.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
/* | ||
* If not stated otherwise in this file or this component's LICENSE file the | ||
* following copyright and licenses apply: | ||
* | ||
* Copyright 2020 RDK Management | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include "../../Module.h" | ||
#include <interfaces/IDeviceIdentification.h> | ||
#include <fstream> | ||
|
||
namespace WPEFramework { | ||
namespace Plugin { | ||
|
||
class DeviceImplementation : public Exchange::IDeviceProperties, public PluginHost::ISubSystem::IIdentifier { | ||
static constexpr const TCHAR* CPUInfoFile= _T("/proc/cpuinfo"); | ||
static constexpr const TCHAR* VERSIONFile= _T("/version.txt"); | ||
|
||
public: | ||
DeviceImplementation() | ||
{ | ||
UpdateChipset(_chipset); | ||
UpdateFirmwareVersion(_firmwareVersion); | ||
UpdateIdentifier(); | ||
} | ||
|
||
DeviceImplementation(const DeviceImplementation&) = delete; | ||
DeviceImplementation& operator= (const DeviceImplementation&) = delete; | ||
virtual ~DeviceImplementation() | ||
{ | ||
/* Nothing to do here. */ | ||
} | ||
|
||
public: | ||
// Device Propertirs interface | ||
const string Chipset() const override | ||
{ | ||
return _chipset; | ||
} | ||
const string FirmwareVersion() const override | ||
{ | ||
return _firmwareVersion; | ||
} | ||
|
||
// Identifier interface | ||
uint8_t Identifier(const uint8_t length, uint8_t buffer[]) const override | ||
{ | ||
uint8_t result = 0; | ||
if ((_identity.length())) { | ||
result = (_identity.length() > length ? length : _identity.length()); | ||
::memcpy(buffer, _identity.c_str(), result); | ||
} else { | ||
SYSLOG(Logging::Notification, (_T("Cannot determine system identity"))); | ||
} | ||
return result; | ||
} | ||
|
||
BEGIN_INTERFACE_MAP(DeviceImplementation) | ||
INTERFACE_ENTRY(Exchange::IDeviceProperties) | ||
INTERFACE_ENTRY(PluginHost::ISubSystem::IIdentifier) | ||
END_INTERFACE_MAP | ||
|
||
private: | ||
inline void UpdateFirmwareVersion(string& firmwareVersion) const | ||
{ | ||
string line; | ||
std::ifstream file(VERSIONFile); | ||
if (file.is_open()) { | ||
while (getline(file, line)) { | ||
if (line.find("SDK_VERSION") != std::string::npos) { | ||
std::size_t position = line.find('='); | ||
if (position != std::string::npos) { | ||
firmwareVersion.assign(line.substr(position + 1, string::npos)); | ||
break; | ||
} | ||
} | ||
} | ||
file.close(); | ||
} | ||
} | ||
|
||
inline void UpdateChipset(string& chipset) const | ||
{ | ||
string line; | ||
std::ifstream file(CPUInfoFile); | ||
if (file.is_open()) { | ||
while (getline(file, line)) { | ||
if (line.find("Hardware") != std::string::npos) { | ||
std::size_t position = line.find(": "); | ||
if (position != std::string::npos) { | ||
chipset.assign(line.substr(position + 2, string::npos)); | ||
} | ||
} | ||
} | ||
file.close(); | ||
} | ||
} | ||
|
||
inline void UpdateIdentifier() | ||
{ | ||
string line; | ||
std::ifstream file(CPUInfoFile); | ||
if (file.is_open()) { | ||
while (getline(file, line)) { | ||
if (line.find("Serial") != std::string::npos) { | ||
std::size_t position = line.find(": "); | ||
if (position != std::string::npos) { | ||
_identity.assign(line.substr(position + 2, string::npos)); | ||
} | ||
} | ||
} | ||
file.close(); | ||
} | ||
} | ||
|
||
private: | ||
string _chipset; | ||
string _firmwareVersion; | ||
string _identity; | ||
}; | ||
|
||
SERVICE_REGISTRATION(DeviceImplementation, 1, 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
/* | ||
* If not stated otherwise in this file or this component's LICENSE file the | ||
* following copyright and licenses apply: | ||
* | ||
* Copyright 2020 RDK Management | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include <string> | ||
#include <iostream> | ||
#include <vector> | ||
#include <cstring> | ||
#include <cstdio> | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <fcntl.h> | ||
#include "kms.h" | ||
|
||
#define MEM_PROCFS "/proc/meminfo" | ||
#define TOTAL_MEM_PARAM_STR "MemTotal:" | ||
#define FREE_MEM_PARAM_STR "MemFree:" | ||
#define DEFAULT_DEVICE "/dev/dri/card0" | ||
|
||
using namespace std; | ||
|
||
static uint64_t parseLine(const char * line); | ||
static uint64_t getMemInfo(const char * param); | ||
static void getPrimaryPlane(int drm_fd, kms_ctx *kms, drmModePlane **plane); | ||
static void getGraphicSize(uint32_t &w, uint32_t &h); | ||
|
||
static uint64_t parseLine(const char * line) | ||
{ | ||
string str(line); | ||
uint64_t val = 0; | ||
size_t begin = str.find_first_of("0123456789"); | ||
size_t end = string::npos; | ||
|
||
if (string::npos != begin) | ||
end = str.find_first_not_of("0123456789", begin); | ||
|
||
if (string::npos != begin && string::npos != end) | ||
{ | ||
|
||
str = str.substr(begin, end); | ||
val = strtoul(str.c_str(), NULL, 10); | ||
|
||
} | ||
else | ||
{ | ||
cout << "Failed to parse: " << line << endl; | ||
} | ||
|
||
return val; | ||
} | ||
|
||
static uint64_t getMemInfo(const char * param) | ||
{ | ||
FILE *meminfoFile = fopen(MEM_PROCFS, "r"); | ||
uint64_t memVal = 0; | ||
if (NULL == meminfoFile) | ||
{ | ||
cout << "Failed to open " << MEM_PROCFS << ", error: " << strerror(errno) << endl; | ||
} | ||
else | ||
{ | ||
vector <char> buf; | ||
buf.resize(1024); | ||
|
||
while (fgets(buf.data(), buf.size(), meminfoFile)) | ||
{ | ||
if ( strstr(buf.data(), param ) == buf.data()) | ||
{ | ||
memVal = parseLine(buf.data()) * 1000; | ||
break; | ||
} | ||
} | ||
|
||
fclose(meminfoFile); | ||
} | ||
return memVal; | ||
} | ||
|
||
static void getPrimaryPlane(int drm_fd, kms_ctx *kms, drmModePlane **plane) | ||
{ | ||
kms_get_plane(drm_fd, kms); | ||
cout << "Primary Plane ID : "<< kms->primary_plane_id << endl; | ||
*plane = drmModeGetPlane(drm_fd, kms->primary_plane_id ); | ||
if(*plane) | ||
printf("fb id : %d\n", (*plane)->fb_id); | ||
} | ||
|
||
static void getGraphicSize(uint32_t &w, uint32_t &h) | ||
{ | ||
int drm_fd; | ||
kms_ctx *kms = NULL; | ||
drmModePlane *plane = NULL; | ||
int trytimes = 0; | ||
|
||
do { | ||
/* Setup buffer information */ | ||
drm_fd = open( DEFAULT_DEVICE, O_RDWR); | ||
|
||
/* Setup KMS */ | ||
kms = kms_setup(drm_fd); | ||
if( !kms->crtc ) { | ||
cout << "[Amlogic] kms_setup fail" << endl; | ||
break; | ||
} | ||
|
||
/* Get primary buffer */ | ||
getPrimaryPlane(drm_fd, kms, &plane); | ||
if( !plane) { | ||
cout << "[Amlogic] fail to getPrimaryPlane" << endl; | ||
break; | ||
} | ||
|
||
/* get fb */ | ||
drmModeFB *fb = drmModeGetFB(drm_fd, plane->fb_id); | ||
while(!fb) { | ||
getPrimaryPlane(drm_fd, kms, &plane); | ||
fb = drmModeGetFB(drm_fd, plane->fb_id); | ||
if (trytimes++ > 100) { | ||
cout << "[Amlogic] fail to getPrimaryPlane" << endl; | ||
break; | ||
} | ||
} | ||
|
||
/* Get the width and height */ | ||
if(fb) { | ||
w = fb->width; | ||
h = fb->height; | ||
drmModeFreeFB(fb); | ||
} | ||
} while(0); | ||
|
||
/* release */ | ||
/* Cleanup buffer info */ | ||
if(kms) { | ||
kms_cleanup_context(kms); | ||
free(kms); | ||
} | ||
|
||
cout << "[getGraphicSize] width : " << w << endl; | ||
cout << "[getGraphicSize] height : " << h << endl; | ||
} | ||
|
||
|
||
uint64_t SoC_GetTotalGpuRam() | ||
{ | ||
return getMemInfo(TOTAL_MEM_PARAM_STR); | ||
} | ||
|
||
uint64_t SoC_GetFreeGpuRam() | ||
{ | ||
return getMemInfo(FREE_MEM_PARAM_STR); | ||
} | ||
|
||
uint32_t SoC_GetGraphicsWidth() | ||
{ | ||
uint32_t w, h; | ||
getGraphicSize(w, h); | ||
return w; | ||
} | ||
|
||
uint32_t SoC_GetGraphicsHeight() | ||
{ | ||
uint32_t w, h; | ||
getGraphicSize(w, h); | ||
return h; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
/* | ||
* If not stated otherwise in this file or this component's LICENSE file the | ||
* following copyright and licenses apply: | ||
* | ||
* Copyright 2020 RDK Management | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <assert.h> | ||
#include <stddef.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include "kms.h" | ||
|
||
void kms_setup_encoder( int fd, kms_ctx *kms ) | ||
{ | ||
int crtcId = 0; | ||
|
||
for( int i = 0; i < kms->res->count_encoders; i++ ) { | ||
|
||
kms->encoder = drmModeGetEncoder(fd,kms->res->encoders[i]); | ||
|
||
if ( kms->encoder && ( kms->encoder->encoder_id == kms->connector->encoder_id ) ) { | ||
|
||
kms->encoder_id = kms->encoder->encoder_id; | ||
return; | ||
} | ||
|
||
|
||
for( int j = 0; j < kms->res->count_crtcs; j++ ) { | ||
|
||
if( kms->encoder->possible_crtcs & ( 1 << j ) ) { | ||
|
||
drmModeFreeEncoder( kms->encoder ); | ||
kms->encoder = drmModeGetEncoder(fd, kms->res->encoders[j]); | ||
|
||
crtcId = kms->res->crtcs[j]; | ||
kms->encoder->crtc_id = kms->crtc_id = j; | ||
goto exit; | ||
} | ||
} | ||
} | ||
|
||
exit: | ||
return; | ||
} | ||
|
||
|
||
|
||
|
||
void kms_setup_connector( int fd, kms_ctx *kms ) | ||
{ | ||
int i = 0, j = 0; | ||
drmModeConnector *connector; | ||
|
||
for( i = 0; i < kms->res->count_connectors; i++ ) { | ||
|
||
connector = drmModeGetConnector(fd, kms->res->connectors[i]); | ||
if( connector ) { | ||
|
||
if( connector->count_modes && ( connector->connection == DRM_MODE_CONNECTED ) ) { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if ( connector ) { | ||
|
||
kms->connector = connector; | ||
kms->connector_id = connector->connector_id; | ||
} | ||
|
||
return; | ||
} | ||
|
||
|
||
void kms_setup_crtc( int fd, kms_ctx *kms ) | ||
{ | ||
if( kms->encoder ) { | ||
|
||
kms->crtc = drmModeGetCrtc(fd, kms->encoder->crtc_id); | ||
|
||
if( kms->crtc && kms->crtc->mode_valid ) { | ||
|
||
kms->current_info = kms->crtc->mode; | ||
kms->crtc_id = kms->encoder->crtc_id; | ||
} | ||
} | ||
|
||
return; | ||
} | ||
|
||
|
||
kms_ctx* kms_setup( int fd ) | ||
{ | ||
kms_ctx *kms = NULL; | ||
kms = (kms_ctx*)calloc(1,sizeof(*kms)); | ||
if( !kms ) | ||
assert(0); | ||
|
||
kms->res = drmModeGetResources(fd); | ||
|
||
kms_setup_connector(fd, kms); | ||
kms_setup_encoder(fd, kms); | ||
kms_setup_crtc(fd, kms); | ||
return kms; | ||
} | ||
|
||
|
||
void kms_cleanup_context( kms_ctx *kms ) | ||
{ | ||
if( kms->connector ) | ||
drmModeFreeConnector(kms->connector); | ||
|
||
if( kms->encoder ) | ||
drmModeFreeEncoder(kms->encoder); | ||
|
||
if( kms->crtc ) | ||
drmModeFreeCrtc(kms->crtc); | ||
|
||
if( kms->res ) | ||
drmModeFreeResources(kms->res); | ||
} | ||
|
||
|
||
uint32_t kms_get_properties(int fd, drmModeObjectProperties *props, const char *name) | ||
{ | ||
drmModePropertyPtr property; | ||
uint32_t i, id = 0; | ||
|
||
for (i = 0; i < props->count_props; i++) { | ||
|
||
property = drmModeGetProperty(fd, props->props[i]); | ||
if (!strcmp(property->name, name)) | ||
id = property->prop_id; | ||
|
||
drmModeFreeProperty(property); | ||
|
||
if ( id ) | ||
return id; | ||
} | ||
} | ||
|
||
|
||
|
||
void kms_get_plane( int fd, kms_ctx *kms ) | ||
{ | ||
int len = 0, n = 0, j = 0, plane_index = -1; | ||
|
||
drmModePlane *plane = NULL; | ||
drmModePlaneRes *planeRes = NULL; | ||
drmModePropertyRes *prop = NULL; | ||
drmModeObjectProperties *props = NULL; | ||
|
||
drmSetClientCap(fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1); | ||
|
||
kms->primary_plane_id = kms->overlay_plane_id = -1; | ||
|
||
planeRes = drmModeGetPlaneResources( fd ); | ||
if ( planeRes ) { | ||
|
||
for( n= 0; n < planeRes->count_planes; ++n ) { | ||
|
||
plane = drmModeGetPlane( fd, planeRes->planes[n] ); | ||
|
||
if ( plane ) { | ||
|
||
props = drmModeObjectGetProperties( fd, planeRes->planes[n], DRM_MODE_OBJECT_PLANE ); | ||
if ( props ) { | ||
|
||
for( j= 0; j < props->count_props; ++j ) { | ||
|
||
prop = drmModeGetProperty( fd, props->props[j] ); | ||
if ( prop ) { | ||
|
||
len = strlen(prop->name); | ||
if ( !strcmp( prop->name, "type") ) { | ||
|
||
if ( ( props->prop_values[j] == DRM_PLANE_TYPE_PRIMARY ) && ( kms->primary_plane_id == -1 ) ) | ||
kms->primary_plane_id = planeRes->planes[n]; | ||
|
||
else if ( ( props->prop_values[j] == DRM_PLANE_TYPE_OVERLAY ) && ( kms->overlay_plane_id == -1 ) ) | ||
kms->overlay_plane_id = planeRes->planes[n]; | ||
} | ||
} | ||
|
||
drmModeFreeProperty( prop ); | ||
} | ||
} | ||
|
||
drmModeFreeObjectProperties( props ); | ||
} | ||
|
||
drmModeFreePlane( plane ); | ||
} | ||
|
||
} | ||
|
||
drmModeFreePlaneResources( planeRes ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* | ||
* If not stated otherwise in this file or this component's LICENSE file the | ||
* following copyright and licenses apply: | ||
* | ||
* Copyright 2020 RDK Management | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef __DRM_KMS_H__ | ||
#define __DRM_KMS_H__ | ||
|
||
#include <xf86drm.h> | ||
#include <xf86drmMode.h> | ||
#include <drm_mode.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef struct _kms_ctx { | ||
|
||
drmModeRes *res; | ||
drmModeConnector *connector; | ||
drmModeEncoder *encoder; | ||
drmModeCrtc *crtc; | ||
|
||
drmModeCrtc *previous_crtc; | ||
drmModeModeInfo current_info; | ||
|
||
uint32_t connector_id; /**< Connector id which will be use in program */ | ||
uint32_t crtc_id; | ||
uint32_t encoder_id; | ||
uint32_t primary_plane_id; | ||
uint32_t overlay_plane_id; | ||
|
||
/* atomic properties */ | ||
uint32_t active_property; | ||
uint32_t mode_id_property; | ||
uint32_t crtc_id_property; | ||
uint32_t blob_id; | ||
|
||
uint32_t fb_id_property; | ||
uint32_t crtc_x_property; | ||
uint32_t crtc_y_property; | ||
uint32_t crtc_h_property; | ||
uint32_t crtc_w_property; | ||
uint32_t src_x_property; | ||
uint32_t src_y_property; | ||
uint32_t src_w_property; | ||
uint32_t src_h_property; | ||
|
||
drmModeAtomicReq *req; | ||
|
||
} kms_ctx; | ||
|
||
/** | ||
* @brief Create kms context | ||
* | ||
* @param[in] fd drm file descriptor | ||
* | ||
* | ||
* @retval kms context | ||
*/ | ||
kms_ctx* kms_setup(int fd); | ||
|
||
|
||
|
||
/** | ||
* @brief Cleanup kms context | ||
* | ||
* @param[in] kms kms context | ||
* | ||
*/ | ||
void kms_cleanup_context(kms_ctx *kms); | ||
|
||
/** | ||
* @brief Set and get possible encoder id | ||
* | ||
* @param[in] fd drm file descriptor | ||
* @param[in] kms kms context | ||
* | ||
*/ | ||
void kms_setup_encoder(int fd, kms_ctx *kms); | ||
|
||
|
||
/** | ||
* @brief Set and get possible connector id | ||
* | ||
* @param[in] fd drm file descriptor | ||
* @para,[in] kms kms context | ||
* | ||
*/ | ||
void kms_setup_connector(int fd, kms_ctx *kms); | ||
|
||
/** | ||
* @brief Set and get possible crtc id | ||
* | ||
* @param[in] fd drm file descriptor | ||
* @param[in] kms kms context | ||
* | ||
*/ | ||
void kms_setup_crtc(int fd, kms_ctx *kms); | ||
|
||
/** | ||
* @brief Get the specific object properties | ||
* | ||
* @param[in] fd drm file descriptor | ||
* @param[in] props all object properties | ||
* @param[in] name the property name which want to be queried | ||
* | ||
*/ | ||
uint32_t kms_get_properties(int fd, drmModeObjectProperties *props, const char *name); | ||
|
||
|
||
/** | ||
* @brief Get primary and overlay plane. | ||
* The plane id will set to -1 if cannot get. | ||
* | ||
* @param[in] fd drm file descriptor | ||
* @param[in] kms kms context | ||
* | ||
*/ | ||
void kms_get_plane( int fd, kms_ctx *kms); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif |
233 changes: 233 additions & 0 deletions
233
DisplayInfo/DeviceSettings/Broadcom/SoC_abstraction.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,233 @@ | ||
/* | ||
* If not stated otherwise in this file or this component's LICENSE file the | ||
* following copyright and licenses apply: | ||
* | ||
* Copyright 2020 RDK Management | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <stdint.h> | ||
#include <iostream> | ||
#include <fstream> | ||
#include <string> | ||
#include <vector> | ||
#include <sstream> | ||
#include <algorithm> | ||
|
||
#include "utils.h" | ||
|
||
#define GRAPHICS_RESOLUTION_LOC 4 | ||
#define WIDTH 0 | ||
#define HEIGHT 1 | ||
#define PROC_BRCM_CORE_PATH "/proc/brcm/core" | ||
#define PROC_BRCM_DISPLAY_PATH "/proc/brcm/display" | ||
|
||
using namespace std; | ||
using namespace WPEFramework; | ||
|
||
/** | ||
* Sanitizeline | ||
* | ||
* @brief : Remove extra white spaces in between words | ||
* | ||
* @param : line to santize. | ||
* @return : void | ||
*/ | ||
void sanitizeLine(string& line) | ||
{ | ||
for(int i = 0; i < line.size(); i++) | ||
{ | ||
while(line[i] == ' ' && line[i+1] == ' ') | ||
{ | ||
line.erase(i,1); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* tokenize | ||
* | ||
* @brief : split line into tokens using delimitter | ||
* | ||
* @param : line | ||
* @param : tokens array | ||
* @param : delimitter | ||
* @return : void | ||
*/ | ||
void tokenize(string line, vector<string>& tokens, char delim) | ||
{ | ||
istringstream iss(line); | ||
string token; | ||
while (getline(iss, token, delim)) | ||
{ | ||
tokens.push_back(token); | ||
} | ||
} | ||
|
||
/** | ||
* parse_proc_brcm_core | ||
* | ||
* @brief : parse profs to obtain GPU ram details | ||
* | ||
* @param : columnHeader | ||
* @param : bufferName | ||
* @return : value | ||
*/ | ||
string parse_proc_brcm_core(string columnHeader) | ||
{ | ||
LOGINFO(); | ||
|
||
ifstream procfile(PROC_BRCM_CORE_PATH); | ||
string line, value; | ||
vector<string> tokens; | ||
int column = 0; | ||
|
||
if (procfile.is_open()) | ||
{ | ||
while (getline(procfile,line)) | ||
{ | ||
if(line.find(columnHeader) != string::npos) | ||
{ | ||
tokens.clear(); | ||
sanitizeLine(line); | ||
tokenize(line, tokens, ' '); | ||
column = find(tokens.begin(), tokens.end(), columnHeader) - tokens.begin(); //found the column where the data can be found | ||
} | ||
if(line.find("GFX") != string::npos) | ||
{ | ||
tokens.clear(); | ||
sanitizeLine(line); | ||
tokenize(line, tokens, ' '); | ||
value = tokens.at(column); //fetch the value in the corresponding column | ||
} | ||
} | ||
procfile.close(); | ||
} | ||
else LOGERR("could not open file %s", PROC_BRCM_CORE_PATH); | ||
return value; | ||
} | ||
|
||
/** | ||
* parse_proc_brcm_display | ||
* | ||
* @brief : parse profs to obtain Graphics resolution details | ||
* @return : value | ||
*/ | ||
string parse_proc_brcm_display() | ||
{ | ||
LOGINFO(); | ||
|
||
ifstream procfile(PROC_BRCM_DISPLAY_PATH); | ||
string line, value; | ||
vector<string> tokens; | ||
if (procfile.is_open()) | ||
{ | ||
while (getline(procfile,line)) | ||
{ | ||
if(line.find("graphics") != string::npos) | ||
{ | ||
tokens.clear(); | ||
sanitizeLine(line); | ||
tokenize(line, tokens, ' '); | ||
if (tokens.size() >= GRAPHICS_RESOLUTION_LOC ) | ||
value = tokens.at(GRAPHICS_RESOLUTION_LOC); | ||
} | ||
} | ||
procfile.close(); | ||
} | ||
else LOGERR("could not open file %s", PROC_BRCM_DISPLAY_PATH); | ||
return value; | ||
} | ||
|
||
uint64_t SoC_GetTotalGpuRam() | ||
{ | ||
string value = parse_proc_brcm_core("MB"); | ||
uint64_t ret = 0; | ||
try | ||
{ | ||
ret = stoi(value) * 1024 * 1024; | ||
LOGINFO("total GPU ram returned from proc = %s MB", value.c_str()); | ||
} | ||
catch(...) | ||
{ | ||
LOGERR("Unable to process Total Gpu ram", value.c_str()); | ||
} | ||
return ret; | ||
} | ||
|
||
uint64_t SoC_GetFreeGpuRam() | ||
{ | ||
LOGINFO(); | ||
|
||
string value = parse_proc_brcm_core("used"); | ||
uint64_t ret = 0; | ||
int usedPercentage = 0; | ||
try | ||
{ | ||
usedPercentage = stoi(value); | ||
LOGINFO("percentage of GPU memory used = %s", value.c_str()); | ||
} | ||
catch(...) | ||
{ | ||
LOGERR("Unable to process Free Gpu ram", value.c_str()); | ||
} | ||
|
||
ret = (100 - usedPercentage) * 0.01 * SoC_GetTotalGpuRam(); | ||
return ret; | ||
} | ||
|
||
uint32_t SoC_GetGraphicsWidth() | ||
{ | ||
vector<string> resolution; | ||
uint32_t ret = 0; | ||
string value = parse_proc_brcm_display(); | ||
LOGINFO("graphics plane dimensions returned from proc = %s" , value.c_str()); | ||
tokenize(value, resolution, 'x'); // graphics resolution is in the format 1280x720 | ||
if(resolution.size() > WIDTH) | ||
{ | ||
try | ||
{ | ||
ret = stoi(resolution.at(WIDTH)); | ||
LOGINFO("graphics plane width = %d", ret); | ||
} | ||
catch(...) | ||
{ | ||
LOGERR("Unable to process gfx plane width"); | ||
} | ||
} | ||
|
||
return ret; | ||
} | ||
|
||
uint32_t SoC_GetGraphicsHeight() | ||
{ | ||
vector<string> resolution; | ||
uint32_t ret = 0; | ||
string value = parse_proc_brcm_display(); | ||
LOGINFO("graphics plane dimensions returned from proc = %s" , value.c_str()); | ||
tokenize(value, resolution, 'x'); // graphics resolution is in the format 1280x720 | ||
if(resolution.size() > HEIGHT) | ||
{ | ||
try | ||
{ | ||
ret = stoi(resolution.at(HEIGHT)); | ||
LOGINFO("graphics plane height = %d", ret); | ||
} | ||
catch(...) | ||
{ | ||
LOGERR("Unable to process gfx plane height"); | ||
} | ||
} | ||
return ret; | ||
} |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
/* | ||
* If not stated otherwise in this file or this component's LICENSE file the | ||
* following copyright and licenses apply: | ||
* | ||
* Copyright 2020 RDK Management | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
#include <string> | ||
#include <iostream> | ||
#include <vector> | ||
#include <cstring> | ||
#include <cstdio> | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <fcntl.h> | ||
#include "kms.h" | ||
|
||
#define MEM_PROCFS "/proc/meminfo" | ||
#define TOTAL_MEM_PARAM_STR "MemTotal:" | ||
#define FREE_MEM_PARAM_STR "MemFree:" | ||
#define DEFAULT_DEVICE "/dev/dri/card0" | ||
|
||
using namespace std; | ||
|
||
static uint64_t parseLine(const char * line); | ||
static uint64_t getMemInfo(const char * param); | ||
static void getPrimaryPlane(int drm_fd, kms_ctx *kms, drmModePlane **plane); | ||
static void getGraphicSize(uint32_t &w, uint32_t &h); | ||
|
||
static uint64_t parseLine(const char * line) | ||
{ | ||
string str(line); | ||
uint64_t val = 0; | ||
size_t begin = str.find_first_of("0123456789"); | ||
size_t end = string::npos; | ||
|
||
if (string::npos != begin) | ||
end = str.find_first_not_of("0123456789", begin); | ||
|
||
if (string::npos != begin && string::npos != end) | ||
{ | ||
|
||
str = str.substr(begin, end); | ||
val = strtoul(str.c_str(), NULL, 10); | ||
|
||
} | ||
else | ||
{ | ||
cout << "Failed to parse: " << line << endl; | ||
} | ||
|
||
return val; | ||
} | ||
|
||
static uint64_t getMemInfo(const char * param) | ||
{ | ||
FILE *meminfoFile = fopen(MEM_PROCFS, "r"); | ||
uint64_t memVal = 0; | ||
if (NULL == meminfoFile) | ||
{ | ||
cout << "Failed to open " << MEM_PROCFS << ", error: " << strerror(errno) << endl; | ||
} | ||
else | ||
{ | ||
vector <char> buf; | ||
buf.resize(1024); | ||
|
||
while (fgets(buf.data(), buf.size(), meminfoFile)) | ||
{ | ||
if ( strstr(buf.data(), param ) == buf.data()) | ||
{ | ||
memVal = parseLine(buf.data()) * 1000; | ||
break; | ||
} | ||
} | ||
|
||
fclose(meminfoFile); | ||
} | ||
return memVal; | ||
} | ||
|
||
static void getPrimaryPlane(int drm_fd, kms_ctx *kms, drmModePlane **plane) | ||
{ | ||
kms_get_plane(drm_fd, kms); | ||
cout << "Primary Plane ID : "<< kms->primary_plane_id << endl; | ||
*plane = drmModeGetPlane(drm_fd, kms->primary_plane_id ); | ||
if(*plane) | ||
printf("fb id : %d\n", (*plane)->fb_id); | ||
} | ||
|
||
static void getGraphicSize(uint32_t &w, uint32_t &h) | ||
{ | ||
int drm_fd; | ||
kms_ctx *kms = NULL; | ||
drmModePlane *plane = NULL; | ||
int trytimes = 0; | ||
|
||
do { | ||
/* Setup buffer information */ | ||
drm_fd = open( DEFAULT_DEVICE, O_RDWR); | ||
|
||
/* Setup KMS */ | ||
kms = kms_setup(drm_fd); | ||
if( !kms->crtc ) { | ||
cout << "[Realtek] kms_setup fail" << endl; | ||
break; | ||
} | ||
|
||
/* Get primary buffer */ | ||
getPrimaryPlane(drm_fd, kms, &plane); | ||
if( !plane) { | ||
cout << "[Realtek] fail to getPrimaryPlane" << endl; | ||
break; | ||
} | ||
|
||
/* get fb */ | ||
drmModeFB *fb = drmModeGetFB(drm_fd, plane->fb_id); | ||
while(!fb) { | ||
getPrimaryPlane(drm_fd, kms, &plane); | ||
fb = drmModeGetFB(drm_fd, plane->fb_id); | ||
if (trytimes++ > 100) { | ||
cout << "[Realtek] fail to getPrimaryPlane" << endl; | ||
break; | ||
} | ||
} | ||
|
||
/* Get the width and height */ | ||
if(fb) { | ||
w = fb->width; | ||
h = fb->height; | ||
drmModeFreeFB(fb); | ||
} | ||
} while(0); | ||
|
||
/* release */ | ||
/* Cleanup buffer info */ | ||
if(kms) { | ||
kms_cleanup_context(kms); | ||
free(kms); | ||
} | ||
|
||
cout << "[getGraphicSize] width : " << w << endl; | ||
cout << "[getGraphicSize] height : " << h << endl; | ||
} | ||
|
||
|
||
uint64_t SoC_GetTotalGpuRam() | ||
{ | ||
return getMemInfo(TOTAL_MEM_PARAM_STR); | ||
} | ||
|
||
uint64_t SoC_GetFreeGpuRam() | ||
{ | ||
return getMemInfo(FREE_MEM_PARAM_STR); | ||
} | ||
|
||
uint32_t SoC_GetGraphicsWidth() | ||
{ | ||
uint32_t w, h; | ||
getGraphicSize(w, h); | ||
return w; | ||
} | ||
|
||
uint32_t SoC_GetGraphicsHeight() | ||
{ | ||
uint32_t w, h; | ||
getGraphicSize(w, h); | ||
return h; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,211 @@ | ||
/* | ||
* If not stated otherwise in this file or this component's LICENSE file the | ||
* following copyright and licenses apply: | ||
* | ||
* Copyright 2020 RDK Management | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include <assert.h> | ||
#include <stddef.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include "kms.h" | ||
|
||
void kms_setup_encoder( int fd, kms_ctx *kms ) | ||
{ | ||
int crtcId = 0; | ||
|
||
for( int i = 0; i < kms->res->count_encoders; i++ ) { | ||
|
||
kms->encoder = drmModeGetEncoder(fd,kms->res->encoders[i]); | ||
|
||
if ( kms->encoder && ( kms->encoder->encoder_id == kms->connector->encoder_id ) ) { | ||
|
||
kms->encoder_id = kms->encoder->encoder_id; | ||
return; | ||
} | ||
|
||
|
||
for( int j = 0; j < kms->res->count_crtcs; j++ ) { | ||
|
||
if( kms->encoder->possible_crtcs & ( 1 << j ) ) { | ||
|
||
drmModeFreeEncoder( kms->encoder ); | ||
kms->encoder = drmModeGetEncoder(fd, kms->res->encoders[j]); | ||
|
||
crtcId = kms->res->crtcs[j]; | ||
kms->encoder->crtc_id = kms->crtc_id = j; | ||
goto exit; | ||
} | ||
} | ||
} | ||
|
||
exit: | ||
return; | ||
} | ||
|
||
|
||
|
||
|
||
void kms_setup_connector( int fd, kms_ctx *kms ) | ||
{ | ||
int i = 0, j = 0; | ||
drmModeConnector *connector; | ||
|
||
for( i = 0; i < kms->res->count_connectors; i++ ) { | ||
|
||
connector = drmModeGetConnector(fd, kms->res->connectors[i]); | ||
if( connector ) { | ||
|
||
if( connector->count_modes && ( connector->connection == DRM_MODE_CONNECTED ) ) { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
if ( connector ) { | ||
|
||
kms->connector = connector; | ||
kms->connector_id = connector->connector_id; | ||
} | ||
|
||
return; | ||
} | ||
|
||
|
||
void kms_setup_crtc( int fd, kms_ctx *kms ) | ||
{ | ||
if( kms->encoder ) { | ||
|
||
kms->crtc = drmModeGetCrtc(fd, kms->encoder->crtc_id); | ||
|
||
if( kms->crtc && kms->crtc->mode_valid ) { | ||
|
||
kms->current_info = kms->crtc->mode; | ||
kms->crtc_id = kms->encoder->crtc_id; | ||
} | ||
} | ||
|
||
return; | ||
} | ||
|
||
|
||
kms_ctx* kms_setup( int fd ) | ||
{ | ||
kms_ctx *kms = NULL; | ||
kms = (kms_ctx*)calloc(1,sizeof(*kms)); | ||
if( !kms ) | ||
assert(0); | ||
|
||
kms->res = drmModeGetResources(fd); | ||
|
||
kms_setup_connector(fd, kms); | ||
kms_setup_encoder(fd, kms); | ||
kms_setup_crtc(fd, kms); | ||
return kms; | ||
} | ||
|
||
|
||
void kms_cleanup_context( kms_ctx *kms ) | ||
{ | ||
if( kms->connector ) | ||
drmModeFreeConnector(kms->connector); | ||
|
||
if( kms->encoder ) | ||
drmModeFreeEncoder(kms->encoder); | ||
|
||
if( kms->crtc ) | ||
drmModeFreeCrtc(kms->crtc); | ||
|
||
if( kms->res ) | ||
drmModeFreeResources(kms->res); | ||
} | ||
|
||
|
||
uint32_t kms_get_properties(int fd, drmModeObjectProperties *props, const char *name) | ||
{ | ||
drmModePropertyPtr property; | ||
uint32_t i, id = 0; | ||
|
||
for (i = 0; i < props->count_props; i++) { | ||
|
||
property = drmModeGetProperty(fd, props->props[i]); | ||
if (!strcmp(property->name, name)) | ||
id = property->prop_id; | ||
|
||
drmModeFreeProperty(property); | ||
|
||
if ( id ) | ||
return id; | ||
} | ||
} | ||
|
||
|
||
|
||
void kms_get_plane( int fd, kms_ctx *kms ) | ||
{ | ||
int len = 0, n = 0, j = 0, plane_index = -1; | ||
|
||
drmModePlane *plane = NULL; | ||
drmModePlaneRes *planeRes = NULL; | ||
drmModePropertyRes *prop = NULL; | ||
drmModeObjectProperties *props = NULL; | ||
|
||
drmSetClientCap(fd, DRM_CLIENT_CAP_UNIVERSAL_PLANES, 1); | ||
|
||
kms->primary_plane_id = kms->overlay_plane_id = -1; | ||
|
||
planeRes = drmModeGetPlaneResources( fd ); | ||
if ( planeRes ) { | ||
|
||
for( n= 0; n < planeRes->count_planes; ++n ) { | ||
|
||
plane = drmModeGetPlane( fd, planeRes->planes[n] ); | ||
|
||
if ( plane ) { | ||
|
||
props = drmModeObjectGetProperties( fd, planeRes->planes[n], DRM_MODE_OBJECT_PLANE ); | ||
if ( props ) { | ||
|
||
for( j= 0; j < props->count_props; ++j ) { | ||
|
||
prop = drmModeGetProperty( fd, props->props[j] ); | ||
if ( prop ) { | ||
|
||
len = strlen(prop->name); | ||
if ( !strcmp( prop->name, "type") ) { | ||
|
||
if ( ( props->prop_values[j] == DRM_PLANE_TYPE_PRIMARY ) && ( kms->primary_plane_id == -1 ) ) | ||
kms->primary_plane_id = planeRes->planes[n]; | ||
|
||
else if ( ( props->prop_values[j] == DRM_PLANE_TYPE_OVERLAY ) && ( kms->overlay_plane_id == -1 ) ) | ||
kms->overlay_plane_id = planeRes->planes[n]; | ||
} | ||
} | ||
|
||
drmModeFreeProperty( prop ); | ||
} | ||
} | ||
|
||
drmModeFreeObjectProperties( props ); | ||
} | ||
|
||
drmModeFreePlane( plane ); | ||
} | ||
|
||
} | ||
|
||
drmModeFreePlaneResources( planeRes ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* | ||
* If not stated otherwise in this file or this component's LICENSE file the | ||
* following copyright and licenses apply: | ||
* | ||
* Copyright 2020 RDK Management | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#ifndef __DRM_KMS_H__ | ||
#define __DRM_KMS_H__ | ||
|
||
#include <xf86drm.h> | ||
#include <xf86drmMode.h> | ||
#include <drm_mode.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef struct _kms_ctx { | ||
|
||
drmModeRes *res; | ||
drmModeConnector *connector; | ||
drmModeEncoder *encoder; | ||
drmModeCrtc *crtc; | ||
|
||
drmModeCrtc *previous_crtc; | ||
drmModeModeInfo current_info; | ||
|
||
uint32_t connector_id; /**< Connector id which will be use in program */ | ||
uint32_t crtc_id; | ||
uint32_t encoder_id; | ||
uint32_t primary_plane_id; | ||
uint32_t overlay_plane_id; | ||
|
||
/* atomic properties */ | ||
uint32_t active_property; | ||
uint32_t mode_id_property; | ||
uint32_t crtc_id_property; | ||
uint32_t blob_id; | ||
|
||
uint32_t fb_id_property; | ||
uint32_t crtc_x_property; | ||
uint32_t crtc_y_property; | ||
uint32_t crtc_h_property; | ||
uint32_t crtc_w_property; | ||
uint32_t src_x_property; | ||
uint32_t src_y_property; | ||
uint32_t src_w_property; | ||
uint32_t src_h_property; | ||
|
||
drmModeAtomicReq *req; | ||
|
||
} kms_ctx; | ||
|
||
/** | ||
* @brief Create kms context | ||
* | ||
* @param[in] fd drm file descriptor | ||
* | ||
* | ||
* @retval kms context | ||
*/ | ||
kms_ctx* kms_setup(int fd); | ||
|
||
|
||
|
||
/** | ||
* @brief Cleanup kms context | ||
* | ||
* @param[in] kms kms context | ||
* | ||
*/ | ||
void kms_cleanup_context(kms_ctx *kms); | ||
|
||
/** | ||
* @brief Set and get possible encoder id | ||
* | ||
* @param[in] fd drm file descriptor | ||
* @param[in] kms kms context | ||
* | ||
*/ | ||
void kms_setup_encoder(int fd, kms_ctx *kms); | ||
|
||
|
||
/** | ||
* @brief Set and get possible connector id | ||
* | ||
* @param[in] fd drm file descriptor | ||
* @para,[in] kms kms context | ||
* | ||
*/ | ||
void kms_setup_connector(int fd, kms_ctx *kms); | ||
|
||
/** | ||
* @brief Set and get possible crtc id | ||
* | ||
* @param[in] fd drm file descriptor | ||
* @param[in] kms kms context | ||
* | ||
*/ | ||
void kms_setup_crtc(int fd, kms_ctx *kms); | ||
|
||
/** | ||
* @brief Get the specific object properties | ||
* | ||
* @param[in] fd drm file descriptor | ||
* @param[in] props all object properties | ||
* @param[in] name the property name which want to be queried | ||
* | ||
*/ | ||
uint32_t kms_get_properties(int fd, drmModeObjectProperties *props, const char *name); | ||
|
||
|
||
/** | ||
* @brief Get primary and overlay plane. | ||
* The plane id will set to -1 if cannot get. | ||
* | ||
* @param[in] fd drm file descriptor | ||
* @param[in] kms kms context | ||
* | ||
*/ | ||
void kms_get_plane( int fd, kms_ctx *kms); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.