winlin

refine code for #250, ts remux

@@ -32,9 +32,7 @@ using namespace std; @@ -32,9 +32,7 @@ using namespace std;
32 #include <srs_kernel_error.hpp> 32 #include <srs_kernel_error.hpp>
33 #include <srs_kernel_log.hpp> 33 #include <srs_kernel_log.hpp>
34 #include <srs_app_config.hpp> 34 #include <srs_app_config.hpp>
35 -  
36 -// Transport Stream packets are 188 bytes in length.  
37 -#define TS_PACKET_SIZE 188 35 +#include <srs_kernel_ts.hpp>
38 36
39 #ifdef SRS_AUTO_STREAM_CASTER 37 #ifdef SRS_AUTO_STREAM_CASTER
40 38
@@ -55,14 +53,14 @@ int SrsMpegtsOverUdp::on_udp_packet(sockaddr_in* from, char* buf, int nb_buf) @@ -55,14 +53,14 @@ int SrsMpegtsOverUdp::on_udp_packet(sockaddr_in* from, char* buf, int nb_buf)
55 int peer_port = ntohs(from->sin_port); 53 int peer_port = ntohs(from->sin_port);
56 54
57 // drop ts packet when size not modulus by 188 55 // drop ts packet when size not modulus by 188
58 - if (nb_buf < TS_PACKET_SIZE || (nb_buf % TS_PACKET_SIZE) != 0) { 56 + if (nb_buf < SRS_TS_PACKET_SIZE || (nb_buf % SRS_TS_PACKET_SIZE) != 0) {
59 srs_warn("udp: drop %s:%d packet %d bytes", peer_ip.c_str(), peer_port, nb_buf); 57 srs_warn("udp: drop %s:%d packet %d bytes", peer_ip.c_str(), peer_port, nb_buf);
60 return ret; 58 return ret;
61 } 59 }
62 srs_info("udp: got %s:%d packet %d bytes", peer_ip.c_str(), peer_port, nb_buf); 60 srs_info("udp: got %s:%d packet %d bytes", peer_ip.c_str(), peer_port, nb_buf);
63 61
64 // process each ts packet 62 // process each ts packet
65 - for (int i = 0; i < nb_buf; i += TS_PACKET_SIZE) { 63 + for (int i = 0; i < nb_buf; i += SRS_TS_PACKET_SIZE) {
66 char* ts_packet = buf + i; 64 char* ts_packet = buf + i;
67 if ((ret = on_ts_packet(ts_packet)) != ERROR_SUCCESS) { 65 if ((ret = on_ts_packet(ts_packet)) != ERROR_SUCCESS) {
68 srs_warn("mpegts: ignore ts packet error. ret=%d", ret); 66 srs_warn("mpegts: ignore ts packet error. ret=%d", ret);
@@ -254,11 +254,11 @@ public: @@ -254,11 +254,11 @@ public:
254 *p++ = header_size; 254 *p++ = header_size;
255 255
256 // pts; // 33bits 256 // pts; // 33bits
257 - p = write_pts(p, flags >> 6, frame->pts + SRS_AUTO_HLS_DELAY); 257 + p = write_dts_pts(p, flags >> 6, frame->pts + SRS_AUTO_HLS_DELAY);
258 258
259 // dts; // 33bits 259 // dts; // 33bits
260 if (frame->dts != frame->pts) { 260 if (frame->dts != frame->pts) {
261 - p = write_pts(p, 1, frame->dts + SRS_AUTO_HLS_DELAY); 261 + p = write_dts_pts(p, 1, frame->dts + SRS_AUTO_HLS_DELAY);
262 } 262 }
263 } 263 }
264 264
@@ -344,7 +344,7 @@ private: @@ -344,7 +344,7 @@ private:
344 344
345 return p; 345 return p;
346 } 346 }
347 - static char* write_pts(char* p, u_int8_t fb, int64_t pts) 347 + static char* write_dts_pts(char* p, u_int8_t fb, int64_t pts)
348 { 348 {
349 int32_t val; 349 int32_t val;
350 350
@@ -39,6 +39,9 @@ class SrsAvcAacCodec; @@ -39,6 +39,9 @@ class SrsAvcAacCodec;
39 class SrsCodecSample; 39 class SrsCodecSample;
40 class SrsSimpleBuffer; 40 class SrsSimpleBuffer;
41 41
  42 +// Transport Stream packets are 188 bytes in length.
  43 +#define SRS_TS_PACKET_SIZE 188
  44 +
42 // @see: ngx_rtmp_SrsMpegtsFrame_t 45 // @see: ngx_rtmp_SrsMpegtsFrame_t
43 class SrsMpegtsFrame 46 class SrsMpegtsFrame
44 { 47 {