20.01.2015 Views

嵌入式计算机系统 - Computer Science and Engineering

嵌入式计算机系统 - Computer Science and Engineering

嵌入式计算机系统 - Computer Science and Engineering

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

嵌 入 式 计 算 机 系 统<br />

Lecture #8<br />

MeeGo Multimedia<br />

内 容 来 自 于 meego.com 以 及 MeeGo 相 关 公 开 教 程


Outline<br />

• MeeGo Multimedia Module Overview<br />

• Qt Mobility Multimedia<br />

• GStreamer Framework<br />

• APIs in Qt Mobility Multimedia


Multimedia in MeeGo Architecture


Multimedia in MeeGo Architecture


Media Stack Architecture <br />

Media Application<br />

Core OS<br />

GStreamer<br />

Qt-Mobility<br />

MeeGo Touch<br />

framework<br />

Qt<br />

libva<br />

Other core modules<br />

HW/Driver<br />

Video<br />

Decoder<br />

Video<br />

Encoder<br />

Graphics<br />

SST audio<br />

engine<br />

5


Multimedia in MeeGo Platform API<br />

• GStreamer<br />

• PulseAudio


Multimedia in MeeGo API


Qt Mobility Overview<br />

• Qt Mobility Project provides desirable functions for<br />

mobile platform<br />

• Qt Mobility covers a collection of APIs or frameworks <br />

Bearer<br />

Management<br />

Contacts Location Message Multimedia<br />

Publish <strong>and</strong><br />

subscribe<br />

Qt Service<br />

Framework<br />

Sensors<br />

API<br />

System<br />

Info<br />


Qt Mobility Multimedia Module<br />

• QtMobility’s media library will<br />

• Easily create applications with system media capabilities<br />

• Cover the items of most direct interest to developers<br />

• playback<br />

• recording<br />

• playlist<br />

• management<br />

• metadata<br />

• radio<br />

• media editing<br />

• TV<br />

• transcoding<br />

• streaming


Qt Mobility Multimedia Module<br />

• Advantage:<br />

• Implement fundamental Multimedia functions with<br />

minimal code<br />

• A great deal of flexibility with the media source<br />

• Many different codecs are supported 'out of the box'


Qt Mobility Multimedia Module<br />

• High Level APIS<br />

• Encapsulate the ability to manipulate media stream at varying level<br />

without detailed knowledge of media subsystem<br />

QT Mobility Multimedia High Level APIs<br />

Playback List<br />

Recording Playback Radio Camera ..<br />

Audio<br />

Video<br />

QT Mobility Multimedia Service


QtMobility Multimedia Module<br />

• Service - access to low-level of Multimedia function<br />

• QAudio*<br />

• QAudioDeviceInfo, QAudioInput, QAudioOutput<br />

• Low level cross platform audio API<br />

• Low latency notifications, simple game, audio data processing/visualisation.<br />

• QVideo*<br />

• QAbstractVideoBuffer, QVideoFrame, QabstractVideoSurface<br />

• Low level tools for passing video frames.<br />

• Abstraction for video buffers <strong>and</strong> surfaces


QtMobility Multimedia Module<br />

• QT MMF supports rich backend:<br />

• GStreamer<br />

• Quicktime<br />

• Directshow<br />

• …<br />

QT MMF<br />

QuickTimeService<br />

Plugin<br />

QuickTimeService<br />

GStreamer Service<br />

Plugin<br />

QGstreamerService<br />

MyService


What is GStreamer<br />

• A framework for creating media applications<br />

• Pipeline based<br />

• Not a player<br />

• One of the most obvious uses is to build a media player<br />

• Main advantage<br />

• Pluggable elements could be mixed to form arbitrary<br />

pipelines to support various kinds of video/audio codecs<br />

• Unified API for user to create pipelines <strong>and</strong> media players


GStreamer Framework


Concepts in GStreamer<br />

• Element<br />

• Pad<br />

• Bin<br />

• Pipeline<br />

• Communication Mechanism


Concepts in GStreamer-element<br />

• Element<br />

• Element is the most important object in GStreamer, it is derived<br />

from GstObject<br />

• Create a chain of elements linked together <strong>and</strong> let data flow through<br />

this chain of elements


Concepts in GStreamer-element<br />

• The way to create an element<br />

GstElement *element;<br />

element = gst_element_factory_make(“fakesrc”, “source”);<br />

if(!element) {<br />

g_print(“Failed to create element\n”);<br />

return -1;<br />

}


Concepts in GStreamer-element<br />

• Using an element as a GObject<br />

GstElement *element;<br />

gchar *name;<br />

element = gst_element_factory_make(“fakesrc”, “source”);<br />

if(!element) {<br />

g_print(“Failed to create element\n”);<br />

return -1;<br />

}<br />

//get the name of element<br />

g_object_get(G_OBJECT(element), “name”, &name, NULL);<br />

g_print(“The name of element is %s.\n”,name);<br />

g_free(name);


Concepts in GStreamer-element<br />

• Linking elements<br />

GstElement *pipeline;<br />

GstElement *source, *filter, *sink;<br />

pipeline = gst_pipeline_new(“my-pipeline”);<br />

source = gst_element_factory_make(“fakesrc”, “source”);<br />

filter = gst_element_factory_make(“identity”, “filter”);<br />

sink = gst_element_factory_make(“fakesink”, “sink”);<br />

gst_bin_add_many(GST_BIN(pipeline), source, filter, sink, NULL);<br />

if(!gst_element_link_many(source, filter, sink, NULL)) {<br />

g_warning(“Failed to link element!”);<br />

}


Concepts in GStreamer-element<br />

• Element States<br />

• GST_STATE_NULL<br />

• GST_STATE_READY<br />

• GST_STATE_PAUSED<br />

• GST_STATE_PLAYING<br />

• Setting the element state<br />

• gst_element_set_state()<br />

• gst_element_sync_state_with_parent()


Concepts in GStreamer-pad<br />

• Pad<br />

• Pad is used to negotiate links <strong>and</strong> data flow between<br />

elements in GStreamer<br />

• Pad could be sink pad or source pad<br />

• Pad can restrict the type of data that flows through it


Concepts in GStreamer-pad<br />

• Pad<br />

GObject<br />

+----GstObject<br />

+----GstElement<br />

+----ffdemux_ogg<br />

Pad Templates:<br />

SRC template: 'video_%02d'<br />

Availability: Sometimes<br />

Capabilities:<br />

ANY<br />

SRC template: 'audio_%02d'<br />

Availability: Sometimes<br />

Capabilities:<br />

ANY<br />

SINK template: 'sink'<br />

Availability: Always<br />

Capabilities:<br />

application/ogg<br />

GObject<br />

+----GstObject<br />

+----GstElement<br />

+----GstMpeg2dec<br />

Pad Templates:<br />

SRC template: 'src'<br />

Availability: Always<br />

Capabilities:<br />

video/x-raw-yuv<br />

format: { YV12, I420, Y42B }<br />

width: [ 16, 4096 ]<br />

height: [ 16, 4096 ]<br />

framerate: [ 0/1, 2147483647/1 ]<br />

SINK template: 'sink'<br />

Availability: Always<br />

Capabilities:<br />

video/mpeg<br />

mpegversion: [ 1, 2 ]<br />

systemstream: false


Concepts in GStreamer-pad<br />

• An example of using Dynamic pads<br />

static void cb_new_pad(GstElement *element, GstPad *pad, gpointer data) {<br />

gchar *name;<br />

name = gst_pad_get_name(pad);<br />

//setup a new pad link for the newly create pad<br />

…<br />

}<br />

GstElement *demux;<br />

demux = gst_element_factory_make(“oggdemux”, “demuxer”);<br />

//listen for newly create pads<br />

g_signal_connect(demux, “pad-added”, G_CALLBACK(cb_new_pad), NULL);


Concepts in GStreamer-Bin&Pipeline<br />

• Bin & Pipeline<br />

• A Bin is a container for a collection of elements. E.g. playbin<br />

• A pipeline is a special subtype of a bin that allows execution of all of<br />

its contained child elements.<br />

• A pipeline is a top-level bin. As you set it to PAUSED or PLAYING<br />

state, data flow will start <strong>and</strong> media processing will take place.<br />

• GstPipeline is derived from GstBin


Concepts in GStreamer-Bin&Pipeline<br />

• Pipeline example - a simple ogg player


Concepts in GStreamer-Bin&Pipeline<br />

• Creating a bin <strong>and</strong> add elements<br />

GstElement *bin, pipeline, *source, sink;<br />

//create pipeline<br />

pipeline = gst_pipeline_new(“my_pipeline”);<br />

//create bin<br />

bin = gst_bin_new(“my_bin”);<br />

source = gst_element_factory_make(“fakesrc”, “ source”);<br />

sink = gst_element_factory_make(“fakesink”, “sink”);<br />

//add elements to the bin<br />

gst_bin_add_many(GST_BIN(bin), source, sink, NULL);<br />

//add the bin to the pipeline<br />

gst_bin_add(GST_BIN(pipeline), bin);


Concepts in GStreamer-Communications<br />

• Mechanism for communication <strong>and</strong> data exchange<br />

between the application <strong>and</strong> the pipeline<br />

• buffers: sent between elements in the pipeline<br />

• events: sent between elements or from the application to<br />

element<br />

• messages: posted by element <strong>and</strong> collected by<br />

application<br />

• queries: application or element queries information from<br />

other element


Concepts in GStreamer-Communications<br />

• Different communications flows in GStreamer<br />

pipeline


Concepts in GStreamer-Communications<br />

• Example of using bus<br />

static GMainLoop *loop;<br />

static gboolean my_bus_callback(Gbus *bus, GstMessage *message,<br />

gpointer data) {<br />

switch(GST_MESSAGE_TYPE(message)) {<br />

case GST_MESSAGE_ERROR: {<br />

…<br />

break;<br />

}<br />

case GST_MESSAGE_EOS: {<br />

…<br />

break;<br />

}<br />

default:<br />

break;<br />

}<br />

}


Concepts in GStreamer-Communications<br />

• Example of using bus<br />

GstElement *pipeline;<br />

GstBus *bus;<br />

pipeline = gst_pipeline_new(“my_pipeline”);<br />

bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline));<br />

gst_bus_add_watch(bus, my_bus_callback, NULL);<br />

loop = g_main_loop_new(NULL, FALSE);<br />

g_main_loop_run(loop);


Tools in GStreamer<br />

• gst-inspect<br />

• Print info about a GStreamer plugin or element<br />

• Example:<br />

gst-inspect oggdemux<br />

• gst-launch<br />

• Build <strong>and</strong> run a GStreamer pipeline<br />

• Example:<br />

gst-launch filesrc location=/home/child.ogg ! mad !<br />

alsasink


Example of video player<br />

QT MMF API QT MMF Backend GStreamer Base 3 rd party plugins<br />

Player->play()<br />

QServicePlugin<br />

QGstremerService<br />

Playbin2<br />

Typefind/autoplug<br />

Demuxer<br />

Decoder<br />

Developing<br />

Developed<br />

Filter<br />


Multimedia Module API Hierarchy<br />

QObject<br />

QMediaObject<br />

QMediaService<br />

QMediaControl<br />

QMediaPlaylist QMediaRecorder QVideoWidget<br />

QAudioCaptureSource<br />

QCameraControl<br />

QCamera<br />

QMediaPlayerControl<br />

QMediaImageViewer<br />

QMediaRecorderControl<br />

QMediaPlayer


Multimedia Module API<br />

• Multimedia module consists of APIs related to<br />

• audio<br />

• video<br />

• image<br />

• camera


Multimedia Module API<br />

• Multimedia module consists of APIs related to<br />

• audio<br />

• video<br />

• image<br />

• camera


Audio<br />

• Classes related to Audio<br />

• QAudioCaptureSource<br />

• QAudioDeviceInfo<br />

• QAudioEncoderControl<br />

• QAudioEncoderSettings<br />

• QAudioEndpointSelector<br />

• QAudioFormat<br />

• QAudioInput<br />

• QAudioOutput


QAudioCaptureSource<br />

• Provides an interface to query <strong>and</strong> select an audio input<br />

endpoint<br />

• Get <strong>and</strong> Set audio input to use


QAudioCaptureSource<br />

• Functions in QAudioCaptureSource<br />

• Qlist QAudioCaptureSource::audioInputs() const<br />

Returns a list of available audio inputs<br />

• void QAudioCaptureSource::setAudioInput(const Qstring &name)<br />

Set the active input to name


QAudioCaptureSource<br />

• Example to use QAudioCaptureSource<br />

QAudioCaptureSource *audiosource = new QAudioCaptureSource;<br />

//get audio input device names<br />

Foreach(const QString &device,audiosource->audioInputs()) {<br />

ui->deviceBox->addItem(device,QVariant(device))<br />

}<br />

//set audio input device name<br />

audiosource.setAudioInput(boxValue(ui->codecBox).toString());<br />

//set the audiosource to the recorder<br />

QMediaRecorder *capture = new QMediaRecorder(audiosource);<br />

capture->record();


QAudioEncoderSettings<br />

• Provides a set of audio encoder settings<br />

int bitRate()<br />

Return the bit rate of the compressed audio stream in bits per second<br />

void setBitRate(int rate)<br />

Set the audio bit rate in bits per second<br />

QString codec()<br />

Return the audio codec<br />

void setCodec(const QString &codec)<br />

Set the audio codec<br />

QtMultimediaKit::EncodingQuality quality()<br />

Returns the audio encoding quality<br />

void setQuality(QtMultimediaKit::EncodingQuality quality)<br />

Set the audio encoding quality


QAudioEncoderSettings<br />

• Example to use QAudioEncoderSettings<br />

QAudioEncoderSettings audioSettings;<br />

audioSettings.setCodec(“audio/mpeg”);<br />

audioSettings.setQuality(QtMultimediaKit::HighQuality);<br />

audioSettings.setChannelCount(2);<br />

aduioSettings.setEncodingMode(QtMultimediaKit::ConstantQualityEncoding);<br />

//set the audio encoder setting when record<br />

QMediaRecorder *capture = new QMediaRecorder(audiosource);<br />

capture.setEncodingSettings(audioSettings);


QMediaRecorder<br />

• Be used for the recording of media content<br />

• Intended to be used with other media object<br />

such as QAudioCaptureSource, QRadioTuner<br />

• State of QMediaRecorder<br />

• QMediaRecorder::StoppedState<br />

• QMediaRecorder:: RecordingState<br />

• QMediaRecorder:: PausedState


QMediaRecorder<br />

• Signals in class QMediaRecorder<br />

• void durationChanged(qint64 duration)<br />

emitted when the duration of the recorded media has<br />

changed<br />

• void stateChanged(QMediaRecorder::State state)<br />

emitted when a media recorder’s state has changed<br />

• void mutedChanged(bool muted)<br />

emitted when the muted state has changed<br />

• void error(QMediaRecorder::Error error)<br />

emitted when an error has occurred


QMediaRecorder<br />

• Functions in class QMediaRecorder<br />

• void record()<br />

start recording<br />

• void stop()<br />

stop recording<br />

• void pause()<br />

pause recording<br />

• bool setOutputLocation(const Qurl &location)<br />

set the destination location of media content<br />

• void setEncodingSettings(const QAudioEncoderSettings &audio)<br />

set the audio <strong>and</strong> video encoder settings


QMediaRecorder<br />

• Example of using QMediaRecorder


Examples<br />

• Audioinput<br />

• audiooutput<br />

11-8-18 47<br />

Embedded <strong>Computer</strong> Systems


Multimedia Module API<br />

• Multimedia module consists of APIs related to<br />

• audio<br />

• video<br />

• image<br />

• camera


Video<br />

• Classes related to video<br />

• QMediaPlayer<br />

• QMediaPlayerList<br />

• QVideoWidget


QMediaPlayer<br />

• Properties in QMediaPlayer<br />

• duration: the duration of the current media<br />

• muted: the muted state of the current media<br />

• playbackRate: the playback rate of the current media<br />

• playlist: the media playlist being used by the player<br />

object<br />

• position: the playback position of the current media<br />

• volume: the current playback volume


QMediaPlayer<br />

• Properties in QMediaPlayer<br />

• media: the active media source being used by the<br />

player object<br />

• state: the media player’s playback state<br />

QMediaPlayer::StoppedState<br />

QMediaPlayer::PlayingState<br />

QMediaPlayer::PausedState


QMediaPlayer<br />

• Functions in QMediaPlayer<br />

• void play()<br />

start or resuming playing the current source<br />

• void pause()<br />

pause playing the current source<br />

• void stop()<br />

stop playing <strong>and</strong> reset the play position to<br />

beginning<br />

the


QMediaPlayer<br />

• Example to use QMediaPlayer<br />

QMediaPlayer *player = new QMediaPlayer;<br />

player->setMedia(QUrl::fromLocalFile(“/home/song.mp3”));<br />

player->setVolume(50);<br />

player->play();


QMediaPlaylist<br />

• Provide a list of media content to play<br />

• Used with other media object like QMediaPlayer or<br />

QMediaImageViewer


QMediaPlaylist<br />

• Functions in QMediaPlaylist<br />

• bool addMedia(const QMediaContent &content)<br />

append the media content to the playlist<br />

• bool insertMedia(int pos, const QMediaContent &content)<br />

insert the media content to the playlist at position pos<br />

• int mediaCount() const<br />

return the number of items in the playlist<br />

• void next()<br />

advanced to the next media content in playlist<br />

• void previous()<br />

return to the previous media content in playlist


QVideoWidget<br />

• Provides a widget which presents video produced by a<br />

media object


QVideoWidget<br />

• Properties in QVideoWidget<br />

• brightness: int<br />

the brightness of displayed video ranging between -100 <strong>and</strong> 100<br />

• contrast: int<br />

the contrast of displayed video ranging between -100 <strong>and</strong> 100<br />

• hue: int<br />

the hue of displayed video ranging between -100 <strong>and</strong> 100<br />

• saturation: int<br />

the saturation of displayed video ranging between -100 <strong>and</strong> 100<br />

• fullScreen:bool<br />

whether video display is confined to a window or is fullScreen


Example<br />

• Example to use QMediaPlayer with QMediaPlaylist <strong>and</strong> QVideoWidget<br />

playlist = new QMediaPlaylist;<br />

playlist->addMedia(Qurl(“http://example.com/movie1.mp4”));<br />

playlist->addMedia(Qurl(“http://example.com/movie2.mp4”));<br />

player = new QMediaPlayer;<br />

player->setPlayList(playlist);<br />

videoWidget = new QVideoWidget;<br />

player->setVideoOutput(videoWidget);<br />

videoWidget->show();<br />

player->play();


Example<br />

• Videowidget<br />

11-8-18 59<br />

Embedded <strong>Computer</strong> Systems


Multimedia Module API<br />

• Multimedia module consists of APIs related to<br />

• audio<br />

• video<br />

• Image<br />

• camera


Image<br />

• Classes related to Image:<br />

• QMediaImageViewer


QMediaImageViewer<br />

• Properties in QMediaImageViewer<br />

• elapsedTime: int<br />

time elapsed since the current image was loaded<br />

• timeout: int<br />

time that an image is displayed for before moving to<br />

the next image<br />

• state: QMediaImageViewer::State<br />

playlist control state of a slide show


QMediaImageViewer<br />

• Example of using QMediaImageViewer with<br />

QVideoWidget<br />

viewer = new QMediaImageViewer;<br />

videoWidget = new QVideoWidget;<br />

viewer->bind(videoWidget);<br />

videoWidget->show();


QMediaImageViewer<br />

• Example of using QMediaImageViewer with QMediaPlaylist<br />

playlist = new QMediaPlaylist;<br />

playlist->setPlaybackMode(QMediaPlaylist::Loop);<br />

playlist->addMedia(image1);<br />

playlist->addMedia(image2);<br />

playlist->addMedia(image3);<br />

view->setPlaylist(playlist);<br />

view->setTimeout(5000);<br />

view->show();


Multimedia Module API<br />

• Multimedia module consists of APIs related to<br />

• audio<br />

• video<br />

• Image<br />

• camera


Camera<br />

• Provides a framework to use Camera device<br />

features when supported by the platform<br />

• Take still photo<br />

• Take video<br />

• Basic settings including flash mode, zoom level etc<br />

• Classes related to Camera<br />

• QCamera<br />

• QCameraViewfinder<br />

• QCameraImageCapture


Camera<br />

• using camera to capture an image<br />

QCamera *camera = new QCamera;<br />

QCameraViewfinder *viewFinder = new QCameraViewfinder();<br />

viewFinder->show();<br />

camera->setViewfinder(viewFinder);<br />

QCameraImageCapture *imageCapture = new<br />

QCameraImageCapture(camera);<br />

camera->setCaptureMode(QCamera::CaptureStillImage);<br />

camera->searchAndLock;<br />

imageCapture->capture();<br />

camera->unlock();


Camera<br />

• using camera to record video<br />

QCamera *camera = new QCamera;<br />

QMediaRecorder *mediaRecorder = new<br />

QMediaRecorder(camera);<br />

camera->setCaptureMode(QCamera::CaptureVideo);<br />

camera->start();<br />

mediaRecorder->record();

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!