| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-or-later |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * cx2341x - generic code for cx23415/6/8 based devices |
|---|
| 3 | 4 | * |
|---|
| 4 | 5 | * Copyright (C) 2006 Hans Verkuil <hverkuil@xs4all.nl> |
|---|
| 5 | | - * |
|---|
| 6 | | - * This program is free software; you can redistribute it and/or modify |
|---|
| 7 | | - * it under the terms of the GNU General Public License as published by |
|---|
| 8 | | - * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | | - * (at your option) any later version. |
|---|
| 10 | | - * |
|---|
| 11 | | - * This program is distributed in the hope that it will be useful, |
|---|
| 12 | | - * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | | - * GNU General Public License for more details. |
|---|
| 15 | 6 | */ |
|---|
| 16 | 7 | |
|---|
| 17 | 8 | |
|---|
| .. | .. |
|---|
| 569 | 560 | qctrl->step = step; |
|---|
| 570 | 561 | qctrl->default_value = def; |
|---|
| 571 | 562 | qctrl->reserved[0] = qctrl->reserved[1] = 0; |
|---|
| 572 | | - strlcpy(qctrl->name, name, sizeof(qctrl->name)); |
|---|
| 563 | + strscpy(qctrl->name, name, sizeof(qctrl->name)); |
|---|
| 573 | 564 | return 0; |
|---|
| 574 | 565 | |
|---|
| 575 | 566 | default: |
|---|
| .. | .. |
|---|
| 1028 | 1019 | return func(priv, cmd, args, 0, data); |
|---|
| 1029 | 1020 | } |
|---|
| 1030 | 1021 | |
|---|
| 1031 | | -#define NEQ(field) (old->field != new->field) |
|---|
| 1022 | +#define CMP_FIELD(__old, __new, __field) (__old->__field != __new->__field) |
|---|
| 1032 | 1023 | |
|---|
| 1033 | 1024 | int cx2341x_update(void *priv, cx2341x_mbox_func func, |
|---|
| 1034 | 1025 | const struct cx2341x_mpeg_params *old, |
|---|
| .. | .. |
|---|
| 1042 | 1033 | 11, /* VCD */ |
|---|
| 1043 | 1034 | 12, /* SVCD */ |
|---|
| 1044 | 1035 | }; |
|---|
| 1045 | | - |
|---|
| 1046 | | - int err = 0; |
|---|
| 1047 | | - int force = (old == NULL); |
|---|
| 1048 | | - u16 temporal = new->video_temporal_filter; |
|---|
| 1036 | + int err; |
|---|
| 1049 | 1037 | |
|---|
| 1050 | 1038 | cx2341x_api(priv, func, CX2341X_ENC_SET_OUTPUT_PORT, 2, new->port, 0); |
|---|
| 1051 | 1039 | |
|---|
| 1052 | | - if (force || NEQ(is_50hz)) { |
|---|
| 1040 | + if (!old || |
|---|
| 1041 | + CMP_FIELD(old, new, is_50hz)) { |
|---|
| 1053 | 1042 | err = cx2341x_api(priv, func, CX2341X_ENC_SET_FRAME_RATE, 1, |
|---|
| 1054 | 1043 | new->is_50hz); |
|---|
| 1055 | | - if (err) return err; |
|---|
| 1044 | + if (err) |
|---|
| 1045 | + return err; |
|---|
| 1056 | 1046 | } |
|---|
| 1057 | 1047 | |
|---|
| 1058 | | - if (force || NEQ(width) || NEQ(height) || NEQ(video_encoding)) { |
|---|
| 1048 | + if (!old || |
|---|
| 1049 | + CMP_FIELD(old, new, width) || |
|---|
| 1050 | + CMP_FIELD(old, new, height) || |
|---|
| 1051 | + CMP_FIELD(old, new, video_encoding)) { |
|---|
| 1059 | 1052 | u16 w = new->width; |
|---|
| 1060 | 1053 | u16 h = new->height; |
|---|
| 1061 | 1054 | |
|---|
| .. | .. |
|---|
| 1065 | 1058 | } |
|---|
| 1066 | 1059 | err = cx2341x_api(priv, func, CX2341X_ENC_SET_FRAME_SIZE, 2, |
|---|
| 1067 | 1060 | h, w); |
|---|
| 1068 | | - if (err) return err; |
|---|
| 1061 | + if (err) |
|---|
| 1062 | + return err; |
|---|
| 1069 | 1063 | } |
|---|
| 1070 | | - if (force || NEQ(stream_type)) { |
|---|
| 1064 | + if (!old || |
|---|
| 1065 | + CMP_FIELD(old, new, stream_type)) { |
|---|
| 1071 | 1066 | err = cx2341x_api(priv, func, CX2341X_ENC_SET_STREAM_TYPE, 1, |
|---|
| 1072 | 1067 | mpeg_stream_type[new->stream_type]); |
|---|
| 1073 | | - if (err) return err; |
|---|
| 1068 | + if (err) |
|---|
| 1069 | + return err; |
|---|
| 1074 | 1070 | } |
|---|
| 1075 | | - if (force || NEQ(video_aspect)) { |
|---|
| 1071 | + if (!old || |
|---|
| 1072 | + CMP_FIELD(old, new, video_aspect)) { |
|---|
| 1076 | 1073 | err = cx2341x_api(priv, func, CX2341X_ENC_SET_ASPECT_RATIO, 1, |
|---|
| 1077 | 1074 | 1 + new->video_aspect); |
|---|
| 1078 | | - if (err) return err; |
|---|
| 1075 | + if (err) |
|---|
| 1076 | + return err; |
|---|
| 1079 | 1077 | } |
|---|
| 1080 | | - if (force || NEQ(video_b_frames) || NEQ(video_gop_size)) { |
|---|
| 1078 | + if (!old || |
|---|
| 1079 | + CMP_FIELD(old, new, video_b_frames) || |
|---|
| 1080 | + CMP_FIELD(old, new, video_gop_size)) { |
|---|
| 1081 | 1081 | err = cx2341x_api(priv, func, CX2341X_ENC_SET_GOP_PROPERTIES, 2, |
|---|
| 1082 | | - new->video_gop_size, new->video_b_frames + 1); |
|---|
| 1083 | | - if (err) return err; |
|---|
| 1082 | + new->video_gop_size, new->video_b_frames + 1); |
|---|
| 1083 | + if (err) |
|---|
| 1084 | + return err; |
|---|
| 1084 | 1085 | } |
|---|
| 1085 | | - if (force || NEQ(video_gop_closure)) { |
|---|
| 1086 | + if (!old || |
|---|
| 1087 | + CMP_FIELD(old, new, video_gop_closure)) { |
|---|
| 1086 | 1088 | err = cx2341x_api(priv, func, CX2341X_ENC_SET_GOP_CLOSURE, 1, |
|---|
| 1087 | 1089 | new->video_gop_closure); |
|---|
| 1088 | | - if (err) return err; |
|---|
| 1090 | + if (err) |
|---|
| 1091 | + return err; |
|---|
| 1089 | 1092 | } |
|---|
| 1090 | | - if (force || NEQ(audio_properties)) { |
|---|
| 1093 | + if (!old || |
|---|
| 1094 | + CMP_FIELD(old, new, audio_properties)) { |
|---|
| 1091 | 1095 | err = cx2341x_api(priv, func, CX2341X_ENC_SET_AUDIO_PROPERTIES, |
|---|
| 1092 | 1096 | 1, new->audio_properties); |
|---|
| 1093 | | - if (err) return err; |
|---|
| 1097 | + if (err) |
|---|
| 1098 | + return err; |
|---|
| 1094 | 1099 | } |
|---|
| 1095 | | - if (force || NEQ(audio_mute)) { |
|---|
| 1100 | + if (!old || |
|---|
| 1101 | + CMP_FIELD(old, new, audio_mute)) { |
|---|
| 1096 | 1102 | err = cx2341x_api(priv, func, CX2341X_ENC_MUTE_AUDIO, 1, |
|---|
| 1097 | 1103 | new->audio_mute); |
|---|
| 1098 | | - if (err) return err; |
|---|
| 1104 | + if (err) |
|---|
| 1105 | + return err; |
|---|
| 1099 | 1106 | } |
|---|
| 1100 | | - if (force || NEQ(video_bitrate_mode) || NEQ(video_bitrate) || |
|---|
| 1101 | | - NEQ(video_bitrate_peak)) { |
|---|
| 1107 | + if (!old || |
|---|
| 1108 | + CMP_FIELD(old, new, video_bitrate_mode) || |
|---|
| 1109 | + CMP_FIELD(old, new, video_bitrate) || |
|---|
| 1110 | + CMP_FIELD(old, new, video_bitrate_peak)) { |
|---|
| 1102 | 1111 | err = cx2341x_api(priv, func, CX2341X_ENC_SET_BIT_RATE, 5, |
|---|
| 1103 | | - new->video_bitrate_mode, new->video_bitrate, |
|---|
| 1104 | | - new->video_bitrate_peak / 400, 0, 0); |
|---|
| 1105 | | - if (err) return err; |
|---|
| 1112 | + new->video_bitrate_mode, new->video_bitrate, |
|---|
| 1113 | + new->video_bitrate_peak / 400, 0, 0); |
|---|
| 1114 | + if (err) |
|---|
| 1115 | + return err; |
|---|
| 1106 | 1116 | } |
|---|
| 1107 | | - if (force || NEQ(video_spatial_filter_mode) || |
|---|
| 1108 | | - NEQ(video_temporal_filter_mode) || |
|---|
| 1109 | | - NEQ(video_median_filter_type)) { |
|---|
| 1117 | + if (!old || |
|---|
| 1118 | + CMP_FIELD(old, new, video_spatial_filter_mode) || |
|---|
| 1119 | + CMP_FIELD(old, new, video_temporal_filter_mode) || |
|---|
| 1120 | + CMP_FIELD(old, new, video_median_filter_type)) { |
|---|
| 1110 | 1121 | err = cx2341x_api(priv, func, CX2341X_ENC_SET_DNR_FILTER_MODE, |
|---|
| 1111 | | - 2, new->video_spatial_filter_mode | |
|---|
| 1122 | + 2, |
|---|
| 1123 | + new->video_spatial_filter_mode | |
|---|
| 1112 | 1124 | (new->video_temporal_filter_mode << 1), |
|---|
| 1113 | | - new->video_median_filter_type); |
|---|
| 1114 | | - if (err) return err; |
|---|
| 1125 | + new->video_median_filter_type); |
|---|
| 1126 | + if (err) |
|---|
| 1127 | + return err; |
|---|
| 1115 | 1128 | } |
|---|
| 1116 | | - if (force || NEQ(video_luma_median_filter_bottom) || |
|---|
| 1117 | | - NEQ(video_luma_median_filter_top) || |
|---|
| 1118 | | - NEQ(video_chroma_median_filter_bottom) || |
|---|
| 1119 | | - NEQ(video_chroma_median_filter_top)) { |
|---|
| 1129 | + if (!old || |
|---|
| 1130 | + CMP_FIELD(old, new, video_luma_median_filter_bottom) || |
|---|
| 1131 | + CMP_FIELD(old, new, video_luma_median_filter_top) || |
|---|
| 1132 | + CMP_FIELD(old, new, video_chroma_median_filter_bottom) || |
|---|
| 1133 | + CMP_FIELD(old, new, video_chroma_median_filter_top)) { |
|---|
| 1120 | 1134 | err = cx2341x_api(priv, func, CX2341X_ENC_SET_CORING_LEVELS, 4, |
|---|
| 1121 | | - new->video_luma_median_filter_bottom, |
|---|
| 1122 | | - new->video_luma_median_filter_top, |
|---|
| 1123 | | - new->video_chroma_median_filter_bottom, |
|---|
| 1124 | | - new->video_chroma_median_filter_top); |
|---|
| 1125 | | - if (err) return err; |
|---|
| 1135 | + new->video_luma_median_filter_bottom, |
|---|
| 1136 | + new->video_luma_median_filter_top, |
|---|
| 1137 | + new->video_chroma_median_filter_bottom, |
|---|
| 1138 | + new->video_chroma_median_filter_top); |
|---|
| 1139 | + if (err) |
|---|
| 1140 | + return err; |
|---|
| 1126 | 1141 | } |
|---|
| 1127 | | - if (force || NEQ(video_luma_spatial_filter_type) || |
|---|
| 1128 | | - NEQ(video_chroma_spatial_filter_type)) { |
|---|
| 1142 | + if (!old || |
|---|
| 1143 | + CMP_FIELD(old, new, video_luma_spatial_filter_type) || |
|---|
| 1144 | + CMP_FIELD(old, new, video_chroma_spatial_filter_type)) { |
|---|
| 1129 | 1145 | err = cx2341x_api(priv, func, |
|---|
| 1130 | 1146 | CX2341X_ENC_SET_SPATIAL_FILTER_TYPE, |
|---|
| 1131 | 1147 | 2, new->video_luma_spatial_filter_type, |
|---|
| 1132 | 1148 | new->video_chroma_spatial_filter_type); |
|---|
| 1133 | | - if (err) return err; |
|---|
| 1149 | + if (err) |
|---|
| 1150 | + return err; |
|---|
| 1134 | 1151 | } |
|---|
| 1135 | | - if (force || NEQ(video_spatial_filter) || |
|---|
| 1136 | | - old->video_temporal_filter != temporal) { |
|---|
| 1152 | + if (!old || |
|---|
| 1153 | + CMP_FIELD(old, new, video_spatial_filter) || |
|---|
| 1154 | + CMP_FIELD(old, new, video_temporal_filter)) { |
|---|
| 1137 | 1155 | err = cx2341x_api(priv, func, CX2341X_ENC_SET_DNR_FILTER_PROPS, |
|---|
| 1138 | | - 2, new->video_spatial_filter, temporal); |
|---|
| 1139 | | - if (err) return err; |
|---|
| 1156 | + 2, new->video_spatial_filter, |
|---|
| 1157 | + new->video_temporal_filter); |
|---|
| 1158 | + if (err) |
|---|
| 1159 | + return err; |
|---|
| 1140 | 1160 | } |
|---|
| 1141 | | - if (force || NEQ(video_temporal_decimation)) { |
|---|
| 1161 | + if (!old || |
|---|
| 1162 | + CMP_FIELD(old, new, video_temporal_decimation)) { |
|---|
| 1142 | 1163 | err = cx2341x_api(priv, func, CX2341X_ENC_SET_FRAME_DROP_RATE, |
|---|
| 1143 | 1164 | 1, new->video_temporal_decimation); |
|---|
| 1144 | | - if (err) return err; |
|---|
| 1165 | + if (err) |
|---|
| 1166 | + return err; |
|---|
| 1145 | 1167 | } |
|---|
| 1146 | | - if (force || NEQ(video_mute) || |
|---|
| 1147 | | - (new->video_mute && NEQ(video_mute_yuv))) { |
|---|
| 1168 | + if (!old || |
|---|
| 1169 | + CMP_FIELD(old, new, video_mute) || |
|---|
| 1170 | + (new->video_mute && CMP_FIELD(old, new, video_mute_yuv))) { |
|---|
| 1148 | 1171 | err = cx2341x_api(priv, func, CX2341X_ENC_MUTE_VIDEO, 1, |
|---|
| 1149 | | - new->video_mute | (new->video_mute_yuv << 8)); |
|---|
| 1150 | | - if (err) return err; |
|---|
| 1172 | + new->video_mute | (new->video_mute_yuv << 8)); |
|---|
| 1173 | + if (err) |
|---|
| 1174 | + return err; |
|---|
| 1151 | 1175 | } |
|---|
| 1152 | | - if (force || NEQ(stream_insert_nav_packets)) { |
|---|
| 1176 | + if (!old || |
|---|
| 1177 | + CMP_FIELD(old, new, stream_insert_nav_packets)) { |
|---|
| 1153 | 1178 | err = cx2341x_api(priv, func, CX2341X_ENC_MISC, 2, |
|---|
| 1154 | | - 7, new->stream_insert_nav_packets); |
|---|
| 1155 | | - if (err) return err; |
|---|
| 1179 | + 7, new->stream_insert_nav_packets); |
|---|
| 1180 | + if (err) |
|---|
| 1181 | + return err; |
|---|
| 1156 | 1182 | } |
|---|
| 1157 | 1183 | return 0; |
|---|
| 1158 | 1184 | } |
|---|