Beta merge 2
[profile/ivi/wrt-plugins-tizen.git] / src / platform / Tizen / Mediacontent / Mediacontent.cpp
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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 #include <dpl/log/log.h>
18 #include <dpl/scoped_ptr.h>
19
20 #include "Mediacontent.h"
21 #include "MediacontentManager.h"
22 #include "MediaFilterValidator.h"
23 #include "MediaSearchVisitor.h"
24
25 #include <mm_file.h>
26 #include <mm_error.h>
27
28
29
30 using namespace TizenApis::Api::Mediacontent;
31 using namespace WrtDeviceApis::Commons;
32
33 #define MEDIA_DEBUG 0
34
35 const string SELECT_FOLDER_QUERY = 
36         "select uuid, path, title, storage_type,modified_date from (select uuid, path, folder_name as title, storage_type,modified_date from visual_folder where valid=1 union select _id, path, folder_name as title, storage_type,modified_date from audio_folder) where 1 ";
37
38 const string VIEW_MEDIA_QUERY_WITH_FOLDER =
39         "select media_uuid, folder_uuid, content_type, display_name, path, thumbnail_path,created_date, released_date, modified_date, description,rating, album, artist, last_played_time, played_count,longitude, latitude, width, height, orientation, genre, author, duration, folder_name, folder_path from \
40 (select media_uuid,folder_uuid, content_type, display_name, path, thumbnail_path,null as created_date, released_date, modified_date, description,rating, album, artist, last_played_time, null as played_count,longitude, latitude, width, height, orientation,null as genre, null as author, duration from visual_media join \
41         (select * from \
42                 (select media_uuid, longitude, latitude, description, width, height, datetaken as released_date, orientation,null as album, null as artist, null as last_played_time,null as duration from image_meta \
43                 union all \
44                 select media_uuid, longitude, latitude, description, width, height, datetaken as released_date, null as orientation, album, artist, last_played_time,duration from video_meta)) \
45 on uuid=media_uuid \
46 union all \
47         select audio_id, folder_id as folder_uuid, content_type, title as display_name, path, thumbnail_path, added_time, year, modified_date, description, favourite, album, artist, last_played_time, played_count, null as longitude, null as latitude, null as width, null as height, null as orientation, genre, author, duration from audio_media) \
48 join ( select uuid as folder_id, path as folder_path, folder_name, modified_date as folder_modified_date, storage_type from visual_folder \
49 union all \
50         select _id as folder_id, path, folder_name, modified_date, storage_type from audio_folder) \
51 on folder_uuid=folder_id where 1 ";
52
53 const string SELECT_MEDIA_ID_WITH_FOLDER = 
54         "select item_id from item_view where folder_uuid=";
55 const string SELECT_EXTRA_AUDIO = 
56         "select copyright,bitrate,track_num,size from audio_media where audio_id=";
57
58
59 namespace TizenApis {
60 namespace Platform {
61 namespace Mediacontent{
62
63 Mediacontent::Mediacontent()
64 {
65     LogDebug("entered");
66
67 //      int ret;
68
69         db_connnect_count++;
70
71         db_util_open(MEDIA_DB_PATH, &hDBCt, 0);
72         LogDebug("hDBCt:" << hDBCt);            
73 }
74
75 Mediacontent::~Mediacontent()
76 {
77     LogDebug("entered");
78         int ret;
79         db_connnect_count--;
80         if(db_connnect_count == 0)
81         {
82                 ret = db_util_close(hDBCt);
83                 if(ret != SQLITE_OK)
84                         ret = -1;
85                 else
86                         hDBCt = NULL;
87         }
88 }
89
90 tm Mediacontent::toDateTm(time_t date)
91 {
92         tm tm_date;
93         
94         tm_date.tm_year = (date / 10000) - 1900;
95         tm_date.tm_mon = ((date - ((tm_date.tm_year + 1900) * 10000)) / 100) - 1;
96         tm_date.tm_mday = (date - ((tm_date.tm_year + 1900) * 10000) - tm_date.tm_mon * 100);
97
98         return tm_date;
99 }       
100
101
102 void Mediacontent::convertToPlatformFolder(folder_s &media_folder, MediacontentFolderPtr& newFolder)
103 {
104         if(media_folder.folder_uuid != NULL)
105         {
106                 newFolder->setFolderUUID(media_folder.folder_uuid);
107         }
108         if(media_folder.folder_path != NULL)
109         {
110                 newFolder->setFolderName(media_folder.folder_name);
111         }
112         if(media_folder.folder_name != NULL)
113         {
114                 newFolder->setFolderPath(media_folder.folder_path);
115         }
116
117         newFolder->setFolderModifiedDate(toDateTm(media_folder.modified_date));
118
119         string storageType;
120         
121         if(media_folder.storage_type == 0)
122         {
123                 storageType = "INTERNAL";
124         }
125         else if( media_folder.storage_type == 1)
126         {
127                 storageType = "EXTERNAL";
128         }
129         else
130         {
131                 storageType = "UNKNOWN";
132         }
133         newFolder->setFolderStorageType(storageType);
134 }
135
136
137
138 string Mediacontent::makeQuerySortMode(SortModeArrayPtr attr)
139 {
140         string query("");
141         string attriName;
142         int cnt = 0;
143         SortModeArray::iterator it = attr->begin();
144         
145         for (;it!=attr->end(); ++it) 
146         {
147                 attriName = (*it)->getAttributeName();
148                 //convert to attribue's name
149                 MediaSearchVisitor visitor;
150                 attriName = visitor.getPlatformAttr(attriName);
151                 if (attriName.compare("") != 0) 
152                 { 
153                         if (cnt == 0) 
154                         {
155                                 query.append(" ORDER BY ");
156                         } else 
157                         {
158                                 query.append(", ");
159                         }
160                         query.append(attriName);
161
162                         if ((*it)->getOrder() == Api::Tizen::ASCENDING_SORT_ORDER) 
163                         {
164                                 query.append(" ASC");
165                         } 
166                         else 
167                         {
168                                 query.append(" DESC");
169                         }
170                         cnt++;
171                 }
172         }
173
174         return query;
175 }
176
177
178
179 void Mediacontent::OnRequestReceived(const IEventFindFolderPtr &eFolder)
180 {
181     LogDebug("entered");
182
183         string projection;
184         string sortMode;
185         string limitOffset;
186         string condition;
187         string query(SELECT_FOLDER_QUERY);
188
189         //set condition
190         MediaSearchVisitorPtr visitor(new MediaSearchVisitor());
191         
192         if(eFolder->getFilterIsSet())
193         {
194                 FilterPtr filter = eFolder->getFilter();
195
196                 FilterValidatorPtr validator = MediaFilterValidatorFactory::getMediaFilterValidator(MediaFilterValidatorFactory::QUERY_FOLDER);
197                 bool success = filter->validate(validator);
198
199                 if(!success)
200                         ThrowMsg(InvalidArgumentException, "Invalid filter arguments.");
201
202                 IFilterVisitorPtr IVisitor = DPL::StaticPointerCast<IFilterVisitor>(visitor);
203
204                 visitor->setQueryType(MediaSearchVisitor::QUERY_FOLDER);
205                 filter->travel(IVisitor);
206                 condition = visitor->getResult();
207
208                 query.append(" and ");
209                 query.append(condition);
210         }
211
212         if(eFolder->getSortModesIsSet()) 
213         {
214                 sortMode = makeQuerySortMode(eFolder->getSortModes());  
215
216                 query.append(sortMode);
217         }
218         
219         //set limit/offset
220         if (eFolder->getLimitIsSet()) 
221         {
222                 limitOffset.append(" LIMIT ");
223                 std::stringstream limitStream;
224                 limitStream << eFolder->getLimit();
225                 limitOffset.append(limitStream.str());
226                 if(eFolder->getOffsetIsSet()) 
227                 {
228                         limitOffset.append(" OFFSET ");
229                         std::stringstream offsetStream;
230                         offsetStream << eFolder->getOffset();
231                         limitOffset.append(offsetStream.str());
232                 }
233
234                 query.append(limitOffset);
235         }
236         LogDebug("execute condition [" << condition << "]");
237         LogDebug("execute projection [" << projection << "]");
238         LogDebug("execute sortMode [" << sortMode << "]");
239         LogDebug("execute limitOffset [" << limitOffset << "]");        
240         LogDebug("execute query [" << query << "]");    
241
242         try
243         {
244                 sqlite3_stmt* pStmt = NULL;
245                 folder_s media_folder;
246                 sqlite3_prepare_v2(hDBCt, (char *)(query.c_str()), strlen((char *)(query.c_str())), &pStmt, NULL);
247                 while( sqlite3_step(pStmt) == SQLITE_ROW)
248                 {
249                         media_folder.folder_uuid = (char *)sqlite3_column_text(pStmt, 0);
250                         media_folder.folder_path = (char *)sqlite3_column_text(pStmt, 1);
251                         media_folder.folder_name = (char *)sqlite3_column_text(pStmt, 2);
252                         media_folder.storage_type = sqlite3_column_int(pStmt, 3);
253                         media_folder.modified_date = sqlite3_column_int(pStmt, 4);      
254
255                         MediacontentFolderPtr newFolder(new MediacontentFolder());
256                         convertToPlatformFolder(media_folder, newFolder);
257
258                         string queryMediaId(SELECT_MEDIA_ID_WITH_FOLDER);
259                         queryMediaId.append("'");
260                         queryMediaId.append(media_folder.folder_uuid);
261                         queryMediaId.append("'");
262                         sqlite3_stmt* pStmt1 = NULL;
263                         if(sqlite3_prepare_v2(hDBCt, (char *)(queryMediaId.c_str()), strlen((char *)(queryMediaId.c_str())), &pStmt1, NULL) == SQLITE_OK)
264                         {
265                                 MediaIdListPtr newMediaIdList(new MediaIdList());
266                                 //sqlite3_bind_text(pStmt1, 1, media_folder.folder_uuid,strlen(media_folder.folder_uuid), SQLITE_TRANSIENT);
267                                 LogDebug("execute 111111 [" << queryMediaId  << "]");
268                                 while( sqlite3_step(pStmt1) == SQLITE_ROW)
269                                 {
270                                         string mediaId = (char *)sqlite3_column_text(pStmt1, 0);
271                                         LogDebug("execute mediaId [" << mediaId << "]");
272                                         newMediaIdList->push_back(mediaId);
273                                 }
274                                 newFolder->setMediaIdList(newMediaIdList);
275                                 sqlite3_finalize(pStmt1);
276                         }
277
278                         eFolder->addFolder(newFolder);
279                 }
280                 sqlite3_finalize(pStmt);
281                 eFolder->setResult(true);
282
283         }
284         catch (const Exception &ex)
285         {
286                 LogError("Exception: " << ex.DumpToString());
287                 eFolder->setResult(false);
288         }
289         eFolder->setCancelAllowed(true);
290 }
291
292
293 void Mediacontent::OnRequestReceived(const IEventFindMediaPtr &eMedia)
294 {
295     LogDebug("OnRequestReceived::IEventFindMediaPtr entered");
296
297         string projection;
298         string sortMode;
299         string limitOffset;
300         string condition;
301         
302         string query(VIEW_MEDIA_QUERY_WITH_FOLDER);
303
304         MediaSearchVisitorPtr visitor(new MediaSearchVisitor());
305         
306         if(eMedia->getFilterIsSet())
307         {
308                 FilterPtr filter = eMedia->getFilter();
309
310                 // FIXME validator have to be placed at JS binding.
311                 FilterValidatorPtr validator = MediaFilterValidatorFactory::getMediaFilterValidator(MediaFilterValidatorFactory::QUERY_MEDIA);
312                 bool success = filter->validate(validator);
313
314                 if(!success)
315                         ThrowMsg(InvalidArgumentException, "Invalid filter arguments.");
316
317                 IFilterVisitorPtr IVisitor = DPL::StaticPointerCast<IFilterVisitor>(visitor);
318
319                 visitor->setQueryType(MediaSearchVisitor::QUERY_MEDIA);
320                 filter->travel(IVisitor);
321                 condition = visitor->getResult();
322                 query.append(" and ");
323                 query.append(condition);                
324         }
325
326         if(eMedia->getSortModesIsSet()) 
327         {
328                 sortMode = makeQuerySortMode(eMedia->getSortModes());   
329
330                 query.append(sortMode);
331         }
332         if (eMedia->getLimitIsSet()) 
333         {
334                 limitOffset.append(" LIMIT ");
335                 std::stringstream limitStream;
336                 limitStream << eMedia->getLimit();
337                 limitOffset.append(limitStream.str());
338                 if(eMedia->getOffsetIsSet()) 
339                 {
340                         limitOffset.append(" OFFSET ");
341                         std::stringstream offsetStream;
342                         offsetStream << eMedia->getOffset();
343                         limitOffset.append(offsetStream.str());
344                 }
345
346                 query.append(limitOffset);
347         }
348         
349         LogDebug("execute condition [" << condition << "]");
350         LogDebug("execute projection [" << projection << "]");
351         LogDebug("execute sortMode [" << sortMode << "]");
352         LogDebug("execute limitOffset [" << limitOffset << "]");        
353         LogDebug("execute query [" << query << "]");
354         
355
356         int ret;
357         
358     try
359         {
360                 sqlite3_stmt* pStmt = NULL;
361                 int content_type;
362                 ret = sqlite3_prepare_v2(hDBCt, (char *)(query.c_str()), query.length(), &pStmt, NULL);
363
364                 while( sqlite3_step(pStmt) == SQLITE_ROW)
365                 {
366
367                         content_type = sqlite3_column_int(pStmt, 2);    
368
369                         if(content_type == MEDIA_TYPE_IMAGE)
370                         {
371
372                                 MediacontentImage *newImage(new MediacontentImage());
373                                 readImageFromDB(pStmt,newImage);
374                                 eMedia->addMedia(newImage);
375                         }
376                         else if(content_type == MEDIA_TYPE_VIDEO)
377                         {
378                                 MediacontentVideo *newVideo(new MediacontentVideo());
379                                 readVideoFromDB(pStmt,newVideo);
380                                 eMedia->addMedia(newVideo);
381                         }
382                         else if(content_type == MEDIA_TYPE_AUDIO)
383                         {
384                                 MediacontentAudio *newVAudio(new MediacontentAudio());
385                                 readAudioFromDB(pStmt,newVAudio);
386                                 eMedia->addMedia(newVAudio);
387
388                         }
389
390                 }
391                 sqlite3_finalize(pStmt);
392                 eMedia->setResult(true);
393
394         }
395     catch (const Exception &ex)
396     {
397         LogError("Exception: " << ex.DumpToString());
398         eMedia->setResult(false);
399     }
400
401     eMedia->setCancelAllowed(true);
402
403 }
404
405
406 void Mediacontent::OnRequestReceived(const IEventUpdateMediaPtr &eMedia)
407 {
408     LogDebug("OnRequestReceived::IEventUpdateMediaPtr entered");
409
410         try
411         {
412                 MediacontentMediaPtr mediaPtr = eMedia->getMediaItem();
413                 string type  = mediaPtr->getMediaType();
414                 
415                 if(type.compare("IMAGE")==0)
416                 {
417                         LogDebug("Image11");
418                         MediacontentImagePtr imagePtr = DPL::DynamicPointerCast<MediacontentImage>(mediaPtr);
419                         if(imagePtr != NULL)
420                         {
421                                 LogDebug("Image22");
422                         }
423                 }
424                 if(type.compare("VIDEO")==0)
425                 {
426                         LogDebug("Video11");
427                         MediacontentVideoPtr videoPtr = DPL::DynamicPointerCast<MediacontentVideo>(mediaPtr);
428                         if(videoPtr != NULL)
429                         {
430                                 LogDebug("video22");
431                         }                       
432                 }
433                 if(type.compare("AUDIO")==0)
434                 {
435                         LogDebug("Audio11");
436                         MediacontentAudioPtr audioPtr = DPL::DynamicPointerCast<MediacontentAudio>(mediaPtr);
437                         if(audioPtr != NULL)
438                         {
439                                 LogDebug("audio22");
440                         }                       
441                 }
442
443                 eMedia->setResult(true);
444         }
445     catch (const Exception &ex)
446     {
447         LogError("Exception: " << ex.DumpToString());
448         eMedia->setResult(false);
449     }
450
451     eMedia->setCancelAllowed(true);
452
453 }
454
455
456
457 void Mediacontent::readImageFromDB(sqlite3_stmt* pStmt, MediacontentImage* newImage)
458 {
459         char* tmp;
460         if(pStmt != NULL)
461         {
462
463                 tmp = (char*)sqlite3_column_text(pStmt,0);
464                 if( tmp != NULL)
465                         newImage->setMediaUUID(tmp);
466
467                 newImage->setMediaType("IMAGE");
468         
469                 //setMimeType //2
470                 tmp = (char*)sqlite3_column_text(pStmt,3);
471                 if( tmp != NULL)
472                         newImage->setDisplayName(tmp);
473
474                 tmp = (char*)sqlite3_column_text(pStmt,4);
475                 if( tmp != NULL)
476                         newImage->setFilePath(tmp);
477
478                 tmp = (char*)sqlite3_column_text(pStmt,5);
479                 if( tmp != NULL)
480                         newImage->setThumbnailPath(tmp);
481
482                 newImage->setCreatedDate(toDateTm(sqlite3_column_int(pStmt,6)));
483                 newImage->setReleasedDate(toDateTm(sqlite3_column_int(pStmt,7)));
484                 newImage->setModifiedDate(toDateTm(sqlite3_column_int(pStmt,8)));
485
486                 tmp = (char*)sqlite3_column_text(pStmt,9);
487                 if( tmp != NULL)
488                         newImage->setDescription(tmp);
489
490                 newImage->setFavorite(sqlite3_column_int(pStmt,10));    
491                 newImage->setImageLatitude(sqlite3_column_double(pStmt,15));
492                 newImage->setImageLongitude(sqlite3_column_double(pStmt,16));   
493                 newImage->setImageWidth(sqlite3_column_int(pStmt,17));
494                 newImage->setImageHeight(sqlite3_column_int(pStmt,18));
495                 int orientation = (sqlite3_column_int(pStmt,19));
496                 string orientationStr;
497                 switch(orientation)
498                 {
499                         case 1: 
500                                 orientationStr = "NORMAL";
501                                 break;
502                         case 2: 
503                                 orientationStr = "FLIP_HORIZONTAL";
504                                 break;
505                         case 3: 
506                                 orientationStr = "ROTATE_180";
507                                 break;
508                         case 4: 
509                                 orientationStr = "FLIP_VERTICAL";
510                                 break;
511                         case 5: 
512                                 orientationStr = "TRANSPOSE";
513                                 break;
514                         case 6: 
515                                 orientationStr = "ROTATE_90";
516                                 break;
517                         case 7: 
518                                 orientationStr = "TRANSVERSE";
519                                 break;
520                         case 8: 
521                                 orientationStr = "ROTATE_270";
522                                 break;
523                 }               
524                 newImage->setImageOrientation(orientationStr);
525         }
526         
527 }
528
529
530
531 void Mediacontent::readVideoFromDB(sqlite3_stmt* pStmt, MediacontentVideo* newVideo)
532 {
533         char* tmp;
534         if(pStmt != NULL)
535         {
536
537                 tmp = (char*)sqlite3_column_text(pStmt,0);
538                 if( tmp != NULL)
539                         newVideo->setMediaUUID(tmp);
540
541                 newVideo->setMediaType("VIDEO");
542
543                 //setMimeType 
544                 tmp = (char*)sqlite3_column_text(pStmt,3);
545                 if( tmp != NULL)
546                         newVideo->setDisplayName(tmp);
547
548                 tmp = (char*)sqlite3_column_text(pStmt,4);
549                 if( tmp != NULL)
550                         newVideo->setFilePath(tmp);
551
552                 tmp = (char*)sqlite3_column_text(pStmt,5);
553                 if( tmp != NULL)
554                         newVideo->setThumbnailPath(tmp);
555
556                 newVideo->setCreatedDate(toDateTm(sqlite3_column_int(pStmt,6)));
557                 newVideo->setReleasedDate(toDateTm(sqlite3_column_int(pStmt,7)));
558                 newVideo->setModifiedDate(toDateTm(sqlite3_column_int(pStmt,8)));
559
560                 tmp = (char*)sqlite3_column_text(pStmt,9);
561                 if( tmp != NULL)
562                         newVideo->setDescription(tmp);
563
564                 newVideo->setFavorite(sqlite3_column_int(pStmt,10));    
565
566                 tmp = (char*)sqlite3_column_text(pStmt,11);
567                 if( tmp != NULL)
568                         newVideo->setVideoAlbum(tmp);
569
570                 tmp = (char*)sqlite3_column_text(pStmt,12);
571                 if( tmp != NULL)                        
572                         newVideo->setVideoArtist(tmp);
573
574                 newVideo->setVideoPlayedTime(sqlite3_column_int(pStmt,13));     
575                 newVideo->setVideoPlayCount(sqlite3_column_int(pStmt,14)); 
576
577                 newVideo->setVideoLongitude(sqlite3_column_double(pStmt,15));   
578                 newVideo->setVideoLatitude(sqlite3_column_double(pStmt,16));
579                 
580                 newVideo->setVideoWidth(sqlite3_column_int(pStmt,17));
581                 newVideo->setVideoHeight(sqlite3_column_int(pStmt,18));
582         
583                 newVideo->setVideoDuration(sqlite3_column_int(pStmt,22));
584
585         }               
586
587 }
588
589 void Mediacontent::readAudioFromDB(sqlite3_stmt* pStmt, MediacontentAudio* newAudio)
590 {
591         char* tmp;
592         if(pStmt != NULL)
593         {
594
595                 tmp = (char*)sqlite3_column_text(pStmt,0);
596                 if( tmp != NULL)
597                         newAudio->setMediaUUID(tmp);
598
599                 newAudio->setMediaType("AUDIO");
600
601                 //setMimeType 
602                 tmp = (char*)sqlite3_column_text(pStmt,3);
603                 if( tmp != NULL)
604                         newAudio->setDisplayName(tmp);
605
606                 tmp = (char*)sqlite3_column_text(pStmt,4);
607                 if( tmp != NULL)
608                         newAudio->setFilePath(tmp);
609
610                 tmp = (char*)sqlite3_column_text(pStmt,5);
611                 if( tmp != NULL)
612                         newAudio->setThumbnailPath(tmp);
613
614                 newAudio->setCreatedDate(toDateTm(sqlite3_column_int(pStmt,6)));
615                 newAudio->setReleasedDate(toDateTm(sqlite3_column_int(pStmt,7)));
616                 newAudio->setModifiedDate(toDateTm(sqlite3_column_int(pStmt,8)));
617
618                 tmp = (char*)sqlite3_column_text(pStmt,9);
619                 if( tmp != NULL)
620                         newAudio->setDescription(tmp);
621
622                 newAudio->setFavorite(sqlite3_column_int(pStmt,10));    
623
624                 tmp = (char*)sqlite3_column_text(pStmt,11);
625                 if( tmp != NULL)
626                         newAudio->setAudioAlbum(tmp);
627
628                 tmp = (char*)sqlite3_column_text(pStmt,12);
629                 if( tmp != NULL)                        
630                         newAudio->setAudioArtist(tmp);
631
632                 newAudio->setAudioPlayedTime(sqlite3_column_int(pStmt,13));     
633                 newAudio->setAudioPlayCount(sqlite3_column_int(pStmt,14));
634
635                 tmp = (char*)sqlite3_column_text(pStmt,20);
636                 if( tmp != NULL)                        
637                         newAudio->setAudioGenre(tmp);
638
639                 tmp = (char*)sqlite3_column_text(pStmt,21);
640                 if( tmp != NULL)                        
641                         newAudio->setAudioComposer(tmp);
642
643                 newAudio->setAudioDuration(sqlite3_column_int(pStmt,22));
644
645                 string queryExtraAudio(SELECT_EXTRA_AUDIO);
646                 queryExtraAudio.append("'");
647                 queryExtraAudio.append(newAudio->getMediaUUID());
648                 queryExtraAudio.append("'");
649                 sqlite3_stmt* pStmt1 = NULL;
650                 //"select copyright,bitrate,track_num,size from audio_media where audio_id=";
651                 if(sqlite3_prepare_v2(hDBCt, (char *)(queryExtraAudio.c_str()), strlen((char *)(queryExtraAudio.c_str())), &pStmt1, NULL) == SQLITE_OK)
652                 {
653                         while( sqlite3_step(pStmt1) == SQLITE_ROW)
654                         {
655                                 tmp = (char*)sqlite3_column_text(pStmt,0);
656                                 if( tmp != NULL)                        
657                                         newAudio->setAudioCopyright(tmp);
658                                 newAudio->setAudioBitrate(sqlite3_column_int(pStmt,1));
659                                 newAudio->setAudioTrackNum(sqlite3_column_int(pStmt,2));
660                                 newAudio->setAudioSize(sqlite3_column_int(pStmt,3));
661                         }
662                         sqlite3_finalize(pStmt1);
663                 }
664
665                 MMHandleType tag_attrs = 0;
666                 LogDebug("AUDIO PATH: " << newAudio->getFilePath());
667                 int ret = mm_file_create_tag_attrs(&tag_attrs, newAudio->getFilePath().c_str());
668
669                 char *err_attr_name = NULL;
670                 char* unSyncText;
671                 int unSyncLen;
672                 int syncTextNum;                
673                 if (ret == MM_ERROR_NONE && tag_attrs) 
674                 {
675                         ret = mm_file_get_attrs( tag_attrs,
676                                                                                 &err_attr_name,
677                                                                                 MM_FILE_TAG_UNSYNCLYRICS, &unSyncText, &unSyncLen,
678                                                                                 MM_FILE_TAG_SYNCLYRICS_NUM, &syncTextNum,
679                                                                                 NULL);          
680                 }
681                 if (ret != MM_ERROR_NONE &&  err_attr_name)
682                 {
683                         MediacontentLyricsPtr lyricsPtr(new MediacontentLyrics());
684                         if(syncTextNum > 0)
685                         {
686                                 lyricsPtr->setMediaLyricsType("SYNCHRONIZED");
687                                 for(int i=0; i < syncTextNum; i++)
688                                 {       
689                                         unsigned long time_info = 0;
690                                         char * lyrics_info = NULL;
691                                         mm_file_get_synclyrics_info(tag_attrs,i,&time_info,&lyrics_info);
692                                         lyricsPtr->addMediaLyricsTimeStamp(time_info);
693                                         lyricsPtr->addMediaLyricsText(lyrics_info);
694                                         LogDebug("SYNCHRONIZED: " << lyrics_info);
695                                 }
696                         }
697                         else
698                         {
699                                 LogDebug("UNSYNCHRONIZED: " << unSyncText);
700                                 lyricsPtr->setMediaLyricsType("UNSYNCHRONIZED");
701                                 lyricsPtr->addMediaLyricsTimeStamp(0);
702                                 lyricsPtr->addMediaLyricsText(unSyncText);
703         
704                         }
705                         newAudio->setAudioLyrics(lyricsPtr);
706                 }
707                 
708         }
709
710 }
711
712
713 }
714 }
715 }