/** * 解像度選択 * IOnUVCSelectSizeHandlerの実装 * @param manager 呼び出し元のUVCManager * @param device 対象となるUVC機器の情報 * @param formats 対応している解像度についての情報 */ public SupportedFormats.Size OnUVCSelectSize(UVCManager manager, UVCDevice device, SupportedFormats formats) { #if (!NDEBUG && DEBUG && ENABLE_LOG) Console.WriteLine($"{TAG}OnUVCSelectSize:{device}"); #endif if (device.IsTHETA_V) { #if (!NDEBUG && DEBUG && ENABLE_LOG) Console.WriteLine($"{TAG}OnUVCSelectSize:THETA V"); #endif return FindSize(formats, 3840, 1920); } else if (device.IsTHETA_S) { #if (!NDEBUG && DEBUG && ENABLE_LOG) Console.WriteLine($"{TAG}OnUVCSelectSize:THETA S"); #endif return FindSize(formats, 1920, 1080); } else { #if (!NDEBUG && DEBUG && ENABLE_LOG) Console.WriteLine($"{TAG}OnUVCSelectSize:other UVC device,{device}"); #endif return formats.Find(DefaultWidth, DefaultHeight); } }
/** * JSON文字列として引き渡された対応解像度をパースしてSupportedFormatsとして返す * @param jsonString * @throws ArgumentException */ public static SupportedFormats Parse(string jsonString) { #if (!NDEBUG && DEBUG && ENABLE_LOG) Console.WriteLine($"SupportedFormats:{jsonString}"); #endif SupportedFormats result; try { var elements = JsonDocument.Parse(jsonString).RootElement.GetProperty("formats"); result = new SupportedFormats(); if (elements.GetArrayLength() > 0) { result.formats = new FrameFormat[elements.GetArrayLength()]; int i = 0; foreach (var element in elements.EnumerateArray()) { result.formats[i++] = new FrameFormat(element); } } } catch (JsonException e) { result = null; Debug.LogError(e.ToString()); } if (result == null) { throw new ArgumentException($"failed to parse ({jsonString})"); } return result; }
/** *获取指定的UVC设备的对应分辨率 *@param deviceName UVC设备识别字符串 */ private SupportedFormats GetSupportedVideoSize(string deviceName) { AndroidDebug.Logd(TAG, "获取指定的UVC设备的对应分辨率:" + deviceName); if (!String.IsNullOrEmpty(deviceName)) { using (AndroidJavaClass clazz = new AndroidJavaClass(FQCN_PLUGIN)) { return(SupportedFormats.Parse( clazz.CallStatic <string>("getSupportedVideoSize", AndroidUtils.GetCurrentActivity(), deviceName))); } } else { throw new ArgumentException("device name is empty/null"); } }
/** * 指定したUVC機器の対応解像度を取得する * @param deviceName UVC機器識別文字列 */ private SupportedFormats GetSupportedVideoSize(string deviceName) { #if (!NDEBUG && DEBUG && ENABLE_LOG) Console.WriteLine($"{TAG}GetSupportedVideoSize:{deviceName}"); #endif if (!String.IsNullOrEmpty(deviceName)) { using (AndroidJavaClass clazz = new AndroidJavaClass(FQCN_PLUGIN)) { return(SupportedFormats.Parse( clazz.CallStatic <string>("getSupportedVideoSize", AndroidUtils.GetCurrentActivity(), deviceName))); } } else { throw new ArgumentException("device name is empty/null"); } }
public static SupportedFormats Parse(WebCamDevice camera) { SupportedFormats result; try { var resolutions = camera.availableResolutions; result = new SupportedFormats(); if ((resolutions != null) && (resolutions.Length > 0)) { result.formats = new FrameFormat[1] { new FrameFormat(resolutions)}; } } catch (Exception e) { result = null; Debug.LogError(e.ToString()); } if (result == null) { throw new ArgumentException($"failed to parse ({camera})"); } return result; }
//-------------------------------------------------------------------------------- private SupportedFormats.Size FindSize(SupportedFormats formats, int width, int height) { return formats.Find(width, height); }
/** * JSON文字列として引き渡された対応解像度をパースしてSupportedFormatsとして返す * @param jsonString * @throws ArgumentException */ public static SupportedFormats Parse(string jsonString) { AndroidDebug.Logd(TAG, "代言数据:" + jsonString); //Debug.Log("代言数据:"+ jsonString); SupportedFormats result; try { var elements = JObject.Parse(jsonString)["formats"]; result = new SupportedFormats(); var elementsLength = ((JArray)elements).Count; AndroidDebug.Logd(TAG, "Parse1:" + elementsLength); if (elementsLength > 0) { AndroidDebug.Logd(TAG, "Parse2:" + elementsLength); result.formats = new FrameFormat[elementsLength]; AndroidDebug.Logd(TAG, "Parse4:" + result.formats); int i = 0; foreach (var element in (JArray)elements) { AndroidDebug.Logd(TAG, "Parse5:" + element); result.formats[i++] = new FrameFormat(element); } } } catch (Newtonsoft.Json.JsonException e) { result = null; AndroidDebug.Logd(TAG, "Parse3:" + e.ToString()); Debug.LogError(e.ToString()); } if (result == null) { AndroidDebug.Logd(TAG, "Parse:result == null"); throw new ArgumentException($"failed to parse ({jsonString})"); } return result; //SupportedFormats result; //try //{ // var elements = JsonDocument.Parse(jsonString).RootElement.GetProperty("formats"); // result = new SupportedFormats(); // if (elements.GetArrayLength() > 0) // { // result.formats = new FrameFormat[elements.GetArrayLength()]; // int i = 0; // foreach (var element in elements.EnumerateArray()) // { // result.formats[i++] = new FrameFormat(element); // } // } //} //catch (JsonException e) //{ // result = null; // Debug.LogError(e.ToString()); //} //if (result == null) //{ // throw new ArgumentException($"failed to parse ({jsonString})"); //} //return result; }