2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <FBaseSysLog.h>
19 #include "FMediaMediaStreamInfo.h"
20 #include "FMedia_MediaStreamInfoImpl.h"
23 using namespace Tizen::Base;
24 using namespace Tizen::Base::Collection;
26 namespace Tizen { namespace Media
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)
34 __albumTitle = albumTitle;
36 __pAlbumArt = pAlbumArt;
38 __pAudioStreamList = pAudioStream;
39 __pVideoStreamList = pVideoStream;
40 __audioStreamListException = audioStreamException;
41 __videoStreamListException = videoStreamException;
45 _MediaStreamInfoImpl::~_MediaStreamInfoImpl()
47 if (__pAudioStreamList != null)
49 __pAudioStreamList->RemoveAll(true);
52 if (__pVideoStreamList != null)
54 __pVideoStreamList->RemoveAll(true);
64 _MediaStreamInfoImpl::_MediaStreamInfoImpl(const _MediaStreamInfoImpl& rhs)
67 __title = rhs.__title;
68 __artist = rhs.__artist;
69 __albumTitle = rhs.__albumTitle;
70 __genre = rhs.__genre;
72 __audioStreamListException = rhs.__audioStreamListException;
73 __videoStreamListException = rhs.__videoStreamListException;
76 __pAlbumArt = new (std::nothrow) ByteBuffer;
77 __pAlbumArt->Construct(*rhs.__pAlbumArt);
84 if (rhs.__pAudioStreamList)
86 __pAudioStreamList = new (std::nothrow) Tizen::Base::Collection::ArrayList();
87 if (__pAudioStreamList)
89 for (int i = 0; i < rhs.__pAudioStreamList->GetCount() ; i++)
91 AudioStreamInfo *pAudioSteamInfo = null;
92 AudioStreamInfo *pSrcInfo = dynamic_cast<AudioStreamInfo*>(rhs.__pAudioStreamList->GetAt(i));
95 pAudioSteamInfo = new (std::nothrow) AudioStreamInfo(*pSrcInfo);
96 if (pAudioSteamInfo != null)
98 __pAudioStreamList->Add(*pAudioSteamInfo);
106 __pAudioStreamList = null;
109 if (rhs.__pVideoStreamList )
111 __pVideoStreamList = new (std::nothrow) Tizen::Base::Collection::ArrayList();
112 if (__pVideoStreamList)
114 for (int i = 0; i < rhs.__pVideoStreamList->GetCount() ; i++)
116 VideoStreamInfo *pVideoSteamInfo = null;
117 VideoStreamInfo *pSrcInfo = dynamic_cast<VideoStreamInfo*>(rhs.__pVideoStreamList->GetAt(i));
118 if (pSrcInfo != null)
120 pVideoSteamInfo = new (std::nothrow) VideoStreamInfo(*pSrcInfo);
121 if (pVideoSteamInfo != null)
123 __pVideoStreamList->Add(*pVideoSteamInfo);
131 __pVideoStreamList = null;
136 _MediaStreamInfoImpl::Equals(const Object& obj) const
138 const _MediaStreamInfoImpl* pMediaStreaInfoImpl = dynamic_cast <const _MediaStreamInfoImpl *> (&obj);
139 if (this == pMediaStreaInfoImpl)
143 if (!pMediaStreaInfoImpl)
147 if (__year != pMediaStreaInfoImpl->__year)
151 if (!__title.Equals(pMediaStreaInfoImpl->__title))
155 if (!__artist.Equals( pMediaStreaInfoImpl->__artist))
159 if (!__albumTitle.Equals(pMediaStreaInfoImpl->__albumTitle))
163 if (!__genre.Equals(pMediaStreaInfoImpl->__genre))
169 if (pMediaStreaInfoImpl->__pAlbumArt)
171 if (!__pAlbumArt->Equals( *pMediaStreaInfoImpl->__pAlbumArt))
181 else if (pMediaStreaInfoImpl->__pAlbumArt)
185 if (__pAudioStreamList)
187 if (pMediaStreaInfoImpl->__pAudioStreamList)
189 if (__pAudioStreamList->GetCount() == pMediaStreaInfoImpl->__pAudioStreamList->GetCount())
191 for (int i = 0; i < __pAudioStreamList->GetCount() ; i++)
193 if (!__pAudioStreamList->GetAt(i)->Equals(*pMediaStreaInfoImpl->__pAudioStreamList->GetAt(i)))
209 else if (pMediaStreaInfoImpl->__pAudioStreamList)
213 if (__pVideoStreamList)
215 if (pMediaStreaInfoImpl->__pVideoStreamList)
217 if (__pVideoStreamList->GetCount() == pMediaStreaInfoImpl->__pVideoStreamList->GetCount())
219 for (int i = 0; i < __pVideoStreamList->GetCount() ; i++)
221 if (!__pVideoStreamList->GetAt(i)->Equals(*pMediaStreaInfoImpl->__pVideoStreamList->GetAt(i)))
237 else if (pMediaStreaInfoImpl->__pVideoStreamList)
246 _MediaStreamInfoImpl::GetHashCode(void) const
248 int hashAlbumArt = 0;
249 int hashAudioStream = 0;
250 int hashVideoStream = 0;
251 int hashMediaItems = 0;
255 hashAlbumArt = __pAlbumArt->GetHashCode();
258 hashMediaItems = __year + __title.GetHashCode() + __albumTitle.GetHashCode() + __artist.GetHashCode() + __genre.GetHashCode();
260 if (__pAudioStreamList)
262 for (int i = 0; i < __pAudioStreamList->GetCount(); i++ )
264 hashAudioStream = ((hashAudioStream) + (__pAudioStreamList->GetAt(i)->GetHashCode()));
268 if (__pVideoStreamList)
270 for (int i = 0; i < __pVideoStreamList->GetCount(); i++ )
272 hashVideoStream = ((hashVideoStream) + (__pVideoStreamList->GetAt(i)->GetHashCode()));
276 return (hashAlbumArt + hashAudioStream + hashVideoStream + hashMediaItems);
280 _MediaStreamInfoImpl::GetTitle() const
286 _MediaStreamInfoImpl::GetArtist(void) const
292 _MediaStreamInfoImpl::GetAlbumTitle(void) const
298 _MediaStreamInfoImpl::GetYear(void) const
304 _MediaStreamInfoImpl::GetGenre(void) const
310 _MediaStreamInfoImpl::GetAlbumArtN(void) const
312 ByteBuffer *pByteBuffer = null;
313 result r = E_SUCCESS;
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));
333 _MediaStreamInfoImpl::GetAudioStreamInfoList() const
335 SetLastResult(__audioStreamListException);
336 return __pAudioStreamList;
340 _MediaStreamInfoImpl::GetVideoStreamInfoList() const
342 SetLastResult(__videoStreamListException);
343 return __pVideoStreamList;