Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: content/renderer/media/local_video_capture.cc

Issue 10918052: create a separate WebMediaPlayer for URL derived from media stream (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: code review Created 8 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
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/renderer/media/local_video_capture.h"
6
7 #include "content/renderer/media/video_capture_impl_manager.h"
8 #include "media/base/video_util.h"
9 #include "media/video/capture/video_capture_proxy.h"
10
11 using media::CopyYPlane;
12 using media::CopyUPlane;
13 using media::CopyVPlane;
14
15 namespace content {
16
17 LocalVideoCapture::LocalVideoCapture(
18 media::VideoCaptureSessionId video_stream_id,
19 VideoCaptureImplManager* vc_manager,
20 const media::VideoCaptureCapability& capability,
21 const base::Closure& error_cb,
22 const RepaintCB& repaint_cb)
23 : video_stream_id_(video_stream_id),
24 vc_manager_(vc_manager),
25 capability_(capability),
26 error_cb_(error_cb),
27 repaint_cb_(repaint_cb),
28 capture_engine_(NULL),
29 message_loop_proxy_(base::MessageLoopProxy::current()),
30 ALLOW_THIS_IN_INITIALIZER_LIST(
31 handler_proxy_(new media::VideoCaptureHandlerProxy(
32 this, message_loop_proxy_))),
33 state_(video_capture::kStopped) {
34 DVLOG(3) << "LocalVideoCapture::ctor";
35 DCHECK(vc_manager);
36 }
37
38 LocalVideoCapture::~LocalVideoCapture() {
39 DVLOG(3) << "LocalVideoCapture::dtor";
40 }
41
42 void LocalVideoCapture::Start() {
43 DVLOG(3) << "LocalVideoCapture::Start";
44 DCHECK(message_loop_proxy_->BelongsToCurrentThread());
45 DCHECK_EQ(state_, video_capture::kStopped);
46
47 capture_engine_ = vc_manager_->AddDevice(video_stream_id_, this);
48 state_ = video_capture::kStarted;
49 AddRef(); // Will be balanced in OnRemoved().
50 capture_engine_->StartCapture(handler_proxy_.get(), capability_);
51 }
52
53 void LocalVideoCapture::Stop() {
54 DVLOG(3) << "LocalVideoCapture::Stop";
55 DCHECK(message_loop_proxy_->BelongsToCurrentThread());
56 if (capture_engine_) {
57 state_ = video_capture::kStopping;
58 capture_engine_->StopCapture(handler_proxy_.get());
59 capture_engine_ = NULL;
60 }
61 }
62
63 void LocalVideoCapture::Play() {
64 DVLOG(3) << "LocalVideoCapture::Play";
65 DCHECK(message_loop_proxy_->BelongsToCurrentThread());
66 if (capture_engine_ && state_ == video_capture::kPaused) {
67 state_ = video_capture::kStarted;
68 }
69 }
70
71 void LocalVideoCapture::Pause() {
72 DVLOG(3) << "LocalVideoCapture::Pause";
73 DCHECK(message_loop_proxy_->BelongsToCurrentThread());
74 if (capture_engine_ && state_ == video_capture::kStarted) {
75 state_ = video_capture::kPaused;
76 }
77 }
78
79 void LocalVideoCapture::OnStarted(media::VideoCapture* capture) {
80 DCHECK(message_loop_proxy_->BelongsToCurrentThread());
81 NOTIMPLEMENTED();
82 }
83
84 void LocalVideoCapture::OnStopped(media::VideoCapture* capture) {
85 DCHECK(message_loop_proxy_->BelongsToCurrentThread());
86 NOTIMPLEMENTED();
87 }
88
89 void LocalVideoCapture::OnPaused(media::VideoCapture* capture) {
90 DCHECK(message_loop_proxy_->BelongsToCurrentThread());
91 NOTIMPLEMENTED();
92 }
93
94 void LocalVideoCapture::OnError(media::VideoCapture* capture,
95 int error_code) {
96 DVLOG(3) << "LocalVideoCapture::OnError, " << error_code;
97 DCHECK(message_loop_proxy_->BelongsToCurrentThread());
98 error_cb_.Run();
99 }
100
101 void LocalVideoCapture::OnRemoved(media::VideoCapture* capture) {
102 DVLOG(3) << "LocalVideoCapture::OnRemoved";
103 DCHECK(message_loop_proxy_->BelongsToCurrentThread());
104 vc_manager_->RemoveDevice(video_stream_id_, this);
105 Release(); // Balance the AddRef() in StartCapture().
106 }
107
108 void LocalVideoCapture::OnDeviceInfoReceived(
109 media::VideoCapture* capture,
110 const media::VideoCaptureParams& device_info) {
111 DVLOG(3) << "LocalVideoCapture::OnDeviceInfoReceived";
112 DCHECK(message_loop_proxy_->BelongsToCurrentThread());
113 }
114
115 void LocalVideoCapture::OnBufferReady(
116 media::VideoCapture* capture,
117 scoped_refptr<media::VideoCapture::VideoFrameBuffer> buf) {
118 DVLOG(3) << "LocalVideoCapture::OnBufferReady, state:" << state_;
119 DCHECK(message_loop_proxy_->BelongsToCurrentThread());
120 DCHECK(buf);
121
122 if (state_ != video_capture::kStarted) {
123 capture->FeedBuffer(buf);
124 return;
125 }
126
127 gfx::Size natural_size(buf->width, buf->height);
128 scoped_refptr<media::VideoFrame> current_frame =
129 media::VideoFrame::CreateFrame(media::VideoFrame::YV12,
130 natural_size, natural_size,
131 buf->timestamp - base::Time());
132 uint8* buffer = buf->memory_pointer;
133
134 // Assume YV12 format.
135 DCHECK_EQ(capability_.color, media::VideoCaptureCapability::kI420);
136 if (capability_.color != media::VideoCaptureCapability::kI420)
137 return;
138
139 int y_width = buf->width;
140 int y_height = buf->height;
141 int uv_width = buf->width / 2;
142 int uv_height = buf->height / 2;
143 CopyYPlane(buffer, y_width, y_height, current_frame);
144 buffer += y_width * y_height;
145 CopyUPlane(buffer, uv_width, uv_height, current_frame);
146 buffer += uv_width * uv_height;
147 CopyVPlane(buffer, uv_width, uv_height, current_frame);
148
149 capture->FeedBuffer(buf);
150 repaint_cb_.Run(current_frame);
151 }
152
153 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/local_video_capture.h ('k') | content/renderer/media/media_stream_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698