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
49namespace WebCore {
50
51Ref<SourceBufferPrivateGStreamer> SourceBufferPrivateGStreamer::create(MediaSourceGStreamer* mediaSource, Ref<MediaSourceClientGStreamerMSE> client, const ContentType& contentType)
52{
53 return adoptRef(*new SourceBufferPrivateGStreamer(mediaSource, client.get(), contentType));
54}
55
56SourceBufferPrivateGStreamer::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{
62}
63
64void SourceBufferPrivateGStreamer::setClient(SourceBufferPrivateClient* client)
65{
66 m_sourceBufferPrivateClient = client;
67}
68
69void SourceBufferPrivateGStreamer::append(Vector<unsigned char>&& data)
70{
71 ASSERT(m_mediaSource);
72
73 if (!m_sourceBufferPrivateClient)
74 return;
75
76 m_client->append(this, WTFMove(data));
77 m_sourceBufferPrivateClient->sourceBufferPrivateAppendComplete(SourceBufferPrivateClient::ReadStreamFailed);
78}
79
80void SourceBufferPrivateGStreamer::abort()
81{
82 m_client->abort(this);
83}
84
85void SourceBufferPrivateGStreamer::resetParserState()
86{
87 m_client->resetParserState(this);
88}
89
90void SourceBufferPrivateGStreamer::removedFromMediaSource()
91{
92 if (m_mediaSource)
93 m_mediaSource->removeSourceBuffer(this);
94 m_client->removedFromMediaSource(this);
95}
96
97MediaPlayer::ReadyState SourceBufferPrivateGStreamer::readyState() const
98{
99 return m_mediaSource->readyState();
100}
101
102void SourceBufferPrivateGStreamer::setReadyState(MediaPlayer::ReadyState state)
103{
104 m_mediaSource->setReadyState(state);
105}
106
107void SourceBufferPrivateGStreamer::flush(const AtomicString& trackId)
108{
109 m_client->flush(trackId);
110}
111
112void SourceBufferPrivateGStreamer::enqueueSample(Ref<MediaSample>&& sample, const AtomicString&)
113{
114 m_notifyWhenReadyForMoreSamples = false;
115
116 m_client->enqueueSample(WTFMove(sample));
117}
118
119void SourceBufferPrivateGStreamer::allSamplesInTrackEnqueued(const AtomicString& trackId)
120{
121 m_client->allSamplesInTrackEnqueued(trackId);
122}
123
124bool SourceBufferPrivateGStreamer::isReadyForMoreSamples(const AtomicString&)
125{
126 return m_isReadyForMoreSamples;
127}
128
129void SourceBufferPrivateGStreamer::setReadyForMoreSamples(bool isReady)
130{
131 ASSERT(WTF::isMainThread());
132 m_isReadyForMoreSamples = isReady;
133}
134
135void SourceBufferPrivateGStreamer::notifyReadyForMoreSamples()
136{
137 ASSERT(WTF::isMainThread());
138 setReadyForMoreSamples(true);
139 if (m_notifyWhenReadyForMoreSamples)
140 m_sourceBufferPrivateClient->sourceBufferPrivateDidBecomeReadyForMoreSamples(m_trackId);
141}
142
143void SourceBufferPrivateGStreamer::setActive(bool isActive)
144{
145 if (m_mediaSource)
146 m_mediaSource->sourceBufferPrivateDidChangeActiveState(this, isActive);
147}
148
149void SourceBufferPrivateGStreamer::notifyClientWhenReadyForMoreSamples(const AtomicString& trackId)
150{
151 ASSERT(WTF::isMainThread());
152 m_notifyWhenReadyForMoreSamples = true;
153 m_trackId = trackId;
154}
155
156void SourceBufferPrivateGStreamer::didReceiveInitializationSegment(const SourceBufferPrivateClient::InitializationSegment& initializationSegment)
157{
158 if (m_sourceBufferPrivateClient)
159 m_sourceBufferPrivateClient->sourceBufferPrivateDidReceiveInitializationSegment(initializationSegment);
160}
161
162void SourceBufferPrivateGStreamer::didReceiveSample(MediaSample& sample)
163{
164 if (m_sourceBufferPrivateClient)
165 m_sourceBufferPrivateClient->sourceBufferPrivateDidReceiveSample(sample);
166}
167
168void SourceBufferPrivateGStreamer::didReceiveAllPendingSamples()
169{
170 if (m_sourceBufferPrivateClient)
171 m_sourceBufferPrivateClient->sourceBufferPrivateAppendComplete(SourceBufferPrivateClient::AppendSucceeded);
172}
173
174void SourceBufferPrivateGStreamer::appendParsingFailed()
175{
176 if (m_sourceBufferPrivateClient)
177 m_sourceBufferPrivateClient->sourceBufferPrivateAppendComplete(SourceBufferPrivateClient::ParsingFailed);
178}
179
180}
181#endif
182