OLD | NEW |
| (Empty) |
1 /* | |
2 * Copyright (c) 2010 The WebRTC project authors. All Rights Reserved. | |
3 * | |
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 | |
6 * tree. An additional intellectual property rights grant can be found | |
7 * in the file PATENTS. All contributing project authors may | |
8 * be found in the AUTHORS file in the root of the source tree. | |
9 */ | |
10 | |
11 // Generates YUV420 frames with a "landscape with striped crosshair" in the | |
12 // Y-plane, plus a horizontal gradient in the U-plane and a vertical one in the | |
13 // V-plane. This makes for a nice mix of colours that is suited for both | |
14 // catching visual errors and making sure e.g. YUV->RGB/BGR conversion looks | |
15 // the same on different platforms. | |
16 // There is also a solid box bouncing around in the Y-plane, and two differently | |
17 // coloured lines bouncing horizontally and vertically in the U and V plane. | |
18 // This helps illustrating how the frame boundary goes, and can aid as a quite | |
19 // handy visual help for noticing e.g. packet loss if the frames are encoded | |
20 // and sent over the network. | |
21 | |
22 #ifndef WEBRTC_MEDIA_BASE_YUVFRAMEGENERATOR_H_ | |
23 #define WEBRTC_MEDIA_BASE_YUVFRAMEGENERATOR_H_ | |
24 | |
25 #include "webrtc/base/basictypes.h" | |
26 #include "webrtc/base/constructormagic.h" | |
27 | |
28 namespace cricket { | |
29 | |
30 class YuvFrameGenerator { | |
31 public: | |
32 // Constructs a frame-generator that produces frames of size |width|x|height|. | |
33 // If |enable_barcode| is specified, barcodes can be included in the frames | |
34 // when calling |GenerateNextFrame(uint8_t*, uint32_t)|. If |enable_barcode| | |
35 // is |true| then |width|x|height| should be at least 160x100; otherwise this | |
36 // constructor will abort. | |
37 YuvFrameGenerator(int width, int height, bool enable_barcode); | |
38 ~YuvFrameGenerator(); | |
39 | |
40 int GetFrameSize() { return frame_data_size_; } | |
41 | |
42 // Generate the next frame and return it in the provided |frame_buffer|. If | |
43 // barcode_value is not |nullptr| the value referred by it will be encoded | |
44 // into a barcode in the frame. The value should in the range: | |
45 // [0..9,999,999]. If the value exceeds this range or barcodes were not | |
46 // requested in the constructor, this function will abort. | |
47 void GenerateNextFrame(uint8_t* frame_buffer, int32_t barcode_value); | |
48 | |
49 int GetHeight() { return height_; } | |
50 int GetWidth() { return width_; } | |
51 | |
52 // Fetch the bounds of the barcode from the generator. The barcode will | |
53 // always be at this location. This function will abort if barcodes were not | |
54 // requested in the constructor. | |
55 void GetBarcodeBounds(int* top, int* left, int* width, int* height); | |
56 | |
57 private: | |
58 void DrawLandscape(uint8_t* p, int w, int h); | |
59 void DrawGradientX(uint8_t* p, int w, int h); | |
60 void DrawGradientY(uint8_t* p, int w, int h); | |
61 void DrawMovingLineX(uint8_t* p, int w, int h, int n); | |
62 void DrawMovingLineY(uint8_t* p, int w, int h, int n); | |
63 void DrawBouncingCube(uint8_t* p, int w, int h, int n); | |
64 | |
65 void DrawBarcode(uint32_t value); | |
66 int DrawSideGuardBars(int x, int y, int height); | |
67 int DrawMiddleGuardBars(int x, int y, int height); | |
68 int DrawEanEncodedDigit(int digit, int x, int y, int height, bool r_code); | |
69 void DrawBlockRectangle(uint8_t* p, | |
70 int x_start, | |
71 int y_start, | |
72 int width, | |
73 int height, | |
74 int pitch, | |
75 uint8_t value); | |
76 | |
77 private: | |
78 int width_; | |
79 int height_; | |
80 int frame_index_; | |
81 int frame_data_size_; | |
82 uint8_t* y_data_; | |
83 uint8_t* u_data_; | |
84 uint8_t* v_data_; | |
85 | |
86 int barcode_start_x_; | |
87 int barcode_start_y_; | |
88 | |
89 RTC_DISALLOW_COPY_AND_ASSIGN(YuvFrameGenerator); | |
90 }; | |
91 | |
92 } // namespace cricket | |
93 | |
94 #endif // WEBRTC_MEDIA_BASE_YUVFRAMEGENERATOR_H_ | |
OLD | NEW |