[content] Change secure log
[platform/framework/native/content.git] / src / FCnt_VideoMetadataImpl.cpp
1 //
2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
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
8 //
9 //     http://www.apache.org/licenses/LICENSE-2.0
10 //
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.
16 //
17 /**
18  * @file                FCnt_VideoMetadataImpl.cpp
19  * @brief               This is the implementation file for the %_VideoMetadataImpl class.
20  *
21  * This file contains implementation of the %_VideoMetadataImpl class.
22  */
23
24 #include <FBaseSysLog.h>
25 #include <FCntVideoMetadata.h>
26 #include <FCnt_VideoMetadataImpl.h>
27 #include <FGrp_BitmapImpl.h>
28
29 using namespace std;
30 using namespace Tizen::Base;
31 using namespace Tizen::Graphics;
32
33 namespace Tizen { namespace Content
34 {
35
36 _VideoMetadataImpl::_VideoMetadataImpl(void)
37         : Object()
38 {
39         unique_ptr<VideoMeta, VideoMetaDeleter> pNewVideoMeta(new (nothrow) VideoMeta());
40         if (pNewVideoMeta != null)
41         {
42                 __pVideoMeta = move(pNewVideoMeta);
43         }
44         else
45         {
46                 __pVideoMeta = null;
47                 SysLog(NID_CNT, "The memory is insufficient.");
48         }
49 }
50
51 _VideoMetadataImpl::~_VideoMetadataImpl(void)
52 {
53
54 }
55
56 _VideoMetadataImpl*
57 _VideoMetadataImpl::GetInstance(VideoMetadata& videoMetadata)
58 {
59         return videoMetadata.__pImpl;
60 }
61
62 const _VideoMetadataImpl*
63 _VideoMetadataImpl::GetInstance(const VideoMetadata& videoMetadata)
64 {
65         return videoMetadata.__pImpl;
66 }
67
68 result
69 _VideoMetadataImpl::SetVideoMetadata(const VideoMeta* pVideoMeta)
70 {
71         ClearLastResult();
72
73         SysTryReturnResult(NID_CNT, pVideoMeta != null, E_INVALID_ARG, "pVideoMeta is null.");
74
75         __pVideoMeta->width = pVideoMeta->width;
76         __pVideoMeta->height = pVideoMeta->height;
77         __pVideoMeta->framerate = pVideoMeta->framerate;
78         __pVideoMeta->audioBitrate = pVideoMeta->audioBitrate;
79         __pVideoMeta->videoBitrate = pVideoMeta->videoBitrate;
80         __pVideoMeta->duration = pVideoMeta->duration;
81         __pVideoMeta->contentPath = pVideoMeta->contentPath;
82
83         if (pVideoMeta->pGenre != null)
84         {
85                 __pVideoMeta->pGenre = new (nothrow) String(*(pVideoMeta->pGenre));
86                 SysTryReturnResult(NID_CNT, __pVideoMeta->pGenre != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
87         }
88         if (pVideoMeta->pComment != null)
89         {
90                 __pVideoMeta->pComment = new (nothrow) String(*(pVideoMeta->pComment));
91                 SysTryReturnResult(NID_CNT, __pVideoMeta->pComment != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
92         }
93         if (pVideoMeta->pDescription != null)
94         {
95                 __pVideoMeta->pDescription = new (nothrow) String(*(pVideoMeta->pDescription));
96                 SysTryReturnResult(NID_CNT, __pVideoMeta->pDescription != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
97         }
98         if (pVideoMeta->pAlbumArt != null)
99         {
100                 __pVideoMeta->pAlbumArt = _BitmapImpl::CloneN(*(pVideoMeta->pAlbumArt));
101                 if (__pVideoMeta->pAlbumArt == null)
102                 {
103                         SysLog(NID_CNT, "_BitmapImpl::CloneN failed.");
104                         // Because album art is one of the metadata, it is not exception in this function but is exception in _AudioMetadataImpl::GetAlbumArtN().
105                 }
106         }
107
108         return E_SUCCESS;
109 }
110
111 VideoMeta*
112 _VideoMetadataImpl::GetVideoMetadata(void) const
113 {
114         return __pVideoMeta.get();
115 }
116
117 _VideoMetadataImpl::_VideoMetadataImpl(const _VideoMetadataImpl& rhs)
118         : Object()
119 {
120         unique_ptr<VideoMeta, VideoMetaDeleter> pNewVideoMeta(new (nothrow) VideoMeta());
121         if (pNewVideoMeta != null)
122         {
123                 pNewVideoMeta->width = (rhs.__pVideoMeta)->width;
124                 pNewVideoMeta->height = (rhs.__pVideoMeta)->height;
125                 pNewVideoMeta->framerate = (rhs.__pVideoMeta)->framerate;
126                 pNewVideoMeta->audioBitrate = (rhs.__pVideoMeta)->audioBitrate;
127                 pNewVideoMeta->videoBitrate = (rhs.__pVideoMeta)->videoBitrate;
128                 pNewVideoMeta->duration = (rhs.__pVideoMeta)->duration;
129                 pNewVideoMeta->contentPath = (rhs.__pVideoMeta)->contentPath;
130
131                 // pGenre
132                 if ((rhs.__pVideoMeta)->pGenre != null)
133                 {
134                         pNewVideoMeta->pGenre = new (nothrow) String(*((rhs.__pVideoMeta)->pGenre));
135                         if (pNewVideoMeta->pGenre == null)
136                         {
137                                 SysLog(NID_CNT, "The memory is insufficient.");
138                                 return;
139                         }
140                 }
141                 // pComment
142                 if ((rhs.__pVideoMeta)->pComment != null)
143                 {
144                         pNewVideoMeta->pComment = new (nothrow) String(*((rhs.__pVideoMeta)->pComment));
145                         if (pNewVideoMeta->pComment == null)
146                         {
147                                 SysLog(NID_CNT, "The memory is insufficient.");
148                                 return;
149                         }
150                 }
151                 // pDescription
152                 if ((rhs.__pVideoMeta)->pDescription != null)
153                 {
154                         pNewVideoMeta->pDescription = new (nothrow) String(*((rhs.__pVideoMeta)->pDescription));
155                         if (pNewVideoMeta->pDescription == null)
156                         {
157                                 SysLog(NID_CNT, "The memory is insufficient.");
158                                 return;
159                         }
160                 }
161                 if ((rhs.__pVideoMeta)->pAlbumArt != null)
162                 {
163                         pNewVideoMeta->pAlbumArt = _BitmapImpl::CloneN(*((rhs.__pVideoMeta)->pAlbumArt));
164                         if (pNewVideoMeta->pAlbumArt == null)
165                         {
166                                 SysLog(NID_CNT, "The memory is insufficient.");
167                                 return;
168                         }
169                 }
170
171                 __pVideoMeta = move(pNewVideoMeta);
172         }
173         else
174         {
175                 __pVideoMeta = null;
176                 SysLog(NID_CNT, "The memory is insufficient.");
177         }
178 }
179
180 _VideoMetadataImpl&
181 _VideoMetadataImpl::operator =(const _VideoMetadataImpl& rhs)
182 {
183         // check for self-assignment
184         if (this == &rhs)
185         {
186                 return *this;
187         }
188
189         // __pVideoMeta
190         if (__pVideoMeta != null && (rhs.__pVideoMeta) != null)
191         {
192                 // DeleteMetadata(__pVideoMeta);
193                 // __pVideoMeta = new (nothrow) VideoMeta;
194
195                 __pVideoMeta.reset(new (nothrow) VideoMeta);
196         }
197         else if (__pVideoMeta != null)
198         {
199                 //DeleteMetadata(__pVideoMeta);
200
201                 __pVideoMeta.reset(null);
202                 return *this;
203         }
204         else if ((rhs.__pVideoMeta) != null)
205         {
206                 //__pVideoMeta = new (nothrow) VideoMeta;
207
208                 __pVideoMeta.reset(new (nothrow) VideoMeta);
209         }
210         else
211         {
212                 // __pVideoMeta and rhs.__pVideoMeta are null.
213                 return *this;
214         }
215
216         __pVideoMeta->width = (rhs.__pVideoMeta)->width;
217         __pVideoMeta->height = (rhs.__pVideoMeta)->height;
218         __pVideoMeta->framerate = (rhs.__pVideoMeta)->framerate;
219         __pVideoMeta->audioBitrate = (rhs.__pVideoMeta)->audioBitrate;
220         __pVideoMeta->videoBitrate = (rhs.__pVideoMeta)->videoBitrate;
221         __pVideoMeta->duration = (rhs.__pVideoMeta)->duration;
222         __pVideoMeta->contentPath = (rhs.__pVideoMeta)->contentPath;
223
224         //pGenre
225         if (__pVideoMeta->pGenre != null && (rhs.__pVideoMeta)->pGenre != null)
226         {
227                 // delete previous data
228                 delete __pVideoMeta->pGenre;
229                 __pVideoMeta->pGenre = null;
230
231                 __pVideoMeta->pGenre = new String(*((rhs.__pVideoMeta)->pGenre));
232         }
233         else if (__pVideoMeta->pGenre != null)
234         {
235                 delete __pVideoMeta->pGenre;
236                 __pVideoMeta->pGenre = null;
237         }
238         else if ((rhs.__pVideoMeta)->pGenre != null)
239         {
240                 __pVideoMeta->pGenre = new String(*((rhs.__pVideoMeta)->pGenre));
241         }
242
243         // pComment
244         if (__pVideoMeta->pComment != null && (rhs.__pVideoMeta)->pComment != null)
245         {
246                 // delete previous data
247                 delete __pVideoMeta->pComment;
248                 __pVideoMeta->pComment = null;
249
250                 __pVideoMeta->pComment = new (nothrow) String(*((rhs.__pVideoMeta)->pComment));
251         }
252         else if (__pVideoMeta->pComment != null)
253         {
254                 delete __pVideoMeta->pComment;
255                 __pVideoMeta->pComment = null;
256         }
257         else if ((rhs.__pVideoMeta)->pComment != null)
258         {
259                 __pVideoMeta->pComment = new (nothrow) String(*((rhs.__pVideoMeta)->pComment));
260         }
261
262         // pDescription
263         if (__pVideoMeta->pDescription != null && (rhs.__pVideoMeta)->pDescription != null)
264         {
265                 // delete previous data
266                 delete __pVideoMeta->pDescription;
267                 __pVideoMeta->pDescription = null;
268
269                 __pVideoMeta->pDescription = new (nothrow) String(*((rhs.__pVideoMeta)->pDescription));
270         }
271         else if (__pVideoMeta->pDescription != null)
272         {
273                 delete __pVideoMeta->pDescription;
274                 __pVideoMeta->pDescription = null;
275         }
276         else if ((rhs.__pVideoMeta)->pDescription != null)
277         {
278                 __pVideoMeta->pDescription = new (nothrow) String(*((rhs.__pVideoMeta)->pDescription));
279         }
280
281         // pAlbumArt
282         if (__pVideoMeta->pAlbumArt != null && (rhs.__pVideoMeta)->pAlbumArt != null)
283         {
284                 // delete previous data
285                 delete __pVideoMeta->pAlbumArt;
286                 __pVideoMeta->pAlbumArt = null;
287
288                 __pVideoMeta->pAlbumArt = _BitmapImpl::CloneN(*((rhs.__pVideoMeta)->pAlbumArt));
289         }
290         else if (__pVideoMeta->pAlbumArt != null)
291         {
292                 delete __pVideoMeta->pAlbumArt;
293                 __pVideoMeta->pAlbumArt = null;
294         }
295         else if ((rhs.__pVideoMeta)->pAlbumArt != null)
296         {
297                 __pVideoMeta->pAlbumArt = _BitmapImpl::CloneN(*((rhs.__pVideoMeta)->pAlbumArt));
298         }
299
300         SysLog(NID_CNT, "_VideoMetadataImpl::operator =(const _VideoMetadataImpl& rhs) is called.");
301         return *this;
302 }
303
304 bool
305 _VideoMetadataImpl::Equals(const Tizen::Base::Object& rhs) const
306 {
307         const _VideoMetadataImpl* pRhs = dynamic_cast <const _VideoMetadataImpl*>(&rhs);
308         if (pRhs == null)
309         {
310                 return false;
311         }
312
313         if (this->GetAudioBitrate() != pRhs->GetAudioBitrate())
314         {
315                 return false;
316         }
317         if (this->GetDuration() != pRhs->GetDuration())
318         {
319                 return false;
320         }
321         if (this->GetFramerate() != pRhs->GetFramerate())
322         {
323                 return false;
324         }
325         if (!((this->GetGenre()).Equals(pRhs->GetGenre())))
326         {
327                 return false;
328         }
329         if (!((this->GetComment()).Equals(pRhs->GetComment())))
330         {
331                 return false;
332         }
333         if (!((this->GetDescription()).Equals(pRhs->GetDescription())))
334         {
335                 return false;
336         }
337         if (this->GetHeight() != pRhs->GetHeight())
338         {
339                 return false;
340         }
341         if (this->GetVideoBitrate() != pRhs->GetVideoBitrate())
342         {
343                 return false;
344         }
345         if (this->GetWidth() != pRhs->GetWidth())
346         {
347                 return false;
348         }
349
350         return true;
351 }
352
353 int
354 _VideoMetadataImpl::GetHashCode(void) const
355 {
356         return Integer::GetHashCode(this->GetAudioBitrate())
357                         ^ Long::GetHashCode(this->GetDuration())
358                         ^ Integer::GetHashCode(this->GetFramerate())
359                         ^ (this->GetGenre()).GetHashCode()
360                         ^ (this->GetComment()).GetHashCode()
361                         ^ (this->GetDescription()).GetHashCode()
362                         ^ Integer::GetHashCode(this->GetHeight())
363                         ^ Integer::GetHashCode(this->GetVideoBitrate())
364                         ^ Integer::GetHashCode(this->GetWidth());
365 }
366
367 int
368 _VideoMetadataImpl::GetWidth(void) const
369 {
370         if (__pVideoMeta == null)
371         {
372                 SysLog(NID_CNT, "__pVideoMeta is null.");
373                 return 0;
374         }
375         return __pVideoMeta->width;
376 }
377
378 int
379 _VideoMetadataImpl::GetHeight(void) const
380 {
381         if (__pVideoMeta == null)
382         {
383                 SysLog(NID_CNT, "__pVideoMeta is null.");
384                 return 0;
385         }
386         return __pVideoMeta->height;
387 }
388
389 long
390 _VideoMetadataImpl::GetDuration(void) const
391 {
392         if (__pVideoMeta == null)
393         {
394                 SysLog(NID_CNT, "__pVideoMeta is null.");
395                 return 0;
396         }
397         return __pVideoMeta->duration;
398 }
399
400 int
401 _VideoMetadataImpl::GetFramerate(void) const
402 {
403         if (__pVideoMeta == null)
404         {
405                 SysLog(NID_CNT, "__pVideoMeta is null.");
406                 return 0;
407         }
408         return __pVideoMeta->framerate;
409 }
410
411 int
412 _VideoMetadataImpl::GetAudioBitrate(void) const
413 {
414         if (__pVideoMeta == null)
415         {
416                 SysLog(NID_CNT, "__pVideoMeta is null.");
417                 return 0;
418         }
419         return __pVideoMeta->audioBitrate;
420 }
421
422 int
423 _VideoMetadataImpl::GetVideoBitrate(void) const
424 {
425         if (__pVideoMeta == null)
426         {
427                 SysLog(NID_CNT, "__pVideoMeta is null.");
428                 return 0;
429         }
430         return __pVideoMeta->videoBitrate;
431 }
432
433 String
434 _VideoMetadataImpl::GetGenre(void) const
435 {
436         if (__pVideoMeta == null || __pVideoMeta->pGenre == null)
437         {
438                 SysLog(NID_CNT, "__pVideoMeta or __pVideoMeta->pGenre is null.");
439                 return String();
440         }
441         return *(__pVideoMeta->pGenre);
442 }
443
444 String
445 _VideoMetadataImpl::GetComment(void) const
446 {
447         if (__pVideoMeta == null || __pVideoMeta->pComment == null)
448         {
449                 SysLog(NID_CNT, "__pVideoMeta or __pVideoMeta->pComment is null.");
450                 return String();
451         }
452         return *(__pVideoMeta->pComment);
453 }
454
455 String
456 _VideoMetadataImpl::GetDescription(void) const
457 {
458         if (__pVideoMeta == null || __pVideoMeta->pDescription == null)
459         {
460                 SysLog(NID_CNT, "__pVideoMeta or __pVideoMeta->pDescription is null.");
461                 return String();
462         }
463         return *(__pVideoMeta->pDescription);
464 }
465
466 //
467 // E_SUCCESS
468 // E_DATA_NOT_FOUND
469 // - E_OUT_OF_MEMORY
470 //
471 Bitmap*
472 _VideoMetadataImpl::GetAlbumArtN(void) const
473 {
474         // E_SUCCESS, E_DATA_NOT_FOUND, E_OUT_OF_MEMORY
475
476         ClearLastResult();
477
478         if (__pVideoMeta == null || __pVideoMeta->pAlbumArt == null)
479         {
480                 SysLogException(NID_CNT, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] __pVideoMeta or __pVideoMeta->pAlbumArt is null.");
481                 return null;
482         }
483
484         Bitmap* pBitmap = _BitmapImpl::CloneN(*(__pVideoMeta->pAlbumArt));
485         SysTryReturn(NID_CNT, pBitmap != null, null, E_DATA_NOT_FOUND, "[E_DATA_NOT_FOUND] _BitmapImpl::CloneN failed.");
486
487         return pBitmap;
488 }
489 }}