validate: media-descriptor: Workaround file:// stream-id changing

file:// base stream-id will vary depending on the file path. As we
don't expect everyone to use the same absolute path to place the
validate testsuite, the resulting stream-id changes. Because of that,
we can't match the stream-id in the recorded file, hence cannot do
further check. We work around this by doing what filesink would do,
which is compute a SHA256 of the URI which we can use to first
validate the ID is prefixed like expected, and decide if we should
consider the stream IDs the same or not.

https://bugzilla.gnome.org/show_bug.cgi?id=753079
This commit is contained in:
Nicolas Dufresne 2015-07-31 10:50:24 -04:00
parent e25a6aaf78
commit 6993666749

View file

@ -20,6 +20,7 @@
* Boston, MA 02110-1301, USA.
*/
#include <string.h>
#include "media-descriptor.h"
G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GstMediaDescriptor, gst_media_descriptor,
@ -285,12 +286,63 @@ compare_tags (GstMediaDescriptor * ref, StreamNode * rstream,
return 1;
}
/* Workaround false warning caused by differnet file path */
static gboolean
stream_id_is_equal (const gchar * uri, const gchar * rid, const gchar * cid)
{
gboolean is_file = g_str_has_prefix (uri, "file://");
GChecksum *cs;
const gchar *stream_id;
/* Simple case it's the same */
if (g_strcmp0 (rid, cid) == 0)
return TRUE;
/* If it's not from file, it should have been the same */
if (!is_file)
return FALSE;
/* taken from basesrc, compute the reference stream-id */
cs = g_checksum_new (G_CHECKSUM_SHA256);
g_checksum_update (cs, (const guchar *) uri, strlen (uri));
stream_id = g_checksum_get_string (cs);
/* If the reference stream_id is the URI SHA256, that means we have a single
* stream file (no demuxing), just assume it's the same id */
if (g_strcmp0 (rid, stream_id) == 0) {
g_checksum_free (cs);
return TRUE;
}
/* It should always be prefixed with the SHA256, otherwise it likely means
* that basesrc is no longer using a SHA256 checksum on the URI, and this
* workaround will need to be fixed */
if (!g_str_has_prefix (rid, stream_id)) {
g_checksum_free (cs);
return FALSE;
}
g_checksum_free (cs);
/* we strip the IDS to the delimitor, and then compare */
rid = strchr (rid, '/');
cid = strchr (cid, '/');
if (rid == NULL || cid == NULL)
return FALSE;
if (g_strcmp0 (rid, cid) == 0)
return TRUE;
return FALSE;
}
/* Return -1 if not found 1 if OK 0 if an error occured */
static gint
compare_streams (GstMediaDescriptor * ref, StreamNode * rstream,
StreamNode * cstream)
{
if (g_strcmp0 (rstream->id, cstream->id) == 0) {
if (stream_id_is_equal (ref->filenode->uri, rstream->id, cstream->id)) {
if (!gst_caps_is_equal (rstream->caps, cstream->caps)) {
gchar *rcaps = gst_caps_to_string (rstream->caps),
*ccaps = gst_caps_to_string (cstream->caps);