VideoFormats.h revision aef5c98cd3f67e0209e1fa28489078e9f40d6f46
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
25namespace android {
26
27struct 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.
36struct 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
73    void setResolutionEnabled(
74            ResolutionType type, size_t index, bool enabled = true);
75
76    bool isResolutionEnabled(ResolutionType type, size_t index) const;
77
78    static bool GetConfiguration(
79            ResolutionType type, size_t index,
80            size_t *width, size_t *height, size_t *framesPerSecond,
81            bool *interlaced);
82
83    bool parseFormatSpec(const char *spec);
84    AString getFormatSpec(bool forM4Message = false) const;
85
86    static bool PickBestFormat(
87            const VideoFormats &sinkSupported,
88            const VideoFormats &sourceSupported,
89            ResolutionType *chosenType,
90            size_t *chosenIndex);
91
92private:
93    bool parseH264Codec(const char *spec);
94    ResolutionType mNativeType;
95    size_t mNativeIndex;
96
97    uint32_t mResolutionEnabled[kNumResolutionTypes];
98    static config_t mConfigs[kNumResolutionTypes][32];
99
100    DISALLOW_EVIL_CONSTRUCTORS(VideoFormats);
101};
102
103}  // namespace android
104
105#endif  // VIDEO_FORMATS_H_
106
107