Commit 9a89dac1 authored by Justin Kim's avatar Justin Kim

ahc2src: accept framerate settings

parent a04acb2b
......@@ -1078,7 +1078,8 @@ gst_ahc2_src_set_caps (GstBaseSrc * src, GstCaps * caps)
GstVideoFormat format;
gint fmt = -1;
const gchar *format_str = NULL;
gint width, height, fps_n, fps_d;
const GValue *framerate_value;
gint width, height, fps_min = 0, fps_max = 0;
ANativeWindow *image_reader_window = NULL;
......@@ -1093,9 +1094,30 @@ gst_ahc2_src_set_caps (GstBaseSrc * src, GstCaps * caps)
gst_structure_get_int (s, "width", &width);
gst_structure_get_int (s, "height", &height);
gst_structure_get_fraction (s, "framerate", &fps_n, &fps_d);
framerate_value = gst_structure_get_value (s, "framerate");
fps_n *= 1000 / fps_d;
if (GST_VALUE_HOLDS_FRACTION_RANGE (framerate_value)) {
const GValue *min, *max;
min = gst_value_get_fraction_range_min (framerate_value);
max = gst_value_get_fraction_range_max (framerate_value);
fps_min = gst_value_get_fraction_numerator (min) / gst_value_get_fraction_denominator (min);
fps_max = gst_value_get_fraction_numerator (max) / gst_value_get_fraction_denominator (max);
} else if (GST_VALUE_HOLDS_FRACTION (framerate_value)) {
fps_min = fps_max =
gst_value_get_fraction_numerator (framerate_value) / gst_value_get_fraction_denominator (framerate_value);
} else {
GST_WARNING_OBJECT (self, "framerate holds unrecognizable value");
}
if (fps_min != 0 && fps_max != 0) {
gint fps_range[2] = { fps_min, fps_max };
ACaptureRequest_setEntry_i32 (priv->capture_request,
ACAMERA_CONTROL_AE_TARGET_FPS_RANGE, 2, fps_range);
GST_DEBUG_OBJECT (self, "setting fps range [%d, %d]", fps_min, fps_max);
}
switch (format) {
case GST_VIDEO_FORMAT_NV12:
......@@ -1182,7 +1204,7 @@ gst_ahc2_src_get_caps (GstBaseSrc * src, GstCaps * filter)
GstStructure *format = NULL;
ACameraMetadata *metadata = NULL;
ACameraMetadata_const_entry entry;
ACameraMetadata_const_entry entry, fps_entry;
if (ACameraManager_getCameraCharacteristics (priv->camera_manager,
priv->camera_id_list->cameraIds[priv->camera_index],
......@@ -1261,16 +1283,16 @@ gst_ahc2_src_get_caps (GstBaseSrc * src, GstCaps * filter)
g_free (cap_str);
}
}
#endif
GST_DEBUG_OBJECT (self, "Checking available FPS ranges:");
if (ACameraMetadata_getConstEntry (metadata,
ACAMERA_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES, &entry) == ACAMERA_OK) {
ACAMERA_CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES, &fps_entry) == ACAMERA_OK) {
int i = 0;
for (; i < entry.count; i++) {
GST_DEBUG_OBJECT (self, " (min: %d, max: %d)", entry.data.i32[i * 2], entry.data.i32[i * 2 + 1]);
for (; i < fps_entry.count; i += 2) {
GST_DEBUG_OBJECT (self, " (min: %d, max: %d)", fps_entry.data.i32[i], fps_entry.data.i32[i + 1]);
}
}
#endif
/* Only NV12 is acceptable. */
format = gst_structure_new ("video/x-raw",
......@@ -1281,26 +1303,40 @@ gst_ahc2_src_get_caps (GstBaseSrc * src, GstCaps * filter)
ACAMERA_SCALER_AVAILABLE_STREAM_CONFIGURATIONS,
&entry) == ACAMERA_OK) {
gint i = 0;
for (; i < entry.count; i++) {
gint input = entry.data.i32[i * 4 + 3];
gint fmt = entry.data.i32[i * 4 + 0];
for (; i < entry.count; i += 4) {
gint input = entry.data.i32[i + 3];
gint fmt = entry.data.i32[i + 0];
if (input)
continue;
if (fmt == AIMAGE_FORMAT_YUV_420_888) {
gint width = entry.data.i32[i * 4 + 1];
gint height = entry.data.i32[i * 4 + 2];
gint fps_idx = 0;
gint width = entry.data.i32[i + 1];
gint height = entry.data.i32[i + 2];
GstStructure *size = gst_structure_copy (format);
GST_DEBUG_OBJECT (self, " (w: %d, h: %d)", width, height);
gst_structure_set (size,
"width", G_TYPE_INT, width,
"height", G_TYPE_INT, height,
"interlaced", G_TYPE_BOOLEAN, FALSE,
"pixel-aspect-ratio", GST_TYPE_FRACTION, 1, 1, NULL);
gst_caps_append_structure (caps, size);
GST_DEBUG_OBJECT (self, " (w: %d, h: %d)", width, height);
for (fps_idx = 0; fps_idx < fps_entry.count; fps_idx += 2) {
GstStructure *s = gst_structure_copy (size);
if (fps_entry.data.i32[fps_idx] == fps_entry.data.i32[fps_idx + 1]) {
gst_structure_set (s, "framerate", GST_TYPE_FRACTION,
fps_entry.data.i32[fps_idx], 1, NULL);
} else {
gst_structure_set (s, "framerate", GST_TYPE_FRACTION_RANGE,
fps_entry.data.i32[fps_idx], 1, fps_entry.data.i32[fps_idx + 1], 1, NULL);
}
gst_caps_append_structure (caps, s);
}
gst_structure_free (size);
}
}
} else {
......@@ -1723,7 +1759,7 @@ image_reader_on_image_available (void *context, AImageReader * reader)
gst_wrapped_aimage_ref (wrapped_aimage),
(GDestroyNotify) gst_wrapped_aimage_unref);
GST_DEBUG_OBJECT (self, "Created a wrapped memory (ptr: %p, length: %d)",
GST_TRACE_OBJECT (self, "Created a wrapped memory (ptr: %p, length: %d)",
mem, length);
gst_buffer_append_memory (buffer, mem);
}
......@@ -1742,7 +1778,7 @@ image_reader_on_image_available (void *context, AImageReader * reader)
gst_wrapped_aimage_unref (wrapped_aimage);
g_mutex_unlock (&priv->mutex);
GST_DEBUG_OBJECT (self,
GST_TRACE_OBJECT (self,
"created buffer from image callback %" G_GSIZE_FORMAT ", ts %"
GST_TIME_FORMAT ", dur %" GST_TIME_FORMAT
", offset %" G_GINT64_FORMAT ", offset_end %" G_GINT64_FORMAT,
......@@ -2099,17 +2135,3 @@ gst_ahc2_src_photography_init (gpointer g_iface, gpointer iface_data)
iface->get_zoom = gst_ahc2_src_get_zoom;
iface->set_zoom = gst_ahc2_src_set_zoom;
}
#if 0
static gboolean
plugin_init (GstPlugin * plugin)
{
if (!gst_element_register (plugin, "ahc2src", GST_RANK_NONE,
GST_TYPE_AHC2_SRC)) {
GST_ERROR ("Failed to register android camera2 source");
return FALSE;
}
return TRUE;
}
#endif
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment