OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/renderer/media/media_stream_impl.h" | 5 #include "content/renderer/media/media_stream_impl.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "content/renderer/media/capture_video_decoder.h" | 8 #include "content/renderer/media/capture_video_decoder.h" |
| 9 #include "content/renderer/media/media_stream_dispatcher.h" |
9 #include "content/renderer/media/video_capture_impl_manager.h" | 10 #include "content/renderer/media/video_capture_impl_manager.h" |
10 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
11 #include "media/base/message_loop_factory.h" | 12 #include "media/base/message_loop_factory.h" |
12 #include "media/base/pipeline.h" | 13 #include "media/base/pipeline.h" |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 static const int kVideoCaptureWidth = 352; | 17 static const int kVideoCaptureWidth = 352; |
17 static const int kVideoCaptureHeight = 288; | 18 static const int kVideoCaptureHeight = 288; |
18 static const int kVideoCaptureFramePerSecond = 30; | 19 static const int kVideoCaptureFramePerSecond = 30; |
19 | 20 |
20 static const int kStartOpenSessionId = 1; | 21 static const int kStartOpenSessionId = 1; |
21 | 22 |
22 // TODO(wjia): remove this string when full media stream code is checked in. | 23 // TODO(wjia): remove this string when full media stream code is checked in. |
23 static const char kRawMediaScheme[] = "mediastream"; | 24 static const char kRawMediaScheme[] = "mediastream"; |
24 | 25 |
| 26 static int desired_device_index = 0; |
| 27 static int next_request_id = 1; |
| 28 |
25 } // namespace | 29 } // namespace |
26 | 30 |
27 MediaStreamImpl::MediaStreamImpl(VideoCaptureImplManager* vc_manager) | 31 MediaStreamImpl::MediaStreamImpl( |
28 : vc_manager_(vc_manager) { | 32 MediaStreamDispatcher* media_stream_dispatcher, |
| 33 VideoCaptureImplManager* vc_manager) |
| 34 : media_stream_dispatcher_(media_stream_dispatcher), |
| 35 vc_manager_(vc_manager) { |
29 } | 36 } |
30 | 37 |
31 MediaStreamImpl::~MediaStreamImpl() {} | 38 MediaStreamImpl::~MediaStreamImpl() {} |
32 | 39 |
| 40 void MediaStreamImpl::GetVideoDevice(int index) { |
| 41 desired_device_index = index; |
| 42 media_stream_dispatcher_->EnumerateVideoDevices(next_request_id++, this, ""); |
| 43 } |
| 44 |
33 scoped_refptr<media::VideoDecoder> MediaStreamImpl::GetVideoDecoder( | 45 scoped_refptr<media::VideoDecoder> MediaStreamImpl::GetVideoDecoder( |
34 const GURL& url, media::MessageLoopFactory* message_loop_factory) { | 46 const GURL& url, media::MessageLoopFactory* message_loop_factory) { |
35 bool raw_media = (url.spec().find(kRawMediaScheme) == 0); | 47 bool raw_media = (url.spec().find(kRawMediaScheme) == 0); |
36 media::VideoDecoder* decoder = NULL; | 48 media::VideoDecoder* decoder = NULL; |
| 49 int session_id = media_stream_dispatcher_->video_session_id(local_label_, 0); |
| 50 if (session_id == media_stream::StreamDeviceInfo::kNoId) |
| 51 session_id = kStartOpenSessionId; |
37 if (raw_media) { | 52 if (raw_media) { |
38 media::VideoCapture::VideoCaptureCapability capability; | 53 media::VideoCapture::VideoCaptureCapability capability; |
39 capability.width = kVideoCaptureWidth; | 54 capability.width = kVideoCaptureWidth; |
40 capability.height = kVideoCaptureHeight; | 55 capability.height = kVideoCaptureHeight; |
41 capability.max_fps = kVideoCaptureFramePerSecond; | 56 capability.max_fps = kVideoCaptureFramePerSecond; |
42 capability.expected_capture_delay = 0; | 57 capability.expected_capture_delay = 0; |
43 capability.raw_type = media::VideoFrame::I420; | 58 capability.raw_type = media::VideoFrame::I420; |
44 capability.interlaced = false; | 59 capability.interlaced = false; |
45 | 60 |
46 decoder = new CaptureVideoDecoder( | 61 decoder = new CaptureVideoDecoder( |
47 message_loop_factory->GetMessageLoopProxy("CaptureVideoDecoder").get(), | 62 message_loop_factory->GetMessageLoopProxy("CaptureVideoDecoder").get(), |
48 kStartOpenSessionId, vc_manager_.get(), capability); | 63 session_id, vc_manager_.get(), capability); |
49 } | 64 } |
50 return decoder; | 65 return decoder; |
51 } | 66 } |
| 67 |
| 68 void MediaStreamImpl::OnStreamGenerated( |
| 69 int request_id, |
| 70 const std::string& label, |
| 71 const media_stream::StreamDeviceInfoArray& audio_array, |
| 72 const media_stream::StreamDeviceInfoArray& video_array) { |
| 73 DVLOG(1) << "MediaStreamImpl::OnStreamGenerated(" |
| 74 << request_id << ", " << label << ")"; |
| 75 NOTIMPLEMENTED(); |
| 76 } |
| 77 |
| 78 void MediaStreamImpl::OnStreamGenerationFailed(int request_id) { |
| 79 DVLOG(1) << "MediaStreamImpl::OnStreamGenerationFailed(" |
| 80 << request_id << ")"; |
| 81 NOTIMPLEMENTED(); |
| 82 } |
| 83 |
| 84 void MediaStreamImpl::OnVideoDeviceFailed(const std::string& label, |
| 85 int index) { |
| 86 DVLOG(1) << "MediaStreamImpl::OnVideoDeviceFailed(" |
| 87 << label << ", " << index << ")"; |
| 88 NOTIMPLEMENTED(); |
| 89 } |
| 90 |
| 91 void MediaStreamImpl::OnAudioDeviceFailed(const std::string& label, |
| 92 int index) { |
| 93 DVLOG(1) << "MediaStreamImpl::OnAudioDeviceFailed(" |
| 94 << label << ", " << index << ")"; |
| 95 NOTIMPLEMENTED(); |
| 96 } |
| 97 |
| 98 void MediaStreamImpl::OnVideoDevicesEnumerated( |
| 99 int request_id, |
| 100 const media_stream::StreamDeviceInfoArray& device_array) { |
| 101 DVLOG(1) << "MediaStreamImpl::OnVideoDevicesEnumerated(" |
| 102 << request_id << ")"; |
| 103 media_stream::StreamDeviceInfoArray::const_iterator it; |
| 104 for (it = device_array.begin(); it != device_array.end(); it++) { |
| 105 } |
| 106 if (desired_device_index < static_cast<int>(device_array.size())) { |
| 107 media_stream_dispatcher_->OpenVideoDevice( |
| 108 next_request_id++, this, |
| 109 device_array[desired_device_index].device_id, ""); |
| 110 } |
| 111 } |
| 112 |
| 113 void MediaStreamImpl::OnVideoDevicesEnumerationFailed(int request_id) { |
| 114 DVLOG(1) << "MediaStreamImpl::OnVideoDevicesEnumerationFailed(" |
| 115 << request_id << ")"; |
| 116 NOTIMPLEMENTED(); |
| 117 } |
| 118 |
| 119 void MediaStreamImpl::OnVideoDeviceOpened( |
| 120 int request_id, |
| 121 const std::string& label, |
| 122 const media_stream::StreamDeviceInfo& video_device) { |
| 123 DVLOG(1) << "MediaStreamImpl::OnVideoDeviceOpened(" |
| 124 << request_id << ", " << label << ")"; |
| 125 local_label_ = label; |
| 126 } |
| 127 |
| 128 void MediaStreamImpl::OnVideoDeviceOpenFailed(int request_id) { |
| 129 DVLOG(1) << "MediaStreamImpl::VideoDeviceOpenFailed(" |
| 130 << request_id << ")"; |
| 131 NOTIMPLEMENTED(); |
| 132 } |
| 133 |
OLD | NEW |