1 /* 2 * Copyright (C) 2010 Igalia S.L 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public License 15 * along with this library; see the file COPYING.LIB. If not, write to 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 */ 19 20 #include "config.h" 21 #include "ImageGStreamer.h" 22 23 #if USE(GSTREAMER) 24 25 #include "GOwnPtr.h" 26 27 using namespace std; 28 using namespace WebCore; 29 30 PassRefPtr<ImageGStreamer> ImageGStreamer::createImage(GstBuffer* buffer) 31 { 32 int width = 0, height = 0; 33 GstCaps* caps = gst_buffer_get_caps(buffer); 34 GstVideoFormat format; 35 if (!gst_video_format_parse_caps(caps, &format, &width, &height)) { 36 gst_caps_unref(caps); 37 return 0; 38 } 39 40 gst_caps_unref(caps); 41 42 cairo_format_t cairoFormat; 43 if (format == GST_VIDEO_FORMAT_ARGB || format == GST_VIDEO_FORMAT_BGRA) 44 cairoFormat = CAIRO_FORMAT_ARGB32; 45 else 46 cairoFormat = CAIRO_FORMAT_RGB24; 47 48 return adoptRef(new ImageGStreamer(buffer, IntSize(width, height), cairoFormat)); 49 } 50 51 ImageGStreamer::ImageGStreamer(GstBuffer*& buffer, IntSize size, cairo_format_t& cairoFormat) 52 : m_image(0) 53 { 54 cairo_surface_t* surface = cairo_image_surface_create_for_data(GST_BUFFER_DATA(buffer), cairoFormat, 55 size.width(), size.height(), 56 cairo_format_stride_for_width(cairoFormat, size.width())); 57 ASSERT(cairo_surface_status(surface) == CAIRO_STATUS_SUCCESS); 58 m_image = BitmapImage::create(surface); 59 } 60 61 ImageGStreamer::~ImageGStreamer() 62 { 63 if (m_image) 64 m_image.clear(); 65 66 m_image = 0; 67 } 68 #endif // USE(GSTREAMER) 69