1 // Copyright 2019 The Chromium OS Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef C2_E2E_TEST_VIDEO_FRAME_H_ 6 #define C2_E2E_TEST_VIDEO_FRAME_H_ 7 8 #include <fstream> 9 #include <memory> 10 #include <string> 11 12 #include "common.h" 13 #include "md5.h" 14 15 namespace android { 16 17 // The helper class to convert video frame data to I420 format and make a copy 18 // of planes, cropped within the visible window. 19 class VideoFrame { 20 public: 21 // Pre-check the validity of input parameters. 22 static std::unique_ptr<VideoFrame> Create(const uint8_t* data, size_t data_size, 23 const Size& coded_size, const Size& visible_size, 24 int32_t color_format); 25 VideoFrame() = delete; 26 ~VideoFrame() = default; 27 28 enum { 29 // Android color format similar to I420. 30 YUV_420_PLANAR = 0x13, 31 // Android color format which is flexible. For Chrome OS devices, it may be 32 // either YV12 or NV12 as HAL pixel format. 33 // Note: This format is not able to parse, client is required to call 34 // MatchHalFormatByGoldenMD5() first to identify the corresponding HAL 35 // pixel format. 36 YUV_420_FLEXIBLE = 0x7f420888, 37 38 // NV12: semiplanar = true, crcb_swap = false. 39 HAL_PIXEL_FORMAT_NV12 = 0x3231564e, 40 // YV12: semiplanar = false, crcb_swap = true. 41 HAL_PIXEL_FORMAT_YV12 = 0x32315659, 42 }; 43 44 // Verify the calculated MD5 of video frame by comparing to |golden|. 45 // It will call MatchHalFormatByGoldenMD5() to find corresponding HAL format 46 // if current color format is YUV_420_FLEXIBLE 47 bool VerifyMD5(const std::string& golden); 48 49 // Write video frame planes to |output_file| as I420 format. 50 bool WriteFrame(std::ofstream* output_file) const; 51 color_format()52 int32_t color_format() const { return color_format_; } 53 54 private: 55 VideoFrame(const uint8_t* data, const Size& coded_size, const Size& visible_size, 56 int32_t color_format); 57 58 // Convert frame data from source |data_| as format |curr_format| to 59 // destination |frame_data_| as I420 and make a copy, with |visible_size_| as 60 // crop window. 61 void CopyAndConvertToI420Frame(int32_t curr_format); 62 63 // Try to match corresponding HAL pixel format by comparing to |golden| MD5. 64 // Return true on found and overwrite |color_format_| to HAL format. 65 bool MatchHalFormatByGoldenMD5(const std::string& golden); 66 67 // Compute and return MD5 for video frame planes as I420 format. 68 std::string ComputeMD5FromFrame() const; 69 70 // Return True if current color format is YUV_420_FLEXIBLE. 71 bool IsFlexibleFormat() const; 72 73 // The frame data returned by decoder. 74 const uint8_t* data_; 75 // The specified coded size from output format. 76 Size coded_size_; 77 // The specified visible size from output format. 78 Size visible_size_; 79 // The specified color format from output format. It may be overwritten by 80 // MatchHalFormatByGoldenMD5(). 81 int32_t color_format_; 82 83 // Converted frame data stored by planes. [0]:Y, [1]:U, [2]:V 84 std::unique_ptr<uint8_t[]> frame_data_[3]; 85 }; 86 87 } // namespace android 88 89 #endif // C2_E2E_TEST_VIDEO_FRAME_H_ 90