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