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 <FIo_FileImpl.h>
32 #include <FApp_AppInfo.h>
34 using namespace Tizen::Base;
35 using namespace Tizen::Io;
36 using namespace Tizen::Locations;
37 using namespace Tizen::App;
38 using namespace Tizen::System;
41 namespace Tizen { namespace Content
44 VideoContentInfo::VideoContentInfo(void)
46 , __pVideoContentData(null)
52 VideoContentInfo::~VideoContentInfo(void)
54 if (__pVideoContentData != null)
56 if (__pVideoContentData->pArtist != null)
58 delete __pVideoContentData->pArtist;
59 __pVideoContentData->pArtist = null;
61 if (__pVideoContentData->pGenre != null)
63 delete __pVideoContentData->pGenre;
64 __pVideoContentData->pGenre = null;
66 if (__pVideoContentData->pTitle != null)
68 delete __pVideoContentData->pTitle;
69 __pVideoContentData->pTitle = null;
71 if (__pVideoContentData->pAlbumName != null)
73 delete __pVideoContentData->pAlbumName;
74 __pVideoContentData->pAlbumName = null;
76 delete __pVideoContentData;
77 __pVideoContentData = null;
89 VideoContentInfo::Construct(const String& contentPath, const String& thumbnailPath, bool setGps)
91 SysAssertf(__pVideoContentData == null,
92 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
97 _ContentData contentData;
98 int contentLength = 0;
99 FileAttributes attribute;
102 contentLength = contentPath.GetLength();
103 SysTryReturnResult(NID_CNT, _FileImpl::IsMediaPath(contentPath), E_INVALID_ARG,
104 "The contentPath should start with /Media or /Storagecard/Media(%ls).", contentPath.GetPointer());
105 SysTryReturnResult(NID_CNT, File::IsFileExist(contentPath), E_FILE_NOT_FOUND,
106 "The file corresponding to contentPath could not be found.");
108 if (!thumbnailPath.IsEmpty())
111 "The thumbnailPath is not supported but you can get the thumbnail managed by Tizen from ContentInfo::GetThumbnailN().");
116 SysLog(NID_CNT, "The setGps is not supported.");
119 // Sets the content path
120 contentData.contentPath = contentPath;
122 // Sets the content type
123 contentData.contentType = CONTENT_TYPE_VIDEO;
125 // E_INVALID_ARG, E_OUT_OF_MEMORY
126 r = SetContentData(&contentData);
127 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
129 _VideoContentData* pVideoContentData = new (nothrow) _VideoContentData();
130 SysTryReturnResult(NID_CNT, pVideoContentData != null, E_OUT_OF_MEMORY, "Construct() failed.");
132 __pVideoContentData = pVideoContentData;
146 VideoContentInfo::Construct(const String* pContentPath)
148 SysAssertf(__pVideoContentData == null,
149 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
153 result r = E_SUCCESS;
154 _ContentData contentData;
156 if (pContentPath != null)
158 if (!_AppInfo::IsOspCompat())
160 if (pContentPath->StartsWith(OSP_MEDIA_PHONE, 0) || pContentPath->StartsWith(OSP_MEDIA_MMC, 0))
162 SysLogException(NID_CNT, E_INVALID_ARG,
163 "[E_INVALID_ARG] /Media/ and /Storagecard/Media/ are not supported from Tizen 2.0.");
164 return E_INVALID_ARG;
166 if (!(pContentPath->StartsWith(Environment::GetMediaPath(), 0)
167 || pContentPath->StartsWith(Environment::GetExternalStoragePath(), 0)))
169 SysLogException(NID_CNT, E_INVALID_ARG,
170 "[E_INVALID_ARG] %ls is not supported.", pContentPath->GetPointer());
171 return E_INVALID_ARG;
177 if (pContentPath->StartsWith(OSP_MEDIA_PHONE, 0))
179 // Because the content path is saved like /opt/media or /opt/storage/sdcard/ in SLP database,
180 // it should be converted in 2.0.
181 r = (const_cast<String*>(pContentPath))->Replace(OSP_MEDIA_PHONE, Environment::GetMediaPath());
182 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
184 else if (pContentPath->StartsWith(OSP_MEDIA_MMC, 0))
186 r = (const_cast<String*>(pContentPath))->Replace(OSP_MEDIA_MMC, Environment::GetExternalStoragePath());
187 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
191 SysLogException(NID_CNT, E_INVALID_ARG,
192 "[E_INVALID_ARG] The contentPath should start with /Media or /Storagecard/Media.");
193 return E_INVALID_ARG;
197 int length = pContentPath->GetLength();
198 SysTryReturnResult(NID_CNT, length != 0, E_INVALID_ARG,
199 "The length of pContentPath is 0.");
200 SysTryReturnResult(NID_CNT, File::IsFileExist(*pContentPath), E_FILE_NOT_FOUND,
201 "The file corresponding to pContentPath could not be found.");
203 // Sets the content path
204 contentData.contentPath = *pContentPath;
206 // Sets the content type
207 contentData.contentType = CONTENT_TYPE_VIDEO;
209 r = SetContentData(&contentData);
210 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
214 contentData.contentType = CONTENT_TYPE_VIDEO;
216 r = SetContentData(&contentData);
217 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
221 _VideoContentData* pVideoContentData = new (nothrow) _VideoContentData();
222 SysTryReturnResult(NID_CNT, pVideoContentData != null, E_OUT_OF_MEMORY, "Construct() failed.");
224 __pVideoContentData = pVideoContentData;
230 VideoContentInfo::SetVideoContentData(const _VideoContentData* pVideoContentData)
234 SysTryReturnResult(NID_CNT, pVideoContentData != null, E_INVALID_ARG, "pVideoContentData is null.");
236 if (__pVideoContentData == null)
238 __pVideoContentData = new (nothrow) _VideoContentData;
239 SysTryReturnResult(NID_CNT, __pVideoContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
242 __pVideoContentData->width = pVideoContentData->width;
243 __pVideoContentData->height = pVideoContentData->height;
244 __pVideoContentData->framerate = pVideoContentData->framerate;
245 __pVideoContentData->audioBitrate = pVideoContentData->audioBitrate;
246 __pVideoContentData->videoBitrate = pVideoContentData->videoBitrate;
247 __pVideoContentData->duration = pVideoContentData->duration;
249 if (pVideoContentData->pArtist != null)
251 __pVideoContentData->pArtist = new (nothrow) String(*(pVideoContentData->pArtist));
252 SysTryReturnResult(NID_CNT, __pVideoContentData->pArtist != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
254 if (pVideoContentData->pGenre != null)
256 __pVideoContentData->pGenre = new (nothrow) String(*(pVideoContentData->pGenre));
257 SysTryReturnResult(NID_CNT, __pVideoContentData->pGenre != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
259 if (pVideoContentData->pTitle != null)
261 __pVideoContentData->pTitle = new (nothrow) String(*(pVideoContentData->pTitle));
262 SysTryReturnResult(NID_CNT, __pVideoContentData->pTitle != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
264 if (pVideoContentData->pAlbumName != null)
266 __pVideoContentData->pAlbumName = new (nothrow) String(*(pVideoContentData->pAlbumName));
267 SysTryReturnResult(NID_CNT, __pVideoContentData->pAlbumName != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
273 VideoContentInfo::_VideoContentData*
274 VideoContentInfo::GetVideoContentData(void)
276 if (__pVideoContentData == null)
278 __pVideoContentData = new (nothrow) VideoContentInfo::_VideoContentData;
279 SysTryReturn(NID_CNT, __pVideoContentData != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
281 return __pVideoContentData;
285 VideoContentInfo::GetGenre(void) const
287 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
289 if (__pVideoContentData->pGenre == null)
291 SysLog(NID_CNT, "GetGenre() failed.");
292 return String(L"Unknown");
295 return *(__pVideoContentData->pGenre);
299 VideoContentInfo::GetArtist(void) const
301 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
303 if (__pVideoContentData->pArtist == null)
305 SysLog(NID_CNT, "GetArtist() failed.");
306 return String(L"Unknown");
309 return *(__pVideoContentData->pArtist);
313 VideoContentInfo::GetBitrate(void) const
315 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
317 if (__pVideoContentData->audioBitrate == 0)
319 // The audio bitrate is not managed in video table.
320 if (this->GetVideoMetadata() != E_SUCCESS)
322 SysLog(NID_CNT, "GetBitrate() failed.");
327 return __pVideoContentData->audioBitrate;
331 VideoContentInfo::GetAudioBitrate(void) const
333 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
335 if (__pVideoContentData->audioBitrate == 0)
337 // The audio bitrate is not managed in video table.
338 if (this->GetVideoMetadata() != E_SUCCESS)
340 SysLog(NID_CNT, "GetAudioBitrate() failed.");
345 return __pVideoContentData->audioBitrate;
349 VideoContentInfo::GetVideoBitrate(void) const
351 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
353 if (__pVideoContentData->videoBitrate == 0)
355 // The video bitrate is not managed in video table.
356 if (this->GetVideoMetadata() != E_SUCCESS)
358 SysLog(NID_CNT, "GetVideoBitrate() failed.");
363 return __pVideoContentData->videoBitrate;
367 VideoContentInfo::GetFramerate(void) const
369 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
371 if (__pVideoContentData->framerate == 0)
373 // The framerate is not managed in video table.
374 if (this->GetVideoMetadata() != E_SUCCESS)
376 SysLog(NID_CNT, "GetFramerate() failed.");
381 return __pVideoContentData->framerate;
385 VideoContentInfo::GetWidth(void) const
387 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
389 return __pVideoContentData->width;
393 VideoContentInfo::GetHeight(void) const
395 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
397 return __pVideoContentData->height;
401 VideoContentInfo::GetTitle(void) const
403 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
405 if (__pVideoContentData->pTitle == null)
407 SysLog(NID_CNT, "GetTitle() failed.");
408 return String(L"Unknown");
411 return *(__pVideoContentData->pTitle);
415 VideoContentInfo::GetAlbumName(void) const
417 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
419 if (__pVideoContentData->pAlbumName == null)
421 SysLog(NID_CNT, "GetAlbumName() failed.");
422 return String(L"Unknown");
425 return *(__pVideoContentData->pAlbumName);
429 VideoContentInfo::GetDuration(void) const
431 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
433 return __pVideoContentData->duration;
437 VideoContentInfo::GetVideoMetadata(void) const
441 result r = E_SUCCESS;
443 VideoMetadata* pVideoMetadata = ContentManagerUtil::GetVideoMetaN(this->GetContentPath());
445 SysTryReturn(NID_CNT, pVideoMetadata != null, r, r, "[%s] GetVideoMetadata() failed.", GetErrorMessage(r));
448 __pVideoContentData->framerate = pVideoMetadata->GetFramerate();
451 __pVideoContentData->audioBitrate = pVideoMetadata->GetAudioBitrate();
454 __pVideoContentData->videoBitrate = pVideoMetadata->GetVideoBitrate();
456 delete pVideoMetadata;