1 /* 2 * Copyright 2013, 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 #ifndef VIDEO_FORMATS_H_ 18 19 #define VIDEO_FORMATS_H_ 20 21 #include <media/stagefright/foundation/ABase.h> 22 23 #include <stdint.h> 24 25 namespace android { 26 27 struct AString; 28 29 // This class encapsulates that video resolution capabilities of a wfd source 30 // or sink as outlined in the wfd specs. Currently three sets of resolutions 31 // are specified, each of which supports up to 32 resolutions. 32 // In addition to its capabilities each sink/source also publishes its 33 // "native" resolution, presumably one that is preferred among all others 34 // because it wouldn't require any scaling and directly corresponds to the 35 // display capabilities/pixels. 36 struct VideoFormats { 37 VideoFormats(); 38 39 struct config_t { 40 size_t width, height, framesPerSecond; 41 bool interlaced; 42 unsigned char profile, level; 43 }; 44 45 enum ProfileType { 46 PROFILE_CBP = 0, 47 PROFILE_CHP, 48 kNumProfileTypes, 49 }; 50 51 enum LevelType { 52 LEVEL_31 = 0, 53 LEVEL_32, 54 LEVEL_40, 55 LEVEL_41, 56 LEVEL_42, 57 kNumLevelTypes, 58 }; 59 60 enum ResolutionType { 61 RESOLUTION_CEA, 62 RESOLUTION_VESA, 63 RESOLUTION_HH, 64 kNumResolutionTypes, 65 }; 66 67 void setNativeResolution(ResolutionType type, size_t index); 68 void getNativeResolution(ResolutionType *type, size_t *index) const; 69 70 void disableAll(); 71 void enableAll(); 72 void enableResolutionUpto( 73 ResolutionType type, size_t index, 74 ProfileType profile, LevelType level); 75 76 void setResolutionEnabled( 77 ResolutionType type, size_t index, bool enabled = true); 78 79 bool isResolutionEnabled(ResolutionType type, size_t index) const; 80 81 void setProfileLevel( 82 ResolutionType type, size_t index, 83 ProfileType profile, LevelType level); 84 85 void getProfileLevel( 86 ResolutionType type, size_t index, 87 ProfileType *profile, LevelType *level) const; 88 89 static bool GetConfiguration( 90 ResolutionType type, size_t index, 91 size_t *width, size_t *height, size_t *framesPerSecond, 92 bool *interlaced); 93 94 static bool GetProfileLevel( 95 ProfileType profile, LevelType level, 96 unsigned *profileIdc, unsigned *levelIdc, 97 unsigned *constraintSet); 98 99 bool parseFormatSpec(const char *spec); 100 AString getFormatSpec(bool forM4Message = false) const; 101 102 static bool PickBestFormat( 103 const VideoFormats &sinkSupported, 104 const VideoFormats &sourceSupported, 105 ResolutionType *chosenType, 106 size_t *chosenIndex, 107 ProfileType *chosenProfile, 108 LevelType *chosenLevel); 109 110 private: 111 bool parseH264Codec(const char *spec); 112 ResolutionType mNativeType; 113 size_t mNativeIndex; 114 115 uint32_t mResolutionEnabled[kNumResolutionTypes]; 116 static const config_t mResolutionTable[kNumResolutionTypes][32]; 117 config_t mConfigs[kNumResolutionTypes][32]; 118 119 DISALLOW_EVIL_CONSTRUCTORS(VideoFormats); 120 }; 121 122 } // namespace android 123 124 #endif // VIDEO_FORMATS_H_ 125 126