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#include "config.h" 27 28#if ENABLE(VIDEO) && USE(AVFOUNDATION) && !HAVE(AVFOUNDATION_LEGIBLE_OUTPUT_SUPPORT) && !PLATFORM(IOS) 29 30#include "InbandTextTrackPrivateLegacyAVCF.h" 31 32#include "InbandTextTrackPrivateAVF.h" 33#include "Logging.h" 34#include "MediaPlayerPrivateAVFoundationCF.h" 35#include "SoftLinking.h" 36 37#include <AVFoundationCF/AVFoundationCF.h> 38 39#include <d3d9.h> 40 41// The softlink header files must be included after the AVCF and CoreMedia header files. 42#include "AVFoundationCFSoftLinking.h" 43 44namespace WebCore { 45 46InbandTextTrackPrivateLegacyAVCF::InbandTextTrackPrivateLegacyAVCF(MediaPlayerPrivateAVFoundationCF* player, AVCFPlayerItemTrackRef track) 47 : InbandTextTrackPrivateAVF(player) 48 , m_playerItemTrack(track) 49{ 50} 51 52void InbandTextTrackPrivateLegacyAVCF::disconnect() 53{ 54 m_playerItemTrack = 0; 55 InbandTextTrackPrivateAVF::disconnect(); 56} 57 58InbandTextTrackPrivate::Kind InbandTextTrackPrivateLegacyAVCF::kind() const 59{ 60 if (!m_playerItemTrack) 61 return InbandTextTrackPrivate::None; 62 63 return InbandTextTrackPrivate::Captions; 64} 65 66bool InbandTextTrackPrivateLegacyAVCF::isClosedCaptions() const 67{ 68 return m_playerItemTrack; 69} 70 71bool InbandTextTrackPrivateLegacyAVCF::containsOnlyForcedSubtitles() const 72{ 73 return false; 74} 75 76bool InbandTextTrackPrivateLegacyAVCF::isMainProgramContent() const 77{ 78 return m_playerItemTrack; 79} 80 81bool InbandTextTrackPrivateLegacyAVCF::isEasyToRead() const 82{ 83 return false; 84} 85 86AtomicString InbandTextTrackPrivateLegacyAVCF::label() const 87{ 88 if (!m_playerItemTrack) 89 return emptyAtom; 90 91 RetainPtr<CFStringRef> title; 92 93 RetainPtr<AVCFAssetTrackRef> assetTrack = adoptCF(AVCFPlayerItemTrackCopyAssetTrack(m_playerItemTrack.get())); 94 RetainPtr<CFArrayRef> commonMetaData = adoptCF(AVCFAssetTrackCopyCommonMetadata(assetTrack.get())); 95 RetainPtr<CFArrayRef> titles = adoptCF(AVCFMetadataItemCopyItemsWithKeyAndKeySpace(commonMetaData.get(), AVCFMetadataCommonKeyTitle, AVCFMetadataKeySpaceCommon)); 96 CFIndex titlesCount = CFArrayGetCount(titles.get()); 97 if (titlesCount) { 98 RetainPtr<CFLocaleRef> currentLocale = adoptCF(CFLocaleCopyCurrent()); 99 RetainPtr<CFArrayRef> titlesForPreferredLanguages = adoptCF(AVCFMetadataItemCopyItemsWithLocale(titles.get(), currentLocale.get())); 100 CFIndex preferredTitlesCount = CFArrayGetCount(titlesForPreferredLanguages.get()); 101 if (preferredTitlesCount) { 102 AVCFMetadataItemRef titleMetadata = static_cast<AVCFMetadataItemRef>(CFArrayGetValueAtIndex(titlesForPreferredLanguages.get(), 0)); 103 title = adoptCF(AVCFMetadataItemCopyStringValue(titleMetadata)); 104 } 105 106 if (!title) { 107 AVCFMetadataItemRef titleMetadata = static_cast<AVCFMetadataItemRef>(CFArrayGetValueAtIndex(titles.get(), 0)); 108 title = adoptCF(AVCFMetadataItemCopyStringValue(titleMetadata)); 109 } 110 } 111 112 return title ? AtomicString(title.get()) : emptyAtom; 113} 114 115AtomicString InbandTextTrackPrivateLegacyAVCF::language() const 116{ 117 if (!m_playerItemTrack) 118 return emptyAtom; 119 120 RetainPtr<AVCFAssetTrackRef> assetTrack = adoptCF(AVCFPlayerItemTrackCopyAssetTrack(m_playerItemTrack.get())); 121 RetainPtr<CFStringRef> languageCode = adoptCF(AVCFAssetTrackCopyLanguageCode(assetTrack.get())); 122 RetainPtr<CFLocaleRef> locale = adoptCF(CFLocaleCreate(kCFAllocatorDefault, languageCode.get())); 123 return CFLocaleGetIdentifier(locale.get()); 124} 125 126} // namespace WebCore 127 128#endif 129