2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 * @file FCntVideoContentInfo.cpp
18 * @brief This is the implementation file for the %VideoContentInfo class.
20 * This file contains implementation of the %VideoContentInfo class.
23 #include <FBaseSysLog.h>
24 #include <FCntVideoContentInfo.h>
25 #include <FCntContentManagerUtil.h>
26 #include <FCntVideoMetadata.h>
28 #include <FIoDirectory.h>
29 #include <FSysEnvironment.h>
30 #include <FIo_FileImpl.h>
31 #include <FApp_AppInfo.h>
33 using namespace Tizen::Base;
34 using namespace Tizen::Io;
35 using namespace Tizen::Locations;
36 using namespace Tizen::App;
37 using namespace Tizen::System;
40 namespace Tizen { namespace Content
43 VideoContentInfo::VideoContentInfo(void)
45 , __pVideoContentData(null)
51 VideoContentInfo::~VideoContentInfo(void)
53 if (__pVideoContentData != null)
55 if (__pVideoContentData->pArtist != null)
57 delete __pVideoContentData->pArtist;
58 __pVideoContentData->pArtist = null;
60 if (__pVideoContentData->pGenre != null)
62 delete __pVideoContentData->pGenre;
63 __pVideoContentData->pGenre = null;
65 if (__pVideoContentData->pTitle != null)
67 delete __pVideoContentData->pTitle;
68 __pVideoContentData->pTitle = null;
70 if (__pVideoContentData->pAlbumName != null)
72 delete __pVideoContentData->pAlbumName;
73 __pVideoContentData->pAlbumName = null;
75 delete __pVideoContentData;
76 __pVideoContentData = null;
88 VideoContentInfo::Construct(const String& contentPath, const String& thumbnailPath, bool setGps)
90 SysAssertf(__pVideoContentData == null,
91 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
96 _ContentData contentData;
97 int contentLength = 0;
98 FileAttributes attribute;
101 contentLength = contentPath.GetLength();
102 SysTryReturnResult(NID_CNT, _FileImpl::IsMediaPath(contentPath), E_INVALID_ARG,
103 "The contentPath should start with /Media or /Storagecard/Media.");
104 SysTryReturnResult(NID_CNT, File::IsFileExist(contentPath), E_FILE_NOT_FOUND,
105 "The file corresponding to contentPath could not be found.");
107 if (!thumbnailPath.IsEmpty())
110 "The thumbnailPath is not supported but you can get the thumbnail managed by Tizen from ContentInfo::GetThumbnailN().");
115 SysLog(NID_CNT, "The setGps is not supported.");
118 // Sets the content path
119 contentData.contentPath = contentPath;
121 // Sets the content type
122 contentData.contentType = CONTENT_TYPE_VIDEO;
124 // E_INVALID_ARG, E_OUT_OF_MEMORY
125 r = SetContentData(&contentData);
126 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
128 _VideoContentData* pVideoContentData = new (nothrow) _VideoContentData();
129 SysTryReturnResult(NID_CNT, pVideoContentData != null, E_OUT_OF_MEMORY, "Construct() failed.");
131 __pVideoContentData = pVideoContentData;
145 VideoContentInfo::Construct(const String* pContentPath)
147 SysAssertf(__pVideoContentData == null,
148 "Already constructed. Calling Construct() twice or more on a same instance is not allowed for this class.");
152 result r = E_SUCCESS;
153 _ContentData contentData;
155 if (pContentPath != null)
157 if (!_AppInfo::IsOspCompat())
159 if (pContentPath->StartsWith(OSP_MEDIA_PHONE, 0) || pContentPath->StartsWith(OSP_MEDIA_MMC, 0))
161 SysLogException(NID_CNT, E_INVALID_ARG,
162 "[E_INVALID_ARG] /Media/ and /Storagecard/Media/ are not supported from Tizen 2.0.");
163 return E_INVALID_ARG;
165 if (!(pContentPath->StartsWith(Environment::GetMediaPath(), 0)
166 || pContentPath->StartsWith(Environment::GetExternalStoragePath(), 0)))
168 SysLogException(NID_CNT, E_INVALID_ARG,
169 "[E_INVALID_ARG] %ls is not supported.", pContentPath->GetPointer());
170 return E_INVALID_ARG;
176 if (pContentPath->StartsWith(OSP_MEDIA_PHONE, 0))
178 // Because the content path is saved like /opt/media or /opt/storage/sdcard/ in SLP database,
179 // it should be converted in 2.0.
180 r = (const_cast<String*>(pContentPath))->Replace(OSP_MEDIA_PHONE, Environment::GetMediaPath());
181 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
183 else if (pContentPath->StartsWith(OSP_MEDIA_MMC, 0))
185 r = (const_cast<String*>(pContentPath))->Replace(OSP_MEDIA_MMC, Environment::GetExternalStoragePath());
186 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
190 SysLogException(NID_CNT, E_INVALID_ARG,
191 "[E_INVALID_ARG] The contentPath should start with /Media or /Storagecard/Media.");
192 return E_INVALID_ARG;
196 int length = pContentPath->GetLength();
197 SysTryReturnResult(NID_CNT, length != 0, E_INVALID_ARG,
198 "The length of pContentPath is 0.");
199 SysTryReturnResult(NID_CNT, File::IsFileExist(*pContentPath), E_FILE_NOT_FOUND,
200 "The file corresponding to pContentPath could not be found.");
202 // Sets the content path
203 contentData.contentPath = *pContentPath;
205 // Sets the content type
206 contentData.contentType = CONTENT_TYPE_VIDEO;
208 r = SetContentData(&contentData);
209 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
213 contentData.contentType = CONTENT_TYPE_VIDEO;
215 r = SetContentData(&contentData);
216 SysTryReturnResult(NID_CNT, !IsFailed(r), r, "Construct() failed.");
220 _VideoContentData* pVideoContentData = new (nothrow) _VideoContentData();
221 SysTryReturnResult(NID_CNT, pVideoContentData != null, E_OUT_OF_MEMORY, "Construct() failed.");
223 __pVideoContentData = pVideoContentData;
229 VideoContentInfo::SetVideoContentData(const _VideoContentData* pVideoContentData)
233 SysTryReturnResult(NID_CNT, pVideoContentData != null, E_INVALID_ARG, "pVideoContentData is null.");
235 if (__pVideoContentData == null)
237 __pVideoContentData = new (nothrow) _VideoContentData;
238 SysTryReturnResult(NID_CNT, __pVideoContentData != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
241 __pVideoContentData->width = pVideoContentData->width;
242 __pVideoContentData->height = pVideoContentData->height;
243 __pVideoContentData->framerate = pVideoContentData->framerate;
244 __pVideoContentData->audioBitrate = pVideoContentData->audioBitrate;
245 __pVideoContentData->videoBitrate = pVideoContentData->videoBitrate;
246 __pVideoContentData->duration = pVideoContentData->duration;
248 if (pVideoContentData->pArtist != null)
250 __pVideoContentData->pArtist = new (nothrow) String(*(pVideoContentData->pArtist));
251 SysTryReturnResult(NID_CNT, __pVideoContentData->pArtist != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
253 if (pVideoContentData->pGenre != null)
255 __pVideoContentData->pGenre = new (nothrow) String(*(pVideoContentData->pGenre));
256 SysTryReturnResult(NID_CNT, __pVideoContentData->pGenre != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
258 if (pVideoContentData->pTitle != null)
260 __pVideoContentData->pTitle = new (nothrow) String(*(pVideoContentData->pTitle));
261 SysTryReturnResult(NID_CNT, __pVideoContentData->pTitle != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
263 if (pVideoContentData->pAlbumName != null)
265 __pVideoContentData->pAlbumName = new (nothrow) String(*(pVideoContentData->pAlbumName));
266 SysTryReturnResult(NID_CNT, __pVideoContentData->pAlbumName != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
272 VideoContentInfo::_VideoContentData*
273 VideoContentInfo::GetVideoContentData(void)
275 if (__pVideoContentData == null)
277 __pVideoContentData = new (nothrow) VideoContentInfo::_VideoContentData;
278 SysTryReturn(NID_CNT, __pVideoContentData != null, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
280 return __pVideoContentData;
284 VideoContentInfo::GetGenre(void) const
286 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
288 if (__pVideoContentData->pGenre == null)
290 SysLog(NID_CNT, "GetGenre() failed.");
291 return String(L"Unknown");
294 return *(__pVideoContentData->pGenre);
298 VideoContentInfo::GetArtist(void) const
300 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
302 if (__pVideoContentData->pArtist == null)
304 SysLog(NID_CNT, "GetArtist() failed.");
305 return String(L"Unknown");
308 return *(__pVideoContentData->pArtist);
312 VideoContentInfo::GetBitrate(void) const
314 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
316 if (__pVideoContentData->audioBitrate == 0)
318 // The audio bitrate is not managed in video table.
319 if (this->GetVideoMetadata() != E_SUCCESS)
321 SysLog(NID_CNT, "GetBitrate() failed.");
326 return __pVideoContentData->audioBitrate;
330 VideoContentInfo::GetAudioBitrate(void) const
332 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
334 if (__pVideoContentData->audioBitrate == 0)
336 // The audio bitrate is not managed in video table.
337 if (this->GetVideoMetadata() != E_SUCCESS)
339 SysLog(NID_CNT, "GetAudioBitrate() failed.");
344 return __pVideoContentData->audioBitrate;
348 VideoContentInfo::GetVideoBitrate(void) const
350 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
352 if (__pVideoContentData->videoBitrate == 0)
354 // The video bitrate is not managed in video table.
355 if (this->GetVideoMetadata() != E_SUCCESS)
357 SysLog(NID_CNT, "GetVideoBitrate() failed.");
362 return __pVideoContentData->videoBitrate;
366 VideoContentInfo::GetFramerate(void) const
368 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
370 if (__pVideoContentData->framerate == 0)
372 // The framerate is not managed in video table.
373 if (this->GetVideoMetadata() != E_SUCCESS)
375 SysLog(NID_CNT, "GetFramerate() failed.");
380 return __pVideoContentData->framerate;
384 VideoContentInfo::GetWidth(void) const
386 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
388 return __pVideoContentData->width;
392 VideoContentInfo::GetHeight(void) const
394 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
396 return __pVideoContentData->height;
400 VideoContentInfo::GetTitle(void) const
402 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
404 if (__pVideoContentData->pTitle == null)
406 SysLog(NID_CNT, "GetTitle() failed.");
407 return String(L"Unknown");
410 return *(__pVideoContentData->pTitle);
414 VideoContentInfo::GetAlbumName(void) const
416 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
418 if (__pVideoContentData->pAlbumName == null)
420 SysLog(NID_CNT, "GetAlbumName() failed.");
421 return String(L"Unknown");
424 return *(__pVideoContentData->pAlbumName);
428 VideoContentInfo::GetDuration(void) const
430 SysAssertf(__pVideoContentData != null, "Not yet constructed. Construct() should be called before use.");
432 return __pVideoContentData->duration;
436 VideoContentInfo::GetVideoMetadata(void) const
440 result r = E_SUCCESS;
442 VideoMetadata* pVideoMetadata = ContentManagerUtil::GetVideoMetaN(this->GetContentPath());
444 SysTryReturn(NID_CNT, pVideoMetadata != null, r, r, "[%s] GetVideoMetadata() failed.", GetErrorMessage(r));
447 __pVideoContentData->framerate = pVideoMetadata->GetFramerate();
450 __pVideoContentData->audioBitrate = pVideoMetadata->GetAudioBitrate();
453 __pVideoContentData->videoBitrate = pVideoMetadata->GetVideoBitrate();
455 delete pVideoMetadata;