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

@ -98,7 +98,7 @@ int SrsAacEncoder::write_audio(int64_t timestamp, char* data, int size)
//int8_t sound_rate = (sound_format >> 2) & 0x03;
sound_format = (sound_format >> 4) & 0x0f;
if ((SrsCodecAudio)sound_format != SrsCodecAudioAAC) {
if ((SrsAudioCodecId)sound_format != SrsAudioCodecIdAAC) {
ret = ERROR_AAC_DECODE_ERROR;
srs_error("aac required, format=%d. ret=%d", sound_format, ret);
return ret;
@ -110,8 +110,8 @@ int SrsAacEncoder::write_audio(int64_t timestamp, char* data, int size)
return ret;
}
SrsCodecAudioType aac_packet_type = (SrsCodecAudioType)stream->read_1bytes();
if (aac_packet_type == SrsCodecAudioTypeSequenceHeader) {
SrsAudioAacFrameTrait aac_packet_type = (SrsAudioAacFrameTrait)stream->read_1bytes();
if (aac_packet_type == SrsAudioAacFrameTraitSequenceHeader) {
// AudioSpecificConfig
// 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
// original/copy 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);
// 4bits left.
// 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_core_autofree.hpp>
string srs_codec_video2str(SrsCodecVideo codec)
string srs_video_codec_id2str(SrsVideoCodecId codec)
{
switch (codec) {
case SrsCodecVideoAVC:
case SrsVideoCodecIdAVC:
return "H264";
case SrsCodecVideoOn2VP6:
case SrsCodecVideoOn2VP6WithAlphaChannel:
case SrsVideoCodecIdOn2VP6:
case SrsVideoCodecIdOn2VP6WithAlphaChannel:
return "VP6";
case SrsCodecVideoReserved:
case SrsCodecVideoReserved1:
case SrsCodecVideoReserved2:
case SrsCodecVideoDisabled:
case SrsCodecVideoSorensonH263:
case SrsCodecVideoScreenVideo:
case SrsCodecVideoScreenVideoVersion2:
case SrsVideoCodecIdReserved:
case SrsVideoCodecIdReserved1:
case SrsVideoCodecIdReserved2:
case SrsVideoCodecIdDisabled:
case SrsVideoCodecIdSorensonH263:
case SrsVideoCodecIdScreenVideo:
case SrsVideoCodecIdScreenVideoVersion2:
default:
return "Other";
}
}
string srs_codec_audio2str(SrsCodecAudio codec)
string srs_audio_codec_id2str(SrsAudioCodecId codec)
{
switch (codec) {
case SrsCodecAudioAAC:
case SrsAudioCodecIdAAC:
return "AAC";
case SrsCodecAudioMP3:
case SrsAudioCodecIdMP3:
return "MP3";
case SrsCodecAudioReserved1:
case SrsCodecAudioLinearPCMPlatformEndian:
case SrsCodecAudioADPCM:
case SrsCodecAudioLinearPCMLittleEndian:
case SrsCodecAudioNellymoser16kHzMono:
case SrsCodecAudioNellymoser8kHzMono:
case SrsCodecAudioNellymoser:
case SrsCodecAudioReservedG711AlawLogarithmicPCM:
case SrsCodecAudioReservedG711MuLawLogarithmicPCM:
case SrsCodecAudioReserved:
case SrsCodecAudioSpeex:
case SrsCodecAudioReservedMP3_8kHz:
case SrsCodecAudioReservedDeviceSpecificSound:
case SrsAudioCodecIdReserved1:
case SrsAudioCodecIdLinearPCMPlatformEndian:
case SrsAudioCodecIdADPCM:
case SrsAudioCodecIdLinearPCMLittleEndian:
case SrsAudioCodecIdNellymoser16kHzMono:
case SrsAudioCodecIdNellymoser8kHzMono:
case SrsAudioCodecIdNellymoser:
case SrsAudioCodecIdReservedG711AlawLogarithmicPCM:
case SrsAudioCodecIdReservedG711MuLawLogarithmicPCM:
case SrsAudioCodecIdReserved:
case SrsAudioCodecIdSpeex:
case SrsAudioCodecIdReservedMP3_8kHz:
case SrsAudioCodecIdReservedDeviceSpecificSound:
default:
return "Other";
}
}
string srs_codec_audio_samplerate2str(SrsCodecAudioSampleRate v)
string srs_codec_audio_samplerate2str(SrsAudioSampleRate v)
{
switch (v) {
case SrsCodecAudioSampleRate5512: return "5512";
case SrsCodecAudioSampleRate11025: return "11025";
case SrsCodecAudioSampleRate22050: return "22050";
case SrsCodecAudioSampleRate44100: return "44100";
case SrsAudioSampleRate5512: return "5512";
case SrsAudioSampleRate11025: return "11025";
case SrsAudioSampleRate22050: return "22050";
case SrsAudioSampleRate44100: return "44100";
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.
if (size < 1) {
@ -107,13 +107,13 @@ bool SrsFlvCodec::video_is_keyframe(char* data, int size)
char frame_type = data[0];
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
if (!video_is_h264(data, size)) {
if (!h264(data, size)) {
return false;
}
@ -127,28 +127,11 @@ bool SrsFlvCodec::video_is_sequence_header(char* data, int size)
char avc_packet_type = data[1];
return frame_type == SrsCodecVideoAVCFrameKeyFrame
&& avc_packet_type == SrsCodecVideoAVCTypeSequenceHeader;
return frame_type == SrsVideoAvcFrameTypeKeyFrame
&& avc_packet_type == SrsVideoAvcFrameTraitSequenceHeader;
}
bool SrsFlvCodec::audio_is_sequence_header(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)
bool SrsFlvVideo::h264(char* data, int size)
{
// 1bytes required.
if (size < 1) {
@ -158,23 +141,10 @@ bool SrsFlvCodec::video_is_h264(char* data, int size)
char codec_id = data[0];
codec_id = codec_id & 0x0F;
return codec_id == SrsCodecVideoAVC;
return codec_id == SrsVideoCodecIdAVC;
}
bool SrsFlvCodec::audio_is_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 == SrsCodecAudioAAC;
}
bool SrsFlvCodec::video_is_acceptable(char* data, int size)
bool SrsFlvVideo::acceptable(char* data, int size)
{
// 1bytes required.
if (size < 1) {
@ -196,6 +166,36 @@ bool SrsFlvCodec::video_is_acceptable(char* data, int size)
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.
*/
@ -203,11 +203,11 @@ bool SrsFlvCodec::video_is_acceptable(char* data, int size)
// 1 = 11 kHz = 11025 Hz
// 2 = 22 kHz = 22050 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,
// in the sequence header.
int aac_sample_rates[] =
int srs_aac_srates[] =
{
96000, 88200, 64000, 48000,
44100, 32000, 24000, 22050,
@ -215,25 +215,25 @@ int aac_sample_rates[] =
7350, 0, 0, 0
};
string srs_codec_audio_samplesize2str(SrsCodecAudioSampleSize v)
string srs_audio_samplesize2str(SrsAudioSampleSize v)
{
switch (v) {
case SrsCodecAudioSampleSize16bit: return "16bits";
case SrsCodecAudioSampleSize8bit: return "8bits";
case SrsAudioSampleSize16bit: return "16bits";
case SrsAudioSampleSize8bit: return "8bits";
default: return "Other";
}
}
string srs_codec_audio_channels2str(SrsCodecAudioSoundType v)
string srs_audio_channels2str(SrsAudioSoundType v)
{
switch (v) {
case SrsCodecAudioSoundTypeStereo: return "Stereo";
case SrsCodecAudioSoundTypeMono: return "Mono";
case SrsAudioSoundTypeStereo: return "Stereo";
case SrsAudioSoundTypeMono: return "Mono";
default: return "Other";
}
}
string srs_codec_avc_nalu2str(SrsAvcNaluType nalu_type)
string srs_avc_nalu2str(SrsAvcNaluType nalu_type)
{
switch (nalu_type) {
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) {
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) {
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) {
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) {
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) {
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) {
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;
sound_rate = SrsCodecAudioSampleRateForbidden;
sound_size = SrsCodecAudioSampleSizeForbidden;
sound_type = SrsCodecAudioSoundTypeForbidden;
id = SrsAudioCodecIdForbidden;
sound_rate = SrsAudioSampleRateForbidden;
sound_size = SrsAudioSampleSizeForbidden;
sound_type = SrsAudioSoundTypeForbidden;
audio_data_rate = 0;
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_extra_size = 0;
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;
}
SrsVideoCodec::SrsVideoCodec()
SrsVideoCodecConfig::SrsVideoCodecConfig()
{
id = SrsCodecVideoForbidden;
id = SrsVideoCodecIdForbidden;
video_data_rate = 0;
frame_rate = duration = 0;
@ -407,14 +407,14 @@ SrsVideoCodec::SrsVideoCodec()
payload_format = SrsAvcPayloadFormatGuess;
}
SrsVideoCodec::~SrsVideoCodec()
SrsVideoCodecConfig::~SrsVideoCodecConfig()
{
srs_freepa(avc_extra_data);
srs_freepa(sequenceParameterSetNALUnit);
srs_freepa(pictureParameterSetNALUnit);
}
bool SrsVideoCodec::is_avc_codec_ok()
bool SrsVideoCodecConfig::is_avc_codec_ok()
{
return avc_extra_size > 0 && avc_extra_data;
}
@ -432,7 +432,7 @@ SrsFrame::~SrsFrame()
srs_freep(codec);
}
int SrsFrame::initialize(SrsCodec* c)
int SrsFrame::initialize(SrsCodecConfig* c)
{
codec = c;
nb_samples = 0;
@ -445,9 +445,9 @@ int SrsFrame::add_sample(char* bytes, int size)
{
int ret = ERROR_SUCCESS;
if (nb_samples >= SRS_MAX_CODEC_SAMPLE) {
if (nb_samples >= SrsMaxNbSamples) {
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;
}
@ -460,22 +460,22 @@ int SrsFrame::add_sample(char* bytes, int size)
SrsAudioFrame::SrsAudioFrame()
{
aac_packet_type = SrsCodecAudioTypeForbidden;
aac_packet_type = SrsAudioAacFrameTraitForbidden;
}
SrsAudioFrame::~SrsAudioFrame()
{
}
SrsAudioCodec* SrsAudioFrame::acodec()
SrsAudioCodecConfig* SrsAudioFrame::acodec()
{
return (SrsAudioCodec*)codec;
return (SrsAudioCodecConfig*)codec;
}
SrsVideoFrame::SrsVideoFrame()
{
frame_type = SrsCodecVideoAVCFrameForbidden;
avc_packet_type = SrsCodecVideoAVCTypeForbidden;
frame_type = SrsVideoAvcFrameTypeForbidden;
avc_packet_type = SrsVideoAvcFrameTraitForbidden;
has_idr = has_aud = has_sps_pps = false;
first_nalu_type = SrsAvcNaluTypeForbidden;
}
@ -510,9 +510,9 @@ int SrsVideoFrame::add_sample(char* bytes, int size)
return ret;
}
SrsVideoCodec* SrsVideoFrame::vcodec()
SrsVideoCodecConfig* SrsVideoFrame::vcodec()
{
return (SrsVideoCodec*)codec;
return (SrsVideoCodecConfig*)codec;
}
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
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;
}
if (!acodec) {
acodec = new SrsAudioCodec();
acodec = new SrsAudioCodecConfig();
}
if (!audio) {
audio = new SrsAudioFrame();
@ -578,9 +578,9 @@ int SrsFormat::on_audio(int64_t timestamp, char* data, int size)
}
buffer->skip(-1 * buffer->pos());
if (codec == SrsCodecAudioMP3) {
if (codec == SrsAudioCodecIdMP3) {
return audio_mp3_demux(buffer, timestamp);
} else if (codec == SrsCodecAudioAAC) {
} else if (codec == SrsAudioCodecIdAAC) {
return audio_aac_demux(buffer, timestamp);
} else {
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
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.
if (codec_id != SrsCodecVideoAVC) {
if (codec_id != SrsVideoCodecIdAVC) {
return ret;
}
if (!vcodec) {
vcodec = new SrsVideoCodec();
vcodec = new SrsVideoCodecConfig();
}
if (!video) {
video = new SrsVideoFrame();
@ -636,7 +636,7 @@ int SrsFormat::on_aac_sequence_header(char* data, int size)
int ret = ERROR_SUCCESS;
if (!acodec) {
acodec = new SrsAudioCodec();
acodec = new SrsAudioCodecConfig();
}
if (!audio) {
audio = new SrsAudioFrame();
@ -651,14 +651,14 @@ int SrsFormat::on_aac_sequence_header(char* data, int size)
bool SrsFormat::is_aac_sequence_header()
{
return acodec && acodec->id == SrsCodecAudioAAC
&& audio && audio->aac_packet_type == SrsCodecAudioTypeSequenceHeader;
return acodec && acodec->id == SrsAudioCodecIdAAC
&& audio && audio->aac_packet_type == SrsAudioAacFrameTraitSequenceHeader;
}
bool SrsFormat::is_avc_sequence_header()
{
return vcodec && vcodec->id == SrsCodecVideoAVC
&& video && video->avc_packet_type == SrsCodecVideoAVCTypeSequenceHeader;
return vcodec && vcodec->id == SrsVideoCodecIdAVC
&& video && video->avc_packet_type == SrsVideoAvcFrameTraitSequenceHeader;
}
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
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;
video->frame_type = (SrsCodecVideoAVCFrame)frame_type;
video->frame_type = (SrsVideoAvcFrameType)frame_type;
// ignore info frame without error,
// @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);
return ret;
}
// only support h.264/avc
if (codec_id != SrsCodecVideoAVC) {
if (codec_id != SrsVideoCodecIdAVC) {
ret = ERROR_HLS_DECODE_ERROR;
srs_error("avc only support video h.264/avc codec. actual=%d, ret=%d", codec_id, ret);
return ret;
@ -698,13 +698,13 @@ int SrsFormat::video_avc_demux(SrsBuffer* stream, int64_t timestamp)
// pts = dts + cts.
video->dts = timestamp;
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) {
return ret;
}
} else if (avc_packet_type == SrsCodecVideoAVCTypeNALU){
} else if (avc_packet_type == SrsVideoAvcFrameTraitNALU){
if ((ret = video_nalu_demux(stream)) != ERROR_SUCCESS) {
return ret;
}
@ -1086,7 +1086,7 @@ int SrsFormat::video_nalu_demux(SrsBuffer* stream)
// ensure the sequence header demuxed
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;
}
@ -1267,20 +1267,20 @@ int SrsFormat::audio_aac_demux(SrsBuffer* stream, int64_t timestamp)
int8_t sound_rate = (sound_format >> 2) & 0x03;
sound_format = (sound_format >> 4) & 0x0f;
SrsCodecAudio codec_id = (SrsCodecAudio)sound_format;
SrsAudioCodecId codec_id = (SrsAudioCodecId)sound_format;
acodec->id = codec_id;
acodec->sound_type = (SrsCodecAudioSoundType)sound_type;
acodec->sound_rate = (SrsCodecAudioSampleRate)sound_rate;
acodec->sound_size = (SrsCodecAudioSampleSize)sound_size;
acodec->sound_type = (SrsAudioSoundType)sound_type;
acodec->sound_rate = (SrsAudioSampleRate)sound_rate;
acodec->sound_size = (SrsAudioSampleSize)sound_size;
// we support h.264+mp3 for hls.
if (codec_id == SrsCodecAudioMP3) {
if (codec_id == SrsAudioCodecIdMP3) {
return ERROR_HLS_TRY_MP3;
}
// only support aac
if (codec_id != SrsCodecAudioAAC) {
if (codec_id != SrsAudioCodecIdAAC) {
ret = ERROR_HLS_DECODE_ERROR;
srs_error("aac only support mp3/aac codec. actual=%d, ret=%d", codec_id, ret);
return ret;
@ -1292,10 +1292,10 @@ int SrsFormat::audio_aac_demux(SrsBuffer* stream, int64_t timestamp)
return ret;
}
SrsCodecAudioType aac_packet_type = (SrsCodecAudioType)stream->read_1bytes();
audio->aac_packet_type = (SrsCodecAudioType)aac_packet_type;
SrsAudioAacFrameTrait aac_packet_type = (SrsAudioAacFrameTrait)stream->read_1bytes();
audio->aac_packet_type = (SrsAudioAacFrameTrait)aac_packet_type;
if (aac_packet_type == SrsCodecAudioTypeSequenceHeader) {
if (aac_packet_type == SrsAudioAacFrameTraitSequenceHeader) {
// AudioSpecificConfig
// 1.6.2.1 AudioSpecificConfig, in ISO_IEC_14496-3-AAC-2001.pdf, page 33.
acodec->aac_extra_size = stream->size() - stream->pos();
@ -1308,7 +1308,7 @@ int SrsFormat::audio_aac_demux(SrsBuffer* stream, int64_t timestamp)
return ret;
}
}
} else if (aac_packet_type == SrsCodecAudioTypeRawData) {
} else if (aac_packet_type == SrsAudioAacFrameTraitRawData) {
// ensure the sequence header demuxed
if (!acodec->is_aac_codec_ok()) {
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
if (acodec->aac_sample_rate != SRS_AAC_SAMPLE_RATE_UNSET) {
static int aac_sample_rates[] = {
if (acodec->aac_sample_rate != SrsAacSampleRateUnset) {
static int srs_aac_srates[] = {
96000, 88200, 64000, 48000,
44100, 32000, 24000, 22050,
16000, 12000, 11025, 8000,
7350, 0, 0, 0
};
switch (aac_sample_rates[acodec->aac_sample_rate]) {
switch (srs_aac_srates[acodec->aac_sample_rate]) {
case 11025:
acodec->sound_rate = SrsCodecAudioSampleRate11025;
acodec->sound_rate = SrsAudioSampleRate11025;
break;
case 22050:
acodec->sound_rate = SrsCodecAudioSampleRate22050;
acodec->sound_rate = SrsAudioSampleRate22050;
break;
case 44100:
acodec->sound_rate = SrsCodecAudioSampleRate44100;
acodec->sound_rate = SrsAudioSampleRate44100;
break;
default:
break;
@ -1362,7 +1362,7 @@ int SrsFormat::audio_mp3_demux(SrsBuffer* stream, int64_t timestamp)
audio->dts = timestamp;
// we always decode aac then mp3.
srs_assert(acodec->id == SrsCodecAudioMP3);
srs_assert(acodec->id == SrsAudioCodecIdMP3);
stream->skip(1);
if (stream->empty()) {

View file

@ -34,207 +34,241 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
class SrsBuffer;
// AACPacketType IF SoundFormat == 10 UI8
// The following values are defined:
// 0 = AAC sequence header
// 1 = AAC raw
enum SrsCodecAudioType
{
// set to the max value to reserved, for array map.
SrsCodecAudioTypeReserved = 2,
SrsCodecAudioTypeForbidden = 2,
SrsCodecAudioTypeSequenceHeader = 0,
SrsCodecAudioTypeRawData = 1,
};
// 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
/**
* The video codec id.
* @doc video_file_format_spec_v10_1.pdf, page78, E.4.3.1 VIDEODATA
* CodecID UB [4]
* Codec Identifier. The following values are defined for FLV:
* 2 = Sorenson H.263
* 3 = Screen video
* 4 = On2 VP6
* 5 = On2 VP6 with alpha channel
* 6 = Screen video version 2
* 7 = AVC
*/
enum SrsVideoCodecId
{
// set to the zero to reserved, for array map.
SrsCodecVideoAVCFrameReserved = 0,
SrsCodecVideoAVCFrameForbidden = 0,
SrsCodecVideoAVCFrameReserved1 = 6,
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,
SrsVideoCodecIdReserved = 0,
SrsVideoCodecIdForbidden = 0,
SrsVideoCodecIdReserved1 = 1,
SrsVideoCodecIdReserved2 = 9,
// for user to disable video, for example, use pure audio hls.
SrsCodecVideoDisabled = 8,
SrsVideoCodecIdDisabled = 8,
SrsCodecVideoSorensonH263 = 2,
SrsCodecVideoScreenVideo = 3,
SrsCodecVideoOn2VP6 = 4,
SrsCodecVideoOn2VP6WithAlphaChannel = 5,
SrsCodecVideoScreenVideoVersion2 = 6,
SrsCodecVideoAVC = 7,
SrsVideoCodecIdSorensonH263 = 2,
SrsVideoCodecIdScreenVideo = 3,
SrsVideoCodecIdOn2VP6 = 4,
SrsVideoCodecIdOn2VP6WithAlphaChannel = 5,
SrsVideoCodecIdScreenVideoVersion2 = 6,
SrsVideoCodecIdAVC = 7,
};
std::string srs_codec_video2str(SrsCodecVideo 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);
std::string srs_video_codec_id2str(SrsVideoCodecId codec);
/**
* the FLV/RTMP supported audio sample rate.
* Sampling rate. The following values are defined:
* 0 = 5.5 kHz = 5512 Hz
* 1 = 11 kHz = 11025 Hz
* 2 = 22 kHz = 22050 Hz
* 3 = 44 kHz = 44100 Hz
*/
enum SrsCodecAudioSampleRate
* The video AVC frame trait(characteristic).
* @doc video_file_format_spec_v10_1.pdf, page79, E.4.3.2 AVCVIDEOPACKET
* 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 SrsVideoAvcFrameTrait
{
// set to the max value to reserved, for array map.
SrsCodecAudioSampleRateReserved = 4,
SrsCodecAudioSampleRateForbidden = 4,
SrsVideoAvcFrameTraitReserved = 3,
SrsVideoAvcFrameTraitForbidden = 3,
SrsCodecAudioSampleRate5512 = 0,
SrsCodecAudioSampleRate11025 = 1,
SrsCodecAudioSampleRate22050 = 2,
SrsCodecAudioSampleRate44100 = 3,
SrsVideoAvcFrameTraitSequenceHeader = 0,
SrsVideoAvcFrameTraitNALU = 1,
SrsVideoAvcFrameTraitSequenceHeaderEOF = 2,
};
std::string srs_codec_audio_samplerate2str(SrsCodecAudioSampleRate v);
/**
* E.4.1 FLV Tag, page 75
*/
enum SrsCodecFlvTag
* The video AVC frame type, such as I/P/B.
* @doc video_file_format_spec_v10_1.pdf, page78, 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 SrsVideoAvcFrameType
{
// set to the zero to reserved, for array map.
SrsCodecFlvTagReserved = 0,
SrsCodecFlvTagForbidden = 0,
// 8 = audio
SrsCodecFlvTagAudio = 8,
// 9 = video
SrsCodecFlvTagVideo = 9,
// 18 = script data
SrsCodecFlvTagScript = 18,
SrsVideoAvcFrameTypeReserved = 0,
SrsVideoAvcFrameTypeForbidden = 0,
SrsVideoAvcFrameTypeReserved1 = 6,
SrsVideoAvcFrameTypeKeyFrame = 1,
SrsVideoAvcFrameTypeInterFrame = 2,
SrsVideoAvcFrameTypeDisposableInterFrame = 3,
SrsVideoAvcFrameTypeGeneratedKeyFrame = 4,
SrsVideoAvcFrameTypeVideoInfoFrame = 5,
};
/**
* Annex E. The FLV File Format
*/
class SrsFlvCodec
* The audio codec id.
* @doc video_file_format_spec_v10_1.pdf, page 76, E.4.2 Audio Tags
* 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:
SrsFlvCodec();
virtual ~SrsFlvCodec();
SrsFlvVideo();
virtual ~SrsFlvVideo();
// the following function used to finger out the flv/rtmp packet detail.
public:
/**
* 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
*/
static bool video_is_sequence_header(char* data, int size);
/**
* check codec aac, sequence header
*/
static bool audio_is_sequence_header(char* data, int size);
static bool sh(char* data, int size);
/**
* check codec h264.
*/
static bool video_is_h264(char* data, int size);
/**
* check codec aac.
*/
static bool audio_is_aac(char* data, int size);
static bool h264(char* data, int size);
/**
* check the video RTMP/flv header info,
* @return true if video RTMP/flv header is ok.
* @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
*/
extern int flv_sample_rates[];
extern int srs_flv_srates[];
/**
* the aac sample rate map
*/
extern int aac_sample_rates[];
extern int srs_aac_srates[];
// 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.
#define SRS_MAX_CODEC_SAMPLE 256
#define SrsMaxNbSamples 256
/**
* the FLV/RTMP supported audio sample size.
@ -264,16 +298,16 @@ extern int aac_sample_rates[];
* 0 = 8-bit samples
* 1 = 16-bit samples
*/
enum SrsCodecAudioSampleSize
enum SrsAudioSampleSize
{
// set to the max value to reserved, for array map.
SrsCodecAudioSampleSizeReserved = 2,
SrsCodecAudioSampleSizeForbidden = 2,
SrsAudioSampleSizeReserved = 2,
SrsAudioSampleSizeForbidden = 2,
SrsCodecAudioSampleSize8bit = 0,
SrsCodecAudioSampleSize16bit = 1,
SrsAudioSampleSize8bit = 0,
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.
@ -281,16 +315,16 @@ std::string srs_codec_audio_samplesize2str(SrsCodecAudioSampleSize v);
* 0 = Mono sound
* 1 = Stereo sound
*/
enum SrsCodecAudioSoundType
enum SrsAudioSoundType
{
// set to the max value to reserved, for array map.
SrsCodecAudioSoundTypeReserved = 2,
SrsCodecAudioSoundTypeForbidden = 2,
SrsAudioSoundTypeReserved = 2,
SrsAudioSoundTypeForbidden = 2,
SrsCodecAudioSoundTypeMono = 0,
SrsCodecAudioSoundTypeStereo = 1,
SrsAudioSoundTypeMono = 0,
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
@ -337,7 +371,7 @@ enum SrsAvcNaluType
// Coded slice extension slice_layer_extension_rbsp( )
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.
@ -364,7 +398,7 @@ enum SrsAacProfile
SrsAacProfileLC = 1,
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
@ -387,11 +421,11 @@ enum SrsAacObjectType
// AAC HEv2 = LC+SBR+PS
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.
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.
SrsAacProfile srs_codec_aac_rtmp2ts(SrsAacObjectType object_type);
SrsAacProfile srs_aac_rtmp2ts(SrsAacObjectType object_type);
/**
* the profile for avc/h.264.
@ -417,7 +451,7 @@ enum SrsAvcProfile
SrsAvcProfileHigh444Predictive = 244,
SrsAvcProfileHigh444Intra = 2192,
};
std::string srs_codec_avc_profile2str(SrsAvcProfile profile);
std::string srs_avc_profile2str(SrsAvcProfile profile);
/**
* the level for avc/h.264.
@ -442,7 +476,7 @@ enum SrsAvcLevel
SrsAvcLevel_5 = 50,
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.
@ -467,25 +501,25 @@ public:
* corresponding to the sequence header of FLV,
* parsed to detail info.
*/
class SrsCodec
class SrsCodecConfig
{
public:
SrsCodec();
virtual ~SrsCodec();
SrsCodecConfig();
virtual ~SrsCodecConfig();
};
/**
* The audio codec info.
*/
class SrsAudioCodec : public SrsCodec
class SrsAudioCodecConfig : public SrsCodecConfig
{
public:
// audio specified
SrsCodecAudio id;
SrsAudioCodecId id;
// audio aac specified.
SrsCodecAudioSampleRate sound_rate;
SrsCodecAudioSampleSize sound_size;
SrsCodecAudioSoundType sound_type;
SrsAudioSampleRate sound_rate;
SrsAudioSampleSize sound_size;
SrsAudioSoundType sound_type;
int audio_data_rate; // in bps
public:
/**
@ -512,8 +546,8 @@ public:
int aac_extra_size;
char* aac_extra_data;
public:
SrsAudioCodec();
virtual ~SrsAudioCodec();
SrsAudioCodecConfig();
virtual ~SrsAudioCodecConfig();
public:
virtual bool is_aac_codec_ok();
};
@ -521,10 +555,10 @@ public:
/**
* The video codec info.
*/
class SrsVideoCodec : public SrsCodec
class SrsVideoCodecConfig : public SrsCodecConfig
{
public:
SrsCodecVideo id;
SrsVideoCodecId id;
int video_data_rate; // in bps
double frame_rate;
double duration;
@ -556,8 +590,8 @@ public:
// the avc payload format.
SrsAvcPayloadFormat payload_format;
public:
SrsVideoCodec();
virtual ~SrsVideoCodec();
SrsVideoCodecConfig();
virtual ~SrsVideoCodecConfig();
public:
virtual bool is_avc_codec_ok();
};
@ -574,17 +608,17 @@ public:
int32_t cts;
public:
// The codec info of frame.
SrsCodec* codec;
SrsCodecConfig* codec;
// The actual parsed number of samples.
int nb_samples;
// The sampels cache.
SrsSample samples[SRS_MAX_CODEC_SAMPLE];
SrsSample samples[SrsMaxNbSamples];
public:
SrsFrame();
virtual ~SrsFrame();
public:
// Initialize the frame, to parse sampels.
virtual int initialize(SrsCodec* c);
virtual int initialize(SrsCodecConfig* c);
// Add a sample to frame.
virtual int add_sample(char* bytes, int size);
};
@ -595,12 +629,12 @@ public:
class SrsAudioFrame : public SrsFrame
{
public:
SrsCodecAudioType aac_packet_type;
SrsAudioAacFrameTrait aac_packet_type;
public:
SrsAudioFrame();
virtual ~SrsAudioFrame();
public:
virtual SrsAudioCodec* acodec();
virtual SrsAudioCodecConfig* acodec();
};
/**
@ -610,8 +644,8 @@ class SrsVideoFrame : public SrsFrame
{
public:
// video specified
SrsCodecVideoAVCFrame frame_type;
SrsCodecVideoAVCType avc_packet_type;
SrsVideoAvcFrameType frame_type;
SrsVideoAvcFrameTrait avc_packet_type;
// whether sample_units contains IDR frame.
bool has_idr;
// Whether exists AUD NALU.
@ -627,7 +661,7 @@ public:
// Add the sample without ANNEXB or IBMF header, or RAW AAC or MP3 data.
virtual int add_sample(char* bytes, int size);
public:
virtual SrsVideoCodec* vcodec();
virtual SrsVideoCodecConfig* vcodec();
};
/**
@ -639,9 +673,9 @@ class SrsFormat
{
public:
SrsAudioFrame* audio;
SrsAudioCodec* acodec;
SrsAudioCodecConfig* acodec;
SrsVideoFrame* video;
SrsVideoCodec* vcodec;
SrsVideoCodecConfig* vcodec;
SrsBuffer* buffer;
public:
// for sequence header, whether parse the h.264 sps.
@ -654,8 +688,10 @@ public:
// Initialize the format.
virtual int initialize();
// When got a parsed audio packet.
// @param data The data in FLV format.
virtual int on_audio(int64_t timestamp, char* data, int size);
// When got a parsed video packet.
// @param data The data in FLV format.
virtual int on_video(int64_t timestamp, char* data, int size);
// When got a audio aac sequence header.
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;
}
} 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;
}
}
@ -605,7 +605,7 @@ int SrsFlvEncoder::write_audio_to_cache(int64_t timestamp, char* data, int size,
// 11bytes 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, // Timestamp UI24 Time in milliseconds at which the data in this tag applies.
(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) {
return ret;
}
tag_stream->write_1bytes(SrsCodecFlvTagAudio);
tag_stream->write_1bytes(SrsFrameTypeAudio);
tag_stream->write_3bytes(size);
tag_stream->write_3bytes((int32_t)timestamp);
// default to little-endian
@ -636,7 +636,7 @@ int SrsFlvEncoder::write_video_to_cache(int64_t timestamp, char* data, int size,
// 11bytes 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, // Timestamp UI24 Time in milliseconds at which the data in this tag applies.
(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) {
return ret;
}
tag_stream->write_1bytes(SrsCodecFlvTagVideo);
tag_stream->write_1bytes(SrsFrameTypeVideo);
tag_stream->write_3bytes(size);
tag_stream->write_3bytes((int32_t)timestamp);
// default to little-endian

View file

@ -470,7 +470,7 @@ public:
/**
* write flv metadata.
* @param type, the type of data, or other message type.
* @see SrsCodecFlvTag
* @see SrsFrameType
* @param data, the amf0 metadata which serialize from:
* AMF0 string: onMetaData,
* 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;
sound_format = (sound_format >> 4) & 0x0f;
if ((SrsCodecAudio)sound_format != SrsCodecAudioMP3) {
if ((SrsAudioCodecId)sound_format != SrsAudioCodecIdMP3) {
ret = ERROR_MP3_DECODE_ERROR;
srs_error("mp3 required, format=%d. ret=%d", sound_format, ret);
return ret;

View file

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

View file

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

View file

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

View file

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