mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
* MP3: Fix bug for TS or HLS with mp3 codec. v4.0.269 (#296) 1. Refresh HLS audio codec if changed in stream. 2. Refresh TS audio codec if changed in stream. 3. Fix mp3 demux bug in SrsFormat::audio_mp3_demux. 4. Use 3(MPEG1) not 4(MPEG2) as PMT stream type, follow FFmpeg. 5. MP3: Update utest for mp3 sample parsing. 6. MP3: Ignore empty frame sample. 7. UTest: Fix utest failed, do not copy files.
This commit is contained in:
parent
2573a25101
commit
577cd299e1
10 changed files with 109 additions and 38 deletions
|
@ -488,6 +488,9 @@ srs_error_t SrsFrame::initialize(SrsCodecConfig* c)
|
|||
srs_error_t SrsFrame::add_sample(char* bytes, int size)
|
||||
{
|
||||
srs_error_t err = srs_success;
|
||||
|
||||
// Ignore empty sample.
|
||||
if (!bytes || size <= 0) return err;
|
||||
|
||||
if (nb_samples >= SrsMaxNbSamples) {
|
||||
return srs_error_new(ERROR_HLS_DECODE_ERROR, "Frame samples overflow");
|
||||
|
@ -1407,20 +1410,13 @@ srs_error_t SrsFormat::audio_mp3_demux(SrsBuffer* stream, int64_t timestamp)
|
|||
// we always decode aac then mp3.
|
||||
srs_assert(acodec->id == SrsAudioCodecIdMP3);
|
||||
|
||||
// Update the RAW MP3 data.
|
||||
// Update the RAW MP3 data. Note the start is 12 bits syncword 0xFFF, so we should not skip any bytes, for detail
|
||||
// please see ISO_IEC_11172-3-MP3-1993.pdf page 20 and 26.
|
||||
raw = stream->data() + stream->pos();
|
||||
nb_raw = stream->size() - stream->pos();
|
||||
|
||||
stream->skip(1);
|
||||
if (stream->empty()) {
|
||||
return err;
|
||||
}
|
||||
|
||||
char* data = stream->data() + stream->pos();
|
||||
int size = stream->size() - stream->pos();
|
||||
|
||||
// mp3 payload.
|
||||
if ((err = audio->add_sample(data, size)) != srs_success) {
|
||||
if ((err = audio->add_sample(raw, nb_raw)) != srs_success) {
|
||||
return srs_error_wrap(err, "add audio frame");
|
||||
}
|
||||
|
||||
|
|
|
@ -2598,8 +2598,8 @@ SrsTsContextWriter::SrsTsContextWriter(ISrsStreamWriter* w, SrsTsContext* c, Srs
|
|||
{
|
||||
writer = w;
|
||||
context = c;
|
||||
|
||||
acodec = ac;
|
||||
|
||||
acodec_ = ac;
|
||||
vcodec = vc;
|
||||
}
|
||||
|
||||
|
@ -2614,7 +2614,7 @@ srs_error_t SrsTsContextWriter::write_audio(SrsTsMessage* audio)
|
|||
srs_info("hls: write audio pts=%" PRId64 ", dts=%" PRId64 ", size=%d",
|
||||
audio->pts, audio->dts, audio->PES_packet_length);
|
||||
|
||||
if ((err = context->encode(writer, audio, vcodec, acodec)) != srs_success) {
|
||||
if ((err = context->encode(writer, audio, vcodec, acodec_)) != srs_success) {
|
||||
return srs_error_wrap(err, "ts: write audio");
|
||||
}
|
||||
srs_info("hls encode audio ok");
|
||||
|
@ -2629,7 +2629,7 @@ srs_error_t SrsTsContextWriter::write_video(SrsTsMessage* video)
|
|||
srs_info("hls: write video pts=%" PRId64 ", dts=%" PRId64 ", size=%d",
|
||||
video->pts, video->dts, video->PES_packet_length);
|
||||
|
||||
if ((err = context->encode(writer, video, vcodec, acodec)) != srs_success) {
|
||||
if ((err = context->encode(writer, video, vcodec, acodec_)) != srs_success) {
|
||||
return srs_error_wrap(err, "ts: write video");
|
||||
}
|
||||
srs_info("hls encode video ok");
|
||||
|
@ -2642,6 +2642,16 @@ SrsVideoCodecId SrsTsContextWriter::video_codec()
|
|||
return vcodec;
|
||||
}
|
||||
|
||||
SrsAudioCodecId SrsTsContextWriter::acodec()
|
||||
{
|
||||
return acodec_;
|
||||
}
|
||||
|
||||
void SrsTsContextWriter::set_acodec(SrsAudioCodecId v)
|
||||
{
|
||||
acodec_ = v;
|
||||
}
|
||||
|
||||
SrsEncFileWriter::SrsEncFileWriter()
|
||||
{
|
||||
memset(iv,0,16);
|
||||
|
@ -3079,6 +3089,13 @@ srs_error_t SrsTsTransmuxer::write_audio(int64_t timestamp, char* data, int size
|
|||
if (format->acodec->id == SrsAudioCodecIdAAC && format->audio->aac_packet_type == SrsAudioAacFrameTraitSequenceHeader) {
|
||||
return err;
|
||||
}
|
||||
|
||||
// Switch audio codec if not AAC.
|
||||
if (tscw->acodec() != format->acodec->id) {
|
||||
srs_trace("TS: Switch audio codec %d(%s) to %d(%s)", tscw->acodec(), srs_audio_codec_id2str(tscw->acodec()).c_str(),
|
||||
format->acodec->id, srs_audio_codec_id2str(format->acodec->id).c_str());
|
||||
tscw->set_acodec(format->acodec->id);
|
||||
}
|
||||
|
||||
// the dts calc from rtmp/flv header.
|
||||
// @remark for http ts stream, the timestamp is always monotonically increase,
|
||||
|
|
|
@ -97,7 +97,7 @@ enum SrsTsPidApply
|
|||
SrsTsPidApplyAudio, // vor audio
|
||||
};
|
||||
|
||||
// Table 2-29 - Stream type assignments
|
||||
// Table 2-29 - Stream type assignments, hls-mpeg-ts-iso13818-1.pdf, page 66
|
||||
enum SrsTsStream
|
||||
{
|
||||
// ITU-T | ISO/IEC Reserved
|
||||
|
@ -106,8 +106,8 @@ enum SrsTsStream
|
|||
// ISO/IEC 11172 Video
|
||||
// ITU-T Rec. H.262 | ISO/IEC 13818-2 Video or ISO/IEC 11172-2 constrained parameter video stream
|
||||
// ISO/IEC 11172 Audio
|
||||
SrsTsStreamAudioMp3 = 0x03,
|
||||
// ISO/IEC 13818-3 Audio
|
||||
SrsTsStreamAudioMp3 = 0x04,
|
||||
// ITU-T Rec. H.222.0 | ISO/IEC 13818-1 private_sections
|
||||
// ITU-T Rec. H.222.0 | ISO/IEC 13818-1 PES packets containing private data
|
||||
// ISO/IEC 13522 MHEG
|
||||
|
@ -1243,7 +1243,7 @@ private:
|
|||
// User must config the codec in right way.
|
||||
// @see https://github.com/ossrs/srs/issues/301
|
||||
SrsVideoCodecId vcodec;
|
||||
SrsAudioCodecId acodec;
|
||||
SrsAudioCodecId acodec_;
|
||||
private:
|
||||
SrsTsContext* context;
|
||||
ISrsStreamWriter* writer;
|
||||
|
@ -1259,6 +1259,10 @@ public:
|
|||
public:
|
||||
// get the video codec of ts muxer.
|
||||
virtual SrsVideoCodecId video_codec();
|
||||
public:
|
||||
// Get and set the audio codec.
|
||||
SrsAudioCodecId acodec();
|
||||
void set_acodec(SrsAudioCodecId v);
|
||||
};
|
||||
|
||||
// Used for HLS Encryption
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue