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

merge from 2.0release

This commit is contained in:
winlin 2015-10-27 17:45:14 +08:00
commit 1d57e53910
6 changed files with 62 additions and 49 deletions

View file

@ -246,12 +246,6 @@ extern int aac_sample_rates[];
#define SRS_SRS_MAX_CODEC_SAMPLE 128
#define SRS_AAC_SAMPLE_RATE_UNSET 15
// in ms, for HLS aac flush the audio
#define SRS_CONF_DEFAULT_AAC_DELAY 60
// max PES packets size to flush the video.
#define SRS_AUTO_HLS_AUDIO_CACHE_SIZE 128 * 1024
/**
* the FLV/RTMP supported audio sample size.
* Size of each audio sample. This parameter only pertains to

View file

@ -469,8 +469,11 @@ int SrsTsContext::encode_pes(SrsFileWriter* writer, SrsTsMessage* msg, int16_t p
while (p < end) {
SrsTsPacket* pkt = NULL;
if (p == start) {
// for pure audio stream, always write pcr.
// write pcr according to message.
bool write_pcr = msg->write_pcr;
// for pure audio, always write pcr.
// TODO: FIXME: maybe only need to write at begin and end of ts.
if (pure_audio && msg->is_audio()) {
write_pcr = true;
}
@ -2772,6 +2775,11 @@ void SrsTSMuxer::close()
writer->close();
}
SrsCodecVideo SrsTSMuxer::video_codec()
{
return vcodec;
}
SrsTsCache::SrsTsCache()
{
audio = NULL;
@ -2792,11 +2800,12 @@ int SrsTsCache::cache_audio(SrsAvcAacCodec* codec, int64_t dts, SrsCodecSample*
if (!audio) {
audio = new SrsTsMessage();
audio->write_pcr = false;
audio->start_pts = dts;
audio->dts = audio->pts = audio->start_pts = dts;
}
audio->dts = dts;
audio->pts = audio->dts;
// TODO: FIXME: refine code.
//audio->dts = dts;
//audio->pts = audio->dts;
audio->sid = SrsTsPESStreamIdAudioCommon;
// must be aac or mp3
@ -3146,20 +3155,11 @@ int SrsTsEncoder::write_audio(int64_t timestamp, char* data, int size)
return ret;
}
// flush if buffer exceed max size.
if (cache->audio->payload->length() > SRS_AUTO_HLS_AUDIO_CACHE_SIZE) {
return flush_video();
}
// TODO: config it.
// in ms, audio delay to flush the audios.
int64_t audio_delay = SRS_CONF_DEFAULT_AAC_DELAY;
// flush if audio delay exceed
if (dts - cache->audio->start_pts > audio_delay * 90) {
return flush_audio();
}
return ret;
// TODO: FIXME: for pure audio, aggregate some frame to one.
// always flush audio frame by frame.
// @see https://github.com/simple-rtmp-server/srs/issues/512
return flush_audio();
}
int SrsTsEncoder::write_video(int64_t timestamp, char* data, int size)

View file

@ -54,6 +54,9 @@ class SrsTsContext;
// Transport Stream packets are 188 bytes in length.
#define SRS_TS_PACKET_SIZE 188
// the aggregate pure audio for hls, in ts tbn(ms * 90).
#define SRS_CONSTS_HLS_PURE_AUDIO_AGGREGATE 720 * 90
/**
* the pid of ts packet,
* Table 2-3 - PID table, hls-mpeg-ts-iso13818-1.pdf, page 37
@ -360,6 +363,7 @@ public:
/**
* whether the hls stream is pure audio stream.
*/
// TODO: FIXME: merge with muxer codec detect.
virtual bool is_pure_audio();
/**
* when PMT table parsed, we know some info about stream.
@ -1594,6 +1598,11 @@ public:
* close the writer.
*/
virtual void close();
public:
/**
* get the video codec of ts muxer.
*/
virtual SrsCodecVideo video_codec();
};
/**