[WTF] Add makeUnique<T>, which ensures T is fast-allocated, makeUnique / makeUniqueWi...
[WebKit-https.git] / Source / WebCore / platform / graphics / avfoundation / objc / AudioTrackPrivateAVFObjC.mm
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 #import "AVTrackPrivateAVFObjCImpl.h"
29 #import "MediaSelectionGroupAVFObjC.h"
30
31 #if ENABLE(VIDEO_TRACK)
32
33 namespace WebCore {
34
35 AudioTrackPrivateAVFObjC::AudioTrackPrivateAVFObjC(AVPlayerItemTrack* track)
36     : m_impl(makeUnique<AVTrackPrivateAVFObjCImpl>(track))
37 {
38     resetPropertiesFromTrack();
39 }
40
41 AudioTrackPrivateAVFObjC::AudioTrackPrivateAVFObjC(MediaSelectionOptionAVFObjC& option)
42     : m_impl(makeUnique<AVTrackPrivateAVFObjCImpl>(option))
43 {
44     resetPropertiesFromTrack();
45 }
46
47 void AudioTrackPrivateAVFObjC::resetPropertiesFromTrack()
48 {
49     // Don't call this->setEnabled() because it also sets the enabled state of the
50     // AVPlayerItemTrack
51     AudioTrackPrivateAVF::setEnabled(m_impl->enabled());
52
53     setTrackIndex(m_impl->index());
54     setKind(m_impl->audioKind());
55     setId(m_impl->id());
56     setLabel(m_impl->label());
57     setLanguage(m_impl->language());
58 }
59
60 void AudioTrackPrivateAVFObjC::setPlayerItemTrack(AVPlayerItemTrack *track)
61 {
62     m_impl = makeUnique<AVTrackPrivateAVFObjCImpl>(track);
63     resetPropertiesFromTrack();
64 }
65
66 AVPlayerItemTrack* AudioTrackPrivateAVFObjC::playerItemTrack()
67 {
68     return m_impl->playerItemTrack();
69 }
70
71 AudioTrackPrivateAVFObjC::AudioTrackPrivateAVFObjC(AVAssetTrack* track)
72     : m_impl(makeUnique<AVTrackPrivateAVFObjCImpl>(track))
73 {
74     resetPropertiesFromTrack();
75 }
76
77 void AudioTrackPrivateAVFObjC::setAssetTrack(AVAssetTrack *track)
78 {
79     m_impl = makeUnique<AVTrackPrivateAVFObjCImpl>(track);
80     resetPropertiesFromTrack();
81 }
82
83 AVAssetTrack* AudioTrackPrivateAVFObjC::assetTrack()
84 {
85     return m_impl->assetTrack();
86 }
87
88 void AudioTrackPrivateAVFObjC::setMediaSelectionOption(MediaSelectionOptionAVFObjC& option)
89 {
90     m_impl = makeUnique<AVTrackPrivateAVFObjCImpl>(option);
91     resetPropertiesFromTrack();
92 }
93
94 MediaSelectionOptionAVFObjC* AudioTrackPrivateAVFObjC::mediaSelectionOption()
95 {
96     return m_impl->mediaSelectionOption();
97 }
98
99 void AudioTrackPrivateAVFObjC::setEnabled(bool enabled)
100 {
101     AudioTrackPrivateAVF::setEnabled(enabled);
102     m_impl->setEnabled(enabled);
103 }
104
105 }
106
107 #endif
108