正在显示
2 个修改的文件
包含
64 行增加
和
5 行删除
| @@ -34,18 +34,20 @@ using namespace std; | @@ -34,18 +34,20 @@ using namespace std; | ||
| 34 | 34 | ||
| 35 | #include <srs_kernel_log.hpp> | 35 | #include <srs_kernel_log.hpp> |
| 36 | #include <srs_kernel_error.hpp> | 36 | #include <srs_kernel_error.hpp> |
| 37 | -#include <srs_kernel_stream.hpp> | ||
| 38 | #include <srs_kernel_file.hpp> | 37 | #include <srs_kernel_file.hpp> |
| 38 | +#include <srs_kernel_avc.hpp> | ||
| 39 | 39 | ||
| 40 | SrsTsEncoder::SrsTsEncoder() | 40 | SrsTsEncoder::SrsTsEncoder() |
| 41 | { | 41 | { |
| 42 | _fs = NULL; | 42 | _fs = NULL; |
| 43 | - tag_stream = new SrsStream(); | 43 | + codec = new SrsAvcAacCodec(); |
| 44 | + sample = new SrsCodecSample(); | ||
| 44 | } | 45 | } |
| 45 | 46 | ||
| 46 | SrsTsEncoder::~SrsTsEncoder() | 47 | SrsTsEncoder::~SrsTsEncoder() |
| 47 | { | 48 | { |
| 48 | - srs_freep(tag_stream); | 49 | + srs_freep(codec); |
| 50 | + srs_freep(sample); | ||
| 49 | } | 51 | } |
| 50 | 52 | ||
| 51 | int SrsTsEncoder::initialize(SrsFileWriter* fs) | 53 | int SrsTsEncoder::initialize(SrsFileWriter* fs) |
| @@ -68,12 +70,67 @@ int SrsTsEncoder::initialize(SrsFileWriter* fs) | @@ -68,12 +70,67 @@ int SrsTsEncoder::initialize(SrsFileWriter* fs) | ||
| 68 | int SrsTsEncoder::write_audio(int64_t timestamp, char* data, int size) | 70 | int SrsTsEncoder::write_audio(int64_t timestamp, char* data, int size) |
| 69 | { | 71 | { |
| 70 | int ret = ERROR_SUCCESS; | 72 | int ret = ERROR_SUCCESS; |
| 73 | + | ||
| 74 | + sample->clear(); | ||
| 75 | + if ((ret = codec->audio_aac_demux(data, size, sample)) != ERROR_SUCCESS) { | ||
| 76 | + srs_error("http: ts codec demux audio failed. ret=%d", ret); | ||
| 77 | + return ret; | ||
| 78 | + } | ||
| 79 | + | ||
| 80 | + if (codec->audio_codec_id != SrsCodecAudioAAC) { | ||
| 81 | + return ret; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + // ignore sequence header | ||
| 85 | + if (sample->aac_packet_type == SrsCodecAudioTypeSequenceHeader) { | ||
| 86 | + return ret; | ||
| 87 | + } | ||
| 88 | + | ||
| 89 | + // the dts calc from rtmp/flv header. | ||
| 90 | + // @remark for http ts stream, the timestamp is always monotonically increase, | ||
| 91 | + // for the packet is filtered by consumer. | ||
| 92 | + int64_t dts = timestamp * 90; | ||
| 93 | + | ||
| 94 | + /*if ((ret = hls_cache->write_audio(codec, muxer, dts, sample)) != ERROR_SUCCESS) { | ||
| 95 | + srs_error("http: ts cache write audio failed. ret=%d", ret); | ||
| 96 | + return ret; | ||
| 97 | + }*/ | ||
| 98 | + | ||
| 71 | return ret; | 99 | return ret; |
| 72 | } | 100 | } |
| 73 | 101 | ||
| 74 | int SrsTsEncoder::write_video(int64_t timestamp, char* data, int size) | 102 | int SrsTsEncoder::write_video(int64_t timestamp, char* data, int size) |
| 75 | { | 103 | { |
| 76 | int ret = ERROR_SUCCESS; | 104 | int ret = ERROR_SUCCESS; |
| 105 | + | ||
| 106 | + sample->clear(); | ||
| 107 | + if ((ret = codec->video_avc_demux(data, size, sample)) != ERROR_SUCCESS) { | ||
| 108 | + srs_error("http: ts codec demux video failed. ret=%d", ret); | ||
| 109 | + return ret; | ||
| 110 | + } | ||
| 111 | + | ||
| 112 | + // ignore info frame, | ||
| 113 | + // @see https://github.com/winlinvip/simple-rtmp-server/issues/288#issuecomment-69863909 | ||
| 114 | + if (sample->frame_type == SrsCodecVideoAVCFrameVideoInfoFrame) { | ||
| 115 | + return ret; | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + if (codec->video_codec_id != SrsCodecVideoAVC) { | ||
| 119 | + return ret; | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + // ignore sequence header | ||
| 123 | + if (sample->frame_type == SrsCodecVideoAVCFrameKeyFrame | ||
| 124 | + && sample->avc_packet_type == SrsCodecVideoAVCTypeSequenceHeader) { | ||
| 125 | + return ret; | ||
| 126 | + } | ||
| 127 | + | ||
| 128 | + int64_t dts = timestamp * 90; | ||
| 129 | + /*if ((ret = hls_cache->write_video(codec, muxer, dts, sample)) != ERROR_SUCCESS) { | ||
| 130 | + srs_error("http: ts cache write video failed. ret=%d", ret); | ||
| 131 | + return ret; | ||
| 132 | + }*/ | ||
| 133 | + | ||
| 77 | return ret; | 134 | return ret; |
| 78 | } | 135 | } |
| 79 | 136 |
| @@ -31,9 +31,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,9 +31,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 31 | 31 | ||
| 32 | #include <string> | 32 | #include <string> |
| 33 | 33 | ||
| 34 | -class SrsStream; | ||
| 35 | class SrsFileWriter; | 34 | class SrsFileWriter; |
| 36 | class SrsFileReader; | 35 | class SrsFileReader; |
| 36 | +class SrsAvcAacCodec; | ||
| 37 | +class SrsCodecSample; | ||
| 37 | 38 | ||
| 38 | /** | 39 | /** |
| 39 | * encode data to ts file. | 40 | * encode data to ts file. |
| @@ -43,7 +44,8 @@ class SrsTsEncoder | @@ -43,7 +44,8 @@ class SrsTsEncoder | ||
| 43 | private: | 44 | private: |
| 44 | SrsFileWriter* _fs; | 45 | SrsFileWriter* _fs; |
| 45 | private: | 46 | private: |
| 46 | - SrsStream* tag_stream; | 47 | + SrsAvcAacCodec* codec; |
| 48 | + SrsCodecSample* sample; | ||
| 47 | public: | 49 | public: |
| 48 | SrsTsEncoder(); | 50 | SrsTsEncoder(); |
| 49 | virtual ~SrsTsEncoder(); | 51 | virtual ~SrsTsEncoder(); |
-
请 注册 或 登录 后发表评论