2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 * @file FCntVideoContentInfo.cpp
19 * @brief This is the implementation file for the %VideoContentInfo class.
21 * This file contains implementation of the %VideoContentInfo class.
24 #include <FBaseSysLog.h>
25 #include <FCntVideoContentInfo.h>
26 #include <FCntContentManagerUtil.h>
27 #include <FCntVideoMetadata.h>
29 #include <FIoDirectory.h>
30 #include <FSysEnvironment.h>
31 //#include <FLocLocationProvider.h>
32 //#include <FLocQualifiedCoordinates.h>
33 #include <FIo_FileImpl.h>
34 #include <FApp_AppInfo.h>
36 using namespace Tizen::Base;
37 using namespace Tizen::Io;
38 using namespace Tizen::Locations;
39 using namespace Tizen::App;
40 using namespace Tizen::System;
43 namespace Tizen { namespace Content
46 VideoContentInfo::VideoContentInfo(void)
48 , __pVideoContentData(null)
54 VideoContentInfo::~VideoContentInfo(void)
56 if (__pVideoContentData != null)
58 if (__pVideoContentData->pArtist != null)
60 delete __pVideoContentData->pArtist;
61 __pVideoContentData->pArtist = null;
63 if (__pVideoContentData->pGenre != null)
65 delete __pVideoContentData->pGenre;
66 __pVideoContentData->pGenre = null;
68 if (__pVideoContentData->pTitle != null)
70 delete __pVideoContentData->pTitle;
71 __pVideoContentData->pTitle = null;
73 if (__pVideoContentData->pAlbumName != null)
75 delete __pVideoContentData->pAlbumName;
76 __pVideoContentData->pAlbumName = null;
78 delete __pVideoContentData;
79 __pVideoContentData = null;
91 VideoContentInfo::Construct(const String& contentPath, const String& thumbnailPath, bool setGps)
93 SysAssertf(__pVideoContentData == null,
94 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
99 _ContentData contentData;
100 int contentLength = 0;
101 FileAttributes attribute;
104 contentLength = contentPath.GetLength();
105 SysTryReturnResult(NID_CNT, _FileImpl::IsMediaPath(contentPath), E_INVALID_ARG,
106 "The contentPath should start with /Media or /Storagecard/Media(%ls).", contentPath.GetPointer());
107 SysTryReturnResult(NID_CNT, File::IsFileExist(contentPath), E_FILE_NOT_FOUND,
108 "The file corresponding to contentPath could not be found.");
110 if (!thumbnailPath.IsEmpty())
113 "The thumbnailPath is not supported but you can get the thumbnail managed by Tizen from ContentInfo::GetThumbnailN().");
118 SysLog(NID_CNT, "The setGps is not supported.");
121 // Sets the content path
122 contentData.contentPath = contentPath;
124 // Sets the content type
125 contentData.contentType = CONTENT_TYPE_VIDEO;
127 // E_INVALID_ARG, E_OUT_OF_MEMORY
128 r = SetContentData(&contentData);
129 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
131 _VideoContentData* pVideoContentData = new (nothrow) _VideoContentData();
132 SysTryReturnResult(NID_CNT, pVideoContentData != null, E_OUT_OF_MEMORY, "Construct() failed.");
134 __pVideoContentData = pVideoContentData;
148 VideoContentInfo::Construct(const String* pContentPath)
150 SysAssertf(__pVideoContentData == null,
151 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
155 result r = E_SUCCESS;
156 _ContentData contentData;
158 if (pContentPath != null)
160 if (!_AppInfo::IsOspCompat())
162 if (pContentPath->StartsWith(OSP_MEDIA_PHONE, 0) || pContentPath->StartsWith(OSP_MEDIA_MMC, 0))
164 SysLogException(NID_CNT, E_INVALID_ARG,
165 "[E_INVALID_ARG] /Media/ and /Storagecard/Media/ are not supported from Tizen 2.0.");
166 return E_INVALID_ARG;
168 if (!(pContentPath->StartsWith(Environment::GetMediaPath(), 0)
169 || pContentPath->StartsWith(Environment::GetExternalStoragePath(), 0)))
171 SysLogException(NID_CNT, E_INVALID_ARG,
172 "[E_INVALID_ARG] %ls is not supported.", pContentPath->GetPointer());
173 return E_INVALID_ARG;
179 if (pContentPath->StartsWith(OSP_MEDIA_PHONE, 0))
181 // Because the content path is saved like /opt/media or /opt/storage/sdcard/ in SLP database,
182 // it should be converted in 2.0.
183 r = (const_cast<String*>(pContentPath))->Replace(OSP_MEDIA_PHONE, Environment::GetMediaPath());
184 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
186 else if (pContentPath->StartsWith(OSP_MEDIA_MMC, 0))
188 r = (const_cast<String*>(pContentPath))->Replace(OSP_MEDIA_MMC, Environment::GetExternalStoragePath());
189 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
193 SysLogException(NID_CNT, E_INVALID_ARG,
194 "[E_INVALID_ARG] The contentPath should start with /Media or /Storagecard/Media.");
195 return E_INVALID_ARG;
199 int length = pContentPath->GetLength();
200 SysTryReturnResult(NID_CNT, length != 0, E_INVALID_ARG,
201 "The length of pContentPath is 0.");
202 SysTryReturnResult(NID_CNT, File::IsFileExist(*pContentPath), E_FILE_NOT_FOUND,
203 "The file corresponding to pContentPath could not be found.");
205 // Sets the content path
206 contentData.contentPath = *pContentPath;
208 // Sets the content type
209 contentData.contentType = CONTENT_TYPE_VIDEO;
211 r = SetContentData(&contentData);
212 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
216 contentData.contentType = CONTENT_TYPE_VIDEO;
218 r = SetContentData(&contentData);
219 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
223 _VideoContentData* pVideoContentData = new (nothrow) _VideoContentData();
224 SysTryReturnResult(NID_CNT, pVideoContentData != null, E_OUT_OF_MEMORY, "Construct() failed.");
226 __pVideoContentData = pVideoContentData;
232 VideoContentInfo::SetVideoContentData(const _VideoContentData* pVideoContentData)
236 SysTryReturnResult(NID_CNT, pVideoContentData != null, E_INVALID_ARG, "pVideoContentData is null.");
238 if (__pVideoContentData == null)
240 __pVideoContentData = new (nothrow) _VideoContentData;
241 SysTryReturnResult(NID_CNT, __pVideoContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
244 __pVideoContentData->width = pVideoContentData->width;
245 __pVideoContentData->height = pVideoContentData->height;
246 __pVideoContentData->framerate = pVideoContentData->framerate;
247 __pVideoContentData->audioBitrate = pVideoContentData->audioBitrate;
248 __pVideoContentData->videoBitrate = pVideoContentData->videoBitrate;
249 __pVideoContentData->duration = pVideoContentData->duration;
251 if (pVideoContentData->pArtist != null)
253 __pVideoContentData->pArtist = new (nothrow) String(*(pVideoContentData->pArtist));
254 SysTryReturnResult(NID_CNT, __pVideoContentData->pArtist != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
256 if (pVideoContentData->pGenre != null)
258 __pVideoContentData->pGenre = new (nothrow) String(*(pVideoContentData->pGenre));
259 SysTryReturnResult(NID_CNT, __pVideoContentData->pGenre != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
261 if (pVideoContentData->pTitle != null)
263 __pVideoContentData->pTitle = new (nothrow) String(*(pVideoContentData->pTitle));
264 SysTryReturnResult(NID_CNT, __pVideoContentData->pTitle != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
266 if (pVideoContentData->pAlbumName != null)
268 __pVideoContentData->pAlbumName = new (nothrow) String(*(pVideoContentData->pAlbumName));
269 SysTryReturnResult(NID_CNT, __pVideoContentData->pAlbumName != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
275 VideoContentInfo::_VideoContentData*
276 VideoContentInfo::GetVideoContentData(void)
278 if (__pVideoContentData == null)
280 __pVideoContentData = new (nothrow) VideoContentInfo::_VideoContentData;
281 SysTryReturn(NID_CNT, __pVideoContentData != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
283 return __pVideoContentData;
287 VideoContentInfo::GetGenre(void) const
289 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
291 if (__pVideoContentData->pGenre == null)
293 SysLog(NID_CNT, "GetGenre() failed.");
294 return String(L"Unknown");
297 return *(__pVideoContentData->pGenre);
301 VideoContentInfo::GetArtist(void) const
303 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
305 if (__pVideoContentData->pArtist == null)
307 SysLog(NID_CNT, "GetArtist() failed.");
308 return String(L"Unknown");
311 return *(__pVideoContentData->pArtist);
315 VideoContentInfo::GetBitrate(void) const
317 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
319 if (__pVideoContentData->audioBitrate == 0)
321 // The audio bitrate is not managed in video table.
322 if (this->GetVideoMetadata() != E_SUCCESS)
324 SysLog(NID_CNT, "GetBitrate() failed.");
329 return __pVideoContentData->audioBitrate;
333 VideoContentInfo::GetAudioBitrate(void) const
335 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
337 if (__pVideoContentData->audioBitrate == 0)
339 // The audio bitrate is not managed in video table.
340 if (this->GetVideoMetadata() != E_SUCCESS)
342 SysLog(NID_CNT, "GetAudioBitrate() failed.");
347 return __pVideoContentData->audioBitrate;
351 VideoContentInfo::GetVideoBitrate(void) const
353 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
355 if (__pVideoContentData->videoBitrate == 0)
357 // The video bitrate is not managed in video table.
358 if (this->GetVideoMetadata() != E_SUCCESS)
360 SysLog(NID_CNT, "GetVideoBitrate() failed.");
365 return __pVideoContentData->videoBitrate;
369 VideoContentInfo::GetFramerate(void) const
371 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
373 if (__pVideoContentData->framerate == 0)
375 // The framerate is not managed in video table.
376 if (this->GetVideoMetadata() != E_SUCCESS)
378 SysLog(NID_CNT, "GetFramerate() failed.");
383 return __pVideoContentData->framerate;
387 VideoContentInfo::GetWidth(void) const
389 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
391 return __pVideoContentData->width;
395 VideoContentInfo::GetHeight(void) const
397 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
399 return __pVideoContentData->height;
403 VideoContentInfo::GetTitle(void) const
405 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
407 if (__pVideoContentData->pTitle == null)
409 SysLog(NID_CNT, "GetTitle() failed.");
410 return String(L"Unknown");
413 return *(__pVideoContentData->pTitle);
417 VideoContentInfo::GetAlbumName(void) const
419 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
421 if (__pVideoContentData->pAlbumName == null)
423 SysLog(NID_CNT, "GetAlbumName() failed.");
424 return String(L"Unknown");
427 return *(__pVideoContentData->pAlbumName);
431 VideoContentInfo::GetDuration(void) const
433 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
435 return __pVideoContentData->duration;
439 VideoContentInfo::GetVideoMetadata(void) const
443 result r = E_SUCCESS;
445 VideoMetadata* pVideoMetadata = ContentManagerUtil::GetVideoMetaN(this->GetContentPath());
447 SysTryReturn(NID_CNT, pVideoMetadata != null, r, r, "[%s] GetVideoMetadata() failed.", GetErrorMessage(r));
450 __pVideoContentData->framerate = pVideoMetadata->GetFramerate();
453 __pVideoContentData->audioBitrate = pVideoMetadata->GetAudioBitrate();
456 __pVideoContentData->videoBitrate = pVideoMetadata->GetVideoBitrate();
458 delete pVideoMetadata;