Skip to content

Commit c0e0423

Browse files
committed
rebase fix
1 parent 1c8b391 commit c0e0423

12 files changed

+492
-237
lines changed

nw.gypi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@
175175
'src/geolocation/shell_access_token_store.h',
176176
'src/media/media_internals.cc',
177177
'src/media/media_internals.h',
178+
'src/media/media_capture_devices_dispatcher.cc',
179+
'src/media/media_capture_devices_dispatcher.h',
178180
'src/media/media_stream_devices_controller.cc',
179181
'src/media/media_stream_devices_controller.h',
180182
'src/net/clear_on_exit_policy.h',

src/api/app/app.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ App.filteredArgv = [
2828
/--no-toolbar/,
2929
/--url=.*/,
3030
/--remote-debugging-port=.*/,
31+
/--renderer-cmd-prefix.*/,
3132
];
3233

3334
App.prototype.quit = function() {
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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.
4+
5+
#include "content/nw/src/media/media_capture_devices_dispatcher.h"
6+
7+
#include "content/public/browser/browser_thread.h"
8+
#include "content/public/browser/media_devices_monitor.h"
9+
#include "content/public/common/media_stream_request.h"
10+
11+
using content::BrowserThread;
12+
using content::MediaStreamDevices;
13+
14+
MediaCaptureDevicesDispatcher::MediaCaptureDevicesDispatcher()
15+
: devices_enumerated_(false) {}
16+
17+
MediaCaptureDevicesDispatcher::~MediaCaptureDevicesDispatcher() {}
18+
19+
void MediaCaptureDevicesDispatcher::AudioCaptureDevicesChanged(
20+
const MediaStreamDevices& devices) {
21+
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
22+
23+
BrowserThread::PostTask(
24+
BrowserThread::UI, FROM_HERE,
25+
base::Bind(&MediaCaptureDevicesDispatcher::UpdateAudioDevicesOnUIThread,
26+
this, devices));
27+
}
28+
29+
void MediaCaptureDevicesDispatcher::VideoCaptureDevicesChanged(
30+
const MediaStreamDevices& devices) {
31+
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
32+
33+
BrowserThread::PostTask(
34+
BrowserThread::UI, FROM_HERE,
35+
base::Bind(&MediaCaptureDevicesDispatcher::UpdateVideoDevicesOnUIThread,
36+
this, devices));
37+
}
38+
39+
void MediaCaptureDevicesDispatcher::AddObserver(Observer* observer) {
40+
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
41+
if (!observers_.HasObserver(observer))
42+
observers_.AddObserver(observer);
43+
}
44+
45+
void MediaCaptureDevicesDispatcher::RemoveObserver(Observer* observer) {
46+
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
47+
observers_.RemoveObserver(observer);
48+
}
49+
50+
const MediaStreamDevices&
51+
MediaCaptureDevicesDispatcher::GetAudioCaptureDevices() {
52+
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
53+
if (!devices_enumerated_) {
54+
BrowserThread::PostTask(
55+
BrowserThread::IO, FROM_HERE,
56+
base::Bind(&content::EnsureMonitorCaptureDevices));
57+
devices_enumerated_ = true;
58+
}
59+
return audio_devices_;
60+
}
61+
62+
const MediaStreamDevices&
63+
MediaCaptureDevicesDispatcher::GetVideoCaptureDevices() {
64+
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
65+
if (!devices_enumerated_) {
66+
BrowserThread::PostTask(
67+
BrowserThread::IO, FROM_HERE,
68+
base::Bind(&content::EnsureMonitorCaptureDevices));
69+
devices_enumerated_ = true;
70+
}
71+
return video_devices_;
72+
}
73+
74+
void MediaCaptureDevicesDispatcher::UpdateAudioDevicesOnUIThread(
75+
const content::MediaStreamDevices& devices) {
76+
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
77+
devices_enumerated_ = true;
78+
audio_devices_ = devices;
79+
FOR_EACH_OBSERVER(Observer, observers_,
80+
OnUpdateAudioDevices(audio_devices_));
81+
}
82+
83+
void MediaCaptureDevicesDispatcher::UpdateVideoDevicesOnUIThread(
84+
const content::MediaStreamDevices& devices){
85+
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
86+
devices_enumerated_ = true;
87+
video_devices_ = devices;
88+
FOR_EACH_OBSERVER(Observer, observers_,
89+
OnUpdateVideoDevices(video_devices_));
90+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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.
4+
5+
#ifndef NW_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_
6+
#define NW_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_
7+
8+
#include "base/memory/ref_counted.h"
9+
#include "base/memory/scoped_ptr.h"
10+
#include "base/observer_list.h"
11+
#include "content/public/common/media_stream_request.h"
12+
13+
// This observer is owned by MediaInternals and deleted when MediaInternals
14+
// is deleted.
15+
class MediaCaptureDevicesDispatcher
16+
: public base::RefCountedThreadSafe<MediaCaptureDevicesDispatcher> {
17+
public:
18+
class Observer {
19+
public:
20+
// Handle an information update consisting of a up-to-date audio capture
21+
// device lists. This happens when a microphone is plugged in or unplugged.
22+
virtual void OnUpdateAudioDevices(
23+
const content::MediaStreamDevices& devices) {}
24+
25+
// Handle an information update consisting of a up-to-date video capture
26+
// device lists. This happens when a camera is plugged in or unplugged.
27+
virtual void OnUpdateVideoDevices(
28+
const content::MediaStreamDevices& devices) {}
29+
30+
virtual ~Observer() {}
31+
};
32+
33+
MediaCaptureDevicesDispatcher();
34+
35+
// Called on IO thread when one audio device is plugged in or unplugged.
36+
void AudioCaptureDevicesChanged(const content::MediaStreamDevices& devices);
37+
38+
// Called on IO thread when one video device is plugged in or unplugged.
39+
void VideoCaptureDevicesChanged(const content::MediaStreamDevices& devices);
40+
41+
// Methods for observers. Called on UI thread.
42+
// Observers should add themselves on construction and remove themselves
43+
// on destruction.
44+
void AddObserver(Observer* observer);
45+
void RemoveObserver(Observer* observer);
46+
const content::MediaStreamDevices& GetAudioCaptureDevices();
47+
const content::MediaStreamDevices& GetVideoCaptureDevices();
48+
49+
private:
50+
friend class base::RefCountedThreadSafe<MediaCaptureDevicesDispatcher>;
51+
virtual ~MediaCaptureDevicesDispatcher();
52+
53+
// Called by the public Audio/VideoCaptureDevicesChanged() functions,
54+
// executed on UI thread.
55+
void UpdateAudioDevicesOnUIThread(const content::MediaStreamDevices& devices);
56+
void UpdateVideoDevicesOnUIThread(const content::MediaStreamDevices& devices);
57+
58+
// A list of cached audio capture devices.
59+
content::MediaStreamDevices audio_devices_;
60+
61+
// A list of cached video capture devices.
62+
content::MediaStreamDevices video_devices_;
63+
64+
// A list of observers for the device update notifications.
65+
ObserverList<Observer> observers_;
66+
67+
// Flag to indicate if device enumeration has been done/doing.
68+
// Only accessed on UI thread.
69+
bool devices_enumerated_;
70+
};
71+
72+
#endif // CHROME_BROWSER_MEDIA_MEDIA_CAPTURE_DEVICES_DISPATCHER_H_

src/media/media_internals.cc

Lines changed: 77 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,66 @@
2323
#include "base/memory/scoped_ptr.h"
2424
#include "base/string16.h"
2525
#include "base/stringprintf.h"
26+
#include "content/nw/src/media/media_capture_devices_dispatcher.h"
27+
#include "content/public/browser/browser_thread.h"
2628
#include "media/base/media_log.h"
2729
#include "media/base/media_log_event.h"
2830

31+
using content::BrowserThread;
32+
33+
namespace media {
34+
35+
namespace {
36+
37+
const content::MediaStreamDevice* FindDefaultDeviceWithId(
38+
const content::MediaStreamDevices& devices,
39+
const std::string& device_id) {
40+
if (devices.empty())
41+
return NULL;
42+
43+
content::MediaStreamDevices::const_iterator iter = devices.begin();
44+
for (; iter != devices.end(); ++iter) {
45+
if (iter->id == device_id) {
46+
return &(*iter);
47+
}
48+
}
49+
50+
return &(*devices.begin());
51+
};
52+
53+
} // namespace
54+
55+
void GetDefaultDevicesForProfile(bool audio,
56+
bool video,
57+
content::MediaStreamDevices* devices) {
58+
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
59+
DCHECK(audio || video);
60+
61+
MediaCaptureDevicesDispatcher* dispatcher =
62+
MediaInternals::GetInstance()->GetMediaCaptureDevicesDispatcher();
63+
if (audio) {
64+
std::string default_device;
65+
const content::MediaStreamDevices& audio_devices =
66+
dispatcher->GetAudioCaptureDevices();
67+
const content::MediaStreamDevice* const device =
68+
FindDefaultDeviceWithId(audio_devices, default_device);
69+
if (device)
70+
devices->push_back(*device);
71+
}
72+
73+
if (video) {
74+
std::string default_device;
75+
const content::MediaStreamDevices& video_devices =
76+
dispatcher->GetVideoCaptureDevices();
77+
const content::MediaStreamDevice* const device =
78+
FindDefaultDeviceWithId(video_devices, default_device);
79+
if (device)
80+
devices->push_back(*device);
81+
}
82+
}
83+
84+
} // namespace media
85+
2986
MediaInternals* MediaInternals::GetInstance() {
3087
return Singleton<MediaInternals>::get();
3188
}
@@ -63,11 +120,30 @@ void MediaInternals::OnCaptureDevicesClosed(
63120
const content::MediaStreamDevices& devices) {
64121
}
65122

123+
void MediaInternals::OnAudioCaptureDevicesChanged(
124+
const content::MediaStreamDevices& devices) {
125+
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
126+
media_devices_dispatcher_->AudioCaptureDevicesChanged(devices);
127+
}
128+
129+
void MediaInternals::OnVideoCaptureDevicesChanged(
130+
const content::MediaStreamDevices& devices) {
131+
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
132+
media_devices_dispatcher_->VideoCaptureDevicesChanged(devices);
133+
}
134+
66135
void MediaInternals::OnMediaRequestStateChanged(
67136
int render_process_id,
68137
int render_view_id,
69138
const content::MediaStreamDevice& device,
70139
content::MediaRequestState state) {
71140
}
72141

73-
MediaInternals::MediaInternals() {}
142+
scoped_refptr<MediaCaptureDevicesDispatcher>
143+
MediaInternals::GetMediaCaptureDevicesDispatcher() {
144+
return media_devices_dispatcher_;
145+
}
146+
147+
MediaInternals::MediaInternals()
148+
: media_devices_dispatcher_(new MediaCaptureDevicesDispatcher()) {
149+
}

src/media/media_internals.h

Lines changed: 63 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
1-
// Copyright (c) 2012 Intel Corp
2-
// Copyright (c) 2012 The Chromium Authors
3-
//
4-
// Permission is hereby granted, free of charge, to any person obtaining a copy
5-
// of this software and associated documentation files (the "Software"), to deal
6-
// in the Software without restriction, including without limitation the rights
7-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell co
8-
// pies of the Software, and to permit persons to whom the Software is furnished
9-
// to do so, subject to the following conditions:
10-
//
11-
// The above copyright notice and this permission notice shall be included in al
12-
// l copies or substantial portions of the Software.
13-
//
14-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM
15-
// PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNES
16-
// S FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
17-
// OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WH
18-
// ETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19-
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20-
21-
#ifndef CONTENT_NW_SRC_MEDIA_MEDIA_INTERNALS_H_
22-
#define CONTENT_NW_SRC_MEDIA_MEDIA_INTERNALS_H_
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.
4+
5+
#ifndef NW_MEDIA_MEDIA_INTERNALS_H_
6+
#define NW_MEDIA_MEDIA_INTERNALS_H_
7+
8+
#include <string>
239

2410
#include "base/memory/ref_counted.h"
2511
#include "base/memory/singleton.h"
2612
#include "base/observer_list.h"
2713
#include "base/values.h"
2814
#include "content/public/browser/media_observer.h"
15+
#include "content/public/common/media_stream_request.h"
16+
17+
class MediaCaptureDevicesDispatcher;
18+
class MediaInternalsObserver;
19+
class MediaStreamCaptureIndicator;
20+
21+
namespace media {
22+
23+
struct MediaLogEvent;
24+
25+
// Helper to get the default devices which can be used by the media request,
26+
// if the return list is empty, it means there is no available device on the OS.
27+
// Called on the UI thread.
28+
void GetDefaultDevicesForProfile(
29+
bool audio,
30+
bool video,
31+
content::MediaStreamDevices* devices);
32+
33+
}
2934

3035
// This class stores information about currently active media.
3136
// It's constructed on the UI thread but all of its methods are called on the IO
@@ -58,21 +63,54 @@ class MediaInternals : public content::MediaObserver {
5863
int render_view_id,
5964
const content::MediaStreamDevices& devices) OVERRIDE;
6065
virtual void OnAudioCaptureDevicesChanged(
61-
const content::MediaStreamDevices& devices) OVERRIDE {}
66+
const content::MediaStreamDevices& devices) OVERRIDE;
6267
virtual void OnVideoCaptureDevicesChanged(
63-
const content::MediaStreamDevices& devices) OVERRIDE {}
68+
const content::MediaStreamDevices& devices) OVERRIDE;
6469
virtual void OnMediaRequestStateChanged(
6570
int render_process_id,
6671
int render_view_id,
6772
const content::MediaStreamDevice& device,
6873
content::MediaRequestState state) OVERRIDE;
6974

75+
// Methods for observers.
76+
// Observers should add themselves on construction and remove themselves
77+
// on destruction.
78+
void AddObserver(MediaInternalsObserver* observer);
79+
void RemoveObserver(MediaInternalsObserver* observer);
80+
void SendEverything();
81+
82+
scoped_refptr<MediaStreamCaptureIndicator> GetMediaStreamCaptureIndicator();
83+
scoped_refptr<MediaCaptureDevicesDispatcher>
84+
GetMediaCaptureDevicesDispatcher();
85+
7086
private:
87+
friend class MediaInternalsTest;
7188
friend struct DefaultSingletonTraits<MediaInternals>;
7289

7390
MediaInternals();
7491

92+
// Sets |property| of an audio stream to |value| and notifies observers.
93+
// (host, stream_id) is a unique id for the audio stream.
94+
// |host| will never be dereferenced.
95+
void UpdateAudioStream(void* host, int stream_id,
96+
const std::string& property, Value* value);
97+
98+
// Removes |item| from |data_|.
99+
void DeleteItem(const std::string& item);
100+
101+
// Sets data_.id.property = value and notifies attached UIs using update_fn.
102+
// id may be any depth, e.g. "video.decoders.1.2.3"
103+
void UpdateItem(const std::string& update_fn, const std::string& id,
104+
const std::string& property, Value* value);
105+
106+
// Calls javascript |function|(|value|) on each attached UI.
107+
void SendUpdate(const std::string& function, Value* value);
108+
109+
DictionaryValue data_;
110+
ObserverList<MediaInternalsObserver> observers_;
111+
scoped_refptr<MediaCaptureDevicesDispatcher> media_devices_dispatcher_;
112+
75113
DISALLOW_COPY_AND_ASSIGN(MediaInternals);
76114
};
77115

78-
#endif // CONTENT_NW_SRC_MEDIA_MEDIA_INTERNALS_H_
116+
#endif // CHROME_BROWSER_MEDIA_MEDIA_INTERNALS_H_

0 commit comments

Comments
 (0)