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