1 /* 2 * libjingle 3 * Copyright 2010 Google Inc. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 3. The name of the author may not be used to endorse or promote products 14 * derived from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 // Generates YUV420 frames with a "landscape with striped crosshair" in the 29 // Y-plane, plus a horizontal gradient in the U-plane and a vertical one in the 30 // V-plane. This makes for a nice mix of colours that is suited for both 31 // catching visual errors and making sure e.g. YUV->RGB/BGR conversion looks 32 // the same on different platforms. 33 // There is also a solid box bouncing around in the Y-plane, and two differently 34 // coloured lines bouncing horizontally and vertically in the U and V plane. 35 // This helps illustrating how the frame boundary goes, and can aid as a quite 36 // handy visual help for noticing e.g. packet loss if the frames are encoded 37 // and sent over the network. 38 39 #ifndef TALK_MEDIA_BASE_YUVFRAMEGENERATOR_H_ 40 #define TALK_MEDIA_BASE_YUVFRAMEGENERATOR_H_ 41 42 #include "webrtc/base/basictypes.h" 43 #include "webrtc/base/constructormagic.h" 44 45 namespace cricket { 46 47 class YuvFrameGenerator { 48 public: 49 // Constructs a frame-generator that produces frames of size |width|x|height|. 50 // If |enable_barcode| is specified, barcodes can be included in the frames 51 // when calling |GenerateNextFrame(uint8_t*, uint32_t)|. If |enable_barcode| 52 // is |true| then |width|x|height| should be at least 160x100; otherwise this 53 // constructor will abort. 54 YuvFrameGenerator(int width, int height, bool enable_barcode); 55 ~YuvFrameGenerator(); 56 GetFrameSize()57 int GetFrameSize() { return frame_data_size_; } 58 59 // Generate the next frame and return it in the provided |frame_buffer|. If 60 // barcode_value is not |nullptr| the value referred by it will be encoded 61 // into a barcode in the frame. The value should in the range: 62 // [0..9,999,999]. If the value exceeds this range or barcodes were not 63 // requested in the constructor, this function will abort. 64 void GenerateNextFrame(uint8_t* frame_buffer, int32_t barcode_value); 65 GetHeight()66 int GetHeight() { return height_; } GetWidth()67 int GetWidth() { return width_; } 68 69 // Fetch the bounds of the barcode from the generator. The barcode will 70 // always be at this location. This function will abort if barcodes were not 71 // requested in the constructor. 72 void GetBarcodeBounds(int* top, int* left, int* width, int* height); 73 74 private: 75 void DrawLandscape(uint8_t* p, int w, int h); 76 void DrawGradientX(uint8_t* p, int w, int h); 77 void DrawGradientY(uint8_t* p, int w, int h); 78 void DrawMovingLineX(uint8_t* p, int w, int h, int n); 79 void DrawMovingLineY(uint8_t* p, int w, int h, int n); 80 void DrawBouncingCube(uint8_t* p, int w, int h, int n); 81 82 void DrawBarcode(uint32_t value); 83 int DrawSideGuardBars(int x, int y, int height); 84 int DrawMiddleGuardBars(int x, int y, int height); 85 int DrawEanEncodedDigit(int digit, int x, int y, int height, bool r_code); 86 void DrawBlockRectangle(uint8_t* p, 87 int x_start, 88 int y_start, 89 int width, 90 int height, 91 int pitch, 92 uint8_t value); 93 94 private: 95 int width_; 96 int height_; 97 int frame_index_; 98 int frame_data_size_; 99 uint8_t* y_data_; 100 uint8_t* u_data_; 101 uint8_t* v_data_; 102 103 int barcode_start_x_; 104 int barcode_start_y_; 105 106 RTC_DISALLOW_COPY_AND_ASSIGN(YuvFrameGenerator); 107 }; 108 109 } // namespace cricket 110 111 #endif // TALK_MEDIA_BASE_YUVFRAMEGENERATOR_H_ 112