1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.media.cts.bitstreams; 18 19 import com.android.tradefed.device.DeviceNotAvailableException; 20 import com.android.tradefed.device.ITestDevice; 21 import com.android.tradefed.log.LogUtil.CLog; 22 import java.util.Collections; 23 import java.util.HashMap; 24 import java.util.LinkedHashSet; 25 import java.util.Map; 26 import java.util.Set; 27 28 /** 29 * Runs a test on target device to query support for bitstreams listed in device side 30 * dynamic configuration file. 31 */ 32 public class SupportedBitstreamsProcessor extends ReportProcessor { 33 34 private final String mPrefix; 35 private final boolean mDebugTargetDevice; 36 private final Set<String> mSupportedBitstreams = new LinkedHashSet<>(); 37 private final Map<String, Map<String, Boolean>> mDecodersForPath = new HashMap<>(); 38 SupportedBitstreamsProcessor()39 public SupportedBitstreamsProcessor() { 40 this("",false); 41 } 42 43 /** 44 * @param prefix only bitstreams whose relative paths start with {@code prefix} 45 * would be processed 46 * @param debugTargetDevice whether to pause {@code device} for debugging 47 */ SupportedBitstreamsProcessor(String prefix, boolean debugTargetDevice)48 public SupportedBitstreamsProcessor(String prefix, boolean debugTargetDevice) { 49 mPrefix = prefix; 50 mDebugTargetDevice = debugTargetDevice; 51 } 52 53 /** 54 * @return paths to bitstreams that are supported on device 55 */ getSupportedBitstreams()56 public Set<String> getSupportedBitstreams() { 57 return mSupportedBitstreams; 58 } 59 60 /** 61 * @return paths to all bitstreams whose relative paths start with <code>prefix</code> 62 */ getBitstreams()63 public Set<String> getBitstreams() { 64 return mDecodersForPath.keySet(); 65 } 66 getDecoderCapabilitiesForPath(String path)67 public Map<String, Boolean> getDecoderCapabilitiesForPath(String path) { 68 if (mDecodersForPath.containsKey(path)) { 69 return mDecodersForPath.get(path); 70 } 71 return Collections.emptyMap(); 72 } 73 74 @Override getArgs()75 Map<String, String> getArgs() { 76 Map<String, String> args = new HashMap<>(); 77 args.put(MediaBitstreams.OPT_BITSTREAMS_PREFIX, mPrefix); 78 args.put(MediaBitstreams.OPT_DEBUG_TARGET_DEVICE, Boolean.toString(mDebugTargetDevice)); 79 return args; 80 } 81 82 @Override process(ITestDevice device, String reportPath)83 void process(ITestDevice device, String reportPath) throws DeviceNotAvailableException { 84 mSupportedBitstreams.clear(); 85 String[] lines = getReportLines(device, reportPath); 86 try { 87 for (int i = 0; i < lines.length;) { 88 String path = lines[i++]; 89 int n = Integer.parseInt(lines[i++]); 90 for (int j = 0; j < n; j++) { 91 String name = lines[i++]; 92 String status = lines[i++]; 93 boolean supported = status.equals("true"); 94 if (supported) { 95 mSupportedBitstreams.add(path); 96 } 97 Map<String, Boolean> decoderCapabilities; 98 if (mDecodersForPath.containsKey(path)) { 99 decoderCapabilities = mDecodersForPath.get(path); 100 } else { 101 mDecodersForPath.put(path, decoderCapabilities = new HashMap<>()); 102 } 103 decoderCapabilities.put(name, supported); 104 } 105 } 106 } catch (Exception e) { 107 CLog.w(e); 108 } 109 } 110 111 } 112