194a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber/* 294a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber * Copyright 2013, The Android Open Source Project 394a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber * 494a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber * Licensed under the Apache License, Version 2.0 (the "License"); 594a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber * you may not use this file except in compliance with the License. 694a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber * You may obtain a copy of the License at 794a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber * 894a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber * http://www.apache.org/licenses/LICENSE-2.0 994a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber * 1094a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber * Unless required by applicable law or agreed to in writing, software 1194a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber * distributed under the License is distributed on an "AS IS" BASIS, 1294a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1394a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber * See the License for the specific language governing permissions and 1494a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber * limitations under the License. 1594a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber */ 1694a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 1794a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber#ifndef VIDEO_FORMATS_H_ 1894a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 1994a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber#define VIDEO_FORMATS_H_ 2094a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 2194a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber#include <media/stagefright/foundation/ABase.h> 2294a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 2394a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber#include <stdint.h> 2494a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 2594a483bf2bd699275673d9cd57cb125d48572f30Andreas Hubernamespace android { 2694a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 2794a483bf2bd699275673d9cd57cb125d48572f30Andreas Huberstruct AString; 2894a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 2994a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber// This class encapsulates that video resolution capabilities of a wfd source 3094a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber// or sink as outlined in the wfd specs. Currently three sets of resolutions 3194a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber// are specified, each of which supports up to 32 resolutions. 3294a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber// In addition to its capabilities each sink/source also publishes its 3394a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber// "native" resolution, presumably one that is preferred among all others 3494a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber// because it wouldn't require any scaling and directly corresponds to the 3594a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber// display capabilities/pixels. 3694a483bf2bd699275673d9cd57cb125d48572f30Andreas Huberstruct VideoFormats { 3794a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber VideoFormats(); 3894a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 39aef5c98cd3f67e0209e1fa28489078e9f40d6f46Chong Zhang struct config_t { 40aef5c98cd3f67e0209e1fa28489078e9f40d6f46Chong Zhang size_t width, height, framesPerSecond; 41aef5c98cd3f67e0209e1fa28489078e9f40d6f46Chong Zhang bool interlaced; 42aef5c98cd3f67e0209e1fa28489078e9f40d6f46Chong Zhang unsigned char profile, level; 43aef5c98cd3f67e0209e1fa28489078e9f40d6f46Chong Zhang }; 44aef5c98cd3f67e0209e1fa28489078e9f40d6f46Chong Zhang 45aef5c98cd3f67e0209e1fa28489078e9f40d6f46Chong Zhang enum ProfileType { 46aef5c98cd3f67e0209e1fa28489078e9f40d6f46Chong Zhang PROFILE_CBP = 0, 47aef5c98cd3f67e0209e1fa28489078e9f40d6f46Chong Zhang PROFILE_CHP, 48aef5c98cd3f67e0209e1fa28489078e9f40d6f46Chong Zhang kNumProfileTypes, 49aef5c98cd3f67e0209e1fa28489078e9f40d6f46Chong Zhang }; 50aef5c98cd3f67e0209e1fa28489078e9f40d6f46Chong Zhang 51aef5c98cd3f67e0209e1fa28489078e9f40d6f46Chong Zhang enum LevelType { 52aef5c98cd3f67e0209e1fa28489078e9f40d6f46Chong Zhang LEVEL_31 = 0, 53aef5c98cd3f67e0209e1fa28489078e9f40d6f46Chong Zhang LEVEL_32, 54aef5c98cd3f67e0209e1fa28489078e9f40d6f46Chong Zhang LEVEL_40, 55aef5c98cd3f67e0209e1fa28489078e9f40d6f46Chong Zhang LEVEL_41, 56aef5c98cd3f67e0209e1fa28489078e9f40d6f46Chong Zhang LEVEL_42, 57aef5c98cd3f67e0209e1fa28489078e9f40d6f46Chong Zhang kNumLevelTypes, 58aef5c98cd3f67e0209e1fa28489078e9f40d6f46Chong Zhang }; 59aef5c98cd3f67e0209e1fa28489078e9f40d6f46Chong Zhang 6094a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber enum ResolutionType { 6194a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber RESOLUTION_CEA, 6294a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber RESOLUTION_VESA, 6394a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber RESOLUTION_HH, 6494a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber kNumResolutionTypes, 6594a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber }; 6694a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 6794a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber void setNativeResolution(ResolutionType type, size_t index); 6894a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber void getNativeResolution(ResolutionType *type, size_t *index) const; 6994a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 7094a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber void disableAll(); 7194a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber void enableAll(); 721ad3eb9441eb509c792c61aa0181b0e74dbe9984Chong Zhang void enableResolutionUpto( 731ad3eb9441eb509c792c61aa0181b0e74dbe9984Chong Zhang ResolutionType type, size_t index, 741ad3eb9441eb509c792c61aa0181b0e74dbe9984Chong Zhang ProfileType profile, LevelType level); 7594a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 7694a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber void setResolutionEnabled( 7794a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber ResolutionType type, size_t index, bool enabled = true); 7894a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 7994a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber bool isResolutionEnabled(ResolutionType type, size_t index) const; 8094a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 81308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang void setProfileLevel( 82308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang ResolutionType type, size_t index, 83308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang ProfileType profile, LevelType level); 84308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang 85308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang void getProfileLevel( 86308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang ResolutionType type, size_t index, 87308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang ProfileType *profile, LevelType *level) const; 88308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang 8994a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber static bool GetConfiguration( 9094a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber ResolutionType type, size_t index, 9194a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber size_t *width, size_t *height, size_t *framesPerSecond, 9294a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber bool *interlaced); 9394a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 94308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang static bool GetProfileLevel( 95308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang ProfileType profile, LevelType level, 96308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang unsigned *profileIdc, unsigned *levelIdc, 97308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang unsigned *constraintSet); 98308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang 9994a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber bool parseFormatSpec(const char *spec); 1005abf87f9af48149972eeb851ecaea679911da040Andreas Huber AString getFormatSpec(bool forM4Message = false) const; 10194a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 10294a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber static bool PickBestFormat( 10394a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber const VideoFormats &sinkSupported, 10494a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber const VideoFormats &sourceSupported, 10594a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber ResolutionType *chosenType, 106308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang size_t *chosenIndex, 107308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang ProfileType *chosenProfile, 108308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang LevelType *chosenLevel); 10994a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 11094a483bf2bd699275673d9cd57cb125d48572f30Andreas Huberprivate: 111aef5c98cd3f67e0209e1fa28489078e9f40d6f46Chong Zhang bool parseH264Codec(const char *spec); 11294a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber ResolutionType mNativeType; 11394a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber size_t mNativeIndex; 11494a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 11594a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber uint32_t mResolutionEnabled[kNumResolutionTypes]; 116308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang static const config_t mResolutionTable[kNumResolutionTypes][32]; 117308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang config_t mConfigs[kNumResolutionTypes][32]; 11894a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 11994a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber DISALLOW_EVIL_CONSTRUCTORS(VideoFormats); 12094a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber}; 12194a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 12294a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber} // namespace android 12394a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 12494a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber#endif // VIDEO_FORMATS_H_ 12594a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 126