RELEASE_LOG should not be Cocoa specific
[WebKit.git] / Source / WebCore / platform / graphics / gstreamer / mse / SourceBufferPrivateGStreamer.cpp
1 /*
2  * Copyright (C) 2013 Google Inc. All rights reserved.
3  * Copyright (C) 2013 Orange
4  * Copyright (C) 2014 Sebastian Dröge <sebastian@centricular.com>
5  * Copyright (C) 2015, 2016 Metrological Group B.V.
6  * Copyright (C) 2015, 2016 Igalia, S.L
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions are
10  * met:
11  *
12  *     * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *     * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following disclaimer
16  * in the documentation and/or other materials provided with the
17  * distribution.
18  *     * Neither the name of Google Inc. nor the names of its
19  * contributors may be used to endorse or promote products derived from
20  * this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #include "config.h"
36 #include "SourceBufferPrivateGStreamer.h"
37
38 #if ENABLE(MEDIA_SOURCE) && USE(GSTREAMER)
39
40 #include "ContentType.h"
41 #include "GStreamerCommon.h"
42 #include "MediaPlayerPrivateGStreamerMSE.h"
43 #include "MediaSample.h"
44 #include "MediaSourceClientGStreamerMSE.h"
45 #include "MediaSourceGStreamer.h"
46 #include "NotImplemented.h"
47 #include "WebKitMediaSourceGStreamer.h"
48
49 namespace WebCore {
50
51 Ref<SourceBufferPrivateGStreamer> SourceBufferPrivateGStreamer::create(MediaSourceGStreamer* mediaSource, Ref<MediaSourceClientGStreamerMSE> client, const ContentType& contentType)
52 {
53     return adoptRef(*new SourceBufferPrivateGStreamer(mediaSource, client.get(), contentType));
54 }
55
56 SourceBufferPrivateGStreamer::SourceBufferPrivateGStreamer(MediaSourceGStreamer* mediaSource, Ref<MediaSourceClientGStreamerMSE> client, const ContentType& contentType)
57     : SourceBufferPrivate()
58     , m_mediaSource(mediaSource)
59     , m_type(contentType)
60     , m_client(client.get())
61 #if !RELEASE_LOG_DISABLED
62     , m_logger(mediaSource->logger())
63     , m_logIdentifier(mediaSource->nextSourceBufferLogIdentifier())
64 #endif
65 {
66 }
67
68 void SourceBufferPrivateGStreamer::setClient(SourceBufferPrivateClient* client)
69 {
70     m_sourceBufferPrivateClient = client;
71 }
72
73 void SourceBufferPrivateGStreamer::append(Vector<unsigned char>&& data)
74 {
75     ASSERT(m_mediaSource);
76
77     if (!m_sourceBufferPrivateClient)
78         return;
79
80     m_client->append(this, WTFMove(data));
81     m_sourceBufferPrivateClient->sourceBufferPrivateAppendComplete(SourceBufferPrivateClient::ReadStreamFailed);
82 }
83
84 void SourceBufferPrivateGStreamer::abort()
85 {
86     m_client->abort(this);
87 }
88
89 void SourceBufferPrivateGStreamer::resetParserState()
90 {
91     m_client->resetParserState(this);
92 }
93
94 void SourceBufferPrivateGStreamer::removedFromMediaSource()
95 {
96     if (m_mediaSource)
97         m_mediaSource->removeSourceBuffer(this);
98     m_client->removedFromMediaSource(this);
99 }
100
101 MediaPlayer::ReadyState SourceBufferPrivateGStreamer::readyState() const
102 {
103     return m_mediaSource->readyState();
104 }
105
106 void SourceBufferPrivateGStreamer::setReadyState(MediaPlayer::ReadyState state)
107 {
108     m_mediaSource->setReadyState(state);
109 }
110
111 void SourceBufferPrivateGStreamer::flush(const AtomString& trackId)
112 {
113     m_client->flush(trackId);
114 }
115
116 void SourceBufferPrivateGStreamer::enqueueSample(Ref<MediaSample>&& sample, const AtomString&)
117 {
118     m_notifyWhenReadyForMoreSamples = false;
119
120     m_client->enqueueSample(WTFMove(sample));
121 }
122
123 void SourceBufferPrivateGStreamer::allSamplesInTrackEnqueued(const AtomString& trackId)
124 {
125     m_client->allSamplesInTrackEnqueued(trackId);
126 }
127
128 bool SourceBufferPrivateGStreamer::isReadyForMoreSamples(const AtomString&)
129 {
130     return m_isReadyForMoreSamples;
131 }
132
133 void SourceBufferPrivateGStreamer::setReadyForMoreSamples(bool isReady)
134 {
135     ASSERT(WTF::isMainThread());
136     m_isReadyForMoreSamples = isReady;
137 }
138
139 void SourceBufferPrivateGStreamer::notifyReadyForMoreSamples()
140 {
141     ASSERT(WTF::isMainThread());
142     setReadyForMoreSamples(true);
143     if (m_notifyWhenReadyForMoreSamples)
144         m_sourceBufferPrivateClient->sourceBufferPrivateDidBecomeReadyForMoreSamples(m_trackId);
145 }
146
147 void SourceBufferPrivateGStreamer::setActive(bool isActive)
148 {
149     if (m_mediaSource)
150         m_mediaSource->sourceBufferPrivateDidChangeActiveState(this, isActive);
151 }
152
153 void SourceBufferPrivateGStreamer::notifyClientWhenReadyForMoreSamples(const AtomString& trackId)
154 {
155     ASSERT(WTF::isMainThread());
156     m_notifyWhenReadyForMoreSamples = true;
157     m_trackId = trackId;
158 }
159
160 void SourceBufferPrivateGStreamer::didReceiveInitializationSegment(const SourceBufferPrivateClient::InitializationSegment& initializationSegment)
161 {
162     if (m_sourceBufferPrivateClient)
163         m_sourceBufferPrivateClient->sourceBufferPrivateDidReceiveInitializationSegment(initializationSegment);
164 }
165
166 void SourceBufferPrivateGStreamer::didReceiveSample(MediaSample& sample)
167 {
168     if (m_sourceBufferPrivateClient)
169         m_sourceBufferPrivateClient->sourceBufferPrivateDidReceiveSample(sample);
170 }
171
172 void SourceBufferPrivateGStreamer::didReceiveAllPendingSamples()
173 {
174     if (m_sourceBufferPrivateClient)
175         m_sourceBufferPrivateClient->sourceBufferPrivateAppendComplete(SourceBufferPrivateClient::AppendSucceeded);
176 }
177
178 void SourceBufferPrivateGStreamer::appendParsingFailed()
179 {
180     if (m_sourceBufferPrivateClient)
181         m_sourceBufferPrivateClient->sourceBufferPrivateAppendComplete(SourceBufferPrivateClient::ParsingFailed);
182 }
183
184 #if !RELEASE_LOG_DISABLED
185 WTFLogChannel& SourceBufferPrivateGStreamer::logChannel() const
186 {
187     return LogMediaSource;
188 }
189 #endif
190
191 }
192 #endif