tagging audio streams and changing audio sink to pulseaudio
[profile/ivi/webkit-efl.git] / Source / WebCore / platform / graphics / gstreamer / ImageGStreamerQt.cpp
1 /*
2     Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
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 ENABLE(VIDEO) && USE(GSTREAMER)
24 #include <gst/gst.h>
25 #include <gst/video/video.h>
26
27 #ifdef GST_API_VERSION_1
28 #include <gst/video/gstvideometa.h>
29 #endif
30
31 #include <wtf/gobject/GOwnPtr.h>
32
33 using namespace std;
34 using namespace WebCore;
35
36 ImageGStreamer::ImageGStreamer(GstBuffer* buffer, GstCaps* caps)
37     : m_image(0)
38 {
39     GstVideoFormat format;
40     IntSize size;
41     int pixelAspectRatioNumerator, pixelAspectRatioDenominator, stride;
42     getVideoSizeAndFormatFromCaps(caps, size, format, pixelAspectRatioNumerator, pixelAspectRatioDenominator, stride);
43
44 #ifdef GST_API_VERSION_1
45     GstMapInfo info;
46     gst_buffer_map(buffer, &info, GST_MAP_READ);
47     uchar* bufferData = reinterpret_cast<uchar*>(info.data);
48 #else
49     uchar* bufferData = reinterpret_cast<uchar*>(GST_BUFFER_DATA(buffer));
50 #endif
51     QImage::Format imageFormat;
52     QImage::InvertMode invertMode;
53 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
54     if (format == GST_VIDEO_FORMAT_BGRA) {
55         imageFormat = QImage::Format_ARGB32;
56         invertMode = QImage::InvertRgba;
57     } else {
58         imageFormat = QImage::Format_RGB32;
59         invertMode = QImage::InvertRgb;
60     }
61 #else
62     imageFormat = (format == GST_VIDEO_FORMAT_ARGB) ? QImage::Format_ARGB32 : QImage::Format_RGB32;
63 #endif
64
65     QImage image(bufferData, size.width(), size.height(), imageFormat);
66
67 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
68     image.invertPixels(invertMode);
69 #endif
70
71     m_image = BitmapImage::create(new QImage(image));
72
73 #ifdef GST_API_VERSION_1
74     if (GstVideoCropMeta* cropMeta = gst_buffer_get_video_crop_meta(buffer))
75         setCropRect(FloatRect(cropMeta->x, cropMeta->y, cropMeta->width, cropMeta->height));
76
77     gst_buffer_unmap(buffer, &info);
78 #endif
79 }
80
81 ImageGStreamer::~ImageGStreamer()
82 {
83     if (m_image)
84         m_image.clear();
85
86     m_image = 0;
87 }
88 #endif // USE(GSTREAMER)
89