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

for #299, refine the codec object name

This commit is contained in:
winlin 2017-02-12 20:38:39 +08:00
parent d7458c4e72
commit caf69f193d
29 changed files with 731 additions and 699 deletions

View file

@ -454,9 +454,9 @@ int SrsDvrFlvSegmenter::encode_video(SrsSharedPtrMessage* video)
char* payload = video->payload; char* payload = video->payload;
int size = video->size; int size = video->size;
bool sh = SrsFlvCodec::video_is_sequence_header(payload, size); bool sh = SrsFlvVideo::sh(payload, size);
bool keyframe = SrsFlvCodec::video_is_h264(payload, size) bool keyframe = SrsFlvVideo::h264(payload, size)
&& SrsFlvCodec::video_is_keyframe(payload, size) && !sh; && SrsFlvVideo::keyframe(payload, size) && !sh;
if (keyframe) { if (keyframe) {
has_keyframe = true; has_keyframe = true;
@ -534,23 +534,23 @@ int SrsDvrMp4Segmenter::encode_audio(SrsSharedPtrMessage* audio)
return ret; return ret;
} }
uint8_t v = buffer->read_1bytes(); uint8_t v = buffer->read_1bytes();
SrsCodecAudio sound_format = (SrsCodecAudio)((v >> 4) & 0x0f); SrsAudioCodecId sound_format = (SrsAudioCodecId)((v >> 4) & 0x0f);
SrsCodecAudioSampleRate sound_rate = (SrsCodecAudioSampleRate)((v >> 2) & 0x03); SrsAudioSampleRate sound_rate = (SrsAudioSampleRate)((v >> 2) & 0x03);
SrsCodecAudioSampleSize sound_size = (SrsCodecAudioSampleSize)((v >> 1) & 0x01); SrsAudioSampleSize sound_size = (SrsAudioSampleSize)((v >> 1) & 0x01);
SrsCodecAudioSoundType channels = (SrsCodecAudioSoundType)(v&0x01); SrsAudioSoundType channels = (SrsAudioSoundType)(v&0x01);
uint16_t ct = 0x00; uint16_t ct = 0x00;
if (sound_format == SrsCodecAudioAAC) { if (sound_format == SrsAudioCodecIdAAC) {
if (!buffer->require(1)) { if (!buffer->require(1)) {
ret = ERROR_FLV_REQUIRE_SPACE; ret = ERROR_FLV_REQUIRE_SPACE;
srs_error("DVR require flva 1 byte space, format=%d. ret=%d", sound_format, ret); srs_error("DVR require flva 1 byte space, format=%d. ret=%d", sound_format, ret);
return ret; return ret;
} }
v = buffer->read_1bytes(); v = buffer->read_1bytes();
ct = (v == 0? SrsCodecAudioTypeSequenceHeader:SrsCodecAudioTypeRawData); ct = (v == 0? SrsAudioAacFrameTraitSequenceHeader:SrsAudioAacFrameTraitRawData);
} }
if (ct == SrsCodecAudioTypeSequenceHeader) { if (ct == SrsAudioAacFrameTraitSequenceHeader) {
enc->acodec = sound_format; enc->acodec = sound_format;
enc->sample_rate = sound_rate; enc->sample_rate = sound_rate;
enc->sound_bits = sound_size; enc->sound_bits = sound_size;
@ -579,18 +579,18 @@ int SrsDvrMp4Segmenter::encode_video(SrsSharedPtrMessage* video)
return ret; return ret;
} }
uint8_t v = buffer->read_1bytes(); uint8_t v = buffer->read_1bytes();
SrsCodecVideoAVCFrame frame_type = (SrsCodecVideoAVCFrame)((v>>4)&0x0f); SrsVideoAvcFrameType frame_type = (SrsVideoAvcFrameType)((v>>4)&0x0f);
SrsCodecVideo codec_id = (SrsCodecVideo)(v&0x0f); SrsVideoCodecId codec_id = (SrsVideoCodecId)(v&0x0f);
if (!buffer->require(4)) { if (!buffer->require(4)) {
ret = ERROR_FLV_REQUIRE_SPACE; ret = ERROR_FLV_REQUIRE_SPACE;
srs_error("DVR require flvv 4 bytes space, codec=%d. ret=%d", codec_id, ret); srs_error("DVR require flvv 4 bytes space, codec=%d. ret=%d", codec_id, ret);
return ret; return ret;
} }
SrsCodecVideoAVCType ct = (SrsCodecVideoAVCType)buffer->read_1bytes(); SrsVideoAvcFrameTrait ct = (SrsVideoAvcFrameTrait)buffer->read_1bytes();
uint32_t cts = (uint32_t)buffer->read_3bytes(); uint32_t cts = (uint32_t)buffer->read_3bytes();
if (ct == SrsCodecVideoAVCTypeSequenceHeader) { if (ct == SrsVideoAvcFrameTraitSequenceHeader) {
enc->vcodec = codec_id; enc->vcodec = codec_id;
} }
@ -929,9 +929,9 @@ int SrsDvrSegmentPlan::update_duration(SrsSharedPtrMessage* msg)
char* payload = msg->payload; char* payload = msg->payload;
int size = msg->size; int size = msg->size;
bool is_key_frame = SrsFlvCodec::video_is_h264(payload, size) bool is_key_frame = SrsFlvVideo::h264(payload, size)
&& SrsFlvCodec::video_is_keyframe(payload, size) && SrsFlvVideo::keyframe(payload, size)
&& !SrsFlvCodec::video_is_sequence_header(payload, size); && !SrsFlvVideo::sh(payload, size);
if (!is_key_frame) { if (!is_key_frame) {
return ret; return ret;
} }

View file

@ -184,7 +184,7 @@ int SrsForwarder::on_audio(SrsSharedPtrMessage* shared_audio)
return ret; return ret;
} }
if (SrsFlvCodec::audio_is_sequence_header(msg->payload, msg->size)) { if (SrsFlvAudio::sh(msg->payload, msg->size)) {
srs_freep(sh_audio); srs_freep(sh_audio);
sh_audio = msg->copy(); sh_audio = msg->copy();
} }
@ -208,7 +208,7 @@ int SrsForwarder::on_video(SrsSharedPtrMessage* shared_video)
return ret; return ret;
} }
if (SrsFlvCodec::video_is_sequence_header(msg->payload, msg->size)) { if (SrsFlvVideo::sh(msg->payload, msg->size)) {
srs_freep(sh_video); srs_freep(sh_video);
sh_video = msg->copy(); sh_video = msg->copy();
} }

View file

@ -331,7 +331,7 @@ int SrsHds::on_video(SrsSharedPtrMessage* msg)
return ret; return ret;
} }
if (SrsFlvCodec::video_is_sequence_header(msg->payload, msg->size)) { if (SrsFlvVideo::sh(msg->payload, msg->size)) {
srs_freep(video_sh); srs_freep(video_sh);
video_sh = msg->copy(); video_sh = msg->copy();
} }
@ -383,7 +383,7 @@ int SrsHds::on_audio(SrsSharedPtrMessage* msg)
return ret; return ret;
} }
if (SrsFlvCodec::audio_is_sequence_header(msg->payload, msg->size)) { if (SrsFlvAudio::sh(msg->payload, msg->size)) {
srs_freep(audio_sh); srs_freep(audio_sh);
audio_sh = msg->copy(); audio_sh = msg->copy();
} }

View file

@ -62,7 +62,7 @@ using namespace std;
// reset the piece id when deviation overflow this. // reset the piece id when deviation overflow this.
#define SRS_JUMP_WHEN_PIECE_DEVIATION 20 #define SRS_JUMP_WHEN_PIECE_DEVIATION 20
SrsHlsSegment::SrsHlsSegment(SrsTsContext* c, SrsCodecAudio ac, SrsCodecVideo vc) SrsHlsSegment::SrsHlsSegment(SrsTsContext* c, SrsAudioCodecId ac, SrsVideoCodecId vc)
{ {
duration = 0; duration = 0;
sequence_no = 0; sequence_no = 0;
@ -223,7 +223,7 @@ SrsHlsMuxer::SrsHlsMuxer()
max_td = 0; max_td = 0;
_sequence_no = 0; _sequence_no = 0;
current = NULL; current = NULL;
acodec = SrsCodecAudioReserved1; acodec = SrsAudioCodecIdReserved1;
async = new SrsAsyncCallWorker(); async = new SrsAsyncCallWorker();
context = new SrsTsContext(); context = new SrsTsContext();
} }
@ -361,17 +361,17 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts)
srs_assert(!current); srs_assert(!current);
// load the default acodec from config. // load the default acodec from config.
SrsCodecAudio default_acodec = SrsCodecAudioAAC; SrsAudioCodecId default_acodec = SrsAudioCodecIdAAC;
if (true) { if (true) {
std::string default_acodec_str = _srs_config->get_hls_acodec(req->vhost); std::string default_acodec_str = _srs_config->get_hls_acodec(req->vhost);
if (default_acodec_str == "mp3") { if (default_acodec_str == "mp3") {
default_acodec = SrsCodecAudioMP3; default_acodec = SrsAudioCodecIdMP3;
srs_info("hls: use default mp3 acodec"); srs_info("hls: use default mp3 acodec");
} else if (default_acodec_str == "aac") { } else if (default_acodec_str == "aac") {
default_acodec = SrsCodecAudioAAC; default_acodec = SrsAudioCodecIdAAC;
srs_info("hls: use default aac acodec"); srs_info("hls: use default aac acodec");
} else if (default_acodec_str == "an") { } else if (default_acodec_str == "an") {
default_acodec = SrsCodecAudioDisabled; default_acodec = SrsAudioCodecIdDisabled;
srs_info("hls: use default an acodec for pure video"); srs_info("hls: use default an acodec for pure video");
} else { } else {
srs_warn("hls: use aac for other codec=%s", default_acodec_str.c_str()); srs_warn("hls: use aac for other codec=%s", default_acodec_str.c_str());
@ -379,14 +379,14 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts)
} }
// load the default vcodec from config. // load the default vcodec from config.
SrsCodecVideo default_vcodec = SrsCodecVideoAVC; SrsVideoCodecId default_vcodec = SrsVideoCodecIdAVC;
if (true) { if (true) {
std::string default_vcodec_str = _srs_config->get_hls_vcodec(req->vhost); std::string default_vcodec_str = _srs_config->get_hls_vcodec(req->vhost);
if (default_vcodec_str == "h264") { if (default_vcodec_str == "h264") {
default_vcodec = SrsCodecVideoAVC; default_vcodec = SrsVideoCodecIdAVC;
srs_info("hls: use default h264 vcodec"); srs_info("hls: use default h264 vcodec");
} else if (default_vcodec_str == "vn") { } else if (default_vcodec_str == "vn") {
default_vcodec = SrsCodecVideoDisabled; default_vcodec = SrsVideoCodecIdDisabled;
srs_info("hls: use default vn vcodec for pure audio"); srs_info("hls: use default vn vcodec for pure audio");
} else { } else {
srs_warn("hls: use h264 for other codec=%s", default_vcodec_str.c_str()); srs_warn("hls: use h264 for other codec=%s", default_vcodec_str.c_str());
@ -483,7 +483,7 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts)
// set the segment muxer audio codec. // set the segment muxer audio codec.
// TODO: FIXME: refine code, use event instead. // TODO: FIXME: refine code, use event instead.
if (acodec != SrsCodecAudioReserved1) { if (acodec != SrsAudioCodecIdReserved1) {
current->muxer->update_acodec(acodec); current->muxer->update_acodec(acodec);
} }
@ -543,7 +543,7 @@ bool SrsHlsMuxer::is_segment_absolutely_overflow()
return current->duration >= hls_aof_ratio * hls_fragment + deviation; return current->duration >= hls_aof_ratio * hls_fragment + deviation;
} }
int SrsHlsMuxer::update_acodec(SrsCodecAudio ac) int SrsHlsMuxer::update_acodec(SrsAudioCodecId ac)
{ {
srs_assert(current); srs_assert(current);
srs_assert(current->muxer); srs_assert(current->muxer);
@ -553,7 +553,7 @@ int SrsHlsMuxer::update_acodec(SrsCodecAudio ac)
bool SrsHlsMuxer::pure_audio() bool SrsHlsMuxer::pure_audio()
{ {
return current && current->muxer && current->muxer->video_codec() == SrsCodecVideoDisabled; return current && current->muxer && current->muxer->video_codec() == SrsVideoCodecIdDisabled;
} }
int SrsHlsMuxer::flush_audio(SrsTsCache* cache) int SrsHlsMuxer::flush_audio(SrsTsCache* cache)
@ -863,7 +863,7 @@ void SrsHlsController::dispose()
muxer->dispose(); muxer->dispose();
} }
int SrsHlsController::update_acodec(SrsCodecAudio ac) int SrsHlsController::update_acodec(SrsAudioCodecId ac)
{ {
return muxer->update_acodec(ac); return muxer->update_acodec(ac);
} }
@ -1020,7 +1020,7 @@ int SrsHlsController::write_video(SrsVideoFrame* frame, int64_t dts)
// do reap ts if any of: // do reap ts if any of:
// a. wait keyframe and got keyframe. // a. wait keyframe and got keyframe.
// b. always reap when not wait keyframe. // b. always reap when not wait keyframe.
if (!muxer->wait_keyframe() || frame->frame_type == SrsCodecVideoAVCFrameKeyFrame) { if (!muxer->wait_keyframe() || frame->frame_type == SrsVideoAvcFrameTypeKeyFrame) {
// reap the segment, which will also flush the video. // reap the segment, which will also flush the video.
if ((ret = reap_segment("video", ts->video->dts)) != ERROR_SUCCESS) { if ((ret = reap_segment("video", ts->video->dts)) != ERROR_SUCCESS) {
return ret; return ret;
@ -1216,8 +1216,8 @@ int SrsHls::on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* format)
// ts support audio codec: aac/mp3 // ts support audio codec: aac/mp3
srs_assert(format->acodec); srs_assert(format->acodec);
SrsCodecAudio acodec = format->acodec->id; SrsAudioCodecId acodec = format->acodec->id;
if (acodec != SrsCodecAudioAAC && acodec != SrsCodecAudioMP3) { if (acodec != SrsAudioCodecIdAAC && acodec != SrsAudioCodecIdMP3) {
return ret; return ret;
} }
@ -1229,7 +1229,7 @@ int SrsHls::on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* format)
// ignore sequence header // ignore sequence header
srs_assert(format->audio); srs_assert(format->audio);
if (acodec == SrsCodecAudioAAC && format->audio->aac_packet_type == SrsCodecAudioTypeSequenceHeader) { if (acodec == SrsAudioCodecIdAAC && format->audio->aac_packet_type == SrsAudioAacFrameTraitSequenceHeader) {
return controller->on_sequence_header(); return controller->on_sequence_header();
} }
@ -1270,17 +1270,17 @@ int SrsHls::on_video(SrsSharedPtrMessage* shared_video, SrsFormat* format)
// ignore info frame, // ignore info frame,
// @see https://github.com/ossrs/srs/issues/288#issuecomment-69863909 // @see https://github.com/ossrs/srs/issues/288#issuecomment-69863909
srs_assert(format->video); srs_assert(format->video);
if (format->video->frame_type == SrsCodecVideoAVCFrameVideoInfoFrame) { if (format->video->frame_type == SrsVideoAvcFrameTypeVideoInfoFrame) {
return ret; return ret;
} }
srs_assert(format->vcodec); srs_assert(format->vcodec);
if (format->vcodec->id != SrsCodecVideoAVC) { if (format->vcodec->id != SrsVideoCodecIdAVC) {
return ret; return ret;
} }
// ignore sequence header // ignore sequence header
if (format->video->avc_packet_type == SrsCodecVideoAVCTypeSequenceHeader) { if (format->video->avc_packet_type == SrsVideoAvcFrameTraitSequenceHeader) {
return controller->on_sequence_header(); return controller->on_sequence_header();
} }

View file

@ -78,7 +78,7 @@ public:
// whether current segement is sequence header. // whether current segement is sequence header.
bool is_sequence_header; bool is_sequence_header;
public: public:
SrsHlsSegment(SrsTsContext* c, SrsCodecAudio ac, SrsCodecVideo vc); SrsHlsSegment(SrsTsContext* c, SrsAudioCodecId ac, SrsVideoCodecId vc);
virtual ~SrsHlsSegment(); virtual ~SrsHlsSegment();
public: public:
/** /**
@ -179,7 +179,7 @@ private:
* set the muxer audio codec. * set the muxer audio codec.
* @see https://github.com/ossrs/srs/issues/301 * @see https://github.com/ossrs/srs/issues/301
*/ */
SrsCodecAudio acodec; SrsAudioCodecId acodec;
/** /**
* the ts context, to keep cc continous between ts. * the ts context, to keep cc continous between ts.
* @see https://github.com/ossrs/srs/issues/375 * @see https://github.com/ossrs/srs/issues/375
@ -230,7 +230,7 @@ public:
*/ */
virtual bool is_segment_absolutely_overflow(); virtual bool is_segment_absolutely_overflow();
public: public:
virtual int update_acodec(SrsCodecAudio ac); virtual int update_acodec(SrsAudioCodecId ac);
/** /**
* whether current hls muxer is pure audio mode. * whether current hls muxer is pure audio mode.
*/ */
@ -278,7 +278,7 @@ public:
public: public:
virtual int initialize(); virtual int initialize();
virtual void dispose(); virtual void dispose();
virtual int update_acodec(SrsCodecAudio ac); virtual int update_acodec(SrsAudioCodecId ac);
virtual int sequence_no(); virtual int sequence_no();
virtual std::string ts_url(); virtual std::string ts_url();
virtual double duration(); virtual double duration();

View file

@ -266,7 +266,7 @@ int SrsFlvStreamEncoder::write_video(int64_t timestamp, char* data, int size)
int SrsFlvStreamEncoder::write_metadata(int64_t timestamp, char* data, int size) int SrsFlvStreamEncoder::write_metadata(int64_t timestamp, char* data, int size)
{ {
return enc->write_metadata(SrsCodecFlvTagScript, data, size); return enc->write_metadata(SrsFrameTypeScript, data, size);
} }
bool SrsFlvStreamEncoder::has_cache() bool SrsFlvStreamEncoder::has_cache()

View file

@ -438,8 +438,8 @@ int SrsMpegtsOverUdp::write_h264_sps_pps(uint32_t dts, uint32_t pts)
} }
// h264 packet to flv packet. // h264 packet to flv packet.
int8_t frame_type = SrsCodecVideoAVCFrameKeyFrame; int8_t frame_type = SrsVideoAvcFrameTypeKeyFrame;
int8_t avc_packet_type = SrsCodecVideoAVCTypeSequenceHeader; int8_t avc_packet_type = SrsVideoAvcFrameTraitSequenceHeader;
char* flv = NULL; char* flv = NULL;
int nb_flv = 0; int nb_flv = 0;
if ((ret = avc->mux_avc2flv(sh, frame_type, avc_packet_type, dts, pts, &flv, &nb_flv)) != ERROR_SUCCESS) { if ((ret = avc->mux_avc2flv(sh, frame_type, avc_packet_type, dts, pts, &flv, &nb_flv)) != ERROR_SUCCESS) {
@ -448,7 +448,7 @@ int SrsMpegtsOverUdp::write_h264_sps_pps(uint32_t dts, uint32_t pts)
// the timestamp in rtmp message header is dts. // the timestamp in rtmp message header is dts.
uint32_t timestamp = dts; uint32_t timestamp = dts;
if ((ret = rtmp_write_packet(SrsCodecFlvTagVideo, timestamp, flv, nb_flv)) != ERROR_SUCCESS) { if ((ret = rtmp_write_packet(SrsFrameTypeVideo, timestamp, flv, nb_flv)) != ERROR_SUCCESS) {
return ret; return ret;
} }
@ -476,9 +476,9 @@ int SrsMpegtsOverUdp::write_h264_ipb_frame(char* frame, int frame_size, uint32_t
SrsAvcNaluType nal_unit_type = (SrsAvcNaluType)(frame[0] & 0x1f); SrsAvcNaluType nal_unit_type = (SrsAvcNaluType)(frame[0] & 0x1f);
// for IDR frame, the frame is keyframe. // for IDR frame, the frame is keyframe.
SrsCodecVideoAVCFrame frame_type = SrsCodecVideoAVCFrameInterFrame; SrsVideoAvcFrameType frame_type = SrsVideoAvcFrameTypeInterFrame;
if (nal_unit_type == SrsAvcNaluTypeIDR) { if (nal_unit_type == SrsAvcNaluTypeIDR) {
frame_type = SrsCodecVideoAVCFrameKeyFrame; frame_type = SrsVideoAvcFrameTypeKeyFrame;
} }
std::string ibp; std::string ibp;
@ -486,7 +486,7 @@ int SrsMpegtsOverUdp::write_h264_ipb_frame(char* frame, int frame_size, uint32_t
return ret; return ret;
} }
int8_t avc_packet_type = SrsCodecVideoAVCTypeNALU; int8_t avc_packet_type = SrsVideoAvcFrameTraitNALU;
char* flv = NULL; char* flv = NULL;
int nb_flv = 0; int nb_flv = 0;
if ((ret = avc->mux_avc2flv(ibp, frame_type, avc_packet_type, dts, pts, &flv, &nb_flv)) != ERROR_SUCCESS) { if ((ret = avc->mux_avc2flv(ibp, frame_type, avc_packet_type, dts, pts, &flv, &nb_flv)) != ERROR_SUCCESS) {
@ -495,7 +495,7 @@ int SrsMpegtsOverUdp::write_h264_ipb_frame(char* frame, int frame_size, uint32_t
// the timestamp in rtmp message header is dts. // the timestamp in rtmp message header is dts.
uint32_t timestamp = dts; uint32_t timestamp = dts;
return rtmp_write_packet(SrsCodecFlvTagVideo, timestamp, flv, nb_flv); return rtmp_write_packet(SrsFrameTypeVideo, timestamp, flv, nb_flv);
} }
int SrsMpegtsOverUdp::on_ts_audio(SrsTsMessage* msg, SrsBuffer* avs) int SrsMpegtsOverUdp::on_ts_audio(SrsTsMessage* msg, SrsBuffer* avs)
@ -561,7 +561,7 @@ int SrsMpegtsOverUdp::write_audio_raw_frame(char* frame, int frame_size, SrsRawA
return ret; return ret;
} }
return rtmp_write_packet(SrsCodecFlvTagAudio, dts, data, size); return rtmp_write_packet(SrsFrameTypeAudio, dts, data, size);
} }
int SrsMpegtsOverUdp::rtmp_write_packet(char type, uint32_t timestamp, char* data, int size) int SrsMpegtsOverUdp::rtmp_write_packet(char type, uint32_t timestamp, char* data, int size)

View file

@ -518,28 +518,28 @@ int SrsRtspConn::write_sequence_header()
return ret; return ret;
} }
SrsAudioCodec* dec = format->acodec; SrsAudioCodecConfig* dec = format->acodec;
acodec->sound_format = SrsCodecAudioAAC; acodec->sound_format = SrsAudioCodecIdAAC;
acodec->sound_type = (dec->aac_channels == 2)? SrsCodecAudioSoundTypeStereo : SrsCodecAudioSoundTypeMono; acodec->sound_type = (dec->aac_channels == 2)? SrsAudioSoundTypeStereo : SrsAudioSoundTypeMono;
acodec->sound_size = SrsCodecAudioSampleSize16bit; acodec->sound_size = SrsAudioSampleSize16bit;
acodec->aac_packet_type = 0; acodec->aac_packet_type = 0;
static int aac_sample_rates[] = { static int srs_aac_srates[] = {
96000, 88200, 64000, 48000, 96000, 88200, 64000, 48000,
44100, 32000, 24000, 22050, 44100, 32000, 24000, 22050,
16000, 12000, 11025, 8000, 16000, 12000, 11025, 8000,
7350, 0, 0, 0 7350, 0, 0, 0
}; };
switch (aac_sample_rates[dec->aac_sample_rate]) { switch (srs_aac_srates[dec->aac_sample_rate]) {
case 11025: case 11025:
acodec->sound_rate = SrsCodecAudioSampleRate11025; acodec->sound_rate = SrsAudioSampleRate11025;
break; break;
case 22050: case 22050:
acodec->sound_rate = SrsCodecAudioSampleRate22050; acodec->sound_rate = SrsAudioSampleRate22050;
break; break;
case 44100: case 44100:
acodec->sound_rate = SrsCodecAudioSampleRate44100; acodec->sound_rate = SrsAudioSampleRate44100;
break; break;
default: default:
break; break;
@ -564,8 +564,8 @@ int SrsRtspConn::write_h264_sps_pps(uint32_t dts, uint32_t pts)
} }
// h264 packet to flv packet. // h264 packet to flv packet.
int8_t frame_type = SrsCodecVideoAVCFrameKeyFrame; int8_t frame_type = SrsVideoAvcFrameTypeKeyFrame;
int8_t avc_packet_type = SrsCodecVideoAVCTypeSequenceHeader; int8_t avc_packet_type = SrsVideoAvcFrameTraitSequenceHeader;
char* flv = NULL; char* flv = NULL;
int nb_flv = 0; int nb_flv = 0;
if ((ret = avc->mux_avc2flv(sh, frame_type, avc_packet_type, dts, pts, &flv, &nb_flv)) != ERROR_SUCCESS) { if ((ret = avc->mux_avc2flv(sh, frame_type, avc_packet_type, dts, pts, &flv, &nb_flv)) != ERROR_SUCCESS) {
@ -574,7 +574,7 @@ int SrsRtspConn::write_h264_sps_pps(uint32_t dts, uint32_t pts)
// the timestamp in rtmp message header is dts. // the timestamp in rtmp message header is dts.
uint32_t timestamp = dts; uint32_t timestamp = dts;
if ((ret = rtmp_write_packet(SrsCodecFlvTagVideo, timestamp, flv, nb_flv)) != ERROR_SUCCESS) { if ((ret = rtmp_write_packet(SrsFrameTypeVideo, timestamp, flv, nb_flv)) != ERROR_SUCCESS) {
return ret; return ret;
} }
@ -591,9 +591,9 @@ int SrsRtspConn::write_h264_ipb_frame(char* frame, int frame_size, uint32_t dts,
SrsAvcNaluType nal_unit_type = (SrsAvcNaluType)(frame[0] & 0x1f); SrsAvcNaluType nal_unit_type = (SrsAvcNaluType)(frame[0] & 0x1f);
// for IDR frame, the frame is keyframe. // for IDR frame, the frame is keyframe.
SrsCodecVideoAVCFrame frame_type = SrsCodecVideoAVCFrameInterFrame; SrsVideoAvcFrameType frame_type = SrsVideoAvcFrameTypeInterFrame;
if (nal_unit_type == SrsAvcNaluTypeIDR) { if (nal_unit_type == SrsAvcNaluTypeIDR) {
frame_type = SrsCodecVideoAVCFrameKeyFrame; frame_type = SrsVideoAvcFrameTypeKeyFrame;
} }
std::string ibp; std::string ibp;
@ -601,7 +601,7 @@ int SrsRtspConn::write_h264_ipb_frame(char* frame, int frame_size, uint32_t dts,
return ret; return ret;
} }
int8_t avc_packet_type = SrsCodecVideoAVCTypeNALU; int8_t avc_packet_type = SrsVideoAvcFrameTraitNALU;
char* flv = NULL; char* flv = NULL;
int nb_flv = 0; int nb_flv = 0;
if ((ret = avc->mux_avc2flv(ibp, frame_type, avc_packet_type, dts, pts, &flv, &nb_flv)) != ERROR_SUCCESS) { if ((ret = avc->mux_avc2flv(ibp, frame_type, avc_packet_type, dts, pts, &flv, &nb_flv)) != ERROR_SUCCESS) {
@ -610,7 +610,7 @@ int SrsRtspConn::write_h264_ipb_frame(char* frame, int frame_size, uint32_t dts,
// the timestamp in rtmp message header is dts. // the timestamp in rtmp message header is dts.
uint32_t timestamp = dts; uint32_t timestamp = dts;
return rtmp_write_packet(SrsCodecFlvTagVideo, timestamp, flv, nb_flv); return rtmp_write_packet(SrsFrameTypeVideo, timestamp, flv, nb_flv);
} }
int SrsRtspConn::write_audio_raw_frame(char* frame, int frame_size, SrsRawAacStreamCodec* codec, uint32_t dts) int SrsRtspConn::write_audio_raw_frame(char* frame, int frame_size, SrsRawAacStreamCodec* codec, uint32_t dts)
@ -623,7 +623,7 @@ int SrsRtspConn::write_audio_raw_frame(char* frame, int frame_size, SrsRawAacStr
return ret; return ret;
} }
return rtmp_write_packet(SrsCodecFlvTagAudio, dts, data, size); return rtmp_write_packet(SrsFrameTypeAudio, dts, data, size);
} }
int SrsRtspConn::rtmp_write_packet(char type, uint32_t timestamp, char* data, int size) int SrsRtspConn::rtmp_write_packet(char type, uint32_t timestamp, char* data, int size)

View file

@ -362,12 +362,12 @@ void SrsMessageQueue::shrink()
for (int i = 0; i < (int)msgs.size(); i++) { for (int i = 0; i < (int)msgs.size(); i++) {
SrsSharedPtrMessage* msg = msgs.at(i); SrsSharedPtrMessage* msg = msgs.at(i);
if (msg->is_video() && SrsFlvCodec::video_is_sequence_header(msg->payload, msg->size)) { if (msg->is_video() && SrsFlvVideo::sh(msg->payload, msg->size)) {
srs_freep(video_sh); srs_freep(video_sh);
video_sh = msg; video_sh = msg;
continue; continue;
} }
else if (msg->is_audio() && SrsFlvCodec::audio_is_sequence_header(msg->payload, msg->size)) { else if (msg->is_audio() && SrsFlvAudio::sh(msg->payload, msg->size)) {
srs_freep(audio_sh); srs_freep(audio_sh);
audio_sh = msg; audio_sh = msg;
continue; continue;
@ -643,7 +643,7 @@ int SrsGopCache::cache(SrsSharedPtrMessage* shared_msg)
// got video, update the video count if acceptable // got video, update the video count if acceptable
if (msg->is_video()) { if (msg->is_video()) {
// drop video when not h.264 // drop video when not h.264
if (!SrsFlvCodec::video_is_h264(msg->payload, msg->size)) { if (!SrsFlvVideo::h264(msg->payload, msg->size)) {
srs_info("gop cache drop video for none h.264"); srs_info("gop cache drop video for none h.264");
return ret; return ret;
} }
@ -671,7 +671,7 @@ int SrsGopCache::cache(SrsSharedPtrMessage* shared_msg)
} }
// clear gop cache when got key frame // clear gop cache when got key frame
if (msg->is_video() && SrsFlvCodec::video_is_keyframe(msg->payload, msg->size)) { if (msg->is_video() && SrsFlvVideo::keyframe(msg->payload, msg->size)) {
srs_info("clear gop cache when got keyframe. vcount=%d, count=%d", srs_info("clear gop cache when got keyframe. vcount=%d, count=%d",
cached_video_count, (int)gop_cache.size()); cached_video_count, (int)gop_cache.size());
@ -975,22 +975,22 @@ int SrsOriginHub::on_audio(SrsSharedPtrMessage* shared_audio)
// donot cache the sequence header to gop_cache, return here. // donot cache the sequence header to gop_cache, return here.
if (format->is_aac_sequence_header()) { if (format->is_aac_sequence_header()) {
srs_assert(format->acodec); srs_assert(format->acodec);
SrsAudioCodec* c = format->acodec; SrsAudioCodecConfig* c = format->acodec;
static int flv_sample_sizes[] = {8, 16, 0}; static int flv_sample_sizes[] = {8, 16, 0};
static int flv_sound_types[] = {1, 2, 0}; static int flv_sound_types[] = {1, 2, 0};
// when got audio stream info. // when got audio stream info.
SrsStatistic* stat = SrsStatistic::instance(); SrsStatistic* stat = SrsStatistic::instance();
if ((ret = stat->on_audio_info(req, SrsCodecAudioAAC, c->sound_rate, c->sound_type, c->aac_object)) != ERROR_SUCCESS) { if ((ret = stat->on_audio_info(req, SrsAudioCodecIdAAC, c->sound_rate, c->sound_type, c->aac_object)) != ERROR_SUCCESS) {
return ret; return ret;
} }
srs_trace("%dB audio sh, codec(%d, profile=%s, %dchannels, %dkbps, %dHZ), flv(%dbits, %dchannels, %dHZ)", srs_trace("%dB audio sh, codec(%d, profile=%s, %dchannels, %dkbps, %dHZ), flv(%dbits, %dchannels, %dHZ)",
msg->size, c->id, srs_codec_aac_object2str(c->aac_object).c_str(), c->aac_channels, msg->size, c->id, srs_aac_object2str(c->aac_object).c_str(), c->aac_channels,
c->audio_data_rate / 1000, aac_sample_rates[c->aac_sample_rate], c->audio_data_rate / 1000, srs_aac_srates[c->aac_sample_rate],
flv_sample_sizes[c->sound_size], flv_sound_types[c->sound_type], flv_sample_sizes[c->sound_size], flv_sound_types[c->sound_type],
flv_sample_rates[c->sound_rate]); srs_flv_srates[c->sound_rate]);
} }
if ((ret = hls->on_audio(msg, format)) != ERROR_SUCCESS) { if ((ret = hls->on_audio(msg, format)) != ERROR_SUCCESS) {
@ -1080,18 +1080,18 @@ int SrsOriginHub::on_video(SrsSharedPtrMessage* shared_video, bool is_sequence_h
// cache the sequence header if h264 // cache the sequence header if h264
// donot cache the sequence header to gop_cache, return here. // donot cache the sequence header to gop_cache, return here.
if (format->is_avc_sequence_header()) { if (format->is_avc_sequence_header()) {
SrsVideoCodec* c = format->vcodec; SrsVideoCodecConfig* c = format->vcodec;
srs_assert(c); srs_assert(c);
// when got video stream info. // when got video stream info.
SrsStatistic* stat = SrsStatistic::instance(); SrsStatistic* stat = SrsStatistic::instance();
if ((ret = stat->on_video_info(req, SrsCodecVideoAVC, c->avc_profile, c->avc_level, c->width, c->height)) != ERROR_SUCCESS) { if ((ret = stat->on_video_info(req, SrsVideoCodecIdAVC, c->avc_profile, c->avc_level, c->width, c->height)) != ERROR_SUCCESS) {
return ret; return ret;
} }
srs_trace("%dB video sh, codec(%d, profile=%s, level=%s, %dx%d, %dkbps, %.1ffps, %.1fs)", srs_trace("%dB video sh, codec(%d, profile=%s, level=%s, %dx%d, %dkbps, %.1ffps, %.1fs)",
msg->size, c->id, srs_codec_avc_profile2str(c->avc_profile).c_str(), msg->size, c->id, srs_avc_profile2str(c->avc_profile).c_str(),
srs_codec_avc_level2str(c->avc_level).c_str(), c->width, c->height, srs_avc_level2str(c->avc_level).c_str(), c->width, c->height,
c->video_data_rate / 1000, c->frame_rate, c->duration); c->video_data_rate / 1000, c->frame_rate, c->duration);
} }
@ -2171,7 +2171,7 @@ int SrsSource::on_audio_imp(SrsSharedPtrMessage* msg)
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
srs_info("Audio dts=%"PRId64", size=%d", msg->timestamp, msg->size); srs_info("Audio dts=%"PRId64", size=%d", msg->timestamp, msg->size);
bool is_aac_sequence_header = SrsFlvCodec::audio_is_sequence_header(msg->payload, msg->size); bool is_aac_sequence_header = SrsFlvAudio::sh(msg->payload, msg->size);
bool is_sequence_header = is_aac_sequence_header; bool is_sequence_header = is_aac_sequence_header;
// whether consumer should drop for the duplicated sequence header. // whether consumer should drop for the duplicated sequence header.
@ -2247,7 +2247,7 @@ int SrsSource::on_video(SrsCommonMessage* shared_video)
// drop any unknown header video. // drop any unknown header video.
// @see https://github.com/ossrs/srs/issues/421 // @see https://github.com/ossrs/srs/issues/421
if (!SrsFlvCodec::video_is_acceptable(shared_video->payload, shared_video->size)) { if (!SrsFlvVideo::acceptable(shared_video->payload, shared_video->size)) {
char b0 = 0x00; char b0 = 0x00;
if (shared_video->size > 0) { if (shared_video->size > 0) {
b0 = shared_video->payload[0]; b0 = shared_video->payload[0];
@ -2298,7 +2298,7 @@ int SrsSource::on_video_imp(SrsSharedPtrMessage* msg)
srs_info("Video dts=%"PRId64", size=%d", msg->timestamp, msg->size); srs_info("Video dts=%"PRId64", size=%d", msg->timestamp, msg->size);
bool is_sequence_header = SrsFlvCodec::video_is_sequence_header(msg->payload, msg->size); bool is_sequence_header = SrsFlvVideo::sh(msg->payload, msg->size);
// whether consumer should drop for the duplicated sequence header. // whether consumer should drop for the duplicated sequence header.
bool drop_for_reduce = false; bool drop_for_reduce = false;

View file

@ -99,14 +99,14 @@ SrsStatisticStream::SrsStatisticStream()
connection_cid = -1; connection_cid = -1;
has_video = false; has_video = false;
vcodec = SrsCodecVideoReserved; vcodec = SrsVideoCodecIdReserved;
avc_profile = SrsAvcProfileReserved; avc_profile = SrsAvcProfileReserved;
avc_level = SrsAvcLevelReserved; avc_level = SrsAvcLevelReserved;
has_audio = false; has_audio = false;
acodec = SrsCodecAudioReserved1; acodec = SrsAudioCodecIdReserved1;
asample_rate = SrsCodecAudioSampleRateReserved; asample_rate = SrsAudioSampleRateReserved;
asound_type = SrsCodecAudioSoundTypeReserved; asound_type = SrsAudioSoundTypeReserved;
aac_object = SrsAacObjectTypeReserved; aac_object = SrsAacObjectTypeReserved;
width = 0; width = 0;
height = 0; height = 0;
@ -153,9 +153,9 @@ int SrsStatisticStream::dumps(SrsJsonObject* obj)
SrsJsonObject* video = SrsJsonAny::object(); SrsJsonObject* video = SrsJsonAny::object();
obj->set("video", video); obj->set("video", video);
video->set("codec", SrsJsonAny::str(srs_codec_video2str(vcodec).c_str())); video->set("codec", SrsJsonAny::str(srs_video_codec_id2str(vcodec).c_str()));
video->set("profile", SrsJsonAny::str(srs_codec_avc_profile2str(avc_profile).c_str())); video->set("profile", SrsJsonAny::str(srs_avc_profile2str(avc_profile).c_str()));
video->set("level", SrsJsonAny::str(srs_codec_avc_level2str(avc_level).c_str())); video->set("level", SrsJsonAny::str(srs_avc_level2str(avc_level).c_str()));
video->set("width", SrsJsonAny::integer(width)); video->set("width", SrsJsonAny::integer(width));
video->set("height", SrsJsonAny::integer(height)); video->set("height", SrsJsonAny::integer(height));
} }
@ -166,10 +166,10 @@ int SrsStatisticStream::dumps(SrsJsonObject* obj)
SrsJsonObject* audio = SrsJsonAny::object(); SrsJsonObject* audio = SrsJsonAny::object();
obj->set("audio", audio); obj->set("audio", audio);
audio->set("codec", SrsJsonAny::str(srs_codec_audio2str(acodec).c_str())); audio->set("codec", SrsJsonAny::str(srs_audio_codec_id2str(acodec).c_str()));
audio->set("sample_rate", SrsJsonAny::integer(flv_sample_rates[asample_rate])); audio->set("sample_rate", SrsJsonAny::integer(srs_flv_srates[asample_rate]));
audio->set("channel", SrsJsonAny::integer(asound_type + 1)); audio->set("channel", SrsJsonAny::integer(asound_type + 1));
audio->set("profile", SrsJsonAny::str(srs_codec_aac_object2str(aac_object).c_str())); audio->set("profile", SrsJsonAny::str(srs_aac_object2str(aac_object).c_str()));
} }
return ret; return ret;
@ -309,7 +309,7 @@ SrsStatisticClient* SrsStatistic::find_client(int cid)
} }
int SrsStatistic::on_video_info(SrsRequest* req, int SrsStatistic::on_video_info(SrsRequest* req,
SrsCodecVideo vcodec, SrsAvcProfile avc_profile, SrsAvcLevel avc_level, SrsVideoCodecId vcodec, SrsAvcProfile avc_profile, SrsAvcLevel avc_level,
int width, int height int width, int height
) { ) {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
@ -329,7 +329,7 @@ int SrsStatistic::on_video_info(SrsRequest* req,
} }
int SrsStatistic::on_audio_info(SrsRequest* req, int SrsStatistic::on_audio_info(SrsRequest* req,
SrsCodecAudio acodec, SrsCodecAudioSampleRate asample_rate, SrsCodecAudioSoundType asound_type, SrsAudioCodecId acodec, SrsAudioSampleRate asample_rate, SrsAudioSoundType asound_type,
SrsAacObjectType aac_object SrsAacObjectType aac_object
) { ) {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;

View file

@ -80,7 +80,7 @@ public:
SrsKbps* kbps; SrsKbps* kbps;
public: public:
bool has_video; bool has_video;
SrsCodecVideo vcodec; SrsVideoCodecId vcodec;
// profile_idc, ISO_IEC_14496-10-AVC-2003.pdf, page 45. // profile_idc, ISO_IEC_14496-10-AVC-2003.pdf, page 45.
SrsAvcProfile avc_profile; SrsAvcProfile avc_profile;
// level_idc, ISO_IEC_14496-10-AVC-2003.pdf, page 45. // level_idc, ISO_IEC_14496-10-AVC-2003.pdf, page 45.
@ -90,9 +90,9 @@ public:
int height; int height;
public: public:
bool has_audio; bool has_audio;
SrsCodecAudio acodec; SrsAudioCodecId acodec;
SrsCodecAudioSampleRate asample_rate; SrsAudioSampleRate asample_rate;
SrsCodecAudioSoundType asound_type; SrsAudioSoundType asound_type;
/** /**
* audio specified * audio specified
* audioObjectType, in 1.6.2.1 AudioSpecificConfig, page 33, * audioObjectType, in 1.6.2.1 AudioSpecificConfig, page 33,
@ -170,14 +170,14 @@ public:
* when got video info for stream. * when got video info for stream.
*/ */
virtual int on_video_info(SrsRequest* req, virtual int on_video_info(SrsRequest* req,
SrsCodecVideo vcodec, SrsAvcProfile avc_profile, SrsAvcLevel avc_level, SrsVideoCodecId vcodec, SrsAvcProfile avc_profile, SrsAvcLevel avc_level,
int width, int height int width, int height
); );
/** /**
* when got audio info for stream. * when got audio info for stream.
*/ */
virtual int on_audio_info(SrsRequest* req, virtual int on_audio_info(SrsRequest* req,
SrsCodecAudio acodec, SrsCodecAudioSampleRate asample_rate, SrsCodecAudioSoundType asound_type, SrsAudioCodecId acodec, SrsAudioSampleRate asample_rate, SrsAudioSoundType asound_type,
SrsAacObjectType aac_object SrsAacObjectType aac_object
); );
/** /**

View file

@ -98,7 +98,7 @@ int SrsAacEncoder::write_audio(int64_t timestamp, char* data, int size)
//int8_t sound_rate = (sound_format >> 2) & 0x03; //int8_t sound_rate = (sound_format >> 2) & 0x03;
sound_format = (sound_format >> 4) & 0x0f; sound_format = (sound_format >> 4) & 0x0f;
if ((SrsCodecAudio)sound_format != SrsCodecAudioAAC) { if ((SrsAudioCodecId)sound_format != SrsAudioCodecIdAAC) {
ret = ERROR_AAC_DECODE_ERROR; ret = ERROR_AAC_DECODE_ERROR;
srs_error("aac required, format=%d. ret=%d", sound_format, ret); srs_error("aac required, format=%d. ret=%d", sound_format, ret);
return ret; return ret;
@ -110,8 +110,8 @@ int SrsAacEncoder::write_audio(int64_t timestamp, char* data, int size)
return ret; return ret;
} }
SrsCodecAudioType aac_packet_type = (SrsCodecAudioType)stream->read_1bytes(); SrsAudioAacFrameTrait aac_packet_type = (SrsAudioAacFrameTrait)stream->read_1bytes();
if (aac_packet_type == SrsCodecAudioTypeSequenceHeader) { if (aac_packet_type == SrsAudioAacFrameTraitSequenceHeader) {
// AudioSpecificConfig // AudioSpecificConfig
// 1.6.2.1 AudioSpecificConfig, in ISO_IEC_14496-3-AAC-2001.pdf, page 33. // 1.6.2.1 AudioSpecificConfig, in ISO_IEC_14496-3-AAC-2001.pdf, page 33.
// //
@ -187,7 +187,7 @@ int SrsAacEncoder::write_audio(int64_t timestamp, char* data, int size)
// channel_configuration 3 uimsbf // channel_configuration 3 uimsbf
// original/copy 1 bslbf // original/copy 1 bslbf
// home 1 bslbf // home 1 bslbf
SrsAacProfile aac_profile = srs_codec_aac_rtmp2ts(aac_object); SrsAacProfile aac_profile = srs_aac_rtmp2ts(aac_object);
*pp++ = ((aac_profile << 6) & 0xc0) | ((aac_sample_rate << 2) & 0x3c) | ((aac_channels >> 2) & 0x01); *pp++ = ((aac_profile << 6) & 0xc0) | ((aac_sample_rate << 2) & 0x3c) | ((aac_channels >> 2) & 0x01);
// 4bits left. // 4bits left.
// adts_variable_header(), 1.A.2.2.2 Variable Header of ADTS // adts_variable_header(), 1.A.2.2.2 Variable Header of ADTS

View file

@ -33,71 +33,71 @@ using namespace std;
#include <srs_kernel_utility.hpp> #include <srs_kernel_utility.hpp>
#include <srs_core_autofree.hpp> #include <srs_core_autofree.hpp>
string srs_codec_video2str(SrsCodecVideo codec) string srs_video_codec_id2str(SrsVideoCodecId codec)
{ {
switch (codec) { switch (codec) {
case SrsCodecVideoAVC: case SrsVideoCodecIdAVC:
return "H264"; return "H264";
case SrsCodecVideoOn2VP6: case SrsVideoCodecIdOn2VP6:
case SrsCodecVideoOn2VP6WithAlphaChannel: case SrsVideoCodecIdOn2VP6WithAlphaChannel:
return "VP6"; return "VP6";
case SrsCodecVideoReserved: case SrsVideoCodecIdReserved:
case SrsCodecVideoReserved1: case SrsVideoCodecIdReserved1:
case SrsCodecVideoReserved2: case SrsVideoCodecIdReserved2:
case SrsCodecVideoDisabled: case SrsVideoCodecIdDisabled:
case SrsCodecVideoSorensonH263: case SrsVideoCodecIdSorensonH263:
case SrsCodecVideoScreenVideo: case SrsVideoCodecIdScreenVideo:
case SrsCodecVideoScreenVideoVersion2: case SrsVideoCodecIdScreenVideoVersion2:
default: default:
return "Other"; return "Other";
} }
} }
string srs_codec_audio2str(SrsCodecAudio codec) string srs_audio_codec_id2str(SrsAudioCodecId codec)
{ {
switch (codec) { switch (codec) {
case SrsCodecAudioAAC: case SrsAudioCodecIdAAC:
return "AAC"; return "AAC";
case SrsCodecAudioMP3: case SrsAudioCodecIdMP3:
return "MP3"; return "MP3";
case SrsCodecAudioReserved1: case SrsAudioCodecIdReserved1:
case SrsCodecAudioLinearPCMPlatformEndian: case SrsAudioCodecIdLinearPCMPlatformEndian:
case SrsCodecAudioADPCM: case SrsAudioCodecIdADPCM:
case SrsCodecAudioLinearPCMLittleEndian: case SrsAudioCodecIdLinearPCMLittleEndian:
case SrsCodecAudioNellymoser16kHzMono: case SrsAudioCodecIdNellymoser16kHzMono:
case SrsCodecAudioNellymoser8kHzMono: case SrsAudioCodecIdNellymoser8kHzMono:
case SrsCodecAudioNellymoser: case SrsAudioCodecIdNellymoser:
case SrsCodecAudioReservedG711AlawLogarithmicPCM: case SrsAudioCodecIdReservedG711AlawLogarithmicPCM:
case SrsCodecAudioReservedG711MuLawLogarithmicPCM: case SrsAudioCodecIdReservedG711MuLawLogarithmicPCM:
case SrsCodecAudioReserved: case SrsAudioCodecIdReserved:
case SrsCodecAudioSpeex: case SrsAudioCodecIdSpeex:
case SrsCodecAudioReservedMP3_8kHz: case SrsAudioCodecIdReservedMP3_8kHz:
case SrsCodecAudioReservedDeviceSpecificSound: case SrsAudioCodecIdReservedDeviceSpecificSound:
default: default:
return "Other"; return "Other";
} }
} }
string srs_codec_audio_samplerate2str(SrsCodecAudioSampleRate v) string srs_codec_audio_samplerate2str(SrsAudioSampleRate v)
{ {
switch (v) { switch (v) {
case SrsCodecAudioSampleRate5512: return "5512"; case SrsAudioSampleRate5512: return "5512";
case SrsCodecAudioSampleRate11025: return "11025"; case SrsAudioSampleRate11025: return "11025";
case SrsCodecAudioSampleRate22050: return "22050"; case SrsAudioSampleRate22050: return "22050";
case SrsCodecAudioSampleRate44100: return "44100"; case SrsAudioSampleRate44100: return "44100";
default: return "Other"; default: return "Other";
} }
} }
SrsFlvCodec::SrsFlvCodec() SrsFlvVideo::SrsFlvVideo()
{ {
} }
SrsFlvCodec::~SrsFlvCodec() SrsFlvVideo::~SrsFlvVideo()
{ {
} }
bool SrsFlvCodec::video_is_keyframe(char* data, int size) bool SrsFlvVideo::keyframe(char* data, int size)
{ {
// 2bytes required. // 2bytes required.
if (size < 1) { if (size < 1) {
@ -107,13 +107,13 @@ bool SrsFlvCodec::video_is_keyframe(char* data, int size)
char frame_type = data[0]; char frame_type = data[0];
frame_type = (frame_type >> 4) & 0x0F; frame_type = (frame_type >> 4) & 0x0F;
return frame_type == SrsCodecVideoAVCFrameKeyFrame; return frame_type == SrsVideoAvcFrameTypeKeyFrame;
} }
bool SrsFlvCodec::video_is_sequence_header(char* data, int size) bool SrsFlvVideo::sh(char* data, int size)
{ {
// sequence header only for h264 // sequence header only for h264
if (!video_is_h264(data, size)) { if (!h264(data, size)) {
return false; return false;
} }
@ -127,28 +127,11 @@ bool SrsFlvCodec::video_is_sequence_header(char* data, int size)
char avc_packet_type = data[1]; char avc_packet_type = data[1];
return frame_type == SrsCodecVideoAVCFrameKeyFrame return frame_type == SrsVideoAvcFrameTypeKeyFrame
&& avc_packet_type == SrsCodecVideoAVCTypeSequenceHeader; && avc_packet_type == SrsVideoAvcFrameTraitSequenceHeader;
} }
bool SrsFlvCodec::audio_is_sequence_header(char* data, int size) bool SrsFlvVideo::h264(char* data, int size)
{
// sequence header only for aac
if (!audio_is_aac(data, size)) {
return false;
}
// 2bytes required.
if (size < 2) {
return false;
}
char aac_packet_type = data[1];
return aac_packet_type == SrsCodecAudioTypeSequenceHeader;
}
bool SrsFlvCodec::video_is_h264(char* data, int size)
{ {
// 1bytes required. // 1bytes required.
if (size < 1) { if (size < 1) {
@ -158,23 +141,10 @@ bool SrsFlvCodec::video_is_h264(char* data, int size)
char codec_id = data[0]; char codec_id = data[0];
codec_id = codec_id & 0x0F; codec_id = codec_id & 0x0F;
return codec_id == SrsCodecVideoAVC; return codec_id == SrsVideoCodecIdAVC;
} }
bool SrsFlvCodec::audio_is_aac(char* data, int size) bool SrsFlvVideo::acceptable(char* data, int size)
{
// 1bytes required.
if (size < 1) {
return false;
}
char sound_format = data[0];
sound_format = (sound_format >> 4) & 0x0F;
return sound_format == SrsCodecAudioAAC;
}
bool SrsFlvCodec::video_is_acceptable(char* data, int size)
{ {
// 1bytes required. // 1bytes required.
if (size < 1) { if (size < 1) {
@ -196,6 +166,36 @@ bool SrsFlvCodec::video_is_acceptable(char* data, int size)
return true; return true;
} }
bool SrsFlvAudio::sh(char* data, int size)
{
// sequence header only for aac
if (!aac(data, size)) {
return false;
}
// 2bytes required.
if (size < 2) {
return false;
}
char aac_packet_type = data[1];
return aac_packet_type == SrsAudioAacFrameTraitSequenceHeader;
}
bool SrsFlvAudio::aac(char* data, int size)
{
// 1bytes required.
if (size < 1) {
return false;
}
char sound_format = data[0];
sound_format = (sound_format >> 4) & 0x0F;
return sound_format == SrsAudioCodecIdAAC;
}
/** /**
* the public data, event HLS disable, others can use it. * the public data, event HLS disable, others can use it.
*/ */
@ -203,11 +203,11 @@ bool SrsFlvCodec::video_is_acceptable(char* data, int size)
// 1 = 11 kHz = 11025 Hz // 1 = 11 kHz = 11025 Hz
// 2 = 22 kHz = 22050 Hz // 2 = 22 kHz = 22050 Hz
// 3 = 44 kHz = 44100 Hz // 3 = 44 kHz = 44100 Hz
int flv_sample_rates[] = {5512, 11025, 22050, 44100}; int srs_flv_srates[] = {5512, 11025, 22050, 44100};
// the sample rates in the codec, // the sample rates in the codec,
// in the sequence header. // in the sequence header.
int aac_sample_rates[] = int srs_aac_srates[] =
{ {
96000, 88200, 64000, 48000, 96000, 88200, 64000, 48000,
44100, 32000, 24000, 22050, 44100, 32000, 24000, 22050,
@ -215,25 +215,25 @@ int aac_sample_rates[] =
7350, 0, 0, 0 7350, 0, 0, 0
}; };
string srs_codec_audio_samplesize2str(SrsCodecAudioSampleSize v) string srs_audio_samplesize2str(SrsAudioSampleSize v)
{ {
switch (v) { switch (v) {
case SrsCodecAudioSampleSize16bit: return "16bits"; case SrsAudioSampleSize16bit: return "16bits";
case SrsCodecAudioSampleSize8bit: return "8bits"; case SrsAudioSampleSize8bit: return "8bits";
default: return "Other"; default: return "Other";
} }
} }
string srs_codec_audio_channels2str(SrsCodecAudioSoundType v) string srs_audio_channels2str(SrsAudioSoundType v)
{ {
switch (v) { switch (v) {
case SrsCodecAudioSoundTypeStereo: return "Stereo"; case SrsAudioSoundTypeStereo: return "Stereo";
case SrsCodecAudioSoundTypeMono: return "Mono"; case SrsAudioSoundTypeMono: return "Mono";
default: return "Other"; default: return "Other";
} }
} }
string srs_codec_avc_nalu2str(SrsAvcNaluType nalu_type) string srs_avc_nalu2str(SrsAvcNaluType nalu_type)
{ {
switch (nalu_type) { switch (nalu_type) {
case SrsAvcNaluTypeNonIDR: return "NonIDR"; case SrsAvcNaluTypeNonIDR: return "NonIDR";
@ -257,7 +257,7 @@ string srs_codec_avc_nalu2str(SrsAvcNaluType nalu_type)
} }
} }
string srs_codec_aac_profile2str(SrsAacProfile aac_profile) string srs_aac_profile2str(SrsAacProfile aac_profile)
{ {
switch (aac_profile) { switch (aac_profile) {
case SrsAacProfileMain: return "Main"; case SrsAacProfileMain: return "Main";
@ -267,7 +267,7 @@ string srs_codec_aac_profile2str(SrsAacProfile aac_profile)
} }
} }
string srs_codec_aac_object2str(SrsAacObjectType aac_object) string srs_aac_object2str(SrsAacObjectType aac_object)
{ {
switch (aac_object) { switch (aac_object) {
case SrsAacObjectTypeAacMain: return "Main"; case SrsAacObjectTypeAacMain: return "Main";
@ -279,7 +279,7 @@ string srs_codec_aac_object2str(SrsAacObjectType aac_object)
} }
} }
SrsAacObjectType srs_codec_aac_ts2rtmp(SrsAacProfile profile) SrsAacObjectType srs_aac_ts2rtmp(SrsAacProfile profile)
{ {
switch (profile) { switch (profile) {
case SrsAacProfileMain: return SrsAacObjectTypeAacMain; case SrsAacProfileMain: return SrsAacObjectTypeAacMain;
@ -289,7 +289,7 @@ SrsAacObjectType srs_codec_aac_ts2rtmp(SrsAacProfile profile)
} }
} }
SrsAacProfile srs_codec_aac_rtmp2ts(SrsAacObjectType object_type) SrsAacProfile srs_aac_rtmp2ts(SrsAacObjectType object_type)
{ {
switch (object_type) { switch (object_type) {
case SrsAacObjectTypeAacMain: return SrsAacProfileMain; case SrsAacObjectTypeAacMain: return SrsAacProfileMain;
@ -301,7 +301,7 @@ SrsAacProfile srs_codec_aac_rtmp2ts(SrsAacObjectType object_type)
} }
} }
string srs_codec_avc_profile2str(SrsAvcProfile profile) string srs_avc_profile2str(SrsAvcProfile profile)
{ {
switch (profile) { switch (profile) {
case SrsAvcProfileBaseline: return "Baseline"; case SrsAvcProfileBaseline: return "Baseline";
@ -320,7 +320,7 @@ string srs_codec_avc_profile2str(SrsAvcProfile profile)
} }
} }
string srs_codec_avc_level2str(SrsAvcLevel level) string srs_avc_level2str(SrsAvcLevel level)
{ {
switch (level) { switch (level) {
case SrsAvcLevel_1: return "1"; case SrsAvcLevel_1: return "1";
@ -351,42 +351,42 @@ SrsSample::~SrsSample()
{ {
} }
SrsCodec::SrsCodec() SrsCodecConfig::SrsCodecConfig()
{ {
} }
SrsCodec::~SrsCodec() SrsCodecConfig::~SrsCodecConfig()
{ {
} }
SrsAudioCodec::SrsAudioCodec() SrsAudioCodecConfig::SrsAudioCodecConfig()
{ {
id = SrsCodecAudioForbidden; id = SrsAudioCodecIdForbidden;
sound_rate = SrsCodecAudioSampleRateForbidden; sound_rate = SrsAudioSampleRateForbidden;
sound_size = SrsCodecAudioSampleSizeForbidden; sound_size = SrsAudioSampleSizeForbidden;
sound_type = SrsCodecAudioSoundTypeForbidden; sound_type = SrsAudioSoundTypeForbidden;
audio_data_rate = 0; audio_data_rate = 0;
aac_object = SrsAacObjectTypeForbidden; aac_object = SrsAacObjectTypeForbidden;
aac_sample_rate = SRS_AAC_SAMPLE_RATE_UNSET; // sample rate ignored aac_sample_rate = SrsAacSampleRateUnset; // sample rate ignored
aac_channels = 0; aac_channels = 0;
aac_extra_size = 0; aac_extra_size = 0;
aac_extra_data = NULL; aac_extra_data = NULL;
} }
SrsAudioCodec::~SrsAudioCodec() SrsAudioCodecConfig::~SrsAudioCodecConfig()
{ {
} }
bool SrsAudioCodec::is_aac_codec_ok() bool SrsAudioCodecConfig::is_aac_codec_ok()
{ {
return aac_extra_size > 0 && aac_extra_data; return aac_extra_size > 0 && aac_extra_data;
} }
SrsVideoCodec::SrsVideoCodec() SrsVideoCodecConfig::SrsVideoCodecConfig()
{ {
id = SrsCodecVideoForbidden; id = SrsVideoCodecIdForbidden;
video_data_rate = 0; video_data_rate = 0;
frame_rate = duration = 0; frame_rate = duration = 0;
@ -407,14 +407,14 @@ SrsVideoCodec::SrsVideoCodec()
payload_format = SrsAvcPayloadFormatGuess; payload_format = SrsAvcPayloadFormatGuess;
} }
SrsVideoCodec::~SrsVideoCodec() SrsVideoCodecConfig::~SrsVideoCodecConfig()
{ {
srs_freepa(avc_extra_data); srs_freepa(avc_extra_data);
srs_freepa(sequenceParameterSetNALUnit); srs_freepa(sequenceParameterSetNALUnit);
srs_freepa(pictureParameterSetNALUnit); srs_freepa(pictureParameterSetNALUnit);
} }
bool SrsVideoCodec::is_avc_codec_ok() bool SrsVideoCodecConfig::is_avc_codec_ok()
{ {
return avc_extra_size > 0 && avc_extra_data; return avc_extra_size > 0 && avc_extra_data;
} }
@ -432,7 +432,7 @@ SrsFrame::~SrsFrame()
srs_freep(codec); srs_freep(codec);
} }
int SrsFrame::initialize(SrsCodec* c) int SrsFrame::initialize(SrsCodecConfig* c)
{ {
codec = c; codec = c;
nb_samples = 0; nb_samples = 0;
@ -445,9 +445,9 @@ int SrsFrame::add_sample(char* bytes, int size)
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
if (nb_samples >= SRS_MAX_CODEC_SAMPLE) { if (nb_samples >= SrsMaxNbSamples) {
ret = ERROR_HLS_DECODE_ERROR; ret = ERROR_HLS_DECODE_ERROR;
srs_error("Frame samples overflow, max=%d. ret=%d", SRS_MAX_CODEC_SAMPLE, ret); srs_error("Frame samples overflow, max=%d. ret=%d", SrsMaxNbSamples, ret);
return ret; return ret;
} }
@ -460,22 +460,22 @@ int SrsFrame::add_sample(char* bytes, int size)
SrsAudioFrame::SrsAudioFrame() SrsAudioFrame::SrsAudioFrame()
{ {
aac_packet_type = SrsCodecAudioTypeForbidden; aac_packet_type = SrsAudioAacFrameTraitForbidden;
} }
SrsAudioFrame::~SrsAudioFrame() SrsAudioFrame::~SrsAudioFrame()
{ {
} }
SrsAudioCodec* SrsAudioFrame::acodec() SrsAudioCodecConfig* SrsAudioFrame::acodec()
{ {
return (SrsAudioCodec*)codec; return (SrsAudioCodecConfig*)codec;
} }
SrsVideoFrame::SrsVideoFrame() SrsVideoFrame::SrsVideoFrame()
{ {
frame_type = SrsCodecVideoAVCFrameForbidden; frame_type = SrsVideoAvcFrameTypeForbidden;
avc_packet_type = SrsCodecVideoAVCTypeForbidden; avc_packet_type = SrsVideoAvcFrameTraitForbidden;
has_idr = has_aud = has_sps_pps = false; has_idr = has_aud = has_sps_pps = false;
first_nalu_type = SrsAvcNaluTypeForbidden; first_nalu_type = SrsAvcNaluTypeForbidden;
} }
@ -510,9 +510,9 @@ int SrsVideoFrame::add_sample(char* bytes, int size)
return ret; return ret;
} }
SrsVideoCodec* SrsVideoFrame::vcodec() SrsVideoCodecConfig* SrsVideoFrame::vcodec()
{ {
return (SrsVideoCodec*)codec; return (SrsVideoCodecConfig*)codec;
} }
SrsFormat::SrsFormat() SrsFormat::SrsFormat()
@ -560,14 +560,14 @@ int SrsFormat::on_audio(int64_t timestamp, char* data, int size)
} }
// @see: E.4.2 Audio Tags, video_file_format_spec_v10_1.pdf, page 76 // @see: E.4.2 Audio Tags, video_file_format_spec_v10_1.pdf, page 76
SrsCodecAudio codec = (SrsCodecAudio)((buffer->read_1bytes() >> 4) & 0x0f); SrsAudioCodecId codec = (SrsAudioCodecId)((buffer->read_1bytes() >> 4) & 0x0f);
if (codec != SrsCodecAudioMP3 && codec != SrsCodecAudioAAC) { if (codec != SrsAudioCodecIdMP3 && codec != SrsAudioCodecIdAAC) {
return ret; return ret;
} }
if (!acodec) { if (!acodec) {
acodec = new SrsAudioCodec(); acodec = new SrsAudioCodecConfig();
} }
if (!audio) { if (!audio) {
audio = new SrsAudioFrame(); audio = new SrsAudioFrame();
@ -578,9 +578,9 @@ int SrsFormat::on_audio(int64_t timestamp, char* data, int size)
} }
buffer->skip(-1 * buffer->pos()); buffer->skip(-1 * buffer->pos());
if (codec == SrsCodecAudioMP3) { if (codec == SrsAudioCodecIdMP3) {
return audio_mp3_demux(buffer, timestamp); return audio_mp3_demux(buffer, timestamp);
} else if (codec == SrsCodecAudioAAC) { } else if (codec == SrsAudioCodecIdAAC) {
return audio_aac_demux(buffer, timestamp); return audio_aac_demux(buffer, timestamp);
} else { } else {
return ret; return ret;
@ -609,15 +609,15 @@ int SrsFormat::on_video(int64_t timestamp, char* data, int size)
// @see: E.4.3 Video Tags, video_file_format_spec_v10_1.pdf, page 78 // @see: E.4.3 Video Tags, video_file_format_spec_v10_1.pdf, page 78
int8_t frame_type = buffer->read_1bytes(); int8_t frame_type = buffer->read_1bytes();
SrsCodecVideo codec_id = (SrsCodecVideo)(frame_type & 0x0f); SrsVideoCodecId codec_id = (SrsVideoCodecId)(frame_type & 0x0f);
// TODO: Support other codecs. // TODO: Support other codecs.
if (codec_id != SrsCodecVideoAVC) { if (codec_id != SrsVideoCodecIdAVC) {
return ret; return ret;
} }
if (!vcodec) { if (!vcodec) {
vcodec = new SrsVideoCodec(); vcodec = new SrsVideoCodecConfig();
} }
if (!video) { if (!video) {
video = new SrsVideoFrame(); video = new SrsVideoFrame();
@ -636,7 +636,7 @@ int SrsFormat::on_aac_sequence_header(char* data, int size)
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
if (!acodec) { if (!acodec) {
acodec = new SrsAudioCodec(); acodec = new SrsAudioCodecConfig();
} }
if (!audio) { if (!audio) {
audio = new SrsAudioFrame(); audio = new SrsAudioFrame();
@ -651,14 +651,14 @@ int SrsFormat::on_aac_sequence_header(char* data, int size)
bool SrsFormat::is_aac_sequence_header() bool SrsFormat::is_aac_sequence_header()
{ {
return acodec && acodec->id == SrsCodecAudioAAC return acodec && acodec->id == SrsAudioCodecIdAAC
&& audio && audio->aac_packet_type == SrsCodecAudioTypeSequenceHeader; && audio && audio->aac_packet_type == SrsAudioAacFrameTraitSequenceHeader;
} }
bool SrsFormat::is_avc_sequence_header() bool SrsFormat::is_avc_sequence_header()
{ {
return vcodec && vcodec->id == SrsCodecVideoAVC return vcodec && vcodec->id == SrsVideoCodecIdAVC
&& video && video->avc_packet_type == SrsCodecVideoAVCTypeSequenceHeader; && video && video->avc_packet_type == SrsVideoAvcFrameTraitSequenceHeader;
} }
int SrsFormat::video_avc_demux(SrsBuffer* stream, int64_t timestamp) int SrsFormat::video_avc_demux(SrsBuffer* stream, int64_t timestamp)
@ -667,20 +667,20 @@ int SrsFormat::video_avc_demux(SrsBuffer* stream, int64_t timestamp)
// @see: E.4.3 Video Tags, video_file_format_spec_v10_1.pdf, page 78 // @see: E.4.3 Video Tags, video_file_format_spec_v10_1.pdf, page 78
int8_t frame_type = stream->read_1bytes(); int8_t frame_type = stream->read_1bytes();
SrsCodecVideo codec_id = (SrsCodecVideo)(frame_type & 0x0f); SrsVideoCodecId codec_id = (SrsVideoCodecId)(frame_type & 0x0f);
frame_type = (frame_type >> 4) & 0x0f; frame_type = (frame_type >> 4) & 0x0f;
video->frame_type = (SrsCodecVideoAVCFrame)frame_type; video->frame_type = (SrsVideoAvcFrameType)frame_type;
// ignore info frame without error, // ignore info frame without error,
// @see https://github.com/ossrs/srs/issues/288#issuecomment-69863909 // @see https://github.com/ossrs/srs/issues/288#issuecomment-69863909
if (video->frame_type == SrsCodecVideoAVCFrameVideoInfoFrame) { if (video->frame_type == SrsVideoAvcFrameTypeVideoInfoFrame) {
srs_warn("avc igone the info frame, ret=%d", ret); srs_warn("avc igone the info frame, ret=%d", ret);
return ret; return ret;
} }
// only support h.264/avc // only support h.264/avc
if (codec_id != SrsCodecVideoAVC) { if (codec_id != SrsVideoCodecIdAVC) {
ret = ERROR_HLS_DECODE_ERROR; ret = ERROR_HLS_DECODE_ERROR;
srs_error("avc only support video h.264/avc codec. actual=%d, ret=%d", codec_id, ret); srs_error("avc only support video h.264/avc codec. actual=%d, ret=%d", codec_id, ret);
return ret; return ret;
@ -698,13 +698,13 @@ int SrsFormat::video_avc_demux(SrsBuffer* stream, int64_t timestamp)
// pts = dts + cts. // pts = dts + cts.
video->dts = timestamp; video->dts = timestamp;
video->cts = composition_time; video->cts = composition_time;
video->avc_packet_type = (SrsCodecVideoAVCType)avc_packet_type; video->avc_packet_type = (SrsVideoAvcFrameTrait)avc_packet_type;
if (avc_packet_type == SrsCodecVideoAVCTypeSequenceHeader) { if (avc_packet_type == SrsVideoAvcFrameTraitSequenceHeader) {
if ((ret = avc_demux_sps_pps(stream)) != ERROR_SUCCESS) { if ((ret = avc_demux_sps_pps(stream)) != ERROR_SUCCESS) {
return ret; return ret;
} }
} else if (avc_packet_type == SrsCodecVideoAVCTypeNALU){ } else if (avc_packet_type == SrsVideoAvcFrameTraitNALU){
if ((ret = video_nalu_demux(stream)) != ERROR_SUCCESS) { if ((ret = video_nalu_demux(stream)) != ERROR_SUCCESS) {
return ret; return ret;
} }
@ -1086,7 +1086,7 @@ int SrsFormat::video_nalu_demux(SrsBuffer* stream)
// ensure the sequence header demuxed // ensure the sequence header demuxed
if (!vcodec->is_avc_codec_ok()) { if (!vcodec->is_avc_codec_ok()) {
srs_warn("avc ignore type=%d for no sequence header. ret=%d", SrsCodecVideoAVCTypeNALU, ret); srs_warn("avc ignore type=%d for no sequence header. ret=%d", SrsVideoAvcFrameTraitNALU, ret);
return ret; return ret;
} }
@ -1267,20 +1267,20 @@ int SrsFormat::audio_aac_demux(SrsBuffer* stream, int64_t timestamp)
int8_t sound_rate = (sound_format >> 2) & 0x03; int8_t sound_rate = (sound_format >> 2) & 0x03;
sound_format = (sound_format >> 4) & 0x0f; sound_format = (sound_format >> 4) & 0x0f;
SrsCodecAudio codec_id = (SrsCodecAudio)sound_format; SrsAudioCodecId codec_id = (SrsAudioCodecId)sound_format;
acodec->id = codec_id; acodec->id = codec_id;
acodec->sound_type = (SrsCodecAudioSoundType)sound_type; acodec->sound_type = (SrsAudioSoundType)sound_type;
acodec->sound_rate = (SrsCodecAudioSampleRate)sound_rate; acodec->sound_rate = (SrsAudioSampleRate)sound_rate;
acodec->sound_size = (SrsCodecAudioSampleSize)sound_size; acodec->sound_size = (SrsAudioSampleSize)sound_size;
// we support h.264+mp3 for hls. // we support h.264+mp3 for hls.
if (codec_id == SrsCodecAudioMP3) { if (codec_id == SrsAudioCodecIdMP3) {
return ERROR_HLS_TRY_MP3; return ERROR_HLS_TRY_MP3;
} }
// only support aac // only support aac
if (codec_id != SrsCodecAudioAAC) { if (codec_id != SrsAudioCodecIdAAC) {
ret = ERROR_HLS_DECODE_ERROR; ret = ERROR_HLS_DECODE_ERROR;
srs_error("aac only support mp3/aac codec. actual=%d, ret=%d", codec_id, ret); srs_error("aac only support mp3/aac codec. actual=%d, ret=%d", codec_id, ret);
return ret; return ret;
@ -1292,10 +1292,10 @@ int SrsFormat::audio_aac_demux(SrsBuffer* stream, int64_t timestamp)
return ret; return ret;
} }
SrsCodecAudioType aac_packet_type = (SrsCodecAudioType)stream->read_1bytes(); SrsAudioAacFrameTrait aac_packet_type = (SrsAudioAacFrameTrait)stream->read_1bytes();
audio->aac_packet_type = (SrsCodecAudioType)aac_packet_type; audio->aac_packet_type = (SrsAudioAacFrameTrait)aac_packet_type;
if (aac_packet_type == SrsCodecAudioTypeSequenceHeader) { if (aac_packet_type == SrsAudioAacFrameTraitSequenceHeader) {
// AudioSpecificConfig // AudioSpecificConfig
// 1.6.2.1 AudioSpecificConfig, in ISO_IEC_14496-3-AAC-2001.pdf, page 33. // 1.6.2.1 AudioSpecificConfig, in ISO_IEC_14496-3-AAC-2001.pdf, page 33.
acodec->aac_extra_size = stream->size() - stream->pos(); acodec->aac_extra_size = stream->size() - stream->pos();
@ -1308,7 +1308,7 @@ int SrsFormat::audio_aac_demux(SrsBuffer* stream, int64_t timestamp)
return ret; return ret;
} }
} }
} else if (aac_packet_type == SrsCodecAudioTypeRawData) { } else if (aac_packet_type == SrsAudioAacFrameTraitRawData) {
// ensure the sequence header demuxed // ensure the sequence header demuxed
if (!acodec->is_aac_codec_ok()) { if (!acodec->is_aac_codec_ok()) {
srs_warn("aac ignore type=%d for no sequence header. ret=%d", aac_packet_type, ret); srs_warn("aac ignore type=%d for no sequence header. ret=%d", aac_packet_type, ret);
@ -1326,22 +1326,22 @@ int SrsFormat::audio_aac_demux(SrsBuffer* stream, int64_t timestamp)
} }
// reset the sample rate by sequence header // reset the sample rate by sequence header
if (acodec->aac_sample_rate != SRS_AAC_SAMPLE_RATE_UNSET) { if (acodec->aac_sample_rate != SrsAacSampleRateUnset) {
static int aac_sample_rates[] = { static int srs_aac_srates[] = {
96000, 88200, 64000, 48000, 96000, 88200, 64000, 48000,
44100, 32000, 24000, 22050, 44100, 32000, 24000, 22050,
16000, 12000, 11025, 8000, 16000, 12000, 11025, 8000,
7350, 0, 0, 0 7350, 0, 0, 0
}; };
switch (aac_sample_rates[acodec->aac_sample_rate]) { switch (srs_aac_srates[acodec->aac_sample_rate]) {
case 11025: case 11025:
acodec->sound_rate = SrsCodecAudioSampleRate11025; acodec->sound_rate = SrsAudioSampleRate11025;
break; break;
case 22050: case 22050:
acodec->sound_rate = SrsCodecAudioSampleRate22050; acodec->sound_rate = SrsAudioSampleRate22050;
break; break;
case 44100: case 44100:
acodec->sound_rate = SrsCodecAudioSampleRate44100; acodec->sound_rate = SrsAudioSampleRate44100;
break; break;
default: default:
break; break;
@ -1362,7 +1362,7 @@ int SrsFormat::audio_mp3_demux(SrsBuffer* stream, int64_t timestamp)
audio->dts = timestamp; audio->dts = timestamp;
// we always decode aac then mp3. // we always decode aac then mp3.
srs_assert(acodec->id == SrsCodecAudioMP3); srs_assert(acodec->id == SrsAudioCodecIdMP3);
stream->skip(1); stream->skip(1);
if (stream->empty()) { if (stream->empty()) {

View file

@ -34,207 +34,241 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class SrsBuffer; class SrsBuffer;
// AACPacketType IF SoundFormat == 10 UI8 /**
// The following values are defined: * The video codec id.
// 0 = AAC sequence header * @doc video_file_format_spec_v10_1.pdf, page78, E.4.3.1 VIDEODATA
// 1 = AAC raw * CodecID UB [4]
enum SrsCodecAudioType * Codec Identifier. The following values are defined for FLV:
{ * 2 = Sorenson H.263
// set to the max value to reserved, for array map. * 3 = Screen video
SrsCodecAudioTypeReserved = 2, * 4 = On2 VP6
SrsCodecAudioTypeForbidden = 2, * 5 = On2 VP6 with alpha channel
* 6 = Screen video version 2
SrsCodecAudioTypeSequenceHeader = 0, * 7 = AVC
SrsCodecAudioTypeRawData = 1, */
}; enum SrsVideoCodecId
// E.4.3.1 VIDEODATA
// Frame Type UB [4]
// Type of video frame. The following values are defined:
// 1 = key frame (for AVC, a seekable frame)
// 2 = inter frame (for AVC, a non-seekable frame)
// 3 = disposable inter frame (H.263 only)
// 4 = generated key frame (reserved for server use only)
// 5 = video info/command frame
enum SrsCodecVideoAVCFrame
{ {
// set to the zero to reserved, for array map. // set to the zero to reserved, for array map.
SrsCodecVideoAVCFrameReserved = 0, SrsVideoCodecIdReserved = 0,
SrsCodecVideoAVCFrameForbidden = 0, SrsVideoCodecIdForbidden = 0,
SrsCodecVideoAVCFrameReserved1 = 6, SrsVideoCodecIdReserved1 = 1,
SrsVideoCodecIdReserved2 = 9,
SrsCodecVideoAVCFrameKeyFrame = 1,
SrsCodecVideoAVCFrameInterFrame = 2,
SrsCodecVideoAVCFrameDisposableInterFrame = 3,
SrsCodecVideoAVCFrameGeneratedKeyFrame = 4,
SrsCodecVideoAVCFrameVideoInfoFrame = 5,
};
// AVCPacketType IF CodecID == 7 UI8
// The following values are defined:
// 0 = AVC sequence header
// 1 = AVC NALU
// 2 = AVC end of sequence (lower level NALU sequence ender is
// not required or supported)
enum SrsCodecVideoAVCType
{
// set to the max value to reserved, for array map.
SrsCodecVideoAVCTypeReserved = 3,
SrsCodecVideoAVCTypeForbidden = 3,
SrsCodecVideoAVCTypeSequenceHeader = 0,
SrsCodecVideoAVCTypeNALU = 1,
SrsCodecVideoAVCTypeSequenceHeaderEOF = 2,
};
// E.4.3.1 VIDEODATA
// CodecID UB [4]
// Codec Identifier. The following values are defined:
// 2 = Sorenson H.263
// 3 = Screen video
// 4 = On2 VP6
// 5 = On2 VP6 with alpha channel
// 6 = Screen video version 2
// 7 = AVC
enum SrsCodecVideo
{
// set to the zero to reserved, for array map.
SrsCodecVideoReserved = 0,
SrsCodecVideoForbidden = 0,
SrsCodecVideoReserved1 = 1,
SrsCodecVideoReserved2 = 9,
// for user to disable video, for example, use pure audio hls. // for user to disable video, for example, use pure audio hls.
SrsCodecVideoDisabled = 8, SrsVideoCodecIdDisabled = 8,
SrsCodecVideoSorensonH263 = 2, SrsVideoCodecIdSorensonH263 = 2,
SrsCodecVideoScreenVideo = 3, SrsVideoCodecIdScreenVideo = 3,
SrsCodecVideoOn2VP6 = 4, SrsVideoCodecIdOn2VP6 = 4,
SrsCodecVideoOn2VP6WithAlphaChannel = 5, SrsVideoCodecIdOn2VP6WithAlphaChannel = 5,
SrsCodecVideoScreenVideoVersion2 = 6, SrsVideoCodecIdScreenVideoVersion2 = 6,
SrsCodecVideoAVC = 7, SrsVideoCodecIdAVC = 7,
}; };
std::string srs_codec_video2str(SrsCodecVideo codec); std::string srs_video_codec_id2str(SrsVideoCodecId codec);
// SoundFormat UB [4]
// Format of SoundData. The following values are defined:
// 0 = Linear PCM, platform endian
// 1 = ADPCM
// 2 = MP3
// 3 = Linear PCM, little endian
// 4 = Nellymoser 16 kHz mono
// 5 = Nellymoser 8 kHz mono
// 6 = Nellymoser
// 7 = G.711 A-law logarithmic PCM
// 8 = G.711 mu-law logarithmic PCM
// 9 = reserved
// 10 = AAC
// 11 = Speex
// 14 = MP3 8 kHz
// 15 = Device-specific sound
// Formats 7, 8, 14, and 15 are reserved.
// AAC is supported in Flash Player 9,0,115,0 and higher.
// Speex is supported in Flash Player 10 and higher.
enum SrsCodecAudio
{
// set to the max value to reserved, for array map.
SrsCodecAudioReserved1 = 16,
SrsCodecAudioForbidden = 16,
// for user to disable audio, for example, use pure video hls.
SrsCodecAudioDisabled = 17,
SrsCodecAudioLinearPCMPlatformEndian = 0,
SrsCodecAudioADPCM = 1,
SrsCodecAudioMP3 = 2,
SrsCodecAudioLinearPCMLittleEndian = 3,
SrsCodecAudioNellymoser16kHzMono = 4,
SrsCodecAudioNellymoser8kHzMono = 5,
SrsCodecAudioNellymoser = 6,
SrsCodecAudioReservedG711AlawLogarithmicPCM = 7,
SrsCodecAudioReservedG711MuLawLogarithmicPCM = 8,
SrsCodecAudioReserved = 9,
SrsCodecAudioAAC = 10,
SrsCodecAudioSpeex = 11,
SrsCodecAudioReservedMP3_8kHz = 14,
SrsCodecAudioReservedDeviceSpecificSound = 15,
};
std::string srs_codec_audio2str(SrsCodecAudio codec);
/** /**
* the FLV/RTMP supported audio sample rate. * The video AVC frame trait(characteristic).
* Sampling rate. The following values are defined: * @doc video_file_format_spec_v10_1.pdf, page79, E.4.3.2 AVCVIDEOPACKET
* 0 = 5.5 kHz = 5512 Hz * AVCPacketType IF CodecID == 7 UI8
* 1 = 11 kHz = 11025 Hz * The following values are defined:
* 2 = 22 kHz = 22050 Hz * 0 = AVC sequence header
* 3 = 44 kHz = 44100 Hz * 1 = AVC NALU
*/ * 2 = AVC end of sequence (lower level NALU sequence ender is not required or supported)
enum SrsCodecAudioSampleRate */
enum SrsVideoAvcFrameTrait
{ {
// set to the max value to reserved, for array map. // set to the max value to reserved, for array map.
SrsCodecAudioSampleRateReserved = 4, SrsVideoAvcFrameTraitReserved = 3,
SrsCodecAudioSampleRateForbidden = 4, SrsVideoAvcFrameTraitForbidden = 3,
SrsCodecAudioSampleRate5512 = 0, SrsVideoAvcFrameTraitSequenceHeader = 0,
SrsCodecAudioSampleRate11025 = 1, SrsVideoAvcFrameTraitNALU = 1,
SrsCodecAudioSampleRate22050 = 2, SrsVideoAvcFrameTraitSequenceHeaderEOF = 2,
SrsCodecAudioSampleRate44100 = 3,
}; };
std::string srs_codec_audio_samplerate2str(SrsCodecAudioSampleRate v);
/** /**
* E.4.1 FLV Tag, page 75 * The video AVC frame type, such as I/P/B.
*/ * @doc video_file_format_spec_v10_1.pdf, page78, E.4.3.1 VIDEODATA
enum SrsCodecFlvTag * Frame Type UB [4]
* Type of video frame. The following values are defined:
* 1 = key frame (for AVC, a seekable frame)
* 2 = inter frame (for AVC, a non-seekable frame)
* 3 = disposable inter frame (H.263 only)
* 4 = generated key frame (reserved for server use only)
* 5 = video info/command frame
*/
enum SrsVideoAvcFrameType
{ {
// set to the zero to reserved, for array map. // set to the zero to reserved, for array map.
SrsCodecFlvTagReserved = 0, SrsVideoAvcFrameTypeReserved = 0,
SrsCodecFlvTagForbidden = 0, SrsVideoAvcFrameTypeForbidden = 0,
SrsVideoAvcFrameTypeReserved1 = 6,
// 8 = audio SrsVideoAvcFrameTypeKeyFrame = 1,
SrsCodecFlvTagAudio = 8, SrsVideoAvcFrameTypeInterFrame = 2,
// 9 = video SrsVideoAvcFrameTypeDisposableInterFrame = 3,
SrsCodecFlvTagVideo = 9, SrsVideoAvcFrameTypeGeneratedKeyFrame = 4,
// 18 = script data SrsVideoAvcFrameTypeVideoInfoFrame = 5,
SrsCodecFlvTagScript = 18,
}; };
/** /**
* Annex E. The FLV File Format * The audio codec id.
*/ * @doc video_file_format_spec_v10_1.pdf, page 76, E.4.2 Audio Tags
class SrsFlvCodec * SoundFormat UB [4]
* Format of SoundData. The following values are defined:
* 0 = Linear PCM, platform endian
* 1 = ADPCM
* 2 = MP3
* 3 = Linear PCM, little endian
* 4 = Nellymoser 16 kHz mono
* 5 = Nellymoser 8 kHz mono
* 6 = Nellymoser
* 7 = G.711 A-law logarithmic PCM
* 8 = G.711 mu-law logarithmic PCM
* 9 = reserved
* 10 = AAC
* 11 = Speex
* 14 = MP3 8 kHz
* 15 = Device-specific sound
* Formats 7, 8, 14, and 15 are reserved.
* AAC is supported in Flash Player 9,0,115,0 and higher.
* Speex is supported in Flash Player 10 and higher.
*/
enum SrsAudioCodecId
{
// set to the max value to reserved, for array map.
SrsAudioCodecIdReserved1 = 16,
SrsAudioCodecIdForbidden = 16,
// for user to disable audio, for example, use pure video hls.
SrsAudioCodecIdDisabled = 17,
SrsAudioCodecIdLinearPCMPlatformEndian = 0,
SrsAudioCodecIdADPCM = 1,
SrsAudioCodecIdMP3 = 2,
SrsAudioCodecIdLinearPCMLittleEndian = 3,
SrsAudioCodecIdNellymoser16kHzMono = 4,
SrsAudioCodecIdNellymoser8kHzMono = 5,
SrsAudioCodecIdNellymoser = 6,
SrsAudioCodecIdReservedG711AlawLogarithmicPCM = 7,
SrsAudioCodecIdReservedG711MuLawLogarithmicPCM = 8,
SrsAudioCodecIdReserved = 9,
SrsAudioCodecIdAAC = 10,
SrsAudioCodecIdSpeex = 11,
SrsAudioCodecIdReservedMP3_8kHz = 14,
SrsAudioCodecIdReservedDeviceSpecificSound = 15,
};
std::string srs_audio_codec_id2str(SrsAudioCodecId codec);
/**
* The audio AAC frame trait(characteristic).
* @doc video_file_format_spec_v10_1.pdf, page 77, E.4.2 Audio Tags
* AACPacketType IF SoundFormat == 10 UI8
* The following values are defined:
* 0 = AAC sequence header
* 1 = AAC raw
*/
enum SrsAudioAacFrameTrait
{
// set to the max value to reserved, for array map.
SrsAudioAacFrameTraitReserved = 2,
SrsAudioAacFrameTraitForbidden = 2,
SrsAudioAacFrameTraitSequenceHeader = 0,
SrsAudioAacFrameTraitRawData = 1,
};
/**
* The audio sample rate.
* @see srs_flv_srates and srs_aac_srates.
* @doc video_file_format_spec_v10_1.pdf, page 76, E.4.2 Audio Tags
* 0 = 5.5 kHz = 5512 Hz
* 1 = 11 kHz = 11025 Hz
* 2 = 22 kHz = 22050 Hz
* 3 = 44 kHz = 44100 Hz
* However, we can extends this table.
*/
enum SrsAudioSampleRate
{
// set to the max value to reserved, for array map.
SrsAudioSampleRateReserved = 4,
SrsAudioSampleRateForbidden = 4,
SrsAudioSampleRate5512 = 0,
SrsAudioSampleRate11025 = 1,
SrsAudioSampleRate22050 = 2,
SrsAudioSampleRate44100 = 3,
};
std::string srs_codec_audio_samplerate2str(SrsAudioSampleRate v);
/**
* The frame type, for example, audio, video or data.
* @doc video_file_format_spec_v10_1.pdf, page 75, E.4.1 FLV Tag
*/
enum SrsFrameType
{
// set to the zero to reserved, for array map.
SrsFrameTypeReserved = 0,
SrsFrameTypeForbidden = 0,
// 8 = audio
SrsFrameTypeAudio = 8,
// 9 = video
SrsFrameTypeVideo = 9,
// 18 = script data
SrsFrameTypeScript = 18,
};
/**
* Fast tough the codec of FLV video.
* @doc video_file_format_spec_v10_1.pdf, page 78, E.4.3 Video Tags
*/
class SrsFlvVideo
{ {
public: public:
SrsFlvCodec(); SrsFlvVideo();
virtual ~SrsFlvCodec(); virtual ~SrsFlvVideo();
// the following function used to finger out the flv/rtmp packet detail. // the following function used to finger out the flv/rtmp packet detail.
public: public:
/** /**
* only check the frame_type, not check the codec type. * only check the frame_type, not check the codec type.
*/ */
static bool video_is_keyframe(char* data, int size); static bool keyframe(char* data, int size);
/** /**
* check codec h264, keyframe, sequence header * check codec h264, keyframe, sequence header
*/ */
static bool video_is_sequence_header(char* data, int size); static bool sh(char* data, int size);
/**
* check codec aac, sequence header
*/
static bool audio_is_sequence_header(char* data, int size);
/** /**
* check codec h264. * check codec h264.
*/ */
static bool video_is_h264(char* data, int size); static bool h264(char* data, int size);
/**
* check codec aac.
*/
static bool audio_is_aac(char* data, int size);
/** /**
* check the video RTMP/flv header info, * check the video RTMP/flv header info,
* @return true if video RTMP/flv header is ok. * @return true if video RTMP/flv header is ok.
* @remark all type of audio is possible, no need to check audio. * @remark all type of audio is possible, no need to check audio.
*/ */
static bool video_is_acceptable(char* data, int size); static bool acceptable(char* data, int size);
};
/**
* Fast tough the codec of FLV video.
* @doc video_file_format_spec_v10_1.pdf, page 76, E.4.2 Audio Tags
*/
class SrsFlvAudio
{
public:
SrsFlvAudio();
virtual ~SrsFlvAudio();
// the following function used to finger out the flv/rtmp packet detail.
public:
/**
* check codec aac, sequence header
*/
static bool sh(char* data, int size);
/**
* check codec aac.
*/
static bool aac(char* data, int size);
}; };
/** /**
@ -243,18 +277,18 @@ public:
/** /**
* the flv sample rate map * the flv sample rate map
*/ */
extern int flv_sample_rates[]; extern int srs_flv_srates[];
/** /**
* the aac sample rate map * the aac sample rate map
*/ */
extern int aac_sample_rates[]; extern int srs_aac_srates[];
// The impossible aac sample rate index. // The impossible aac sample rate index.
#define SRS_AAC_SAMPLE_RATE_UNSET 15 #define SrsAacSampleRateUnset 15
// The max number of NALUs in a video, or aac frame in audio packet. // The max number of NALUs in a video, or aac frame in audio packet.
#define SRS_MAX_CODEC_SAMPLE 256 #define SrsMaxNbSamples 256
/** /**
* the FLV/RTMP supported audio sample size. * the FLV/RTMP supported audio sample size.
@ -264,16 +298,16 @@ extern int aac_sample_rates[];
* 0 = 8-bit samples * 0 = 8-bit samples
* 1 = 16-bit samples * 1 = 16-bit samples
*/ */
enum SrsCodecAudioSampleSize enum SrsAudioSampleSize
{ {
// set to the max value to reserved, for array map. // set to the max value to reserved, for array map.
SrsCodecAudioSampleSizeReserved = 2, SrsAudioSampleSizeReserved = 2,
SrsCodecAudioSampleSizeForbidden = 2, SrsAudioSampleSizeForbidden = 2,
SrsCodecAudioSampleSize8bit = 0, SrsAudioSampleSize8bit = 0,
SrsCodecAudioSampleSize16bit = 1, SrsAudioSampleSize16bit = 1,
}; };
std::string srs_codec_audio_samplesize2str(SrsCodecAudioSampleSize v); std::string srs_audio_samplesize2str(SrsAudioSampleSize v);
/** /**
* the FLV/RTMP supported audio sound type/channel. * the FLV/RTMP supported audio sound type/channel.
@ -281,16 +315,16 @@ std::string srs_codec_audio_samplesize2str(SrsCodecAudioSampleSize v);
* 0 = Mono sound * 0 = Mono sound
* 1 = Stereo sound * 1 = Stereo sound
*/ */
enum SrsCodecAudioSoundType enum SrsAudioSoundType
{ {
// set to the max value to reserved, for array map. // set to the max value to reserved, for array map.
SrsCodecAudioSoundTypeReserved = 2, SrsAudioSoundTypeReserved = 2,
SrsCodecAudioSoundTypeForbidden = 2, SrsAudioSoundTypeForbidden = 2,
SrsCodecAudioSoundTypeMono = 0, SrsAudioSoundTypeMono = 0,
SrsCodecAudioSoundTypeStereo = 1, SrsAudioSoundTypeStereo = 1,
}; };
std::string srs_codec_audio_channels2str(SrsCodecAudioSoundType v); std::string srs_audio_channels2str(SrsAudioSoundType v);
/** /**
* Table 7-1 - NAL unit type codes, syntax element categories, and NAL unit type classes * Table 7-1 - NAL unit type codes, syntax element categories, and NAL unit type classes
@ -337,7 +371,7 @@ enum SrsAvcNaluType
// Coded slice extension slice_layer_extension_rbsp( ) // Coded slice extension slice_layer_extension_rbsp( )
SrsAvcNaluTypeCodedSliceExt = 20, SrsAvcNaluTypeCodedSliceExt = 20,
}; };
std::string srs_codec_avc_nalu2str(SrsAvcNaluType nalu_type); std::string srs_avc_nalu2str(SrsAvcNaluType nalu_type);
/** /**
* the avc payload format, must be ibmf or annexb format. * the avc payload format, must be ibmf or annexb format.
@ -364,7 +398,7 @@ enum SrsAacProfile
SrsAacProfileLC = 1, SrsAacProfileLC = 1,
SrsAacProfileSSR = 2, SrsAacProfileSSR = 2,
}; };
std::string srs_codec_aac_profile2str(SrsAacProfile aac_profile); std::string srs_aac_profile2str(SrsAacProfile aac_profile);
/** /**
* the aac object type, for RTMP sequence header * the aac object type, for RTMP sequence header
@ -387,11 +421,11 @@ enum SrsAacObjectType
// AAC HEv2 = LC+SBR+PS // AAC HEv2 = LC+SBR+PS
SrsAacObjectTypeAacHEV2 = 29, SrsAacObjectTypeAacHEV2 = 29,
}; };
std::string srs_codec_aac_object2str(SrsAacObjectType aac_object); std::string srs_aac_object2str(SrsAacObjectType aac_object);
// ts/hls/adts audio header profile to RTMP sequence header object type. // ts/hls/adts audio header profile to RTMP sequence header object type.
SrsAacObjectType srs_codec_aac_ts2rtmp(SrsAacProfile profile); SrsAacObjectType srs_aac_ts2rtmp(SrsAacProfile profile);
// RTMP sequence header object type to ts/hls/adts audio header profile. // RTMP sequence header object type to ts/hls/adts audio header profile.
SrsAacProfile srs_codec_aac_rtmp2ts(SrsAacObjectType object_type); SrsAacProfile srs_aac_rtmp2ts(SrsAacObjectType object_type);
/** /**
* the profile for avc/h.264. * the profile for avc/h.264.
@ -417,7 +451,7 @@ enum SrsAvcProfile
SrsAvcProfileHigh444Predictive = 244, SrsAvcProfileHigh444Predictive = 244,
SrsAvcProfileHigh444Intra = 2192, SrsAvcProfileHigh444Intra = 2192,
}; };
std::string srs_codec_avc_profile2str(SrsAvcProfile profile); std::string srs_avc_profile2str(SrsAvcProfile profile);
/** /**
* the level for avc/h.264. * the level for avc/h.264.
@ -442,7 +476,7 @@ enum SrsAvcLevel
SrsAvcLevel_5 = 50, SrsAvcLevel_5 = 50,
SrsAvcLevel_51 = 51, SrsAvcLevel_51 = 51,
}; };
std::string srs_codec_avc_level2str(SrsAvcLevel level); std::string srs_avc_level2str(SrsAvcLevel level);
/** /**
* A sample is the unit of frame. * A sample is the unit of frame.
@ -467,25 +501,25 @@ public:
* corresponding to the sequence header of FLV, * corresponding to the sequence header of FLV,
* parsed to detail info. * parsed to detail info.
*/ */
class SrsCodec class SrsCodecConfig
{ {
public: public:
SrsCodec(); SrsCodecConfig();
virtual ~SrsCodec(); virtual ~SrsCodecConfig();
}; };
/** /**
* The audio codec info. * The audio codec info.
*/ */
class SrsAudioCodec : public SrsCodec class SrsAudioCodecConfig : public SrsCodecConfig
{ {
public: public:
// audio specified // audio specified
SrsCodecAudio id; SrsAudioCodecId id;
// audio aac specified. // audio aac specified.
SrsCodecAudioSampleRate sound_rate; SrsAudioSampleRate sound_rate;
SrsCodecAudioSampleSize sound_size; SrsAudioSampleSize sound_size;
SrsCodecAudioSoundType sound_type; SrsAudioSoundType sound_type;
int audio_data_rate; // in bps int audio_data_rate; // in bps
public: public:
/** /**
@ -512,8 +546,8 @@ public:
int aac_extra_size; int aac_extra_size;
char* aac_extra_data; char* aac_extra_data;
public: public:
SrsAudioCodec(); SrsAudioCodecConfig();
virtual ~SrsAudioCodec(); virtual ~SrsAudioCodecConfig();
public: public:
virtual bool is_aac_codec_ok(); virtual bool is_aac_codec_ok();
}; };
@ -521,10 +555,10 @@ public:
/** /**
* The video codec info. * The video codec info.
*/ */
class SrsVideoCodec : public SrsCodec class SrsVideoCodecConfig : public SrsCodecConfig
{ {
public: public:
SrsCodecVideo id; SrsVideoCodecId id;
int video_data_rate; // in bps int video_data_rate; // in bps
double frame_rate; double frame_rate;
double duration; double duration;
@ -556,8 +590,8 @@ public:
// the avc payload format. // the avc payload format.
SrsAvcPayloadFormat payload_format; SrsAvcPayloadFormat payload_format;
public: public:
SrsVideoCodec(); SrsVideoCodecConfig();
virtual ~SrsVideoCodec(); virtual ~SrsVideoCodecConfig();
public: public:
virtual bool is_avc_codec_ok(); virtual bool is_avc_codec_ok();
}; };
@ -574,17 +608,17 @@ public:
int32_t cts; int32_t cts;
public: public:
// The codec info of frame. // The codec info of frame.
SrsCodec* codec; SrsCodecConfig* codec;
// The actual parsed number of samples. // The actual parsed number of samples.
int nb_samples; int nb_samples;
// The sampels cache. // The sampels cache.
SrsSample samples[SRS_MAX_CODEC_SAMPLE]; SrsSample samples[SrsMaxNbSamples];
public: public:
SrsFrame(); SrsFrame();
virtual ~SrsFrame(); virtual ~SrsFrame();
public: public:
// Initialize the frame, to parse sampels. // Initialize the frame, to parse sampels.
virtual int initialize(SrsCodec* c); virtual int initialize(SrsCodecConfig* c);
// Add a sample to frame. // Add a sample to frame.
virtual int add_sample(char* bytes, int size); virtual int add_sample(char* bytes, int size);
}; };
@ -595,12 +629,12 @@ public:
class SrsAudioFrame : public SrsFrame class SrsAudioFrame : public SrsFrame
{ {
public: public:
SrsCodecAudioType aac_packet_type; SrsAudioAacFrameTrait aac_packet_type;
public: public:
SrsAudioFrame(); SrsAudioFrame();
virtual ~SrsAudioFrame(); virtual ~SrsAudioFrame();
public: public:
virtual SrsAudioCodec* acodec(); virtual SrsAudioCodecConfig* acodec();
}; };
/** /**
@ -610,8 +644,8 @@ class SrsVideoFrame : public SrsFrame
{ {
public: public:
// video specified // video specified
SrsCodecVideoAVCFrame frame_type; SrsVideoAvcFrameType frame_type;
SrsCodecVideoAVCType avc_packet_type; SrsVideoAvcFrameTrait avc_packet_type;
// whether sample_units contains IDR frame. // whether sample_units contains IDR frame.
bool has_idr; bool has_idr;
// Whether exists AUD NALU. // Whether exists AUD NALU.
@ -627,7 +661,7 @@ public:
// Add the sample without ANNEXB or IBMF header, or RAW AAC or MP3 data. // Add the sample without ANNEXB or IBMF header, or RAW AAC or MP3 data.
virtual int add_sample(char* bytes, int size); virtual int add_sample(char* bytes, int size);
public: public:
virtual SrsVideoCodec* vcodec(); virtual SrsVideoCodecConfig* vcodec();
}; };
/** /**
@ -639,9 +673,9 @@ class SrsFormat
{ {
public: public:
SrsAudioFrame* audio; SrsAudioFrame* audio;
SrsAudioCodec* acodec; SrsAudioCodecConfig* acodec;
SrsVideoFrame* video; SrsVideoFrame* video;
SrsVideoCodec* vcodec; SrsVideoCodecConfig* vcodec;
SrsBuffer* buffer; SrsBuffer* buffer;
public: public:
// for sequence header, whether parse the h.264 sps. // for sequence header, whether parse the h.264 sps.
@ -654,8 +688,10 @@ public:
// Initialize the format. // Initialize the format.
virtual int initialize(); virtual int initialize();
// When got a parsed audio packet. // When got a parsed audio packet.
// @param data The data in FLV format.
virtual int on_audio(int64_t timestamp, char* data, int size); virtual int on_audio(int64_t timestamp, char* data, int size);
// When got a parsed video packet. // When got a parsed video packet.
// @param data The data in FLV format.
virtual int on_video(int64_t timestamp, char* data, int size); virtual int on_video(int64_t timestamp, char* data, int size);
// When got a audio aac sequence header. // When got a audio aac sequence header.
virtual int on_aac_sequence_header(char* data, int size); virtual int on_aac_sequence_header(char* data, int size);

View file

@ -532,7 +532,7 @@ int SrsFlvEncoder::write_tags(SrsSharedPtrMessage** msgs, int count)
return ret; return ret;
} }
} else { } else {
if ((ret = write_metadata_to_cache(SrsCodecFlvTagScript, msg->payload, msg->size, cache)) != ERROR_SUCCESS) { if ((ret = write_metadata_to_cache(SrsFrameTypeScript, msg->payload, msg->size, cache)) != ERROR_SUCCESS) {
return ret; return ret;
} }
} }
@ -605,7 +605,7 @@ int SrsFlvEncoder::write_audio_to_cache(int64_t timestamp, char* data, int size,
// 11bytes tag header // 11bytes tag header
/*char tag_header[] = { /*char tag_header[] = {
(char)SrsCodecFlvTagAudio, // TagType UB [5], 8 = audio (char)SrsFrameTypeAudio, // TagType UB [5], 8 = audio
(char)0x00, (char)0x00, (char)0x00, // DataSize UI24 Length of the message. (char)0x00, (char)0x00, (char)0x00, // DataSize UI24 Length of the message.
(char)0x00, (char)0x00, (char)0x00, // Timestamp UI24 Time in milliseconds at which the data in this tag applies. (char)0x00, (char)0x00, (char)0x00, // Timestamp UI24 Time in milliseconds at which the data in this tag applies.
(char)0x00, // TimestampExtended UI8 (char)0x00, // TimestampExtended UI8
@ -616,7 +616,7 @@ int SrsFlvEncoder::write_audio_to_cache(int64_t timestamp, char* data, int size,
if ((ret = tag_stream->initialize(cache, 11)) != ERROR_SUCCESS) { if ((ret = tag_stream->initialize(cache, 11)) != ERROR_SUCCESS) {
return ret; return ret;
} }
tag_stream->write_1bytes(SrsCodecFlvTagAudio); tag_stream->write_1bytes(SrsFrameTypeAudio);
tag_stream->write_3bytes(size); tag_stream->write_3bytes(size);
tag_stream->write_3bytes((int32_t)timestamp); tag_stream->write_3bytes((int32_t)timestamp);
// default to little-endian // default to little-endian
@ -636,7 +636,7 @@ int SrsFlvEncoder::write_video_to_cache(int64_t timestamp, char* data, int size,
// 11bytes tag header // 11bytes tag header
/*char tag_header[] = { /*char tag_header[] = {
(char)SrsCodecFlvTagVideo, // TagType UB [5], 9 = video (char)SrsFrameTypeVideo, // TagType UB [5], 9 = video
(char)0x00, (char)0x00, (char)0x00, // DataSize UI24 Length of the message. (char)0x00, (char)0x00, (char)0x00, // DataSize UI24 Length of the message.
(char)0x00, (char)0x00, (char)0x00, // Timestamp UI24 Time in milliseconds at which the data in this tag applies. (char)0x00, (char)0x00, (char)0x00, // Timestamp UI24 Time in milliseconds at which the data in this tag applies.
(char)0x00, // TimestampExtended UI8 (char)0x00, // TimestampExtended UI8
@ -647,7 +647,7 @@ int SrsFlvEncoder::write_video_to_cache(int64_t timestamp, char* data, int size,
if ((ret = tag_stream->initialize(cache, 11)) != ERROR_SUCCESS) { if ((ret = tag_stream->initialize(cache, 11)) != ERROR_SUCCESS) {
return ret; return ret;
} }
tag_stream->write_1bytes(SrsCodecFlvTagVideo); tag_stream->write_1bytes(SrsFrameTypeVideo);
tag_stream->write_3bytes(size); tag_stream->write_3bytes(size);
tag_stream->write_3bytes((int32_t)timestamp); tag_stream->write_3bytes((int32_t)timestamp);
// default to little-endian // default to little-endian

View file

@ -470,7 +470,7 @@ public:
/** /**
* write flv metadata. * write flv metadata.
* @param type, the type of data, or other message type. * @param type, the type of data, or other message type.
* @see SrsCodecFlvTag * @see SrsFrameType
* @param data, the amf0 metadata which serialize from: * @param data, the amf0 metadata which serialize from:
* AMF0 string: onMetaData, * AMF0 string: onMetaData,
* AMF0 object: the metadata object. * AMF0 object: the metadata object.

View file

@ -111,7 +111,7 @@ int SrsMp3Encoder::write_audio(int64_t timestamp, char* data, int size)
//int8_t sound_rate = (sound_format >> 2) & 0x03; //int8_t sound_rate = (sound_format >> 2) & 0x03;
sound_format = (sound_format >> 4) & 0x0f; sound_format = (sound_format >> 4) & 0x0f;
if ((SrsCodecAudio)sound_format != SrsCodecAudioMP3) { if ((SrsAudioCodecId)sound_format != SrsAudioCodecIdMP3) {
ret = ERROR_MP3_DECODE_ERROR; ret = ERROR_MP3_DECODE_ERROR;
srs_error("mp3 required, format=%d. ret=%d", sound_format, ret); srs_error("mp3 required, format=%d. ret=%d", sound_format, ret);
return ret; return ret;

View file

@ -978,39 +978,39 @@ SrsMp4MediaHeaderBox* SrsMp4TrackBox::mdhd()
return box? box->mdhd():NULL; return box? box->mdhd():NULL;
} }
SrsCodecVideo SrsMp4TrackBox::vide_codec() SrsVideoCodecId SrsMp4TrackBox::vide_codec()
{ {
SrsMp4SampleDescriptionBox* box = stsd(); SrsMp4SampleDescriptionBox* box = stsd();
if (!box) { if (!box) {
return SrsCodecVideoForbidden; return SrsVideoCodecIdForbidden;
} }
if (box->entry_count() == 0) { if (box->entry_count() == 0) {
return SrsCodecVideoForbidden; return SrsVideoCodecIdForbidden;
} }
SrsMp4SampleEntry* entry = box->entrie_at(0); SrsMp4SampleEntry* entry = box->entrie_at(0);
switch(entry->type) { switch(entry->type) {
case SrsMp4BoxTypeAVC1: return SrsCodecVideoAVC; case SrsMp4BoxTypeAVC1: return SrsVideoCodecIdAVC;
default: return SrsCodecVideoForbidden; default: return SrsVideoCodecIdForbidden;
} }
} }
SrsCodecAudio SrsMp4TrackBox::soun_codec() SrsAudioCodecId SrsMp4TrackBox::soun_codec()
{ {
SrsMp4SampleDescriptionBox* box = stsd(); SrsMp4SampleDescriptionBox* box = stsd();
if (!box) { if (!box) {
return SrsCodecAudioForbidden; return SrsAudioCodecIdForbidden;
} }
if (box->entry_count() == 0) { if (box->entry_count() == 0) {
return SrsCodecAudioForbidden; return SrsAudioCodecIdForbidden;
} }
SrsMp4SampleEntry* entry = box->entrie_at(0); SrsMp4SampleEntry* entry = box->entrie_at(0);
switch(entry->type) { switch(entry->type) {
case SrsMp4BoxTypeMP4A: return SrsCodecAudioAAC; case SrsMp4BoxTypeMP4A: return SrsAudioCodecIdAAC;
default: return SrsCodecAudioForbidden; default: return SrsAudioCodecIdForbidden;
} }
} }
@ -3405,13 +3405,13 @@ int SrsMp4UserDataBox::decode_header(SrsBuffer* buf)
SrsMp4Sample::SrsMp4Sample() SrsMp4Sample::SrsMp4Sample()
{ {
type = SrsCodecFlvTagForbidden; type = SrsFrameTypeForbidden;
offset = 0; offset = 0;
index = 0; index = 0;
dts = pts = 0; dts = pts = 0;
nb_data = 0; nb_data = 0;
data = NULL; data = NULL;
frame_type = SrsCodecVideoAVCFrameForbidden; frame_type = SrsVideoAvcFrameTypeForbidden;
tbn = 0; tbn = 0;
adjust = 0; adjust = 0;
} }
@ -3474,7 +3474,7 @@ int SrsMp4SampleManager::load(SrsMp4MovieBox* moov)
SrsMp4Sample* sample = it->second; SrsMp4Sample* sample = it->second;
samples.push_back(sample); samples.push_back(sample);
if (sample->type == SrsCodecFlvTagVideo) { if (sample->type == SrsFrameTypeVideo) {
pvideo = sample; pvideo = sample;
} else if (pvideo) { } else if (pvideo) {
tbn = sample->tbn; tbn = sample->tbn;
@ -3496,7 +3496,7 @@ int SrsMp4SampleManager::load(SrsMp4MovieBox* moov)
map<uint64_t, SrsMp4Sample*>::iterator it; map<uint64_t, SrsMp4Sample*>::iterator it;
for (it = tses.begin(); it != tses.end(); ++it) { for (it = tses.begin(); it != tses.end(); ++it) {
SrsMp4Sample* sample = it->second; SrsMp4Sample* sample = it->second;
if (sample->type == SrsCodecFlvTagAudio) { if (sample->type == SrsFrameTypeAudio) {
sample->adjust = 0 - maxp - maxn; sample->adjust = 0 - maxp - maxn;
} }
} }
@ -3557,7 +3557,7 @@ int SrsMp4SampleManager::write(SrsMp4MovieBox* moov)
SrsMp4ChunkOffsetBox* stco = new SrsMp4ChunkOffsetBox(); SrsMp4ChunkOffsetBox* stco = new SrsMp4ChunkOffsetBox();
stbl->set_stco(stco); stbl->set_stco(stco);
if ((ret = write_track(SrsCodecFlvTagVideo, stts, stss, ctts, stsc, stsz, stco)) != ERROR_SUCCESS) { if ((ret = write_track(SrsFrameTypeVideo, stts, stss, ctts, stsc, stsz, stco)) != ERROR_SUCCESS) {
return ret; return ret;
} }
} }
@ -3581,7 +3581,7 @@ int SrsMp4SampleManager::write(SrsMp4MovieBox* moov)
SrsMp4ChunkOffsetBox* stco = new SrsMp4ChunkOffsetBox(); SrsMp4ChunkOffsetBox* stco = new SrsMp4ChunkOffsetBox();
stbl->set_stco(stco); stbl->set_stco(stco);
if ((ret = write_track(SrsCodecFlvTagAudio, stts, stss, ctts, stsc, stsz, stco)) != ERROR_SUCCESS) { if ((ret = write_track(SrsFrameTypeAudio, stts, stss, ctts, stsc, stsz, stco)) != ERROR_SUCCESS) {
return ret; return ret;
} }
} }
@ -3589,7 +3589,7 @@ int SrsMp4SampleManager::write(SrsMp4MovieBox* moov)
return ret; return ret;
} }
int SrsMp4SampleManager::write_track(SrsCodecFlvTag track, int SrsMp4SampleManager::write_track(SrsFrameType track,
SrsMp4DecodingTime2SampleBox* stts, SrsMp4SyncSampleBox* stss, SrsMp4CompositionTime2SampleBox* ctts, SrsMp4DecodingTime2SampleBox* stts, SrsMp4SyncSampleBox* stss, SrsMp4CompositionTime2SampleBox* ctts,
SrsMp4Sample2ChunkBox* stsc, SrsMp4SampleSizeBox* stsz, SrsMp4ChunkOffsetBox* stco) SrsMp4Sample2ChunkBox* stsc, SrsMp4SampleSizeBox* stsz, SrsMp4ChunkOffsetBox* stco)
{ {
@ -3616,7 +3616,7 @@ int SrsMp4SampleManager::write_track(SrsCodecFlvTag track,
stsz_entries.push_back(sample->nb_data); stsz_entries.push_back(sample->nb_data);
stco_entries.push_back((uint32_t)sample->offset); stco_entries.push_back((uint32_t)sample->offset);
if (sample->frame_type == SrsCodecVideoAVCFrameKeyFrame) { if (sample->frame_type == SrsVideoAvcFrameTypeKeyFrame) {
stss_entries.push_back(sample->index + 1); stss_entries.push_back(sample->index + 1);
} }
@ -3737,7 +3737,7 @@ int SrsMp4SampleManager::do_load(map<uint64_t, SrsMp4Sample*>& tses, SrsMp4Movie
return ret; return ret;
} }
if ((ret = load_trak(tses, SrsCodecFlvTagVideo, mdhd, stco, stsz, stsc, stts, ctts, stss)) != ERROR_SUCCESS) { if ((ret = load_trak(tses, SrsFrameTypeVideo, mdhd, stco, stsz, stsc, stts, ctts, stss)) != ERROR_SUCCESS) {
return ret; return ret;
} }
} }
@ -3757,7 +3757,7 @@ int SrsMp4SampleManager::do_load(map<uint64_t, SrsMp4Sample*>& tses, SrsMp4Movie
return ret; return ret;
} }
if ((ret = load_trak(tses, SrsCodecFlvTagAudio, mdhd, stco, stsz, stsc, stts, NULL, NULL)) != ERROR_SUCCESS) { if ((ret = load_trak(tses, SrsFrameTypeAudio, mdhd, stco, stsz, stsc, stts, NULL, NULL)) != ERROR_SUCCESS) {
return ret; return ret;
} }
} }
@ -3765,7 +3765,7 @@ int SrsMp4SampleManager::do_load(map<uint64_t, SrsMp4Sample*>& tses, SrsMp4Movie
return ret; return ret;
} }
int SrsMp4SampleManager::load_trak(map<uint64_t, SrsMp4Sample*>& tses, SrsCodecFlvTag tt, int SrsMp4SampleManager::load_trak(map<uint64_t, SrsMp4Sample*>& tses, SrsFrameType tt,
SrsMp4MediaHeaderBox* mdhd, SrsMp4ChunkOffsetBox* stco, SrsMp4SampleSizeBox* stsz, SrsMp4Sample2ChunkBox* stsc, SrsMp4MediaHeaderBox* mdhd, SrsMp4ChunkOffsetBox* stco, SrsMp4SampleSizeBox* stsz, SrsMp4Sample2ChunkBox* stsc,
SrsMp4DecodingTime2SampleBox* stts, SrsMp4CompositionTime2SampleBox* ctts, SrsMp4SyncSampleBox* stss) SrsMp4DecodingTime2SampleBox* stts, SrsMp4CompositionTime2SampleBox* ctts, SrsMp4SyncSampleBox* stss)
{ {
@ -3822,11 +3822,11 @@ int SrsMp4SampleManager::load_trak(map<uint64_t, SrsMp4Sample*>& tses, SrsCodecF
sample->pts = sample->dts + ctts_entry->sample_offset; sample->pts = sample->dts + ctts_entry->sample_offset;
} }
if (tt == SrsCodecFlvTagVideo) { if (tt == SrsFrameTypeVideo) {
if (!stss || stss->is_sync(sample->index)) { if (!stss || stss->is_sync(sample->index)) {
sample->frame_type = SrsCodecVideoAVCFrameKeyFrame; sample->frame_type = SrsVideoAvcFrameTypeKeyFrame;
} else { } else {
sample->frame_type = SrsCodecVideoAVCFrameInterFrame; sample->frame_type = SrsVideoAvcFrameTypeInterFrame;
} }
} }
@ -3855,14 +3855,14 @@ SrsMp4Decoder::SrsMp4Decoder()
brand = SrsMp4BoxBrandForbidden; brand = SrsMp4BoxBrandForbidden;
buf = new char[SRS_MP4_BUF_SIZE]; buf = new char[SRS_MP4_BUF_SIZE];
stream = new SrsSimpleStream(); stream = new SrsSimpleStream();
vcodec = SrsCodecVideoForbidden; vcodec = SrsVideoCodecIdForbidden;
acodec = SrsCodecAudioForbidden; acodec = SrsAudioCodecIdForbidden;
nb_asc = nb_avcc = 0; nb_asc = nb_avcc = 0;
pasc = pavcc = NULL; pasc = pavcc = NULL;
asc_written = avcc_written = false; asc_written = avcc_written = false;
sample_rate = SrsCodecAudioSampleRateForbidden; sample_rate = SrsAudioSampleRateForbidden;
sound_bits = SrsCodecAudioSampleSizeForbidden; sound_bits = SrsAudioSampleSizeForbidden;
channels = SrsCodecAudioSoundTypeForbidden; channels = SrsAudioSoundTypeForbidden;
samples = new SrsMp4SampleManager(); samples = new SrsMp4SampleManager();
current_index = 0; current_index = 0;
current_offset = 0; current_offset = 0;
@ -3944,8 +3944,8 @@ int SrsMp4Decoder::read_sample(SrsMp4HandlerType* pht,
uint8_t* sample = *psample = new uint8_t[nb_sample]; uint8_t* sample = *psample = new uint8_t[nb_sample];
memcpy(sample, pavcc, nb_sample); memcpy(sample, pavcc, nb_sample);
*pft = SrsCodecVideoAVCFrameKeyFrame; *pft = SrsVideoAvcFrameTypeKeyFrame;
*pct = SrsCodecVideoAVCTypeSequenceHeader; *pct = SrsVideoAvcFrameTraitSequenceHeader;
return ret; return ret;
} }
@ -3960,7 +3960,7 @@ int SrsMp4Decoder::read_sample(SrsMp4HandlerType* pht,
memcpy(sample, pasc, nb_sample); memcpy(sample, pasc, nb_sample);
*pft = 0x00; *pft = 0x00;
*pct = SrsCodecAudioTypeSequenceHeader; *pct = SrsAudioAacFrameTraitSequenceHeader;
return ret; return ret;
} }
@ -3970,12 +3970,12 @@ int SrsMp4Decoder::read_sample(SrsMp4HandlerType* pht,
return ERROR_SYSTEM_FILE_EOF; return ERROR_SYSTEM_FILE_EOF;
} }
if (ps->type == SrsCodecFlvTagVideo) { if (ps->type == SrsFrameTypeVideo) {
*pht = SrsMp4HandlerTypeVIDE; *pht = SrsMp4HandlerTypeVIDE;
*pct = SrsCodecVideoAVCTypeNALU; *pct = SrsVideoAvcFrameTraitNALU;
} else { } else {
*pht = SrsMp4HandlerTypeSOUN; *pht = SrsMp4HandlerTypeSOUN;
*pct = SrsCodecAudioTypeRawData; *pct = SrsAudioAacFrameTraitRawData;
} }
*pdts = ps->dts_ms(); *pdts = ps->dts_ms();
*ppts = ps->pts_ms(); *ppts = ps->pts_ms();
@ -4052,25 +4052,25 @@ int SrsMp4Decoder::parse_moov(SrsMp4MovieBox* moov)
if (mp4a) { if (mp4a) {
uint32_t sr = mp4a->samplerate>>16; uint32_t sr = mp4a->samplerate>>16;
if (sr >= 44100) { if (sr >= 44100) {
sample_rate = SrsCodecAudioSampleRate44100; sample_rate = SrsAudioSampleRate44100;
} else if (sr >= 22050) { } else if (sr >= 22050) {
sample_rate = SrsCodecAudioSampleRate22050; sample_rate = SrsAudioSampleRate22050;
} else if (sr >= 11025) { } else if (sr >= 11025) {
sample_rate = SrsCodecAudioSampleRate11025; sample_rate = SrsAudioSampleRate11025;
} else { } else {
sample_rate = SrsCodecAudioSampleRate5512; sample_rate = SrsAudioSampleRate5512;
} }
if (mp4a->samplesize == 16) { if (mp4a->samplesize == 16) {
sound_bits = SrsCodecAudioSampleSize16bit; sound_bits = SrsAudioSampleSize16bit;
} else { } else {
sound_bits = SrsCodecAudioSampleSize8bit; sound_bits = SrsAudioSampleSize8bit;
} }
if (mp4a->channelcount == 2) { if (mp4a->channelcount == 2) {
channels = SrsCodecAudioSoundTypeStereo; channels = SrsAudioSoundTypeStereo;
} else { } else {
channels = SrsCodecAudioSoundTypeMono; channels = SrsAudioSoundTypeMono;
} }
} }
@ -4087,8 +4087,8 @@ int SrsMp4Decoder::parse_moov(SrsMp4MovieBox* moov)
return ret; return ret;
} }
vcodec = vide?vide->vide_codec():SrsCodecVideoForbidden; vcodec = vide?vide->vide_codec():SrsVideoCodecIdForbidden;
acodec = soun?soun->soun_codec():SrsCodecAudioForbidden; acodec = soun?soun->soun_codec():SrsAudioCodecIdForbidden;
if (avcc && avcc->nb_config) { if (avcc && avcc->nb_config) {
nb_avcc = avcc->nb_config; nb_avcc = avcc->nb_config;
@ -4111,13 +4111,13 @@ int SrsMp4Decoder::parse_moov(SrsMp4MovieBox* moov)
ss << "dur=" << mvhd->duration() << "ms"; ss << "dur=" << mvhd->duration() << "ms";
// video codec. // video codec.
ss << ", vide=" << moov->nb_vide_tracks() << "(" ss << ", vide=" << moov->nb_vide_tracks() << "("
<< srs_codec_video2str(vcodec) << "," << nb_avcc << "BSH" << srs_video_codec_id2str(vcodec) << "," << nb_avcc << "BSH"
<< ")"; << ")";
// audio codec. // audio codec.
ss << ", soun=" << moov->nb_soun_tracks() << "(" ss << ", soun=" << moov->nb_soun_tracks() << "("
<< srs_codec_audio2str(acodec) << "," << nb_asc << "BSH" << srs_audio_codec_id2str(acodec) << "," << nb_asc << "BSH"
<< "," << srs_codec_audio_channels2str(channels) << "," << srs_audio_channels2str(channels)
<< "," << srs_codec_audio_samplesize2str(sound_bits) << "," << srs_audio_samplesize2str(sound_bits)
<< "," << srs_codec_audio_samplerate2str(sample_rate) << "," << srs_codec_audio_samplerate2str(sample_rate)
<< ")"; << ")";
@ -4231,11 +4231,11 @@ SrsMp4Encoder::SrsMp4Encoder()
aduration = vduration = 0; aduration = vduration = 0;
width = height = 0; width = height = 0;
acodec = SrsCodecAudioForbidden; acodec = SrsAudioCodecIdForbidden;
sample_rate = SrsCodecAudioSampleRateForbidden; sample_rate = SrsAudioSampleRateForbidden;
sound_bits = SrsCodecAudioSampleSizeForbidden; sound_bits = SrsAudioSampleSizeForbidden;
channels = SrsCodecAudioSoundTypeForbidden; channels = SrsAudioSoundTypeForbidden;
vcodec = SrsCodecVideoForbidden; vcodec = SrsVideoCodecIdForbidden;
} }
SrsMp4Encoder::~SrsMp4Encoder() SrsMp4Encoder::~SrsMp4Encoder()
@ -4319,8 +4319,8 @@ int SrsMp4Encoder::write_sample(SrsMp4HandlerType ht,
SrsMp4Sample* ps = new SrsMp4Sample(); SrsMp4Sample* ps = new SrsMp4Sample();
// For SPS/PPS or ASC, copy it to moov. // For SPS/PPS or ASC, copy it to moov.
bool vsh = (ht == SrsMp4HandlerTypeVIDE) && (ct == SrsCodecVideoAVCTypeSequenceHeader); bool vsh = (ht == SrsMp4HandlerTypeVIDE) && (ct == SrsVideoAvcFrameTraitSequenceHeader);
bool ash = (ht == SrsMp4HandlerTypeSOUN) && (ct == SrsCodecAudioTypeSequenceHeader); bool ash = (ht == SrsMp4HandlerTypeSOUN) && (ct == SrsAudioAacFrameTraitSequenceHeader);
if (vsh || ash) { if (vsh || ash) {
ret = copy_sequence_header(vsh, sample, nb_sample); ret = copy_sequence_header(vsh, sample, nb_sample);
srs_freep(ps); srs_freep(ps);
@ -4328,12 +4328,12 @@ int SrsMp4Encoder::write_sample(SrsMp4HandlerType ht,
} }
if (ht == SrsMp4HandlerTypeVIDE) { if (ht == SrsMp4HandlerTypeVIDE) {
ps->type = SrsCodecFlvTagVideo; ps->type = SrsFrameTypeVideo;
ps->frame_type = (SrsCodecVideoAVCFrame)ft; ps->frame_type = (SrsVideoAvcFrameType)ft;
ps->index = nb_videos++; ps->index = nb_videos++;
vduration = dts; vduration = dts;
} else if (ht == SrsMp4HandlerTypeSOUN) { } else if (ht == SrsMp4HandlerTypeSOUN) {
ps->type = SrsCodecFlvTagAudio; ps->type = SrsFrameTypeAudio;
ps->index = nb_audios++; ps->index = nb_audios++;
aduration = dts; aduration = dts;
} else { } else {
@ -4493,13 +4493,13 @@ int SrsMp4Encoder::flush()
stbl->set_stsd(stsd); stbl->set_stsd(stsd);
SrsMp4AudioSampleEntry* mp4a = new SrsMp4AudioSampleEntry(); SrsMp4AudioSampleEntry* mp4a = new SrsMp4AudioSampleEntry();
mp4a->samplerate = uint32_t(flv_sample_rates[sample_rate]) << 16; mp4a->samplerate = uint32_t(srs_flv_srates[sample_rate]) << 16;
if (sound_bits == SrsCodecAudioSampleSize16bit) { if (sound_bits == SrsAudioSampleSize16bit) {
mp4a->samplesize = 16; mp4a->samplesize = 16;
} else { } else {
mp4a->samplesize = 8; mp4a->samplesize = 8;
} }
if (channels == SrsCodecAudioSoundTypeStereo) { if (channels == SrsAudioSoundTypeStereo) {
mp4a->channelcount = 2; mp4a->channelcount = 2;
} else { } else {
mp4a->channelcount = 1; mp4a->channelcount = 1;

View file

@ -432,9 +432,9 @@ public:
virtual SrsMp4MediaHeaderBox* mdhd(); virtual SrsMp4MediaHeaderBox* mdhd();
public: public:
// For vide track, get the video codec. // For vide track, get the video codec.
virtual SrsCodecVideo vide_codec(); virtual SrsVideoCodecId vide_codec();
// For soun track, get the audio codec. // For soun track, get the audio codec.
virtual SrsCodecAudio soun_codec(); virtual SrsAudioCodecId soun_codec();
// For H.264/AVC codec, get the sps/pps. // For H.264/AVC codec, get the sps/pps.
virtual SrsMp4AvccBox* avcc(); virtual SrsMp4AvccBox* avcc();
// For AAC codec, get the asc. // For AAC codec, get the asc.
@ -1476,7 +1476,7 @@ class SrsMp4Sample
{ {
public: public:
// The type of sample, audio or video. // The type of sample, audio or video.
SrsCodecFlvTag type; SrsFrameType type;
// The offset of sample in file. // The offset of sample in file.
off_t offset; off_t offset;
// The index of sample with a track, start from 0. // The index of sample with a track, start from 0.
@ -1488,7 +1488,7 @@ public:
// The tbn(timebase). // The tbn(timebase).
uint32_t tbn; uint32_t tbn;
// For video, the frame type, whether keyframe. // For video, the frame type, whether keyframe.
SrsCodecVideoAVCFrame frame_type; SrsVideoAvcFrameType frame_type;
// The adjust timestamp in milliseconds. // The adjust timestamp in milliseconds.
// For example, we can adjust a timestamp for A/V to monotonically increase. // For example, we can adjust a timestamp for A/V to monotonically increase.
int32_t adjust; int32_t adjust;
@ -1534,7 +1534,7 @@ public:
// Write the samples info to moov. // Write the samples info to moov.
virtual int write(SrsMp4MovieBox* moov); virtual int write(SrsMp4MovieBox* moov);
private: private:
virtual int write_track(SrsCodecFlvTag track, virtual int write_track(SrsFrameType track,
SrsMp4DecodingTime2SampleBox* stts, SrsMp4SyncSampleBox* stss, SrsMp4CompositionTime2SampleBox* ctts, SrsMp4DecodingTime2SampleBox* stts, SrsMp4SyncSampleBox* stss, SrsMp4CompositionTime2SampleBox* ctts,
SrsMp4Sample2ChunkBox* stsc, SrsMp4SampleSizeBox* stsz, SrsMp4ChunkOffsetBox* stco); SrsMp4Sample2ChunkBox* stsc, SrsMp4SampleSizeBox* stsz, SrsMp4ChunkOffsetBox* stco);
virtual int do_load(std::map<uint64_t, SrsMp4Sample*>& tses, SrsMp4MovieBox* moov); virtual int do_load(std::map<uint64_t, SrsMp4Sample*>& tses, SrsMp4MovieBox* moov);
@ -1543,7 +1543,7 @@ private:
// @param tses The temporary samples, key is offset, value is sample. // @param tses The temporary samples, key is offset, value is sample.
// @param tt The type of sample, convert to flv tag type. // @param tt The type of sample, convert to flv tag type.
// TODO: Support co64 for stco. // TODO: Support co64 for stco.
virtual int load_trak(std::map<uint64_t, SrsMp4Sample*>& tses, SrsCodecFlvTag tt, virtual int load_trak(std::map<uint64_t, SrsMp4Sample*>& tses, SrsFrameType tt,
SrsMp4MediaHeaderBox* mdhd, SrsMp4ChunkOffsetBox* stco, SrsMp4SampleSizeBox* stsz, SrsMp4Sample2ChunkBox* stsc, SrsMp4MediaHeaderBox* mdhd, SrsMp4ChunkOffsetBox* stco, SrsMp4SampleSizeBox* stsz, SrsMp4Sample2ChunkBox* stsc,
SrsMp4DecodingTime2SampleBox* stts, SrsMp4CompositionTime2SampleBox* ctts, SrsMp4SyncSampleBox* stss); SrsMp4DecodingTime2SampleBox* stts, SrsMp4CompositionTime2SampleBox* ctts, SrsMp4SyncSampleBox* stss);
}; };
@ -1564,7 +1564,8 @@ private:
public: public:
// The video codec of first track, generally there is zero or one track. // The video codec of first track, generally there is zero or one track.
// Forbidden if no video stream. // Forbidden if no video stream.
SrsCodecVideo vcodec; // TODO: FIXME: Use SrsFormat instead.
SrsVideoCodecId vcodec;
private: private:
// For H.264/AVC, the avcc contains the sps/pps. // For H.264/AVC, the avcc contains the sps/pps.
int nb_avcc; int nb_avcc;
@ -1574,13 +1575,13 @@ private:
public: public:
// The audio codec of first track, generally there is zero or one track. // The audio codec of first track, generally there is zero or one track.
// Forbidden if no audio stream. // Forbidden if no audio stream.
SrsCodecAudio acodec; SrsAudioCodecId acodec;
// The audio sample rate. // The audio sample rate.
SrsCodecAudioSampleRate sample_rate; SrsAudioSampleRate sample_rate;
// The audio sound bits. // The audio sound bits.
SrsCodecAudioSampleSize sound_bits; SrsAudioSampleSize sound_bits;
// The audio sound type. // The audio sound type.
SrsCodecAudioSoundType channels; SrsAudioSoundType channels;
private: private:
// For AAC, the asc in esds box. // For AAC, the asc in esds box.
int nb_asc; int nb_asc;
@ -1608,8 +1609,8 @@ public:
/** /**
* Read a sample from mp4. * Read a sample from mp4.
* @param pht The sample hanler type, audio/soun or video/vide. * @param pht The sample hanler type, audio/soun or video/vide.
* @param pft, The frame type. For video, it's SrsCodecVideoAVCFrame. * @param pft, The frame type. For video, it's SrsVideoAvcFrameType.
* @param pct, The codec type. For video, it's SrsCodecVideoAVCType. For audio, it's SrsCodecAudioType. * @param pct, The codec type. For video, it's SrsVideoAvcFrameTrait. For audio, it's SrsAudioAacFrameTrait.
* @param pdts The output dts in milliseconds. * @param pdts The output dts in milliseconds.
* @param ppts The output pts in milliseconds. * @param ppts The output pts in milliseconds.
* @param pnb_sample The output size of payload. * @param pnb_sample The output size of payload.
@ -1647,13 +1648,13 @@ private:
public: public:
// The audio codec of first track, generally there is zero or one track. // The audio codec of first track, generally there is zero or one track.
// Forbidden if no audio stream. // Forbidden if no audio stream.
SrsCodecAudio acodec; SrsAudioCodecId acodec;
// The audio sample rate. // The audio sample rate.
SrsCodecAudioSampleRate sample_rate; SrsAudioSampleRate sample_rate;
// The audio sound bits. // The audio sound bits.
SrsCodecAudioSampleSize sound_bits; SrsAudioSampleSize sound_bits;
// The audio sound type. // The audio sound type.
SrsCodecAudioSoundType channels; SrsAudioSoundType channels;
private: private:
// For AAC, the asc in esds box. // For AAC, the asc in esds box.
int nb_asc; int nb_asc;
@ -1665,7 +1666,7 @@ private:
public: public:
// The video codec of first track, generally there is zero or one track. // The video codec of first track, generally there is zero or one track.
// Forbidden if no video stream. // Forbidden if no video stream.
SrsCodecVideo vcodec; SrsVideoCodecId vcodec;
private: private:
// For H.264/AVC, the avcc contains the sps/pps. // For H.264/AVC, the avcc contains the sps/pps.
int nb_avcc; int nb_avcc;
@ -1686,8 +1687,8 @@ public:
virtual int initialize(ISrsWriteSeeker* ws); virtual int initialize(ISrsWriteSeeker* ws);
// Write a sampel to mp4. // Write a sampel to mp4.
// @param ht, The sample handler type, audio/soun or video/vide. // @param ht, The sample handler type, audio/soun or video/vide.
// @param ft, The frame type. For video, it's SrsCodecVideoAVCFrame. // @param ft, The frame type. For video, it's SrsVideoAvcFrameType.
// @param ct, The codec type. For video, it's SrsCodecVideoAVCType. For audio, it's SrsCodecAudioType. // @param ct, The codec type. For video, it's SrsVideoAvcFrameTrait. For audio, it's SrsAudioAacFrameTrait.
// @param dts The output dts in milliseconds. // @param dts The output dts in milliseconds.
// @param pts The output pts in milliseconds. // @param pts The output pts in milliseconds.
// @param sample The output payload, user must free it. // @param sample The output payload, user must free it.

View file

@ -201,8 +201,8 @@ SrsTsContext::SrsTsContext()
{ {
pure_audio = false; pure_audio = false;
sync_byte = 0x47; // ts default sync byte. sync_byte = 0x47; // ts default sync byte.
vcodec = SrsCodecVideoReserved; vcodec = SrsVideoCodecIdReserved;
acodec = SrsCodecAudioReserved1; acodec = SrsAudioCodecIdReserved1;
} }
SrsTsContext::~SrsTsContext() SrsTsContext::~SrsTsContext()
@ -235,8 +235,8 @@ void SrsTsContext::on_pmt_parsed()
void SrsTsContext::reset() void SrsTsContext::reset()
{ {
vcodec = SrsCodecVideoReserved; vcodec = SrsVideoCodecIdReserved;
acodec = SrsCodecAudioReserved1; acodec = SrsAudioCodecIdReserved1;
} }
SrsTsChannel* SrsTsContext::get(int pid) SrsTsChannel* SrsTsContext::get(int pid)
@ -294,56 +294,56 @@ int SrsTsContext::decode(SrsBuffer* stream, ISrsTsHandler* handler)
return ret; return ret;
} }
int SrsTsContext::encode(SrsFileWriter* writer, SrsTsMessage* msg, SrsCodecVideo vc, SrsCodecAudio ac) int SrsTsContext::encode(SrsFileWriter* writer, SrsTsMessage* msg, SrsVideoCodecId vc, SrsAudioCodecId ac)
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
SrsTsStream vs, as; SrsTsStream vs, as;
int16_t video_pid = 0, audio_pid = 0; int16_t video_pid = 0, audio_pid = 0;
switch (vc) { switch (vc) {
case SrsCodecVideoAVC: case SrsVideoCodecIdAVC:
vs = SrsTsStreamVideoH264; vs = SrsTsStreamVideoH264;
video_pid = TS_VIDEO_AVC_PID; video_pid = TS_VIDEO_AVC_PID;
break; break;
case SrsCodecVideoDisabled: case SrsVideoCodecIdDisabled:
vs = SrsTsStreamReserved; vs = SrsTsStreamReserved;
break; break;
case SrsCodecVideoReserved: case SrsVideoCodecIdReserved:
case SrsCodecVideoReserved1: case SrsVideoCodecIdReserved1:
case SrsCodecVideoReserved2: case SrsVideoCodecIdReserved2:
case SrsCodecVideoSorensonH263: case SrsVideoCodecIdSorensonH263:
case SrsCodecVideoScreenVideo: case SrsVideoCodecIdScreenVideo:
case SrsCodecVideoOn2VP6: case SrsVideoCodecIdOn2VP6:
case SrsCodecVideoOn2VP6WithAlphaChannel: case SrsVideoCodecIdOn2VP6WithAlphaChannel:
case SrsCodecVideoScreenVideoVersion2: case SrsVideoCodecIdScreenVideoVersion2:
vs = SrsTsStreamReserved; vs = SrsTsStreamReserved;
break; break;
} }
switch (ac) { switch (ac) {
case SrsCodecAudioAAC: case SrsAudioCodecIdAAC:
as = SrsTsStreamAudioAAC; as = SrsTsStreamAudioAAC;
audio_pid = TS_AUDIO_AAC_PID; audio_pid = TS_AUDIO_AAC_PID;
break; break;
case SrsCodecAudioMP3: case SrsAudioCodecIdMP3:
as = SrsTsStreamAudioMp3; as = SrsTsStreamAudioMp3;
audio_pid = TS_AUDIO_MP3_PID; audio_pid = TS_AUDIO_MP3_PID;
break; break;
case SrsCodecAudioDisabled: case SrsAudioCodecIdDisabled:
as = SrsTsStreamReserved; as = SrsTsStreamReserved;
break; break;
case SrsCodecAudioReserved1: case SrsAudioCodecIdReserved1:
case SrsCodecAudioLinearPCMPlatformEndian: case SrsAudioCodecIdLinearPCMPlatformEndian:
case SrsCodecAudioADPCM: case SrsAudioCodecIdADPCM:
case SrsCodecAudioLinearPCMLittleEndian: case SrsAudioCodecIdLinearPCMLittleEndian:
case SrsCodecAudioNellymoser16kHzMono: case SrsAudioCodecIdNellymoser16kHzMono:
case SrsCodecAudioNellymoser8kHzMono: case SrsAudioCodecIdNellymoser8kHzMono:
case SrsCodecAudioNellymoser: case SrsAudioCodecIdNellymoser:
case SrsCodecAudioReservedG711AlawLogarithmicPCM: case SrsAudioCodecIdReservedG711AlawLogarithmicPCM:
case SrsCodecAudioReservedG711MuLawLogarithmicPCM: case SrsAudioCodecIdReservedG711MuLawLogarithmicPCM:
case SrsCodecAudioReserved: case SrsAudioCodecIdReserved:
case SrsCodecAudioSpeex: case SrsAudioCodecIdSpeex:
case SrsCodecAudioReservedMP3_8kHz: case SrsAudioCodecIdReservedMP3_8kHz:
case SrsCodecAudioReservedDeviceSpecificSound: case SrsAudioCodecIdReservedDeviceSpecificSound:
as = SrsTsStreamReserved; as = SrsTsStreamReserved;
break; break;
} }
@ -2708,7 +2708,7 @@ int SrsTsPayloadPMT::psi_encode(SrsBuffer* stream)
return ret; return ret;
} }
SrsTsMuxer::SrsTsMuxer(SrsFileWriter* w, SrsTsContext* c, SrsCodecAudio ac, SrsCodecVideo vc) SrsTsMuxer::SrsTsMuxer(SrsFileWriter* w, SrsTsContext* c, SrsAudioCodecId ac, SrsVideoCodecId vc)
{ {
writer = w; writer = w;
context = c; context = c;
@ -2740,7 +2740,7 @@ int SrsTsMuxer::open(string p)
return ret; return ret;
} }
int SrsTsMuxer::update_acodec(SrsCodecAudio ac) int SrsTsMuxer::update_acodec(SrsAudioCodecId ac)
{ {
acodec = ac; acodec = ac;
return ERROR_SUCCESS; return ERROR_SUCCESS;
@ -2783,7 +2783,7 @@ void SrsTsMuxer::close()
writer->close(); writer->close();
} }
SrsCodecVideo SrsTsMuxer::video_codec() SrsVideoCodecId SrsTsMuxer::video_codec()
{ {
return vcodec; return vcodec;
} }
@ -2817,11 +2817,11 @@ int SrsTsCache::cache_audio(SrsAudioFrame* frame, int64_t dts)
audio->sid = SrsTsPESStreamIdAudioCommon; audio->sid = SrsTsPESStreamIdAudioCommon;
// must be aac or mp3 // must be aac or mp3
SrsAudioCodec* acodec = frame->acodec(); SrsAudioCodecConfig* acodec = frame->acodec();
srs_assert(acodec->id == SrsCodecAudioAAC || acodec->id == SrsCodecAudioMP3); srs_assert(acodec->id == SrsAudioCodecIdAAC || acodec->id == SrsAudioCodecIdMP3);
// write video to cache. // write video to cache.
if (acodec->id == SrsCodecAudioAAC) { if (acodec->id == SrsAudioCodecIdAAC) {
if ((ret = do_cache_aac(frame)) != ERROR_SUCCESS) { if ((ret = do_cache_aac(frame)) != ERROR_SUCCESS) {
return ret; return ret;
} }
@ -2841,7 +2841,7 @@ int SrsTsCache::cache_video(SrsVideoFrame* frame, int64_t dts)
// create the ts video message. // create the ts video message.
if (!video) { if (!video) {
video = new SrsTsMessage(); video = new SrsTsMessage();
video->write_pcr = (frame->frame_type == SrsCodecVideoAVCFrameKeyFrame); video->write_pcr = (frame->frame_type == SrsVideoAvcFrameTypeKeyFrame);
video->start_pts = dts; video->start_pts = dts;
} }
@ -2875,7 +2875,7 @@ int SrsTsCache::do_cache_aac(SrsAudioFrame* frame)
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
SrsAudioCodec* codec = frame->acodec(); SrsAudioCodecConfig* codec = frame->acodec();
srs_assert(codec); srs_assert(codec);
for (int i = 0; i < frame->nb_samples; i++) { for (int i = 0; i < frame->nb_samples; i++) {
@ -2920,7 +2920,7 @@ int SrsTsCache::do_cache_aac(SrsAudioFrame* frame)
int8_t number_of_raw_data_blocks_in_frame; //2bits, 0 indicating 1 raw_data_block() int8_t number_of_raw_data_blocks_in_frame; //2bits, 0 indicating 1 raw_data_block()
*/ */
// profile, 2bits // profile, 2bits
SrsAacProfile aac_profile = srs_codec_aac_rtmp2ts(codec->aac_object); SrsAacProfile aac_profile = srs_aac_rtmp2ts(codec->aac_object);
adts_header[2] = (aac_profile << 6) & 0xc0; adts_header[2] = (aac_profile << 6) & 0xc0;
// sampling_frequency_index 4bits // sampling_frequency_index 4bits
adts_header[2] |= (codec->aac_sample_rate << 2) & 0x3c; adts_header[2] |= (codec->aac_sample_rate << 2) & 0x3c;
@ -3042,7 +3042,7 @@ int SrsTsCache::do_cache_avc(SrsVideoFrame* frame)
video->payload->append((const char*)default_aud_nalu, 2); video->payload->append((const char*)default_aud_nalu, 2);
} }
SrsVideoCodec* codec = frame->vcodec(); SrsVideoCodecConfig* codec = frame->vcodec();
srs_assert(codec); srs_assert(codec);
// all sample use cont nalu header, except the sps-pps before IDR frame. // all sample use cont nalu header, except the sps-pps before IDR frame.
@ -3117,7 +3117,7 @@ int SrsTsEncoder::initialize(SrsFileWriter* fw)
writer = fw; writer = fw;
srs_freep(muxer); srs_freep(muxer);
muxer = new SrsTsMuxer(fw, context, SrsCodecAudioAAC, SrsCodecVideoAVC); muxer = new SrsTsMuxer(fw, context, SrsAudioCodecIdAAC, SrsVideoCodecIdAVC);
if ((ret = muxer->open("")) != ERROR_SUCCESS) { if ((ret = muxer->open("")) != ERROR_SUCCESS) {
return ret; return ret;
@ -3136,7 +3136,7 @@ int SrsTsEncoder::write_audio(int64_t timestamp, char* data, int size)
// ts support audio codec: aac/mp3 // ts support audio codec: aac/mp3
srs_assert(format->acodec && format->audio); srs_assert(format->acodec && format->audio);
if (format->acodec->id != SrsCodecAudioAAC && format->acodec->id != SrsCodecAudioMP3) { if (format->acodec->id != SrsAudioCodecIdAAC && format->acodec->id != SrsAudioCodecIdMP3) {
return ret; return ret;
} }
@ -3147,7 +3147,7 @@ int SrsTsEncoder::write_audio(int64_t timestamp, char* data, int size)
} }
// for aac: ignore sequence header // for aac: ignore sequence header
if (format->acodec->id == SrsCodecAudioAAC && format->audio->aac_packet_type == SrsCodecAudioTypeSequenceHeader) { if (format->acodec->id == SrsAudioCodecIdAAC && format->audio->aac_packet_type == SrsAudioAacFrameTraitSequenceHeader) {
return ret; return ret;
} }
@ -3179,17 +3179,17 @@ int SrsTsEncoder::write_video(int64_t timestamp, char* data, int size)
// ignore info frame, // ignore info frame,
// @see https://github.com/ossrs/srs/issues/288#issuecomment-69863909 // @see https://github.com/ossrs/srs/issues/288#issuecomment-69863909
srs_assert(format->video && format->vcodec); srs_assert(format->video && format->vcodec);
if (format->video->frame_type == SrsCodecVideoAVCFrameVideoInfoFrame) { if (format->video->frame_type == SrsVideoAvcFrameTypeVideoInfoFrame) {
return ret; return ret;
} }
if (format->vcodec->id != SrsCodecVideoAVC) { if (format->vcodec->id != SrsVideoCodecIdAVC) {
return ret; return ret;
} }
// ignore sequence header // ignore sequence header
if (format->video->frame_type == SrsCodecVideoAVCFrameKeyFrame if (format->video->frame_type == SrsVideoAvcFrameTypeKeyFrame
&& format->video->avc_packet_type == SrsCodecVideoAVCTypeSequenceHeader) { && format->video->avc_packet_type == SrsVideoAvcFrameTraitSequenceHeader) {
return ret; return ret;
} }

View file

@ -353,8 +353,8 @@ private:
// encoder // encoder
private: private:
// when any codec changed, write the PAT/PMT. // when any codec changed, write the PAT/PMT.
SrsCodecVideo vcodec; SrsVideoCodecId vcodec;
SrsCodecAudio acodec; SrsAudioCodecId acodec;
public: public:
SrsTsContext(); SrsTsContext();
virtual ~SrsTsContext(); virtual ~SrsTsContext();
@ -399,7 +399,7 @@ public:
* @param vc the video codec, write the PAT/PMT table when changed. * @param vc the video codec, write the PAT/PMT table when changed.
* @param ac the audio codec, write the PAT/PMT table when changed. * @param ac the audio codec, write the PAT/PMT table when changed.
*/ */
virtual int encode(SrsFileWriter* writer, SrsTsMessage* msg, SrsCodecVideo vc, SrsCodecAudio ac); virtual int encode(SrsFileWriter* writer, SrsTsMessage* msg, SrsVideoCodecId vc, SrsAudioCodecId ac);
// drm methods // drm methods
public: public:
/** /**
@ -1562,14 +1562,14 @@ protected:
class SrsTsMuxer class SrsTsMuxer
{ {
private: private:
SrsCodecVideo vcodec; SrsVideoCodecId vcodec;
SrsCodecAudio acodec; SrsAudioCodecId acodec;
private: private:
SrsTsContext* context; SrsTsContext* context;
SrsFileWriter* writer; SrsFileWriter* writer;
std::string path; std::string path;
public: public:
SrsTsMuxer(SrsFileWriter* w, SrsTsContext* c, SrsCodecAudio ac, SrsCodecVideo vc); SrsTsMuxer(SrsFileWriter* w, SrsTsContext* c, SrsAudioCodecId ac, SrsVideoCodecId vc);
virtual ~SrsTsMuxer(); virtual ~SrsTsMuxer();
public: public:
/** /**
@ -1585,7 +1585,7 @@ public:
* @see https://github.com/ossrs/srs/issues/301 * @see https://github.com/ossrs/srs/issues/301
*/ */
// TODO: FIXME: Remove it. // TODO: FIXME: Remove it.
virtual int update_acodec(SrsCodecAudio ac); virtual int update_acodec(SrsAudioCodecId ac);
/** /**
* write an audio frame to ts, * write an audio frame to ts,
*/ */
@ -1602,7 +1602,7 @@ public:
/** /**
* get the video codec of ts muxer. * get the video codec of ts muxer.
*/ */
virtual SrsCodecVideo video_codec(); virtual SrsVideoCodecId video_codec();
}; };
/** /**

View file

@ -1243,7 +1243,7 @@ int srs_audio_write_raw_frame(srs_rtmp_t rtmp,
Context* context = (Context*)rtmp; Context* context = (Context*)rtmp;
srs_assert(context); srs_assert(context);
if (sound_format == SrsCodecAudioAAC) { if (sound_format == SrsAudioCodecIdAAC) {
// for aac, the frame must be ADTS format. // for aac, the frame must be ADTS format.
if (!srs_aac_is_adts(frame, frame_size)) { if (!srs_aac_is_adts(frame, frame_size)) {
return ERROR_AAC_REQUIRED_ADTS; return ERROR_AAC_REQUIRED_ADTS;
@ -1340,9 +1340,9 @@ int srs_write_h264_ipb_frame(Context* context,
} }
// for IDR frame, the frame is keyframe. // for IDR frame, the frame is keyframe.
SrsCodecVideoAVCFrame frame_type = SrsCodecVideoAVCFrameInterFrame; SrsVideoAvcFrameType frame_type = SrsVideoAvcFrameTypeInterFrame;
if (nut == SrsAvcNaluTypeIDR) { if (nut == SrsAvcNaluTypeIDR) {
frame_type = SrsCodecVideoAVCFrameKeyFrame; frame_type = SrsVideoAvcFrameTypeKeyFrame;
} }
std::string ibp; std::string ibp;
@ -1350,7 +1350,7 @@ int srs_write_h264_ipb_frame(Context* context,
return ret; return ret;
} }
int8_t avc_packet_type = SrsCodecVideoAVCTypeNALU; int8_t avc_packet_type = SrsVideoAvcFrameTraitNALU;
char* flv = NULL; char* flv = NULL;
int nb_flv = 0; int nb_flv = 0;
if ((ret = context->avc_raw.mux_avc2flv(ibp, frame_type, avc_packet_type, dts, pts, &flv, &nb_flv)) != ERROR_SUCCESS) { if ((ret = context->avc_raw.mux_avc2flv(ibp, frame_type, avc_packet_type, dts, pts, &flv, &nb_flv)) != ERROR_SUCCESS) {
@ -1381,8 +1381,8 @@ int srs_write_h264_sps_pps(Context* context, uint32_t dts, uint32_t pts)
} }
// h264 packet to flv packet. // h264 packet to flv packet.
int8_t frame_type = SrsCodecVideoAVCFrameKeyFrame; int8_t frame_type = SrsVideoAvcFrameTypeKeyFrame;
int8_t avc_packet_type = SrsCodecVideoAVCTypeSequenceHeader; int8_t avc_packet_type = SrsVideoAvcFrameTraitSequenceHeader;
char* flv = NULL; char* flv = NULL;
int nb_flv = 0; int nb_flv = 0;
if ((ret = context->avc_raw.mux_avc2flv(sh, frame_type, avc_packet_type, dts, pts, &flv, &nb_flv)) != ERROR_SUCCESS) { if ((ret = context->avc_raw.mux_avc2flv(sh, frame_type, avc_packet_type, dts, pts, &flv, &nb_flv)) != ERROR_SUCCESS) {
@ -1595,7 +1595,7 @@ int srs_mp4_read_sample(srs_mp4_t mp4, srs_mp4_sample_t* s)
SrsMp4Decoder* dec = &context->dec; SrsMp4Decoder* dec = &context->dec;
SrsMp4HandlerType ht = SrsMp4HandlerTypeForbidden; SrsMp4HandlerType ht = SrsMp4HandlerTypeForbidden;
if ((ret = dec->read_sample(&ht, &s->frame_type, &s->codec_type, &s->dts, &s->pts, &s->sample, &s->nb_sample)) != ERROR_SUCCESS) { if ((ret = dec->read_sample(&ht, &s->frame_type, &s->frame_trait, &s->dts, &s->pts, &s->sample, &s->nb_sample)) != ERROR_SUCCESS) {
return ret; return ret;
} }
@ -1624,13 +1624,13 @@ void srs_mp4_free_sample(srs_mp4_sample_t* s)
int32_t srs_mp4_sizeof(srs_mp4_t mp4, srs_mp4_sample_t* s) int32_t srs_mp4_sizeof(srs_mp4_t mp4, srs_mp4_sample_t* s)
{ {
if (s->handler_type == SrsMp4HandlerTypeSOUN) { if (s->handler_type == SrsMp4HandlerTypeSOUN) {
if (s->codec == SrsCodecAudioAAC) { if (s->codec == SrsAudioCodecIdAAC) {
return s->nb_sample + 2; return s->nb_sample + 2;
} }
return s->nb_sample + 1; return s->nb_sample + 1;
} }
if (s->codec == SrsCodecVideoAVC) { if (s->codec == SrsVideoCodecIdAVC) {
return s->nb_sample + 5; return s->nb_sample + 5;
} }
return s->nb_sample + 1; return s->nb_sample + 1;
@ -1648,8 +1648,8 @@ int srs_mp4_to_flv_tag(srs_mp4_t mp4, srs_mp4_sample_t* s, char* type, uint32_t*
// E.4.2.1 AUDIODATA, flv_v10_1.pdf, page 3 // E.4.2.1 AUDIODATA, flv_v10_1.pdf, page 3
p.write_1bytes(uint8_t(s->codec << 4) | uint8_t(s->sample_rate << 2) | uint8_t(s->sound_bits << 1) | s->channels); p.write_1bytes(uint8_t(s->codec << 4) | uint8_t(s->sample_rate << 2) | uint8_t(s->sound_bits << 1) | s->channels);
if (s->codec == SrsCodecAudioAAC) { if (s->codec == SrsAudioCodecIdAAC) {
p.write_1bytes(uint8_t(s->codec_type == SrsCodecAudioTypeSequenceHeader? 0:1)); p.write_1bytes(uint8_t(s->frame_trait == SrsAudioAacFrameTraitSequenceHeader? 0:1));
} }
p.write_bytes((char*)s->sample, s->nb_sample); p.write_bytes((char*)s->sample, s->nb_sample);
@ -1658,10 +1658,10 @@ int srs_mp4_to_flv_tag(srs_mp4_t mp4, srs_mp4_sample_t* s, char* type, uint32_t*
// E.4.3.1 VIDEODATA, flv_v10_1.pdf, page 5 // E.4.3.1 VIDEODATA, flv_v10_1.pdf, page 5
p.write_1bytes(uint8_t(s->frame_type<<4) | s->codec); p.write_1bytes(uint8_t(s->frame_type<<4) | s->codec);
if (s->codec == SrsCodecVideoAVC) { if (s->codec == SrsVideoCodecIdAVC) {
*type = SRS_RTMP_TYPE_VIDEO; *type = SRS_RTMP_TYPE_VIDEO;
p.write_1bytes(uint8_t(s->codec_type == SrsCodecVideoAVCTypeSequenceHeader? 0:1)); p.write_1bytes(uint8_t(s->frame_trait == SrsVideoAvcFrameTraitSequenceHeader? 0:1));
// cts = pts - dts, where dts = flvheader->timestamp. // cts = pts - dts, where dts = flvheader->timestamp.
uint32_t cts = s->pts - s->dts; uint32_t cts = s->pts - s->dts;
p.write_3bytes(cts); p.write_3bytes(cts);
@ -1851,12 +1851,12 @@ srs_bool srs_flv_is_eof(int error_code)
srs_bool srs_flv_is_sequence_header(char* data, int32_t size) srs_bool srs_flv_is_sequence_header(char* data, int32_t size)
{ {
return SrsFlvCodec::video_is_sequence_header(data, (int)size); return SrsFlvVideo::sh(data, (int)size);
} }
srs_bool srs_flv_is_keyframe(char* data, int32_t size) srs_bool srs_flv_is_keyframe(char* data, int32_t size)
{ {
return SrsFlvCodec::video_is_keyframe(data, (int)size); return SrsFlvVideo::keyframe(data, (int)size);
} }
srs_amf0_t srs_amf0_parse(char* data, int size, int* nparsed) srs_amf0_t srs_amf0_parse(char* data, int size, int* nparsed)
@ -2191,11 +2191,11 @@ int srs_utils_parse_timestamp(
return ret; return ret;
} }
if (!SrsFlvCodec::video_is_h264(data, size)) { if (!SrsFlvVideo::h264(data, size)) {
return ERROR_FLV_INVALID_VIDEO_TAG; return ERROR_FLV_INVALID_VIDEO_TAG;
} }
if (SrsFlvCodec::video_is_sequence_header(data, size)) { if (SrsFlvVideo::sh(data, size)) {
*ppts = time; *ppts = time;
return ret; return ret;
} }
@ -2259,7 +2259,7 @@ char srs_utils_flv_video_avc_packet_type(char* data, int size)
return -1; return -1;
} }
if (!SrsFlvCodec::video_is_h264(data, size)) { if (!SrsFlvVideo::h264(data, size)) {
return -1; return -1;
} }
@ -2278,7 +2278,7 @@ char srs_utils_flv_video_frame_type(char* data, int size)
return -1; return -1;
} }
if (!SrsFlvCodec::video_is_h264(data, size)) { if (!SrsFlvVideo::h264(data, size)) {
return -1; return -1;
} }

View file

@ -520,25 +520,25 @@ typedef struct {
// The dts in milliseconds. // The dts in milliseconds.
uint32_t dts; uint32_t dts;
// The codec type. // The codec id.
// video: SrsCodecVideo. // video: SrsVideoCodecId.
// audio: SrsCodecAudio. // audio: SrsAudioCodecId.
uint16_t codec; uint16_t codec;
// The codec type: // The frame trait, some characteristic:
// video: SrsCodecVideoAVCType. // video: SrsVideoAvcFrameTrait.
// audio: SrsCodecAudioType. // audio: SrsAudioAacFrameTrait.
uint16_t codec_type; uint16_t frame_trait;
// The video pts in milliseconds. Ignore for audio. // The video pts in milliseconds. Ignore for audio.
uint32_t pts; uint32_t pts;
// The video frame type, it's SrsCodecVideoAVCFrame. // The video frame type, it's SrsVideoAvcFrameType.
uint16_t frame_type; uint16_t frame_type;
// The audio sample rate, it's SrsCodecAudioSampleRate. // The audio sample rate, it's SrsAudioSampleRate.
uint8_t sample_rate; uint8_t sample_rate;
// The audio sound bits, it's SrsCodecAudioSampleSize. // The audio sound bits, it's SrsAudioSampleSize.
uint8_t sound_bits; uint8_t sound_bits;
// The audio sound type, it's SrsCodecAudioSoundType. // The audio sound type, it's SrsAudioSoundType.
uint8_t channels; uint8_t channels;
// The size of sample payload in bytes. // The size of sample payload in bytes.

View file

@ -653,7 +653,7 @@ private:
virtual int parse_message_queue(); virtual int parse_message_queue();
virtual int on_ts_video(SrsTsMessage* msg, SrsBuffer* avs); virtual int on_ts_video(SrsTsMessage* msg, SrsBuffer* avs);
virtual int write_h264_sps_pps(uint32_t dts, uint32_t pts); virtual int write_h264_sps_pps(uint32_t dts, uint32_t pts);
virtual int write_h264_ipb_frame(std::string ibps, SrsCodecVideoAVCFrame frame_type, uint32_t dts, uint32_t pts); virtual int write_h264_ipb_frame(std::string ibps, SrsVideoAvcFrameType frame_type, uint32_t dts, uint32_t pts);
virtual int on_ts_audio(SrsTsMessage* msg, SrsBuffer* avs); virtual int on_ts_audio(SrsTsMessage* msg, SrsBuffer* avs);
virtual int write_audio_raw_frame(char* frame, int frame_size, SrsRawAacStreamCodec* codec, uint32_t dts); virtual int write_audio_raw_frame(char* frame, int frame_size, SrsRawAacStreamCodec* codec, uint32_t dts);
private: private:
@ -959,7 +959,7 @@ int SrsIngestSrsOutput::on_ts_video(SrsTsMessage* msg, SrsBuffer* avs)
uint32_t pts = (uint32_t)(msg->dts / 90); uint32_t pts = (uint32_t)(msg->dts / 90);
std::string ibps; std::string ibps;
SrsCodecVideoAVCFrame frame_type = SrsCodecVideoAVCFrameInterFrame; SrsVideoAvcFrameType frame_type = SrsVideoAvcFrameTypeInterFrame;
// send each frame. // send each frame.
while (!avs->empty()) { while (!avs->empty()) {
@ -976,7 +976,7 @@ int SrsIngestSrsOutput::on_ts_video(SrsTsMessage* msg, SrsBuffer* avs)
// for IDR frame, the frame is keyframe. // for IDR frame, the frame is keyframe.
if (nal_unit_type == SrsAvcNaluTypeIDR) { if (nal_unit_type == SrsAvcNaluTypeIDR) {
frame_type = SrsCodecVideoAVCFrameKeyFrame; frame_type = SrsVideoAvcFrameTypeKeyFrame;
} }
// ignore the nalu type aud(9) // ignore the nalu type aud(9)
@ -1060,8 +1060,8 @@ int SrsIngestSrsOutput::write_h264_sps_pps(uint32_t dts, uint32_t pts)
} }
// h264 packet to flv packet. // h264 packet to flv packet.
int8_t frame_type = SrsCodecVideoAVCFrameKeyFrame; int8_t frame_type = SrsVideoAvcFrameTypeKeyFrame;
int8_t avc_packet_type = SrsCodecVideoAVCTypeSequenceHeader; int8_t avc_packet_type = SrsVideoAvcFrameTraitSequenceHeader;
char* flv = NULL; char* flv = NULL;
int nb_flv = 0; int nb_flv = 0;
if ((ret = avc->mux_avc2flv(sh, frame_type, avc_packet_type, dts, pts, &flv, &nb_flv)) != ERROR_SUCCESS) { if ((ret = avc->mux_avc2flv(sh, frame_type, avc_packet_type, dts, pts, &flv, &nb_flv)) != ERROR_SUCCESS) {
@ -1070,7 +1070,7 @@ int SrsIngestSrsOutput::write_h264_sps_pps(uint32_t dts, uint32_t pts)
// the timestamp in rtmp message header is dts. // the timestamp in rtmp message header is dts.
uint32_t timestamp = dts; uint32_t timestamp = dts;
if ((ret = rtmp_write_packet(SrsCodecFlvTagVideo, timestamp, flv, nb_flv)) != ERROR_SUCCESS) { if ((ret = rtmp_write_packet(SrsFrameTypeVideo, timestamp, flv, nb_flv)) != ERROR_SUCCESS) {
return ret; return ret;
} }
@ -1083,7 +1083,7 @@ int SrsIngestSrsOutput::write_h264_sps_pps(uint32_t dts, uint32_t pts)
return ret; return ret;
} }
int SrsIngestSrsOutput::write_h264_ipb_frame(string ibps, SrsCodecVideoAVCFrame frame_type, uint32_t dts, uint32_t pts) int SrsIngestSrsOutput::write_h264_ipb_frame(string ibps, SrsVideoAvcFrameType frame_type, uint32_t dts, uint32_t pts)
{ {
int ret = ERROR_SUCCESS; int ret = ERROR_SUCCESS;
@ -1093,7 +1093,7 @@ int SrsIngestSrsOutput::write_h264_ipb_frame(string ibps, SrsCodecVideoAVCFrame
return ERROR_H264_DROP_BEFORE_SPS_PPS; return ERROR_H264_DROP_BEFORE_SPS_PPS;
} }
int8_t avc_packet_type = SrsCodecVideoAVCTypeNALU; int8_t avc_packet_type = SrsVideoAvcFrameTraitNALU;
char* flv = NULL; char* flv = NULL;
int nb_flv = 0; int nb_flv = 0;
if ((ret = avc->mux_avc2flv(ibps, frame_type, avc_packet_type, dts, pts, &flv, &nb_flv)) != ERROR_SUCCESS) { if ((ret = avc->mux_avc2flv(ibps, frame_type, avc_packet_type, dts, pts, &flv, &nb_flv)) != ERROR_SUCCESS) {
@ -1102,7 +1102,7 @@ int SrsIngestSrsOutput::write_h264_ipb_frame(string ibps, SrsCodecVideoAVCFrame
// the timestamp in rtmp message header is dts. // the timestamp in rtmp message header is dts.
uint32_t timestamp = dts; uint32_t timestamp = dts;
return rtmp_write_packet(SrsCodecFlvTagVideo, timestamp, flv, nb_flv); return rtmp_write_packet(SrsFrameTypeVideo, timestamp, flv, nb_flv);
} }
int SrsIngestSrsOutput::on_ts_audio(SrsTsMessage* msg, SrsBuffer* avs) int SrsIngestSrsOutput::on_ts_audio(SrsTsMessage* msg, SrsBuffer* avs)
@ -1175,7 +1175,7 @@ int SrsIngestSrsOutput::write_audio_raw_frame(char* frame, int frame_size, SrsRa
return ret; return ret;
} }
return rtmp_write_packet(SrsCodecFlvTagAudio, dts, data, size); return rtmp_write_packet(SrsFrameTypeAudio, dts, data, size);
} }
int SrsIngestSrsOutput::rtmp_write_packet(char type, uint32_t timestamp, char* data, int size) int SrsIngestSrsOutput::rtmp_write_packet(char type, uint32_t timestamp, char* data, int size)

View file

@ -32,11 +32,6 @@
#include <srs_kernel_codec.hpp> #include <srs_kernel_codec.hpp>
class SrsBuffer;
class SrsAudioFrame;
class SrsVideoFrame;
class SrsAudioCodec;
class SrsVideoCodec;
class SrsOnMetaDataPacket; class SrsOnMetaDataPacket;
class SrsSharedPtrMessage; class SrsSharedPtrMessage;

View file

@ -200,7 +200,7 @@ int srs_do_rtmp_create_msg(char type, uint32_t timestamp, char* data, int size,
*ppmsg = NULL; *ppmsg = NULL;
T* msg = NULL; T* msg = NULL;
if (type == SrsCodecFlvTagAudio) { if (type == SrsFrameTypeAudio) {
SrsMessageHeader header; SrsMessageHeader header;
header.initialize_audio(size, timestamp, stream_id); header.initialize_audio(size, timestamp, stream_id);
@ -209,7 +209,7 @@ int srs_do_rtmp_create_msg(char type, uint32_t timestamp, char* data, int size,
srs_freep(msg); srs_freep(msg);
return ret; return ret;
} }
} else if (type == SrsCodecFlvTagVideo) { } else if (type == SrsFrameTypeVideo) {
SrsMessageHeader header; SrsMessageHeader header;
header.initialize_video(size, timestamp, stream_id); header.initialize_video(size, timestamp, stream_id);
@ -218,7 +218,7 @@ int srs_do_rtmp_create_msg(char type, uint32_t timestamp, char* data, int size,
srs_freep(msg); srs_freep(msg);
return ret; return ret;
} }
} else if (type == SrsCodecFlvTagScript) { } else if (type == SrsFrameTypeScript) {
SrsMessageHeader header; SrsMessageHeader header;
header.initialize_amf0_script(size, stream_id); header.initialize_amf0_script(size, stream_id);

View file

@ -278,7 +278,7 @@ int SrsRawH264Stream::mux_avc2flv(string video, int8_t frame_type, int8_t avc_pa
// Frame Type, Type of video frame. // Frame Type, Type of video frame.
// CodecID, Codec Identifier. // CodecID, Codec Identifier.
// set the rtmp header // set the rtmp header
*p++ = (frame_type << 4) | SrsCodecVideoAVC; *p++ = (frame_type << 4) | SrsVideoCodecIdAVC;
// AVCPacketType // AVCPacketType
*p++ = avc_packet_type; *p++ = avc_packet_type;
@ -424,7 +424,7 @@ int SrsRawAacStream::adts_demux(SrsBuffer* stream, char** pframe, int* pnb_frame
// the codec info. // the codec info.
codec.protection_absent = protection_absent; codec.protection_absent = protection_absent;
codec.aac_object = srs_codec_aac_ts2rtmp((SrsAacProfile)profile); codec.aac_object = srs_aac_ts2rtmp((SrsAacProfile)profile);
codec.sampling_frequency_index = sampling_frequency_index; codec.sampling_frequency_index = sampling_frequency_index;
codec.channel_configuration = channel_configuration; codec.channel_configuration = channel_configuration;
codec.frame_length = frame_length; codec.frame_length = frame_length;
@ -433,15 +433,15 @@ int SrsRawAacStream::adts_demux(SrsBuffer* stream, char** pframe, int* pnb_frame
// TODO: FIXME: maybe need to resample audio. // TODO: FIXME: maybe need to resample audio.
codec.sound_format = 10; // AAC codec.sound_format = 10; // AAC
if (sampling_frequency_index <= 0x0c && sampling_frequency_index > 0x0a) { if (sampling_frequency_index <= 0x0c && sampling_frequency_index > 0x0a) {
codec.sound_rate = SrsCodecAudioSampleRate5512; codec.sound_rate = SrsAudioSampleRate5512;
} else if (sampling_frequency_index <= 0x0a && sampling_frequency_index > 0x07) { } else if (sampling_frequency_index <= 0x0a && sampling_frequency_index > 0x07) {
codec.sound_rate = SrsCodecAudioSampleRate11025; codec.sound_rate = SrsAudioSampleRate11025;
} else if (sampling_frequency_index <= 0x07 && sampling_frequency_index > 0x04) { } else if (sampling_frequency_index <= 0x07 && sampling_frequency_index > 0x04) {
codec.sound_rate = SrsCodecAudioSampleRate22050; codec.sound_rate = SrsAudioSampleRate22050;
} else if (sampling_frequency_index <= 0x04) { } else if (sampling_frequency_index <= 0x04) {
codec.sound_rate = SrsCodecAudioSampleRate44100; codec.sound_rate = SrsAudioSampleRate44100;
} else { } else {
codec.sound_rate = SrsCodecAudioSampleRate44100; codec.sound_rate = SrsAudioSampleRate44100;
srs_warn("adts invalid sample rate for flv, rate=%#x", sampling_frequency_index); srs_warn("adts invalid sample rate for flv, rate=%#x", sampling_frequency_index);
} }
codec.sound_type = srs_max(0, srs_min(1, channel_configuration - 1)); codec.sound_type = srs_max(0, srs_min(1, channel_configuration - 1));
@ -475,11 +475,11 @@ int SrsRawAacStream::mux_sequence_header(SrsRawAacStreamCodec* codec, string& sh
// override the aac samplerate by user specified. // override the aac samplerate by user specified.
// @see https://github.com/ossrs/srs/issues/212#issuecomment-64146899 // @see https://github.com/ossrs/srs/issues/212#issuecomment-64146899
switch (codec->sound_rate) { switch (codec->sound_rate) {
case SrsCodecAudioSampleRate11025: case SrsAudioSampleRate11025:
samplingFrequencyIndex = 0x0a; break; samplingFrequencyIndex = 0x0a; break;
case SrsCodecAudioSampleRate22050: case SrsAudioSampleRate22050:
samplingFrequencyIndex = 0x07; break; samplingFrequencyIndex = 0x07; break;
case SrsCodecAudioSampleRate44100: case SrsAudioSampleRate44100:
samplingFrequencyIndex = 0x04; break; samplingFrequencyIndex = 0x04; break;
default: default:
break; break;
@ -532,7 +532,7 @@ int SrsRawAacStream::mux_aac2flv(char* frame, int nb_frame, SrsRawAacStreamCodec
// 1bytes, SoundFormat|SoundRate|SoundSize|SoundType // 1bytes, SoundFormat|SoundRate|SoundSize|SoundType
// 1bytes, AACPacketType for SoundFormat == 10, 0 is sequence header. // 1bytes, AACPacketType for SoundFormat == 10, 0 is sequence header.
int size = nb_frame + 1; int size = nb_frame + 1;
if (sound_format == SrsCodecAudioAAC) { if (sound_format == SrsAudioCodecIdAAC) {
size += 1; size += 1;
} }
char* data = new char[size]; char* data = new char[size];
@ -545,7 +545,7 @@ int SrsRawAacStream::mux_aac2flv(char* frame, int nb_frame, SrsRawAacStreamCodec
*p++ = audio_header; *p++ = audio_header;
if (sound_format == SrsCodecAudioAAC) { if (sound_format == SrsAudioCodecIdAAC) {
*p++ = aac_packet_type; *p++ = aac_packet_type;
} }

View file

@ -79,8 +79,8 @@ public:
virtual int mux_ipb_frame(char* frame, int nb_frame, std::string& ibp); virtual int mux_ipb_frame(char* frame, int nb_frame, std::string& ibp);
/** /**
* mux the avc video packet to flv video packet. * mux the avc video packet to flv video packet.
* @param frame_type, SrsCodecVideoAVCFrameKeyFrame or SrsCodecVideoAVCFrameInterFrame. * @param frame_type, SrsVideoAvcFrameTypeKeyFrame or SrsVideoAvcFrameTypeInterFrame.
* @param avc_packet_type, SrsCodecVideoAVCTypeSequenceHeader or SrsCodecVideoAVCTypeNALU. * @param avc_packet_type, SrsVideoAvcFrameTraitSequenceHeader or SrsVideoAvcFrameTraitNALU.
* @param video the h.264 raw data. * @param video the h.264 raw data.
* @param flv output the muxed flv packet. * @param flv output the muxed flv packet.
* @param nb_flv output the muxed flv size. * @param nb_flv output the muxed flv size.

View file

@ -297,11 +297,11 @@ VOID TEST(KernelCodecTest, IsKeyFrame)
char data; char data;
data = 0x10; data = 0x10;
EXPECT_TRUE(SrsFlvCodec::video_is_keyframe(&data, 1)); EXPECT_TRUE(SrsFlvVideo::keyframe(&data, 1));
EXPECT_FALSE(SrsFlvCodec::video_is_keyframe(&data, 0)); EXPECT_FALSE(SrsFlvVideo::keyframe(&data, 0));
data = 0x20; data = 0x20;
EXPECT_FALSE(SrsFlvCodec::video_is_keyframe(&data, 1)); EXPECT_FALSE(SrsFlvVideo::keyframe(&data, 1));
} }
/** /**
@ -312,16 +312,16 @@ VOID TEST(KernelCodecTest, IsH264)
{ {
char data; char data;
EXPECT_FALSE(SrsFlvCodec::video_is_h264(&data, 0)); EXPECT_FALSE(SrsFlvVideo::h264(&data, 0));
data = 0x17; data = 0x17;
EXPECT_TRUE(SrsFlvCodec::video_is_h264(&data, 1)); EXPECT_TRUE(SrsFlvVideo::h264(&data, 1));
data = 0x07; data = 0x07;
EXPECT_TRUE(SrsFlvCodec::video_is_h264(&data, 1)); EXPECT_TRUE(SrsFlvVideo::h264(&data, 1));
data = 0x08; data = 0x08;
EXPECT_FALSE(SrsFlvCodec::video_is_h264(&data, 1)); EXPECT_FALSE(SrsFlvVideo::h264(&data, 1));
} }
/** /**
@ -333,19 +333,19 @@ VOID TEST(KernelCodecTest, IsSequenceHeader)
int16_t data; int16_t data;
char* pp = (char*)&data; char* pp = (char*)&data;
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((char*)pp, 0)); EXPECT_FALSE(SrsFlvVideo::sh((char*)pp, 0));
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((char*)pp, 1)); EXPECT_FALSE(SrsFlvVideo::sh((char*)pp, 1));
pp[0] = 0x17; pp[0] = 0x17;
pp[1] = 0x00; pp[1] = 0x00;
EXPECT_TRUE(SrsFlvCodec::video_is_sequence_header((char*)pp, 2)); EXPECT_TRUE(SrsFlvVideo::sh((char*)pp, 2));
pp[0] = 0x18; pp[0] = 0x18;
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((char*)pp, 2)); EXPECT_FALSE(SrsFlvVideo::sh((char*)pp, 2));
pp[0] = 0x27; pp[0] = 0x27;
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((char*)pp, 2)); EXPECT_FALSE(SrsFlvVideo::sh((char*)pp, 2));
pp[0] = 0x17; pp[0] = 0x17;
pp[1] = 0x01; pp[1] = 0x01;
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((char*)pp, 2)); EXPECT_FALSE(SrsFlvVideo::sh((char*)pp, 2));
} }
/** /**
@ -356,16 +356,16 @@ VOID TEST(KernelCodecTest, IsAAC)
{ {
char data; char data;
EXPECT_FALSE(SrsFlvCodec::audio_is_aac(&data, 0)); EXPECT_FALSE(SrsFlvAudio::aac(&data, 0));
data = 0xa0; data = 0xa0;
EXPECT_TRUE(SrsFlvCodec::audio_is_aac(&data, 1)); EXPECT_TRUE(SrsFlvAudio::aac(&data, 1));
data = 0xa7; data = 0xa7;
EXPECT_TRUE(SrsFlvCodec::audio_is_aac(&data, 1)); EXPECT_TRUE(SrsFlvAudio::aac(&data, 1));
data = 0x00; data = 0x00;
EXPECT_FALSE(SrsFlvCodec::audio_is_aac(&data, 1)); EXPECT_FALSE(SrsFlvAudio::aac(&data, 1));
} }
/** /**
@ -377,17 +377,17 @@ VOID TEST(KernelCodecTest, IsAudioSequenceHeader)
int16_t data; int16_t data;
char* pp = (char*)&data; char* pp = (char*)&data;
EXPECT_FALSE(SrsFlvCodec::audio_is_sequence_header((char*)pp, 0)); EXPECT_FALSE(SrsFlvAudio::sh((char*)pp, 0));
EXPECT_FALSE(SrsFlvCodec::audio_is_sequence_header((char*)pp, 1)); EXPECT_FALSE(SrsFlvAudio::sh((char*)pp, 1));
pp[0] = 0xa0; pp[0] = 0xa0;
pp[1] = 0x00; pp[1] = 0x00;
EXPECT_TRUE(SrsFlvCodec::audio_is_sequence_header((char*)pp, 2)); EXPECT_TRUE(SrsFlvAudio::sh((char*)pp, 2));
pp[0] = 0x00; pp[0] = 0x00;
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((char*)pp, 2)); EXPECT_FALSE(SrsFlvVideo::sh((char*)pp, 2));
pp[0] = 0xa0; pp[0] = 0xa0;
pp[1] = 0x01; pp[1] = 0x01;
EXPECT_FALSE(SrsFlvCodec::video_is_sequence_header((char*)pp, 2)); EXPECT_FALSE(SrsFlvVideo::sh((char*)pp, 2));
} }
/** /**