正在显示
5 个修改的文件
包含
105 行增加
和
83 行删除
| @@ -30,26 +30,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -30,26 +30,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 30 | #include <srs_kernel_codec.hpp> | 30 | #include <srs_kernel_codec.hpp> |
| 31 | #include <srs_kernel_stream.hpp> | 31 | #include <srs_kernel_stream.hpp> |
| 32 | 32 | ||
| 33 | -SrsCodecBuffer::SrsCodecBuffer() | 33 | +SrsCodecSampleUnit::SrsCodecSampleUnit() |
| 34 | { | 34 | { |
| 35 | size = 0; | 35 | size = 0; |
| 36 | bytes = NULL; | 36 | bytes = NULL; |
| 37 | } | 37 | } |
| 38 | 38 | ||
| 39 | -void SrsCodecBuffer::append(void* data, int len) | 39 | +SrsCodecSampleUnit::~SrsCodecSampleUnit() |
| 40 | { | 40 | { |
| 41 | - srs_assert(data); | ||
| 42 | - srs_assert(len > 0); | ||
| 43 | - | ||
| 44 | - bytes = (char*)realloc(bytes, size + len); | ||
| 45 | - memcpy(bytes + size, data, len); | ||
| 46 | - size += len; | ||
| 47 | -} | ||
| 48 | - | ||
| 49 | -void SrsCodecBuffer::free() | ||
| 50 | -{ | ||
| 51 | - size = 0; | ||
| 52 | - srs_freep(bytes); | ||
| 53 | } | 41 | } |
| 54 | 42 | ||
| 55 | SrsCodecSample::SrsCodecSample() | 43 | SrsCodecSample::SrsCodecSample() |
| @@ -64,7 +52,7 @@ SrsCodecSample::~SrsCodecSample() | @@ -64,7 +52,7 @@ SrsCodecSample::~SrsCodecSample() | ||
| 64 | void SrsCodecSample::clear() | 52 | void SrsCodecSample::clear() |
| 65 | { | 53 | { |
| 66 | is_video = false; | 54 | is_video = false; |
| 67 | - nb_buffers = 0; | 55 | + nb_sample_units = 0; |
| 68 | 56 | ||
| 69 | cts = 0; | 57 | cts = 0; |
| 70 | frame_type = SrsCodecVideoAVCFrameReserved; | 58 | frame_type = SrsCodecVideoAVCFrameReserved; |
| @@ -76,20 +64,20 @@ void SrsCodecSample::clear() | @@ -76,20 +64,20 @@ void SrsCodecSample::clear() | ||
| 76 | aac_packet_type = SrsCodecAudioTypeReserved; | 64 | aac_packet_type = SrsCodecAudioTypeReserved; |
| 77 | } | 65 | } |
| 78 | 66 | ||
| 79 | -int SrsCodecSample::add_sample(char* bytes, int size) | 67 | +int SrsCodecSample::add_sample_unit(char* bytes, int size) |
| 80 | { | 68 | { |
| 81 | int ret = ERROR_SUCCESS; | 69 | int ret = ERROR_SUCCESS; |
| 82 | 70 | ||
| 83 | - if (nb_buffers >= SRS_MAX_CODEC_SAMPLE) { | 71 | + if (nb_sample_units >= SRS_MAX_CODEC_SAMPLE) { |
| 84 | ret = ERROR_HLS_DECODE_ERROR; | 72 | ret = ERROR_HLS_DECODE_ERROR; |
| 85 | srs_error("hls decode samples error, " | 73 | srs_error("hls decode samples error, " |
| 86 | "exceed the max count: %d, ret=%d", SRS_MAX_CODEC_SAMPLE, ret); | 74 | "exceed the max count: %d, ret=%d", SRS_MAX_CODEC_SAMPLE, ret); |
| 87 | return ret; | 75 | return ret; |
| 88 | } | 76 | } |
| 89 | 77 | ||
| 90 | - SrsCodecBuffer* buf = &buffers[nb_buffers++]; | ||
| 91 | - buf->bytes = bytes; | ||
| 92 | - buf->size = size; | 78 | + SrsCodecSampleUnit* sample_unit = &sample_units[nb_sample_units++]; |
| 79 | + sample_unit->bytes = bytes; | ||
| 80 | + sample_unit->size = size; | ||
| 93 | 81 | ||
| 94 | return ret; | 82 | return ret; |
| 95 | } | 83 | } |
| @@ -239,7 +227,7 @@ int SrsAvcAacCodec::audio_aac_demux(char* data, int size, SrsCodecSample* sample | @@ -239,7 +227,7 @@ int SrsAvcAacCodec::audio_aac_demux(char* data, int size, SrsCodecSample* sample | ||
| 239 | 227 | ||
| 240 | // Raw AAC frame data in UI8 [] | 228 | // Raw AAC frame data in UI8 [] |
| 241 | // 6.3 Raw Data, aac-iso-13818-7.pdf, page 28 | 229 | // 6.3 Raw Data, aac-iso-13818-7.pdf, page 28 |
| 242 | - if ((ret = sample->add_sample(stream->data() + stream->pos(), stream->size() - stream->pos())) != ERROR_SUCCESS) { | 230 | + if ((ret = sample->add_sample_unit(stream->data() + stream->pos(), stream->size() - stream->pos())) != ERROR_SUCCESS) { |
| 243 | srs_error("hls add audio sample failed. ret=%d", ret); | 231 | srs_error("hls add audio sample failed. ret=%d", ret); |
| 244 | return ret; | 232 | return ret; |
| 245 | } | 233 | } |
| @@ -445,7 +433,7 @@ int SrsAvcAacCodec::video_avc_demux(char* data, int size, SrsCodecSample* sample | @@ -445,7 +433,7 @@ int SrsAvcAacCodec::video_avc_demux(char* data, int size, SrsCodecSample* sample | ||
| 445 | return ret; | 433 | return ret; |
| 446 | } | 434 | } |
| 447 | // 7.3.1 NAL unit syntax, H.264-AVC-ISO_IEC_14496-10.pdf, page 44. | 435 | // 7.3.1 NAL unit syntax, H.264-AVC-ISO_IEC_14496-10.pdf, page 44. |
| 448 | - if ((ret = sample->add_sample(stream->data() + stream->pos(), NALUnitLength)) != ERROR_SUCCESS) { | 436 | + if ((ret = sample->add_sample_unit(stream->data() + stream->pos(), NALUnitLength)) != ERROR_SUCCESS) { |
| 449 | srs_error("hls add video sample failed. ret=%d", ret); | 437 | srs_error("hls add video sample failed. ret=%d", ret); |
| 450 | return ret; | 438 | return ret; |
| 451 | } | 439 | } |
| @@ -89,30 +89,38 @@ enum SrsCodecAudioSoundType | @@ -89,30 +89,38 @@ enum SrsCodecAudioSoundType | ||
| 89 | }; | 89 | }; |
| 90 | 90 | ||
| 91 | /** | 91 | /** |
| 92 | -* buffer indicates the position and size. | 92 | +* the codec sample unit. |
| 93 | +* for h.264 video packet, a NALU is a sample unit. | ||
| 94 | +* for aac raw audio packet, a NALU is the entire aac raw data. | ||
| 95 | +* for sequence header, it's not a sample unit. | ||
| 93 | */ | 96 | */ |
| 94 | -class SrsCodecBuffer | 97 | +class SrsCodecSampleUnit |
| 95 | { | 98 | { |
| 96 | public: | 99 | public: |
| 97 | /** | 100 | /** |
| 98 | - * @remark user must manage the bytes. | 101 | + * the sample bytes is directly ptr to packet bytes, |
| 102 | + * user should never use it when packet destroyed. | ||
| 99 | */ | 103 | */ |
| 100 | int size; | 104 | int size; |
| 101 | char* bytes; | 105 | char* bytes; |
| 102 | public: | 106 | public: |
| 103 | - SrsCodecBuffer(); | ||
| 104 | - void append(void* data, int len); | ||
| 105 | -public: | ||
| 106 | - /** | ||
| 107 | - * free the bytes, | ||
| 108 | - * user can invoke it to free the bytes, | ||
| 109 | - * the SrsCodecBuffer never free automatically. | ||
| 110 | - */ | ||
| 111 | - void free(); | 107 | + SrsCodecSampleUnit(); |
| 108 | + virtual ~SrsCodecSampleUnit(); | ||
| 112 | }; | 109 | }; |
| 113 | 110 | ||
| 114 | /** | 111 | /** |
| 115 | * the samples in the flv audio/video packet. | 112 | * the samples in the flv audio/video packet. |
| 113 | +* the sample used to analysis a video/audio packet, | ||
| 114 | +* split the h.264 NALUs to buffers, or aac raw data to a buffer, | ||
| 115 | +* and decode the video/audio specified infos. | ||
| 116 | +* | ||
| 117 | +* the sample unit: | ||
| 118 | +* a video packet codec in h.264 contains many NALUs, each is a sample unit. | ||
| 119 | +* a audio packet codec in aac is a sample unit. | ||
| 120 | +* @remark, the video/audio sequence header is not sample unit, | ||
| 121 | +* all sequence header stores as extra data, | ||
| 122 | +* @see SrsAvcAacCodec.avc_extra_data and SrsAvcAacCodec.aac_extra_data | ||
| 123 | +* @remark, user must clear all samples before decode a new video/audio packet. | ||
| 116 | */ | 124 | */ |
| 117 | class SrsCodecSample | 125 | class SrsCodecSample |
| 118 | { | 126 | { |
| @@ -123,12 +131,14 @@ public: | @@ -123,12 +131,14 @@ public: | ||
| 123 | * generally, aac audio packet corresponding to one buffer, | 131 | * generally, aac audio packet corresponding to one buffer, |
| 124 | * where avc/h264 video packet may contains multiple buffer. | 132 | * where avc/h264 video packet may contains multiple buffer. |
| 125 | */ | 133 | */ |
| 126 | - int nb_buffers; | ||
| 127 | - SrsCodecBuffer buffers[SRS_MAX_CODEC_SAMPLE]; | 134 | + int nb_sample_units; |
| 135 | + SrsCodecSampleUnit sample_units[SRS_MAX_CODEC_SAMPLE]; | ||
| 128 | public: | 136 | public: |
| 129 | bool is_video; | 137 | bool is_video; |
| 130 | - // CompositionTime, video_file_format_spec_v10_1.pdf, page 78. | ||
| 131 | - // cts = pts - dts, where dts = flvheader->timestamp. | 138 | + /** |
| 139 | + * CompositionTime, video_file_format_spec_v10_1.pdf, page 78. | ||
| 140 | + * cts = pts - dts, where dts = flvheader->timestamp. | ||
| 141 | + */ | ||
| 132 | int32_t cts; | 142 | int32_t cts; |
| 133 | public: | 143 | public: |
| 134 | // video specified | 144 | // video specified |
| @@ -143,13 +153,37 @@ public: | @@ -143,13 +153,37 @@ public: | ||
| 143 | public: | 153 | public: |
| 144 | SrsCodecSample(); | 154 | SrsCodecSample(); |
| 145 | virtual ~SrsCodecSample(); | 155 | virtual ~SrsCodecSample(); |
| 156 | +public: | ||
| 157 | + /** | ||
| 158 | + * clear all samples. | ||
| 159 | + * the sample units never copy the bytes, it directly use the ptr, | ||
| 160 | + * so when video/audio packet is destroyed, the sample must be clear. | ||
| 161 | + * in a word, user must clear sample before demux it. | ||
| 162 | + * @remark demux sample use SrsAvcAacCodec.audio_aac_demux or video_avc_demux. | ||
| 163 | + */ | ||
| 146 | void clear(); | 164 | void clear(); |
| 147 | - int add_sample(char* bytes, int size); | 165 | + /** |
| 166 | + * add the a sample unit, it's a h.264 NALU or aac raw data. | ||
| 167 | + * the sample unit directly use the ptr of packet bytes, | ||
| 168 | + * so user must never use sample unit when packet is destroyed. | ||
| 169 | + * in a word, user must clear sample before demux it. | ||
| 170 | + */ | ||
| 171 | + int add_sample_unit(char* bytes, int size); | ||
| 148 | }; | 172 | }; |
| 149 | 173 | ||
| 150 | /** | 174 | /** |
| 151 | * the h264/avc and aac codec, for media stream. | 175 | * the h264/avc and aac codec, for media stream. |
| 152 | -* to decode the stream of avc/aac for hls. | 176 | +* |
| 177 | +* to demux the FLV/RTMP video/audio packet to sample, | ||
| 178 | +* add each NALUs of h.264 as a sample unit to sample, | ||
| 179 | +* while the entire aac raw data as a sample unit. | ||
| 180 | +* | ||
| 181 | +* for sequence header, | ||
| 182 | +* demux it and save it in the avc_extra_data and aac_extra_data, | ||
| 183 | +* | ||
| 184 | +* for the codec info, such as audio sample rate, | ||
| 185 | +* decode from FLV/RTMP header, then use codec info in sequence | ||
| 186 | +* header to override it. | ||
| 153 | */ | 187 | */ |
| 154 | class SrsAvcAacCodec | 188 | class SrsAvcAacCodec |
| 155 | { | 189 | { |
| @@ -68,6 +68,7 @@ using namespace std; | @@ -68,6 +68,7 @@ using namespace std; | ||
| 68 | #include <srs_kernel_utility.hpp> | 68 | #include <srs_kernel_utility.hpp> |
| 69 | #include <srs_app_avc_aac.hpp> | 69 | #include <srs_app_avc_aac.hpp> |
| 70 | #include <srs_kernel_file.hpp> | 70 | #include <srs_kernel_file.hpp> |
| 71 | +#include <srs_kernel_buffer.hpp> | ||
| 71 | 72 | ||
| 72 | // max PES packets size to flush the video. | 73 | // max PES packets size to flush the video. |
| 73 | #define SRS_AUTO_HLS_AUDIO_CACHE_SIZE 1024 * 1024 | 74 | #define SRS_AUTO_HLS_AUDIO_CACHE_SIZE 1024 * 1024 |
| @@ -195,16 +196,16 @@ public: | @@ -195,16 +196,16 @@ public: | ||
| 195 | 196 | ||
| 196 | return ret; | 197 | return ret; |
| 197 | } | 198 | } |
| 198 | - static int write_frame(SrsFileWriter* writer, SrsMpegtsFrame* frame, SrsCodecBuffer* buffer) | 199 | + static int write_frame(SrsFileWriter* writer, SrsMpegtsFrame* frame, SrsBuffer* buffer) |
| 199 | { | 200 | { |
| 200 | int ret = ERROR_SUCCESS; | 201 | int ret = ERROR_SUCCESS; |
| 201 | 202 | ||
| 202 | - if (!buffer->bytes || buffer->size <= 0) { | 203 | + if (!buffer->bytes() || buffer->length() <= 0) { |
| 203 | return ret; | 204 | return ret; |
| 204 | } | 205 | } |
| 205 | 206 | ||
| 206 | - char* last = buffer->bytes + buffer->size; | ||
| 207 | - char* pos = buffer->bytes; | 207 | + char* last = buffer->bytes() + buffer->length(); |
| 208 | + char* pos = buffer->bytes(); | ||
| 208 | 209 | ||
| 209 | bool first = true; | 210 | bool first = true; |
| 210 | while (pos < last) { | 211 | while (pos < last) { |
| @@ -478,7 +479,7 @@ int SrsTSMuxer::open(string _path) | @@ -478,7 +479,7 @@ int SrsTSMuxer::open(string _path) | ||
| 478 | return ret; | 479 | return ret; |
| 479 | } | 480 | } |
| 480 | 481 | ||
| 481 | -int SrsTSMuxer::write_audio(SrsMpegtsFrame* af, SrsCodecBuffer* ab) | 482 | +int SrsTSMuxer::write_audio(SrsMpegtsFrame* af, SrsBuffer* ab) |
| 482 | { | 483 | { |
| 483 | int ret = ERROR_SUCCESS; | 484 | int ret = ERROR_SUCCESS; |
| 484 | 485 | ||
| @@ -489,7 +490,7 @@ int SrsTSMuxer::write_audio(SrsMpegtsFrame* af, SrsCodecBuffer* ab) | @@ -489,7 +490,7 @@ int SrsTSMuxer::write_audio(SrsMpegtsFrame* af, SrsCodecBuffer* ab) | ||
| 489 | return ret; | 490 | return ret; |
| 490 | } | 491 | } |
| 491 | 492 | ||
| 492 | -int SrsTSMuxer::write_video(SrsMpegtsFrame* vf, SrsCodecBuffer* vb) | 493 | +int SrsTSMuxer::write_video(SrsMpegtsFrame* vf, SrsBuffer* vb) |
| 493 | { | 494 | { |
| 494 | int ret = ERROR_SUCCESS; | 495 | int ret = ERROR_SUCCESS; |
| 495 | 496 | ||
| @@ -651,7 +652,7 @@ bool SrsHlsMuxer::is_segment_overflow() | @@ -651,7 +652,7 @@ bool SrsHlsMuxer::is_segment_overflow() | ||
| 651 | return current->duration >= hls_fragment; | 652 | return current->duration >= hls_fragment; |
| 652 | } | 653 | } |
| 653 | 654 | ||
| 654 | -int SrsHlsMuxer::flush_audio(SrsMpegtsFrame* af, SrsCodecBuffer* ab) | 655 | +int SrsHlsMuxer::flush_audio(SrsMpegtsFrame* af, SrsBuffer* ab) |
| 655 | { | 656 | { |
| 656 | int ret = ERROR_SUCCESS; | 657 | int ret = ERROR_SUCCESS; |
| 657 | 658 | ||
| @@ -661,7 +662,7 @@ int SrsHlsMuxer::flush_audio(SrsMpegtsFrame* af, SrsCodecBuffer* ab) | @@ -661,7 +662,7 @@ int SrsHlsMuxer::flush_audio(SrsMpegtsFrame* af, SrsCodecBuffer* ab) | ||
| 661 | return ret; | 662 | return ret; |
| 662 | } | 663 | } |
| 663 | 664 | ||
| 664 | - if (ab->size <= 0) { | 665 | + if (ab->length() <= 0) { |
| 665 | return ret; | 666 | return ret; |
| 666 | } | 667 | } |
| 667 | 668 | ||
| @@ -673,13 +674,12 @@ int SrsHlsMuxer::flush_audio(SrsMpegtsFrame* af, SrsCodecBuffer* ab) | @@ -673,13 +674,12 @@ int SrsHlsMuxer::flush_audio(SrsMpegtsFrame* af, SrsCodecBuffer* ab) | ||
| 673 | } | 674 | } |
| 674 | 675 | ||
| 675 | // write success, clear and free the buffer | 676 | // write success, clear and free the buffer |
| 676 | - ab->free(); | 677 | + ab->erase(ab->length()); |
| 677 | 678 | ||
| 678 | return ret; | 679 | return ret; |
| 679 | } | 680 | } |
| 680 | 681 | ||
| 681 | -int SrsHlsMuxer::flush_video( | ||
| 682 | - SrsMpegtsFrame* af, SrsCodecBuffer* ab, SrsMpegtsFrame* vf, SrsCodecBuffer* vb) | 682 | +int SrsHlsMuxer::flush_video(SrsMpegtsFrame* af, SrsBuffer* ab, SrsMpegtsFrame* vf, SrsBuffer* vb) |
| 683 | { | 683 | { |
| 684 | int ret = ERROR_SUCCESS; | 684 | int ret = ERROR_SUCCESS; |
| 685 | 685 | ||
| @@ -699,7 +699,7 @@ int SrsHlsMuxer::flush_video( | @@ -699,7 +699,7 @@ int SrsHlsMuxer::flush_video( | ||
| 699 | } | 699 | } |
| 700 | 700 | ||
| 701 | // write success, clear and free the buffer | 701 | // write success, clear and free the buffer |
| 702 | - vb->free(); | 702 | + vb->erase(vb->length()); |
| 703 | 703 | ||
| 704 | return ret; | 704 | return ret; |
| 705 | } | 705 | } |
| @@ -962,8 +962,8 @@ SrsHlsCache::SrsHlsCache() | @@ -962,8 +962,8 @@ SrsHlsCache::SrsHlsCache() | ||
| 962 | { | 962 | { |
| 963 | aac_jitter = new SrsHlsAacJitter(); | 963 | aac_jitter = new SrsHlsAacJitter(); |
| 964 | 964 | ||
| 965 | - ab = new SrsCodecBuffer(); | ||
| 966 | - vb = new SrsCodecBuffer(); | 965 | + ab = new SrsBuffer(); |
| 966 | + vb = new SrsBuffer(); | ||
| 967 | 967 | ||
| 968 | af = new SrsMpegtsFrame(); | 968 | af = new SrsMpegtsFrame(); |
| 969 | vf = new SrsMpegtsFrame(); | 969 | vf = new SrsMpegtsFrame(); |
| @@ -975,8 +975,8 @@ SrsHlsCache::~SrsHlsCache() | @@ -975,8 +975,8 @@ SrsHlsCache::~SrsHlsCache() | ||
| 975 | { | 975 | { |
| 976 | srs_freep(aac_jitter); | 976 | srs_freep(aac_jitter); |
| 977 | 977 | ||
| 978 | - ab->free(); | ||
| 979 | - vb->free(); | 978 | + ab->erase(ab->length()); |
| 979 | + vb->erase(vb->length()); | ||
| 980 | 980 | ||
| 981 | srs_freep(ab); | 981 | srs_freep(ab); |
| 982 | srs_freep(vb); | 982 | srs_freep(vb); |
| @@ -1051,7 +1051,7 @@ int SrsHlsCache::write_audio(SrsAvcAacCodec* codec, SrsHlsMuxer* muxer, int64_t | @@ -1051,7 +1051,7 @@ int SrsHlsCache::write_audio(SrsAvcAacCodec* codec, SrsHlsMuxer* muxer, int64_t | ||
| 1051 | int ret = ERROR_SUCCESS; | 1051 | int ret = ERROR_SUCCESS; |
| 1052 | 1052 | ||
| 1053 | // start buffer, set the af | 1053 | // start buffer, set the af |
| 1054 | - if (ab->size == 0) { | 1054 | + if (ab->length() == 0) { |
| 1055 | pts = aac_jitter->on_buffer_start(pts, sample->sound_rate, codec->aac_sample_rate); | 1055 | pts = aac_jitter->on_buffer_start(pts, sample->sound_rate, codec->aac_sample_rate); |
| 1056 | 1056 | ||
| 1057 | af->dts = af->pts = audio_buffer_start_pts = pts; | 1057 | af->dts = af->pts = audio_buffer_start_pts = pts; |
| @@ -1067,7 +1067,7 @@ int SrsHlsCache::write_audio(SrsAvcAacCodec* codec, SrsHlsMuxer* muxer, int64_t | @@ -1067,7 +1067,7 @@ int SrsHlsCache::write_audio(SrsAvcAacCodec* codec, SrsHlsMuxer* muxer, int64_t | ||
| 1067 | } | 1067 | } |
| 1068 | 1068 | ||
| 1069 | // flush if buffer exceed max size. | 1069 | // flush if buffer exceed max size. |
| 1070 | - if (ab->size > SRS_AUTO_HLS_AUDIO_CACHE_SIZE) { | 1070 | + if (ab->length() > SRS_AUTO_HLS_AUDIO_CACHE_SIZE) { |
| 1071 | if ((ret = muxer->flush_audio(af, ab)) != ERROR_SUCCESS) { | 1071 | if ((ret = muxer->flush_audio(af, ab)) != ERROR_SUCCESS) { |
| 1072 | return ret; | 1072 | return ret; |
| 1073 | } | 1073 | } |
| @@ -1159,11 +1159,11 @@ int SrsHlsCache::cache_audio(SrsAvcAacCodec* codec, SrsCodecSample* sample) | @@ -1159,11 +1159,11 @@ int SrsHlsCache::cache_audio(SrsAvcAacCodec* codec, SrsCodecSample* sample) | ||
| 1159 | { | 1159 | { |
| 1160 | int ret = ERROR_SUCCESS; | 1160 | int ret = ERROR_SUCCESS; |
| 1161 | 1161 | ||
| 1162 | - for (int i = 0; i < sample->nb_buffers; i++) { | ||
| 1163 | - SrsCodecBuffer* buf = &sample->buffers[i]; | ||
| 1164 | - int32_t size = buf->size; | 1162 | + for (int i = 0; i < sample->nb_sample_units; i++) { |
| 1163 | + SrsCodecSampleUnit* sample_unit = &sample->sample_units[i]; | ||
| 1164 | + int32_t size = sample_unit->size; | ||
| 1165 | 1165 | ||
| 1166 | - if (!buf->bytes || size <= 0 || size > 0x1fff) { | 1166 | + if (!sample_unit->bytes || size <= 0 || size > 0x1fff) { |
| 1167 | ret = ERROR_HLS_AAC_FRAME_LENGTH; | 1167 | ret = ERROR_HLS_AAC_FRAME_LENGTH; |
| 1168 | srs_error("invalid aac frame length=%d, ret=%d", size, ret); | 1168 | srs_error("invalid aac frame length=%d, ret=%d", size, ret); |
| 1169 | return ret; | 1169 | return ret; |
| @@ -1215,8 +1215,8 @@ int SrsHlsCache::cache_audio(SrsAvcAacCodec* codec, SrsCodecSample* sample) | @@ -1215,8 +1215,8 @@ int SrsHlsCache::cache_audio(SrsAvcAacCodec* codec, SrsCodecSample* sample) | ||
| 1215 | adts_header[5] |= 0x1f; | 1215 | adts_header[5] |= 0x1f; |
| 1216 | 1216 | ||
| 1217 | // copy to audio buffer | 1217 | // copy to audio buffer |
| 1218 | - ab->append(adts_header, sizeof(adts_header)); | ||
| 1219 | - ab->append(buf->bytes, buf->size); | 1218 | + ab->append((const char*)adts_header, sizeof(adts_header)); |
| 1219 | + ab->append(sample_unit->bytes, sample_unit->size); | ||
| 1220 | } | 1220 | } |
| 1221 | 1221 | ||
| 1222 | return ret; | 1222 | return ret; |
| @@ -1239,11 +1239,11 @@ int SrsHlsCache::cache_video(SrsAvcAacCodec* codec, SrsCodecSample* sample) | @@ -1239,11 +1239,11 @@ int SrsHlsCache::cache_video(SrsAvcAacCodec* codec, SrsCodecSample* sample) | ||
| 1239 | * xxxxxxx // data bytes. | 1239 | * xxxxxxx // data bytes. |
| 1240 | * so, for each sample, we append header in aud_nal, then appends the bytes in sample. | 1240 | * so, for each sample, we append header in aud_nal, then appends the bytes in sample. |
| 1241 | */ | 1241 | */ |
| 1242 | - for (int i = 0; i < sample->nb_buffers; i++) { | ||
| 1243 | - SrsCodecBuffer* buf = &sample->buffers[i]; | ||
| 1244 | - int32_t size = buf->size; | 1242 | + for (int i = 0; i < sample->nb_sample_units; i++) { |
| 1243 | + SrsCodecSampleUnit* sample_unit = &sample->sample_units[i]; | ||
| 1244 | + int32_t size = sample_unit->size; | ||
| 1245 | 1245 | ||
| 1246 | - if (!buf->bytes || size <= 0) { | 1246 | + if (!sample_unit->bytes || size <= 0) { |
| 1247 | ret = ERROR_HLS_AVC_SAMPLE_SIZE; | 1247 | ret = ERROR_HLS_AVC_SAMPLE_SIZE; |
| 1248 | srs_error("invalid avc sample length=%d, ret=%d", size, ret); | 1248 | srs_error("invalid avc sample length=%d, ret=%d", size, ret); |
| 1249 | return ret; | 1249 | return ret; |
| @@ -1259,7 +1259,7 @@ int SrsHlsCache::cache_video(SrsAvcAacCodec* codec, SrsCodecSample* sample) | @@ -1259,7 +1259,7 @@ int SrsHlsCache::cache_video(SrsAvcAacCodec* codec, SrsCodecSample* sample) | ||
| 1259 | // 5bits, 7.3.1 NAL unit syntax, | 1259 | // 5bits, 7.3.1 NAL unit syntax, |
| 1260 | // H.264-AVC-ISO_IEC_14496-10.pdf, page 44. | 1260 | // H.264-AVC-ISO_IEC_14496-10.pdf, page 44. |
| 1261 | u_int8_t nal_unit_type; | 1261 | u_int8_t nal_unit_type; |
| 1262 | - nal_unit_type = *buf->bytes; | 1262 | + nal_unit_type = *sample_unit->bytes; |
| 1263 | nal_unit_type &= 0x1f; | 1263 | nal_unit_type &= 0x1f; |
| 1264 | 1264 | ||
| 1265 | // @see: ngx_rtmp_hls_video | 1265 | // @see: ngx_rtmp_hls_video |
| @@ -1277,7 +1277,7 @@ int SrsHlsCache::cache_video(SrsAvcAacCodec* codec, SrsCodecSample* sample) | @@ -1277,7 +1277,7 @@ int SrsHlsCache::cache_video(SrsAvcAacCodec* codec, SrsCodecSample* sample) | ||
| 1277 | } | 1277 | } |
| 1278 | if (nal_unit_type == 1 || nal_unit_type == 5 || nal_unit_type == 6) { | 1278 | if (nal_unit_type == 1 || nal_unit_type == 5 || nal_unit_type == 6) { |
| 1279 | // for type 6, append a aud with type 9. | 1279 | // for type 6, append a aud with type 9. |
| 1280 | - vb->append(aud_nal, sizeof(aud_nal)); | 1280 | + vb->append((const char*)aud_nal, sizeof(aud_nal)); |
| 1281 | aud_sent = true; | 1281 | aud_sent = true; |
| 1282 | } | 1282 | } |
| 1283 | } | 1283 | } |
| @@ -1290,13 +1290,13 @@ int SrsHlsCache::cache_video(SrsAvcAacCodec* codec, SrsCodecSample* sample) | @@ -1290,13 +1290,13 @@ int SrsHlsCache::cache_video(SrsAvcAacCodec* codec, SrsCodecSample* sample) | ||
| 1290 | // @see: ngx_rtmp_hls_append_sps_pps | 1290 | // @see: ngx_rtmp_hls_append_sps_pps |
| 1291 | if (codec->sequenceParameterSetLength > 0) { | 1291 | if (codec->sequenceParameterSetLength > 0) { |
| 1292 | // AnnexB prefix, for sps always 4 bytes header | 1292 | // AnnexB prefix, for sps always 4 bytes header |
| 1293 | - vb->append(aud_nal, 4); | 1293 | + vb->append((const char*)aud_nal, 4); |
| 1294 | // sps | 1294 | // sps |
| 1295 | vb->append(codec->sequenceParameterSetNALUnit, codec->sequenceParameterSetLength); | 1295 | vb->append(codec->sequenceParameterSetNALUnit, codec->sequenceParameterSetLength); |
| 1296 | } | 1296 | } |
| 1297 | if (codec->pictureParameterSetLength > 0) { | 1297 | if (codec->pictureParameterSetLength > 0) { |
| 1298 | // AnnexB prefix, for pps always 4 bytes header | 1298 | // AnnexB prefix, for pps always 4 bytes header |
| 1299 | - vb->append(aud_nal, 4); | 1299 | + vb->append((const char*)aud_nal, 4); |
| 1300 | // pps | 1300 | // pps |
| 1301 | vb->append(codec->pictureParameterSetNALUnit, codec->pictureParameterSetLength); | 1301 | vb->append(codec->pictureParameterSetNALUnit, codec->pictureParameterSetLength); |
| 1302 | } | 1302 | } |
| @@ -1318,13 +1318,13 @@ int SrsHlsCache::cache_video(SrsAvcAacCodec* codec, SrsCodecSample* sample) | @@ -1318,13 +1318,13 @@ int SrsHlsCache::cache_video(SrsAvcAacCodec* codec, SrsCodecSample* sample) | ||
| 1318 | u_int8_t* end = p + 3; | 1318 | u_int8_t* end = p + 3; |
| 1319 | 1319 | ||
| 1320 | // first AnnexB prefix is long (4 bytes) | 1320 | // first AnnexB prefix is long (4 bytes) |
| 1321 | - if (vb->size == 0) { | 1321 | + if (vb->length() == 0) { |
| 1322 | p = aud_nal; | 1322 | p = aud_nal; |
| 1323 | } | 1323 | } |
| 1324 | - vb->append(p, end - p); | 1324 | + vb->append((const char*)p, end - p); |
| 1325 | 1325 | ||
| 1326 | // sample data | 1326 | // sample data |
| 1327 | - vb->append(buf->bytes, buf->size); | 1327 | + vb->append(sample_unit->bytes, sample_unit->size); |
| 1328 | } | 1328 | } |
| 1329 | 1329 | ||
| 1330 | return ret; | 1330 | return ret; |
| @@ -50,9 +50,9 @@ extern int aac_sample_rates[]; | @@ -50,9 +50,9 @@ extern int aac_sample_rates[]; | ||
| 50 | #include <string> | 50 | #include <string> |
| 51 | #include <vector> | 51 | #include <vector> |
| 52 | 52 | ||
| 53 | +class SrsBuffer; | ||
| 53 | class SrsSharedPtrMessage; | 54 | class SrsSharedPtrMessage; |
| 54 | class SrsCodecSample; | 55 | class SrsCodecSample; |
| 55 | -class SrsCodecBuffer; | ||
| 56 | class SrsMpegtsFrame; | 56 | class SrsMpegtsFrame; |
| 57 | class SrsAmf0Object; | 57 | class SrsAmf0Object; |
| 58 | class SrsRtmpJitter; | 58 | class SrsRtmpJitter; |
| @@ -109,8 +109,8 @@ public: | @@ -109,8 +109,8 @@ public: | ||
| 109 | virtual ~SrsTSMuxer(); | 109 | virtual ~SrsTSMuxer(); |
| 110 | public: | 110 | public: |
| 111 | virtual int open(std::string _path); | 111 | virtual int open(std::string _path); |
| 112 | - virtual int write_audio(SrsMpegtsFrame* af, SrsCodecBuffer* ab); | ||
| 113 | - virtual int write_video(SrsMpegtsFrame* vf, SrsCodecBuffer* vb); | 112 | + virtual int write_audio(SrsMpegtsFrame* af, SrsBuffer* ab); |
| 113 | + virtual int write_video(SrsMpegtsFrame* vf, SrsBuffer* vb); | ||
| 114 | virtual void close(); | 114 | virtual void close(); |
| 115 | }; | 115 | }; |
| 116 | 116 | ||
| @@ -196,8 +196,8 @@ public: | @@ -196,8 +196,8 @@ public: | ||
| 196 | * that is whether the current segment duration >= the segment in config | 196 | * that is whether the current segment duration >= the segment in config |
| 197 | */ | 197 | */ |
| 198 | virtual bool is_segment_overflow(); | 198 | virtual bool is_segment_overflow(); |
| 199 | - virtual int flush_audio(SrsMpegtsFrame* af, SrsCodecBuffer* ab); | ||
| 200 | - virtual int flush_video(SrsMpegtsFrame* af, SrsCodecBuffer* ab, SrsMpegtsFrame* vf, SrsCodecBuffer* vb); | 199 | + virtual int flush_audio(SrsMpegtsFrame* af, SrsBuffer* ab); |
| 200 | + virtual int flush_video(SrsMpegtsFrame* af, SrsBuffer* ab, SrsMpegtsFrame* vf, SrsBuffer* vb); | ||
| 201 | /** | 201 | /** |
| 202 | * close segment(ts). | 202 | * close segment(ts). |
| 203 | * @param log_desc the description for log. | 203 | * @param log_desc the description for log. |
| @@ -231,9 +231,9 @@ class SrsHlsCache | @@ -231,9 +231,9 @@ class SrsHlsCache | ||
| 231 | private: | 231 | private: |
| 232 | // current frame and buffer | 232 | // current frame and buffer |
| 233 | SrsMpegtsFrame* af; | 233 | SrsMpegtsFrame* af; |
| 234 | - SrsCodecBuffer* ab; | 234 | + SrsBuffer* ab; |
| 235 | SrsMpegtsFrame* vf; | 235 | SrsMpegtsFrame* vf; |
| 236 | - SrsCodecBuffer* vb; | 236 | + SrsBuffer* vb; |
| 237 | private: | 237 | private: |
| 238 | // the audio cache buffer start pts, to flush audio if full. | 238 | // the audio cache buffer start pts, to flush audio if full. |
| 239 | int64_t audio_buffer_start_pts; | 239 | int64_t audio_buffer_start_pts; |
| @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | @@ -31,7 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 31 | // current release version | 31 | // current release version |
| 32 | #define VERSION_MAJOR "0" | 32 | #define VERSION_MAJOR "0" |
| 33 | #define VERSION_MINOR "9" | 33 | #define VERSION_MINOR "9" |
| 34 | -#define VERSION_REVISION "160" | 34 | +#define VERSION_REVISION "161" |
| 35 | #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION | 35 | #define RTMP_SIG_SRS_VERSION VERSION_MAJOR"."VERSION_MINOR"."VERSION_REVISION |
| 36 | // server info. | 36 | // server info. |
| 37 | #define RTMP_SIG_SRS_KEY "SRS" | 37 | #define RTMP_SIG_SRS_KEY "SRS" |
-
请 注册 或 登录 后发表评论