| 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 "MediaSourceGStreamer.h" |
| 37 | |
| 38 | #if ENABLE(MEDIA_SOURCE) && USE(GSTREAMER) |
| 39 | |
| 40 | #include "ContentType.h" |
| 41 | #include "MediaPlayerPrivateGStreamer.h" |
| 42 | #include "MediaPlayerPrivateGStreamerMSE.h" |
| 43 | #include "MediaSourceClientGStreamerMSE.h" |
| 44 | #include "NotImplemented.h" |
| 45 | #include "SourceBufferPrivateGStreamer.h" |
| 46 | #include "TimeRanges.h" |
| 47 | #include "WebKitMediaSourceGStreamer.h" |
| 48 | #include <wtf/RefPtr.h> |
| 49 | #include <wtf/glib/GRefPtr.h> |
| 50 | |
| 51 | namespace WebCore { |
| 52 | |
| 53 | void MediaSourceGStreamer::open(MediaSourcePrivateClient& mediaSource, MediaPlayerPrivateGStreamerMSE& playerPrivate) |
| 54 | { |
| 55 | mediaSource.setPrivateAndOpen(adoptRef(*new MediaSourceGStreamer(mediaSource, playerPrivate))); |
| 56 | } |
| 57 | |
| 58 | MediaSourceGStreamer::MediaSourceGStreamer(MediaSourcePrivateClient& mediaSource, MediaPlayerPrivateGStreamerMSE& playerPrivate) |
| 59 | : MediaSourcePrivate() |
| 60 | , m_client(MediaSourceClientGStreamerMSE::create(playerPrivate)) |
| 61 | , m_mediaSource(mediaSource) |
| 62 | , m_playerPrivate(playerPrivate) |
| 63 | { |
| 64 | } |
| 65 | |
| 66 | MediaSourceGStreamer::~MediaSourceGStreamer() |
| 67 | { |
| 68 | for (auto& sourceBufferPrivate : m_sourceBuffers) |
| 69 | sourceBufferPrivate->clearMediaSource(); |
| 70 | } |
| 71 | |
| 72 | MediaSourceGStreamer::AddStatus MediaSourceGStreamer::addSourceBuffer(const ContentType& contentType, RefPtr<SourceBufferPrivate>& sourceBufferPrivate) |
| 73 | { |
| 74 | sourceBufferPrivate = SourceBufferPrivateGStreamer::create(this, m_client.get(), contentType); |
| 75 | RefPtr<SourceBufferPrivateGStreamer> sourceBufferPrivateGStreamer = static_cast<SourceBufferPrivateGStreamer*>(sourceBufferPrivate.get()); |
| 76 | m_sourceBuffers.add(sourceBufferPrivateGStreamer); |
| 77 | return m_client->addSourceBuffer(sourceBufferPrivateGStreamer, contentType); |
| 78 | } |
| 79 | |
| 80 | void MediaSourceGStreamer::removeSourceBuffer(SourceBufferPrivate* sourceBufferPrivate) |
| 81 | { |
| 82 | RefPtr<SourceBufferPrivateGStreamer> sourceBufferPrivateGStreamer = static_cast<SourceBufferPrivateGStreamer*>(sourceBufferPrivate); |
| 83 | ASSERT(m_sourceBuffers.contains(sourceBufferPrivateGStreamer)); |
| 84 | |
| 85 | sourceBufferPrivateGStreamer->clearMediaSource(); |
| 86 | m_sourceBuffers.remove(sourceBufferPrivateGStreamer); |
| 87 | m_activeSourceBuffers.remove(sourceBufferPrivateGStreamer.get()); |
| 88 | } |
| 89 | |
| 90 | void MediaSourceGStreamer::durationChanged() |
| 91 | { |
| 92 | m_client->durationChanged(m_mediaSource->duration()); |
| 93 | } |
| 94 | |
| 95 | void MediaSourceGStreamer::markEndOfStream(EndOfStreamStatus status) |
| 96 | { |
| 97 | m_client->markEndOfStream(status); |
| 98 | } |
| 99 | |
| 100 | void MediaSourceGStreamer::unmarkEndOfStream() |
| 101 | { |
| 102 | notImplemented(); |
| 103 | } |
| 104 | |
| 105 | MediaPlayer::ReadyState MediaSourceGStreamer::readyState() const |
| 106 | { |
| 107 | return m_playerPrivate.readyState(); |
| 108 | } |
| 109 | |
| 110 | void MediaSourceGStreamer::setReadyState(MediaPlayer::ReadyState state) |
| 111 | { |
| 112 | m_playerPrivate.setReadyState(state); |
| 113 | } |
| 114 | |
| 115 | void MediaSourceGStreamer::waitForSeekCompleted() |
| 116 | { |
| 117 | m_playerPrivate.waitForSeekCompleted(); |
| 118 | } |
| 119 | |
| 120 | void MediaSourceGStreamer::seekCompleted() |
| 121 | { |
| 122 | m_playerPrivate.seekCompleted(); |
| 123 | } |
| 124 | |
| 125 | void MediaSourceGStreamer::sourceBufferPrivateDidChangeActiveState(SourceBufferPrivateGStreamer* sourceBufferPrivate, bool isActive) |
| 126 | { |
| 127 | if (!isActive) |
| 128 | m_activeSourceBuffers.remove(sourceBufferPrivate); |
| 129 | else if (!m_activeSourceBuffers.contains(sourceBufferPrivate)) |
| 130 | m_activeSourceBuffers.add(sourceBufferPrivate); |
| 131 | } |
| 132 | |
| 133 | std::unique_ptr<PlatformTimeRanges> MediaSourceGStreamer::buffered() |
| 134 | { |
| 135 | return m_mediaSource->buffered(); |
| 136 | } |
| 137 | |
| 138 | } |
| 139 | #endif |
| 140 | |