[0.6.231] Fix typo error
[platform/core/multimedia/libmm-player.git] / unittest / gtest_mm_player_priv.cpp
1 /*
2  * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include "mm_error.h"
17 #include "mm_player_utils.h"
18 #include "gtest_mm_player_priv.h"
19
20 MMPlayerPriv::MMPlayerPriv()
21 {
22         priv_player = NULL;
23 }
24
25 MMPlayerPriv::~MMPlayerPriv()
26 {
27         if (priv_player) {
28                 _mmplayer_destroy((MMHandleType)priv_player);
29                 g_mutex_clear(&priv_player->cmd_lock);
30                 g_mutex_clear(&priv_player->reconfigure_lock);
31                 g_cond_clear(&priv_player->reconfigure_cond);
32
33                 g_free(priv_player);
34                 priv_player = NULL;
35         }
36 }
37
38 int MMPlayerPriv::Create(void)
39 {
40         int ret = MM_ERROR_NONE;
41         mmplayer_t *new_player = NULL;
42
43         /* alloc player structure */
44         new_player = (mmplayer_t *)g_malloc0(sizeof(mmplayer_t));
45
46         /* create player lock */
47         g_mutex_init(&new_player->cmd_lock);
48
49         /* create reconfigure lock & cond */
50         g_mutex_init(&new_player->reconfigure_lock);
51         g_cond_init(&new_player->reconfigure_cond);
52
53         /* load ini files */
54         if (mm_player_ini_load(&new_player->ini) != MM_ERROR_NONE) {
55                 LOGE("can't load ini");
56                 return MM_ERROR_PLAYER_INTERNAL;
57         }
58
59         if (mm_player_audio_effect_ini_load(&new_player->ini) != MM_ERROR_NONE) {
60                 LOGE("can't load audio ini");
61                 return MM_ERROR_PLAYER_INTERNAL;
62         }
63
64         /* create player */
65         ret = _mmplayer_create_player((MMHandleType)new_player);
66
67         priv_player = new_player;
68
69         return ret;
70 }
71
72 int MMPlayerPriv::Destroy(void)
73 {
74         int ret = MM_ERROR_NONE;
75
76         if (!priv_player)
77                 return MM_ERROR_PLAYER_NOT_INITIALIZED;
78
79         __mmplayer_bus_msg_thread_destroy(priv_player);
80
81         MMPLAYER_CMD_LOCK(priv_player);
82
83         ret = _mmplayer_destroy(priv_player);
84
85         MMPLAYER_CMD_UNLOCK(priv_player);
86
87         g_mutex_clear(&((mmplayer_t *)priv_player)->cmd_lock);
88         g_mutex_clear(&((mmplayer_t *)priv_player)->reconfigure_lock);
89         g_cond_clear(&((mmplayer_t *)priv_player)->reconfigure_cond);
90
91         memset((mmplayer_t *)priv_player, 0x00, sizeof(mmplayer_t));
92
93         /* free player */
94         g_free((void *)priv_player);
95         priv_player = NULL;
96
97         return ret;
98 }
99
100 int MMPlayerPriv::SetUri(const gchar *uri)
101 {
102         int ret = MM_ERROR_NONE;
103
104         MMPLAYER_CMD_LOCK(priv_player);
105         ret = _mmplayer_set_uri(priv_player, uri);
106         MMPLAYER_CMD_UNLOCK(priv_player);
107
108         return ret;
109 }
110
111 int MMPlayerPriv::Realize(void)
112 {
113         int ret = MM_ERROR_NONE;
114
115         MMPLAYER_CMD_LOCK(priv_player);
116         ret = _mmplayer_realize(priv_player);
117         MMPLAYER_CMD_UNLOCK(priv_player);
118
119         return ret;
120 }
121
122 int MMPlayerPriv::Unrealize(void)
123 {
124         int ret = MM_ERROR_NONE;
125
126         MMPLAYER_CMD_LOCK(priv_player);
127         ret = _mmplayer_unrealize(priv_player);
128         MMPLAYER_CMD_UNLOCK(priv_player);
129
130         return ret;
131 }
132
133 int MMPlayerPriv::GetCurrentState(mmplayer_state_e *state)
134 {
135         int ret = MM_ERROR_NONE;
136
137         *state = MM_PLAYER_STATE_NULL;
138         ret = _mmplayer_get_state(priv_player, (int *)state);
139
140         return ret;
141 }
142
143 int MMPlayerPriv::ParseProfile(const gchar *uri, int *uri_type)
144 {
145         int ret = MM_ERROR_NONE;
146         mmplayer_parse_profile_t profile;
147
148         memset((void *)&profile, 0, sizeof(mmplayer_parse_profile_t));
149
150         ret = _mmplayer_parse_profile(uri, NULL, &profile);
151         if (uri_type)
152                 *uri_type = profile.uri_type;
153
154         return ret;
155 }