+ }
+ return YES;
+}
+
+- (BOOL)setDeviceCaps:(GstVideoInfo *)info
+{
+ double framerate;
+ gboolean found_format = FALSE, found_framerate = FALSE;
+ NSArray *formats = [device valueForKey:@"formats"];
+ gst_util_fraction_to_double (info->fps_n, info->fps_d, &framerate);
+
+ if ([device lockForConfiguration:NULL] == YES) {
+ for (AVCaptureDeviceFormat *f in formats) {
+ CMFormatDescriptionRef formatDescription = f.formatDescription;
+ CMVideoDimensions dimensions = CMVideoFormatDescriptionGetDimensions(formatDescription);
+ if (dimensions.width == info->width && dimensions.height == info->height) {
+ found_format = TRUE;
+ device.activeFormat = f;
+ for (AVFrameRateRange *rate in f.videoSupportedFrameRateRanges) {
+ if (abs (framerate - rate.maxFrameRate) < 0.00001) {
+ found_framerate = TRUE;
+ device.activeVideoMinFrameDuration = rate.minFrameDuration;
+ [device setValue:[NSValue valueWithCMTime:rate.minFrameDuration]
+ forKey:@"activeVideoMinFrameDuration"];
+ @try {
+ /* Only available on OSX >= 10.8 and iOS >= 7.0 */
+ [device setValue:[NSValue valueWithCMTime:rate.maxFrameDuration]
+ forKey:@"activeVideoMaxFrameDuration"];
+ } @catch (NSException *exception) {
+ if (![[exception name] isEqualTo:NSUndefinedKeyException]) {
+ GST_WARNING ("An unexcepted error occured: %s",
+ [exception.reason UTF8String]);
+ }
+ }
+ break;
+ }
+ }
+ }
+ }
+ if (!found_format) {
+ GST_WARNING ("Unsupported capture dimensions %dx%d", info->width, info->height);
+ return NO;
+ }
+ if (!found_framerate) {
+ GST_WARNING ("Unsupported capture framerate %d/%d", info->fps_n, info->fps_d);
+ return NO;
+ }
+ } else {
+ GST_WARNING ("Couldn't lock device for configuration");
+ return NO;
+ }
+ return YES;
+}
+
+- (BOOL)getSessionPresetCaps:(GstCaps *)result
+{
+ NSArray *pixel_formats = output.availableVideoCVPixelFormatTypes;
+ for (NSNumber *pixel_format in pixel_formats) {
+ GstVideoFormat gst_format = [self getGstVideoFormat:pixel_format];
+ if (gst_format == GST_VIDEO_FORMAT_UNKNOWN)
+ continue;