| // Copyright 2020 The Chromium OS Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| package encoding |
| |
| import ( |
| "fmt" |
| |
| "chromiumos/tast/local/coords" |
| "chromiumos/tast/local/media/videotype" |
| ) |
| |
| // StreamParams is the parameter for video_encode_accelerator_unittest. |
| type StreamParams struct { |
| // Name is the name of input raw data file. |
| Name string |
| // Size is the width and height of YUV image in the input raw data. |
| Size coords.Size |
| // Bitrate is the requested bitrate in bits per second. VideoEncodeAccelerator is forced to output |
| // encoded video in expected range around the bitrate. |
| Bitrate int |
| // FrameRate is the initial frame rate in the test. This value is optional, and will be set to |
| // 30 if unspecified. |
| FrameRate int |
| // SubseqBitrate is the bitrate to switch to in the middle of the stream in some test cases in |
| // video_encode_accelerator_unittest. This value is optional, and will be set to two times of Bitrate if unspecified. |
| SubseqBitrate int |
| // SubseqFrameRate is the frame rate to switch to in the middle of the stream in some test cases in |
| // video_encode_accelerator_unittest. This value is optional, and will be set to 30 if unspecified. |
| SubseqFrameRate int |
| // Level is the requested output level. This value is optional and currently only used by the H264 codec. The value |
| // should be aligned with the H264LevelIDC enum in https://cs.chromium.org/chromium/src/media/video/h264_parser.h, |
| // as well as level_idc(u8) definition of sequence parameter set data in official H264 spec. |
| Level int |
| } |
| |
| // CreateStreamDataArg creates an argument of video_encode_accelerator_unittest from profile, dataPath and outFile. |
| func CreateStreamDataArg(params StreamParams, profile videotype.CodecProfile, pixelFormat videotype.PixelFormat, dataPath, outFile string) string { |
| const ( |
| defaultFrameRate = 30 |
| defaultSubseqBitrateRatio = 2 |
| ) |
| |
| // Fill default values if they are unsettled. |
| if params.FrameRate == 0 { |
| params.FrameRate = defaultFrameRate |
| } |
| if params.SubseqBitrate == 0 { |
| params.SubseqBitrate = params.Bitrate * defaultSubseqBitrateRatio |
| } |
| if params.SubseqFrameRate == 0 { |
| params.SubseqFrameRate = defaultFrameRate |
| } |
| streamDataArgs := fmt.Sprintf("--test_stream_data=%s:%d:%d:%d:%s:%d:%d:%d:%d:%d", |
| dataPath, params.Size.Width, params.Size.Height, int(profile), outFile, |
| params.Bitrate, params.FrameRate, params.SubseqBitrate, |
| params.SubseqFrameRate, int(pixelFormat)) |
| if params.Level != 0 { |
| streamDataArgs += fmt.Sprintf(":%d", params.Level) |
| } |
| return streamDataArgs |
| } |