###前提・実現したいこと
Objective-Cで書かれた以下の関数をXamarin(C#)へ移植したいですが、移植ができず詰まっている部分があります。
問題部分の移植方法並びに、怪しい移植をしている部分をご教示いただけますと幸いです。
Objective
1// captureSessionはクラスのprivate変数です。 2 3- (void)switchFormatWithDesiredFPS:(CGFloat)desiredFPS 4{ 5 BOOL isRunning = self.captureSession.isRunning; 6 7 if (isRunning) [self.captureSession stopRunning]; 8 9 AVCaptureDevice *videoDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo]; 10 AVCaptureDeviceFormat *selectedFormat = nil; 11 int32_t maxWidth = 0; 12 AVFrameRateRange *frameRateRange = nil; 13 14 for (AVCaptureDeviceFormat *format in [videoDevice formats]) { 15 16 for (AVFrameRateRange *range in format.videoSupportedFrameRateRanges) { 17 18 CMFormatDescriptionRef desc = format.formatDescription; 19 CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(desc); 20 int32_t width = dimensions.width; 21 22 if (range.minFrameRate <= desiredFPS && desiredFPS <= range.maxFrameRate && width >= maxWidth) { 23 24 selectedFormat = format; 25 frameRateRange = range; 26 maxWidth = width; 27 } 28 } 29 } 30 31 if (selectedFormat) { 32 33 if ([videoDevice lockForConfiguration:nil]) { 34 35 NSLog(@"selected format:%@", selectedFormat); 36 videoDevice.activeFormat = selectedFormat; 37 videoDevice.activeVideoMinFrameDuration = CMTimeMake(1, (int32_t)desiredFPS); 38 videoDevice.activeVideoMaxFrameDuration = CMTimeMake(1, (int32_t)desiredFPS); 39 [videoDevice unlockForConfiguration]; 40 } 41 } 42 43 if (isRunning) [self.captureSession startRunning]; 44}
###発生している問題・エラーメッセージ
以下のソース中の『//★』を付けた箇所でコンパイルエラーが起きます(左辺と右辺で型が異なるため)。
また、『//☆』を付けた行は、移植がこれで正しいのか判断しかねています。
C#
1// captureSessionはクラスのprivate変数です。 2 3 public void switchFormatWithDesiredFPS(nfloat desireFPS) 4 { 5 bool isRunning = this.captureSession.Running; 6 if (isRunning) 7 { 8 this.captureSession.StopRunning(); 9 } 10 11 AVCaptureDevice videoDevice = AVCaptureDevice.DefaultDeviceWithMediaType(AVMediaType.Video); 12 AVCaptureDeviceFormat selectedFormat = null; 13 int maxWidth = 0; 14 AVFrameRateRange frameRateRange = null; 15 16 foreach (AVCaptureDeviceFormat format in videoDevice.Formats) 17 { 18 foreach (AVFrameRateRange range in format.VideoSupportedFrameRateRanges) 19 { 20 CMFormatDescription desc = format.FormatDescription; //☆ 21 CMVideoDimensions dimensions = CMVideoFormatDescription.Create(desc.Handle); //★ この行でエラー 22 int width = dimensions.Width; 23 24 if ((range.MinFrameRate <= desireFPS) && 25 (desireFPS <= range.MaxFrameRate) && (width >= maxWidth)) 26 { 27 selectedFormat = format; 28 frameRateRange = range; 29 maxWidth = width; 30 } 31 } 32 } 33 34 if (selectedFormat != null) 35 { 36 NSError error = new NSError(); 37 if (videoDevice.LockForConfiguration(out error)) 38 { 39 Console.WriteLine("selected format:{0}", selectedFormat); 40 videoDevice.ActiveFormat = selectedFormat; 41 videoDevice.ActiveVideoMinFrameDuration = CMTime.FromSeconds(1, (int)desireFPS); //☆ 42 videoDevice.ActiveVideoMaxFrameDuration = CMTime.FromSeconds(1, (int)desireFPS); //☆ 43 videoDevice.UnlockForConfiguration(); 44 } 45 } 46 47 if (isRunning) 48 { 49 this.captureSession.StartRunning(); 50 } 51 }
###試したこと
Xamarinで『CMVideoFormatDescription.』まで入力した際に表示されるサジェストは一通り試しました。
また、右辺をCMVideoDimensions型でキャストすることはできませんでした。
###補足情報(言語/FW/ツール等のバージョンなど)
OS: Mac OSX El Capitan 10.11.6
開発環境: Xamarin Studio Community 6.0.1(build 9)
回答1件
あなたの回答
tips
プレビュー