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