#include <mm_error.h>
#include "mm_player_priv.h"
#include "mm_player_360.h"
+#include "mm_player_utils.h"
#include <gst/gst.h>
#include <gst/gstutils.h>
#include <glib.h>
-int _mmplayer_360_set_enable(MMHandleType player, bool enable)
+static bool
+__mmplayer_check_video_360_used(mmplayer_t *player)
{
- ((mm_player_t*) player)->is_video360_enabled = enable;
+ /* check video 360 plugin is created */
+ MMPLAYER_RETURN_VAL_IF_FAIL(player &&
+ player->pipeline &&
+ player->pipeline->videobin &&
+ player->pipeline->videobin[MMPLAYER_V_BIN].gst &&
+ player->pipeline->videobin[MMPLAYER_V_360].gst,
+ false);
- if (((mm_player_t*) player)->is_content_spherical &&
- ((mm_player_t*) player)->is_video360_plugin_used) {
- /* We will get here if player is pending ready or ready and above */
- g_object_set(G_OBJECT(((mm_player_t*) player)->pipeline->videobin[MMPLAYER_V_360].gst),
- "passthrough", !enable, NULL);
- return MM_ERROR_NONE;
+ return true;
+}
+
+static bool
+__mmplayer_check_audio_sink(mmplayer_t *player)
+{
+ /* check audio sink is created */
+ MMPLAYER_RETURN_VAL_IF_FAIL(player &&
+ player->pipeline &&
+ player->pipeline->videobin &&
+ player->pipeline->videobin[MMPLAYER_A_BIN].gst &&
+ player->pipeline->videobin[MMPLAYER_A_SINK].gst,
+ false);
+
+ return true;
+}
+
+int
+_mmplayer_360_is_content_spherical(MMHandleType hplayer, bool *is_spherical)
+{
+ mmplayer_t *player = (mmplayer_t *)hplayer;
+
+ MMPLAYER_FENTER();
+ MMPLAYER_RETURN_VAL_IF_FAIL(player && player->pipeline, MM_ERROR_PLAYER_NOT_INITIALIZED);
+ MMPLAYER_RETURN_VAL_IF_FAIL(is_spherical, MM_ERROR_INVALID_ARGUMENT);
+
+ LOGD("state %s, spherical info %d",
+ MMPLAYER_STATE_GET_NAME(MMPLAYER_CURRENT_STATE(player)), player->is_content_spherical);
+
+ if (player->state < MM_PLAYER_STATE_READY) {
+ *is_spherical = false;
+ return MM_ERROR_PLAYER_INVALID_STATE;
}
- return ((mm_player_t*) player)->state < MM_PLAYER_STATE_READY ? MM_ERROR_NONE : MM_ERROR_PLAYER_INTERNAL;
+ *is_spherical = (bool)player->is_content_spherical;
+
+ MMPLAYER_FLEAVE();
+ return MM_ERROR_NONE;
}
-int _mmplayer_360_is_enabled(MMHandleType player, bool *enabled)
+int
+_mmplayer_360_set_enabled(MMHandleType hplayer, bool enabled)
{
- if (((mm_player_t*) player)->state < MM_PLAYER_STATE_READY) {
- *enabled = ((mm_player_t*) player)->is_video360_enabled;
- return MM_ERROR_NONE;
+ mmplayer_t *player = (mmplayer_t *)hplayer;
+
+ MMPLAYER_FENTER();
+ MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+ LOGD("state %s, spherical info %d",
+ MMPLAYER_STATE_GET_NAME(MMPLAYER_CURRENT_STATE(player)), player->is_content_spherical);
+
+ player->is_video360_enabled = (gboolean)enabled;
+
+ if (player->is_content_spherical && __mmplayer_check_video_360_used(player)) {
+ /* We will get here if player is pending ready or ready and above */
+ LOGD("set enabled %d", player->is_video360_enabled);
+ g_object_set(G_OBJECT(player->pipeline->videobin[MMPLAYER_V_360].gst),
+ "passthrough", !player->is_video360_enabled, NULL);
}
- if (((mm_player_t*) player)->is_content_spherical &&
- ((mm_player_t*) player)->is_video360_plugin_used) {
- g_object_get(G_OBJECT(((mm_player_t*) player)->pipeline->videobin[MMPLAYER_V_360].gst),
- "passthrough", enabled, NULL);
- *enabled = !(*enabled);
- return MM_ERROR_NONE;
+ MMPLAYER_FLEAVE();
+ return MM_ERROR_NONE;
+}
+
+int
+_mmplayer_360_is_enabled(MMHandleType hplayer, bool *enabled)
+{
+ mmplayer_t *player = (mmplayer_t *)hplayer;
+ gboolean is_enabled;
+
+ MMPLAYER_FENTER();
+ MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+ MMPLAYER_RETURN_VAL_IF_FAIL(enabled, MM_ERROR_INVALID_ARGUMENT);
+
+ LOGD("state %s, spherical info %d",
+ MMPLAYER_STATE_GET_NAME(MMPLAYER_CURRENT_STATE(player)), player->is_content_spherical);
+
+ if (player->is_content_spherical && __mmplayer_check_video_360_used(player)) {
+ g_object_get(G_OBJECT(player->pipeline->videobin[MMPLAYER_V_360].gst),
+ "passthrough", &is_enabled, NULL);
+ *enabled = !((bool)is_enabled);
+ } else {
+ *enabled = (bool)player->is_video360_enabled;
}
- return MM_ERROR_PLAYER_INTERNAL;
+ LOGD("get enabled %d", *enabled);
+
+ MMPLAYER_FLEAVE();
+ return MM_ERROR_NONE;
}
-int _mmplayer_360_set_direction_of_view(MMHandleType player, float yaw, float pitch)
+int
+_mmplayer_360_set_direction_of_view(MMHandleType hplayer, float yaw, float pitch)
{
- if (yaw > M_PI || yaw < -M_PI || pitch > M_PI_2 || pitch < -M_PI_2)
+ mmplayer_t *player = (mmplayer_t *)hplayer;
+
+ MMPLAYER_FENTER();
+ MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+ if (yaw > (float)(M_PI) || yaw < (float)(-M_PI) || pitch > (float)(M_PI_2) || pitch < (float)(-M_PI_2)) {
+ LOGE("invalid argument %f, %f", yaw, pitch);
return MM_ERROR_INVALID_ARGUMENT;
+ }
- ((mm_player_t*) player)->video360_yaw_radians = yaw;
- ((mm_player_t*) player)->video360_pitch_radians = pitch;
+ LOGD("state %s, spherical info %d",
+ MMPLAYER_STATE_GET_NAME(MMPLAYER_CURRENT_STATE(player)), player->is_content_spherical);
- if (((mm_player_t*) player)->is_content_spherical) {
+ player->video360_yaw_radians = yaw;
+ player->video360_pitch_radians = pitch;
+
+ if (player->is_content_spherical) {
/* We will get here if player is pending ready or ready and above */
- if (((mm_player_t*) player)->is_video360_plugin_used) {
- g_object_set(G_OBJECT(((mm_player_t*) player)->pipeline->videobin[MMPLAYER_V_360].gst),
- "pose-yaw", (int) (yaw * 180.0f / M_PI),
- "pose-pitch", (int) (pitch * 180.0f / M_PI), NULL);
+ if (__mmplayer_check_video_360_used(player)) {
+ LOGD("set yaw %f, pitch %f for video", yaw, pitch);
+ g_object_set(G_OBJECT(player->pipeline->videobin[MMPLAYER_V_360].gst),
+ "pose-yaw", (int)(yaw * 180.0f / M_PI),
+ "pose-pitch", (int)(pitch * 180.0f / M_PI), NULL);
}
- if (((mm_player_t*) player)->is_openal_plugin_used) {
- g_object_set(G_OBJECT(((mm_player_t*) player)->pipeline->audiobin[MMPLAYER_A_SINK].gst),
- "source-orientation-y", (int) (yaw * 180.0f / M_PI),
- "source-orientation-x", (int) (pitch * 180.0f / M_PI), NULL);
+ if (player->is_openal_plugin_used && __mmplayer_check_audio_sink(player)) {
+ g_object_set(G_OBJECT(player->pipeline->audiobin[MMPLAYER_A_SINK].gst),
+ "source-orientation-y", (int)(yaw * 180.0f / M_PI),
+ "source-orientation-x", (int)(pitch * 180.0f / M_PI), NULL);
}
- return MM_ERROR_NONE;
}
- return ((mm_player_t*) player)->state < MM_PLAYER_STATE_READY ? MM_ERROR_NONE : MM_ERROR_PLAYER_INTERNAL;
+ MMPLAYER_FLEAVE();
+ return MM_ERROR_NONE;
}
-int _mmplayer_360_get_direction_of_view(MMHandleType player, float *yaw, float *pitch)
+int
+_mmplayer_360_get_direction_of_view(MMHandleType hplayer, float *yaw, float *pitch)
{
- int yaw_degrees, pitch_degrees;
+ mmplayer_t *player = (mmplayer_t *)hplayer;
+ int yaw_degrees = 0;
+ int pitch_degrees = 0;
- if (((mm_player_t*) player)->state < MM_PLAYER_STATE_READY) {
- *yaw = ((mm_player_t*) player)->video360_yaw_radians;
- *pitch = ((mm_player_t*) player)->video360_pitch_radians;
- return MM_ERROR_NONE;
- }
+ MMPLAYER_FENTER();
+ MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+ MMPLAYER_RETURN_VAL_IF_FAIL(yaw && pitch, MM_ERROR_INVALID_ARGUMENT);
- if (((mm_player_t*) player)->is_content_spherical &&
- ((mm_player_t*) player)->is_video360_plugin_used) {
- g_object_get(G_OBJECT(((mm_player_t*) player)->pipeline->videobin[MMPLAYER_V_360].gst),
+ LOGD("state %s, spherical info %d",
+ MMPLAYER_STATE_GET_NAME(MMPLAYER_CURRENT_STATE(player)), player->is_content_spherical);
+
+ if (player->is_content_spherical && __mmplayer_check_video_360_used(player)) {
+ g_object_get(G_OBJECT(player->pipeline->videobin[MMPLAYER_V_360].gst),
"pose-yaw", &yaw_degrees, "pose-pitch", &pitch_degrees, NULL);
*yaw = M_PI * yaw_degrees / 180.0f;
*pitch = M_PI * pitch_degrees / 180.0f;
+
+ LOGD("get yaw %f, pitch %f", *yaw, *pitch);
return MM_ERROR_NONE;
}
- return MM_ERROR_PLAYER_INTERNAL;
+ *yaw = player->video360_yaw_radians;
+ *pitch = player->video360_pitch_radians;
+
+ MMPLAYER_FLEAVE();
+ return MM_ERROR_NONE;
}
-int _mmplayer_360_set_zoom(MMHandleType player, float level)
+int
+_mmplayer_360_set_zoom(MMHandleType hplayer, float level)
{
- if (level < 1.0f || level > VIDEO360_MAX_ZOOM)
+ mmplayer_t *player = (mmplayer_t *)hplayer;
+
+ MMPLAYER_FENTER();
+ MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+ if (level < 1.0f || level > VIDEO360_MAX_ZOOM) {
+ LOGE("invalid argument %f", level);
return MM_ERROR_INVALID_ARGUMENT;
+ }
- ((mm_player_t*) player)->video360_zoom = 1.0f / level;
+ LOGD("state %s, spherical info %d",
+ MMPLAYER_STATE_GET_NAME(MMPLAYER_CURRENT_STATE(player)), player->is_content_spherical);
- if (((mm_player_t*) player)->is_content_spherical &&
- ((mm_player_t*) player)->is_video360_plugin_used) {
+ player->video360_zoom = level;
+
+ if (player->is_content_spherical && __mmplayer_check_video_360_used(player)) {
/* We will get here if player is pending ready or ready and above */
- g_object_set(G_OBJECT(((mm_player_t*) player)->pipeline->videobin[MMPLAYER_V_360].gst),
+
+ LOGD("set level %f", level);
+ g_object_set(G_OBJECT(player->pipeline->videobin[MMPLAYER_V_360].gst),
"zoom", 1.0f / level, NULL);
- return MM_ERROR_NONE;
}
- return ((mm_player_t*) player)->state < MM_PLAYER_STATE_READY ? MM_ERROR_NONE : MM_ERROR_PLAYER_INTERNAL;
+ MMPLAYER_FLEAVE();
+ return MM_ERROR_NONE;
}
-int _mmplayer_360_get_zoom(MMHandleType player, float *level)
+int
+_mmplayer_360_get_zoom(MMHandleType hplayer, float *level)
{
- float current_zoom;
+ mmplayer_t *player = (mmplayer_t *)hplayer;
+ float current_zoom = 0.0;
- if (((mm_player_t*) player)->state < MM_PLAYER_STATE_READY) {
- *level = 1.0f / ((mm_player_t*) player)->video360_zoom;
- return MM_ERROR_NONE;
- }
+ MMPLAYER_FENTER();
+ MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+ MMPLAYER_RETURN_VAL_IF_FAIL(level, MM_ERROR_INVALID_ARGUMENT);
- if (((mm_player_t*) player)->is_content_spherical &&
- ((mm_player_t*) player)->is_video360_plugin_used) {
- g_object_get(G_OBJECT(((mm_player_t*) player)->pipeline->videobin[MMPLAYER_V_360].gst),
+ LOGD("state %s, spherical info %d",
+ MMPLAYER_STATE_GET_NAME(MMPLAYER_CURRENT_STATE(player)), player->is_content_spherical);
+
+ if (player->is_content_spherical && __mmplayer_check_video_360_used(player)) {
+ g_object_get(G_OBJECT(player->pipeline->videobin[MMPLAYER_V_360].gst),
"zoom", ¤t_zoom, NULL);
*level = 1.0f / current_zoom;
+
+ LOGD("get level %f", *level);
return MM_ERROR_NONE;
}
- return MM_ERROR_PLAYER_INTERNAL;
+ *level = player->video360_zoom;
+
+ MMPLAYER_FLEAVE();
+ return MM_ERROR_NONE;
}
-int _mmplayer_360_set_field_of_view(MMHandleType player, int horizontal_degrees, int vertical_degrees)
+int
+_mmplayer_360_set_field_of_view(MMHandleType hplayer, int horizontal_degrees, int vertical_degrees)
{
- if (horizontal_degrees < 1 || horizontal_degrees > 360 || vertical_degrees < 1 || vertical_degrees > 180)
+ mmplayer_t *player = (mmplayer_t *)hplayer;
+
+ MMPLAYER_FENTER();
+ MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+
+ if (horizontal_degrees < 1 || horizontal_degrees > 360 || vertical_degrees < 1 || vertical_degrees > 180) {
+ LOGE("invalid argument %d, %d", horizontal_degrees, vertical_degrees);
return MM_ERROR_INVALID_ARGUMENT;
+ }
+
+ LOGD("state %s, spherical info %d",
+ MMPLAYER_STATE_GET_NAME(MMPLAYER_CURRENT_STATE(player)), player->is_content_spherical);
- ((mm_player_t*) player)->video360_horizontal_fov = horizontal_degrees;
- ((mm_player_t*) player)->video360_vertical_fov = vertical_degrees;
+ player->video360_horizontal_fov = horizontal_degrees;
+ player->video360_vertical_fov = vertical_degrees;
- if (((mm_player_t*) player)->is_content_spherical &&
- ((mm_player_t*) player)->is_video360_plugin_used) {
+ if (player->is_content_spherical && __mmplayer_check_video_360_used(player)) {
/* We will get here if player is pending ready or ready and above */
- g_object_set(G_OBJECT(((mm_player_t*) player)->pipeline->videobin[MMPLAYER_V_360].gst),
+ LOGD("set h-fov %d, v-fov %d", horizontal_degrees, vertical_degrees);
+ g_object_set(G_OBJECT(player->pipeline->videobin[MMPLAYER_V_360].gst),
"horizontal-fov", horizontal_degrees, "vertical-fov", vertical_degrees, NULL);
- return MM_ERROR_NONE;
}
- return ((mm_player_t*) player)->state < MM_PLAYER_STATE_READY ? MM_ERROR_NONE : MM_ERROR_PLAYER_INTERNAL;
+ MMPLAYER_FLEAVE();
+ return MM_ERROR_NONE;
}
-int _mmplayer_360_get_field_of_view(MMHandleType player, int *horizontal_degrees, int *vertical_degrees)
+int
+_mmplayer_360_get_field_of_view(MMHandleType hplayer, int *horizontal_degrees, int *vertical_degrees)
{
- if (((mm_player_t*) player)->state < MM_PLAYER_STATE_READY) {
- *horizontal_degrees = ((mm_player_t*) player)->video360_horizontal_fov;
- *vertical_degrees = ((mm_player_t*) player)->video360_vertical_fov;
- return MM_ERROR_NONE;
- }
+ mmplayer_t *player = (mmplayer_t *)hplayer;
+
+ MMPLAYER_FENTER();
+ MMPLAYER_RETURN_VAL_IF_FAIL(player, MM_ERROR_PLAYER_NOT_INITIALIZED);
+ MMPLAYER_RETURN_VAL_IF_FAIL(horizontal_degrees && vertical_degrees, MM_ERROR_INVALID_ARGUMENT);
- if (((mm_player_t*) player)->is_content_spherical &&
- ((mm_player_t*) player)->is_video360_plugin_used) {
- g_object_get(G_OBJECT(((mm_player_t*) player)->pipeline->videobin[MMPLAYER_V_360].gst),
+ LOGD("state %s, spherical info %d",
+ MMPLAYER_STATE_GET_NAME(MMPLAYER_CURRENT_STATE(player)), player->is_content_spherical);
+
+ if (player->is_content_spherical && __mmplayer_check_video_360_used(player)) {
+ g_object_get(G_OBJECT(player->pipeline->videobin[MMPLAYER_V_360].gst),
"horizontal-fov", horizontal_degrees, "vertical-fov", vertical_degrees, NULL);
+
+ LOGD("get h-fov %d, v-fov %d", *horizontal_degrees, *vertical_degrees);
return MM_ERROR_NONE;
}
- return MM_ERROR_PLAYER_INTERNAL;
+ *horizontal_degrees = player->video360_horizontal_fov;
+ *vertical_degrees = player->video360_vertical_fov;
+
+ MMPLAYER_FLEAVE();
+ return MM_ERROR_NONE;
}