Changeset 28792 in webkit


Ignore:
Timestamp:
Dec 16, 2007 8:08:39 PM (16 years ago)
Author:
alp@webkit.org
Message:

2007-12-16 Alp Toker <alp@atoker.com>

Reviewed by Maciej.

http://bugs.webkit.org/show_bug.cgi?id=16356
[GTK] Integrate GStreamer video with the graphics backend

Integrate the GStreamer media backend with the Cairo graphics backend.
There are still some issues: Data is copied more often than necessary,
and repaint() is not called, causing transformed video not to update
sometimes.

  • WebCore.pro:
  • platform/graphics/gtk/MediaPlayerPrivateGStreamer.cpp: (WebCore::MediaPlayerPrivate::MediaPlayerPrivate): (WebCore::MediaPlayerPrivate::~MediaPlayerPrivate): (WebCore::MediaPlayerPrivate::currentTime): (WebCore::MediaPlayerPrivate::setEndTime): (WebCore::MediaPlayerPrivate::seeking): (WebCore::MediaPlayerPrivate::naturalSize): (WebCore::MediaPlayerPrivate::setMuted): (WebCore::MediaPlayerPrivate::setRect): (WebCore::MediaPlayerPrivate::setVisible): (WebCore::MediaPlayerPrivate::repaint): (WebCore::MediaPlayerPrivate::paint): (WebCore::MediaPlayerPrivate::createGSTPlayBin):
  • platform/graphics/gtk/MediaPlayerPrivateGStreamer.h:
  • platform/graphics/gtk/VideoSinkGStreamer.cpp: Added. (webkit_video_sink_base_init): (webkit_video_sink_init): (webkit_video_sink_idle_func): (webkit_video_sink_render): (webkit_video_sink_set_caps): (webkit_video_sink_dispose): (webkit_video_sink_finalize): (webkit_video_sink_set_property): (webkit_video_sink_get_property): (webkit_video_sink_stop): (webkit_video_sink_class_init): (webkit_video_sink_new): (webkit_video_sink_set_surface): (plugin_init):
  • platform/graphics/gtk/VideoSinkGStreamer.h: Added.
Location:
trunk/WebCore
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r28791 r28792  
     12007-12-16  Alp Toker  <alp@atoker.com>
     2
     3        Reviewed by Maciej.
     4
     5        http://bugs.webkit.org/show_bug.cgi?id=16356
     6        [GTK] Integrate GStreamer video with the graphics backend
     7
     8        Integrate the GStreamer media backend with the Cairo graphics backend.
     9        There are still some issues: Data is copied more often than necessary,
     10        and repaint() is not called, causing transformed video not to update
     11        sometimes.
     12
     13        * WebCore.pro:
     14        * platform/graphics/gtk/MediaPlayerPrivateGStreamer.cpp:
     15        (WebCore::MediaPlayerPrivate::MediaPlayerPrivate):
     16        (WebCore::MediaPlayerPrivate::~MediaPlayerPrivate):
     17        (WebCore::MediaPlayerPrivate::currentTime):
     18        (WebCore::MediaPlayerPrivate::setEndTime):
     19        (WebCore::MediaPlayerPrivate::seeking):
     20        (WebCore::MediaPlayerPrivate::naturalSize):
     21        (WebCore::MediaPlayerPrivate::setMuted):
     22        (WebCore::MediaPlayerPrivate::setRect):
     23        (WebCore::MediaPlayerPrivate::setVisible):
     24        (WebCore::MediaPlayerPrivate::repaint):
     25        (WebCore::MediaPlayerPrivate::paint):
     26        (WebCore::MediaPlayerPrivate::createGSTPlayBin):
     27        * platform/graphics/gtk/MediaPlayerPrivateGStreamer.h:
     28        * platform/graphics/gtk/VideoSinkGStreamer.cpp: Added.
     29        (webkit_video_sink_base_init):
     30        (webkit_video_sink_init):
     31        (webkit_video_sink_idle_func):
     32        (webkit_video_sink_render):
     33        (webkit_video_sink_set_caps):
     34        (webkit_video_sink_dispose):
     35        (webkit_video_sink_finalize):
     36        (webkit_video_sink_set_property):
     37        (webkit_video_sink_get_property):
     38        (webkit_video_sink_stop):
     39        (webkit_video_sink_class_init):
     40        (webkit_video_sink_new):
     41        (webkit_video_sink_set_surface):
     42        (plugin_init):
     43        * platform/graphics/gtk/VideoSinkGStreamer.h: Added.
     44
    1452007-12-16  Mark Rowe  <mrowe@apple.com>
    246
  • trunk/WebCore/WebCore.pro

    r28779 r28792  
    11121112    gtk-port {
    11131113        SOURCES += \
    1114             platform/graphics/gtk/MediaPlayerPrivateGStreamer.cpp
     1114            platform/graphics/gtk/MediaPlayerPrivateGStreamer.cpp \
     1115            platform/graphics/gtk/VideoSinkGStreamer.cpp
    11151116
    11161117        PKGCONFIG += gstreamer-0.10 gstreamer-plugins-base-0.10 gnome-vfs-2.0
  • trunk/WebCore/platform/graphics/gtk/MediaPlayerPrivateGStreamer.cpp

    r28664 r28792  
    22 * Copyright (C) 2007 Apple Inc.  All rights reserved.
    33 * Copyright (C) 2007 Collabora Ltd.  All rights reserved.
     4 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
    45 *
    56 * This library is free software; you can redistribute it and/or
     
    2425
    2526#include "MediaPlayerPrivateGStreamer.h"
    26 
    27 #include "CString.h"
     27#include "VideoSinkGStreamer.h"
     28
    2829#include "CString.h"
    2930#include "GraphicsContext.h"
     
    117118    , m_startedPlaying(false)
    118119    , m_isStreaming(false)
    119 {
     120    , m_rect(IntRect())
     121    , m_visible(true)
     122{
     123
     124    static bool gstInitialized = false;
    120125    // FIXME: We should pass the arguments from the command line
    121     gst_init(0, NULL);
     126    if (!gstInitialized) {
     127        gst_init(0, NULL);
     128        gstInitialized = true;
     129    }
     130
     131    // FIXME: The size shouldn't be fixed here, this is just a quick hack.
     132    m_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, 640, 480);
    122133}
    123134
    124135MediaPlayerPrivate::~MediaPlayerPrivate()
    125136{
    126     gst_element_set_state(m_playBin, GST_STATE_NULL);
    127     gst_object_unref(GST_OBJECT(m_playBin));
     137    if (m_surface)
     138        cairo_surface_destroy(m_surface);
     139
     140    if (m_playBin) {
     141        gst_element_set_state(m_playBin, GST_STATE_NULL);
     142        gst_object_unref(GST_OBJECT(m_playBin));
     143    }
    128144}
    129145
     
    193209
    194210    float ret;
    195     GstQuery* query;
    196     gboolean res;
    197 
    198     query = gst_query_new_position(GST_FORMAT_TIME);
    199     res = gst_element_query(m_playBin, query);
    200     if (res) {
     211
     212    GstQuery* query = gst_query_new_position(GST_FORMAT_TIME);
     213    if (gst_element_query(m_playBin, query)) {
    201214        gint64 position;
    202215        gst_query_parse_position(query, NULL, &position);
     
    208221    }
    209222    gst_query_unref(query);
     223
    210224    return ret;
    211225}
     
    243257        LOG_VERBOSE(Media, "setEndTime: %" GST_TIME_FORMAT, GST_TIME_ARGS(end));
    244258        // FIXME: What happens when the seeked position is not available?
    245         if (!gst_element_seek( m_playBin, m_rate,
     259        if (!gst_element_seek(m_playBin, m_rate,
    246260                GST_FORMAT_TIME,
    247261                (GstSeekFlags)(GST_SEEK_FLAG_FLUSH | GST_SEEK_FLAG_ACCURATE),
     
    274288bool MediaPlayerPrivate::seeking() const
    275289{
    276     return false;;
     290    return false;
    277291}
    278292
     
    280294IntSize MediaPlayerPrivate::naturalSize()
    281295{
     296    if (!hasVideo())
     297        return IntSize();
     298
    282299    int x = 0, y = 0;
    283     if (hasVideo()) {
    284         GstPad* pad = NULL;
    285         pad = gst_element_get_pad(m_videoSink, "sink");
    286         if (pad)
    287             gst_video_get_size(GST_PAD(pad), &x, &y);
    288     }
     300    if (GstPad* pad = gst_element_get_static_pad(m_videoSink, "sink")) {
     301        gst_video_get_size(GST_PAD(pad), &x, &y);
     302        gst_object_unref(GST_OBJECT(pad));
     303    }
     304
    289305    return IntSize(x, y);
    290306}
     
    307323void MediaPlayerPrivate::setMuted(bool b)
    308324{
    309     if (!m_playBin) 
     325    if (!m_playBin)
    310326        return;
    311327
     
    538554}
    539555
    540 void MediaPlayerPrivate::setRect(const IntRect& r)
    541 {
    542     notImplemented();
    543 }
    544 
    545 void MediaPlayerPrivate::setVisible(bool b)
    546 {
    547     notImplemented();
    548 }
    549 
    550 void MediaPlayerPrivate::paint(GraphicsContext* p, const IntRect& r)
     556void MediaPlayerPrivate::setRect(const IntRect& rect)
     557{
     558    m_rect = rect;
     559}
     560
     561void MediaPlayerPrivate::setVisible(bool visible)
     562{
     563    m_visible = visible;
     564}
     565
     566void MediaPlayerPrivate::repaint()
     567{
     568    m_player->repaint();
     569}
     570
     571void MediaPlayerPrivate::paint(GraphicsContext* context, const IntRect& rect)
     572{
     573    if (context->paintingDisabled())
     574        return;
     575
     576    if (!m_visible)
     577        return;
     578
     579    //TODO: m_rect vs rect?
     580    cairo_t* cr = context->platformContext();
     581
     582    cairo_save(cr);
     583    cairo_set_operator(cr, CAIRO_OPERATOR_SOURCE);
     584    cairo_translate(cr, rect.x(), rect.y());
     585    cairo_rectangle(cr, 0, 0, rect.width(), rect.height());
     586    cairo_set_source_surface(cr, m_surface, 0, 0);
     587    cairo_fill(cr);
     588    cairo_restore(cr);
     589}
     590
     591void MediaPlayerPrivate::getSupportedTypes(HashSet<String>& types)
    551592{
    552593    // FIXME: do the real thing
    553     if (p->paintingDisabled())
    554         return;
    555     // For now draw a placeholder rectangle
    556     p->drawRect(r);
    557 }
    558 
    559 void MediaPlayerPrivate::getSupportedTypes(HashSet<String>& types)
    560 {
    561     // FIXME: do the real thing
    562594    notImplemented();
    563595    types.add(String("video/x-theora+ogg"));
     
    566598void MediaPlayerPrivate::createGSTPlayBin(String url)
    567599{
    568     GstElement* audioSink;
    569     GstBus* bus;
    570 
     600    ASSERT(!m_playBin);
    571601    m_playBin = gst_element_factory_make("playbin", "play");
    572602
    573     bus = gst_pipeline_get_bus(GST_PIPELINE(m_playBin));
    574 
     603    GstBus* bus = gst_pipeline_get_bus(GST_PIPELINE(m_playBin));
    575604    gst_bus_add_signal_watch(bus);
    576 
    577605    g_signal_connect(bus, "message::error", G_CALLBACK(mediaPlayerPrivateErrorCallback), this);
    578606    g_signal_connect(bus, "message::eos", G_CALLBACK(mediaPlayerPrivateEOSCallback), this);
    579607    g_signal_connect(bus, "message::state-changed", G_CALLBACK(mediaPlayerPrivateStateCallback), this);
    580608    g_signal_connect(bus, "message::buffering", G_CALLBACK(mediaPlayerPrivateBufferingCallback), this);
    581 
    582609    gst_object_unref(bus);
    583610
    584611    g_object_set(G_OBJECT(m_playBin), "uri", url.utf8().data(), NULL);
    585     audioSink = gst_element_factory_make("gconfaudiosink", NULL);
    586     m_videoSink = gst_element_factory_make("gconfvideosink", NULL);
     612
     613    GstElement* audioSink = gst_element_factory_make("gconfaudiosink", NULL);
     614    m_videoSink = webkit_video_sink_new(m_surface);
    587615
    588616    g_object_set(m_playBin, "audio-sink", audioSink, NULL);
  • trunk/WebCore/platform/graphics/gtk/MediaPlayerPrivateGStreamer.h

    r28664 r28792  
    22 * Copyright (C) 2007 Apple Inc.  All rights reserved.
    33 * Copyright (C) 2007 Collabora Ltd. All rights reserved.
     4 * Copyright (C) 2007 Alp Toker <alp@atoker.com>
    45 *
    56 * This library is free software; you can redistribute it and/or
     
    2627#include "MediaPlayer.h"
    2728#include "Timer.h"
    28 #include "wtf/Noncopyable.h"
    2929
    3030#include <gtk/gtk.h>
     
    5252
    5353    public:
    54         MediaPlayerPrivate(MediaPlayer* m);
     54        MediaPlayerPrivate(MediaPlayer*);
    5555        ~MediaPlayerPrivate();
    5656
     
    6969        float duration();
    7070        float currentTime() const;
    71         void seek(float time);
    72         void setEndTime(float time);
     71        void seek(float);
     72        void setEndTime(float);
    7373
    7474        void setRate(float);
     
    8888
    8989        void setVisible(bool);
    90         void setRect(const IntRect& r);
     90        void setRect(const IntRect&);
    9191
    9292        void loadStateChanged();
     
    9898        void loadingFailed();
    9999
    100         void paint(GraphicsContext* p, const IntRect& r);
    101         static void getSupportedTypes(HashSet<String>& types);
     100        void repaint();
     101        void paint(GraphicsContext*, const IntRect&);
     102        static void getSupportedTypes(HashSet<String>&);
    102103
    103104    private:
     
    124125        bool m_startedPlaying;
    125126        bool m_isStreaming;
     127        IntRect m_rect;
     128        bool m_visible;
     129        cairo_surface_t* m_surface;
    126130    };
    127131}
Note: See TracChangeset for help on using the changeset viewer.