Im streaming video to the Android device using Gstreamer and udpsrc. Problem Im facing is that stream works for only couple of seconds and then stops (permanent freezed frame is displayed). First I create TCP server on my Android device which is used by video hosting device to connect. To do so Im using ServerSocket and threads in MainActivity:
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();
}
}
}
}
My app is basically a Gstreamer tutorial-3 (https://gstreamer.freedesktop.org/documentation/tutorials/android/video.html?gi-language=c), with ServerSocket added and where I updated the pipeline in the c code to use udpsrc
gst_parse_launch ("udpsrc buffer-size=622080 port=8001 ! application/x-rtp, encoding-name=JPEG, payload=96 ! rtpjpegdepay ! jpegdec ! autovideosink sync=false",
&error);
What happens is the video streams for couple of seconds and then just stops. While Im getting the stream the gstreamer log output is something like
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
but when the video stops it stops as well.
Can you help me narrow down where the possible issue could be? Is it possible there's something wrong with the way Im managing the TCP connection? The stream works fine on other devices.
Below is full logcat output
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
Looks like the problem is with keeping the connection alive, keepAlive method does don anything unfrotunately but whenever I keep on sending empty messages to the client the video keeps on runinng.