1/*
2 * Copyright (C) 2016 Metrological Group B.V.
3 * Copyright (C) 2016 Igalia S.L
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * aint with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#include "config.h"
22#include "GStreamerMediaDescription.h"
23#include "GStreamerCommon.h"
24
25#include <gst/pbutils/pbutils.h>
26#include <wtf/text/AtomicString.h>
27#include <wtf/text/WTFString.h>
28
29#if ENABLE(VIDEO) && USE(GSTREAMER) && ENABLE(MEDIA_SOURCE)
30
31namespace WebCore {
32
33AtomicString GStreamerMediaDescription::codec() const
34{
35 return m_codecName;
36}
37
38bool GStreamerMediaDescription::isVideo() const
39{
40 return doCapsHaveType(m_caps.get(), GST_VIDEO_CAPS_TYPE_PREFIX);
41}
42
43bool GStreamerMediaDescription::isAudio() const
44{
45 return doCapsHaveType(m_caps.get(), GST_AUDIO_CAPS_TYPE_PREFIX);
46}
47
48bool GStreamerMediaDescription::isText() const
49{
50 // FIXME: Implement proper text track support.
51 return false;
52}
53
54AtomicString GStreamerMediaDescription::extractCodecName()
55{
56 GRefPtr<GstCaps> originalCaps = m_caps;
57
58 if (areEncryptedCaps(originalCaps.get())) {
59 originalCaps = adoptGRef(gst_caps_copy(originalCaps.get()));
60 GstStructure* structure = gst_caps_get_structure(originalCaps.get(), 0);
61
62 if (!gst_structure_has_field(structure, "original-media-type"))
63 return AtomicString();
64
65 gst_structure_set_name(structure, gst_structure_get_string(structure, "original-media-type"));
66 // Remove the DRM related fields from the caps.
67 for (int j = 0; j < gst_structure_n_fields(structure); ++j) {
68 const char* fieldName = gst_structure_nth_field_name(structure, j);
69
70 if (g_str_has_prefix(fieldName, "protection-system")
71 || g_str_has_prefix(fieldName, "original-media-type"))
72 gst_structure_remove_field(structure, fieldName);
73 }
74 }
75
76 GUniquePtr<gchar> description(gst_pb_utils_get_codec_description(originalCaps.get()));
77 String codecName(description.get());
78
79 // Report "H.264 (Main Profile)" and "H.264 (High Profile)" just as "H.264" to allow changes between both variants
80 // go unnoticed to the SourceBuffer layer.
81 if (codecName.startsWith("H.264")) {
82 size_t braceStart = codecName.find(" (");
83 size_t braceEnd = codecName.find(")");
84 if (braceStart != notFound && braceEnd != notFound)
85 codecName.remove(braceStart, braceEnd - braceStart);
86 }
87
88 return codecName;
89}
90
91} // namespace WebCore.
92
93#endif // USE(GSTREAMER)
94