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 | #pragma once |
22 | |
23 | #if ENABLE(VIDEO) && USE(GSTREAMER) && ENABLE(MEDIA_SOURCE) |
24 | |
25 | #include "AudioTrackPrivateGStreamer.h" |
26 | #include "GUniquePtrGStreamer.h" |
27 | #include "MainThreadNotifier.h" |
28 | #include "SourceBufferPrivateGStreamer.h" |
29 | #include "VideoTrackPrivateGStreamer.h" |
30 | #include "WebKitMediaSourceGStreamer.h" |
31 | |
32 | #include <gst/app/gstappsrc.h> |
33 | #include <gst/gst.h> |
34 | #include <wtf/Forward.h> |
35 | #include <wtf/glib/GRefPtr.h> |
36 | |
37 | namespace WebCore { |
38 | |
39 | class MediaPlayerPrivateGStreamerMSE; |
40 | |
41 | }; |
42 | |
43 | void webKitMediaSrcUriHandlerInit(gpointer, gpointer); |
44 | |
45 | #define WEBKIT_MEDIA_SRC_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), WEBKIT_TYPE_MEDIA_SRC, WebKitMediaSrcPrivate)) |
46 | |
47 | typedef struct _Stream Stream; |
48 | |
49 | struct _Stream { |
50 | // Fields filled when the Stream is created. |
51 | WebKitMediaSrc* parent; |
52 | |
53 | // AppSrc. Never modified after first assignment. |
54 | GstElement* appsrc; |
55 | |
56 | // Never modified after first assignment. |
57 | WebCore::SourceBufferPrivateGStreamer* sourceBuffer; |
58 | |
59 | // Fields filled when the track is attached. |
60 | WebCore::MediaSourceStreamTypeGStreamer type; |
61 | GRefPtr<GstCaps> caps; |
62 | |
63 | // Only audio, video or nothing at a given time. |
64 | RefPtr<WebCore::AudioTrackPrivateGStreamer> audioTrack; |
65 | RefPtr<WebCore::VideoTrackPrivateGStreamer> videoTrack; |
66 | WebCore::FloatSize presentationSize; |
67 | |
68 | // This helps WebKitMediaSrcPrivate.appsrcNeedDataCount, ensuring that needDatas are |
69 | // counted only once per each appsrc. |
70 | bool appsrcNeedDataFlag; |
71 | |
72 | // Used to enforce continuity in the appended data and avoid breaking the decoder. |
73 | // Only used from the main thread. |
74 | MediaTime lastEnqueuedTime; |
75 | }; |
76 | |
77 | enum { |
78 | PROP_0, |
79 | PROP_LOCATION, |
80 | PROP_N_AUDIO, |
81 | PROP_N_VIDEO, |
82 | PROP_N_TEXT, |
83 | PROP_LAST |
84 | }; |
85 | |
86 | enum { |
87 | SIGNAL_VIDEO_CHANGED, |
88 | SIGNAL_AUDIO_CHANGED, |
89 | SIGNAL_TEXT_CHANGED, |
90 | LAST_SIGNAL |
91 | }; |
92 | |
93 | enum OnSeekDataAction { |
94 | Nothing, |
95 | MediaSourceSeekToTime |
96 | }; |
97 | |
98 | enum WebKitMediaSrcMainThreadNotification { |
99 | ReadyForMoreSamples = 1 << 0, |
100 | SeekNeedsData = 1 << 1 |
101 | }; |
102 | |
103 | struct _WebKitMediaSrcPrivate { |
104 | // Used to coordinate the release of Stream track info. |
105 | Lock streamLock; |
106 | Condition streamCondition; |
107 | |
108 | // Streams are only added/removed in the main thread. |
109 | Vector<Stream*> streams; |
110 | |
111 | GUniquePtr<gchar> location; |
112 | int numberOfAudioStreams; |
113 | int numberOfVideoStreams; |
114 | int numberOfTextStreams; |
115 | bool asyncStart; |
116 | bool allTracksConfigured; |
117 | unsigned numberOfPads; |
118 | |
119 | MediaTime seekTime; |
120 | |
121 | // On seek, we wait for all the seekDatas, then for all the needDatas, and then run the nextAction. |
122 | OnSeekDataAction appsrcSeekDataNextAction; |
123 | int appsrcSeekDataCount; |
124 | int appsrcNeedDataCount; |
125 | |
126 | WebCore::MediaPlayerPrivateGStreamerMSE* mediaPlayerPrivate; |
127 | |
128 | RefPtr<WebCore::MainThreadNotifier<WebKitMediaSrcMainThreadNotification>> notifier; |
129 | GUniquePtr<GstFlowCombiner> flowCombiner; |
130 | }; |
131 | |
132 | extern guint webKitMediaSrcSignals[LAST_SIGNAL]; |
133 | extern GstAppSrcCallbacks enabledAppsrcCallbacks; |
134 | extern GstAppSrcCallbacks disabledAppsrcCallbacks; |
135 | |
136 | void webKitMediaSrcUriHandlerInit(gpointer gIface, gpointer ifaceData); |
137 | void webKitMediaSrcFinalize(GObject*); |
138 | void webKitMediaSrcSetProperty(GObject*, guint propertyId, const GValue*, GParamSpec*); |
139 | void webKitMediaSrcGetProperty(GObject*, guint propertyId, GValue*, GParamSpec*); |
140 | void webKitMediaSrcDoAsyncStart(WebKitMediaSrc*); |
141 | void webKitMediaSrcDoAsyncDone(WebKitMediaSrc*); |
142 | GstStateChangeReturn webKitMediaSrcChangeState(GstElement*, GstStateChange); |
143 | gint64 webKitMediaSrcGetSize(WebKitMediaSrc*); |
144 | gboolean webKitMediaSrcQueryWithParent(GstPad*, GstObject*, GstQuery*); |
145 | void webKitMediaSrcUpdatePresentationSize(GstCaps*, Stream*); |
146 | void webKitMediaSrcLinkStreamToSrcPad(GstPad*, Stream*); |
147 | void webKitMediaSrcLinkSourcePad(GstPad*, GstCaps*, Stream*); |
148 | void webKitMediaSrcFreeStream(WebKitMediaSrc*, Stream*); |
149 | void webKitMediaSrcCheckAllTracksConfigured(WebKitMediaSrc*); |
150 | GstURIType webKitMediaSrcUriGetType(GType); |
151 | const gchar* const* webKitMediaSrcGetProtocols(GType); |
152 | gchar* webKitMediaSrcGetUri(GstURIHandler*); |
153 | gboolean webKitMediaSrcSetUri(GstURIHandler*, const gchar*, GError**); |
154 | |
155 | #endif // USE(GSTREAMER) |
156 | |