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

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

Issue 2278883002: Move MutableDataY{,U,V} methods to I420Buffer only. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Update android capture and decoder code. Created 4 years, 3 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
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 21
22 namespace webrtc { 22 namespace webrtc {
23 namespace test { 23 namespace test {
24 namespace { 24 namespace {
25 25
26 class ChromaGenerator : public FrameGenerator { 26 class ChromaGenerator : public FrameGenerator {
27 public: 27 public:
28 ChromaGenerator(size_t width, size_t height) 28 ChromaGenerator(size_t width, size_t height) : angle_(0.0) {
29 : angle_(0.0), width_(width), height_(height) {
30 assert(width > 0); 29 assert(width > 0);
31 assert(height > 0); 30 assert(height > 0);
31 size_t half_width = (width + 1) / 2;
32 y_size_ = width * height;
33 uv_size_ = half_width * ((height + 1) / 2);
34
35 // Ensure stride == width.
36 buffer_ = I420Buffer::Create(width, height, width, half_width, half_width);
32 } 37 }
33 38
34 VideoFrame* NextFrame() override { 39 VideoFrame* NextFrame() override {
35 frame_.CreateEmptyFrame(static_cast<int>(width_),
36 static_cast<int>(height_),
37 static_cast<int>(width_),
38 static_cast<int>((width_ + 1) / 2),
39 static_cast<int>((width_ + 1) / 2));
40 angle_ += 30.0; 40 angle_ += 30.0;
41 uint8_t u = fabs(sin(angle_)) * 0xFF; 41 uint8_t u = fabs(sin(angle_)) * 0xFF;
42 uint8_t v = fabs(cos(angle_)) * 0xFF; 42 uint8_t v = fabs(cos(angle_)) * 0xFF;
43 43
44 memset(frame_.video_frame_buffer()->MutableDataY(), 0x80, 44 memset(buffer_->MutableDataY(), 0x80, y_size_);
45 frame_.allocated_size(kYPlane)); 45 memset(buffer_->MutableDataU(), u, uv_size_);
46 memset(frame_.video_frame_buffer()->MutableDataU(), u, 46 memset(buffer_->MutableDataV(), v, uv_size_);
47 frame_.allocated_size(kUPlane)); 47
48 memset(frame_.video_frame_buffer()->MutableDataV(), v, 48 frame_.reset(new VideoFrame(buffer_, 0, 0, webrtc::kVideoRotation_0));
49 frame_.allocated_size(kVPlane)); 49 return frame_.get();
50 return &frame_;
51 } 50 }
52 51
53 private: 52 private:
54 double angle_; 53 double angle_;
55 size_t width_; 54 size_t y_size_;
56 size_t height_; 55 size_t uv_size_;
57 VideoFrame frame_; 56 rtc::scoped_refptr<I420Buffer> buffer_;
57 std::unique_ptr<VideoFrame> frame_;
58 }; 58 };
59 59
60 class YuvFileGenerator : public FrameGenerator { 60 class YuvFileGenerator : public FrameGenerator {
61 public: 61 public:
62 YuvFileGenerator(std::vector<FILE*> files, 62 YuvFileGenerator(std::vector<FILE*> files,
63 size_t width, 63 size_t width,
64 size_t height, 64 size_t height,
65 int frame_repeat_count) 65 int frame_repeat_count)
66 : file_index_(0), 66 : file_index_(0),
67 files_(files), 67 files_(files),
(...skipping 14 matching lines...) Expand all
82 for (FILE* file : files_) 82 for (FILE* file : files_)
83 fclose(file); 83 fclose(file);
84 } 84 }
85 85
86 VideoFrame* NextFrame() override { 86 VideoFrame* NextFrame() override {
87 if (current_display_count_ == 0) 87 if (current_display_count_ == 0)
88 ReadNextFrame(); 88 ReadNextFrame();
89 if (++current_display_count_ >= frame_display_count_) 89 if (++current_display_count_ >= frame_display_count_)
90 current_display_count_ = 0; 90 current_display_count_ = 0;
91 91
92 // If this is the last repeatition of this frame, it's OK to use the 92 temp_frame_.reset(
93 // original instance, otherwise use a copy. 93 new VideoFrame(last_read_buffer_, 0, 0, webrtc::kVideoRotation_0));
94 if (current_display_count_ == frame_display_count_) 94 return temp_frame_.get();
95 return &last_read_frame_;
96
97 temp_frame_copy_.CopyFrame(last_read_frame_);
98 return &temp_frame_copy_;
99 } 95 }
100 96
101 void ReadNextFrame() { 97 void ReadNextFrame() {
102 size_t bytes_read = 98 size_t bytes_read =
103 fread(frame_buffer_.get(), 1, frame_size_, files_[file_index_]); 99 fread(frame_buffer_.get(), 1, frame_size_, files_[file_index_]);
104 if (bytes_read < frame_size_) { 100 if (bytes_read < frame_size_) {
105 // No more frames to read in this file, rewind and move to next file. 101 // No more frames to read in this file, rewind and move to next file.
106 rewind(files_[file_index_]); 102 rewind(files_[file_index_]);
107 file_index_ = (file_index_ + 1) % files_.size(); 103 file_index_ = (file_index_ + 1) % files_.size();
108 bytes_read = fread(frame_buffer_.get(), 1, frame_size_, 104 bytes_read = fread(frame_buffer_.get(), 1, frame_size_,
109 files_[file_index_]); 105 files_[file_index_]);
110 assert(bytes_read >= frame_size_); 106 assert(bytes_read >= frame_size_);
111 } 107 }
112 108
113 last_read_frame_.CreateEmptyFrame( 109 last_read_buffer_ = I420Buffer::Create(
114 static_cast<int>(width_), static_cast<int>(height_), 110 static_cast<int>(width_), static_cast<int>(height_),
115 static_cast<int>(width_), static_cast<int>((width_ + 1) / 2), 111 static_cast<int>(width_), static_cast<int>((width_ + 1) / 2),
116 static_cast<int>((width_ + 1) / 2)); 112 static_cast<int>((width_ + 1) / 2));
117
118 ConvertToI420(kI420, frame_buffer_.get(), 0, 0, static_cast<int>(width_), 113 ConvertToI420(kI420, frame_buffer_.get(), 0, 0, static_cast<int>(width_),
119 static_cast<int>(height_), 0, kVideoRotation_0, 114 static_cast<int>(height_), 0, kVideoRotation_0,
120 &last_read_frame_); 115 last_read_buffer_);
121 } 116 }
122 117
123 private: 118 private:
124 size_t file_index_; 119 size_t file_index_;
125 const std::vector<FILE*> files_; 120 const std::vector<FILE*> files_;
126 const size_t width_; 121 const size_t width_;
127 const size_t height_; 122 const size_t height_;
128 const size_t frame_size_; 123 const size_t frame_size_;
129 const std::unique_ptr<uint8_t[]> frame_buffer_; 124 const std::unique_ptr<uint8_t[]> frame_buffer_;
130 const int frame_display_count_; 125 const int frame_display_count_;
131 int current_display_count_; 126 int current_display_count_;
132 VideoFrame last_read_frame_; 127 rtc::scoped_refptr<I420Buffer> last_read_buffer_;
133 VideoFrame temp_frame_copy_; 128 std::unique_ptr<VideoFrame> temp_frame_;
134 }; 129 };
135 130
136 class ScrollingImageFrameGenerator : public FrameGenerator { 131 class ScrollingImageFrameGenerator : public FrameGenerator {
137 public: 132 public:
138 ScrollingImageFrameGenerator(Clock* clock, 133 ScrollingImageFrameGenerator(Clock* clock,
139 const std::vector<FILE*>& files, 134 const std::vector<FILE*>& files,
140 size_t source_width, 135 size_t source_width,
141 size_t source_height, 136 size_t source_height,
142 size_t target_width, 137 size_t target_width,
143 size_t target_height, 138 size_t target_height,
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 files.push_back(file); 272 files.push_back(file);
278 } 273 }
279 274
280 return new ScrollingImageFrameGenerator( 275 return new ScrollingImageFrameGenerator(
281 clock, files, source_width, source_height, target_width, target_height, 276 clock, files, source_width, source_height, target_width, target_height,
282 scroll_time_ms, pause_time_ms); 277 scroll_time_ms, pause_time_ms);
283 } 278 }
284 279
285 } // namespace test 280 } // namespace test
286 } // namespace webrtc 281 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698