1
0
Fork 0
mirror of https://github.com/ossrs/srs.git synced 2025-03-09 15:49:59 +00:00

remove the analysis doc for ts

This commit is contained in:
winlin 2013-11-24 16:00:45 +08:00
parent ecc8688455
commit 19f16ba7a8
11 changed files with 108 additions and 1127 deletions

View file

@ -30,6 +30,39 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_core_log.hpp>
#include <srs_core_autofree.hpp>
SrsCodecSample::SrsCodecSample()
{
clear();
}
SrsCodecSample::~SrsCodecSample()
{
}
void SrsCodecSample::clear()
{
cts = 0;
nb_buffers = 0;
}
int SrsCodecSample::add_sample(char* bytes, int size)
{
int ret = ERROR_SUCCESS;
if (nb_buffers >= SRS_MAX_CODEC_SAMPLE) {
ret = ERROR_HLS_DECODE_ERROR;
srs_error("hls decode samples error, "
"exceed the max count: %d, ret=%d", SRS_MAX_CODEC_SAMPLE, ret);
return ret;
}
SrsCodecBuffer* buf = &buffers[nb_buffers++];
buf->bytes = bytes;
buf->size = size;
return ret;
}
SrsCodec::SrsCodec()
{
width = 0;
@ -62,7 +95,7 @@ SrsCodec::~SrsCodec()
srs_freep(stream);
}
int SrsCodec::audio_aac_demux(int8_t* data, int size)
int SrsCodec::audio_aac_demux(int8_t* data, int size, SrsCodecSample* sample)
{
int ret = ERROR_SUCCESS;
@ -109,11 +142,11 @@ int SrsCodec::audio_aac_demux(int8_t* data, int size)
if (aac_packet_type == SrsCodecAudioTypeSequenceHeader) {
// AudioSpecificConfig
// 1.6.2.1 AudioSpecificConfig, in aac-mp4a-format-ISO_IEC_14496-3+2001.pdf, page 33.
aac_extra_size = size - stream->pos();
aac_extra_size = stream->left();
if (aac_extra_size > 0) {
srs_freepa(aac_extra_data);
aac_extra_data = new char[aac_extra_size];
memcpy(aac_extra_data, data + stream->pos(), aac_extra_size);
memcpy(aac_extra_data, stream->current(), aac_extra_size);
}
} else if (aac_packet_type == SrsCodecAudioTypeRawData) {
// ensure the sequence header demuxed
@ -125,6 +158,10 @@ int SrsCodec::audio_aac_demux(int8_t* data, int size)
// Raw AAC frame data in UI8 []
// 6.3 Raw Data, aac-iso-13818-7.pdf, page 28
if ((ret = sample->add_sample(stream->current(), stream->left())) != ERROR_SUCCESS) {
srs_error("hls add audio sample failed. ret=%d", ret);
return ret;
}
} else {
// ignored.
}
@ -135,7 +172,7 @@ int SrsCodec::audio_aac_demux(int8_t* data, int size)
return ret;
}
int SrsCodec::video_avc_demux(int8_t* data, int size)
int SrsCodec::video_avc_demux(int8_t* data, int size, SrsCodecSample* sample)
{
int ret = ERROR_SUCCESS;
@ -175,17 +212,17 @@ int SrsCodec::video_avc_demux(int8_t* data, int size)
int8_t avc_packet_type = stream->read_1bytes();
int32_t composition_time = stream->read_3bytes();
// avoid warning, used it future.
(void)composition_time;
// pts = dts + cts.
sample->cts = composition_time;
if (avc_packet_type == SrsCodecVideoAVCTypeSequenceHeader) {
// AVCDecoderConfigurationRecord
// 5.2.4.1.1 Syntax, H.264-AVC-ISO_IEC_14496-15.pdf, page 16
avc_extra_size = size - stream->pos();
avc_extra_size = stream->left();
if (avc_extra_size > 0) {
srs_freepa(avc_extra_data);
avc_extra_data = new char[avc_extra_size];
memcpy(avc_extra_data, data + stream->pos(), avc_extra_size);
memcpy(avc_extra_data, stream->current(), avc_extra_size);
}
if (!stream->require(6)) {
@ -222,7 +259,7 @@ int SrsCodec::video_avc_demux(int8_t* data, int size)
// One or more NALUs (Full frames are required)
// 5.3.4.2.1 Syntax, H.264-AVC-ISO_IEC_14496-15.pdf, page 20
int PictureLength = size - stream->pos();
int PictureLength = stream->left();
for (int i = 0; i < PictureLength;) {
if (!stream->require(NAL_unit_length + 1)) {
ret = ERROR_HLS_DECODE_ERROR;
@ -246,6 +283,10 @@ int SrsCodec::video_avc_demux(int8_t* data, int size)
return ret;
}
// 7.3.1 NAL unit syntax, H.264-AVC-ISO_IEC_14496-10.pdf, page 44.
if ((ret = sample->add_sample(stream->current(), NALUnitLength)) != ERROR_SUCCESS) {
srs_error("hls add video sample failed. ret=%d", ret);
return ret;
}
stream->skip(NALUnitLength);
i += NAL_unit_length + 1 + NALUnitLength;

View file

@ -30,6 +30,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_core.hpp>
#define SRS_MAX_CODEC_SAMPLE 128
class SrsStream;
// E.4.3.1 VIDEODATA
@ -161,6 +163,33 @@ enum SrsCodecAudioSoundType
SrsCodecAudioSoundTypeStereo = 1,
};
/**
* buffer indicates the position and size.
*/
struct SrsCodecBuffer
{
int size;
char* bytes;
};
/**
* the samples in the flv audio/video packet.
*/
class SrsCodecSample
{
public:
int nb_buffers;
SrsCodecBuffer buffers[SRS_MAX_CODEC_SAMPLE];
// CompositionTime, video_file_format_spec_v10_1.pdf, page 78.
// cts = pts - dts, where dts = flvheader->timestamp.
int32_t cts;
public:
SrsCodecSample();
virtual ~SrsCodecSample();
void clear();
int add_sample(char* bytes, int size);
};
/**
* Annex E. The FLV File Format
*/
@ -212,8 +241,8 @@ public:
virtual ~SrsCodec();
// the following function used for hls to build the codec info.
public:
virtual int audio_aac_demux(int8_t* data, int size);
virtual int video_avc_demux(int8_t* data, int size);
virtual int audio_aac_demux(int8_t* data, int size, SrsCodecSample* sample);
virtual int video_avc_demux(int8_t* data, int size, SrsCodecSample* sample);
// the following function used to finger out the flv/rtmp packet detail.
public:
/**

View file

@ -31,11 +31,13 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
SrsHLS::SrsHLS()
{
codec = new SrsCodec();
sample = new SrsCodecSample();
}
SrsHLS::~SrsHLS()
{
srs_freep(codec);
srs_freep(sample);
}
int SrsHLS::on_publish()
@ -134,7 +136,12 @@ int SrsHLS::on_audio(SrsCommonMessage* audio)
{
int ret = ERROR_SUCCESS;
if ((ret = codec->audio_aac_demux(audio->payload, audio->size)) != ERROR_SUCCESS) {
sample->clear();
if ((ret = codec->audio_aac_demux(audio->payload, audio->size, sample)) != ERROR_SUCCESS) {
return ret;
}
if (codec->audio_codec_id != SrsCodecAudioAAC) {
return ret;
}
@ -145,7 +152,8 @@ int SrsHLS::on_video(SrsCommonMessage* video)
{
int ret = ERROR_SUCCESS;
if ((ret = codec->video_avc_demux(video->payload, video->size)) != ERROR_SUCCESS) {
sample->clear();
if ((ret = codec->video_avc_demux(video->payload, video->size, sample)) != ERROR_SUCCESS) {
return ret;
}

View file

@ -31,12 +31,14 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class SrsOnMetaDataPacket;
class SrsCommonMessage;
class SrsCodecSample;
class SrsCodec;
class SrsHLS
{
private:
SrsCodec* codec;
SrsCodecSample* sample;
public:
SrsHLS();
virtual ~SrsHLS();

View file

@ -87,6 +87,16 @@ int SrsStream::pos()
return p - bytes;
}
int SrsStream::left()
{
return size - pos();
}
char* SrsStream::current()
{
return p;
}
int8_t SrsStream::read_1bytes()
{
srs_assert(require(1));

View file

@ -74,6 +74,11 @@ public:
* tell the current pos.
*/
virtual int pos();
/**
* left size of bytes.
*/
virtual int left();
virtual char* current();
public:
/**
* get 1bytes char from stream.