clapper: Store full caps in harvest

Make it possible to know which enhancer harvested this cached data
This commit is contained in:
Rafał Dzięgiel
2025-07-25 19:04:04 +02:00
parent b717471d91
commit aacf798c49
3 changed files with 28 additions and 14 deletions

View File

@@ -29,6 +29,9 @@ G_BEGIN_DECLS
G_GNUC_INTERNAL G_GNUC_INTERNAL
ClapperHarvest * clapper_harvest_new (void); ClapperHarvest * clapper_harvest_new (void);
G_GNUC_INTERNAL
void clapper_harvest_set_enhancer_in_caps (ClapperHarvest *harvest, ClapperEnhancerProxy *proxy);
G_GNUC_INTERNAL G_GNUC_INTERNAL
gboolean clapper_harvest_unpack (ClapperHarvest *harvest, GstBuffer **buffer, gsize *buf_size, GstCaps **caps, GstTagList **tags, GstToc **toc, GstStructure **headers); gboolean clapper_harvest_unpack (ClapperHarvest *harvest, GstBuffer **buffer, gsize *buf_size, GstCaps **caps, GstTagList **tags, GstToc **toc, GstStructure **headers);

View File

@@ -94,6 +94,13 @@ clapper_harvest_new (void)
return harvest; return harvest;
} }
void
clapper_harvest_set_enhancer_in_caps (ClapperHarvest *self, ClapperEnhancerProxy *proxy)
{
gst_caps_set_simple (self->caps, "enhancer", G_TYPE_STRING,
clapper_enhancer_proxy_get_module_name (proxy), NULL);
}
gboolean gboolean
clapper_harvest_unpack (ClapperHarvest *self, clapper_harvest_unpack (ClapperHarvest *self,
GstBuffer **buffer, gsize *buf_size, GstCaps **caps, GstBuffer **buffer, gsize *buf_size, GstCaps **caps,
@@ -221,7 +228,6 @@ clapper_harvest_fill_from_cache (ClapperHarvest *self, ClapperEnhancerProxy *pro
gchar *filename; gchar *filename;
const gchar *data, *read_str; const gchar *data, *read_str;
const guint8 *buf_data; const guint8 *buf_data;
guint8 *buf_copy;
gsize buf_size; gsize buf_size;
gint64 epoch_cached, epoch_now = 0; gint64 epoch_cached, epoch_now = 0;
gdouble exp_seconds; gdouble exp_seconds;
@@ -281,10 +287,10 @@ clapper_harvest_fill_from_cache (ClapperHarvest *self, ClapperEnhancerProxy *pro
goto finish; goto finish;
} }
/* Read media type */ /* Read caps */
read_str = clapper_cache_read_string (&data); read_str = clapper_cache_read_string (&data);
if (G_UNLIKELY (read_str == NULL)) { if (G_UNLIKELY (read_str == NULL)) {
GST_ERROR_OBJECT (self, "Could not read media type from cache file"); GST_ERROR_OBJECT (self, "Could not read caps from cache file");
goto finish; goto finish;
} }
@@ -296,9 +302,12 @@ clapper_harvest_fill_from_cache (ClapperHarvest *self, ClapperEnhancerProxy *pro
} }
/* Fill harvest */ /* Fill harvest */
buf_copy = g_memdup2 (buf_data, buf_size); if (!(self->caps = gst_caps_from_string (read_str))) {
if (!clapper_harvest_fill (self, read_str, buf_copy, buf_size)) GST_ERROR_OBJECT (self, "Could not construct caps from cache");
goto finish; goto finish;
}
self->buffer = gst_buffer_new_memdup (buf_data, buf_size);
self->buf_size = buf_size;
/* Read tags */ /* Read tags */
read_str = clapper_cache_read_string (&data); read_str = clapper_cache_read_string (&data);
@@ -332,7 +341,6 @@ clapper_harvest_export_to_cache (ClapperHarvest *self, ClapperEnhancerProxy *pro
const GstStructure *config, GUri *uri) const GstStructure *config, GUri *uri)
{ {
GByteArray *bytes; GByteArray *bytes;
const GstStructure *caps_structure;
gchar *filename, *temp_str = NULL; gchar *filename, *temp_str = NULL;
gboolean data_ok = TRUE; gboolean data_ok = TRUE;
@@ -366,12 +374,13 @@ clapper_harvest_export_to_cache (ClapperHarvest *self, ClapperEnhancerProxy *pro
clapper_cache_store_string (bytes, temp_str); // NULL when no config clapper_cache_store_string (bytes, temp_str); // NULL when no config
g_clear_pointer (&temp_str, g_free); g_clear_pointer (&temp_str, g_free);
/* Store media type */ /* Store caps */
caps_structure = gst_caps_get_structure (self->caps, 0); temp_str = gst_caps_to_string (self->caps);
if (G_LIKELY (caps_structure != NULL)) { if (G_LIKELY (temp_str != NULL)) {
clapper_cache_store_string (bytes, gst_structure_get_name (caps_structure)); clapper_cache_store_string (bytes, temp_str);
g_clear_pointer (&temp_str, g_free);
} else { } else {
GST_ERROR_OBJECT (self, "Cannot cache empty caps"); GST_ERROR_OBJECT (self, "Cannot cache caps");
data_ok = FALSE; data_ok = FALSE;
} }

View File

@@ -106,9 +106,10 @@ clapper_enhancer_director_extract_in_thread (ClapperEnhancerDirectorData *data)
/* We are done with extractable, but keep harvest and try to cache it */ /* We are done with extractable, but keep harvest and try to cache it */
if (success) { if (success) {
if (!g_cancellable_is_cancelled (data->cancellable)) if (!g_cancellable_is_cancelled (data->cancellable)) {
clapper_harvest_set_enhancer_in_caps (harvest, proxy);
clapper_harvest_export_to_cache (harvest, proxy, config, data->uri); clapper_harvest_export_to_cache (harvest, proxy, config, data->uri);
}
gst_clear_structure (&config); gst_clear_structure (&config);
break; break;
} }
@@ -163,7 +164,8 @@ clapper_enhancer_director_parse_in_thread (ClapperEnhancerDirectorData *data)
mem = gst_buffer_peek_memory (data->buffer, 0); mem = gst_buffer_peek_memory (data->buffer, 0);
if (!mem || !gst_memory_map (mem, &info, GST_MAP_READ)) { if (!mem || !gst_memory_map (mem, &info, GST_MAP_READ)) {
GST_ERROR_OBJECT (self, "Could not read playlist buffer data"); g_set_error (data->error, GST_RESOURCE_ERROR,
GST_RESOURCE_ERROR_FAILED, "Could not read playlist buffer data");
return NULL; return NULL;
} }