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 <unique_ptr.h>
24 #include <FBaseSysLog.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>
32 #include "FCnt_VideoContentInfoImpl.h"
35 using namespace Tizen::App;
36 using namespace Tizen::Base;
37 using namespace Tizen::Io;
38 using namespace Tizen::Locations;
39 using namespace Tizen::System;
41 namespace Tizen { namespace Content
44 _VideoContentInfoImpl::_VideoContentInfoImpl(void)
59 _VideoContentInfoImpl::~_VideoContentInfoImpl(void)
64 _VideoContentInfoImpl*
65 _VideoContentInfoImpl::GetInstance(VideoContentInfo& videoContentInfo)
67 return videoContentInfo.__pVideoContentInfoImpl;
70 const _VideoContentInfoImpl*
71 _VideoContentInfoImpl::GetInstance(const VideoContentInfo& videoContentInfo)
73 return videoContentInfo.__pVideoContentInfoImpl;
77 _VideoContentInfoImpl::Construct(const String& contentPath, const String& thumbnailPath, bool setGps)
80 String tempPath(contentPath);
82 if (_AppInfo::GetApiVersion() == _API_VERSION_2_0 && _AppInfo::IsOspCompat())
84 if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0))
86 // Because the content path is saved like /opt/media or /opt/storage/sdcard/ in SLP database,
87 // it should be converted in 2.0.
88 r = tempPath.Replace(OSP_MEDIA_PHONE, Environment::GetMediaPath());
89 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
91 else if (contentPath.StartsWith(OSP_MEDIA_MMC, 0))
93 r = tempPath.Replace(OSP_MEDIA_MMC, Environment::GetExternalStoragePath());
94 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
98 SysLogException(NID_CNT, E_INVALID_ARG,
99 "[E_INVALID_ARG] The contentPath should start with /Media or /Storagecard/Media.");
100 return E_INVALID_ARG;
105 SysTryReturnResult(NID_CNT, _FileImpl::IsMediaPath(contentPath), E_INVALID_ARG,
106 "The contentPath should start with /Media or /Storagecard/Media.");
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 SetContentPath(tempPath);
122 SetContentType(CONTENT_TYPE_VIDEO);
128 _VideoContentInfoImpl::Construct(const String* pContentPath)
130 result r = E_SUCCESS;
132 if (pContentPath != null)
134 String contentPath(*pContentPath);
136 if (!_AppInfo::IsOspCompat())
138 if (!(contentPath.StartsWith(Environment::GetMediaPath(), 0)
139 || contentPath.StartsWith(Environment::GetExternalStoragePath(), 0)))
141 SysLogException(NID_CNT, E_INVALID_ARG, "[E_INVALID_ARG] The path is not supported.");
142 return E_INVALID_ARG;
148 if (contentPath.StartsWith(OSP_MEDIA_PHONE, 0))
150 // Because the content path is saved like /opt/media or /opt/storage/sdcard/ in SLP database,
151 // it should be converted in 2.0.
152 r = contentPath.Replace(OSP_MEDIA_PHONE, Environment::GetMediaPath());
153 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
155 else if (contentPath.StartsWith(OSP_MEDIA_MMC, 0))
157 r = contentPath.Replace(OSP_MEDIA_MMC, Environment::GetExternalStoragePath());
158 SysTryReturnResult(NID_CNT, !IsFailed(r), E_INVALID_ARG, "Construct() failed.");
162 SysLogException(NID_CNT, E_INVALID_ARG,
163 "[E_INVALID_ARG] The contentPath should start with /Media or /Storagecard/Media.");
164 return E_INVALID_ARG;
168 int length = contentPath.GetLength();
169 SysTryReturnResult(NID_CNT, length != 0, E_INVALID_ARG,
170 "The length of pContentPath is 0.");
171 SysTryReturnResult(NID_CNT, File::IsFileExist(*pContentPath), E_FILE_NOT_FOUND,
172 "The file corresponding to pContentPath could not be found.");
174 SetContentPath(contentPath);
175 SetContentType(CONTENT_TYPE_VIDEO);
179 SetContentType(CONTENT_TYPE_VIDEO);
186 _VideoContentInfoImpl::GetGenre(void) const
188 if (__genre.IsEmpty())
190 SysLog(NID_CNT, "Genre is empty.");
191 return String(L"Unknown");
198 _VideoContentInfoImpl::GetArtist(void) const
200 if (__artist.IsEmpty())
202 SysLog(NID_CNT, "Artist is empty.");
203 return String(L"Unknown");
210 _VideoContentInfoImpl::GetBitrate(void) const
212 return __audioBitrate;
216 _VideoContentInfoImpl::GetAudioBitrate(void) const
218 if (__audioBitrate == 0)
220 result r = GetVideoMetadata();
221 SysTryLogReturn(NID_CNT, !IsFailed(r), __audioBitrate, "GetVideoMetadata failed.");
224 return __audioBitrate;
228 _VideoContentInfoImpl::GetVideoBitrate(void) const
230 if (__videoBitrate == 0)
232 result r = GetVideoMetadata();
233 SysTryLogReturn(NID_CNT, !IsFailed(r), __videoBitrate, "GetVideoMetadata failed.");
236 return __videoBitrate;
240 _VideoContentInfoImpl::GetFramerate(void) const
242 if (__framerate == 0)
244 result r = GetVideoMetadata();
245 SysTryLogReturn(NID_CNT, !IsFailed(r), __framerate, "GetVideoMetadata failed.");
252 _VideoContentInfoImpl::GetWidth(void) const
258 _VideoContentInfoImpl::GetHeight(void) const
264 _VideoContentInfoImpl::GetTitle(void) const
266 if (__title.IsEmpty())
268 SysLog(NID_CNT, "Title is empty.");
269 return String(L"Unknown");
276 _VideoContentInfoImpl::GetAlbumName(void) const
278 if (__albumName.IsEmpty())
280 SysLog(NID_CNT, "AlbumName is empty.");
281 return String(L"Unknown");
288 _VideoContentInfoImpl::GetDuration(void) const
294 _VideoContentInfoImpl::GetVideoRecordedDate(void) const
296 return __recordedDate;
300 _VideoContentInfoImpl::SetGenre(const Tizen::Base::String& genre)
306 _VideoContentInfoImpl::SetArtist(const Tizen::Base::String& artist)
312 _VideoContentInfoImpl::SetBitrate(int bitrate)
314 __audioBitrate = bitrate;
318 _VideoContentInfoImpl::SetAudioBitrate(int audioBitrate)
320 __audioBitrate = audioBitrate;
324 _VideoContentInfoImpl::SetVideoBitrate(int videoBitrate)
326 __videoBitrate = videoBitrate;
330 _VideoContentInfoImpl::SetFramerate(int framerate)
332 __framerate = framerate;
336 _VideoContentInfoImpl::SetWidth(int width)
342 _VideoContentInfoImpl::SetHeight(int height)
348 _VideoContentInfoImpl::SetTitle(const Tizen::Base::String& title)
354 _VideoContentInfoImpl::SetAlbumName(const Tizen::Base::String& albumName)
356 __albumName = albumName;
360 _VideoContentInfoImpl::SetDuration(long duration)
362 __duration = duration;
366 _VideoContentInfoImpl::SetVideoRecordedDate(const DateTime& recordedDate)
368 __recordedDate = recordedDate;
372 _VideoContentInfoImpl::GetVideoMetadata(void) const
374 unique_ptr< VideoMetadata > pVideoMetadata(ContentManagerUtil::GetVideoMetaN(GetContentPath()));
375 result r = GetLastResult();
376 SysTryReturn(NID_CNT, pVideoMetadata != null, r, r, "[%s] Failed to perform GetVideoMetadata operation.", GetErrorMessage(r));
379 __framerate = pVideoMetadata->GetFramerate();
382 __audioBitrate = pVideoMetadata->GetAudioBitrate();
385 __videoBitrate = pVideoMetadata->GetVideoBitrate();