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 #include "webrtc/test/frame_generator.h" | 10 #include "webrtc/test/frame_generator.h" |
11 | 11 |
12 #include <math.h> | 12 #include <math.h> |
13 #include <stdio.h> | 13 #include <stdio.h> |
14 #include <string.h> | 14 #include <string.h> |
15 | 15 |
16 #include <memory> | 16 #include <memory> |
17 | 17 |
18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
20 #include "webrtc/system_wrappers/include/clock.h" | 20 #include "webrtc/system_wrappers/include/clock.h" |
21 #include "libyuv/convert.h" | 21 #include "libyuv/convert.h" |
22 | 22 |
23 namespace webrtc { | 23 namespace webrtc { |
24 namespace test { | 24 namespace test { |
25 namespace { | 25 namespace { |
26 | 26 |
27 class ChromaGenerator : public FrameGenerator { | 27 class ChromaGenerator : public FrameGenerator { |
28 public: | 28 public: |
29 ChromaGenerator(size_t width, size_t height) | 29 ChromaGenerator(size_t width, size_t height) : angle_(0.0) { |
30 : angle_(0.0), width_(width), height_(height) { | 30 ChangeResolution(width, height); |
31 } | |
32 | |
33 void ChangeResolution(size_t width, size_t height) override { | |
34 rtc::CritScope lock(&crit_); | |
35 width_ = width; | |
36 height_ = height; | |
31 RTC_CHECK(width_ > 0); | 37 RTC_CHECK(width_ > 0); |
32 RTC_CHECK(height_ > 0); | 38 RTC_CHECK(height_ > 0); |
33 half_width_ = (width_ + 1) / 2; | 39 half_width_ = (width_ + 1) / 2; |
34 y_size_ = width_ * height_; | 40 y_size_ = width_ * height_; |
35 uv_size_ = half_width_ * ((height_ + 1) / 2); | 41 uv_size_ = half_width_ * ((height_ + 1) / 2); |
36 } | 42 } |
37 | 43 |
38 VideoFrame* NextFrame() override { | 44 VideoFrame* NextFrame() override { |
45 rtc::CritScope lock(&crit_); | |
39 angle_ += 30.0; | 46 angle_ += 30.0; |
40 uint8_t u = fabs(sin(angle_)) * 0xFF; | 47 uint8_t u = fabs(sin(angle_)) * 0xFF; |
41 uint8_t v = fabs(cos(angle_)) * 0xFF; | 48 uint8_t v = fabs(cos(angle_)) * 0xFF; |
42 | 49 |
43 // Ensure stride == width. | 50 // Ensure stride == width. |
44 rtc::scoped_refptr<I420Buffer> buffer(I420Buffer::Create( | 51 rtc::scoped_refptr<I420Buffer> buffer(I420Buffer::Create( |
45 static_cast<int>(width_), static_cast<int>(height_), | 52 static_cast<int>(width_), static_cast<int>(height_), |
46 static_cast<int>(width_), static_cast<int>(half_width_), | 53 static_cast<int>(width_), static_cast<int>(half_width_), |
47 static_cast<int>(half_width_))); | 54 static_cast<int>(half_width_))); |
48 | 55 |
49 memset(buffer->MutableDataY(), 0x80, y_size_); | 56 memset(buffer->MutableDataY(), 0x80, y_size_); |
50 memset(buffer->MutableDataU(), u, uv_size_); | 57 memset(buffer->MutableDataU(), u, uv_size_); |
51 memset(buffer->MutableDataV(), v, uv_size_); | 58 memset(buffer->MutableDataV(), v, uv_size_); |
52 | 59 |
53 frame_.reset(new VideoFrame(buffer, 0, 0, webrtc::kVideoRotation_0)); | 60 frame_.reset(new VideoFrame(buffer, 0, 0, webrtc::kVideoRotation_0)); |
54 return frame_.get(); | 61 return frame_.get(); |
55 } | 62 } |
56 | 63 |
57 private: | 64 private: |
65 rtc::CriticalSection crit_; | |
58 double angle_; | 66 double angle_; |
59 size_t width_; | 67 size_t width_; |
mflodman
2016/09/27 11:28:01
Can you add GUARDED_BY(...) here.
perkj_webrtc
2016/09/27 13:45:17
Done.
| |
60 size_t height_; | 68 size_t height_; |
61 size_t half_width_; | 69 size_t half_width_; |
62 size_t y_size_; | 70 size_t y_size_; |
63 size_t uv_size_; | 71 size_t uv_size_; |
64 std::unique_ptr<VideoFrame> frame_; | 72 std::unique_ptr<VideoFrame> frame_; |
65 }; | 73 }; |
66 | 74 |
67 class YuvFileGenerator : public FrameGenerator { | 75 class YuvFileGenerator : public FrameGenerator { |
68 public: | 76 public: |
69 YuvFileGenerator(std::vector<FILE*> files, | 77 YuvFileGenerator(std::vector<FILE*> files, |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
310 files.push_back(file); | 318 files.push_back(file); |
311 } | 319 } |
312 | 320 |
313 return new ScrollingImageFrameGenerator( | 321 return new ScrollingImageFrameGenerator( |
314 clock, files, source_width, source_height, target_width, target_height, | 322 clock, files, source_width, source_height, target_width, target_height, |
315 scroll_time_ms, pause_time_ms); | 323 scroll_time_ms, pause_time_ms); |
316 } | 324 } |
317 | 325 |
318 } // namespace test | 326 } // namespace test |
319 } // namespace webrtc | 327 } // namespace webrtc |
OLD | NEW |