gnomemm r1715 - in clutter-gstreamermm/trunk: . clutter-gstreamer/src examples
- From: siavashs svn gnome org
- To: svn-commits-list gnome org
- Subject: gnomemm r1715 - in clutter-gstreamermm/trunk: . clutter-gstreamer/src examples
- Date: Tue, 23 Sep 2008 21:13:46 +0000 (UTC)
Author: siavashs
Date: Tue Sep 23 21:13:46 2008
New Revision: 1715
URL: http://svn.gnome.org/viewvc/gnomemm?rev=1715&view=rev
Log:
Fixed Clutter::Gst::VideoTexture to derive from Clutter::Scriptable & Clutter::Media too
Added the video-payer example
* clutter-gstreamer/src/gst-video-texture.hg: Derive from
Clutter::Scriptable & Clutter::Media too (FIXME: using Clutter::Scriptable is
ambiguous)
* examples/Makefile.am:
* examples/README:
* examples/video-player.cc:
* examples/videoapp.cc:
* examples/videoapp.hh: Added the video-player example (minor bugs
exist)
Added:
clutter-gstreamermm/trunk/examples/video-player.cc
clutter-gstreamermm/trunk/examples/videoapp.cc
clutter-gstreamermm/trunk/examples/videoapp.hh
Modified:
clutter-gstreamermm/trunk/ChangeLog
clutter-gstreamermm/trunk/clutter-gstreamer/src/gst-video-texture.hg
clutter-gstreamermm/trunk/examples/Makefile.am
clutter-gstreamermm/trunk/examples/README
Modified: clutter-gstreamermm/trunk/clutter-gstreamer/src/gst-video-texture.hg
==============================================================================
--- clutter-gstreamermm/trunk/clutter-gstreamer/src/gst-video-texture.hg (original)
+++ clutter-gstreamermm/trunk/clutter-gstreamer/src/gst-video-texture.hg Tue Sep 23 21:13:46 2008
@@ -15,6 +15,8 @@
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#include <cluttermm/media.h>
+#include <cluttermm/scriptable.h>
#include <cluttermm/texture.h>
#include <gstreamermm/element.h>
@@ -29,8 +31,9 @@
{
//TODO: Documentation.
+//FIXME: using Clutter::Scriptable is ambiguous
class VideoTexture :
- public Texture
+ public Texture, public Scriptable, public Media
{
_CLASS_GOBJECT(VideoTexture, ClutterGstVideoTexture, CLUTTER_GST_VIDEO_TEXTURE, Texture, ClutterTexture)
Modified: clutter-gstreamermm/trunk/examples/Makefile.am
==============================================================================
--- clutter-gstreamermm/trunk/examples/Makefile.am (original)
+++ clutter-gstreamermm/trunk/examples/Makefile.am Tue Sep 23 21:13:46 2008
@@ -2,6 +2,12 @@
include Makefile.am_fragment
-noinst_PROGRAMS = audio video-sink
+noinst_PROGRAMS = audio video-player video-sink
audio_SOURCES = audio.cc
+video_player_SOURCES= videoapp.hh videoapp.cc video-player.cc
video_sink_SOURCES = video-sink.cc
+
+EXTRA_DIST = media-actions-pause.png \
+ media-actions-start.png \
+ vid-panel.png \
+ README
Modified: clutter-gstreamermm/trunk/examples/README
==============================================================================
--- clutter-gstreamermm/trunk/examples/README (original)
+++ clutter-gstreamermm/trunk/examples/README Tue Sep 23 21:13:46 2008
@@ -15,11 +15,6 @@
- Has some useless cheesy effects built in.
- Hit e to flip the video.
- o video-cube.
-
- Pure evil. A nasty hack to do a video cube with clutter.
- Could be done much nicer.
-
o video-sink.
Demonstrates use of ClutterGstVideoSink with a custom
Added: clutter-gstreamermm/trunk/examples/video-player.cc
==============================================================================
--- (empty file)
+++ clutter-gstreamermm/trunk/examples/video-player.cc Tue Sep 23 21:13:46 2008
@@ -0,0 +1,49 @@
+#include <clutter-gstreamermm.h>
+#include <iostream>
+#include "videoapp.hh"
+
+//FIXME: the video playback is paused when moving the mouse pointer which is related to signals
+
+int main(int argc, char** argv)
+{
+ Glib::RefPtr<Clutter::Stage> stage;
+ Glib::RefPtr<VideoApp> videoapp;
+ Clutter::Color stage_color("black");
+
+ if (argc < 2)
+ {
+ g_error("%s <video file>", argv[0]);
+ return 1;
+ }
+
+ Clutter::init(&argc, &argv);
+ Gst::init(argc, argv);
+
+ stage = Clutter::Stage::get_default();
+ stage->fullscreen();
+ stage->set_color(stage_color);
+
+ videoapp = VideoApp::create(argv[1]);
+
+ stage->add_actor(videoapp->get_video_texture());
+ stage->add_actor(videoapp);
+
+ std::cout << "start" << std::endl;
+
+ int x = (stage->get_width() - videoapp->get_width())/2;
+ int y = stage->get_height() - (stage->get_height()/3);
+
+ std::cout << Glib::ustring::compose("setting x = %1, y = %2, width = %2", x, y, videoapp->get_width()) << std::endl;
+
+ videoapp->set_position(x, y);
+
+ std::cout << "stop" << std::endl;
+
+ videoapp->get_video_texture()->set_playing();
+
+ stage->show();
+
+ Clutter::main();
+
+ return 0;
+}
Added: clutter-gstreamermm/trunk/examples/videoapp.cc
==============================================================================
--- (empty file)
+++ clutter-gstreamermm/trunk/examples/videoapp.cc Tue Sep 23 21:13:46 2008
@@ -0,0 +1,292 @@
+#include "videoapp.hh"
+#include <iostream>
+
+#define SEEK_H 20
+#define SEEK_W 690
+
+VideoApp::VideoApp(const Glib::ustring& filename)
+: video_texture(Clutter::Gst::VideoTexture::create()),
+ control_color1(73, 74, 77, 0xee),
+ control_color2(0xcc, 0xcc, 0xcc, 0xff),
+ control_bg(Clutter::Texture::create()),
+ control_play(Clutter::Texture::create()),
+ control_pause(Clutter::Texture::create()),
+ control_seek1(Clutter::Rectangle::create(control_color1)),
+ control_seek2(Clutter::Rectangle::create(control_color2)),
+ control_seekbar(Clutter::Rectangle::create(control_color1)),
+ control_label(Clutter::Label::create("Sans Bold 24", Glib::path_get_basename(filename), control_color1)),
+ controls_tl(Clutter::Timeline::create(10, 30)),
+ effect_tl(Clutter::Timeline::create(30, 90))
+{
+ video_texture->set_filename(filename);
+ video_texture->property_sync_size() = false;
+ video_texture->signal_size_change().connect(sigc::mem_fun(*this, &VideoApp::on_vtexture_size_change));
+ video_texture->property_position().signal_changed().connect(sigc::mem_fun(*this, &VideoApp::on_notify));
+
+ sink = Clutter::Gst::VideoSink::create_element(video_texture);
+ //sink->property_use_shaders() = true;
+
+ control_bg->set_from_file("vid-panel.png");
+ control_play->set_from_file("media-actions-start.png");
+ control_pause->set_from_file("media-actions-pause.png");
+
+ control_seekbar->set_opacity(0x99);
+
+ add_actor(control_bg);
+ add_actor(control_play);
+ add_actor(control_pause);
+ add_actor(control_seek1);
+ add_actor(control_seek2);
+ add_actor(control_seekbar);
+ add_actor(control_label);
+
+ control_play->set_position(30, 30);
+ control_pause->set_position(30, 30);
+
+ control_seek1->set_size(SEEK_W+10, SEEK_H+10);
+ control_seek1->set_position(200, 100);
+
+ control_seek2->set_size(SEEK_W, SEEK_H);
+ control_seek2->set_position(205, 105);
+
+ control_seekbar->set_size(0, SEEK_H);
+ control_seekbar->set_position(205, 105);
+
+ control_label->set_position(200, 40);
+
+ controls_tl->signal_new_frame().connect(sigc::mem_fun(*this, &VideoApp::on_controls_tl_new_frame));
+ controls_tl->signal_completed().connect(sigc::mem_fun(*this, &VideoApp::on_controls_tl_completed));
+
+ effect_tl->signal_new_frame().connect(sigc::mem_fun(*this, &VideoApp::on_effect_tl_new_frame));
+
+ Clutter::Stage::get_default()->signal_event().connect(sigc::mem_fun(*this, &VideoApp::on_input));
+
+ set_opacity(0xee);
+ hide();
+}
+
+VideoApp::~VideoApp()
+{
+}
+
+Glib::RefPtr<VideoApp> VideoApp::create(const Glib::ustring& filename)
+{
+ return Glib::RefPtr<VideoApp>(new VideoApp(filename));
+}
+
+void VideoApp::show_controls(bool show)
+{
+ if(controls_tl->is_playing())
+ return;
+
+ if(show && !controls_showing)
+ {
+ controls_showing = true;
+ controls_tl->start();
+
+ sigc::slot<bool> my_slot = sigc::mem_fun(*this, &VideoApp::on_controls_timeout);
+ sigc::connection connection = Glib::signal_timeout().connect(my_slot, 5000);
+ controls_timer = connection;
+
+ return;
+ }
+
+ if(show && controls_showing)
+ {
+ if(controls_timer)
+ {
+ controls_timer.disconnect();
+
+ sigc::slot<bool> my_slot = sigc::mem_fun(*this, &VideoApp::on_controls_timeout);
+ sigc::connection connection = Glib::signal_timeout().connect(my_slot, 5000);
+ controls_timer = connection;
+ }
+
+ return;
+ }
+
+ if (!show && controls_showing)
+ {
+ controls_showing = false;
+ controls_tl->start();
+ return;
+ }
+}
+
+void VideoApp::toggle_pause_state()
+{
+ if(paused)
+ {
+ video_texture->set_playing();
+ paused = false;
+ control_play->hide();
+ control_pause->show();
+ }
+ else
+ {
+ video_texture->set_playing(false);
+ paused = true;
+ control_pause->hide();
+ control_play->show();
+ }
+}
+
+Glib::RefPtr<Clutter::Gst::VideoTexture> VideoApp::get_video_texture()
+{
+ return video_texture;
+}
+
+void VideoApp::on_vtexture_size_change(int width, int height)
+{
+ int new_x, new_y, new_width, new_height;
+ Glib::RefPtr<Clutter::Stage> stage = Clutter::Stage::get_default();
+
+ new_height = (height * stage->get_width()) / width;
+ if (new_height <= stage->get_height())
+ {
+ new_width = stage->get_width();
+
+ new_x = 0;
+ new_y = (stage->get_height() - new_height) / 2;
+ }
+ else
+ {
+ new_width = (width * stage->get_height()) / height;
+ new_height = stage->get_height();
+
+ new_x = (stage->get_width() - new_width) / 2;
+ new_y = 0;
+ }
+
+ Glib::RefPtr<Clutter::Actor>::cast_dynamic(video_texture)->set_position(new_x, new_y);
+ video_texture->set_size(new_width, new_height);
+}
+
+void VideoApp::on_controls_tl_new_frame(int frame_num)
+{
+ guint8 opacity;
+
+ show_all();
+ if(paused)
+ {
+ control_pause->hide();
+ control_play->show();
+ }
+ else
+ {
+ control_pause->show();
+ control_play->hide();
+ }
+
+ opacity = (frame_num * 0xde) / controls_tl->get_n_frames();
+
+ if(!controls_showing)
+ opacity = 0xde - opacity;
+
+ set_opacity(opacity);
+}
+
+void VideoApp::on_controls_tl_completed()
+{
+ if(!controls_showing)
+ hide_all();
+
+ //controls_timer = 0;
+}
+
+void VideoApp::on_effect_tl_new_frame(int frame_num)
+{
+ video_texture->set_rotation(Clutter::Y_AXIS, frame_num * 12, CLUTTER_STAGE_WIDTH() / 2, 0, 0);
+}
+
+bool VideoApp::on_controls_timeout()
+{
+ show_controls(false);
+ return false;
+}
+
+bool VideoApp::on_input(Clutter::Event *event)
+{
+ switch (event->type)
+ {
+ case CLUTTER_MOTION:
+ show_controls();
+ break;
+
+ case CLUTTER_BUTTON_PRESS:
+ if(controls_showing)
+ {
+ Glib::RefPtr<Clutter::Actor> actor;
+ Clutter::ButtonEvent *bev = (ClutterButtonEvent*) event;
+
+ actor = Clutter::Stage::get_default()->get_actor_at_pos(bev->x, bev->y);
+
+ std::cout << Glib::ustring::compose("got actor %1 at pos %2x%3", actor, bev->x, bev->y) << std::endl;
+
+ if(actor == control_pause || actor == control_play)
+ {
+ toggle_pause_state();
+ return false;
+ }
+
+ if(actor == control_seek1 || actor == control_seek2 || actor == control_seekbar)
+ {
+ int x, y, dist, pos;
+
+ control_seekbar->get_transformed_position(x, y);
+
+ dist = bev->x - x;
+
+ CLAMP(dist, 0, SEEK_W);
+
+ pos = (dist * video_texture->get_duration()) / SEEK_W;
+
+ Glib::RefPtr<Clutter::Media>::cast_dynamic(video_texture)->set_position(pos);
+ }
+ }
+ break;
+
+ case CLUTTER_KEY_RELEASE:
+ {
+ Clutter::KeyEvent* kev = (ClutterKeyEvent*) event;
+
+ switch(Clutter::key_event_symbol(kev))
+ {
+ case CLUTTER_q:
+
+ case CLUTTER_Escape:
+ Clutter::main_quit();
+ break;
+
+ case CLUTTER_e:
+ if(!effect_tl->is_playing())
+ effect_tl->start();
+ break;
+
+ default:
+ toggle_pause_state();
+ break;
+ }
+ }
+
+ default:
+ break;
+ }
+
+ return false;
+}
+
+void VideoApp::on_notify()
+{
+ int w, h, position, duration, seek_w;
+ gchar buf[256];
+
+ position = Glib::RefPtr<Clutter::Media>::cast_dynamic(video_texture)->get_position();
+ duration = video_texture->get_duration();
+
+ if(duration == 0 || position == 0)
+ return;
+
+ control_seekbar->set_size((position * SEEK_W) / duration, SEEK_H);
+}
+
Added: clutter-gstreamermm/trunk/examples/videoapp.hh
==============================================================================
--- (empty file)
+++ clutter-gstreamermm/trunk/examples/videoapp.hh Tue Sep 23 21:13:46 2008
@@ -0,0 +1,35 @@
+#include <clutter-gstreamermm.h>
+
+class VideoApp : public Clutter::Group
+{
+public:
+ virtual ~VideoApp();
+
+ static Glib::RefPtr<VideoApp> create(const Glib::ustring&);
+ Glib::RefPtr<Clutter::Gst::VideoTexture> get_video_texture();
+ void show_controls(bool show=true);
+ void toggle_pause_state();
+ virtual bool on_input(Clutter::Event *event);
+
+private:
+ VideoApp(const Glib::ustring&);
+
+protected:
+ virtual void on_vtexture_size_change(int, int);
+ virtual void on_controls_tl_new_frame(int);
+ virtual void on_controls_tl_completed();
+ virtual void on_effect_tl_new_frame(int);
+ bool on_controls_timeout();
+ virtual void on_notify();
+
+ bool controls_showing, paused;
+ sigc::connection controls_timer;
+ Glib::RefPtr<Clutter::Gst::VideoTexture> video_texture;
+ Glib::RefPtr<Gst::Element> sink;
+ Clutter::Color control_color1, control_color2;
+ Glib::RefPtr<Clutter::Texture> control_bg, control_play, control_pause;
+ Glib::RefPtr<Clutter::Rectangle> control_seek1, control_seek2, control_seekbar;
+ Glib::RefPtr<Clutter::Label> control_label;
+ Glib::RefPtr<Clutter::Timeline> controls_tl, effect_tl;
+};
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]