TizenRefApp-7700 *.3gp audio file share issue 79/100279/3 submit/tizen_3.0/20161125.150533
authorDenis Dolzhenko <d.dolzhenko@samsung.com>
Fri, 25 Nov 2016 13:29:26 +0000 (15:29 +0200)
committerDenis Dolzhenko <d.dolzhenko@samsung.com>
Fri, 25 Nov 2016 14:52:49 +0000 (16:52 +0200)
Change-Id: I5e45fab24d19909ed264c13186dc36fef5182283
Signed-off-by: Denis Dolzhenko <d.dolzhenko@samsung.com>
src/Common/Utils/inc/MediaUtils.h
src/Common/Utils/src/MediaUtils.cpp
src/Conversation/ConvList/Controller/inc/BubbleEntityFactory.h
src/Conversation/ConvList/Controller/src/BubbleEntityFactory.cpp

index 3806f25d414ed7123cb8b11ecfc213f07cd0e946..53ec06612ba060619513b2c50918449b769c7d40 100644 (file)
@@ -30,6 +30,8 @@ namespace Msg
             static bool getVideoFrame(const std::string &videoFilePath, const std::string &imageFilePath);
             static bool getFrameSize(const std::string &videoFilePath, int &width, int &height);
             static long long downgradeImageQuality(const std::string &imagePath);
+            static bool hasAudio(const std::string &path);
+            static bool hasVideo(const std::string &path);
     };
 }
 
index 8ffa83bdd2002e84162968974c8630c7511654ea..7464d6d02f4eea3f860917ebc3aadb9c4491623c 100644 (file)
@@ -66,6 +66,12 @@ namespace
                 return str.empty() ? 0 : atoi(str.c_str());
             }
 
+            int getBool(metadata_extractor_attr_e attr) const
+            {
+                std::string str = getStr(attr);
+                return str == "1";
+            }
+
             std::string getStr(metadata_extractor_attr_e attr) const
             {
                 std::string res;
@@ -192,6 +198,24 @@ bool MediaUtils::getFrameSize(const std::string &videoFilePath, int &width, int
     return true;
 }
 
+bool MediaUtils::hasAudio(const std::string &path)
+{
+    MetadataExtractor extractor(path);
+    if (!extractor.isValid())
+        return false;
+
+    return extractor.getBool(METADATA_HAS_AUDIO);
+}
+
+bool MediaUtils::hasVideo(const std::string &path)
+{
+    MetadataExtractor extractor(path);
+    if (!extractor.isValid())
+        return false;
+
+    return extractor.getBool(METADATA_HAS_VIDEO);
+}
+
 long long MediaUtils::downgradeImageQuality(const std::string &imagePath)
 {
     image_util_decode_h decode_h = {};
index e8d52b0612cf350b192527ba8c997bfe2c8d469e..a306f2a48587afc2327b18f3510a68bbd093114f 100644 (file)
@@ -1,17 +1,17 @@
-/*\r
- * Copyright 2016  Samsung Electronics Co., Ltd\r
- *\r
- * Licensed under the Flora License, Version 1.1 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- * http://floralicense.org/license/\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
+/*
+ * Copyright 2016  Samsung Electronics Co., Ltd
+ *
+ * Licensed under the Flora License, Version 1.1 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://floralicense.org/license/
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
  */
 
 #ifndef BubbleEntityFactory_h_
@@ -48,7 +48,8 @@ namespace Msg
 
         private:
             BubbleEntity *createEntity(const std::string &filePath, const std::string &fileName, std::string mime, BubbleBgViewItem::BgType bgType, Message::Direction direction);
-
+            BubbleEntity *createVideoEntity(const std::string &filePath, const std::string &fileName, BubbleBgViewItem::BgType bgType, Message::Direction direction);
+            BubbleEntity *createAudioEntity(const std::string &filePath, const std::string &fileName, BubbleBgViewItem::BgType bgType, Message::Direction direction);
             BubbleEntityFactory(BubbleEntityFactory&) = delete;
             BubbleEntityFactory& operator=(const BubbleEntityFactory&) = delete;
 
index f4f399faf3b2ef5be6344126d68749f98e0acaeb..b9d4c2e31dfbbeecf59468af8ba2e7927cc60232 100644 (file)
  * limitations under the License.
  */
 
-
 #include "BubbleEntityFactory.h"
 #include "FileUtils.h"
 #include "MediaType.h"
+#include "MediaUtils.h"
 
 // Bubble items:
 #include "BubbleTextEntity.h"
@@ -73,21 +73,40 @@ BubbleDownloadButtonEntity *BubbleEntityFactory::createDownloadButtonEntity()
     return new BubbleDownloadButtonEntity;
 }
 
+BubbleEntity *BubbleEntityFactory::createAudioEntity(const std::string &filePath, const std::string &fileName, BubbleBgViewItem::BgType bgType, Message::Direction direction)
+{
+    if (MediaUtils::hasAudio(filePath))
+        return new BubbleAudioEntity(filePath, fileName, bgType, direction);
+
+    // File does not contain audio or broken:
+    return new BubbleUnknownFileEntity(filePath, fileName, bgType, direction);
+}
+
+BubbleEntity *BubbleEntityFactory::createVideoEntity(const std::string &filePath, const std::string &fileName, BubbleBgViewItem::BgType bgType, Message::Direction direction)
+{
+    if (MediaUtils::hasVideo(filePath))
+           return new BubbleVideoEntity(m_WorkingDir, filePath, direction);
+
+    // Try to create Audio entity.
+    return createAudioEntity(filePath, fileName, bgType, direction);
+}
+
 BubbleEntity *BubbleEntityFactory::createEntity(const std::string &filePath, const std::string &fileName, std::string mime, BubbleBgViewItem::BgType bgType, Message::Direction direction)
 {
-    std::transform(mime.begin(), mime.end(), mime.begin(), ::tolower);
     if (FileUtils::isExists(filePath))
     {
+        std::transform(mime.begin(), mime.end(), mime.begin(), ::tolower);
         MsgMedia::Type msgMediaType = getMsgMediaTypeByMime(mime);
         switch (msgMediaType)
         {
             case MsgMedia::ImageType:
                 return new BubbleImageEntity(filePath, direction);
             case MsgMedia::AudioType:
-                return new BubbleAudioEntity(filePath, fileName, bgType, direction);
+                return createAudioEntity(filePath, fileName, bgType, direction);
             case MsgMedia::VideoType:
-                return new BubbleVideoEntity(m_WorkingDir, filePath, direction);
+                return createVideoEntity(filePath, fileName, bgType, direction);
             default:
+            {
               if (mime == "text/x-vcalendar" || mime == "text/calendar")
                   return new BubbleCalEventEntity(filePath, fileName, bgType, direction);
               else if (mime == "text/x-vcard" ||
@@ -96,6 +115,7 @@ BubbleEntity *BubbleEntityFactory::createEntity(const std::string &filePath, con
                   return new BubbleContactEntity(m_App, filePath, fileName , bgType, direction);
               else if (mime != "application/smil")
                   return new BubbleUnknownFileEntity(filePath, fileName, bgType, direction);
+            }
         }
     }