1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
// Take a look at the license at the top of the repository in the LICENSE file.

use glib::{
    prelude::*,
    translate::{from_glib, ToGlibPtr},
    FlagsClass,
};
use gst::bitflags_serde_impl;

bitflags_serde_impl!(crate::NavigationModifierType, "v1_22");
bitflags_serde_impl!(crate::VideoBufferFlags);
bitflags_serde_impl!(crate::VideoChromaSite);
bitflags_serde_impl!(crate::VideoCodecFrameFlags, "v1_20");
bitflags_serde_impl!(crate::VideoDecoderRequestSyncPointFlags, "v1_20");
bitflags_serde_impl!(crate::VideoFlags);
bitflags_serde_impl!(crate::VideoFormatFlags);
bitflags_serde_impl!(crate::VideoFrameFlags);
bitflags_serde_impl!(crate::VideoMultiviewFlags);
bitflags_serde_impl!(crate::VideoOverlayFormatFlags, "v1_16");
bitflags_serde_impl!(crate::VideoPackFlags);
bitflags_serde_impl!(crate::VideoTimeCodeFlags, "v1_18");

#[cfg(test)]
mod tests {
    macro_rules! check_serialize {
        ($flags:expr, $expected:expr) => {
            let actual = serde_json::to_string(&$flags).unwrap();
            assert_eq!(actual, $expected);
        };
    }

    macro_rules! check_deserialize {
        ($ty:ty, $expected:expr, $json:expr) => {
            let actual: $ty = serde_json::from_str(&$json).unwrap();
            assert_eq!(actual, $expected);
        };
    }

    macro_rules! check_roundtrip {
        ($ty:ty, $flags:expr) => {
            let json = serde_json::to_string(&$flags).unwrap();
            let deserialized: $ty = serde_json::from_str(&json).unwrap();
            assert_eq!(deserialized, $flags);
        };
    }

    #[test]
    fn test_serialize() {
        gst::init().unwrap();

        #[cfg(feature = "v1_22")]
        check_serialize!(
            crate::NavigationModifierType::all(),
            concat!(
                "\"shift-mask+lock-mask+control-mask+mod1-mask+mod2-mask+mod3-mask",
                "+mod4-mask+mod5-mask+button1-mask+button2-mask+button3-mask",
                "+button4-mask+button5-mask+super-mask+hyper-mask+meta-mask\""
            )
        );
        #[cfg(feature = "v1_18")]
        check_serialize!(
            crate::VideoBufferFlags::all(),
            "\"interlaced+tff+rff+onefield+multiple-view+first-in-bundle+marker\""
        );
        check_serialize!(
            crate::VideoChromaSite::all(),
            "\"none+h-cosited+v-cosited+alt-line\""
        );
        #[cfg(feature = "v1_20")]
        check_serialize!(
            crate::VideoCodecFrameFlags::all(),
            "\"decode-only+sync-point+force-keyframe+force-keyframe-headers+corrupted\""
        );
        #[cfg(feature = "v1_20")]
        check_serialize!(
            crate::VideoDecoderRequestSyncPointFlags::all(),
            "\"discard-input+corrupt-output\""
        );
        check_serialize!(
            crate::VideoFlags::all(),
            "\"variable-fps+premultiplied-alpha\""
        );
        #[cfg(feature = "v1_22")]
        check_serialize!(
            crate::VideoFormatFlags::all(),
            "\"yuv+rgb+gray+alpha+le+palette+complex+unpack+tiled+subtiles\""
        );
        check_serialize!(
            crate::VideoFrameFlags::all(),
            "\"interlaced+tff+rff+onefield+multiple-view+first-in-bundle\""
        );
        check_serialize!(
            crate::VideoMultiviewFlags::all(),
            concat!(
                "\"right-view-first+left-flipped+left-flopped+right-flipped",
                "+right-flopped+half-aspect+mixed-mono\""
            )
        );
        #[cfg(feature = "v1_16")]
        check_serialize!(
            crate::VideoOverlayFormatFlags::all(),
            "\"premultiplied-alpha+global-alpha\""
        );
        check_serialize!(
            crate::VideoPackFlags::all(),
            "\"truncate-range+interlaced\""
        );
        #[cfg(feature = "v1_18")]
        check_serialize!(
            crate::VideoTimeCodeFlags::all(),
            "\"drop-frame+interlaced\""
        );
    }

    #[test]
    fn test_deserialize() {
        gst::init().unwrap();

        #[cfg(feature = "v1_22")]
        check_deserialize!(
            crate::NavigationModifierType,
            crate::NavigationModifierType::all(),
            concat!(
                "\"shift-mask+lock-mask+control-mask+mod1-mask+mod2-mask",
                "+mod3-mask+mod4-mask+mod5-mask+button1-mask",
                "+button2-mask+button3-mask+button4-mask+button5-mask",
                "+super-mask+hyper-mask+meta-mask\""
            )
        );
        #[cfg(feature = "v1_18")]
        check_deserialize!(
            crate::VideoBufferFlags,
            crate::VideoBufferFlags::all(),
            "\"interlaced+tff+rff+onefield+multiple-view+first-in-bundle+marker\""
        );
        check_deserialize!(
            crate::VideoChromaSite,
            crate::VideoChromaSite::all(),
            "\"none+h-cosited+v-cosited+alt-line\""
        );
        #[cfg(feature = "v1_20")]
        check_deserialize!(
            crate::VideoCodecFrameFlags,
            crate::VideoCodecFrameFlags::all(),
            "\"decode-only+sync-point+force-keyframe+force-keyframe-headers+corrupted\""
        );
        #[cfg(feature = "v1_20")]
        check_deserialize!(
            crate::VideoDecoderRequestSyncPointFlags,
            crate::VideoDecoderRequestSyncPointFlags::all(),
            "\"discard-input+corrupt-output\""
        );
        check_deserialize!(
            crate::VideoFlags,
            crate::VideoFlags::all(),
            "\"variable-fps+premultiplied-alpha\""
        );
        #[cfg(feature = "v1_22")]
        check_deserialize!(
            crate::VideoFormatFlags,
            crate::VideoFormatFlags::all(),
            "\"yuv+rgb+gray+alpha+le+palette+complex+unpack+tiled+subtiles\""
        );
        check_deserialize!(
            crate::VideoFrameFlags,
            crate::VideoFrameFlags::all(),
            "\"interlaced+tff+rff+onefield+multiple-view+first-in-bundle\""
        );
        check_deserialize!(
            crate::VideoMultiviewFlags,
            crate::VideoMultiviewFlags::all(),
            concat!(
                "\"right-view-first+left-flipped+left-flopped+right-flipped",
                "+right-flopped+half-aspect+mixed-mono\""
            )
        );
        #[cfg(feature = "v1_16")]
        check_deserialize!(
            crate::VideoOverlayFormatFlags,
            crate::VideoOverlayFormatFlags::all(),
            "\"premultiplied-alpha+global-alpha\""
        );
        check_deserialize!(
            crate::VideoPackFlags,
            crate::VideoPackFlags::all(),
            "\"truncate-range+interlaced\""
        );
        #[cfg(feature = "v1_18")]
        check_deserialize!(
            crate::VideoTimeCodeFlags,
            crate::VideoTimeCodeFlags::all(),
            "\"drop-frame+interlaced\""
        );
    }

    #[test]
    fn test_serde_roundtrip() {
        gst::init().unwrap();

        #[cfg(feature = "v1_22")]
        check_roundtrip!(
            crate::NavigationModifierType,
            crate::NavigationModifierType::all()
        );
        #[cfg(feature = "v1_18")]
        check_roundtrip!(crate::VideoBufferFlags, crate::VideoBufferFlags::all());
        check_roundtrip!(crate::VideoChromaSite, crate::VideoChromaSite::all());
        #[cfg(feature = "v1_20")]
        check_roundtrip!(
            crate::VideoCodecFrameFlags,
            crate::VideoCodecFrameFlags::all()
        );
        #[cfg(feature = "v1_20")]
        check_roundtrip!(
            crate::VideoDecoderRequestSyncPointFlags,
            crate::VideoDecoderRequestSyncPointFlags::all()
        );
        check_roundtrip!(crate::VideoFlags, crate::VideoFlags::all());
        #[cfg(feature = "v1_22")]
        check_roundtrip!(crate::VideoFormatFlags, crate::VideoFormatFlags::all());
        check_roundtrip!(crate::VideoFrameFlags, crate::VideoFrameFlags::all());
        check_roundtrip!(
            crate::VideoMultiviewFlags,
            crate::VideoMultiviewFlags::all()
        );
        #[cfg(feature = "v1_16")]
        check_roundtrip!(
            crate::VideoOverlayFormatFlags,
            crate::VideoOverlayFormatFlags::all()
        );
        check_roundtrip!(crate::VideoPackFlags, crate::VideoPackFlags::all());
        #[cfg(feature = "v1_18")]
        check_roundtrip!(crate::VideoTimeCodeFlags, crate::VideoTimeCodeFlags::all());
    }
}