@@ -93,13 +93,17 @@ namespace winrt::ReactNativeCameraCPP {
9393 auto titleString = titleValue.String ();
9494 props.Title (winrt::to_hstring (titleString));
9595 }
96+ else
97+ {
98+ throw winrt::hresult_invalid_argument ();
99+ }
96100 co_await props.SavePropertiesAsync ();
97101 }
98102 }
99103
100104 // RNW has a bug where the numeric value is set as int in debug but double in release
101105 // ToDo: remove this function once bug https://github.com/microsoft/react-native-windows/issues/4225 is fixed.
102- bool ReactCameraView::GetNumericValue (std::map<std::wstring, JSValue> const & options, const std::wstring key, int &value)
106+ bool ReactCameraView::TryGetalueAsInt (std::map<std::wstring, JSValue> const & options, const std::wstring key, int &value)
103107 {
104108 bool found = false ;
105109 auto search = options.find (key);
@@ -130,7 +134,7 @@ namespace winrt::ReactNativeCameraCPP {
130134 {
131135 if (!m_isInitialized)
132136 {
133- result.Reject (L" Media device is not initialized! " );
137+ result.Reject (L" Media device is not initialized. " );
134138 return ;
135139 }
136140
@@ -142,9 +146,9 @@ namespace winrt::ReactNativeCameraCPP {
142146 auto randomStream = winrt::InMemoryRandomAccessStream ();
143147 co_await mediaCapture.CapturePhotoToStreamAsync (encoding, randomStream);
144148 int target;
145- if (!GetNumericValue (options, L" target" , target))
149+ if (!TryGetalueAsInt (options, L" target" , target))
146150 {
147- result.Reject (L" target parameter not specified! " );
151+ result.Reject (L" target parameter not specified. " );
148152 return ;
149153 }
150154 if (target == CameraCaptureTargetMemory)
@@ -178,7 +182,7 @@ namespace winrt::ReactNativeCameraCPP {
178182 }
179183 else
180184 {
181- result.Reject (L" Media device is not initialized! " );
185+ result.Reject (L" Media device is not initialized. " );
182186 }
183187
184188 co_await resume_background ();
@@ -188,7 +192,7 @@ namespace winrt::ReactNativeCameraCPP {
188192 {
189193 if (!m_isInitialized)
190194 {
191- result.Reject (L" Media device is not initialized! " );
195+ result.Reject (L" Media device is not initialized. " );
192196 return ;
193197 }
194198
@@ -197,7 +201,7 @@ namespace winrt::ReactNativeCameraCPP {
197201 if (auto mediaCapture = m_childElement.Source ())
198202 {
199203 int quality = static_cast <int >(VideoEncodingQuality::Auto);
200- GetNumericValue (options, L" quality" , quality);
204+ TryGetalueAsInt (options, L" quality" , quality);
201205 auto encodingProfile = winrt::MediaEncodingProfile ();
202206 auto encoding = encodingProfile.CreateMp4 (static_cast <VideoEncodingQuality>(quality));
203207
@@ -209,12 +213,12 @@ namespace winrt::ReactNativeCameraCPP {
209213 }
210214
211215 int totalSeconds = INT_MAX;
212- GetNumericValue (options, L" totalSeconds" , totalSeconds);
216+ TryGetalueAsInt (options, L" totalSeconds" , totalSeconds);
213217
214218 int target;
215- if (!GetNumericValue (options, L" target" , target))
219+ if (!TryGetalueAsInt (options, L" target" , target))
216220 {
217- result.Reject (L" target parameter not specified! " );
221+ result.Reject (L" target parameter not specified. " );
218222 return ;
219223 }
220224 if (target == CameraCaptureTargetMemory)
@@ -248,7 +252,7 @@ namespace winrt::ReactNativeCameraCPP {
248252 }
249253 else
250254 {
251- result.Reject (" No media capture device found! " );
255+ result.Reject (" No media capture device found" );
252256 }
253257 co_await resume_background ();
254258 }
@@ -482,7 +486,7 @@ namespace winrt::ReactNativeCameraCPP {
482486 {
483487 const GUID RotationKey = { 0xC380465D , 0x2271 , 0x428C , {0x9B , 0x83 , 0xEC , 0xEA , 0x3B , 0x4A , 0x85 , 0xC1 } };
484488 auto props = mediaCapture.VideoDeviceController ().GetMediaStreamProperties (MediaStreamType::VideoPreview);
485- props.Properties ().Insert (RotationKey, winrt::box_value (m_rotationHelper.GetConvertedCameraPreviewOrientation ()));
489+ props.Properties ().Insert (RotationKey, winrt::box_value (m_rotationHelper.GetCameraPreviewClockwiseDegrees ()));
486490 co_await mediaCapture.SetEncodingPropertiesAsync (MediaStreamType::VideoPreview, props, nullptr );
487491 }
488492 }
0 commit comments