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. AND ITS CONTRIBUTORS ``AS IS'' 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 23 * THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26#ifndef CDM_h 27#define CDM_h 28 29#if ENABLE(ENCRYPTED_MEDIA_V2) 30 31#include <wtf/Forward.h> 32#include <wtf/PassRefPtr.h> 33#include <wtf/Uint8Array.h> 34#include <wtf/text/WTFString.h> 35 36namespace WebCore { 37 38class CDM; 39class CDMPrivateInterface; 40class CDMSession; 41class MediaPlayer; 42 43typedef PassOwnPtr<CDMPrivateInterface> (*CreateCDM)(CDM*); 44typedef bool (*CDMSupportsKeySystem)(const String&); 45typedef bool (*CDMSupportsKeySystemAndMimeType)(const String&, const String&); 46 47class CDMClient { 48public: 49 virtual ~CDMClient() { } 50 51 virtual MediaPlayer* cdmMediaPlayer(const CDM*) const = 0; 52}; 53 54class CDMSession { 55public: 56 CDMSession() { } 57 virtual ~CDMSession() { } 58 59 virtual const String& sessionId() const = 0; 60 virtual PassRefPtr<Uint8Array> generateKeyRequest(const String& mimeType, Uint8Array* initData, String& destinationURL, unsigned short& errorCode, unsigned long& systemCode) = 0; 61 virtual void releaseKeys() = 0; 62 virtual bool update(Uint8Array*, RefPtr<Uint8Array>& nextMessage, unsigned short& errorCode, unsigned long& systemCode) = 0; 63}; 64 65class CDM { 66public: 67 68 enum CDMErrorCode { UnknownError = 1, ClientError, ServiceError, OutputError, HardwareChangeError, DomainError }; 69 static bool supportsKeySystem(const String&); 70 static bool keySystemSupportsMimeType(const String& keySystem, const String& mimeType); 71 static PassOwnPtr<CDM> create(const String& keySystem); 72 static void registerCDMFactory(CreateCDM, CDMSupportsKeySystem, CDMSupportsKeySystemAndMimeType); 73 ~CDM(); 74 75 bool supportsMIMEType(const String&) const; 76 PassOwnPtr<CDMSession> createSession(); 77 78 const String& keySystem() const { return m_keySystem; } 79 80 CDMClient* client() const { return m_client; } 81 void setClient(CDMClient* client) { m_client = client; } 82 83 MediaPlayer* mediaPlayer() const; 84 85private: 86 CDM(const String& keySystem); 87 88 String m_keySystem; 89 OwnPtr<CDMPrivateInterface> m_private; 90 CDMClient* m_client; 91}; 92 93} 94 95#endif // ENABLE(ENCRYPTED_MEDIA_V2) 96 97#endif // CDM_h 98