summaryrefslogtreecommitdiffstats
path: root/content/renderer/media/rtc_media_constraints.cc
blob: 9118152f0bc9230272dacbec4efdb5d26999bc4e (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
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "content/renderer/media/rtc_media_constraints.h"

#include "base/logging.h"

#include "content/common/media/media_stream_options.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebMediaConstraints.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebCString.h"
#include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"

namespace content {
namespace {

void GetNativeMediaConstraints(
    const WebKit::WebVector<WebKit::WebMediaConstraint>& constraints,
    webrtc::MediaConstraintsInterface::Constraints* native_constraints) {
  DCHECK(native_constraints);
  for (size_t i = 0; i < constraints.size(); ++i) {
    webrtc::MediaConstraintsInterface::Constraint new_constraint;
    new_constraint.key = constraints[i].m_name.utf8();
    new_constraint.value = constraints[i].m_value.utf8();

    // Ignore Chrome specific Tab capture constraints.
    if (new_constraint.key == kMediaStreamSource ||
        new_constraint.key == kMediaStreamSourceId)
      continue;
    DVLOG(3) << "MediaStreamConstraints:" << new_constraint.key
             << " : " <<  new_constraint.value;
    native_constraints->push_back(new_constraint);
  }
}

}  // namespace

RTCMediaConstraints::RTCMediaConstraints(
      const WebKit::WebMediaConstraints& constraints) {
  if (constraints.isNull())
    return;  // Will happen in unit tests.
  WebKit::WebVector<WebKit::WebMediaConstraint> mandatory;
  constraints.getMandatoryConstraints(mandatory);
  GetNativeMediaConstraints(mandatory, &mandatory_);
  WebKit::WebVector<WebKit::WebMediaConstraint> optional;
  constraints.getOptionalConstraints(optional);
  GetNativeMediaConstraints(optional, &optional_);
}

RTCMediaConstraints::~RTCMediaConstraints() {}

const webrtc::MediaConstraintsInterface::Constraints&
RTCMediaConstraints::GetMandatory() const  {
  return mandatory_;
}

const webrtc::MediaConstraintsInterface::Constraints&
RTCMediaConstraints::GetOptional() const {
  return optional_;
}

}  // namespace content