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

Side by Side Diff: trunk/src/media/video/capture/android/video_capture_device_android.cc

Issue 84393002: Revert 236927 "Reorganize media::VideoCapture* types" (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: Created 7 years 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/android/video_capture_device_android.h" 5 #include "media/video/capture/android/video_capture_device_android.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h" 10 #include "base/android/jni_string.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 return ret.release(); 79 return ret.release();
80 return NULL; 80 return NULL;
81 } 81 }
82 82
83 // static 83 // static
84 bool VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice(JNIEnv* env) { 84 bool VideoCaptureDeviceAndroid::RegisterVideoCaptureDevice(JNIEnv* env) {
85 return RegisterNativesImpl(env); 85 return RegisterNativesImpl(env);
86 } 86 }
87 87
88 VideoCaptureDeviceAndroid::VideoCaptureDeviceAndroid(const Name& device_name) 88 VideoCaptureDeviceAndroid::VideoCaptureDeviceAndroid(const Name& device_name)
89 : state_(kIdle), got_first_frame_(false), device_name_(device_name) {} 89 : state_(kIdle),
90 got_first_frame_(false),
91 device_name_(device_name),
92 current_settings_() {
93 }
90 94
91 VideoCaptureDeviceAndroid::~VideoCaptureDeviceAndroid() { 95 VideoCaptureDeviceAndroid::~VideoCaptureDeviceAndroid() {
92 StopAndDeAllocate(); 96 StopAndDeAllocate();
93 } 97 }
94 98
95 bool VideoCaptureDeviceAndroid::Init() { 99 bool VideoCaptureDeviceAndroid::Init() {
96 int id; 100 int id;
97 if (!base::StringToInt(device_name_.id(), &id)) 101 if (!base::StringToInt(device_name_.id(), &id))
98 return false; 102 return false;
99 103
100 JNIEnv* env = AttachCurrentThread(); 104 JNIEnv* env = AttachCurrentThread();
101 105
102 j_capture_.Reset(Java_VideoCapture_createVideoCapture( 106 j_capture_.Reset(Java_VideoCapture_createVideoCapture(
103 env, base::android::GetApplicationContext(), id, 107 env, base::android::GetApplicationContext(), id,
104 reinterpret_cast<intptr_t>(this))); 108 reinterpret_cast<intptr_t>(this)));
105 109
106 return true; 110 return true;
107 } 111 }
108 112
109 void VideoCaptureDeviceAndroid::AllocateAndStart( 113 void VideoCaptureDeviceAndroid::AllocateAndStart(
110 const VideoCaptureParams& params, 114 const VideoCaptureCapability& capture_format,
111 scoped_ptr<Client> client) { 115 scoped_ptr<Client> client) {
112 DVLOG(1) << "VideoCaptureDeviceAndroid::AllocateAndStart"; 116 DVLOG(1) << "VideoCaptureDeviceAndroid::AllocateAndStart";
113 { 117 {
114 base::AutoLock lock(lock_); 118 base::AutoLock lock(lock_);
115 if (state_ != kIdle) 119 if (state_ != kIdle)
116 return; 120 return;
117 client_ = client.Pass(); 121 client_ = client.Pass();
118 got_first_frame_ = false; 122 got_first_frame_ = false;
119 } 123 }
120 124
121 JNIEnv* env = AttachCurrentThread(); 125 JNIEnv* env = AttachCurrentThread();
122 126
123 jboolean ret = 127 jboolean ret = Java_VideoCapture_allocate(env,
124 Java_VideoCapture_allocate(env, 128 j_capture_.obj(),
125 j_capture_.obj(), 129 capture_format.width,
126 params.requested_format.frame_size.width(), 130 capture_format.height,
127 params.requested_format.frame_size.height(), 131 capture_format.frame_rate);
128 params.requested_format.frame_rate);
129 if (!ret) { 132 if (!ret) {
130 SetErrorState("failed to allocate"); 133 SetErrorState("failed to allocate");
131 return; 134 return;
132 } 135 }
133 136
134 // Store current width and height. 137 // Store current width and height.
135 capture_format_.frame_size.SetSize( 138 current_settings_.width =
136 Java_VideoCapture_queryWidth(env, j_capture_.obj()), 139 Java_VideoCapture_queryWidth(env, j_capture_.obj());
137 Java_VideoCapture_queryHeight(env, j_capture_.obj())); 140 current_settings_.height =
138 capture_format_.frame_rate = 141 Java_VideoCapture_queryHeight(env, j_capture_.obj());
142 current_settings_.frame_rate =
139 Java_VideoCapture_queryFrameRate(env, j_capture_.obj()); 143 Java_VideoCapture_queryFrameRate(env, j_capture_.obj());
140 capture_format_.pixel_format = GetColorspace(); 144 current_settings_.color = GetColorspace();
141 DCHECK_NE(capture_format_.pixel_format, media::PIXEL_FORMAT_UNKNOWN); 145 DCHECK_NE(current_settings_.color, media::PIXEL_FORMAT_UNKNOWN);
142 CHECK(capture_format_.frame_size.GetArea() > 0); 146 CHECK(current_settings_.width > 0 && !(current_settings_.width % 2));
143 CHECK(!(capture_format_.frame_size.width() % 2)); 147 CHECK(current_settings_.height > 0 && !(current_settings_.height % 2));
144 CHECK(!(capture_format_.frame_size.height() % 2));
145 148
146 if (capture_format_.frame_rate > 0) { 149 if (capture_format.frame_rate > 0) {
147 frame_interval_ = base::TimeDelta::FromMicroseconds( 150 frame_interval_ = base::TimeDelta::FromMicroseconds(
148 (base::Time::kMicrosecondsPerSecond + capture_format_.frame_rate - 1) / 151 (base::Time::kMicrosecondsPerSecond + capture_format.frame_rate - 1) /
149 capture_format_.frame_rate); 152 capture_format.frame_rate);
150 } 153 }
151 154
152 DVLOG(1) << "VideoCaptureDeviceAndroid::Allocate: queried frame_size=" 155 DVLOG(1) << "VideoCaptureDeviceAndroid::Allocate: queried width="
153 << capture_format_.frame_size.ToString() 156 << current_settings_.width
154 << ", frame_rate=" << capture_format_.frame_rate; 157 << ", height="
158 << current_settings_.height
159 << ", frame_rate="
160 << current_settings_.frame_rate;
155 161
156 jint result = Java_VideoCapture_startCapture(env, j_capture_.obj()); 162 jint result = Java_VideoCapture_startCapture(env, j_capture_.obj());
157 if (result < 0) { 163 if (result < 0) {
158 SetErrorState("failed to start capture"); 164 SetErrorState("failed to start capture");
159 return; 165 return;
160 } 166 }
161 167
162 { 168 {
163 base::AutoLock lock(lock_); 169 base::AutoLock lock(lock_);
164 state_ = kCapturing; 170 state_ = kCapturing;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 // Deliver the frame when it doesn't arrive too early. 227 // Deliver the frame when it doesn't arrive too early.
222 if (expected_next_frame_time_ <= current_time) { 228 if (expected_next_frame_time_ <= current_time) {
223 expected_next_frame_time_ += frame_interval_; 229 expected_next_frame_time_ += frame_interval_;
224 230
225 client_->OnIncomingCapturedFrame(reinterpret_cast<uint8*>(buffer), 231 client_->OnIncomingCapturedFrame(reinterpret_cast<uint8*>(buffer),
226 length, 232 length,
227 base::Time::Now(), 233 base::Time::Now(),
228 rotation, 234 rotation,
229 flip_vert, 235 flip_vert,
230 flip_horiz, 236 flip_horiz,
231 capture_format_); 237 current_settings_);
232 } 238 }
233 239
234 env->ReleaseByteArrayElements(data, buffer, JNI_ABORT); 240 env->ReleaseByteArrayElements(data, buffer, JNI_ABORT);
235 } 241 }
236 242
237 VideoPixelFormat VideoCaptureDeviceAndroid::GetColorspace() { 243 VideoPixelFormat VideoCaptureDeviceAndroid::GetColorspace() {
238 JNIEnv* env = AttachCurrentThread(); 244 JNIEnv* env = AttachCurrentThread();
239 int current_capture_colorspace = 245 int current_capture_colorspace =
240 Java_VideoCapture_getColorspace(env, j_capture_.obj()); 246 Java_VideoCapture_getColorspace(env, j_capture_.obj());
241 switch (current_capture_colorspace){ 247 switch (current_capture_colorspace){
(...skipping 16 matching lines...) Expand all
258 void VideoCaptureDeviceAndroid::SetErrorState(const std::string& reason) { 264 void VideoCaptureDeviceAndroid::SetErrorState(const std::string& reason) {
259 LOG(ERROR) << "VideoCaptureDeviceAndroid::SetErrorState: " << reason; 265 LOG(ERROR) << "VideoCaptureDeviceAndroid::SetErrorState: " << reason;
260 { 266 {
261 base::AutoLock lock(lock_); 267 base::AutoLock lock(lock_);
262 state_ = kError; 268 state_ = kError;
263 } 269 }
264 client_->OnError(); 270 client_->OnError();
265 } 271 }
266 272
267 } // namespace media 273 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698