GSTREAMER,如何使用Android上的C播放UDP流?

发布于 2025-01-18 14:50:38 字数 2185 浏览 2 评论 0 原文

我正在尝试使用Android上的GSTREAMER播放UDP流。 (我已经使用了官方GStreamer的教程)。我可以播放RTSP和HTTPS流,但是当我通过UDP URI(像这样: udp://@238.0.0.1:1234 )时,什么都不会发生(有黑屏幕)。在日志中,我有:从element uredecodebin1收到的错误:您的gstreamer安装缺少插件。我找到了一些文档在这里关于安装插件,但我不明白该怎么做。

这是我使用的代码的部分:

data->context = g_main_context_new ();
g_main_context_push_thread_default (data->context);

/* Build pipeline */

data->pipeline = gst_parse_launch ("playbin", &error);

if (error) {
 gchar *message =
    g_strdup_printf ("Unable to build pipeline: %s", error->message);
 g_clear_error (&error);
 set_ui_message (message, data);
 g_free (message);
 return NULL;
}

第二个:

/* Set playbin2's URI */
void gst_native_set_uri (JNIEnv * env, jobject thiz, jstring uri)
{
CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id);
if (!data || !data->pipeline)
   return;
const gchar *char_uri = (*env)->GetStringUTFChars (env, uri, NULL);
GST_DEBUG ("Setting URI to %s", char_uri);
if (data->target_state >= GST_STATE_READY)
  gst_element_set_state (data->pipeline, GST_STATE_READY);
g_object_set (data->pipeline, "uri", char_uri, NULL);

(*env)->ReleaseStringUTFChars (env, uri, char_uri);

data->duration = GST_CLOCK_TIME_NONE;
data->is_live |=
      (gst_element_set_state (data->pipeline,
                              data->target_state) == GST_STATE_CHANGE_NO_PREROLL);

}

完整代码是在这里

这是我在C和JNI中所做的第一件事,所以我将感谢工作代码片段。

I'm trying to play udp stream using Gstreamer on android. (I've used this tutorial from the official Gstreamer website). I can play rtsp and https streams, but when I pass udp uri (like this: udp://@238.0.0.1:1234) nothing happens (there is a black screen). In the log I have: Error received from element uridecodebin1: Your GStreamer installation is missing a plug-in. I've found some documentation here about installing plugins, but I don't understand how to do that.

Here is the piece of the code I use:

data->context = g_main_context_new ();
g_main_context_push_thread_default (data->context);

/* Build pipeline */

data->pipeline = gst_parse_launch ("playbin", &error);

if (error) {
 gchar *message =
    g_strdup_printf ("Unable to build pipeline: %s", error->message);
 g_clear_error (&error);
 set_ui_message (message, data);
 g_free (message);
 return NULL;
}

and the 2nd one:

/* Set playbin2's URI */
void gst_native_set_uri (JNIEnv * env, jobject thiz, jstring uri)
{
CustomData *data = GET_CUSTOM_DATA (env, thiz, custom_data_field_id);
if (!data || !data->pipeline)
   return;
const gchar *char_uri = (*env)->GetStringUTFChars (env, uri, NULL);
GST_DEBUG ("Setting URI to %s", char_uri);
if (data->target_state >= GST_STATE_READY)
  gst_element_set_state (data->pipeline, GST_STATE_READY);
g_object_set (data->pipeline, "uri", char_uri, NULL);

(*env)->ReleaseStringUTFChars (env, uri, char_uri);

data->duration = GST_CLOCK_TIME_NONE;
data->is_live |=
      (gst_element_set_state (data->pipeline,
                              data->target_state) == GST_STATE_CHANGE_NO_PREROLL);

}

Full code is here

This is the first thing I'm doing in C and JNI, so I would be grateful for working code snippet.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

薄荷→糖丶微凉 2025-01-25 14:50:38

好吧,我无意中找到了解决方案。我刚刚修改了 Android.mk 文件,将 $(GSTREAMER_PLUGINS_CODECS_RESTRICTED) 添加到 GSTREAMER_PLUGINS 行中。现在 udp 流工作正常!

Ok, I've accidentaly found the solution. I just modified my Android.mk file by adding $(GSTREAMER_PLUGINS_CODECS_RESTRICTED) into GSTREAMER_PLUGINS line. Now udp streams works fine!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文