| // Copyright 2021 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 cca |
| |
| import ( |
| "os" |
| |
| "github.com/abema/go-mp4" |
| |
| "chromiumos/tast/errors" |
| ) |
| |
| // CheckVideoProfile checks profile of video file recorded by CCA. |
| func CheckVideoProfile(path string, profile Profile) error { |
| videoAVCConfigure := func(path string) (*mp4.AVCDecoderConfiguration, error) { |
| file, err := os.Open(path) |
| if err != nil { |
| return nil, errors.Wrapf(err, "failed to open video file %v", path) |
| } |
| defer file.Close() |
| boxes, err := mp4.ExtractBoxWithPayload( |
| file, nil, |
| mp4.BoxPath{ |
| mp4.BoxTypeMoov(), |
| mp4.BoxTypeTrak(), |
| mp4.BoxTypeMdia(), |
| mp4.BoxTypeMinf(), |
| mp4.BoxTypeStbl(), |
| mp4.BoxTypeStsd(), |
| mp4.StrToBoxType("avc1"), |
| mp4.StrToBoxType("avcC"), |
| }) |
| if err != nil { |
| return nil, err |
| } |
| if len(boxes) != 1 { |
| return nil, errors.Errorf("mp4 file %v has %v avcC box(es), want 1", path, len(boxes)) |
| } |
| return boxes[0].Payload.(*mp4.AVCDecoderConfiguration), nil |
| } |
| |
| config, err := videoAVCConfigure(path) |
| if err != nil { |
| return errors.Wrap(err, "failed to get videoAVCConfigure from result video") |
| } |
| if int(config.Profile) != int(profile.Value) { |
| return errors.Errorf("mismatch video profile, got %v; want %v", config.Profile, profile.Value) |
| } |
| return nil |
| } |