1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "content/public/common/media_stream_request.h"
7 #include "base/logging.h"
11 bool IsAudioInputMediaType(MediaStreamType type
) {
12 return (type
== MEDIA_DEVICE_AUDIO_CAPTURE
||
13 type
== content::MEDIA_TAB_AUDIO_CAPTURE
||
14 type
== content::MEDIA_DESKTOP_AUDIO_CAPTURE
);
17 bool IsVideoMediaType(MediaStreamType type
) {
18 return (type
== MEDIA_DEVICE_VIDEO_CAPTURE
||
19 type
== content::MEDIA_TAB_VIDEO_CAPTURE
||
20 type
== content::MEDIA_DESKTOP_VIDEO_CAPTURE
);
23 MediaStreamDevice::MediaStreamDevice()
24 : type(MEDIA_NO_SERVICE
),
25 video_facing(MEDIA_VIDEO_FACING_NONE
) {
28 MediaStreamDevice::MediaStreamDevice(
30 const std::string
& id
,
31 const std::string
& name
)
34 video_facing(MEDIA_VIDEO_FACING_NONE
),
36 #if defined(OS_ANDROID)
37 if (name
.find("front") != std::string::npos
) {
38 video_facing
= MEDIA_VIDEO_FACING_USER
;
39 } else if (name
.find("back") != std::string::npos
) {
40 video_facing
= MEDIA_VIDEO_FACING_ENVIRONMENT
;
45 MediaStreamDevice::MediaStreamDevice(
47 const std::string
& id
,
48 const std::string
& name
,
51 int frames_per_buffer
)
54 video_facing(MEDIA_VIDEO_FACING_NONE
),
56 input(sample_rate
, channel_layout
, frames_per_buffer
) {
59 MediaStreamDevice::~MediaStreamDevice() {}
61 bool MediaStreamDevice::IsEqual(const MediaStreamDevice
& second
) const {
62 const AudioDeviceParameters
& input_second
= second
.input
;
63 return type
== second
.type
&&
64 name
== second
.name
&&
66 input
.sample_rate
== input_second
.sample_rate
&&
67 input
.channel_layout
== input_second
.channel_layout
;
70 MediaStreamDevices::MediaStreamDevices() {}
72 MediaStreamDevices::MediaStreamDevices(size_t count
,
73 const MediaStreamDevice
& value
)
74 : std::vector
<MediaStreamDevice
>(count
, value
) {
77 const MediaStreamDevice
* MediaStreamDevices::FindById(
78 const std::string
& device_id
) const {
79 for (const_iterator iter
= begin(); iter
!= end(); ++iter
) {
80 if (iter
->id
== device_id
)
86 MediaStreamDevice::AudioDeviceParameters::AudioDeviceParameters()
87 : sample_rate(), channel_layout(), frames_per_buffer(), effects() {}
89 MediaStreamDevice::AudioDeviceParameters::AudioDeviceParameters(
92 int frames_per_buffer
)
93 : sample_rate(sample_rate
),
94 channel_layout(channel_layout
),
95 frames_per_buffer(frames_per_buffer
),
98 MediaStreamDevice::AudioDeviceParameters::~AudioDeviceParameters() {}
100 MediaStreamRequest::MediaStreamRequest(
101 int render_process_id
,
104 const GURL
& security_origin
,
106 MediaStreamRequestType request_type
,
107 const std::string
& requested_audio_device_id
,
108 const std::string
& requested_video_device_id
,
109 MediaStreamType audio_type
,
110 MediaStreamType video_type
)
111 : render_process_id(render_process_id
),
112 render_frame_id(render_frame_id
),
113 page_request_id(page_request_id
),
114 security_origin(security_origin
),
115 user_gesture(user_gesture
),
116 request_type(request_type
),
117 requested_audio_device_id(requested_audio_device_id
),
118 requested_video_device_id(requested_video_device_id
),
119 audio_type(audio_type
),
120 video_type(video_type
),
121 all_ancestors_have_same_origin(false) {
124 MediaStreamRequest::~MediaStreamRequest() {}
126 } // namespace content