/src/mozilla-central/dom/media/gmp/GMPVideoHost.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | #include "GMPVideoHost.h" |
7 | | #include "mozilla/Assertions.h" |
8 | | #include "GMPVideoi420FrameImpl.h" |
9 | | #include "GMPVideoEncodedFrameImpl.h" |
10 | | |
11 | | namespace mozilla { |
12 | | namespace gmp { |
13 | | |
14 | | GMPVideoHostImpl::GMPVideoHostImpl(GMPSharedMemManager* aSharedMemMgr) |
15 | | : mSharedMemMgr(aSharedMemMgr) |
16 | 0 | { |
17 | 0 | } |
18 | | |
19 | | GMPVideoHostImpl::~GMPVideoHostImpl() |
20 | 0 | { |
21 | 0 | } |
22 | | |
23 | | GMPErr |
24 | | GMPVideoHostImpl::CreateFrame(GMPVideoFrameFormat aFormat, GMPVideoFrame** aFrame) |
25 | 0 | { |
26 | 0 | if (!mSharedMemMgr) { |
27 | 0 | return GMPGenericErr; |
28 | 0 | } |
29 | 0 | |
30 | 0 | if (!aFrame) { |
31 | 0 | return GMPGenericErr; |
32 | 0 | } |
33 | 0 | *aFrame = nullptr; |
34 | 0 |
|
35 | 0 | switch (aFormat) { |
36 | 0 | case kGMPI420VideoFrame: |
37 | 0 | *aFrame = new GMPVideoi420FrameImpl(this); |
38 | 0 | return GMPNoErr; |
39 | 0 | case kGMPEncodedVideoFrame: |
40 | 0 | *aFrame = new GMPVideoEncodedFrameImpl(this); |
41 | 0 | return GMPNoErr; |
42 | 0 | default: |
43 | 0 | MOZ_ASSERT_UNREACHABLE("Unknown frame format!"); |
44 | 0 | } |
45 | 0 |
|
46 | 0 | return GMPGenericErr; |
47 | 0 | } |
48 | | |
49 | | GMPErr |
50 | | GMPVideoHostImpl::CreatePlane(GMPPlane** aPlane) |
51 | 0 | { |
52 | 0 | if (!mSharedMemMgr) { |
53 | 0 | return GMPGenericErr; |
54 | 0 | } |
55 | 0 | |
56 | 0 | if (!aPlane) { |
57 | 0 | return GMPGenericErr; |
58 | 0 | } |
59 | 0 | *aPlane = nullptr; |
60 | 0 |
|
61 | 0 | auto p = new GMPPlaneImpl(this); |
62 | 0 |
|
63 | 0 | *aPlane = p; |
64 | 0 |
|
65 | 0 | return GMPNoErr; |
66 | 0 | } |
67 | | |
68 | | GMPSharedMemManager* |
69 | | GMPVideoHostImpl::SharedMemMgr() |
70 | 0 | { |
71 | 0 | return mSharedMemMgr; |
72 | 0 | } |
73 | | |
74 | | // XXX This should merge with ActorDestroyed |
75 | | void |
76 | | GMPVideoHostImpl::DoneWithAPI() |
77 | 0 | { |
78 | 0 | ActorDestroyed(); |
79 | 0 | } |
80 | | |
81 | | void |
82 | | GMPVideoHostImpl::ActorDestroyed() |
83 | 0 | { |
84 | 0 | for (uint32_t i = mPlanes.Length(); i > 0; i--) { |
85 | 0 | mPlanes[i - 1]->DoneWithAPI(); |
86 | 0 | mPlanes.RemoveElementAt(i - 1); |
87 | 0 | } |
88 | 0 | for (uint32_t i = mEncodedFrames.Length(); i > 0; i--) { |
89 | 0 | mEncodedFrames[i - 1]->DoneWithAPI(); |
90 | 0 | mEncodedFrames.RemoveElementAt(i - 1); |
91 | 0 | } |
92 | 0 | mSharedMemMgr = nullptr; |
93 | 0 | } |
94 | | |
95 | | void |
96 | | GMPVideoHostImpl::PlaneCreated(GMPPlaneImpl* aPlane) |
97 | 0 | { |
98 | 0 | mPlanes.AppendElement(aPlane); |
99 | 0 | } |
100 | | |
101 | | void |
102 | | GMPVideoHostImpl::PlaneDestroyed(GMPPlaneImpl* aPlane) |
103 | 0 | { |
104 | 0 | MOZ_ALWAYS_TRUE(mPlanes.RemoveElement(aPlane)); |
105 | 0 | } |
106 | | |
107 | | void |
108 | | GMPVideoHostImpl::EncodedFrameCreated(GMPVideoEncodedFrameImpl* aEncodedFrame) |
109 | 0 | { |
110 | 0 | mEncodedFrames.AppendElement(aEncodedFrame); |
111 | 0 | } |
112 | | |
113 | | void |
114 | | GMPVideoHostImpl::EncodedFrameDestroyed(GMPVideoEncodedFrameImpl* aFrame) |
115 | 0 | { |
116 | 0 | MOZ_ALWAYS_TRUE(mEncodedFrames.RemoveElement(aFrame)); |
117 | 0 | } |
118 | | |
119 | | } // namespace gmp |
120 | | } // namespace mozilla |