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

Side by Side Diff: media/video/capture/fake_video_capture_device.cc

Issue 9837095: [Coverity] Fixed frame size (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 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
« no previous file with comments | « media/video/capture/fake_video_capture_device.h ('k') | 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 (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 "media/video/capture/fake_video_capture_device.h" 5 #include "media/video/capture/fake_video_capture_device.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
(...skipping 23 matching lines...) Expand all
34 return new FakeVideoCaptureDevice(device_name); 34 return new FakeVideoCaptureDevice(device_name);
35 } 35 }
36 } 36 }
37 return NULL; 37 return NULL;
38 } 38 }
39 39
40 FakeVideoCaptureDevice::FakeVideoCaptureDevice(const Name& device_name) 40 FakeVideoCaptureDevice::FakeVideoCaptureDevice(const Name& device_name)
41 : device_name_(device_name), 41 : device_name_(device_name),
42 observer_(NULL), 42 observer_(NULL),
43 state_(kIdle), 43 state_(kIdle),
44 capture_thread_("CaptureThread") { 44 capture_thread_("CaptureThread"),
45 frame_size_(0) {
45 } 46 }
46 47
47 FakeVideoCaptureDevice::~FakeVideoCaptureDevice() { 48 FakeVideoCaptureDevice::~FakeVideoCaptureDevice() {
48 // Check if the thread is running. 49 // Check if the thread is running.
49 // This means that the device have not been DeAllocated properly. 50 // This means that the device have not been DeAllocated properly.
50 DCHECK(!capture_thread_.IsRunning()); 51 DCHECK(!capture_thread_.IsRunning());
51 } 52 }
52 53
53 void FakeVideoCaptureDevice::Allocate(int width, 54 void FakeVideoCaptureDevice::Allocate(int width,
54 int height, 55 int height,
(...skipping 13 matching lines...) Expand all
68 } else { // QVGA 69 } else { // QVGA
69 current_settings.width = 320; 70 current_settings.width = 320;
70 current_settings.height = 240; 71 current_settings.height = 240;
71 current_settings.frame_rate = 30; 72 current_settings.frame_rate = 30;
72 } 73 }
73 74
74 size_t fake_frame_size = 75 size_t fake_frame_size =
75 current_settings.width * current_settings.height * 3 / 2; 76 current_settings.width * current_settings.height * 3 / 2;
76 fake_frame_.reset(new uint8[fake_frame_size]); 77 fake_frame_.reset(new uint8[fake_frame_size]);
77 memset(fake_frame_.get(), 0, fake_frame_size); 78 memset(fake_frame_.get(), 0, fake_frame_size);
79 frame_size_ = fake_frame_size;
78 80
79 state_ = kAllocated; 81 state_ = kAllocated;
80 observer_->OnFrameInfo(current_settings); 82 observer_->OnFrameInfo(current_settings);
81 } 83 }
82 84
83 void FakeVideoCaptureDevice::Start() { 85 void FakeVideoCaptureDevice::Start() {
84 if (state_ != kAllocated) { 86 if (state_ != kAllocated) {
85 return; // Wrong state. 87 return; // Wrong state.
86 } 88 }
87 state_ = kCapturing; 89 state_ = kCapturing;
(...skipping 23 matching lines...) Expand all
111 const VideoCaptureDevice::Name& FakeVideoCaptureDevice::device_name() { 113 const VideoCaptureDevice::Name& FakeVideoCaptureDevice::device_name() {
112 return device_name_; 114 return device_name_;
113 } 115 }
114 116
115 void FakeVideoCaptureDevice::OnCaptureTask() { 117 void FakeVideoCaptureDevice::OnCaptureTask() {
116 if (state_ != kCapturing) { 118 if (state_ != kCapturing) {
117 return; 119 return;
118 } 120 }
119 // Give the captured frame to the observer. 121 // Give the captured frame to the observer.
120 observer_->OnIncomingCapturedFrame(fake_frame_.get(), 122 observer_->OnIncomingCapturedFrame(fake_frame_.get(),
121 sizeof(fake_frame_.get()), 123 frame_size_,
122 base::Time::Now()); 124 base::Time::Now());
123 // Reschedule next CaptureTask. 125 // Reschedule next CaptureTask.
124 capture_thread_.message_loop()->PostDelayedTask( 126 capture_thread_.message_loop()->PostDelayedTask(
125 FROM_HERE, 127 FROM_HERE,
126 base::Bind(&FakeVideoCaptureDevice::OnCaptureTask, 128 base::Bind(&FakeVideoCaptureDevice::OnCaptureTask,
127 base::Unretained(this)), 129 base::Unretained(this)),
128 base::TimeDelta::FromMilliseconds(kFakeCaptureTimeoutMs)); 130 base::TimeDelta::FromMilliseconds(kFakeCaptureTimeoutMs));
129 } 131 }
130 132
131 } // namespace media 133 } // namespace media
OLDNEW
« no previous file with comments | « media/video/capture/fake_video_capture_device.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698