使用udpsrc播放的Gstreamer视频在几秒钟后在Android上停止播放

问题描述 投票:0回答:1

使用Gstreamer和udpsrc将视频流式传输到Android设备。我面临的问题是,流仅工作几秒钟,然后停止(显示永久冻结的帧)。首先,我在Android设备上创建TCP服务器,视频托管设备使用该TCP服务器进行连接。为此,我在MainActivity中使用ServerSocket和线程:

  class ServerThread implements Runnable {

        public void run() {
            Socket socket = null;
            Log.d(TAG, "running server thread");
            try {
                serverSocket = new ServerSocket(SERVERPORT);
            } catch (IOException e) {
                Log.d(TAG,e.getLocalizedMessage());
                e.printStackTrace();
            }
            while (!Thread.currentThread().isInterrupted()) {

                try {

                    socket = serverSocket.accept();

                    CommunicationThread commThread = new CommunicationThread(socket);
                    new Thread(commThread).start();

                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    class CommunicationThread implements Runnable {

        private Socket clientSocket;

        private BufferedReader input;

        public CommunicationThread(Socket clientSocket) {

            this.clientSocket = clientSocket;

            try {
                this.input = new BufferedReader(new InputStreamReader(this.clientSocket.getInputStream()));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        public void run() {
            while (!Thread.currentThread().isInterrupted()) {

                try {

                    String read = input.readLine();
                    PrintWriter out = new PrintWriter(new BufferedWriter(
                            new OutputStreamWriter(clientSocket.getOutputStream())),
                            true);
                    Log.d(TAG, "Received message: " + read);

                    String msg = "Stream\r";
                    Log.d(TAG, "Sending message: " + msg);
                    out.println(msg);

                    if (read != null && read.equals("Stream")) {
                        Log.d(TAG,"Starting stream");
                        updateConversationHandler.post(new updateUIThread("OK"));
                        nativePlay();
                    }
//                    if(read!=null) updateConversationHandler.post(new updateUIThread(read));

                } catch (IOException e) {
                    Log.d(TAG, e.getMessage());
                    Log.d(TAG, e.getLocalizedMessage());
                    e.printStackTrace();
                }
            }
        }

    }

我的应用程序基本上是Gstreamer教程3(https://gstreamer.freedesktop.org/documentation/tutorials/android/video.html?gi-language=c),添加了ServerSocket,并在其中更新了C代码中的管道以使用udpsrc

  gst_parse_launch ("udpsrc buffer-size=622080 port=8001 ! application/x-rtp, encoding-name=JPEG, payload=96 ! rtpjpegdepay ! jpegdec ! autovideosink sync=false",
      &error);

会发生几秒钟的视频流,然后停止。当我获取流时,gstreamer日志输出类似于

2019-11-20 13:33:57.149 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:40.650418010 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header

但是当视频停止播放时,它也会停止播放。

您能帮我缩小可能出现的问题的范围吗?我管理TCP连接的方式是否有问题?该流在其他设备上可以正常工作。

下面是完整的logcat输出

2019-11-20 13:33:56.836 22940-23426/org.freedesktop.gstreamer.tutorials.tutorial_3 D/GStreamer+tutorial-3: 0:00:40.337306818 0x717b1f8c70 /Users/radek/dev/StudioProjects/gst-docs/examples/tutorials/android/android-tutorial-3/jni/tutorial-3.c:286:gst_native_play Setting state to PLAYING
2019-11-20 13:33:56.998 22940-23082/org.freedesktop.gstreamer.tutorials.tutorial_3 E/GStreamer+gldebug: 0:00:40.498616587 0x717b1f9400 ../gst-libs/gst/gl/gstgldebug.c:307:_gst_gl_debug_callback:<glcontextegl1> high: GL error from API id:1, Error:glBeginQueryEXT::failed to allocate CPU memory
2019-11-20 13:33:56.998 22940-23082/org.freedesktop.gstreamer.tutorials.tutorial_3 E/GStreamer+gldebug: 0:00:40.499609894 0x717b1f9400 ../gst-libs/gst/gl/gstgldebug.c:307:_gst_gl_debug_callback:<glcontextegl1> high: GL error from API id:149, Error:glEndQueryEXT::query name is 0
2019-11-20 13:33:56.999 22940-23082/org.freedesktop.gstreamer.tutorials.tutorial_3 E/GStreamer+gldebug: 0:00:40.499794818 0x717b1f9400 ../gst-libs/gst/gl/gstgldebug.c:307:_gst_gl_debug_callback:<glcontextegl1> high: GL error from API id:1, Error:glBeginQueryEXT::failed to allocate CPU memory
2019-11-20 13:33:56.999 22940-23082/org.freedesktop.gstreamer.tutorials.tutorial_3 E/GStreamer+gldebug: 0:00:40.500697125 0x717b1f9400 ../gst-libs/gst/gl/gstgldebug.c:307:_gst_gl_debug_callback:<glcontextegl1> high: GL error from API id:149, Error:glEndQueryEXT::query name is 0
2019-11-20 13:33:57.001 22940-23082/org.freedesktop.gstreamer.tutorials.tutorial_3 E/GStreamer+gldebug: 0:00:40.502285471 0x717b1f9400 ../gst-libs/gst/gl/gstgldebug.c:307:_gst_gl_debug_callback:<glcontextegl1> high: GL error from API id:1, Error:glBeginQueryEXT::failed to allocate CPU memory
2019-11-20 13:33:57.001 22940-23082/org.freedesktop.gstreamer.tutorials.tutorial_3 E/GStreamer+gldebug: 0:00:40.502463087 0x717b1f9400 ../gst-libs/gst/gl/gstgldebug.c:307:_gst_gl_debug_callback:<glcontextegl1> high: GL error from API id:149, Error:glEndQueryEXT::query name is 0
2019-11-20 13:33:57.028 22940-23082/org.freedesktop.gstreamer.tutorials.tutorial_3 D/mali_winsys: EGLint new_window_surface(egl_winsys_display *, void *, EGLSurface, EGLConfig, egl_winsys_surface **, EGLBoolean) returns 0x3000
2019-11-20 13:33:57.057 22940-23059/org.freedesktop.gstreamer.tutorials.tutorial_3 D/GStreamer+tutorial-3: 0:00:40.558404894 0x717b055090 /Users/radek/dev/StudioProjects/gst-docs/examples/tutorials/android/android-tutorial-3/jni/tutorial-3.c:97:set_ui_message Setting message to: State changed to PLAYING
2019-11-20 13:33:57.093 22940-23082/org.freedesktop.gstreamer.tutorials.tutorial_3 E/GStreamer+gldebug: 0:00:40.594268125 0x717b1f9400 ../gst-libs/gst/gl/gstgldebug.c:307:_gst_gl_debug_callback:<glcontextegl1> high: GL error from API id:151, Error:glGetQueryObjectui64vEXT::invalid query object
2019-11-20 13:33:57.096 22940-23082/org.freedesktop.gstreamer.tutorials.tutorial_3 E/GStreamer+gldebug: 0:00:40.596843356 0x717b1f9400 ../gst-libs/gst/gl/gstgldebug.c:307:_gst_gl_debug_callback:<glcontextegl1> high: GL error from API id:151, Error:glGetQueryObjectui64vEXT::invalid query object
2019-11-20 13:33:57.099 22940-23082/org.freedesktop.gstreamer.tutorials.tutorial_3 E/GStreamer+gldebug: 0:00:40.600435779 0x717b1f9400 ../gst-libs/gst/gl/gstgldebug.c:307:_gst_gl_debug_callback:<glcontextegl1> high: GL error from API id:151, Error:glGetQueryObjectui64vEXT::invalid query object
2019-11-20 13:34:06.459 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.959991772 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.459 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.960143734 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.459 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.960289465 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.459 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.960433234 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.459 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.960561618 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.459 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.960688349 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.460 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.960815503 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.460 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.960941618 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.460 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.961071618 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.460 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.961200888 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.460 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.961325657 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.461 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.962256080 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.461 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.962511811 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.461 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.962655965 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.462 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.962811465 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.462 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.962956503 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.462 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.963086965 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.462 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.963211542 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.462 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.963336965 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.462 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.963463426 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.462 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.963592272 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.462 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.963717811 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.463 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.963869234 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.463 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.964007195 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.463 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.964146118 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.463 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.964283234 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.463 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.964451157 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.463 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.964586465 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.463 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.964723388 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.464 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.964858849 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.464 22940-23095/org.freedesktop.gstreamer.tutorials.tutorial_3 W/GStreamer+rtpjpegdepay: 0:00:49.964997195 0x717b0471e0 ../gst/rtp/gstrtpjpegdepay.c:759:gst_rtp_jpeg_depay_process:<rtpjpegdepay0> discarding data packets received when we have no header
2019-11-20 13:34:06.734 22940-23426/org.freedesktop.gstreamer.tutorials.tutorial_3 D/TCPServerDebug: Received message: null
2019-11-20 13:34:06.735 22940-23426/org.freedesktop.gstreamer.tutorials.tutorial_3 D/TCPServerDebug: Received message: null
2019-11-20 13:34:06.736 22940-23426/org.freedesktop.gstreamer.tutorials.tutorial_3 D/TCPServerDebug: Received message: null
2019-11-20 13:34:06.759 22940-23426/org.freedesktop.gstreamer.tutorials.tutorial_3 I/chatty: uid=11215(org.freedesktop.gstreamer.tutorials.tutorial_3) Thread-7 identical 6 lines
2019-11-20 13:34:06.761 22940-23426/org.freedesktop.gstreamer.tutorials.tutorial_3 D/TCPServerDebug: Received message: null
2019-11-20 13:34:06.763 22940-23426/org.freedesktop.gstreamer.tutorials.tutorial_3 D/TCPServerDebug: Received message: null
2019-11-20 13:34:06.764 22940-23426/org.freedesktop.gstreamer.tutorials.tutorial_3 D/TCPServerDebug: Received message: null
2019-11-20 13:34:06.765 22940-23426/org.freedesktop.gstreamer.tutorials.tutorial_3 D/TCPServerDebug: Received message: null
2019-11-20 13:34:06.766 22940-23426/org.freedesktop.gstreamer.tutorials.tutorial_3 D/TCPServerDebug: Received message: null
android udp gstreamer serversocket
1个回答
0
投票

看起来问题在于保持连接的活动状态,keepAlive方法毫不费力地做任何事情,但是每当我继续向客户端发送空消息时,视频就会继续运行。

© www.soinside.com 2019 - 2024. All rights reserved.