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