From c9d270fbe06e496e976c7867af26abf172adda03 Mon Sep 17 00:00:00 2001 From: winlin Date: Sun, 25 Jan 2015 13:19:22 +0800 Subject: [PATCH] refine code for #250, ts remux --- trunk/src/app/srs_app_mpegts_udp.cpp | 8 +++----- trunk/src/kernel/srs_kernel_ts.cpp | 6 +++--- trunk/src/kernel/srs_kernel_ts.hpp | 3 +++ 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/trunk/src/app/srs_app_mpegts_udp.cpp b/trunk/src/app/srs_app_mpegts_udp.cpp index 63ab2a8e06..22b29843b1 100644 --- a/trunk/src/app/srs_app_mpegts_udp.cpp +++ b/trunk/src/app/srs_app_mpegts_udp.cpp @@ -32,9 +32,7 @@ using namespace std; #include #include #include - -// Transport Stream packets are 188 bytes in length. -#define TS_PACKET_SIZE 188 +#include #ifdef SRS_AUTO_STREAM_CASTER @@ -55,14 +53,14 @@ int SrsMpegtsOverUdp::on_udp_packet(sockaddr_in* from, char* buf, int nb_buf) int peer_port = ntohs(from->sin_port); // drop ts packet when size not modulus by 188 - if (nb_buf < TS_PACKET_SIZE || (nb_buf % TS_PACKET_SIZE) != 0) { + if (nb_buf < SRS_TS_PACKET_SIZE || (nb_buf % SRS_TS_PACKET_SIZE) != 0) { srs_warn("udp: drop %s:%d packet %d bytes", peer_ip.c_str(), peer_port, nb_buf); return ret; } srs_info("udp: got %s:%d packet %d bytes", peer_ip.c_str(), peer_port, nb_buf); // process each ts packet - for (int i = 0; i < nb_buf; i += TS_PACKET_SIZE) { + for (int i = 0; i < nb_buf; i += SRS_TS_PACKET_SIZE) { char* ts_packet = buf + i; if ((ret = on_ts_packet(ts_packet)) != ERROR_SUCCESS) { srs_warn("mpegts: ignore ts packet error. ret=%d", ret); diff --git a/trunk/src/kernel/srs_kernel_ts.cpp b/trunk/src/kernel/srs_kernel_ts.cpp index d51b68f055..e9f010fbba 100644 --- a/trunk/src/kernel/srs_kernel_ts.cpp +++ b/trunk/src/kernel/srs_kernel_ts.cpp @@ -254,11 +254,11 @@ class SrsMpegtsWriter *p++ = header_size; // pts; // 33bits - p = write_pts(p, flags >> 6, frame->pts + SRS_AUTO_HLS_DELAY); + p = write_dts_pts(p, flags >> 6, frame->pts + SRS_AUTO_HLS_DELAY); // dts; // 33bits if (frame->dts != frame->pts) { - p = write_pts(p, 1, frame->dts + SRS_AUTO_HLS_DELAY); + p = write_dts_pts(p, 1, frame->dts + SRS_AUTO_HLS_DELAY); } } @@ -344,7 +344,7 @@ class SrsMpegtsWriter return p; } - static char* write_pts(char* p, u_int8_t fb, int64_t pts) + static char* write_dts_pts(char* p, u_int8_t fb, int64_t pts) { int32_t val; diff --git a/trunk/src/kernel/srs_kernel_ts.hpp b/trunk/src/kernel/srs_kernel_ts.hpp index 4b813f7529..4ee411924c 100644 --- a/trunk/src/kernel/srs_kernel_ts.hpp +++ b/trunk/src/kernel/srs_kernel_ts.hpp @@ -39,6 +39,9 @@ class SrsAvcAacCodec; class SrsCodecSample; class SrsSimpleBuffer; +// Transport Stream packets are 188 bytes in length. +#define SRS_TS_PACKET_SIZE 188 + // @see: ngx_rtmp_SrsMpegtsFrame_t class SrsMpegtsFrame {