qtkitvideosrc: get the framerate from caps

...and configure QTKit accordingly. Hardcoding to 30fps was pretty -bad.
This commit is contained in:
Alessandro Decina 2011-08-15 02:08:14 +02:00
parent 84ee1c4d58
commit b6747292e0

View file

@ -42,40 +42,35 @@ static GstStaticPadTemplate src_template = GST_STATIC_PAD_TEMPLATE ("src",
"format = (fourcc) " DEVICE_YUV_FOURCC ", " "format = (fourcc) " DEVICE_YUV_FOURCC ", "
"width = (int) 640, " "width = (int) 640, "
"height = (int) 480, " "height = (int) 480, "
"framerate = (fraction) " G_STRINGIFY (DEVICE_FPS_N) "/" "framerate = [0/1, 100/1], "
G_STRINGIFY (DEVICE_FPS_D) ", "
"pixel-aspect-ratio = (fraction) 1/1" "pixel-aspect-ratio = (fraction) 1/1"
"; " "; "
"video/x-raw-yuv, " "video/x-raw-yuv, "
"format = (fourcc) " DEVICE_YUV_FOURCC ", " "format = (fourcc) " DEVICE_YUV_FOURCC ", "
"width = (int) 160, " "width = (int) 160, "
"height = (int) 120, " "height = (int) 120, "
"framerate = (fraction) " G_STRINGIFY (DEVICE_FPS_N) "/" "framerate = [0/1, 100/1], "
G_STRINGIFY (DEVICE_FPS_D) ", "
"pixel-aspect-ratio = (fraction) 1/1" "pixel-aspect-ratio = (fraction) 1/1"
"; " "; "
"video/x-raw-yuv, " "video/x-raw-yuv, "
"format = (fourcc) " DEVICE_YUV_FOURCC ", " "format = (fourcc) " DEVICE_YUV_FOURCC ", "
"width = (int) 176, " "width = (int) 176, "
"height = (int) 144, " "height = (int) 144, "
"framerate = (fraction) " G_STRINGIFY (DEVICE_FPS_N) "/" "framerate = [0/1, 100/1], "
G_STRINGIFY (DEVICE_FPS_D) ", "
"pixel-aspect-ratio = (fraction) 12/11" "pixel-aspect-ratio = (fraction) 12/11"
"; " "; "
"video/x-raw-yuv, " "video/x-raw-yuv, "
"format = (fourcc) " DEVICE_YUV_FOURCC ", " "format = (fourcc) " DEVICE_YUV_FOURCC ", "
"width = (int) 320, " "width = (int) 320, "
"height = (int) 240, " "height = (int) 240, "
"framerate = (fraction) " G_STRINGIFY (DEVICE_FPS_N) "/" "framerate = [0/1, 100/1], "
G_STRINGIFY (DEVICE_FPS_D) ", "
"pixel-aspect-ratio = (fraction) 1/1" "pixel-aspect-ratio = (fraction) 1/1"
"; " "; "
"video/x-raw-yuv, " "video/x-raw-yuv, "
"format = (fourcc) " DEVICE_YUV_FOURCC ", " "format = (fourcc) " DEVICE_YUV_FOURCC ", "
"width = (int) 352, " "width = (int) 352, "
"height = (int) 288, " "height = (int) 288, "
"framerate = (fraction) " G_STRINGIFY (DEVICE_FPS_N) "/" "framerate = [0/1, 100/1], "
G_STRINGIFY (DEVICE_FPS_D) ", "
"pixel-aspect-ratio = (fraction) 12/11" "pixel-aspect-ratio = (fraction) 12/11"
";" ";"
) )
@ -107,6 +102,7 @@ GST_BOILERPLATE (GstQTKitVideoSrc, gst_qtkit_video_src, GstPushSrc,
BOOL stopRequest; BOOL stopRequest;
gint width, height; gint width, height;
gint fps_n, fps_d;
GstClockTime duration; GstClockTime duration;
guint64 offset; guint64 offset;
} }
@ -123,6 +119,7 @@ GST_BOILERPLATE (GstQTKitVideoSrc, gst_qtkit_video_src, GstPushSrc,
- (BOOL)stop; - (BOOL)stop;
- (BOOL)unlock; - (BOOL)unlock;
- (BOOL)unlockStop; - (BOOL)unlockStop;
- (void)fixate:(GstCaps *)caps;
- (BOOL)query:(GstQuery *)query; - (BOOL)query:(GstQuery *)query;
- (GstStateChangeReturn)changeState:(GstStateChange)transition; - (GstStateChangeReturn)changeState:(GstStateChange)transition;
- (GstFlowReturn)create:(GstBuffer **)buf; - (GstFlowReturn)create:(GstBuffer **)buf;
@ -243,6 +240,7 @@ openFailed:
NSDictionary *outputAttrs; NSDictionary *outputAttrs;
BOOL success; BOOL success;
NSRunLoop *mainRunLoop; NSRunLoop *mainRunLoop;
NSTimeInterval interval;
g_assert (device != nil); g_assert (device != nil);
@ -251,7 +249,12 @@ openFailed:
s = gst_caps_get_structure (caps, 0); s = gst_caps_get_structure (caps, 0);
gst_structure_get_int (s, "width", &width); gst_structure_get_int (s, "width", &width);
gst_structure_get_int (s, "height", &height); gst_structure_get_int (s, "height", &height);
if (!gst_structure_get_fraction (s, "framerate", &fps_n, &fps_d)) {
fps_n = DEVICE_FPS_N;
fps_d = DEVICE_FPS_D;
}
GST_INFO ("got caps %dx%d %d/%d", width, height, fps_n, fps_d);
input = [[QTCaptureDeviceInput alloc] initWithDevice:device]; input = [[QTCaptureDeviceInput alloc] initWithDevice:device];
output = [[QTCaptureDecompressedVideoOutput alloc] init]; output = [[QTCaptureDecompressedVideoOutput alloc] init];
@ -269,6 +272,16 @@ openFailed:
]; ];
[output setPixelBufferAttributes:outputAttrs]; [output setPixelBufferAttributes:outputAttrs];
if (fps_n != 0) {
duration = gst_util_uint64_scale (GST_SECOND, fps_d, fps_n);
gst_util_fraction_to_double (fps_d, fps_n, (gdouble *) &interval);
} else {
duration = GST_CLOCK_TIME_NONE;
interval = 0;
}
[output setMinimumVideoFrameInterval:interval];
session = [[QTCaptureSession alloc] init]; session = [[QTCaptureSession alloc] init];
success = [session addInput:input success = [session addInput:input
error:nil]; error:nil];
@ -299,8 +312,11 @@ openFailed:
queue = [[NSMutableArray alloc] initWithCapacity:FRAME_QUEUE_SIZE]; queue = [[NSMutableArray alloc] initWithCapacity:FRAME_QUEUE_SIZE];
stopRequest = NO; stopRequest = NO;
duration = gst_util_uint64_scale (GST_SECOND, DEVICE_FPS_D, DEVICE_FPS_N);
offset = 0; offset = 0;
width = height = 0;
fps_n = 0;
fps_d = 1;
duration = GST_CLOCK_TIME_NONE;
return YES; return YES;
} }
@ -359,6 +375,18 @@ openFailed:
return YES; return YES;
} }
- (void)fixate:(GstCaps *)caps
{
GstStructure *structure;
gst_caps_truncate (caps);
structure = gst_caps_get_structure (caps, 0);
if (gst_structure_has_field (structure, "framerate")) {
gst_structure_fixate_field_nearest_fraction (structure, "framerate",
DEVICE_FPS_N, DEVICE_FPS_D);
}
}
- (GstStateChangeReturn)changeState:(GstStateChange)transition - (GstStateChangeReturn)changeState:(GstStateChange)transition
{ {
GstStateChangeReturn ret; GstStateChangeReturn ret;
@ -484,6 +512,7 @@ static gboolean gst_qtkit_video_src_unlock (GstBaseSrc * basesrc);
static gboolean gst_qtkit_video_src_unlock_stop (GstBaseSrc * basesrc); static gboolean gst_qtkit_video_src_unlock_stop (GstBaseSrc * basesrc);
static GstFlowReturn gst_qtkit_video_src_create (GstPushSrc * pushsrc, static GstFlowReturn gst_qtkit_video_src_create (GstPushSrc * pushsrc,
GstBuffer ** buf); GstBuffer ** buf);
static void gst_qtkit_video_src_fixate (GstBaseSrc * basesrc, GstCaps * caps);
static void static void
gst_qtkit_video_src_base_init (gpointer gclass) gst_qtkit_video_src_base_init (gpointer gclass)
@ -519,6 +548,7 @@ gst_qtkit_video_src_class_init (GstQTKitVideoSrcClass * klass)
gstbasesrc_class->query = gst_qtkit_video_src_query; gstbasesrc_class->query = gst_qtkit_video_src_query;
gstbasesrc_class->unlock = gst_qtkit_video_src_unlock; gstbasesrc_class->unlock = gst_qtkit_video_src_unlock;
gstbasesrc_class->unlock_stop = gst_qtkit_video_src_unlock_stop; gstbasesrc_class->unlock_stop = gst_qtkit_video_src_unlock_stop;
gstbasesrc_class->fixate = gst_qtkit_video_src_fixate;
gstpushsrc_class->create = gst_qtkit_video_src_create; gstpushsrc_class->create = gst_qtkit_video_src_create;
@ -684,3 +714,11 @@ gst_qtkit_video_src_create (GstPushSrc * pushsrc, GstBuffer ** buf)
return ret; return ret;
} }
static void
gst_qtkit_video_src_fixate (GstBaseSrc * basesrc, GstCaps * caps)
{
OBJC_CALLOUT_BEGIN ();
[GST_QTKIT_VIDEO_SRC_IMPL (basesrc) fixate: caps];
OBJC_CALLOUT_END ();
}