VideoFormats.h revision 308bcaa44e578279e61be32b572fdb0b11b1e4c7
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(); 7294a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 7394a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber void setResolutionEnabled( 7494a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber ResolutionType type, size_t index, bool enabled = true); 7594a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 7694a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber bool isResolutionEnabled(ResolutionType type, size_t index) const; 7794a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 78308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang void setProfileLevel( 79308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang ResolutionType type, size_t index, 80308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang ProfileType profile, LevelType level); 81308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang 82308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang void getProfileLevel( 83308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang ResolutionType type, size_t index, 84308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang ProfileType *profile, LevelType *level) const; 85308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang 8694a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber static bool GetConfiguration( 8794a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber ResolutionType type, size_t index, 8894a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber size_t *width, size_t *height, size_t *framesPerSecond, 8994a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber bool *interlaced); 9094a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 91308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang static bool GetProfileLevel( 92308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang ProfileType profile, LevelType level, 93308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang unsigned *profileIdc, unsigned *levelIdc, 94308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang unsigned *constraintSet); 95308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang 9694a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber bool parseFormatSpec(const char *spec); 975abf87f9af48149972eeb851ecaea679911da040Andreas Huber AString getFormatSpec(bool forM4Message = false) const; 9894a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 9994a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber static bool PickBestFormat( 10094a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber const VideoFormats &sinkSupported, 10194a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber const VideoFormats &sourceSupported, 10294a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber ResolutionType *chosenType, 103308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang size_t *chosenIndex, 104308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang ProfileType *chosenProfile, 105308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang LevelType *chosenLevel); 10694a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 10794a483bf2bd699275673d9cd57cb125d48572f30Andreas Huberprivate: 108aef5c98cd3f67e0209e1fa28489078e9f40d6f46Chong Zhang bool parseH264Codec(const char *spec); 10994a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber ResolutionType mNativeType; 11094a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber size_t mNativeIndex; 11194a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 11294a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber uint32_t mResolutionEnabled[kNumResolutionTypes]; 113308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang static const config_t mResolutionTable[kNumResolutionTypes][32]; 114308bcaa44e578279e61be32b572fdb0b11b1e4c7Chong Zhang config_t mConfigs[kNumResolutionTypes][32]; 11594a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 11694a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber DISALLOW_EVIL_CONSTRUCTORS(VideoFormats); 11794a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber}; 11894a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 11994a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber} // namespace android 12094a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 12194a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber#endif // VIDEO_FORMATS_H_ 12294a483bf2bd699275673d9cd57cb125d48572f30Andreas Huber 123