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

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

Issue 23587018: Replace media::VideoCapture::VideoFrameBuffer with media::VideoFrame. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@git-svn
Patch Set: a1e0098f Reset timestamps on Stop(). Created 7 years, 3 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
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_capturer.h" 5 #include "content/renderer/media/rtc_video_capturer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/trace_event.h" 8 #include "base/debug/trace_event.h"
9 9
10 namespace content { 10 namespace content {
11 11
12 RtcVideoCapturer::RtcVideoCapturer( 12 RtcVideoCapturer::RtcVideoCapturer(
13 const media::VideoCaptureSessionId id, 13 const media::VideoCaptureSessionId id,
14 VideoCaptureImplManager* vc_manager, 14 VideoCaptureImplManager* vc_manager,
15 bool is_screencast) 15 bool is_screencast)
16 : is_screencast_(is_screencast), 16 : is_screencast_(is_screencast),
17 delegate_(new RtcVideoCaptureDelegate(id, vc_manager)), 17 delegate_(new RtcVideoCaptureDelegate(id, vc_manager)),
18 state_(VIDEO_CAPTURE_STATE_STOPPED) { 18 state_(VIDEO_CAPTURE_STATE_STOPPED),
19 first_frame_timestamp_valid_(false) {
19 } 20 }
20 21
21 RtcVideoCapturer::~RtcVideoCapturer() { 22 RtcVideoCapturer::~RtcVideoCapturer() {
22 DCHECK(VIDEO_CAPTURE_STATE_STOPPED); 23 DCHECK(VIDEO_CAPTURE_STATE_STOPPED);
23 DVLOG(3) << " RtcVideoCapturer::dtor"; 24 DVLOG(3) << " RtcVideoCapturer::dtor";
24 } 25 }
25 26
26 cricket::CaptureState RtcVideoCapturer::Start( 27 cricket::CaptureState RtcVideoCapturer::Start(
27 const cricket::VideoFormat& capture_format) { 28 const cricket::VideoFormat& capture_format) {
28 DVLOG(3) << " RtcVideoCapturer::Start "; 29 DVLOG(3) << " RtcVideoCapturer::Start ";
29 if (state_ == VIDEO_CAPTURE_STATE_STARTED) { 30 if (state_ == VIDEO_CAPTURE_STATE_STARTED) {
30 DVLOG(1) << "Got a StartCapture when already started!!! "; 31 DVLOG(1) << "Got a StartCapture when already started!!! ";
31 return cricket::CS_FAILED; 32 return cricket::CS_FAILED;
32 } 33 }
33 34
34 media::VideoCaptureCapability cap; 35 media::VideoCaptureCapability cap;
35 cap.width = capture_format.width; 36 cap.width = capture_format.width;
36 cap.height = capture_format.height; 37 cap.height = capture_format.height;
37 cap.frame_rate = capture_format.framerate(); 38 cap.frame_rate = capture_format.framerate();
38 cap.color = media::PIXEL_FORMAT_I420; 39 cap.color = media::PIXEL_FORMAT_I420;
39 40
40 SetCaptureFormat(&capture_format); 41 SetCaptureFormat(&capture_format);
41 42
42 state_ = VIDEO_CAPTURE_STATE_STARTED; 43 state_ = VIDEO_CAPTURE_STATE_STARTED;
43 start_time_ = base::Time::Now(); 44 delegate_->StartCapture(
44 delegate_->StartCapture(cap, 45 cap,
45 base::Bind(&RtcVideoCapturer::OnFrameCaptured, base::Unretained(this)), 46 base::Bind(&RtcVideoCapturer::OnFrameCaptured, base::Unretained(this)),
46 base::Bind(&RtcVideoCapturer::OnStateChange, base::Unretained(this))); 47 base::Bind(&RtcVideoCapturer::OnStateChange, base::Unretained(this)));
47 // Update the desired aspect ratio so that later the video frame can be 48 // Update the desired aspect ratio so that later the video frame can be
48 // cropped to meet the requirement if the camera returns a different 49 // cropped to meet the requirement if the camera returns a different
49 // resolution than the |cap|. 50 // resolution than the |cap|.
50 UpdateAspectRatio(cap.width, cap.height); 51 UpdateAspectRatio(cap.width, cap.height);
51 return cricket::CS_STARTING; 52 return cricket::CS_STARTING;
52 } 53 }
53 54
54 void RtcVideoCapturer::Stop() { 55 void RtcVideoCapturer::Stop() {
55 DVLOG(3) << " RtcVideoCapturer::Stop "; 56 DVLOG(3) << " RtcVideoCapturer::Stop ";
56 if (state_ == VIDEO_CAPTURE_STATE_STOPPED) { 57 if (state_ == VIDEO_CAPTURE_STATE_STOPPED) {
57 DVLOG(1) << "Got a StopCapture while not started."; 58 DVLOG(1) << "Got a StopCapture while not started.";
58 return; 59 return;
59 } 60 }
60 61
61 SetCaptureFormat(NULL); 62 SetCaptureFormat(NULL);
62 state_ = VIDEO_CAPTURE_STATE_STOPPED; 63 state_ = VIDEO_CAPTURE_STATE_STOPPED;
64 first_frame_timestamp_valid_ = false;
63 delegate_->StopCapture(); 65 delegate_->StopCapture();
64 SignalStateChange(this, cricket::CS_STOPPED); 66 SignalStateChange(this, cricket::CS_STOPPED);
65 } 67 }
66 68
67 bool RtcVideoCapturer::IsRunning() { 69 bool RtcVideoCapturer::IsRunning() {
68 return state_ == VIDEO_CAPTURE_STATE_STARTED; 70 return state_ == VIDEO_CAPTURE_STATE_STARTED;
69 } 71 }
70 72
71 bool RtcVideoCapturer::GetPreferredFourccs(std::vector<uint32>* fourccs) { 73 bool RtcVideoCapturer::GetPreferredFourccs(std::vector<uint32>* fourccs) {
72 if (!fourccs) 74 if (!fourccs)
(...skipping 15 matching lines...) Expand all
88 // Chrome does not support capability enumeration. 90 // Chrome does not support capability enumeration.
89 // Use the desired format as the best format. 91 // Use the desired format as the best format.
90 best_format->width = desired.width; 92 best_format->width = desired.width;
91 best_format->height = desired.height; 93 best_format->height = desired.height;
92 best_format->fourcc = cricket::FOURCC_I420; 94 best_format->fourcc = cricket::FOURCC_I420;
93 best_format->interval = desired.interval; 95 best_format->interval = desired.interval;
94 return true; 96 return true;
95 } 97 }
96 98
97 void RtcVideoCapturer::OnFrameCaptured( 99 void RtcVideoCapturer::OnFrameCaptured(
98 const media::VideoCapture::VideoFrameBuffer& buf) { 100 const scoped_refptr<media::VideoFrame>& frame) {
101 if (!first_frame_timestamp_valid_) {
102 first_frame_timestamp_ = frame->GetTimestamp();
103 first_frame_timestamp_valid_ = true;
104 }
105
99 // Currently, |fourcc| is always I420. 106 // Currently, |fourcc| is always I420.
100 cricket::CapturedFrame frame; 107 cricket::CapturedFrame cricket_frame;
Ami GONE FROM CHROMIUM 2013/09/12 22:40:41 your attempts at disambiguation are no match for t
101 frame.width = buf.width; 108 cricket_frame.width = frame->coded_size().width();
102 frame.height = buf.height; 109 cricket_frame.height = frame->coded_size().height();
103 frame.fourcc = cricket::FOURCC_I420; 110 cricket_frame.fourcc = cricket::FOURCC_I420;
104 frame.data_size = buf.buffer_size;
105 // cricket::CapturedFrame time is in nanoseconds. 111 // cricket::CapturedFrame time is in nanoseconds.
106 frame.elapsed_time = (buf.timestamp - start_time_).InMicroseconds() * 112 cricket_frame.elapsed_time =
113 (frame->GetTimestamp() - first_frame_timestamp_).InMicroseconds() *
107 base::Time::kNanosecondsPerMicrosecond; 114 base::Time::kNanosecondsPerMicrosecond;
108 frame.time_stamp = 115 cricket_frame.time_stamp = frame->GetTimestamp().InMicroseconds() *
109 (buf.timestamp - base::Time::UnixEpoch()).InMicroseconds() * 116 base::Time::kNanosecondsPerMicrosecond;
110 base::Time::kNanosecondsPerMicrosecond; 117 // TODO(sheu): we assume contiguous layout of image planes.
Ami GONE FROM CHROMIUM 2013/09/12 22:40:41 then the pepper code can be simplified even more,
sheu 2013/09/13 00:15:19 yes, but I'd like not to make that assumption expl
111 frame.data = buf.memory_pointer; 118 cricket_frame.data = frame->data(0);
112 frame.pixel_height = 1; 119 cricket_frame.data_size =
113 frame.pixel_width = 1; 120 media::VideoFrame::AllocationSize(frame->format(), frame->coded_size());
121 cricket_frame.pixel_height = 1;
122 cricket_frame.pixel_width = 1;
114 123
115 TRACE_EVENT_INSTANT2("rtc_video_capturer", 124 TRACE_EVENT_INSTANT2(
116 "OnFrameCaptured", 125 "rtc_video_capturer",
117 TRACE_EVENT_SCOPE_THREAD, 126 "OnFrameCaptured",
118 "elapsed time", 127 TRACE_EVENT_SCOPE_THREAD,
119 frame.elapsed_time, 128 "elapsed time",
120 "timestamp_ms", 129 cricket_frame.elapsed_time,
121 frame.time_stamp / talk_base::kNumNanosecsPerMillisec); 130 "timestamp_ms",
131 cricket_frame.time_stamp / talk_base::kNumNanosecsPerMillisec);
122 132
123 // This signals to libJingle that a new VideoFrame is available. 133 // This signals to libJingle that a new VideoFrame is available.
124 // libJingle have no assumptions on what thread this signal come from. 134 // libJingle have no assumptions on what thread this signal come from.
125 SignalFrameCaptured(this, &frame); 135 SignalFrameCaptured(this, &cricket_frame);
126 } 136 }
127 137
128 void RtcVideoCapturer::OnStateChange( 138 void RtcVideoCapturer::OnStateChange(
129 RtcVideoCaptureDelegate::CaptureState state) { 139 RtcVideoCaptureDelegate::CaptureState state) {
130 cricket::CaptureState converted_state = cricket::CS_FAILED; 140 cricket::CaptureState converted_state = cricket::CS_FAILED;
131 DVLOG(3) << " RtcVideoCapturer::OnStateChange " << state; 141 DVLOG(3) << " RtcVideoCapturer::OnStateChange " << state;
132 switch (state) { 142 switch (state) {
133 case RtcVideoCaptureDelegate::CAPTURE_STOPPED: 143 case RtcVideoCaptureDelegate::CAPTURE_STOPPED:
134 converted_state = cricket::CS_STOPPED; 144 converted_state = cricket::CS_STOPPED;
135 break; 145 break;
136 case RtcVideoCaptureDelegate::CAPTURE_RUNNING: 146 case RtcVideoCaptureDelegate::CAPTURE_RUNNING:
137 converted_state = cricket::CS_RUNNING; 147 converted_state = cricket::CS_RUNNING;
138 break; 148 break;
139 case RtcVideoCaptureDelegate::CAPTURE_FAILED: 149 case RtcVideoCaptureDelegate::CAPTURE_FAILED:
140 // TODO(perkj): Update the comments in the the definition of 150 // TODO(perkj): Update the comments in the the definition of
141 // cricket::CS_FAILED. According to the comments, cricket::CS_FAILED 151 // cricket::CS_FAILED. According to the comments, cricket::CS_FAILED
142 // means that the capturer failed to start. But here and in libjingle it 152 // means that the capturer failed to start. But here and in libjingle it
143 // is also used if an error occur during capturing. 153 // is also used if an error occur during capturing.
144 converted_state = cricket::CS_FAILED; 154 converted_state = cricket::CS_FAILED;
145 break; 155 break;
146 default: 156 default:
147 NOTREACHED(); 157 NOTREACHED();
148 break; 158 break;
149 } 159 }
150 SignalStateChange(this, converted_state); 160 SignalStateChange(this, converted_state);
151 } 161 }
152 162
153 } // namespace content 163 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698