2 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include "public/platform/WebMediaConstraints.h"
35 #include "wtf/PassRefPtr.h"
36 #include "wtf/RefCounted.h"
40 class WebMediaConstraintsPrivate final
: public RefCounted
<WebMediaConstraintsPrivate
> {
42 static PassRefPtr
<WebMediaConstraintsPrivate
> create();
43 static PassRefPtr
<WebMediaConstraintsPrivate
> create(const WebVector
<WebMediaConstraint
>& optional
, const WebVector
<WebMediaConstraint
>& mandatory
);
45 void getOptionalConstraints(WebVector
<WebMediaConstraint
>&);
46 void getMandatoryConstraints(WebVector
<WebMediaConstraint
>&);
47 bool getMandatoryConstraintValue(const WebString
& name
, WebString
& value
);
48 bool getOptionalConstraintValue(const WebString
& name
, WebString
& value
);
51 WebMediaConstraintsPrivate(const WebVector
<WebMediaConstraint
>& optional
, const WebVector
<WebMediaConstraint
>& mandatory
);
53 WebVector
<WebMediaConstraint
> m_optional
;
54 WebVector
<WebMediaConstraint
> m_mandatory
;
57 PassRefPtr
<WebMediaConstraintsPrivate
> WebMediaConstraintsPrivate::create()
59 WebVector
<WebMediaConstraint
> optional
;
60 WebVector
<WebMediaConstraint
> mandatory
;
61 return adoptRef(new WebMediaConstraintsPrivate(optional
, mandatory
));
64 PassRefPtr
<WebMediaConstraintsPrivate
> WebMediaConstraintsPrivate::create(const WebVector
<WebMediaConstraint
>& optional
, const WebVector
<WebMediaConstraint
>& mandatory
)
66 return adoptRef(new WebMediaConstraintsPrivate(optional
, mandatory
));
69 WebMediaConstraintsPrivate::WebMediaConstraintsPrivate(const WebVector
<WebMediaConstraint
>& optional
, const WebVector
<WebMediaConstraint
>& mandatory
)
70 : m_optional(optional
)
71 , m_mandatory(mandatory
)
75 void WebMediaConstraintsPrivate::getOptionalConstraints(WebVector
<WebMediaConstraint
>& constraints
)
77 constraints
= m_optional
;
80 void WebMediaConstraintsPrivate::getMandatoryConstraints(WebVector
<WebMediaConstraint
>& constraints
)
82 constraints
= m_mandatory
;
85 bool WebMediaConstraintsPrivate::getMandatoryConstraintValue(const WebString
& name
, WebString
& value
)
87 for (size_t i
= 0; i
< m_mandatory
.size(); ++i
) {
88 if (m_mandatory
[i
].m_name
== name
) {
89 value
= m_mandatory
[i
].m_value
;
96 bool WebMediaConstraintsPrivate::getOptionalConstraintValue(const WebString
& name
, WebString
& value
)
98 for (size_t i
= 0; i
< m_optional
.size(); ++i
) {
99 if (m_optional
[i
].m_name
== name
) {
100 value
= m_optional
[i
].m_value
;
107 // WebMediaConstraints
109 void WebMediaConstraints::assign(const WebMediaConstraints
& other
)
111 m_private
= other
.m_private
;
114 void WebMediaConstraints::reset()
119 void WebMediaConstraints::getMandatoryConstraints(WebVector
<WebMediaConstraint
>& constraints
) const
122 m_private
->getMandatoryConstraints(constraints
);
125 void WebMediaConstraints::getOptionalConstraints(WebVector
<WebMediaConstraint
>& constraints
) const
128 m_private
->getOptionalConstraints(constraints
);
131 bool WebMediaConstraints::getMandatoryConstraintValue(const WebString
& name
, WebString
& value
) const
134 return m_private
->getMandatoryConstraintValue(name
, value
);
137 bool WebMediaConstraints::getOptionalConstraintValue(const WebString
& name
, WebString
& value
) const
140 return m_private
->getOptionalConstraintValue(name
, value
);
143 void WebMediaConstraints::initialize()
146 m_private
= WebMediaConstraintsPrivate::create();
149 void WebMediaConstraints::initialize(const WebVector
<WebMediaConstraint
>& optional
, const WebVector
<WebMediaConstraint
>& mandatory
)
152 m_private
= WebMediaConstraintsPrivate::create(optional
, mandatory
);