tagging audio streams and changing audio sink to pulseaudio
[profile/ivi/webkit-efl.git] / Source / WebCore / platform / graphics / gstreamer / GStreamerVersioning.cpp
1 /*
2  * Copyright (C) 2012 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
22 #include "GStreamerVersioning.h"
23
24 #include "IntSize.h"
25
26 void webkitGstObjectRefSink(GstObject* gstObject)
27 {
28 #ifdef GST_API_VERSION_1
29     gst_object_ref_sink(gstObject);
30 #else
31     gst_object_ref(gstObject);
32     gst_object_sink(gstObject);
33 #endif
34 }
35
36 GstCaps* webkitGstGetPadCaps(GstPad* pad)
37 {
38     if (!pad)
39         return 0;
40
41     GstCaps* caps;
42 #ifdef GST_API_VERSION_1
43     caps = gst_pad_get_current_caps(pad);
44     if (!caps)
45         caps = gst_pad_query_caps(pad, 0);
46 #else
47     caps = GST_PAD_CAPS(pad);
48 #endif
49     return caps;
50 }
51
52 bool getVideoSizeAndFormatFromCaps(GstCaps* caps, WebCore::IntSize& size, GstVideoFormat& format, int& pixelAspectRatioNumerator, int& pixelAspectRatioDenominator, int& stride)
53 {
54 #ifdef GST_API_VERSION_1
55     GstVideoInfo info;
56     if (!gst_video_info_from_caps(&info, caps))
57         return false;
58
59     format = GST_VIDEO_INFO_FORMAT(&info);
60     size.setWidth(GST_VIDEO_INFO_WIDTH(&info));
61     size.setHeight(GST_VIDEO_INFO_HEIGHT(&info));
62     pixelAspectRatioNumerator = GST_VIDEO_INFO_PAR_N(&info);
63     pixelAspectRatioDenominator = GST_VIDEO_INFO_PAR_D(&info);
64     stride = GST_VIDEO_INFO_PLANE_STRIDE(&info, 0);
65 #else
66     gint width, height;
67     if (!GST_IS_CAPS(caps) || !gst_caps_is_fixed(caps)
68         || !gst_video_format_parse_caps(caps, &format, &width, &height)
69         || !gst_video_parse_caps_pixel_aspect_ratio(caps, &pixelAspectRatioNumerator,
70                                                     &pixelAspectRatioDenominator))
71         return false;
72     size.setWidth(width);
73     size.setHeight(height);
74     stride = size.width() * 4;
75 #endif
76
77     return true;
78 }
79
80 GstBuffer* createGstBuffer(GstBuffer* buffer)
81 {
82 #ifndef GST_API_VERSION_1
83     GstBuffer* newBuffer = gst_buffer_try_new_and_alloc(GST_BUFFER_SIZE(buffer));
84 #else
85     gsize bufferSize = gst_buffer_get_size(buffer);
86     GstBuffer* newBuffer = gst_buffer_new_and_alloc(bufferSize);
87 #endif
88
89     if (!newBuffer)
90         return 0;
91
92 #ifndef GST_API_VERSION_1
93     gst_buffer_copy_metadata(newBuffer, buffer, static_cast<GstBufferCopyFlags>(GST_BUFFER_COPY_ALL));
94 #else
95     gst_buffer_copy_into(newBuffer, buffer, static_cast<GstBufferCopyFlags>(GST_BUFFER_COPY_METADATA), 0, bufferSize);
96 #endif
97     return newBuffer;
98 }
99
100 void setGstElementClassMetadata(GstElementClass* elementClass, const char* name, const char* longName, const char* description, const char* author)
101 {
102 #ifdef GST_API_VERSION_1
103     gst_element_class_set_metadata(elementClass, name, longName, description, author);
104 #else
105     gst_element_class_set_details_simple(elementClass, name, longName, description, author);
106 #endif
107 }