OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2015 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #include "webrtc/api/androidvideocapturer.h" |
| 12 |
| 13 #include <memory> |
| 14 |
| 15 #include "webrtc/api/android/jni/native_handle_impl.h" |
| 16 #include "webrtc/base/common.h" |
| 17 #include "webrtc/base/timeutils.h" |
| 18 #include "webrtc/media/engine/webrtcvideoframe.h" |
| 19 |
| 20 namespace webrtc { |
| 21 |
| 22 AndroidVideoCapturer::AndroidVideoCapturer( |
| 23 const rtc::scoped_refptr<AndroidVideoCapturerDelegate>& delegate) |
| 24 : running_(false), |
| 25 delegate_(delegate) { |
| 26 thread_checker_.DetachFromThread(); |
| 27 SetSupportedFormats(delegate_->GetSupportedFormats()); |
| 28 } |
| 29 |
| 30 AndroidVideoCapturer::~AndroidVideoCapturer() { |
| 31 RTC_CHECK(!running_); |
| 32 } |
| 33 |
| 34 cricket::CaptureState AndroidVideoCapturer::Start( |
| 35 const cricket::VideoFormat& capture_format) { |
| 36 RTC_CHECK(thread_checker_.CalledOnValidThread()); |
| 37 RTC_CHECK(!running_); |
| 38 const int fps = cricket::VideoFormat::IntervalToFps(capture_format.interval); |
| 39 LOG(LS_INFO) << " AndroidVideoCapturer::Start " << capture_format.width << "x" |
| 40 << capture_format.height << "@" << fps; |
| 41 |
| 42 running_ = true; |
| 43 delegate_->Start(capture_format.width, capture_format.height, fps, this); |
| 44 SetCaptureFormat(&capture_format); |
| 45 return cricket::CS_STARTING; |
| 46 } |
| 47 |
| 48 void AndroidVideoCapturer::Stop() { |
| 49 LOG(LS_INFO) << " AndroidVideoCapturer::Stop "; |
| 50 RTC_CHECK(thread_checker_.CalledOnValidThread()); |
| 51 RTC_CHECK(running_); |
| 52 running_ = false; |
| 53 SetCaptureFormat(NULL); |
| 54 |
| 55 delegate_->Stop(); |
| 56 SetCaptureState(cricket::CS_STOPPED); |
| 57 } |
| 58 |
| 59 bool AndroidVideoCapturer::IsRunning() { |
| 60 RTC_CHECK(thread_checker_.CalledOnValidThread()); |
| 61 return running_; |
| 62 } |
| 63 |
| 64 bool AndroidVideoCapturer::GetPreferredFourccs(std::vector<uint32_t>* fourccs) { |
| 65 RTC_CHECK(thread_checker_.CalledOnValidThread()); |
| 66 fourccs->push_back(cricket::FOURCC_YV12); |
| 67 return true; |
| 68 } |
| 69 |
| 70 void AndroidVideoCapturer::OnCapturerStarted(bool success) { |
| 71 RTC_CHECK(thread_checker_.CalledOnValidThread()); |
| 72 const cricket::CaptureState new_state = |
| 73 success ? cricket::CS_RUNNING : cricket::CS_FAILED; |
| 74 SetCaptureState(new_state); |
| 75 } |
| 76 |
| 77 void AndroidVideoCapturer::OnOutputFormatRequest( |
| 78 int width, int height, int fps) { |
| 79 RTC_CHECK(thread_checker_.CalledOnValidThread()); |
| 80 cricket::VideoFormat format(width, height, |
| 81 cricket::VideoFormat::FpsToInterval(fps), 0); |
| 82 video_adapter()->OnOutputFormatRequest(format); |
| 83 } |
| 84 |
| 85 bool AndroidVideoCapturer::GetBestCaptureFormat( |
| 86 const cricket::VideoFormat& desired, |
| 87 cricket::VideoFormat* best_format) { |
| 88 // Delegate this choice to VideoCapturer.startCapture(). |
| 89 *best_format = desired; |
| 90 return true; |
| 91 } |
| 92 |
| 93 } // namespace webrtc |
OLD | NEW |