1/* 2 * Copyright (C) 2013 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 1. Redistributions of source code must retain the above copyright 8 * notice, this list of conditions and the following disclaimer. 9 * 2. Redistributions in binary form must reproduce the above copyright 10 * notice, this list of conditions and the following disclaimer in the 11 * documentation and/or other materials provided with the distribution. 12 * 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#ifndef MediaSourcePrivateAVFObjC_h 27#define MediaSourcePrivateAVFObjC_h 28 29#if ENABLE(MEDIA_SOURCE) && USE(AVFOUNDATION) 30 31#include "MediaSourcePrivate.h" 32#include <wtf/Deque.h> 33#include <wtf/HashMap.h> 34#include <wtf/RefPtr.h> 35#include <wtf/RetainPtr.h> 36#include <wtf/Vector.h> 37 38OBJC_CLASS AVAsset; 39OBJC_CLASS AVStreamDataParser; 40OBJC_CLASS NSError; 41OBJC_CLASS NSObject; 42typedef struct opaqueCMSampleBuffer *CMSampleBufferRef; 43 44namespace WebCore { 45 46class CDMSession; 47class MediaPlayerPrivateMediaSourceAVFObjC; 48class MediaSourcePrivateClient; 49class SourceBufferPrivateAVFObjC; 50class TimeRanges; 51 52class MediaSourcePrivateAVFObjC final : public MediaSourcePrivate { 53public: 54 static RefPtr<MediaSourcePrivateAVFObjC> create(MediaPlayerPrivateMediaSourceAVFObjC*, MediaSourcePrivateClient*); 55 virtual ~MediaSourcePrivateAVFObjC(); 56 57 MediaPlayerPrivateMediaSourceAVFObjC* player() const { return m_player; } 58 const Vector<SourceBufferPrivateAVFObjC*>& activeSourceBuffers() const { return m_activeSourceBuffers; } 59 60 virtual AddStatus addSourceBuffer(const ContentType&, RefPtr<SourceBufferPrivate>&) override; 61 virtual void durationChanged() override; 62 virtual void markEndOfStream(EndOfStreamStatus) override; 63 virtual void unmarkEndOfStream() override; 64 virtual MediaPlayer::ReadyState readyState() const override; 65 virtual void setReadyState(MediaPlayer::ReadyState) override; 66 virtual void waitForSeekCompleted() override; 67 virtual void seekCompleted() override; 68 69 MediaTime duration(); 70 std::unique_ptr<PlatformTimeRanges> buffered(); 71 72 bool hasAudio() const; 73 bool hasVideo() const; 74 75 void seekToTime(const MediaTime&); 76 MediaTime fastSeekTimeForMediaTime(const MediaTime&, const MediaTime& negativeThreshold, const MediaTime& positiveThreshold); 77 IntSize naturalSize() const; 78 79#if ENABLE(ENCRYPTED_MEDIA_V2) 80 std::unique_ptr<CDMSession> createSession(const String&); 81#endif 82 83private: 84 MediaSourcePrivateAVFObjC(MediaPlayerPrivateMediaSourceAVFObjC*, MediaSourcePrivateClient*); 85 86 void sourceBufferPrivateDidChangeActiveState(SourceBufferPrivateAVFObjC*, bool active); 87 void sourceBufferPrivateDidReceiveInitializationSegment(SourceBufferPrivateAVFObjC*); 88#if ENABLE(ENCRYPTED_MEDIA_V2) 89 void sourceBufferKeyNeeded(SourceBufferPrivateAVFObjC*, Uint8Array*); 90#endif 91 void monitorSourceBuffers(); 92 void removeSourceBuffer(SourceBufferPrivate*); 93 94 friend class SourceBufferPrivateAVFObjC; 95 96 MediaPlayerPrivateMediaSourceAVFObjC* m_player; 97 RefPtr<MediaSourcePrivateClient> m_client; 98 Vector<RefPtr<SourceBufferPrivateAVFObjC>> m_sourceBuffers; 99 Vector<SourceBufferPrivateAVFObjC*> m_activeSourceBuffers; 100 Deque<SourceBufferPrivateAVFObjC*> m_sourceBuffersNeedingSessions; 101 bool m_isEnded; 102}; 103 104} 105 106#endif // ENABLE(MEDIA_SOURCE) && USE(AVFOUNDATION) 107 108#endif 109