Skip to content

Commit 8ede384

Browse files
committed
AVInput COM-RPC Support: WIP
1 parent 5fce3c9 commit 8ede384

File tree

6 files changed

+191
-90
lines changed

6 files changed

+191
-90
lines changed

AVInput/AVInput.cpp

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
// because it requires optional parameters which are not supported in Thunder 4.x. This can
3333
// be refactored after migrating to 5.x.
3434
#define AVINPUT_METHOD_GET_INPUT_DEVICES "getInputDevices"
35-
#define HDMI 0
36-
#define COMPOSITE 1
3735

3836
namespace WPEFramework {
3937
namespace {
@@ -169,10 +167,10 @@ namespace Plugin {
169167
try
170168
{
171169
int num = 0;
172-
if (iType == HDMI) {
170+
if (iType == INPUT_TYPE_STRING_HDMI) {
173171
num = device::HdmiInput::getInstance().getNumberOfInputs();
174172
}
175-
else if (iType == COMPOSITE) {
173+
else if (iType == INPUT_TYPE_STRING_COMPOSITE) {
176174
num = device::CompositeInput::getInstance().getNumberOfInputs();
177175
}
178176
if (num > 0) {
@@ -182,11 +180,11 @@ namespace Plugin {
182180
JsonObject hash;
183181
hash["id"] = i;
184182
std::stringstream locator;
185-
if (iType == HDMI) {
183+
if (iType == INPUT_TYPE_STRING_HDMI) {
186184
locator << "hdmiin://localhost/deviceid/" << i;
187185
hash["connected"] = device::HdmiInput::getInstance().isPortConnected(i);
188186
}
189-
else if (iType == COMPOSITE) {
187+
else if (iType == INPUT_TYPE_STRING_COMPOSITE) {
190188
locator << "cvbsin://localhost/deviceid/" << i;
191189
hash["connected"] = device::CompositeInput::getInstance().isPortConnected(i);
192190
}
@@ -202,18 +200,6 @@ namespace Plugin {
202200
return list;
203201
}
204202

205-
int getTypeOfInput(string sType)
206-
{
207-
int iType = -1;
208-
if (strcmp(sType.c_str(), "HDMI") == 0)
209-
iType = HDMI;
210-
else if (strcmp(sType.c_str(), "COMPOSITE") == 0)
211-
iType = COMPOSITE;
212-
else
213-
throw "Invalide type of INPUT, please specify HDMI/COMPOSITE";
214-
return iType;
215-
}
216-
217203
uint32_t AVInput::getInputDevicesWrapper(const JsonObject& parameters, JsonObject& response)
218204
{
219205
LOGINFOMETHOD();
@@ -222,16 +208,16 @@ namespace Plugin {
222208
string sType = parameters["typeOfInput"].String();
223209
int iType = 0;
224210
try {
225-
iType = getTypeOfInput (sType);
211+
iType = AVInputUtils::getTypeOfInput(sType);
226212
}catch (...) {
227213
LOGWARN("Invalid Arguments");
228214
returnResponse(false);
229215
}
230216
response["devices"] = getInputDevices(iType);
231217
}
232218
else {
233-
JsonArray listHdmi = getInputDevices(HDMI);
234-
JsonArray listComposite = getInputDevices(COMPOSITE);
219+
JsonArray listHdmi = getInputDevices(INPUT_TYPE_STRING_HDMI);
220+
JsonArray listComposite = getInputDevices(INPUT_TYPE_STRING_COMPOSITE);
235221
for (int i = 0; i < listComposite.Length(); i++) {
236222
listHdmi.Add(listComposite.Get(i));
237223
}

AVInput/AVInput.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <interfaces/json/JAVInput.h>
2727
#include <interfaces/json/JsonData_AVInput.h>
2828
#include "AVInputJsonData.h"
29+
#include "AVInputUtils.h"
2930

3031
#include "UtilsLogging.h"
3132
#include "tracing/Logging.h"

AVInput/AVInputImplementation.cpp

Lines changed: 97 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,12 @@ namespace Plugin {
175175
int hdmiin_hotplug_port = eventData->data.hdmi_in_connect.port;
176176
int hdmiin_hotplug_conn = eventData->data.hdmi_in_connect.isPortConnected;
177177
LOGWARN("Received IARM_BUS_DSMGR_EVENT_HDMI_IN_HOTPLUG event data:%d", hdmiin_hotplug_port);
178-
AVInputImplementation::_instance->AVInputHotplug(hdmiin_hotplug_port, hdmiin_hotplug_conn ? AV_HOT_PLUG_EVENT_CONNECTED : AV_HOT_PLUG_EVENT_DISCONNECTED, HDMI);
178+
AVInputImplementation::_instance->AVInputHotplug(hdmiin_hotplug_port, hdmiin_hotplug_conn ? AV_HOT_PLUG_EVENT_CONNECTED : AV_HOT_PLUG_EVENT_DISCONNECTED, INPUT_TYPE_INT_HDMI);
179179
} else if (IARM_BUS_DSMGR_EVENT_COMPOSITE_IN_HOTPLUG == eventId) {
180180
int compositein_hotplug_port = eventData->data.composite_in_connect.port;
181181
int compositein_hotplug_conn = eventData->data.composite_in_connect.isPortConnected;
182182
LOGWARN("Received IARM_BUS_DSMGR_EVENT_COMPOSITE_IN_HOTPLUG event data:%d", compositein_hotplug_port);
183-
AVInputImplementation::_instance->AVInputHotplug(compositein_hotplug_port, compositein_hotplug_conn ? AV_HOT_PLUG_EVENT_CONNECTED : AV_HOT_PLUG_EVENT_DISCONNECTED, COMPOSITE);
183+
AVInputImplementation::_instance->AVInputHotplug(compositein_hotplug_port, compositein_hotplug_conn ? AV_HOT_PLUG_EVENT_CONNECTED : AV_HOT_PLUG_EVENT_DISCONNECTED, INPUT_TYPE_INT_COMPOSITE);
184184
}
185185
}
186186

@@ -193,12 +193,12 @@ namespace Plugin {
193193
int hdmi_in_port = eventData->data.hdmi_in_sig_status.port;
194194
int hdmi_in_signal_status = eventData->data.hdmi_in_sig_status.status;
195195
LOGWARN("Received IARM_BUS_DSMGR_EVENT_HDMI_IN_SIGNAL_STATUS event port: %d, signal status: %d", hdmi_in_port, hdmi_in_signal_status);
196-
AVInputImplementation::_instance->AVInputSignalChange(hdmi_in_port, hdmi_in_signal_status, HDMI);
196+
AVInputImplementation::_instance->AVInputSignalChange(hdmi_in_port, hdmi_in_signal_status, INPUT_TYPE_INT_HDMI);
197197
} else if (IARM_BUS_DSMGR_EVENT_COMPOSITE_IN_SIGNAL_STATUS == eventId) {
198198
int composite_in_port = eventData->data.composite_in_sig_status.port;
199199
int composite_in_signal_status = eventData->data.composite_in_sig_status.status;
200200
LOGWARN("Received IARM_BUS_DSMGR_EVENT_COMPOSITE_IN_SIGNAL_STATUS event port: %d, signal status: %d", composite_in_port, composite_in_signal_status);
201-
AVInputImplementation::_instance->AVInputSignalChange(composite_in_port, composite_in_signal_status, COMPOSITE);
201+
AVInputImplementation::_instance->AVInputSignalChange(composite_in_port, composite_in_signal_status, INPUT_TYPE_INT_COMPOSITE);
202202
}
203203
}
204204

@@ -211,12 +211,12 @@ namespace Plugin {
211211
int hdmi_in_port = eventData->data.hdmi_in_status.port;
212212
bool hdmi_in_status = eventData->data.hdmi_in_status.isPresented;
213213
LOGWARN("Received IARM_BUS_DSMGR_EVENT_HDMI_IN_STATUS event port: %d, started: %d", hdmi_in_port, hdmi_in_status);
214-
AVInputImplementation::_instance->AVInputStatusChange(hdmi_in_port, hdmi_in_status, HDMI);
214+
AVInputImplementation::_instance->AVInputStatusChange(hdmi_in_port, hdmi_in_status, INPUT_TYPE_INT_HDMI);
215215
} else if (IARM_BUS_DSMGR_EVENT_COMPOSITE_IN_STATUS == eventId) {
216216
int composite_in_port = eventData->data.composite_in_status.port;
217217
bool composite_in_status = eventData->data.composite_in_status.isPresented;
218218
LOGWARN("Received IARM_BUS_DSMGR_EVENT_COMPOSITE_IN_STATUS event port: %d, started: %d", composite_in_port, composite_in_status);
219-
AVInputImplementation::_instance->AVInputStatusChange(composite_in_port, composite_in_status, COMPOSITE);
219+
AVInputImplementation::_instance->AVInputStatusChange(composite_in_port, composite_in_status, INPUT_TYPE_INT_COMPOSITE);
220220
}
221221
}
222222

@@ -233,7 +233,7 @@ namespace Plugin {
233233
resolution.interlaced = eventData->data.hdmi_in_video_mode.resolution.interlaced;
234234
resolution.frameRate = eventData->data.hdmi_in_video_mode.resolution.frameRate;
235235
LOGWARN("Received IARM_BUS_DSMGR_EVENT_HDMI_IN_VIDEO_MODE_UPDATE event port: %d, pixelResolution: %d, interlaced : %d, frameRate: %d \n", hdmi_in_port, resolution.pixelResolution, resolution.interlaced, resolution.frameRate);
236-
AVInputImplementation::_instance->AVInputVideoModeUpdate(hdmi_in_port, resolution, HDMI);
236+
AVInputImplementation::_instance->AVInputVideoModeUpdate(hdmi_in_port, resolution, INPUT_TYPE_INT_HDMI);
237237
} else if (IARM_BUS_DSMGR_EVENT_COMPOSITE_IN_VIDEO_MODE_UPDATE == eventId) {
238238
IARM_Bus_DSMgr_EventData_t* eventData = (IARM_Bus_DSMgr_EventData_t*)data;
239239
int composite_in_port = eventData->data.composite_in_video_mode.port;
@@ -242,7 +242,7 @@ namespace Plugin {
242242
resolution.interlaced = eventData->data.composite_in_video_mode.resolution.interlaced;
243243
resolution.frameRate = eventData->data.composite_in_video_mode.resolution.frameRate;
244244
LOGWARN("Received IARM_BUS_DSMGR_EVENT_COMPOSITE_IN_VIDEO_MODE_UPDATE event port: %d, pixelResolution: %d, interlaced : %d, frameRate: %d \n", composite_in_port, resolution.pixelResolution, resolution.interlaced, resolution.frameRate);
245-
AVInputImplementation::_instance->AVInputVideoModeUpdate(composite_in_port, resolution, COMPOSITE);
245+
AVInputImplementation::_instance->AVInputVideoModeUpdate(composite_in_port, resolution, INPUT_TYPE_INT_COMPOSITE);
246246
}
247247
}
248248

@@ -567,17 +567,21 @@ namespace Plugin {
567567
}
568568

569569
try {
570-
if (strcmp(typeOfInput.c_str(), INPUT_TYPE_HDMI) == 0) {
571-
device::HdmiInput::getInstance().selectPort(id, requestAudioMix, plane, topMost);
572-
} else if (strcmp(typeOfInput.c_str(), INPUT_TYPE_COMPOSITE) == 0) {
573-
device::CompositeInput::getInstance().selectPort(id);
574-
} else {
575-
LOGWARN("Invalid input type passed to StartInput");
576-
successResult.success = false;
577-
return Core::ERROR_GENERAL;
570+
switch(AVInputUtils::getTypeOfInput(typeOfInput)) {
571+
case INPUT_TYPE_INT_HDMI: {
572+
device::HdmiInput::getInstance().selectPort(id, requestAudioMix, plane, topMost);
573+
break;
574+
}
575+
case INPUT_TYPE_INT_COMPOSITE: {
576+
device::CompositeInput::getInstance().selectPort(id);
577+
}
578+
default: {
579+
LOGWARN("Invalid input type passed to StartInput");
580+
successResult.success = false;
581+
return Core::ERROR_GENERAL;
582+
}
578583
}
579-
} catch (const device::Exception& err) {
580-
LOG_DEVICE_EXCEPTION1(std::to_string(id));
584+
} catch(...) {
581585
successResult.success = false;
582586
return Core::ERROR_GENERAL;
583587
}
@@ -598,14 +602,20 @@ namespace Plugin {
598602
device::Host::getInstance().setAudioMixerLevels(dsAUDIO_INPUT_SYSTEM, DEFAULT_INPUT_VOL_LEVEL);
599603
isAudioBalanceSet = false;
600604
}
601-
if (strcmp(typeOfInput.c_str(), INPUT_TYPE_HDMI) == 0) {
602-
device::HdmiInput::getInstance().selectPort(-1);
603-
} else if (strcmp(typeOfInput.c_str(), INPUT_TYPE_COMPOSITE) == 0) {
604-
device::CompositeInput::getInstance().selectPort(-1);
605-
} else {
606-
LOGWARN("Invalid input type passed to StopInput");
607-
successResult.success = false;
608-
ret = Core::ERROR_GENERAL;
605+
606+
switch(AVInputUtils::getTypeOfInput(typeOfInput)) {
607+
case INPUT_TYPE_INT_HDMI: {
608+
device::HdmiInput::getInstance().selectPort(-1);
609+
break;
610+
}
611+
case INPUT_TYPE_INT_COMPOSITE: {
612+
device::CompositeInput::getInstance().selectPort(-1);
613+
}
614+
default: {
615+
LOGWARN("Invalid input type passed to StopInput");
616+
successResult.success = false;
617+
return Core::ERROR_GENERAL;
618+
}
609619
}
610620
} catch (const device::Exception& err) {
611621
LOGWARN("AVInputImplementation::StopInput Failed");
@@ -619,12 +629,20 @@ namespace Plugin {
619629
Core::hresult AVInputImplementation::SetVideoRectangle(const uint16_t x, const uint16_t y, const uint16_t w, const uint16_t h, const string& typeOfInput, SuccessResult& successResult)
620630
{
621631
try {
622-
if (strcmp(typeOfInput.c_str(), INPUT_TYPE_HDMI) == 0) {
623-
device::HdmiInput::getInstance().scaleVideo(x, y, w, h);
624-
} else {
625-
device::CompositeInput::getInstance().scaleVideo(x, y, w, h);
632+
switch(AVInputUtils::getTypeOfInput(typeOfInput)) {
633+
case INPUT_TYPE_INT_HDMI: {
634+
device::HdmiInput::getInstance().scaleVideo(x, y, w, h);
635+
break;
636+
}
637+
case INPUT_TYPE_INT_COMPOSITE: {
638+
device::CompositeInput::getInstance().scaleVideo(x, y, w, h);
639+
}
640+
default: {
641+
successResult.success = false;
642+
return Core::ERROR_GENERAL;
643+
}
626644
}
627-
} catch (const device::Exception& err) {
645+
} catch(...) {
628646
successResult.success = false;
629647
return Core::ERROR_GENERAL;
630648
}
@@ -639,14 +657,20 @@ namespace Plugin {
639657
bool isHdmi = true;
640658

641659
try {
642-
if (strcmp(typeOfInput.c_str(), INPUT_TYPE_HDMI) == 0) {
643-
num = device::HdmiInput::getInstance().getNumberOfInputs();
644-
} else if (strcmp(typeOfInput.c_str(), INPUT_TYPE_COMPOSITE) == 0) {
645-
num = device::CompositeInput::getInstance().getNumberOfInputs();
646-
isHdmi = false;
647-
} else {
648-
LOGERR("getInputDevices: Invalid input type");
649-
return Core::ERROR_GENERAL;
660+
switch(AVInputUtils::getTypeOfInput(typeOfInput)) {
661+
case INPUT_TYPE_INT_HDMI: {
662+
num = device::HdmiInput::getInstance().getNumberOfInputs();
663+
break;
664+
}
665+
case INPUT_TYPE_INT_COMPOSITE: {
666+
num = device::CompositeInput::getInstance().getNumberOfInputs();
667+
isHdmi = false;
668+
}
669+
default: {
670+
LOGERR("getInputDevices: Invalid input type");
671+
successResult.success = false;
672+
return Core::ERROR_GENERAL;
673+
}
650674
}
651675

652676
if (num > 0) {
@@ -683,15 +707,25 @@ namespace Plugin {
683707
std::list<WPEFramework::Exchange::IAVInput::InputDevice> inputDeviceList;
684708
success = false;
685709

686-
if(strcmp(typeOfInput.c_str(), INPUT_TYPE_ALL) == 0) {
687-
result = getInputDevices(INPUT_TYPE_HDMI, inputDeviceList);
688-
if (result == Core::ERROR_NONE) {
689-
result = getInputDevices(INPUT_TYPE_COMPOSITE, inputDeviceList);
710+
try {
711+
switch(AVInputUtils::getTypeOfInput(typeOfInput)) {
712+
case INPUT_TYPE_INT_ALL: {
713+
result = getInputDevices(INPUT_TYPE_HDMI, inputDeviceList);
714+
if(result == Core::ERROR_NONE) {
715+
result = getInputDevices(INPUT_TYPE_COMPOSITE, inputDeviceList);
716+
}
717+
break;
718+
}
719+
case INPUT_TYPE_INT_HDMI:
720+
case INPUT_TYPE_INT_COMPOSITE: {
721+
result = getInputDevices(typeOfInput, inputDeviceList);
722+
}
723+
default: {
724+
LOGERR("GetInputDevices: Invalid input type");
725+
return Core::ERROR_GENERAL;
726+
}
690727
}
691-
} else if((strcmp(typeOfInput.c_str(), INPUT_TYPE_HDMI) == 0) || (strcmp(typeOfInput.c_str(), INPUT_TYPE_COMPOSITE) == 0)) {
692-
result = getInputDevices(typeOfInput, inputDeviceList);
693-
} else {
694-
LOGERR("GetInputDevices: Invalid input type");
728+
} catch(...) {
695729
return Core::ERROR_GENERAL;
696730
}
697731

@@ -742,6 +776,11 @@ namespace Plugin {
742776
// convert to base64
743777
uint16_t size = min(edidVec.size(), (size_t)numeric_limits<uint16_t>::max());
744778

779+
if(0 == size) {
780+
success = false;
781+
return Core::ERROR_GENERAL;
782+
}
783+
745784
LOGWARN("AVInputImplementation::readEDID size:%d edidVec.size:%zu", size, edidVec.size());
746785
if (edidVec.size() > (size_t)numeric_limits<uint16_t>::max()) {
747786
LOGERR("Size too large to use ToString base64 wpe api");
@@ -774,19 +813,12 @@ namespace Plugin {
774813
bool success;
775814

776815
string typeOfInput;
777-
switch(type) {
778-
case HDMI:
779-
typeOfInput = INPUT_TYPE_HDMI;
780-
break;
781-
case COMPOSITE:
782-
typeOfInput = INPUT_TYPE_COMPOSITE;
783-
break;
784-
case ALL:
785-
typeOfInput = INPUT_TYPE_ALL;
786-
break;
787-
default:
788-
LOGERR("AVInputHotplug: Invalid input type");
789-
return;
816+
817+
try {
818+
typeOfInput = AVInputUtils::getTypeOfInput(type);
819+
} catch(...) {
820+
LOGERR("AVInputHotplug: Invalid input type");
821+
return;
790822
}
791823

792824
Core::hresult result = GetInputDevices(typeOfInput, devices, success);
@@ -814,7 +846,7 @@ namespace Plugin {
814846
string signalStatusStr;
815847

816848
std::stringstream locator;
817-
if (type == HDMI) {
849+
if (type == INPUT_TYPE_INT_HDMI) {
818850
locator << "hdmiin://localhost/deviceid/" << port;
819851
} else {
820852
locator << "cvbsin://localhost/deviceid/" << port;
@@ -862,9 +894,9 @@ namespace Plugin {
862894

863895
std::stringstream locator;
864896

865-
if (type == HDMI) {
897+
if (type == INPUT_TYPE_INT_HDMI) {
866898
locator << "hdmiin://localhost/deviceid/" << port;
867-
} else if (type == COMPOSITE) {
899+
} else if (type == INPUT_TYPE_INT_COMPOSITE) {
868900
locator << "cvbsin://localhost/deviceid/" << port;
869901
}
870902

@@ -893,7 +925,7 @@ namespace Plugin {
893925

894926
LOGWARN("AVInputVideoModeUpdate [%d]", port);
895927

896-
if (type == HDMI) {
928+
if (type == INPUT_TYPE_INT_HDMI) {
897929
locator << "hdmiin://localhost/deviceid/" << port;
898930

899931
switch (resolution.pixelResolution) {
@@ -936,7 +968,7 @@ namespace Plugin {
936968

937969
progressive = (!resolution.interlaced);
938970

939-
} else if (type == COMPOSITE) {
971+
} else if (type == INPUT_TYPE_INT_COMPOSITE) {
940972
locator << "cvbsin://localhost/deviceid/" << port;
941973

942974
switch (resolution.pixelResolution) {

AVInput/AVInputImplementation.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@
4040
#include <com/com.h>
4141
#include <core/core.h>
4242

43+
#include "AVInputUtils.h"
44+
4345
#define DEFAULT_PRIM_VOL_LEVEL 25
4446
#define MAX_PRIM_VOL_LEVEL 100
4547
#define DEFAULT_INPUT_VOL_LEVEL 100
4648

47-
#define ALL -1
48-
#define HDMI 0
49-
#define COMPOSITE 1
50-
5149
using ParamsType = boost::variant<
5250
WPEFramework::Exchange::IAVInput::IInputDeviceIterator* const, // OnDevicesChanged
5351
std::tuple<int, string, string>, // OnSignalChanged

0 commit comments

Comments
 (0)