Search code examples
androidandroid-ndkgstreamergstreamer-1.0

udpsink0 Could not create socket on Android 10 emulator


I'm new to android app and GStreamer so please bear with me. Appreciate any guidance on resolving this.

After spending considerable amount of time I'm able to successfully run/port all GStreamer tutorials on Pixel_3a_API_29 emulator on Android Studio Chipmunk Patch 1 with GStreamer pre-built library.

Now I'm trying to modify android-tutorial-2 with following pipeline to send the audio data over network stream but the udpsink is creating problem. I've confirmed it by replacing udpsink with fakesink and the pipeline runs fine.

const gchar *pipeline = "audiotestsrc ! audioconvert ! rtpL16pay ! udpsink";

udpsink fail error emulator image

I did some troubleshooting to find out what is the problem and am able find the error gst_multiudpsink_start:<udpsink0> error: Could not create socket: Unable to create socket: Operation not permitted.

I found this thread but it is completely un-related compared to my environment.

2022-06-24 13:57:28.714 13587-13587/org.freedesktop.gstreamer.tutorials.tutorial_2 I/GStreamer: GStreamer initialization complete
2022-06-24 13:57:28.767 13587-13587/org.freedesktop.gstreamer.tutorials.tutorial_2 I/GStreamer: Activity created. There is no saved state, playing: false
2022-06-24 13:57:28.768 13587-13587/org.freedesktop.gstreamer.tutorials.tutorial_2 D/GStreamer+tutorial-2: 0:00:00.176483700 0x77698cb49d30 C:/Sandbox/gst-docs-master/examples/tutorials/android/android-tutorial-2/jni/tutorial-2.c:236:gst_native_init Created CustomData at 0x77698a063550
2022-06-24 13:57:28.768 13587-13587/org.freedesktop.gstreamer.tutorials.tutorial_2 D/GStreamer+tutorial-2: 0:00:00.176564000 0x77698cb49d30 C:/Sandbox/gst-docs-master/examples/tutorials/android/android-tutorial-2/jni/tutorial-2.c:238:gst_native_init Created GlobalRef for app object at 0x2cba
2022-06-24 13:57:28.768 13587-13663/org.freedesktop.gstreamer.tutorials.tutorial_2 D/GStreamer+tutorial-2: 0:00:00.177255400 0x776989f9e210 C:/Sandbox/gst-docs-master/examples/tutorials/android/android-tutorial-2/jni/tutorial-2.c:163:app_function Creating pipeline in CustomData at 0x77698a063550
2022-06-24 13:57:28.770 13587-13663/org.freedesktop.gstreamer.tutorials.tutorial_2 D/GStreamer+tutorial-2: 0:00:00.179423700 0x776989f9e210 C:/Sandbox/gst-docs-master/examples/tutorials/android/android-tutorial-2/jni/tutorial-2.c:206:app_function Entering main loop... (CustomData:0x77698a063550)
2022-06-24 13:57:28.771 13587-13663/org.freedesktop.gstreamer.tutorials.tutorial_2 D/GStreamer+tutorial-2: 0:00:00.179482100 0x776989f9e210 C:/Sandbox/gst-docs-master/examples/tutorials/android/android-tutorial-2/jni/tutorial-2.c:51:attach_current_thread Attaching thread 0x776989f9e210
2022-06-24 13:57:28.771 13587-13663/org.freedesktop.gstreamer.tutorials.tutorial_2 D/GStreamer+tutorial-2: 0:00:00.179939100 0x776989f9e210 C:/Sandbox/gst-docs-master/examples/tutorials/android/android-tutorial-2/jni/tutorial-2.c:143:check_initialization_complete Initialization complete, notifying application. main_loop:0x77698a07f8e0
2022-06-24 13:57:28.771 13587-13663/org.freedesktop.gstreamer.tutorials.tutorial_2 I/GStreamer: Gst initialized. Restoring state, playing:false
2022-06-24 13:57:28.771 13587-13663/org.freedesktop.gstreamer.tutorials.tutorial_2 D/GStreamer+tutorial-2: 0:00:00.180105000 0x776989f9e210 C:/Sandbox/gst-docs-master/examples/tutorials/android/android-tutorial-2/jni/tutorial-2.c:279:gst_native_pause Setting state to PAUSED
2022-06-24 13:57:28.771 13587-13663/org.freedesktop.gstreamer.tutorials.tutorial_2 W/GStreamer+multiudpsink: 0:00:00.180351400 0x776989f9e210 ../gst/udp/gstmultiudpsink.c:1445:gst_multiudpsink_start:<udpsink0> error: Could not create socket: Unable to create socket: Operation not permitted
2022-06-24 13:57:28.771 13587-13663/org.freedesktop.gstreamer.tutorials.tutorial_2 W/GStreamer+basesink: 0:00:00.180394100 0x776989f9e210 ../libs/gst/base/gstbasesink.c:5879:gst_base_sink_change_state:<udpsink0> error: Failed to start
2022-06-24 13:57:28.772 13587-13663/org.freedesktop.gstreamer.tutorials.tutorial_2 D/GStreamer+tutorial-2: 0:00:00.180738700 0x776989f9e210 C:/Sandbox/gst-docs-master/examples/tutorials/android/android-tutorial-2/jni/tutorial-2.c:91:set_ui_message Setting message to: Error received from element udpsink0: GStreamer encountered a general resource error.
2022-06-24 13:57:28.772 13587-13663/org.freedesktop.gstreamer.tutorials.tutorial_2 D/GStreamer+tutorial-2: 0:00:00.181023400 0x776989f9e210 C:/Sandbox/gst-docs-master/examples/tutorials/android/android-tutorial-2/jni/tutorial-2.c:91:set_ui_message Setting message to: Error received from element udpsink0: GStreamer error: state change failed and some element failed to post a proper error message with the reason for the failure.
2022-06-24 13:57:28.822 13587-13660/org.freedesktop.gstreamer.tutorials.tutorial_2 D/HostConnection: HostConnection::get() New Host Connection established 0x7769d889f7c0, tid 13660

Solution

  • It was not a problem with the code but permission. I had no idea how the android apps work obviously, Adding following in AndroidManifest.xml solved my problem.

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
    

    Later I also found that there are other permission tags that might be useful if you are dealing with reading and writing from the media,

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    

    Hope this help someone beginner like me.