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

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

Issue 13616004: Switch event type when a capture device has been stopped from the render process. This make sure th… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed code review comments. Created 7 years, 8 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/rtc_video_capture_delegate.h" 5 #include "content/renderer/media/rtc_video_capture_delegate.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 8
9 namespace content { 9 namespace content {
10 10
11 RtcVideoCaptureDelegate::RtcVideoCaptureDelegate( 11 RtcVideoCaptureDelegate::RtcVideoCaptureDelegate(
12 const media::VideoCaptureSessionId id, 12 const media::VideoCaptureSessionId id,
13 VideoCaptureImplManager* vc_manager) 13 VideoCaptureImplManager* vc_manager)
14 : session_id_(id), 14 : session_id_(id),
15 vc_manager_(vc_manager), 15 vc_manager_(vc_manager),
16 capture_engine_(NULL), 16 capture_engine_(NULL),
17 got_first_frame_(false) { 17 got_first_frame_(false),
18 error_occured_(false) {
18 DVLOG(3) << " RtcVideoCaptureDelegate::ctor"; 19 DVLOG(3) << " RtcVideoCaptureDelegate::ctor";
19 capture_engine_ = vc_manager_->AddDevice(session_id_, this); 20 capture_engine_ = vc_manager_->AddDevice(session_id_, this);
20 } 21 }
21 22
22 RtcVideoCaptureDelegate::~RtcVideoCaptureDelegate() { 23 RtcVideoCaptureDelegate::~RtcVideoCaptureDelegate() {
23 DVLOG(3) << " RtcVideoCaptureDelegate::dtor"; 24 DVLOG(3) << " RtcVideoCaptureDelegate::dtor";
24 vc_manager_->RemoveDevice(session_id_, this); 25 vc_manager_->RemoveDevice(session_id_, this);
25 } 26 }
26 27
27 void RtcVideoCaptureDelegate::StartCapture( 28 void RtcVideoCaptureDelegate::StartCapture(
28 const media::VideoCaptureCapability& capability, 29 const media::VideoCaptureCapability& capability,
29 const FrameCapturedCallback& captured_callback, 30 const FrameCapturedCallback& captured_callback,
30 const StateChangeCallback& state_callback) { 31 const StateChangeCallback& state_callback) {
31 DVLOG(3) << " RtcVideoCaptureDelegate::StartCapture "; 32 DVLOG(3) << " RtcVideoCaptureDelegate::StartCapture ";
32 message_loop_proxy_ = base::MessageLoopProxy::current(); 33 message_loop_proxy_ = base::MessageLoopProxy::current();
33 captured_callback_ = captured_callback; 34 captured_callback_ = captured_callback;
34 state_callback_ = state_callback; 35 state_callback_ = state_callback;
36 got_first_frame_ = false;
37 error_occured_ = false;
35 38
36 // Increase the reference count to ensure we are not deleted until 39 // Increase the reference count to ensure we are not deleted until
37 // The we are unregistered in RtcVideoCaptureDelegate::OnRemoved. 40 // The we are unregistered in RtcVideoCaptureDelegate::OnRemoved.
38 AddRef(); 41 AddRef();
39 capture_engine_->StartCapture(this, capability); 42 capture_engine_->StartCapture(this, capability);
40 } 43 }
41 44
42 void RtcVideoCaptureDelegate::StopCapture() { 45 void RtcVideoCaptureDelegate::StopCapture() {
43 // Immediately make sure we don't provide more frames. 46 // Immediately make sure we don't provide more frames.
44 captured_callback_.Reset(); 47 captured_callback_.Reset();
45 state_callback_.Reset(); 48 state_callback_.Reset();
46 capture_engine_->StopCapture(this); 49 capture_engine_->StopCapture(this);
47 } 50 }
48 51
49 void RtcVideoCaptureDelegate::OnStarted(media::VideoCapture* capture) { 52 void RtcVideoCaptureDelegate::OnStarted(media::VideoCapture* capture) {
50 DVLOG(3) << " RtcVideoCaptureDelegate::OnStarted"; 53 DVLOG(3) << " RtcVideoCaptureDelegate::OnStarted";
51 } 54 }
52 55
53 void RtcVideoCaptureDelegate::OnStopped(media::VideoCapture* capture) { 56 void RtcVideoCaptureDelegate::OnStopped(media::VideoCapture* capture) {
54 } 57 }
55 58
56 void RtcVideoCaptureDelegate::OnPaused(media::VideoCapture* capture) { 59 void RtcVideoCaptureDelegate::OnPaused(media::VideoCapture* capture) {
57 NOTIMPLEMENTED(); 60 NOTIMPLEMENTED();
58 } 61 }
59 62
60 void RtcVideoCaptureDelegate::OnError(media::VideoCapture* capture, 63 void RtcVideoCaptureDelegate::OnError(media::VideoCapture* capture,
61 int error_code) { 64 int error_code) {
65 DVLOG(3) << " RtcVideoCaptureDelegate::OnError";
62 message_loop_proxy_->PostTask( 66 message_loop_proxy_->PostTask(
63 FROM_HERE, 67 FROM_HERE,
64 base::Bind(&RtcVideoCaptureDelegate::OnErrorOnCaptureThread, 68 base::Bind(&RtcVideoCaptureDelegate::OnErrorOnCaptureThread,
65 this, capture, error_code)); 69 this, capture));
66 } 70 }
67 71
68 void RtcVideoCaptureDelegate::OnRemoved(media::VideoCapture* capture) { 72 void RtcVideoCaptureDelegate::OnRemoved(media::VideoCapture* capture) {
69 DVLOG(3) << " RtcVideoCaptureDelegate::OnRemoved"; 73 DVLOG(3) << " RtcVideoCaptureDelegate::OnRemoved";
74 message_loop_proxy_->PostTask(
75 FROM_HERE,
76 base::Bind(&RtcVideoCaptureDelegate::OnRemovedOnCaptureThread,
77 this, capture));
78
70 // Balance the AddRef in StartCapture. 79 // Balance the AddRef in StartCapture.
71 // This means we are no longer registered as an event handler and can safely 80 // This means we are no longer registered as an event handler and can safely
72 // be deleted. 81 // be deleted.
73 Release(); 82 Release();
74 } 83 }
75 84
76 void RtcVideoCaptureDelegate::OnBufferReady( 85 void RtcVideoCaptureDelegate::OnBufferReady(
77 media::VideoCapture* capture, 86 media::VideoCapture* capture,
78 scoped_refptr<media::VideoCapture::VideoFrameBuffer> buf) { 87 scoped_refptr<media::VideoCapture::VideoFrameBuffer> buf) {
79 message_loop_proxy_->PostTask( 88 message_loop_proxy_->PostTask(
(...skipping 17 matching lines...) Expand all
97 if (!state_callback_.is_null()) 106 if (!state_callback_.is_null())
98 state_callback_.Run(CAPTURE_RUNNING); 107 state_callback_.Run(CAPTURE_RUNNING);
99 } 108 }
100 109
101 captured_callback_.Run(*buf); 110 captured_callback_.Run(*buf);
102 } 111 }
103 capture->FeedBuffer(buf); 112 capture->FeedBuffer(buf);
104 } 113 }
105 114
106 void RtcVideoCaptureDelegate::OnErrorOnCaptureThread( 115 void RtcVideoCaptureDelegate::OnErrorOnCaptureThread(
107 media::VideoCapture* capture, int error_code) { 116 media::VideoCapture* capture) {
117 error_occured_ = true;
108 if (!state_callback_.is_null()) 118 if (!state_callback_.is_null())
109 state_callback_.Run(got_first_frame_ ? CAPTURE_STOPPED : CAPTURE_FAILED); 119 state_callback_.Run(CAPTURE_FAILED);
120 }
121
122
123 void RtcVideoCaptureDelegate::OnRemovedOnCaptureThread(
124 media::VideoCapture* capture) {
125 if (!error_occured_ && !state_callback_.is_null())
126 state_callback_.Run(CAPTURE_STOPPED);
110 } 127 }
111 128
112 } // namespace content 129 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/rtc_video_capture_delegate.h ('k') | content/renderer/media/rtc_video_capturer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698