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#import "config.h"
27#import "AudioTrackPrivateAVFObjC.h"
28
29#if ENABLE(VIDEO_TRACK)
30
31#import "SoftLinking.h"
32#import <objc/runtime.h>
33#import <AVFoundation/AVAssetTrack.h>
34#import <AVFoundation/AVPlayerItemTrack.h>
35#import <AVFoundation/AVMetadataItem.h>
36
37SOFT_LINK_FRAMEWORK_OPTIONAL(AVFoundation)
38
39SOFT_LINK_CLASS(AVFoundation, AVAssetTrack)
40SOFT_LINK_CLASS(AVFoundation, AVPlayerItemTrack)
41
42SOFT_LINK_POINTER(AVFoundation, AVMediaCharacteristicIsMainProgramContent, NSString *)
43SOFT_LINK_POINTER(AVFoundation, AVMediaCharacteristicDescribesVideoForAccessibility, NSString *)
44SOFT_LINK_POINTER(AVFoundation, AVMediaCharacteristicIsAuxiliaryContent, NSString *)
45SOFT_LINK_POINTER(AVFoundation, AVMediaCharacteristicTranscribesSpokenDialogForAccessibility, NSString *)
46SOFT_LINK_POINTER(AVFoundation, AVMetadataCommonKeyTitle, NSString *)
47
48#define AVMediaCharacteristicIsMainProgramContent getAVMediaCharacteristicIsMainProgramContent()
49#define AVMediaCharacteristicDescribesVideoForAccessibility getAVMediaCharacteristicDescribesVideoForAccessibility()
50#define AVMediaCharacteristicIsAuxiliaryContent getAVMediaCharacteristicIsAuxiliaryContent()
51#define AVMediaCharacteristicTranscribesSpokenDialogForAccessibility getAVMediaCharacteristicTranscribesSpokenDialogForAccessibility()
52#define AVMetadataCommonKeyTitle getAVMetadataCommonKeyTitle()
53
54namespace WebCore {
55
56AudioTrackPrivateAVFObjC::AudioTrackPrivateAVFObjC(AVPlayerItemTrack* track)
57 : m_playerItemTrack(track)
58{
59 resetPropertiesFromTrack();
60}
61
62void AudioTrackPrivateAVFObjC::resetPropertiesFromTrack()
63{
64 AVAssetTrack* assetTrack = [m_playerItemTrack.get() assetTrack];
65 if (!assetTrack) {
66 setEnabled(false);
67 setKind(None);
68 setId(emptyAtom);
69 setLabel(emptyAtom);
70 setLanguage(emptyAtom);
71 return;
72 }
73
74 setEnabled([m_playerItemTrack.get() isEnabled]);
75 setId(String::format("%d", [assetTrack trackID]));
76
77 if ([assetTrack hasMediaCharacteristic:AVMediaCharacteristicDescribesVideoForAccessibility])
78 setKind(Description);
79 else if ([assetTrack hasMediaCharacteristic:AVMediaCharacteristicTranscribesSpokenDialogForAccessibility])
80 setKind(Translation);
81 else if ([assetTrack hasMediaCharacteristic:AVMediaCharacteristicIsAuxiliaryContent])
82 setKind(Alternative);
83 else if ([assetTrack hasMediaCharacteristic:AVMediaCharacteristicIsMainProgramContent])
84 setKind(Main);
85 else
86 setKind(None);
87
88 for (AVMetadataItem* item in [assetTrack commonMetadata]) {
89 if ([item.key isEqual:AVMetadataCommonKeyTitle]) {
90 setLabel((NSString*)item.value);
91 break;
92 }
93 }
94
95 setLanguage([assetTrack extendedLanguageTag]);
96}
97
98void AudioTrackPrivateAVFObjC::setPlayerItemTrack(AVPlayerItemTrack *track)
99{
100 m_playerItemTrack = track;
101 resetPropertiesFromTrack();
102}
103
104void AudioTrackPrivateAVFObjC::setEnabled(bool enabled)
105{
106 AudioTrackPrivateAVF::setEnabled(enabled);
107 [m_playerItemTrack.get() setEnabled:enabled];
108}
109
110}
111
112#endif
113