[PlayerUtil] Plugin implementation. 43/83543/5
authorPiotr Kosko <p.kosko@samsung.com>
Thu, 11 Aug 2016 10:30:50 +0000 (12:30 +0200)
committerHyunjin Park <hj.na.park@samsung.com>
Mon, 26 Sep 2016 10:39:18 +0000 (19:39 +0900)
[Verification] Code compiles. Plugin is seen.
Getting and setting latency works correctly.

Change-Id: I567860a26327e8da911796c30e1ef8f2478c3dd8
Signed-off-by: Piotr Kosko <p.kosko@samsung.com>
packaging/webapi-plugins.spec
src/playerutil/playerutil.gyp [new file with mode: 0644]
src/playerutil/playerutil_api.js [new file with mode: 0644]
src/playerutil/playerutil_extension.cc [new file with mode: 0644]
src/playerutil/playerutil_extension.h [new file with mode: 0644]
src/playerutil/playerutil_instance.cc [new file with mode: 0644]
src/playerutil/playerutil_instance.h [new file with mode: 0644]
src/playerutil/playerutil_utils.cc [new file with mode: 0644]
src/playerutil/playerutil_utils.h [new file with mode: 0644]
src/tizen-wrt.gyp

index b9615121d4f5fd2cfe96cb5b379496ea83ae3962..f26ed42e98df40eed1c7c5027e31a5e3f145ebcf 100644 (file)
@@ -62,6 +62,7 @@ Source0:    %{name}-%{version}.tar.gz
 %define tizen_feature_nfc_support                     0
 %define tizen_feature_notification_support            0
 %define tizen_feature_package_support                 1
+%define tizen_feature_player_util_support             0
 %define tizen_feature_power_support                   0
 %define tizen_feature_preference_support              0
 %define tizen_feature_push_support                    0
@@ -137,6 +138,7 @@ Source0:    %{name}-%{version}.tar.gz
 #%endif
 %define tizen_feature_notification_support            1
 %define tizen_feature_package_support                 1
+%define tizen_feature_player_util_support             1
 %define tizen_feature_power_support                   1
 %define tizen_feature_preference_support              1
 %define tizen_feature_push_support                    1
@@ -241,6 +243,7 @@ Source0:    %{name}-%{version}.tar.gz
 %define tizen_feature_nfc_support                     1
 %define tizen_feature_notification_support            1
 %define tizen_feature_package_support                 1
+%define tizen_feature_player_util_support             1
 %define tizen_feature_power_support                   1
 %define tizen_feature_preference_support              1
 %define tizen_feature_push_support                    1
@@ -322,6 +325,7 @@ Source0:    %{name}-%{version}.tar.gz
 %define tizen_feature_nfc_support                     0
 %define tizen_feature_notification_support            0
 %define tizen_feature_package_support                 1
+%define tizen_feature_player_util_support             0
 %define tizen_feature_power_support                   0
 %define tizen_feature_preference_support              0
 %define tizen_feature_push_support                    0
@@ -430,6 +434,10 @@ BuildRequires: pkgconfig(sensor)
 BuildRequires: pkgconfig(iotcon)
 %endif
 
+%if 0%{?tizen_feature_player_util_support}
+BuildRequires: pkgconfig(chromium-efl)
+%endif
+
 %if 0%{?tizen_feature_power_support}
 BuildRequires: pkgconfig(deviced)
 %endif
@@ -576,6 +584,7 @@ GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_nfc_emulation_support=%{?tizen_feature
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_nfc_support=%{?tizen_feature_nfc_support}"
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_notification_support=%{?tizen_feature_notification_support}"
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_package_support=%{?tizen_feature_package_support}"
+GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_player_util_support=%{?tizen_feature_player_util_support}"
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_power_support=%{?tizen_feature_power_support}"
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_preference_support=%{?tizen_feature_preference_support}"
 GYP_OPTIONS="$GYP_OPTIONS -Dtizen_feature_push_support=%{?tizen_feature_push_support}"
diff --git a/src/playerutil/playerutil.gyp b/src/playerutil/playerutil.gyp
new file mode 100644 (file)
index 0000000..e1fe9e8
--- /dev/null
@@ -0,0 +1,37 @@
+{
+  'includes':[
+    '../common/common.gypi',
+  ],
+  'targets': [
+    {
+      'target_name': 'tizen_playerutil',
+      'type': 'loadable_module',
+      'dependencies': [
+        '../common/common.gyp:tizen_common',
+      ],
+      'sources': [
+        'playerutil_api.js',
+        'playerutil_extension.cc',
+        'playerutil_extension.h',
+        'playerutil_instance.cc',
+        'playerutil_instance.h',
+        'playerutil_utils.cc',
+        'playerutil_utils.h',
+      ],
+      'includes': [
+        '../common/pkg-config.gypi',
+      ],
+      'conditions': [
+        ['tizen == 1', {
+          'variables': {
+            'packages': [
+              'chromium-efl',
+              'eina',
+              'evas'
+            ]
+          },
+        }],
+      ],
+    },
+  ],
+}
diff --git a/src/playerutil/playerutil_api.js b/src/playerutil/playerutil_api.js
new file mode 100644 (file)
index 0000000..41ca4ab
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    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.
+ */
+
+var native = new xwalk.utils.NativeManager(extension);
+var validator = xwalk.utils.validator;
+var types = validator.Types;
+var T = xwalk.utils.type;
+
+var LatencyMode = {
+  LOW: 'LOW',
+  MID: 'MID',
+  HIGH: 'HIGH',
+};
+
+function PlayerUtil() {
+}
+
+PlayerUtil.prototype.getLatencyMode = function() {
+  var result = native.callSync('PlayerUtil_getLatencyMode', {});
+
+  if (native.isSuccess(result)) {
+    return native.getResultObject(result);
+  } else {
+    throw native.getErrorObject(result);
+  }
+};
+
+PlayerUtil.prototype.setLatencyMode = function() {
+  var args = validator.validateMethod(arguments, [{
+    name: 'latencyMode',
+    type: types.ENUM,
+    values: T.getValues(LatencyMode)
+  }]);
+
+  var callArgs = {};
+  callArgs.latencyMode = args.latencyMode;
+
+  var result = native.callSync('PlayerUtil_setLatencyMode', callArgs);
+
+  if (native.isFailure(result)) {
+    throw native.getErrorObject(result);
+  }
+};
+
+// Exports
+exports = new PlayerUtil();
diff --git a/src/playerutil/playerutil_extension.cc b/src/playerutil/playerutil_extension.cc
new file mode 100644 (file)
index 0000000..a358fa4
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    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 "playerutil/playerutil_extension.h"
+
+#include "playerutil/playerutil_instance.h"
+
+// This will be generated from playerutil_api.js
+extern const char kSource_playerutil_api[];
+
+namespace extension {
+namespace playerutil {
+
+PlayerUtilExtension::PlayerUtilExtension() {
+  SetExtensionName("tizen.playerutil");
+  SetJavaScriptAPI(kSource_playerutil_api);
+
+  const char* entry_points[] = {
+    nullptr
+  };
+  SetExtraJSEntryPoints(entry_points);
+}
+
+PlayerUtilExtension::~PlayerUtilExtension() {
+}
+
+common::Instance* PlayerUtilExtension::CreateInstance() {
+  return new PlayerUtilInstance();
+}
+
+}  // namespace playerutil
+}  // namespace extension
+
+common::Extension* CreateExtension() {
+  return new extension::playerutil::PlayerUtilExtension();
+}
diff --git a/src/playerutil/playerutil_extension.h b/src/playerutil/playerutil_extension.h
new file mode 100644 (file)
index 0000000..3733611
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    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 PLAYERUTIL_EXTENSION_H_
+#define PLAYERUTIL_EXTENSION_H_
+
+#include "common/extension.h"
+
+namespace extension {
+namespace playerutil {
+
+class PlayerUtilExtension : public common::Extension {
+ public:
+  PlayerUtilExtension();
+  virtual ~PlayerUtilExtension();
+
+ private:
+  virtual common::Instance* CreateInstance();
+};
+
+}  // namespace playerutil
+}  // namespace extension
+
+#endif  // PLAYERUTIL_EXTENSION_H_
+
diff --git a/src/playerutil/playerutil_instance.cc b/src/playerutil/playerutil_instance.cc
new file mode 100644 (file)
index 0000000..d295a8c
--- /dev/null
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    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 "playerutil/playerutil_instance.h"
+
+#include <thread>
+#include <ewk_context.h>
+
+#include "common/logger.h"
+#include "common/scope_exit.h"
+#include "common/tools.h"
+
+#include "playerutil/playerutil_utils.h"
+
+namespace extension {
+namespace playerutil {
+
+PlayerUtilInstance::PlayerUtilInstance() {
+  ScopeLogger();
+
+  using std::placeholders::_1;
+  using std::placeholders::_2;
+
+#define REGISTER_SYNC(c, x) \
+  RegisterSyncHandler(c, std::bind(&PlayerUtilInstance::x, this, _1))
+
+  REGISTER_SYNC("PlayerUtil_getLatencyMode", GetLatencyMode);
+  REGISTER_SYNC("PlayerUtil_setLatencyMode", SetLatencyMode);
+#undef REGISTER_SYNC
+
+}
+
+PlayerUtilInstance::~PlayerUtilInstance() {
+  ScopeLogger();
+}
+
+common::TizenResult PlayerUtilInstance::GetLatencyMode(const picojson::object& args) {
+  ScopeLogger();
+
+  Ewk_Context *context = ewk_context_default_get();
+
+  Ewk_Audio_Latency_Mode latency_mode = ewk_context_audio_latency_mode_get(context);
+
+  if (EWK_AUDIO_LATENCY_MODE_ERROR == latency_mode) {
+    LogAndReturnTizenError(common::AbortError(), ("ewk_context_audio_latency_mode_get() failed"));
+  }
+
+  return common::TizenSuccess{picojson::value{PlayerUtilUtils::FromLatencyMode(latency_mode)}};
+}
+
+common::TizenResult PlayerUtilInstance::SetLatencyMode(const picojson::object& args) {
+  ScopeLogger();
+
+  CHECK_EXIST(args, kLatencyMode);
+  auto latency_it = args.find(kLatencyMode)->second;
+  if (latency_it.is<std::string>()) {
+    Ewk_Audio_Latency_Mode latency_mode = PlayerUtilUtils::ToLatencyMode(latency_it.get<std::string>());
+    Ewk_Context *context = ewk_context_default_get();
+
+    auto ret = ewk_context_audio_latency_mode_set(context, latency_mode);
+    if (EINA_TRUE != ret) {
+      LogAndReturnTizenError(common::AbortError(), ("ewk_context_audio_latency_mode_set() failed"));
+    }
+  }
+
+  return common::TizenSuccess();
+}
+
+}  // namespace playerutil
+}  // namespace extension
diff --git a/src/playerutil/playerutil_instance.h b/src/playerutil/playerutil_instance.h
new file mode 100644 (file)
index 0000000..ebdbef3
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    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 PLAYERUTIL_INSTANCE_H_
+#define PLAYERUTIL_INSTANCE_H_
+
+#include "common/tizen_instance.h"
+
+
+namespace extension {
+namespace playerutil {
+
+class PlayerUtilInstance : public common::TizenInstance {
+ public:
+  PlayerUtilInstance();
+  virtual ~PlayerUtilInstance();
+ private:
+  common::TizenResult GetLatencyMode(const picojson::object& args);
+  common::TizenResult SetLatencyMode(const picojson::object& args);
+};
+
+}  // namespace playerutil
+}  // namespace extension
+
+#endif  // PLAYERUTIL_INSTANCE_H_
diff --git a/src/playerutil/playerutil_utils.cc b/src/playerutil/playerutil_utils.cc
new file mode 100644 (file)
index 0000000..7861efd
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    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 "playerutil_utils.h"
+
+#include "common/logger.h"
+
+namespace extension {
+namespace playerutil {
+
+namespace {
+#define PLAYER_UTIL_LATENCY_MODE_E \
+  X(EWK_AUDIO_LATENCY_MODE_HIGH, "HIGH") \
+  X(EWK_AUDIO_LATENCY_MODE_MID, "MID") \
+  X(EWK_AUDIO_LATENCY_MODE_LOW, "LOW") \
+  XD(EWK_AUDIO_LATENCY_MODE_LOW, "unknown")
+
+}  // namespace
+
+const std::string kLatencyMode = "latencyMode";
+
+#define X(v, s) case v: return s;
+#define XD(v, s) \
+  default: \
+    LoggerE("Unknown value: %d, returning default: %s", e, s); \
+    return s;
+
+std::string PlayerUtilUtils::FromLatencyMode(Ewk_Audio_Latency_Mode e) {
+  ScopeLogger();
+
+  switch (e) {
+    PLAYER_UTIL_LATENCY_MODE_E
+  }
+}
+
+#undef X
+#undef XD
+
+#define X(v, s) if (e == s) return v;
+#define XD(v, s) \
+  LoggerE("Unknown value: %s, returning default: %d", e.c_str(), v); \
+  return v;
+
+Ewk_Audio_Latency_Mode PlayerUtilUtils::ToLatencyMode(const std::string& e) {
+  ScopeLogger();
+
+  PLAYER_UTIL_LATENCY_MODE_E
+}
+#undef X
+#undef XD
+
+} // namespace playerutil
+} // namespace extension
diff --git a/src/playerutil/playerutil_utils.h b/src/playerutil/playerutil_utils.h
new file mode 100644 (file)
index 0000000..ad31e3f
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ *    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 WEBAPI_PLUGINS_PLAYER_UTIL_UTILS_H__
+#define WEBAPI_PLUGINS_PLAYER_UTIL_UTILS_H__
+
+#include <string>
+
+#include <ewk_context_product.h>
+
+#include "common/tizen_instance.h"
+#include "common/tizen_result.h"
+
+namespace extension {
+namespace playerutil {
+
+#define CHECK_EXIST(args, name) \
+  if (args.end() == args.find(name)) { \
+    return common::TypeMismatchError(std::string(name) + " is required argument"); \
+  }
+
+extern const std::string kLatencyMode;
+
+class PlayerUtilUtils {
+ public:
+  static std::string FromLatencyMode(Ewk_Audio_Latency_Mode e);
+  static Ewk_Audio_Latency_Mode ToLatencyMode(const std::string& e);
+};
+
+} // namespace playerutil
+} // namespace extension
+
+#endif // WEBAPI_PLUGINS_PLAYER_UTIL_UTILS_H__
index 7cc8a1044f48b91956ad67bf866aa82ee33d8ac8..c53aba3c77161c7d2b39d9a52d8f7bfe4dbbe9c7 100755 (executable)
             ],
           },
         ],
+        [
+          'tizen_feature_player_util_support==1', {
+            'dependencies': [
+              'playerutil/playerutil.gyp:*',
+            ],
+          },
+        ],
         [
           'tizen_feature_power_support==1', {
             'dependencies': [