mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-10-02 08:42:32 +00:00
souphttpsrc: Don't use the source element after setup from the session thread
The source element might be gone already if the session is shared with other source elements. As a consequence, do all logging via the session object instead of using the source element. Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1594>
This commit is contained in:
parent
080d85b19a
commit
42f5873eeb
4 changed files with 30 additions and 22 deletions
|
@ -598,7 +598,7 @@ gst_soup_http_client_sink_start (GstBaseSink * sink)
|
||||||
|
|
||||||
/* Set up logging */
|
/* Set up logging */
|
||||||
gst_soup_util_log_setup (souphttpsink->session, souphttpsink->log_level,
|
gst_soup_util_log_setup (souphttpsink->session, souphttpsink->log_level,
|
||||||
GST_ELEMENT (souphttpsink));
|
G_OBJECT (souphttpsink));
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
|
@ -985,18 +985,19 @@ static gpointer
|
||||||
thread_func (gpointer user_data)
|
thread_func (gpointer user_data)
|
||||||
{
|
{
|
||||||
GstSoupHTTPSrc *src = user_data;
|
GstSoupHTTPSrc *src = user_data;
|
||||||
|
GstSoupSession *session = src->session;
|
||||||
GMainContext *ctx;
|
GMainContext *ctx;
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (src, "thread start");
|
GST_DEBUG_OBJECT (src, "thread start");
|
||||||
|
|
||||||
ctx = g_main_loop_get_context (src->session->loop);
|
ctx = g_main_loop_get_context (session->loop);
|
||||||
|
|
||||||
g_main_context_push_thread_default (ctx);
|
g_main_context_push_thread_default (ctx);
|
||||||
|
|
||||||
/* We explicitly set User-Agent to NULL here and overwrite it per message
|
/* We explicitly set User-Agent to NULL here and overwrite it per message
|
||||||
* to be able to have the same session with different User-Agents per
|
* to be able to have the same session with different User-Agents per
|
||||||
* source */
|
* source */
|
||||||
src->session->session =
|
session->session =
|
||||||
_soup_session_new_with_options ("user-agent", NULL,
|
_soup_session_new_with_options ("user-agent", NULL,
|
||||||
"timeout", src->timeout, "tls-interaction", src->tls_interaction,
|
"timeout", src->timeout, "tls-interaction", src->tls_interaction,
|
||||||
/* Unset the limit the number of maximum allowed connections */
|
/* Unset the limit the number of maximum allowed connections */
|
||||||
|
@ -1015,20 +1016,19 @@ thread_func (gpointer user_data)
|
||||||
g_object_unref (proxy_resolver);
|
g_object_unref (proxy_resolver);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
g_object_set (src->session->session, "ssl-strict", src->ssl_strict, NULL);
|
g_object_set (session->session, "ssl-strict", src->ssl_strict, NULL);
|
||||||
if (src->proxy != NULL) {
|
if (src->proxy != NULL) {
|
||||||
g_object_set (src->session->session, "proxy-uri", src->proxy->soup_uri,
|
g_object_set (session->session, "proxy-uri", src->proxy->soup_uri, NULL);
|
||||||
NULL);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gst_soup_util_log_setup (src->session->session, src->log_level,
|
gst_soup_util_log_setup (session->session, src->log_level,
|
||||||
GST_ELEMENT (src));
|
G_OBJECT (session));
|
||||||
if (gst_soup_loader_get_api_version () < 3) {
|
if (gst_soup_loader_get_api_version () < 3) {
|
||||||
_soup_session_add_feature_by_type (src->session->session,
|
_soup_session_add_feature_by_type (session->session,
|
||||||
_soup_content_decoder_get_type ());
|
_soup_content_decoder_get_type ());
|
||||||
}
|
}
|
||||||
_soup_session_add_feature_by_type (src->session->session,
|
_soup_session_add_feature_by_type (session->session,
|
||||||
_soup_cookie_jar_get_type ());
|
_soup_cookie_jar_get_type ());
|
||||||
|
|
||||||
if (src->session_is_shared) {
|
if (src->session_is_shared) {
|
||||||
|
@ -1036,11 +1036,11 @@ thread_func (gpointer user_data)
|
||||||
GstMessage *message;
|
GstMessage *message;
|
||||||
GstStructure *s;
|
GstStructure *s;
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (src, "Sharing session %p", src->session->session);
|
GST_DEBUG_OBJECT (session, "Sharing session %p", session->session);
|
||||||
|
|
||||||
context = gst_context_new (GST_SOUP_SESSION_CONTEXT, TRUE);
|
context = gst_context_new (GST_SOUP_SESSION_CONTEXT, TRUE);
|
||||||
s = gst_context_writable_structure (context);
|
s = gst_context_writable_structure (context);
|
||||||
gst_structure_set (s, "session", GST_TYPE_SOUP_SESSION, src->session, NULL);
|
gst_structure_set (s, "session", GST_TYPE_SOUP_SESSION, session, NULL);
|
||||||
|
|
||||||
/* during this time the src is locked by the parent thread,
|
/* during this time the src is locked by the parent thread,
|
||||||
* which is waiting, so this is safe to do
|
* which is waiting, so this is safe to do
|
||||||
|
@ -1059,7 +1059,7 @@ thread_func (gpointer user_data)
|
||||||
* and exits early if it does not)
|
* and exits early if it does not)
|
||||||
*/
|
*/
|
||||||
if (gst_soup_loader_get_api_version () < 3) {
|
if (gst_soup_loader_get_api_version () < 3) {
|
||||||
g_signal_connect (src->session->session, "authenticate",
|
g_signal_connect (session->session, "authenticate",
|
||||||
G_CALLBACK (gst_soup_http_src_authenticate_cb_2), src);
|
G_CALLBACK (gst_soup_http_src_authenticate_cb_2), src);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1077,11 +1077,17 @@ thread_func (gpointer user_data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_main_loop_run (src->session->loop);
|
/* Once the main loop is running, the source element that created this
|
||||||
|
* session might disappear if the session is shared with other source
|
||||||
|
* elements.
|
||||||
|
*/
|
||||||
|
src = NULL;
|
||||||
|
|
||||||
|
g_main_loop_run (session->loop);
|
||||||
|
|
||||||
g_main_context_pop_thread_default (ctx);
|
g_main_context_pop_thread_default (ctx);
|
||||||
|
|
||||||
GST_DEBUG_OBJECT (src, "thread stop");
|
GST_DEBUG_OBJECT (session, "thread stop");
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
@ -1165,6 +1171,8 @@ gst_soup_http_src_session_open (GstSoupHTTPSrc * src)
|
||||||
src->session =
|
src->session =
|
||||||
GST_SOUP_SESSION (g_object_new (GST_TYPE_SOUP_SESSION, NULL));
|
GST_SOUP_SESSION (g_object_new (GST_TYPE_SOUP_SESSION, NULL));
|
||||||
|
|
||||||
|
GST_DEBUG_OBJECT (src, "Created session %p", src->session);
|
||||||
|
|
||||||
ctx = g_main_context_new ();
|
ctx = g_main_context_new ();
|
||||||
|
|
||||||
src->session->loop = g_main_loop_new (ctx, FALSE);
|
src->session->loop = g_main_loop_new (ctx, FALSE);
|
||||||
|
|
|
@ -63,26 +63,26 @@ gst_soup_util_log_printer_cb (SoupLogger G_GNUC_UNUSED * logger,
|
||||||
{
|
{
|
||||||
gchar c;
|
gchar c;
|
||||||
c = gst_soup_util_log_make_level_tag (level);
|
c = gst_soup_util_log_make_level_tag (level);
|
||||||
GST_TRACE_OBJECT (GST_ELEMENT (user_data), "HTTP_SESSION(%c): %c %s", c,
|
GST_TRACE_OBJECT (G_OBJECT (user_data), "HTTP_SESSION(%c): %c %s", c,
|
||||||
direction, data);
|
direction, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
gst_soup_util_log_setup (SoupSession * session, SoupLoggerLogLevel level,
|
gst_soup_util_log_setup (SoupSession * session, SoupLoggerLogLevel level,
|
||||||
GstElement * element)
|
GObject * object)
|
||||||
{
|
{
|
||||||
SoupLogger *logger;
|
SoupLogger *logger;
|
||||||
|
|
||||||
if (!level) {
|
if (!level) {
|
||||||
GST_INFO_OBJECT (element, "Not attaching a logger with level 0");
|
GST_INFO_OBJECT (object, "Not attaching a logger with level 0");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
g_assert (session && element);
|
g_assert (session && object);
|
||||||
|
|
||||||
if (gst_debug_category_get_threshold (GST_CAT_DEFAULT)
|
if (gst_debug_category_get_threshold (GST_CAT_DEFAULT)
|
||||||
< GST_LEVEL_TRACE) {
|
< GST_LEVEL_TRACE) {
|
||||||
GST_INFO_OBJECT (element, "Not setting up HTTP session logger. "
|
GST_INFO_OBJECT (object, "Not setting up HTTP session logger. "
|
||||||
"Need at least GST_LEVEL_TRACE");
|
"Need at least GST_LEVEL_TRACE");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -91,7 +91,7 @@ gst_soup_util_log_setup (SoupSession * session, SoupLoggerLogLevel level,
|
||||||
logger = _soup_logger_new (level);
|
logger = _soup_logger_new (level);
|
||||||
|
|
||||||
_soup_logger_set_printer (logger, gst_soup_util_log_printer_cb,
|
_soup_logger_set_printer (logger, gst_soup_util_log_printer_cb,
|
||||||
gst_object_ref (element), (GDestroyNotify) gst_object_unref);
|
gst_object_ref (object), (GDestroyNotify) gst_object_unref);
|
||||||
|
|
||||||
/* Attach logger to session */
|
/* Attach logger to session */
|
||||||
_soup_session_add_feature (session, (SoupSessionFeature *) logger);
|
_soup_session_add_feature (session, (SoupSessionFeature *) logger);
|
||||||
|
|
|
@ -30,7 +30,7 @@
|
||||||
G_BEGIN_DECLS
|
G_BEGIN_DECLS
|
||||||
|
|
||||||
void gst_soup_util_log_setup (SoupSession * session, SoupLoggerLogLevel level,
|
void gst_soup_util_log_setup (SoupSession * session, SoupLoggerLogLevel level,
|
||||||
GstElement * element);
|
GObject * object);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue