Merge "[content] Fix extracting orientation because of changing hardware" into devel_...
[platform/framework/native/content.git] / src / FCnt_VideoContentInfoImpl.cpp
1 //
2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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 /**
17  * @file                FCntVideoContentInfo.cpp
18  * @brief               This is the implementation file for the %VideoContentInfo class.
19  *
20  * This file contains implementation of the %VideoContentInfo class.
21  */
22
23 #include <FBaseSysLog.h>
24 #include <FCntContentManagerUtil.h>
25 #include <FCntVideoMetadata.h>
26 #include <FIoFile.h>
27 #include <FIoDirectory.h>
28 #include <FSysEnvironment.h>
29 #include <FIo_FileImpl.h>
30 #include <FApp_AppInfo.h>
31 #include "FCnt_VideoContentInfoImpl.h"
32
33 using namespace std;
34 using namespace Tizen::App;
35 using namespace Tizen::Base;
36 using namespace Tizen::Io;
37 using namespace Tizen::Locations;
38 using namespace Tizen::System;
39
40 namespace Tizen { namespace Content
41 {
42
43 _VideoContentInfoImpl::_VideoContentInfoImpl(void)
44         : __width(0)
45         , __height(0)
46         , __framerate(0)
47         , __audioBitrate(0)
48         , __videoBitrate(0)
49         , __duration(0)
50         , __artist(L"")
51         , __genre(L"")
52         , __title(L"")
53         , __albumName(L"")
54 {
55
56 }
57
58 _VideoContentInfoImpl::~_VideoContentInfoImpl(void)
59 {
60
61 }
62
63 _VideoContentInfoImpl*
64 _VideoContentInfoImpl::GetInstance(VideoContentInfo& videoContentInfo)
65 {
66         return videoContentInfo.__pVideoContentInfoImpl;
67 }
68
69 const _VideoContentInfoImpl*
70 _VideoContentInfoImpl::GetInstance(const VideoContentInfo& videoContentInfo)
71 {
72         return videoContentInfo.__pVideoContentInfoImpl;
73 }
74
75 result
76 _VideoContentInfoImpl::Construct(const String& contentPath, const String& thumbnailPath, bool setGps)
77 {
78         result r = E_SUCCESS;
79         int contentLength = 0;
80         FileAttributes attribute;
81
82         // checks parameters
83         contentLength = contentPath.GetLength();
84         SysTryReturnResult(NID_CNT, _FileImpl::IsMediaPath(contentPath), E_INVALID_ARG,
85                         "The contentPath should start with /Media or /Storagecard/Media.");
86         SysTryReturnResult(NID_CNT, File::IsFileExist(contentPath), E_FILE_NOT_FOUND,
87                         "The file corresponding to contentPath could not be found.");
88
89         if (!thumbnailPath.IsEmpty())
90         {
91                 SysLog(NID_CNT,
92                                 "The thumbnailPath is not supported but you can get the thumbnail managed by Tizen from ContentInfo::GetThumbnailN().");
93         }
94
95         if (setGps)
96         {
97                 SysLog(NID_CNT, "The setGps is not supported.");
98         }
99
100         SetContentPath(contentPath);
101         SetContentType(CONTENT_TYPE_VIDEO);
102
103         return r;
104 }
105
106 result
107 _VideoContentInfoImpl::Construct(const String* pContentPath)
108 {
109         result r = E_SUCCESS;
110
111         if (pContentPath != null)
112         {
113                 String contentPath(*pContentPath);
114
115                 if (!_AppInfo::IsOspCompat())
116                 {
117                         if (!(contentPath.StartsWith(Environment::GetMediaPath(), 0)
118                                 || contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
119                         {
120                                 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] The path is not supported.");
121                                 return E_INVALID_ARG;
122                         }
123                 }
124                 else
125                 {
126                         // prior to 2.0
127                         if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0))
128                         {
129                                 // Because the content path is saved like /opt/media or /opt/storage/sdcard/ in SLP database,
130                                 // it should be converted in 2.0.
131                                 r = contentPath.Replace(OSP_MEDIA_PHONE, Environment::GetMediaPath());
132                                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
133                         }
134                         else if (contentPath.StartsWith(OSP_MEDIA_MMC, 0))
135                         {
136                                 r = contentPath.Replace(OSP_MEDIA_MMC, Environment::GetExternalStoragePath());
137                                 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
138                         }
139                         else
140                         {
141                                 SysLogException(NID_CNT, E_INVALID_ARG,
142                                                 "[E_INVALID_ARG] The contentPath should start with /Media or /Storagecard/Media.");
143                                 return E_INVALID_ARG;
144                         }
145                 }
146
147                 int length = contentPath.GetLength();
148                 SysTryReturnResult(NID_CNT, length != 0, E_INVALID_ARG,
149                                 "The length of pContentPath is 0.");
150                 SysTryReturnResult(NID_CNT, File::IsFileExist(contentPath), E_FILE_NOT_FOUND,
151                                 "The file corresponding to pContentPath could not be found.");
152
153                 SetContentPath(contentPath);
154                 SetContentType(CONTENT_TYPE_VIDEO);
155         }
156         else
157         {
158                 SetContentType(CONTENT_TYPE_VIDEO);
159         }
160
161         return r;
162 }
163
164 String
165 _VideoContentInfoImpl::GetGenre(void) const
166 {
167         if (__genre.IsEmpty())
168         {
169                 SysLog(NID_CNT, "Genre is empty.");
170                 return String(L"Unknown");
171         }
172
173         return __genre;
174 }
175
176 String
177 _VideoContentInfoImpl::GetArtist(void) const
178 {
179         if (__artist.IsEmpty())
180         {
181                 SysLog(NID_CNT, "Artist is empty.");
182                 return String(L"Unknown");
183         }
184
185         return __artist;
186 }
187
188 int
189 _VideoContentInfoImpl::GetBitrate(void) const
190 {
191         return __audioBitrate;
192 }
193
194 int
195 _VideoContentInfoImpl::GetAudioBitrate(void) const
196 {
197         return __audioBitrate;
198 }
199
200 int
201 _VideoContentInfoImpl::GetVideoBitrate(void) const
202 {
203         return __videoBitrate;
204 }
205
206 int
207 _VideoContentInfoImpl::GetFramerate(void) const
208 {
209         return __framerate;
210 }
211
212 int
213 _VideoContentInfoImpl::GetWidth(void) const
214 {
215         return __width;
216 }
217
218 int
219 _VideoContentInfoImpl::GetHeight(void) const
220 {
221         return __height;
222 }
223
224 String
225 _VideoContentInfoImpl::GetTitle(void) const
226 {
227         if (__title.IsEmpty())
228         {
229                 SysLog(NID_CNT, "Title is empty.");
230                 return String(L"Unknown");
231         }
232
233         return __title;
234 }
235
236 String
237 _VideoContentInfoImpl::GetAlbumName(void) const
238 {
239         if (__albumName.IsEmpty())
240         {
241                 SysLog(NID_CNT, "AlbumName is empty.");
242                 return String(L"Unknown");
243         }
244
245         return __albumName;
246 }
247
248 long
249 _VideoContentInfoImpl::GetDuration(void) const
250 {
251         return __duration;
252 }
253
254 void
255 _VideoContentInfoImpl::SetGenre(const Tizen::Base::String& genre)
256 {
257         __genre = genre;
258 }
259
260 void
261 _VideoContentInfoImpl::SetArtist(const Tizen::Base::String& artist)
262 {
263         __artist = artist;
264 }
265
266 void
267 _VideoContentInfoImpl::SetBitrate(int bitrate)
268 {
269         __audioBitrate = bitrate;
270 }
271
272 void
273 _VideoContentInfoImpl::SetAudioBitrate(int audioBitrate)
274 {
275         __audioBitrate = audioBitrate;
276 }
277
278 void
279 _VideoContentInfoImpl::SetVideoBitrate(int videoBitrate)
280 {
281         __videoBitrate = videoBitrate;
282 }
283
284 void
285 _VideoContentInfoImpl::SetFramerate(int framerate)
286 {
287         __framerate = framerate;
288 }
289
290 void
291 _VideoContentInfoImpl::SetWidth(int width)
292 {
293         __width = width;
294 }
295
296 void
297 _VideoContentInfoImpl::SetHeight(int height)
298 {
299         __height = height;
300 }
301
302 void
303 _VideoContentInfoImpl::SetTitle(const Tizen::Base::String& title)
304 {
305         __title = title;
306 }
307
308 void
309 _VideoContentInfoImpl::SetAlbumName(const Tizen::Base::String& albumName)
310 {
311         __albumName = albumName;
312 }
313
314 void
315 _VideoContentInfoImpl::SetDuration(long duration)
316 {
317         __duration = duration;
318 }
319
320 }}