Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(357)

Side by Side Diff: webrtc/test/frame_generator.cc

Issue 2351633002: Let ViEEncoder handle resolution changes. (Closed)
Patch Set: rebased Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/test/frame_generator.h ('k') | webrtc/test/frame_generator_capturer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "webrtc/test/frame_utils.h" 21 #include "webrtc/test/frame_utils.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:
58 double angle_; 65 rtc::CriticalSection crit_;
59 size_t width_; 66 double angle_ GUARDED_BY(&crit_);
60 size_t height_; 67 size_t width_ GUARDED_BY(&crit_);
61 size_t half_width_; 68 size_t height_ GUARDED_BY(&crit_);
62 size_t y_size_; 69 size_t half_width_ GUARDED_BY(&crit_);
63 size_t uv_size_; 70 size_t y_size_ GUARDED_BY(&crit_);
64 std::unique_ptr<VideoFrame> frame_; 71 size_t uv_size_ GUARDED_BY(&crit_);
72 std::unique_ptr<VideoFrame> frame_ GUARDED_BY(&crit_);
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,
70 size_t width, 78 size_t width,
71 size_t height, 79 size_t height,
72 int frame_repeat_count) 80 int frame_repeat_count)
73 : file_index_(0), 81 : file_index_(0),
74 files_(files), 82 files_(files),
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 files.push_back(file); 304 files.push_back(file);
297 } 305 }
298 306
299 return new ScrollingImageFrameGenerator( 307 return new ScrollingImageFrameGenerator(
300 clock, files, source_width, source_height, target_width, target_height, 308 clock, files, source_width, source_height, target_width, target_height,
301 scroll_time_ms, pause_time_ms); 309 scroll_time_ms, pause_time_ms);
302 } 310 }
303 311
304 } // namespace test 312 } // namespace test
305 } // namespace webrtc 313 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/test/frame_generator.h ('k') | webrtc/test/frame_generator_capturer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698