Tizen 2.0 Release
[framework/osp/media.git] / src / FMedia_MediaStreamInfoImpl.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 #include <FBaseSysLog.h>
19 #include "FMediaMediaStreamInfo.h"
20 #include "FMedia_MediaStreamInfoImpl.h"
21
22
23 using namespace Tizen::Base;
24 using namespace Tizen::Base::Collection;
25
26 namespace Tizen { namespace Media
27 {
28
29 _MediaStreamInfoImpl::_MediaStreamInfoImpl(const Tizen::Base::String& title, const Tizen::Base::String& artist, const Tizen::Base::String& albumTitle, const Tizen::Base::String& genre, int year, Tizen::Base::ByteBuffer* pAlbumArt, Tizen::Base::Collection::IList* pAudioStream, Tizen::Base::Collection::IList* pVideoStream, result audioStreamException, result videoStreamException)
30 {
31         __year = year;
32         __title = title;
33         __artist = artist;
34         __albumTitle = albumTitle;
35         __genre = genre;
36         __pAlbumArt = pAlbumArt;
37
38         __pAudioStreamList = pAudioStream;
39         __pVideoStreamList = pVideoStream;
40         __audioStreamListException = audioStreamException;
41         __videoStreamListException = videoStreamException;
42
43 }
44
45 _MediaStreamInfoImpl::~_MediaStreamInfoImpl()
46 {
47         if (__pAudioStreamList != null)
48         {
49                 __pAudioStreamList->RemoveAll(true);
50         }
51
52         if (__pVideoStreamList != null)
53         {
54                 __pVideoStreamList->RemoveAll(true);
55         }
56         if (__pAlbumArt)
57         {
58                 delete __pAlbumArt;
59                 __pAlbumArt = null;
60         }
61
62 }
63
64 _MediaStreamInfoImpl::_MediaStreamInfoImpl(const _MediaStreamInfoImpl& rhs)
65 {
66         __year = rhs.__year;
67         __title = rhs.__title;
68         __artist = rhs.__artist;
69         __albumTitle = rhs.__albumTitle;
70         __genre = rhs.__genre;
71
72         __audioStreamListException = rhs.__audioStreamListException;
73         __videoStreamListException = rhs.__videoStreamListException;
74         if (rhs.__pAlbumArt)
75         {
76                 __pAlbumArt = new (std::nothrow) ByteBuffer;
77                 __pAlbumArt->Construct(*rhs.__pAlbumArt);
78         }
79         else
80         {
81                 __pAlbumArt = null;
82         }
83
84         if (rhs.__pAudioStreamList)
85         {
86                 __pAudioStreamList = new (std::nothrow) Tizen::Base::Collection::ArrayList();
87                 if (__pAudioStreamList)
88                 {
89                         for (int i = 0; i < rhs.__pAudioStreamList->GetCount() ; i++)
90                         {
91                                 AudioStreamInfo *pAudioSteamInfo = null;
92                                 AudioStreamInfo *pSrcInfo = dynamic_cast<AudioStreamInfo*>(rhs.__pAudioStreamList->GetAt(i));
93                                         if (pSrcInfo != null)
94                                         {
95                                                 pAudioSteamInfo = new (std::nothrow) AudioStreamInfo(*pSrcInfo);
96                                                         if (pAudioSteamInfo != null)
97                                                         {
98                                                                 __pAudioStreamList->Add(*pAudioSteamInfo);
99                                                         }
100                                         }
101                         }
102                 }
103         }
104         else
105         {
106                 __pAudioStreamList = null;
107         }
108
109         if (rhs.__pVideoStreamList )
110         {
111                 __pVideoStreamList = new (std::nothrow) Tizen::Base::Collection::ArrayList();
112                 if (__pVideoStreamList)
113                 {
114                         for (int i = 0; i < rhs.__pVideoStreamList->GetCount() ; i++)
115                         {
116                                 VideoStreamInfo *pVideoSteamInfo = null;
117                                 VideoStreamInfo *pSrcInfo = dynamic_cast<VideoStreamInfo*>(rhs.__pVideoStreamList->GetAt(i));
118                                 if (pSrcInfo != null)
119                                 {
120                                         pVideoSteamInfo = new (std::nothrow) VideoStreamInfo(*pSrcInfo);
121                                         if (pVideoSteamInfo != null)
122                                         {
123                                                 __pVideoStreamList->Add(*pVideoSteamInfo);
124                                         }
125                                 }
126                         }
127                 }
128         }
129         else
130         {
131                 __pVideoStreamList = null;
132         }
133 }
134
135 bool
136 _MediaStreamInfoImpl::Equals(const Object& obj) const
137 {
138         const _MediaStreamInfoImpl* pMediaStreaInfoImpl = dynamic_cast <const _MediaStreamInfoImpl *> (&obj);
139         if (this == pMediaStreaInfoImpl)
140         {
141                 return true;
142         }
143         if (!pMediaStreaInfoImpl)
144         {
145                 return false;
146         }
147         if (__year != pMediaStreaInfoImpl->__year)
148         {
149                 return false;
150         }
151         if (!__title.Equals(pMediaStreaInfoImpl->__title))
152         {
153                 return false;
154         }
155         if (!__artist.Equals( pMediaStreaInfoImpl->__artist))
156         {
157                 return false;
158         }
159         if (!__albumTitle.Equals(pMediaStreaInfoImpl->__albumTitle))
160         {
161                 return false;
162         }
163         if (!__genre.Equals(pMediaStreaInfoImpl->__genre))
164         {
165                 return false;
166         }
167         if (__pAlbumArt)
168         {
169                 if (pMediaStreaInfoImpl->__pAlbumArt)
170                 {
171                         if (!__pAlbumArt->Equals( *pMediaStreaInfoImpl->__pAlbumArt))
172                         {
173                                 return false;
174                         }
175                 }
176                 else
177                 {
178                         return false;
179                 }
180         }
181         else if (pMediaStreaInfoImpl->__pAlbumArt)
182         {
183                 return false;
184         }
185         if (__pAudioStreamList)
186         {
187                 if (pMediaStreaInfoImpl->__pAudioStreamList)
188                 {
189                         if (__pAudioStreamList->GetCount() == pMediaStreaInfoImpl->__pAudioStreamList->GetCount())
190                         {
191                                 for (int i = 0; i < __pAudioStreamList->GetCount() ; i++)
192                                 {
193                                         if (!__pAudioStreamList->GetAt(i)->Equals(*pMediaStreaInfoImpl->__pAudioStreamList->GetAt(i)))
194                                         {
195                                                 return false;
196                                         }
197                                 }
198                         }
199                         else
200                         {
201                                 return false;
202                         }
203                 }
204                 else
205                 {
206                         return false;
207                 }
208         }
209         else if (pMediaStreaInfoImpl->__pAudioStreamList)
210         {
211                 return false;
212         }
213         if (__pVideoStreamList)
214         {
215                 if (pMediaStreaInfoImpl->__pVideoStreamList)
216                 {
217                         if (__pVideoStreamList->GetCount() == pMediaStreaInfoImpl->__pVideoStreamList->GetCount())
218                         {
219                                 for (int i = 0; i < __pVideoStreamList->GetCount() ; i++)
220                                 {
221                                         if (!__pVideoStreamList->GetAt(i)->Equals(*pMediaStreaInfoImpl->__pVideoStreamList->GetAt(i)))
222                                         {
223                                                 return false;
224                                         }
225                                 }
226                         }
227                         else
228                         {
229                                 return false;
230                         }
231                 }
232                 else
233                 {
234                         return false;
235                 }
236         }
237         else if (pMediaStreaInfoImpl->__pVideoStreamList)
238         {
239                 return false;
240         }
241         return true;
242
243 }
244
245 int
246 _MediaStreamInfoImpl::GetHashCode(void) const
247 {
248         int hashAlbumArt = 0;
249         int hashAudioStream = 0;
250         int hashVideoStream = 0;
251         int hashMediaItems = 0;
252
253         if (__pAlbumArt)
254         {
255                 hashAlbumArt = __pAlbumArt->GetHashCode();
256         }
257
258         hashMediaItems = __year + __title.GetHashCode() + __albumTitle.GetHashCode() + __artist.GetHashCode() + __genre.GetHashCode();
259
260         if (__pAudioStreamList)
261         {
262                 for (int i = 0; i < __pAudioStreamList->GetCount(); i++ )
263                 {
264                         hashAudioStream = ((hashAudioStream) + (__pAudioStreamList->GetAt(i)->GetHashCode()));
265                 }
266         }
267
268         if (__pVideoStreamList)
269         {
270                 for (int i = 0; i < __pVideoStreamList->GetCount(); i++ )
271                 {
272                         hashVideoStream = ((hashVideoStream) + (__pVideoStreamList->GetAt(i)->GetHashCode()));
273                 }
274         }
275
276         return (hashAlbumArt + hashAudioStream + hashVideoStream + hashMediaItems);
277 }
278
279 String
280 _MediaStreamInfoImpl::GetTitle() const
281 {
282         return __title;
283 }
284
285 String
286 _MediaStreamInfoImpl::GetArtist(void) const
287 {
288         return __artist;
289 }
290
291 String
292 _MediaStreamInfoImpl::GetAlbumTitle(void) const
293 {
294         return __albumTitle;
295 }
296
297 int
298 _MediaStreamInfoImpl::GetYear(void) const
299 {
300         return __year;
301 }
302
303 String
304 _MediaStreamInfoImpl::GetGenre(void) const
305 {
306         return __genre;
307 }
308
309 ByteBuffer*
310 _MediaStreamInfoImpl::GetAlbumArtN(void) const
311 {
312         ByteBuffer *pByteBuffer = null;
313         result r = E_SUCCESS;
314         if (__pAlbumArt)
315         {
316
317                 pByteBuffer = new (std::nothrow) ByteBuffer;
318                 SysTryReturn(NID_MEDIA, pByteBuffer, null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Memory allocation failed.");
319                 r = pByteBuffer->Construct(*__pAlbumArt);
320                 SysTryCatch(NID_MEDIA, r == E_SUCCESS, , r, "[%s] propagating", GetErrorMessage(r));
321                 return pByteBuffer;
322         }
323         return null;
324 CATCH:
325
326         delete pByteBuffer;
327         pByteBuffer = null;
328
329         return null;
330 }
331
332 const IList*
333 _MediaStreamInfoImpl::GetAudioStreamInfoList() const
334 {
335         SetLastResult(__audioStreamListException);
336         return __pAudioStreamList;
337 }
338
339 const IList*
340 _MediaStreamInfoImpl::GetVideoStreamInfoList() const
341 {
342         SetLastResult(__videoStreamListException);
343         return __pVideoStreamList;
344 }
345
346 };
347 };