VideoCapturerAndroid: Add possibility to request a new resolution from the video adapter.

BUG=
R=glaznev@webrtc.org

Review URL: https://codereview.webrtc.org/1178643006.

Cr-Commit-Position: refs/heads/master@{#9434}
This commit is contained in:
Åsa Persson
2015-06-15 09:53:05 +02:00
parent 70c7fe14ac
commit 2b679250fb
6 changed files with 82 additions and 0 deletions

View File

@ -92,6 +92,9 @@ public class VideoCapturerAndroidTest extends ActivityTestCase {
} }
} }
@Override
public void OnOutputFormatRequest(int width, int height, int fps) {}
public boolean WaitForCapturerToStart() throws InterruptedException { public boolean WaitForCapturerToStart() throws InterruptedException {
synchronized (capturerStartLock) { synchronized (capturerStartLock) {
capturerStartLock.wait(); capturerStartLock.wait();

View File

@ -242,4 +242,13 @@ void AndroidVideoCapturer::OnIncomingFrame(void* frame_data,
SignalFrameCaptured(this, frame_factory_->GetCapturedFrame()); SignalFrameCaptured(this, frame_factory_->GetCapturedFrame());
} }
void AndroidVideoCapturer::OnOutputFormatRequest(
int width, int height, int fps) {
CHECK(thread_checker_.CalledOnValidThread());
const cricket::VideoFormat& current = video_adapter()->output_format();
cricket::VideoFormat format(
width, height, cricket::VideoFormat::FpsToInterval(fps), current.fourcc);
video_adapter()->OnOutputFormatRequest(format);
}
} // namespace webrtc } // namespace webrtc

View File

@ -74,6 +74,9 @@ class AndroidVideoCapturer : public cricket::VideoCapturer {
int rotation, int rotation,
int64 time_stamp); int64 time_stamp);
// Called from JNI to request a new video format.
void OnOutputFormatRequest(int width, int height, int fps);
AndroidVideoCapturerDelegate* delegate() { return delegate_.get(); } AndroidVideoCapturerDelegate* delegate() { return delegate_.get(); }
private: private:

View File

@ -182,6 +182,15 @@ void AndroidVideoCapturerJni::OnIncomingFrame(void* video_frame,
this, video_frame, length, rotation, time_stamp)); this, video_frame, length, rotation, time_stamp));
} }
void AndroidVideoCapturerJni::OnOutputFormatRequest(int width,
int height,
int fps) {
invoker_.AsyncInvoke<void>(
thread_,
rtc::Bind(&AndroidVideoCapturerJni::OnOutputFormatRequest_w,
this, width, height, fps));
}
void AndroidVideoCapturerJni::OnCapturerStarted_w(bool success) { void AndroidVideoCapturerJni::OnCapturerStarted_w(bool success) {
CHECK(thread_checker_.CalledOnValidThread()); CHECK(thread_checker_.CalledOnValidThread());
if (capturer_) { if (capturer_) {
@ -206,6 +215,17 @@ void AndroidVideoCapturerJni::OnIncomingFrame_w(void* video_frame,
} }
} }
void AndroidVideoCapturerJni::OnOutputFormatRequest_w(int width,
int height,
int fps) {
CHECK(thread_checker_.CalledOnValidThread());
if (capturer_) {
capturer_->OnOutputFormatRequest(width, height, fps);
} else {
LOG(LS_WARNING) << "OnOutputFormatRequest_w is called for closed capturer.";
}
}
JNIEnv* AndroidVideoCapturerJni::jni() { return AttachCurrentThreadIfNeeded(); } JNIEnv* AndroidVideoCapturerJni::jni() { return AttachCurrentThreadIfNeeded(); }
JOW(void, VideoCapturerAndroid_00024NativeObserver_nativeOnFrameCaptured) JOW(void, VideoCapturerAndroid_00024NativeObserver_nativeOnFrameCaptured)
@ -233,5 +253,13 @@ JOW(void, VideoCapturerAndroid_00024NativeObserver_nativeCapturerStarted)
j_success); j_success);
} }
JOW(void, VideoCapturerAndroid_00024NativeObserver_nativeOnOutputFormatRequest)
(JNIEnv* jni, jclass, jlong j_capturer, jint j_width, jint j_height,
jint j_fps) {
LOG(LS_INFO) << "NativeObserver_nativeOnOutputFormatRequest";
reinterpret_cast<AndroidVideoCapturerJni*>(j_capturer)->OnOutputFormatRequest(
j_width, j_height, j_fps);
}
} // namespace webrtc_jni } // namespace webrtc_jni

View File

@ -66,6 +66,7 @@ class AndroidVideoCapturerJni : public webrtc::AndroidVideoCapturerDelegate {
int length, int length,
int rotation, int rotation,
int64 time_stamp); int64 time_stamp);
void OnOutputFormatRequest(int width, int height, int fps);
protected: protected:
AndroidVideoCapturerJni(JNIEnv* jni, jobject j_video_capturer); AndroidVideoCapturerJni(JNIEnv* jni, jobject j_video_capturer);
~AndroidVideoCapturerJni(); ~AndroidVideoCapturerJni();
@ -79,6 +80,7 @@ private:
int length, int length,
int rotation, int rotation,
int64 time_stamp); int64 time_stamp);
void OnOutputFormatRequest_w(int width, int height, int fps);
void ReturnBuffer_w(int64 time_stamp); void ReturnBuffer_w(int64 time_stamp);
JNIEnv* jni(); JNIEnv* jni();

View File

@ -270,6 +270,21 @@ public class VideoCapturerAndroid extends VideoCapturer implements PreviewCallba
return true; return true;
} }
// Requests a new output format from the video capturer. Captured frames
// by the camera will be scaled/or dropped by the video capturer.
public synchronized void onOutputFormatRequest(
final int width, final int height, final int fps) {
if (cameraThreadHandler == null) {
Log.e(TAG, "Calling onOutputFormatRequest() for already stopped camera.");
return;
}
cameraThreadHandler.post(new Runnable() {
@Override public void run() {
onOutputFormatRequestOnCameraThread(width, height, fps);
}
});
}
private VideoCapturerAndroid() { private VideoCapturerAndroid() {
Log.d(TAG, "VideoCapturerAndroid"); Log.d(TAG, "VideoCapturerAndroid");
} }
@ -641,6 +656,16 @@ public class VideoCapturerAndroid extends VideoCapturer implements PreviewCallba
} }
} }
private void onOutputFormatRequestOnCameraThread(
int width, int height, int fps) {
if (camera == null) {
return;
}
Log.d(TAG, "onOutputFormatRequestOnCameraThread: " + width + "x" + height +
"@" + fps);
frameObserver.OnOutputFormatRequest(width, height, fps);
}
synchronized void returnBuffer(final long timeStamp) { synchronized void returnBuffer(final long timeStamp) {
if (cameraThreadHandler == null) { if (cameraThreadHandler == null) {
// The camera has been stopped. // The camera has been stopped.
@ -919,6 +944,11 @@ public class VideoCapturerAndroid extends VideoCapturer implements PreviewCallba
// VideoCapturerAndroid. // VideoCapturerAndroid.
abstract void OnFrameCaptured(byte[] data, int length, int rotation, abstract void OnFrameCaptured(byte[] data, int length, int rotation,
long timeStamp); long timeStamp);
// Requests an output format from the video capturer. Captured frames
// by the camera will be scaled/or dropped by the video capturer.
// Called on a Java thread owned by VideoCapturerAndroid.
abstract void OnOutputFormatRequest(int width, int height, int fps);
} }
// An implementation of CapturerObserver that forwards all calls from // An implementation of CapturerObserver that forwards all calls from
@ -941,9 +971,16 @@ public class VideoCapturerAndroid extends VideoCapturer implements PreviewCallba
nativeOnFrameCaptured(nativeCapturer, data, length, rotation, timeStamp); nativeOnFrameCaptured(nativeCapturer, data, length, rotation, timeStamp);
} }
@Override
public void OnOutputFormatRequest(int width, int height, int fps) {
nativeOnOutputFormatRequest(nativeCapturer, width, height, fps);
}
private native void nativeCapturerStarted(long nativeCapturer, private native void nativeCapturerStarted(long nativeCapturer,
boolean success); boolean success);
private native void nativeOnFrameCaptured(long nativeCapturer, private native void nativeOnFrameCaptured(long nativeCapturer,
byte[] data, int length, int rotation, long timeStamp); byte[] data, int length, int rotation, long timeStamp);
private native void nativeOnOutputFormatRequest(long nativeCapturer,
int width, int height, int fps);
} }
} }