From 685f002b3241e890edc81f9b2c9e54e37e6e5df1 Mon Sep 17 00:00:00 2001 From: Denis Dolzhenko Date: Fri, 25 Nov 2016 15:29:26 +0200 Subject: [PATCH] TizenRefApp-7700 *.3gp audio file share issue Change-Id: I5e45fab24d19909ed264c13186dc36fef5182283 Signed-off-by: Denis Dolzhenko --- src/Common/Utils/inc/MediaUtils.h | 2 ++ src/Common/Utils/src/MediaUtils.cpp | 24 ++++++++++++++ .../Controller/inc/BubbleEntityFactory.h | 31 ++++++++++--------- .../Controller/src/BubbleEntityFactory.cpp | 28 ++++++++++++++--- 4 files changed, 66 insertions(+), 19 deletions(-) diff --git a/src/Common/Utils/inc/MediaUtils.h b/src/Common/Utils/inc/MediaUtils.h index 3806f25d..53ec0661 100644 --- a/src/Common/Utils/inc/MediaUtils.h +++ b/src/Common/Utils/inc/MediaUtils.h @@ -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); }; } diff --git a/src/Common/Utils/src/MediaUtils.cpp b/src/Common/Utils/src/MediaUtils.cpp index 8ffa83bd..7464d6d0 100644 --- a/src/Common/Utils/src/MediaUtils.cpp +++ b/src/Common/Utils/src/MediaUtils.cpp @@ -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 = {}; diff --git a/src/Conversation/ConvList/Controller/inc/BubbleEntityFactory.h b/src/Conversation/ConvList/Controller/inc/BubbleEntityFactory.h index e8d52b06..a306f2a4 100644 --- a/src/Conversation/ConvList/Controller/inc/BubbleEntityFactory.h +++ b/src/Conversation/ConvList/Controller/inc/BubbleEntityFactory.h @@ -1,17 +1,17 @@ -/* - * 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. +/* + * 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; diff --git a/src/Conversation/ConvList/Controller/src/BubbleEntityFactory.cpp b/src/Conversation/ConvList/Controller/src/BubbleEntityFactory.cpp index f4f399fa..b9d4c2e3 100644 --- a/src/Conversation/ConvList/Controller/src/BubbleEntityFactory.cpp +++ b/src/Conversation/ConvList/Controller/src/BubbleEntityFactory.cpp @@ -14,10 +14,10 @@ * 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); + } } } -- 2.34.1