| 1 | /* |
| 2 | * Copyright (C) 2018 Apple Inc. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
| 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
| 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
| 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
| 26 | #pragma once |
| 27 | |
| 28 | #if ENABLE(MEDIA_STREAM) |
| 29 | |
| 30 | #include "ImageBuffer.h" |
| 31 | #include "MediaSample.h" |
| 32 | #include "RealtimeMediaSource.h" |
| 33 | #include <wtf/Lock.h> |
| 34 | #include <wtf/RunLoop.h> |
| 35 | |
| 36 | namespace WebCore { |
| 37 | |
| 38 | struct FrameRateRange { |
| 39 | double minimum; |
| 40 | double maximum; |
| 41 | |
| 42 | template<class Encoder> void encode(Encoder&) const; |
| 43 | template<class Decoder> static Optional<FrameRateRange> decode(Decoder&); |
| 44 | }; |
| 45 | |
| 46 | template<class Encoder> |
| 47 | void FrameRateRange::encode(Encoder& encoder) const |
| 48 | { |
| 49 | encoder << minimum; |
| 50 | encoder << maximum; |
| 51 | } |
| 52 | |
| 53 | template <class Decoder> |
| 54 | Optional<FrameRateRange> FrameRateRange::decode(Decoder& decoder) |
| 55 | { |
| 56 | Optional<double> minimum; |
| 57 | decoder >> minimum; |
| 58 | if (!minimum) |
| 59 | return WTF::nullopt; |
| 60 | |
| 61 | Optional<double> maximum; |
| 62 | decoder >> maximum; |
| 63 | if (!maximum) |
| 64 | return WTF::nullopt; |
| 65 | |
| 66 | return FrameRateRange { *minimum, *maximum }; |
| 67 | } |
| 68 | |
| 69 | struct VideoPresetData { |
| 70 | IntSize size; |
| 71 | Vector<FrameRateRange> frameRateRanges; |
| 72 | |
| 73 | template<class Encoder> void encode(Encoder&) const; |
| 74 | template<class Decoder> static Optional<VideoPresetData> decode(Decoder&); |
| 75 | }; |
| 76 | |
| 77 | template<class Encoder> |
| 78 | void VideoPresetData::encode(Encoder& encoder) const |
| 79 | { |
| 80 | encoder << size; |
| 81 | encoder << frameRateRanges; |
| 82 | } |
| 83 | |
| 84 | template <class Decoder> |
| 85 | Optional<VideoPresetData> VideoPresetData::decode(Decoder& decoder) |
| 86 | { |
| 87 | Optional<IntSize> size; |
| 88 | decoder >> size; |
| 89 | if (!size) |
| 90 | return WTF::nullopt; |
| 91 | |
| 92 | Optional<Vector<FrameRateRange>> frameRateRanges; |
| 93 | decoder >> frameRateRanges; |
| 94 | if (!frameRateRanges) |
| 95 | return WTF::nullopt; |
| 96 | |
| 97 | return VideoPresetData { *size, *frameRateRanges }; |
| 98 | } |
| 99 | |
| 100 | class VideoPreset : public RefCounted<VideoPreset> { |
| 101 | public: |
| 102 | static Ref<VideoPreset> create(VideoPresetData&& data) |
| 103 | { |
| 104 | return adoptRef(*new VideoPreset(data.size, WTFMove(data.frameRateRanges), Base)); |
| 105 | } |
| 106 | |
| 107 | enum VideoPresetType { |
| 108 | Base, |
| 109 | AVCapture, |
| 110 | GStreamer |
| 111 | }; |
| 112 | |
| 113 | IntSize size; |
| 114 | Vector<FrameRateRange> frameRateRanges; |
| 115 | VideoPresetType type; |
| 116 | |
| 117 | protected: |
| 118 | VideoPreset(IntSize size, Vector<FrameRateRange>&& frameRateRanges, VideoPresetType type) |
| 119 | : size(size) |
| 120 | , frameRateRanges(WTFMove(frameRateRanges)) |
| 121 | , type(type) |
| 122 | { |
| 123 | } |
| 124 | }; |
| 125 | |
| 126 | } // namespace WebCore |
| 127 | |
| 128 | SPECIALIZE_TYPE_TRAITS_BEGIN(WebCore::VideoPreset) |
| 129 | static bool isType(const WebCore::VideoPreset& preset) { return preset.type == WebCore::VideoPreset::VideoPresetType::Base; } |
| 130 | SPECIALIZE_TYPE_TRAITS_END() |
| 131 | |
| 132 | #endif // ENABLE(MEDIA_STREAM) |
| 133 | |
| 134 | |