1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  * Description: supply cast stream common.
15  * Author: zhangjingnan
16  * Create: 2023-3-11
17  */
18 
19 #ifndef CAST_STREAM_COMMON_H
20 #define CAST_STREAM_COMMON_H
21 
22 namespace OHOS {
23 namespace CastEngine {
24 constexpr int32_t CAST_STREAM_FULL_VOLUME = 100;
25 constexpr int32_t CAST_STREAM_INT_INIT = 0;
26 constexpr int32_t CAST_STREAM_INT_INVALID = -1;
27 constexpr int32_t CAST_STREAM_INT_IGNORE = -1;
28 constexpr int32_t CAST_STREAM_MAX_TIMES = 40;
29 constexpr int32_t CAST_STREAM_WAIT_TIME = 100;
30 constexpr double CAST_STREAM_DOUBLE_INVALID = -1;
31 constexpr int32_t ERR_CODE_PLAY_FAILED = 10003;
32 constexpr int32_t AUTO_POSITION_UPDATE_INTERVAL = 100;
33 constexpr int32_t AUTO_POSITION_SYNC_INTERVAL = 10000;
34 constexpr int32_t POSITION_LAG_MINIMUM = 50;
35 constexpr int32_t POSITION_LAG_MAXIMUM = 150;
36 const std::string PLAYER_ERROR = "PLAYER_ERROR";
37 
38 #define RETURN_IF_PARSE_WRONG(value, data, key, ret, jsonType)            \
39     do {                                                                  \
40         if (!(data).contains(key) || !(data)[key].is_##jsonType()) {      \
41             CLOGE("json object does not contains key:%s", (key).c_str()); \
42             return ret;                                                   \
43         }                                                                 \
44         (value) = (data)[key];                                            \
45     } while (0)
46 
47 #define RET_VOID
48 
49 #define RETURN_FALSE_IF_PARSE_NUMBER_WRONG(value, data, key) RETURN_IF_PARSE_WRONG(value, data, key, false, number)
50 
51 #define RETURN_FALSE_IF_PARSE_STRING_WRONG(value, data, key) RETURN_IF_PARSE_WRONG(value, data, key, false, string)
52 
53 #define RETURN_VOID_IF_PARSE_STRING_WRONG(value, data, key) RETURN_IF_PARSE_WRONG(value, data, key, RET_VOID, string)
54 
55 #define RETURN_FALSE_IF_PARSE_BOOL_WRONG(value, data, key) RETURN_IF_PARSE_WRONG(value, data, key, false, boolean)
56 } // namespace CastEngine
57 } // namespace OHOS
58 #endif // CAST_STREAM_COMMON_H