Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

在MEEGO上如何通过GSTREAMER完成手电筒的功能

From Wiki
Jump to: navigation, search
Article Metadata

代码示例
文章
liuting 在 08 Feb 2012 创建
最后由 hamishwillee 在 26 Jul 2012 编辑

Contents

介绍

本文将介绍在MEEGO上如何使用照相机的闪光灯实现手电筒的功能,QT MOBILITY目前还不支持FLASH TORCH 模式。为了实现这个功能,满足开发者需求,我们将展示如何使用GSTREAMER打开照相机的闪光灯

QML部分实现

import QtQuick 1.1
import com.nokia.meego 1.0
import Torch 1.0
 
Page {
Button{
id: mButton
anchors.centerIn: parent
text: "Switch ON"
onClicked: mTorch.toggle();
}
 
Torch {
id: mTorch
onStatusChanged: mButton.text = on ? "Switch OFF" : "Switch ON";
}
}

上述代码定义了一个简单的按钮用于打开和关闭手电筒

C++部分实现

首先我们需要在MAIN函数里注册TORCH类型

#include "torch.h"
#include <QtDeclarative>
 
Q_DECL_EXPORT int main(int argc, char *argv[])
{
...
qmlRegisterType<torch, 1>("Torch", 1, 0, "Torch");
....
}

接下来我们将在torch.cpp中使用GSTREAMER完成手电筒的功能

#include "torch.h"
#include <gst/gst.h>
#include <QDebug>
 
torch::torch(QObject *parent) :
QObject(parent), src(0), mStatus(false)
{
//gst-launch-0.10 subdevsrc video-torch=1 viewfinder-mode=1 ! fakesink
 
gst_init(NULL, NULL);
src = gst_element_factory_make("subdevsrc", "src");
 
if (!src)
return;
 
g_object_set(G_OBJECT(src), "video-torch", 1, NULL);
g_object_set(G_OBJECT(src), "viewfinder-mode", 1, NULL);
gst_element_set_state(src, GST_STATE_NULL);
}
 
void torch::start(){
qDebug() << "START";
gst_element_set_state(src, GST_STATE_PLAYING);
}
 
void torch::stop(){
qDebug() << "STOP";
gst_element_set_state(src, GST_STATE_NULL);
}
 
void torch::toggle(){
qDebug() << "TOGGLE";
setStatus(!mStatus);
}
 
bool torch::status(){
qDebug() << "STATUS";
return mStatus;
}
 
void torch::setStatus(bool on){
qDebug() << "SET STATUS" << on;
if (on){
emit statusChanged(true);
start();
} else {
emit statusChanged(false);
stop();
}
 
mStatus = on;
}

定义MANIFEST 文件

由于使用了的API将访问CAMERA HW,我们需要定义正确的MANIFEST文件赋予应用程序相应的能力

<aegis>
<request>
<credential name="GRP::video" />
<for path="/opt/flashlight/bin/flashlight" />
</request>
</aegis>

代码下载

Media:Flashlight.zip

相关链接

This page was last modified on 26 July 2012, at 06:46.
109 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×