| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 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 // FakePeriodicVideoCapturer implements a fake cricket::VideoCapturer that | 11 // FakePeriodicVideoCapturer implements a fake cricket::VideoCapturer that |
| 12 // creates video frames periodically after it has been started. | 12 // creates video frames periodically after it has been started. |
| 13 | 13 |
| 14 #ifndef WEBRTC_API_TEST_FAKEPERIODICVIDEOCAPTURER_H_ | 14 #ifndef WEBRTC_API_TEST_FAKEPERIODICVIDEOCAPTURER_H_ |
| 15 #define WEBRTC_API_TEST_FAKEPERIODICVIDEOCAPTURER_H_ | 15 #define WEBRTC_API_TEST_FAKEPERIODICVIDEOCAPTURER_H_ |
| 16 | 16 |
| 17 #include <vector> |
| 18 |
| 17 #include "webrtc/base/thread.h" | 19 #include "webrtc/base/thread.h" |
| 18 #include "webrtc/media/base/fakevideocapturer.h" | 20 #include "webrtc/media/base/fakevideocapturer.h" |
| 19 | 21 |
| 20 namespace webrtc { | 22 namespace webrtc { |
| 21 | 23 |
| 22 class FakePeriodicVideoCapturer : public cricket::FakeVideoCapturer { | 24 class FakePeriodicVideoCapturer : public cricket::FakeVideoCapturer, |
| 25 public rtc::MessageHandler { |
| 23 public: | 26 public: |
| 24 FakePeriodicVideoCapturer() { | 27 FakePeriodicVideoCapturer() { |
| 25 std::vector<cricket::VideoFormat> formats; | 28 std::vector<cricket::VideoFormat> formats; |
| 26 formats.push_back(cricket::VideoFormat(1280, 720, | 29 formats.push_back(cricket::VideoFormat(1280, 720, |
| 27 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 30 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 28 formats.push_back(cricket::VideoFormat(640, 480, | 31 formats.push_back(cricket::VideoFormat(640, 480, |
| 29 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 32 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 30 formats.push_back(cricket::VideoFormat(640, 360, | 33 formats.push_back(cricket::VideoFormat(640, 360, |
| 31 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 34 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 32 formats.push_back(cricket::VideoFormat(320, 240, | 35 formats.push_back(cricket::VideoFormat(320, 240, |
| 33 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 36 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 34 formats.push_back(cricket::VideoFormat(160, 120, | 37 formats.push_back(cricket::VideoFormat(160, 120, |
| 35 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); | 38 cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420)); |
| 36 ResetSupportedFormats(formats); | 39 ResetSupportedFormats(formats); |
| 37 }; | 40 } |
| 38 | 41 |
| 39 virtual cricket::CaptureState Start(const cricket::VideoFormat& format) { | 42 virtual cricket::CaptureState Start(const cricket::VideoFormat& format) { |
| 40 cricket::CaptureState state = FakeVideoCapturer::Start(format); | 43 cricket::CaptureState state = FakeVideoCapturer::Start(format); |
| 41 if (state != cricket::CS_FAILED) { | 44 if (state != cricket::CS_FAILED) { |
| 42 rtc::Thread::Current()->Post(this, MSG_CREATEFRAME); | 45 rtc::Thread::Current()->Post(this, MSG_CREATEFRAME); |
| 43 } | 46 } |
| 44 return state; | 47 return state; |
| 45 } | 48 } |
| 46 virtual void Stop() { | 49 virtual void Stop() { |
| 47 rtc::Thread::Current()->Clear(this); | 50 rtc::Thread::Current()->Clear(this); |
| 48 } | 51 } |
| 49 // Inherited from MesageHandler. | 52 // Inherited from MesageHandler. |
| 50 virtual void OnMessage(rtc::Message* msg) { | 53 virtual void OnMessage(rtc::Message* msg) { |
| 51 if (msg->message_id == MSG_CREATEFRAME) { | 54 if (msg->message_id == MSG_CREATEFRAME) { |
| 52 if (IsRunning()) { | 55 if (IsRunning()) { |
| 53 CaptureFrame(); | 56 CaptureFrame(); |
| 54 rtc::Thread::Current()->PostDelayed(static_cast<int>( | 57 rtc::Thread::Current()->PostDelayed(static_cast<int>( |
| 55 GetCaptureFormat()->interval / rtc::kNumNanosecsPerMillisec), | 58 GetCaptureFormat()->interval / rtc::kNumNanosecsPerMillisec), |
| 56 this, MSG_CREATEFRAME); | 59 this, MSG_CREATEFRAME); |
| 57 } | 60 } |
| 58 } else { | |
| 59 FakeVideoCapturer::OnMessage(msg); | |
| 60 } | 61 } |
| 61 } | 62 } |
| 62 | 63 |
| 63 private: | 64 private: |
| 64 enum { | 65 enum { |
| 65 // Offset 0xFF to make sure this don't collide with base class messages. | 66 // Offset 0xFF to make sure this don't collide with base class messages. |
| 66 MSG_CREATEFRAME = 0xFF | 67 MSG_CREATEFRAME = 0xFF |
| 67 }; | 68 }; |
| 68 }; | 69 }; |
| 69 | 70 |
| 70 } // namespace webrtc | 71 } // namespace webrtc |
| 71 | 72 |
| 72 #endif // WEBRTC_API_TEST_FAKEPERIODICVIDEOCAPTURER_H_ | 73 #endif // WEBRTC_API_TEST_FAKEPERIODICVIDEOCAPTURER_H_ |
| OLD | NEW |