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);
};
}
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;
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 = {};
-/*\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_
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;
* limitations under the License.
*/
-
#include "BubbleEntityFactory.h"
#include "FileUtils.h"
#include "MediaType.h"
+#include "MediaUtils.h"
// Bubble items:
#include "BubbleTextEntity.h"
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" ||
return new BubbleContactEntity(m_App, filePath, fileName , bgType, direction);
else if (mime != "application/smil")
return new BubbleUnknownFileEntity(filePath, fileName, bgType, direction);
+ }
}
}