|
36 | 36 | import com.smartdevicelink.proxy.interfaces.IVideoStreamListener; |
37 | 37 | import com.smartdevicelink.streaming.AbstractPacketizer; |
38 | 38 | import com.smartdevicelink.streaming.IStreamListener; |
| 39 | +import com.smartdevicelink.util.DebugTool; |
39 | 40 |
|
40 | 41 | import java.io.IOException; |
41 | 42 | import java.nio.ByteBuffer; |
|
62 | 63 | */ |
63 | 64 | public class RTPH264Packetizer extends AbstractPacketizer implements IVideoStreamListener, Runnable { |
64 | 65 |
|
| 66 | + private static final String TAG = "RTPH264Packetizer"; |
| 67 | + |
65 | 68 | // Approximate size of data that mOutputQueue can hold in bytes. |
66 | 69 | // By adding a buffer, we accept underlying transport being stuck for a short time. By setting |
67 | 70 | // a limit of the buffer size, we avoid buffer overflows when underlying transport is too slow. |
@@ -170,6 +173,10 @@ public void start() throws IOException { |
170 | 173 | return; |
171 | 174 | } |
172 | 175 |
|
| 176 | + if(mOutputQueue != null){ |
| 177 | + mOutputQueue.clear(); |
| 178 | + } |
| 179 | + |
173 | 180 | mThread = new Thread(this); |
174 | 181 | mThread.start(); |
175 | 182 | } |
@@ -293,13 +300,18 @@ private void onEncoderOutput(NALUnitReader nalUnitReader, long ptsInUs) { |
293 | 300 | } |
294 | 301 |
|
295 | 302 | private boolean outputRTPFrames(ByteBuffer nalUnit, long ptsInUs, boolean isLast) { |
| 303 | + if((mThread == null || mThread.isInterrupted())) { |
| 304 | + DebugTool.logError(TAG, "Dropping potential buffer because consumer thread is not alive"); |
| 305 | + return false; |
| 306 | + } |
| 307 | + |
296 | 308 | if (RTP_HEADER_LEN + nalUnit.remaining() > MAX_RTP_PACKET_SIZE) { |
297 | 309 | // Split into multiple Fragmentation Units ([5.8] in RFC 6184) |
298 | 310 | byte firstByte = nalUnit.get(); |
299 | 311 | boolean firstFragment = true; |
300 | 312 | boolean lastFragment = false; |
301 | 313 |
|
302 | | - while (nalUnit.remaining() > 0) { |
| 314 | + while (nalUnit.remaining() > 0 && mThread != null && !mThread.isInterrupted()) { |
303 | 315 | int payloadLength = MAX_RTP_PACKET_SIZE - (RTP_HEADER_LEN + FU_INDICATOR_LEN + FU_HEADER_LEN); |
304 | 316 | if (nalUnit.remaining() <= payloadLength) { |
305 | 317 | payloadLength = nalUnit.remaining(); |
|
0 commit comments