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

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: 4fe79a572 Initial. 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 {
(...skipping 22 matching lines...) Expand all
33 33
34 media::VideoCaptureCapability cap; 34 media::VideoCaptureCapability cap;
35 cap.width = capture_format.width; 35 cap.width = capture_format.width;
36 cap.height = capture_format.height; 36 cap.height = capture_format.height;
37 cap.frame_rate = capture_format.framerate(); 37 cap.frame_rate = capture_format.framerate();
38 cap.color = media::PIXEL_FORMAT_I420; 38 cap.color = media::PIXEL_FORMAT_I420;
39 39
40 SetCaptureFormat(&capture_format); 40 SetCaptureFormat(&capture_format);
41 41
42 state_ = VIDEO_CAPTURE_STATE_STARTED; 42 state_ = VIDEO_CAPTURE_STATE_STARTED;
43 start_time_ = base::Time::Now(); 43 start_time_delta_ = base::Time::Now() - base::Time::UnixEpoch();
miu 2013/09/12 03:01:58 For consideration: Instead of doing this here, you
44 delegate_->StartCapture(cap, 44 delegate_->StartCapture(
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() {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 // Chrome does not support capability enumeration. 89 // Chrome does not support capability enumeration.
89 // Use the desired format as the best format. 90 // Use the desired format as the best format.
90 best_format->width = desired.width; 91 best_format->width = desired.width;
91 best_format->height = desired.height; 92 best_format->height = desired.height;
92 best_format->fourcc = cricket::FOURCC_I420; 93 best_format->fourcc = cricket::FOURCC_I420;
93 best_format->interval = desired.interval; 94 best_format->interval = desired.interval;
94 return true; 95 return true;
95 } 96 }
96 97
97 void RtcVideoCapturer::OnFrameCaptured( 98 void RtcVideoCapturer::OnFrameCaptured(
98 const media::VideoCapture::VideoFrameBuffer& buf) { 99 const scoped_refptr<media::VideoFrame>& frame) {
99 // Currently, |fourcc| is always I420. 100 // Currently, |fourcc| is always I420.
100 cricket::CapturedFrame frame; 101 cricket::CapturedFrame cricket_frame;
101 frame.width = buf.width; 102 cricket_frame.width = frame->coded_size().width();
102 frame.height = buf.height; 103 cricket_frame.height = frame->coded_size().height();
103 frame.fourcc = cricket::FOURCC_I420; 104 cricket_frame.fourcc = cricket::FOURCC_I420;
104 frame.data_size = buf.buffer_size;
105 // cricket::CapturedFrame time is in nanoseconds. 105 // cricket::CapturedFrame time is in nanoseconds.
106 frame.elapsed_time = (buf.timestamp - start_time_).InMicroseconds() * 106 cricket_frame.elapsed_time =
107 (frame->GetTimestamp() - start_time_delta_).InMicroseconds() *
107 base::Time::kNanosecondsPerMicrosecond; 108 base::Time::kNanosecondsPerMicrosecond;
108 frame.time_stamp = 109 cricket_frame.time_stamp = frame->GetTimestamp().InMicroseconds() *
109 (buf.timestamp - base::Time::UnixEpoch()).InMicroseconds() * 110 base::Time::kNanosecondsPerMicrosecond;
110 base::Time::kNanosecondsPerMicrosecond; 111 // TODO(sheu): we assume contiguous layout of image planes.
111 frame.data = buf.memory_pointer; 112 cricket_frame.data = frame->data(0);
112 frame.pixel_height = 1; 113 cricket_frame.data_size =
113 frame.pixel_width = 1; 114 media::VideoFrame::AllocationSize(frame->format(), frame->coded_size());
115 cricket_frame.pixel_height = 1;
116 cricket_frame.pixel_width = 1;
114 117
115 TRACE_EVENT_INSTANT2("rtc_video_capturer", 118 TRACE_EVENT_INSTANT2(
116 "OnFrameCaptured", 119 "rtc_video_capturer",
117 TRACE_EVENT_SCOPE_THREAD, 120 "OnFrameCaptured",
118 "elapsed time", 121 TRACE_EVENT_SCOPE_THREAD,
119 frame.elapsed_time, 122 "elapsed time",
120 "timestamp_ms", 123 cricket_frame.elapsed_time,
121 frame.time_stamp / talk_base::kNumNanosecsPerMillisec); 124 "timestamp_ms",
125 cricket_frame.time_stamp / talk_base::kNumNanosecsPerMillisec);
122 126
123 // This signals to libJingle that a new VideoFrame is available. 127 // This signals to libJingle that a new VideoFrame is available.
124 // libJingle have no assumptions on what thread this signal come from. 128 // libJingle have no assumptions on what thread this signal come from.
125 SignalFrameCaptured(this, &frame); 129 SignalFrameCaptured(this, &cricket_frame);
126 } 130 }
127 131
128 void RtcVideoCapturer::OnStateChange( 132 void RtcVideoCapturer::OnStateChange(
129 RtcVideoCaptureDelegate::CaptureState state) { 133 RtcVideoCaptureDelegate::CaptureState state) {
130 cricket::CaptureState converted_state = cricket::CS_FAILED; 134 cricket::CaptureState converted_state = cricket::CS_FAILED;
131 DVLOG(3) << " RtcVideoCapturer::OnStateChange " << state; 135 DVLOG(3) << " RtcVideoCapturer::OnStateChange " << state;
132 switch (state) { 136 switch (state) {
133 case RtcVideoCaptureDelegate::CAPTURE_STOPPED: 137 case RtcVideoCaptureDelegate::CAPTURE_STOPPED:
134 converted_state = cricket::CS_STOPPED; 138 converted_state = cricket::CS_STOPPED;
135 break; 139 break;
136 case RtcVideoCaptureDelegate::CAPTURE_RUNNING: 140 case RtcVideoCaptureDelegate::CAPTURE_RUNNING:
137 converted_state = cricket::CS_RUNNING; 141 converted_state = cricket::CS_RUNNING;
138 break; 142 break;
139 case RtcVideoCaptureDelegate::CAPTURE_FAILED: 143 case RtcVideoCaptureDelegate::CAPTURE_FAILED:
140 // TODO(perkj): Update the comments in the the definition of 144 // TODO(perkj): Update the comments in the the definition of
141 // cricket::CS_FAILED. According to the comments, cricket::CS_FAILED 145 // cricket::CS_FAILED. According to the comments, cricket::CS_FAILED
142 // means that the capturer failed to start. But here and in libjingle it 146 // means that the capturer failed to start. But here and in libjingle it
143 // is also used if an error occur during capturing. 147 // is also used if an error occur during capturing.
144 converted_state = cricket::CS_FAILED; 148 converted_state = cricket::CS_FAILED;
145 break; 149 break;
146 default: 150 default:
147 NOTREACHED(); 151 NOTREACHED();
148 break; 152 break;
149 } 153 }
150 SignalStateChange(this, converted_state); 154 SignalStateChange(this, converted_state);
151 } 155 }
152 156
153 } // namespace content 157 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698