| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/test/frame_generator_capturer.h" | 11 #include "webrtc/test/frame_generator_capturer.h" |
| 12 | 12 |
| 13 #include "webrtc/base/criticalsection.h" | 13 #include "webrtc/base/criticalsection.h" |
| 14 #include "webrtc/base/platform_thread.h" | 14 #include "webrtc/base/platform_thread.h" |
| 15 #include "webrtc/system_wrappers/include/clock.h" | 15 #include "webrtc/system_wrappers/include/clock.h" |
| 16 #include "webrtc/system_wrappers/include/event_wrapper.h" | 16 #include "webrtc/system_wrappers/include/event_wrapper.h" |
| 17 #include "webrtc/system_wrappers/include/sleep.h" | 17 #include "webrtc/system_wrappers/include/sleep.h" |
| 18 #include "webrtc/test/frame_generator.h" | 18 #include "webrtc/test/frame_generator.h" |
| 19 #include "webrtc/video_send_stream.h" | 19 #include "webrtc/video_send_stream.h" |
| 20 | 20 |
| 21 namespace webrtc { | 21 namespace webrtc { |
| 22 namespace test { | 22 namespace test { |
| 23 | 23 |
| 24 FrameGeneratorCapturer* FrameGeneratorCapturer::Create(VideoCaptureInput* input, | 24 FrameGeneratorCapturer* FrameGeneratorCapturer::Create(size_t width, |
| 25 size_t width, | |
| 26 size_t height, | 25 size_t height, |
| 27 int target_fps, | 26 int target_fps, |
| 28 Clock* clock) { | 27 Clock* clock) { |
| 29 FrameGeneratorCapturer* capturer = new FrameGeneratorCapturer( | 28 FrameGeneratorCapturer* capturer = new FrameGeneratorCapturer( |
| 30 clock, input, FrameGenerator::CreateChromaGenerator(width, height), | 29 clock, FrameGenerator::CreateChromaGenerator(width, height), target_fps); |
| 31 target_fps); | |
| 32 if (!capturer->Init()) { | 30 if (!capturer->Init()) { |
| 33 delete capturer; | 31 delete capturer; |
| 34 return NULL; | 32 return NULL; |
| 35 } | 33 } |
| 36 | 34 |
| 37 return capturer; | 35 return capturer; |
| 38 } | 36 } |
| 39 | 37 |
| 40 FrameGeneratorCapturer* FrameGeneratorCapturer::CreateFromYuvFile( | 38 FrameGeneratorCapturer* FrameGeneratorCapturer::CreateFromYuvFile( |
| 41 VideoCaptureInput* input, | |
| 42 const std::string& file_name, | 39 const std::string& file_name, |
| 43 size_t width, | 40 size_t width, |
| 44 size_t height, | 41 size_t height, |
| 45 int target_fps, | 42 int target_fps, |
| 46 Clock* clock) { | 43 Clock* clock) { |
| 47 FrameGeneratorCapturer* capturer = new FrameGeneratorCapturer( | 44 FrameGeneratorCapturer* capturer = new FrameGeneratorCapturer( |
| 48 clock, input, | 45 clock, FrameGenerator::CreateFromYuvFile( |
| 49 FrameGenerator::CreateFromYuvFile(std::vector<std::string>(1, file_name), | 46 std::vector<std::string>(1, file_name), width, height, 1), |
| 50 width, height, 1), | |
| 51 target_fps); | 47 target_fps); |
| 52 if (!capturer->Init()) { | 48 if (!capturer->Init()) { |
| 53 delete capturer; | 49 delete capturer; |
| 54 return NULL; | 50 return NULL; |
| 55 } | 51 } |
| 56 | 52 |
| 57 return capturer; | 53 return capturer; |
| 58 } | 54 } |
| 59 | 55 |
| 60 FrameGeneratorCapturer::FrameGeneratorCapturer(Clock* clock, | 56 FrameGeneratorCapturer::FrameGeneratorCapturer(Clock* clock, |
| 61 VideoCaptureInput* input, | |
| 62 FrameGenerator* frame_generator, | 57 FrameGenerator* frame_generator, |
| 63 int target_fps) | 58 int target_fps) |
| 64 : VideoCapturer(input), | 59 : clock_(clock), |
| 65 clock_(clock), | |
| 66 sending_(false), | 60 sending_(false), |
| 61 sink_(nullptr), |
| 67 tick_(EventTimerWrapper::Create()), | 62 tick_(EventTimerWrapper::Create()), |
| 68 thread_(FrameGeneratorCapturer::Run, this, "FrameGeneratorCapturer"), | 63 thread_(FrameGeneratorCapturer::Run, this, "FrameGeneratorCapturer"), |
| 69 frame_generator_(frame_generator), | 64 frame_generator_(frame_generator), |
| 70 target_fps_(target_fps), | 65 target_fps_(target_fps), |
| 71 first_frame_capture_time_(-1) { | 66 first_frame_capture_time_(-1) { |
| 72 assert(input != NULL); | 67 RTC_DCHECK(frame_generator); |
| 73 assert(frame_generator != NULL); | 68 RTC_DCHECK_GT(target_fps, 0); |
| 74 assert(target_fps > 0); | |
| 75 } | 69 } |
| 76 | 70 |
| 77 FrameGeneratorCapturer::~FrameGeneratorCapturer() { | 71 FrameGeneratorCapturer::~FrameGeneratorCapturer() { |
| 78 Stop(); | 72 Stop(); |
| 79 | 73 |
| 80 thread_.Stop(); | 74 thread_.Stop(); |
| 81 } | 75 } |
| 82 | 76 |
| 83 void FrameGeneratorCapturer::SetFakeRotation(VideoRotation rotation) { | 77 void FrameGeneratorCapturer::SetFakeRotation(VideoRotation rotation) { |
| 84 rtc::CritScope cs(&lock_); | 78 rtc::CritScope cs(&lock_); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 106 void FrameGeneratorCapturer::InsertFrame() { | 100 void FrameGeneratorCapturer::InsertFrame() { |
| 107 { | 101 { |
| 108 rtc::CritScope cs(&lock_); | 102 rtc::CritScope cs(&lock_); |
| 109 if (sending_) { | 103 if (sending_) { |
| 110 VideoFrame* frame = frame_generator_->NextFrame(); | 104 VideoFrame* frame = frame_generator_->NextFrame(); |
| 111 frame->set_ntp_time_ms(clock_->CurrentNtpInMilliseconds()); | 105 frame->set_ntp_time_ms(clock_->CurrentNtpInMilliseconds()); |
| 112 frame->set_rotation(fake_rotation_); | 106 frame->set_rotation(fake_rotation_); |
| 113 if (first_frame_capture_time_ == -1) { | 107 if (first_frame_capture_time_ == -1) { |
| 114 first_frame_capture_time_ = frame->ntp_time_ms(); | 108 first_frame_capture_time_ = frame->ntp_time_ms(); |
| 115 } | 109 } |
| 116 input_->IncomingCapturedFrame(*frame); | 110 if (sink_) |
| 111 sink_->OnFrame(*frame); |
| 117 } | 112 } |
| 118 } | 113 } |
| 119 tick_->Wait(WEBRTC_EVENT_INFINITE); | 114 tick_->Wait(WEBRTC_EVENT_INFINITE); |
| 120 } | 115 } |
| 121 | 116 |
| 122 void FrameGeneratorCapturer::Start() { | 117 void FrameGeneratorCapturer::Start() { |
| 123 rtc::CritScope cs(&lock_); | 118 rtc::CritScope cs(&lock_); |
| 124 sending_ = true; | 119 sending_ = true; |
| 125 } | 120 } |
| 126 | 121 |
| 127 void FrameGeneratorCapturer::Stop() { | 122 void FrameGeneratorCapturer::Stop() { |
| 128 rtc::CritScope cs(&lock_); | 123 rtc::CritScope cs(&lock_); |
| 129 sending_ = false; | 124 sending_ = false; |
| 130 } | 125 } |
| 131 | 126 |
| 127 void FrameGeneratorCapturer::AddOrUpdateSink( |
| 128 rtc::VideoSinkInterface<VideoFrame>* sink, |
| 129 const rtc::VideoSinkWants& wants) { |
| 130 rtc::CritScope cs(&lock_); |
| 131 RTC_CHECK(!sink_); |
| 132 sink_ = sink; |
| 133 } |
| 134 |
| 135 void FrameGeneratorCapturer::RemoveSink( |
| 136 rtc::VideoSinkInterface<VideoFrame>* sink) { |
| 137 rtc::CritScope cs(&lock_); |
| 138 RTC_CHECK(sink_ == sink); |
| 139 sink_ = nullptr; |
| 140 } |
| 141 |
| 132 void FrameGeneratorCapturer::ForceFrame() { | 142 void FrameGeneratorCapturer::ForceFrame() { |
| 133 tick_->Set(); | 143 tick_->Set(); |
| 134 } | 144 } |
| 135 } // test | 145 } // test |
| 136 } // webrtc | 146 } // webrtc |
| OLD | NEW |