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

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

Issue 2590823004: Avoid float-cast-overflow in content::VideoCapturerSource::GetCurrentSupportedFormats (Closed)
Patch Set: Created 3 years, 12 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/canvas_capture_handler.h" 5 #include "content/renderer/media/canvas_capture_handler.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/base64.h" 9 #include "base/base64.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/rand_util.h" 12 #include "base/rand_util.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "content/public/renderer/render_thread.h" 14 #include "content/public/renderer/render_thread.h"
15 #include "content/renderer/media/media_stream_video_capturer_source.h" 15 #include "content/renderer/media/media_stream_video_capturer_source.h"
16 #include "content/renderer/media/media_stream_video_source.h" 16 #include "content/renderer/media/media_stream_video_source.h"
17 #include "content/renderer/media/media_stream_video_track.h" 17 #include "content/renderer/media/media_stream_video_track.h"
18 #include "content/renderer/media/webrtc_uma_histograms.h" 18 #include "content/renderer/media/webrtc_uma_histograms.h"
19 #include "content/renderer/render_thread_impl.h" 19 #include "content/renderer/render_thread_impl.h"
20 #include "media/base/limits.h"
20 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" 21 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
21 #include "third_party/WebKit/public/platform/WebString.h" 22 #include "third_party/WebKit/public/platform/WebString.h"
22 #include "third_party/libyuv/include/libyuv.h" 23 #include "third_party/libyuv/include/libyuv.h"
23 #include "third_party/skia/include/core/SkImage.h" 24 #include "third_party/skia/include/core/SkImage.h"
24 25
25 namespace { 26 namespace {
26 27
27 using media::VideoFrame; 28 using media::VideoFrame;
28 29
29 const size_t kArgbBytesPerPixel = 4; 30 const size_t kArgbBytesPerPixel = 4;
30 31
31 } // namespace 32 } // namespace
32 33
33 namespace content { 34 namespace content {
34 35
35 // Implementation VideoCapturerSource that is owned by 36 // Implementation VideoCapturerSource that is owned by
36 // MediaStreamVideoCapturerSource and delegates the Start/Stop calls to 37 // MediaStreamVideoCapturerSource and delegates the Start/Stop calls to
37 // CanvasCaptureHandler. 38 // CanvasCaptureHandler.
38 // This class is single threaded and pinned to main render thread. 39 // This class is single threaded and pinned to main render thread.
39 class VideoCapturerSource : public media::VideoCapturerSource { 40 class VideoCapturerSource : public media::VideoCapturerSource {
40 public: 41 public:
41 explicit VideoCapturerSource(base::WeakPtr<CanvasCaptureHandler> 42 VideoCapturerSource(base::WeakPtr<CanvasCaptureHandler> canvas_handler,
42 canvas_handler, 43 double frame_rate)
43 double frame_rate) 44 : frame_rate_(static_cast<float>(
mcasas 2016/12/20 22:57:14 Why not keep |frame_rate_| as double and avoid thi
emircan 2016/12/20 23:07:38 media::VideoCaptureFormat() in l.59-61 expect the
44 : frame_rate_(frame_rate), 45 std::min(static_cast<double>(media::limits::kMaxFramesPerSecond),
46 frame_rate))),
45 canvas_handler_(canvas_handler) {} 47 canvas_handler_(canvas_handler) {}
46 48
47 protected: 49 protected:
48 void GetCurrentSupportedFormats( 50 void GetCurrentSupportedFormats(
49 int max_requested_width, 51 int max_requested_width,
50 int max_requested_height, 52 int max_requested_height,
51 double max_requested_frame_rate, 53 double max_requested_frame_rate,
52 const VideoCaptureDeviceFormatsCB& callback) override { 54 const VideoCaptureDeviceFormatsCB& callback) override {
53 DCHECK(main_render_thread_checker_.CalledOnValidThread()); 55 DCHECK(main_render_thread_checker_.CalledOnValidThread());
54 const blink::WebSize& size = canvas_handler_->GetSourceSize(); 56 const blink::WebSize& size = canvas_handler_->GetSourceSize();
(...skipping 17 matching lines...) Expand all
72 DCHECK(main_render_thread_checker_.CalledOnValidThread()); 74 DCHECK(main_render_thread_checker_.CalledOnValidThread());
73 canvas_handler_->RequestRefreshFrame(); 75 canvas_handler_->RequestRefreshFrame();
74 } 76 }
75 void StopCapture() override { 77 void StopCapture() override {
76 DCHECK(main_render_thread_checker_.CalledOnValidThread()); 78 DCHECK(main_render_thread_checker_.CalledOnValidThread());
77 if (canvas_handler_.get()) 79 if (canvas_handler_.get())
78 canvas_handler_->StopVideoCapture(); 80 canvas_handler_->StopVideoCapture();
79 } 81 }
80 82
81 private: 83 private:
82 const double frame_rate_; 84 const float frame_rate_;
83 // Bound to Main Render thread. 85 // Bound to Main Render thread.
84 base::ThreadChecker main_render_thread_checker_; 86 base::ThreadChecker main_render_thread_checker_;
85 // CanvasCaptureHandler is owned by CanvasDrawListener in blink and might be 87 // CanvasCaptureHandler is owned by CanvasDrawListener in blink and might be
86 // destroyed before StopCapture() call. 88 // destroyed before StopCapture() call.
87 base::WeakPtr<CanvasCaptureHandler> canvas_handler_; 89 base::WeakPtr<CanvasCaptureHandler> canvas_handler_;
88 }; 90 };
89 91
90 class CanvasCaptureHandler::CanvasCaptureHandlerDelegate { 92 class CanvasCaptureHandler::CanvasCaptureHandlerDelegate {
91 public: 93 public:
92 explicit CanvasCaptureHandlerDelegate( 94 explicit CanvasCaptureHandlerDelegate(
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 270
269 web_track->initialize(webkit_source); 271 web_track->initialize(webkit_source);
270 blink::WebMediaConstraints constraints; 272 blink::WebMediaConstraints constraints;
271 constraints.initialize(); 273 constraints.initialize();
272 web_track->setTrackData(new MediaStreamVideoTrack( 274 web_track->setTrackData(new MediaStreamVideoTrack(
273 media_stream_source.release(), constraints, 275 media_stream_source.release(), constraints,
274 MediaStreamVideoSource::ConstraintsCallback(), true)); 276 MediaStreamVideoSource::ConstraintsCallback(), true));
275 } 277 }
276 278
277 } // namespace content 279 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698