Skip to content

Commit

Permalink
for #299, refine the codec object name
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Feb 12, 2017
1 parent d7458c4 commit caf69f1
Show file tree
Hide file tree
Showing 29 changed files with 713 additions and 681 deletions.
34 changes: 17 additions & 17 deletions trunk/src/app/srs_app_dvr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,9 @@ int SrsDvrFlvSegmenter::encode_video(SrsSharedPtrMessage* video)

char* payload = video->payload;
int size = video->size;
bool sh = SrsFlvCodec::video_is_sequence_header(payload, size);
bool keyframe = SrsFlvCodec::video_is_h264(payload, size)
&& SrsFlvCodec::video_is_keyframe(payload, size) && !sh;
bool sh = SrsFlvVideo::sh(payload, size);
bool keyframe = SrsFlvVideo::h264(payload, size)
&& SrsFlvVideo::keyframe(payload, size) && !sh;

if (keyframe) {
has_keyframe = true;
Expand Down Expand Up @@ -534,23 +534,23 @@ int SrsDvrMp4Segmenter::encode_audio(SrsSharedPtrMessage* audio)
return ret;
}
uint8_t v = buffer->read_1bytes();
SrsCodecAudio sound_format = (SrsCodecAudio)((v >> 4) & 0x0f);
SrsCodecAudioSampleRate sound_rate = (SrsCodecAudioSampleRate)((v >> 2) & 0x03);
SrsCodecAudioSampleSize sound_size = (SrsCodecAudioSampleSize)((v >> 1) & 0x01);
SrsCodecAudioSoundType channels = (SrsCodecAudioSoundType)(v&0x01);
SrsAudioCodecId sound_format = (SrsAudioCodecId)((v >> 4) & 0x0f);
SrsAudioSampleRate sound_rate = (SrsAudioSampleRate)((v >> 2) & 0x03);
SrsAudioSampleSize sound_size = (SrsAudioSampleSize)((v >> 1) & 0x01);
SrsAudioSoundType channels = (SrsAudioSoundType)(v&0x01);

uint16_t ct = 0x00;
if (sound_format == SrsCodecAudioAAC) {
if (sound_format == SrsAudioCodecIdAAC) {
if (!buffer->require(1)) {
ret = ERROR_FLV_REQUIRE_SPACE;
srs_error("DVR require flva 1 byte space, format=%d. ret=%d", sound_format, ret);
return ret;
}
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->sample_rate = sound_rate;
enc->sound_bits = sound_size;
Expand Down Expand Up @@ -579,18 +579,18 @@ int SrsDvrMp4Segmenter::encode_video(SrsSharedPtrMessage* video)
return ret;
}
uint8_t v = buffer->read_1bytes();
SrsCodecVideoAVCFrame frame_type = (SrsCodecVideoAVCFrame)((v>>4)&0x0f);
SrsCodecVideo codec_id = (SrsCodecVideo)(v&0x0f);
SrsVideoAvcFrameType frame_type = (SrsVideoAvcFrameType)((v>>4)&0x0f);
SrsVideoCodecId codec_id = (SrsVideoCodecId)(v&0x0f);

if (!buffer->require(4)) {
ret = ERROR_FLV_REQUIRE_SPACE;
srs_error("DVR require flvv 4 bytes space, codec=%d. ret=%d", codec_id, ret);
return ret;
}
SrsCodecVideoAVCType ct = (SrsCodecVideoAVCType)buffer->read_1bytes();
SrsVideoAvcFrameTrait ct = (SrsVideoAvcFrameTrait)buffer->read_1bytes();
uint32_t cts = (uint32_t)buffer->read_3bytes();

if (ct == SrsCodecVideoAVCTypeSequenceHeader) {
if (ct == SrsVideoAvcFrameTraitSequenceHeader) {
enc->vcodec = codec_id;
}

Expand Down Expand Up @@ -929,9 +929,9 @@ int SrsDvrSegmentPlan::update_duration(SrsSharedPtrMessage* msg)

char* payload = msg->payload;
int size = msg->size;
bool is_key_frame = SrsFlvCodec::video_is_h264(payload, size)
&& SrsFlvCodec::video_is_keyframe(payload, size)
&& !SrsFlvCodec::video_is_sequence_header(payload, size);
bool is_key_frame = SrsFlvVideo::h264(payload, size)
&& SrsFlvVideo::keyframe(payload, size)
&& !SrsFlvVideo::sh(payload, size);
if (!is_key_frame) {
return ret;
}
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/app/srs_app_forward.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ int SrsForwarder::on_audio(SrsSharedPtrMessage* shared_audio)
return ret;
}

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

if (SrsFlvCodec::video_is_sequence_header(msg->payload, msg->size)) {
if (SrsFlvVideo::sh(msg->payload, msg->size)) {
srs_freep(sh_video);
sh_video = msg->copy();
}
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/app/srs_app_hds.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ int SrsHds::on_video(SrsSharedPtrMessage* msg)
return ret;
}

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

if (SrsFlvCodec::audio_is_sequence_header(msg->payload, msg->size)) {
if (SrsFlvAudio::sh(msg->payload, msg->size)) {
srs_freep(audio_sh);
audio_sh = msg->copy();
}
Expand Down
40 changes: 20 additions & 20 deletions trunk/src/app/srs_app_hls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ using namespace std;
// reset the piece id when deviation overflow this.
#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;
sequence_no = 0;
Expand Down Expand Up @@ -223,7 +223,7 @@ SrsHlsMuxer::SrsHlsMuxer()
max_td = 0;
_sequence_no = 0;
current = NULL;
acodec = SrsCodecAudioReserved1;
acodec = SrsAudioCodecIdReserved1;
async = new SrsAsyncCallWorker();
context = new SrsTsContext();
}
Expand Down Expand Up @@ -361,32 +361,32 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts)
srs_assert(!current);

// load the default acodec from config.
SrsCodecAudio default_acodec = SrsCodecAudioAAC;
SrsAudioCodecId default_acodec = SrsAudioCodecIdAAC;
if (true) {
std::string default_acodec_str = _srs_config->get_hls_acodec(req->vhost);
if (default_acodec_str == "mp3") {
default_acodec = SrsCodecAudioMP3;
default_acodec = SrsAudioCodecIdMP3;
srs_info("hls: use default mp3 acodec");
} else if (default_acodec_str == "aac") {
default_acodec = SrsCodecAudioAAC;
default_acodec = SrsAudioCodecIdAAC;
srs_info("hls: use default aac acodec");
} else if (default_acodec_str == "an") {
default_acodec = SrsCodecAudioDisabled;
default_acodec = SrsAudioCodecIdDisabled;
srs_info("hls: use default an acodec for pure video");
} else {
srs_warn("hls: use aac for other codec=%s", default_acodec_str.c_str());
}
}

// load the default vcodec from config.
SrsCodecVideo default_vcodec = SrsCodecVideoAVC;
SrsVideoCodecId default_vcodec = SrsVideoCodecIdAVC;
if (true) {
std::string default_vcodec_str = _srs_config->get_hls_vcodec(req->vhost);
if (default_vcodec_str == "h264") {
default_vcodec = SrsCodecVideoAVC;
default_vcodec = SrsVideoCodecIdAVC;
srs_info("hls: use default h264 vcodec");
} else if (default_vcodec_str == "vn") {
default_vcodec = SrsCodecVideoDisabled;
default_vcodec = SrsVideoCodecIdDisabled;
srs_info("hls: use default vn vcodec for pure audio");
} else {
srs_warn("hls: use h264 for other codec=%s", default_vcodec_str.c_str());
Expand Down Expand Up @@ -483,7 +483,7 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts)

// set the segment muxer audio codec.
// TODO: FIXME: refine code, use event instead.
if (acodec != SrsCodecAudioReserved1) {
if (acodec != SrsAudioCodecIdReserved1) {
current->muxer->update_acodec(acodec);
}

Expand Down Expand Up @@ -543,7 +543,7 @@ bool SrsHlsMuxer::is_segment_absolutely_overflow()
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->muxer);
Expand All @@ -553,7 +553,7 @@ int SrsHlsMuxer::update_acodec(SrsCodecAudio ac)

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)
Expand Down Expand Up @@ -863,7 +863,7 @@ void SrsHlsController::dispose()
muxer->dispose();
}

int SrsHlsController::update_acodec(SrsCodecAudio ac)
int SrsHlsController::update_acodec(SrsAudioCodecId ac)
{
return muxer->update_acodec(ac);
}
Expand Down Expand Up @@ -1020,7 +1020,7 @@ int SrsHlsController::write_video(SrsVideoFrame* frame, int64_t dts)
// do reap ts if any of:
// a. wait keyframe and got 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.
if ((ret = reap_segment("video", ts->video->dts)) != ERROR_SUCCESS) {
return ret;
Expand Down Expand Up @@ -1216,8 +1216,8 @@ int SrsHls::on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* format)

// ts support audio codec: aac/mp3
srs_assert(format->acodec);
SrsCodecAudio acodec = format->acodec->id;
if (acodec != SrsCodecAudioAAC && acodec != SrsCodecAudioMP3) {
SrsAudioCodecId acodec = format->acodec->id;
if (acodec != SrsAudioCodecIdAAC && acodec != SrsAudioCodecIdMP3) {
return ret;
}

Expand All @@ -1229,7 +1229,7 @@ int SrsHls::on_audio(SrsSharedPtrMessage* shared_audio, SrsFormat* format)

// ignore sequence header
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();
}

Expand Down Expand Up @@ -1270,17 +1270,17 @@ int SrsHls::on_video(SrsSharedPtrMessage* shared_video, SrsFormat* format)
// ignore info frame,
// @see https://github.com/ossrs/srs/issues/288#issuecomment-69863909
srs_assert(format->video);
if (format->video->frame_type == SrsCodecVideoAVCFrameVideoInfoFrame) {
if (format->video->frame_type == SrsVideoAvcFrameTypeVideoInfoFrame) {
return ret;
}

srs_assert(format->vcodec);
if (format->vcodec->id != SrsCodecVideoAVC) {
if (format->vcodec->id != SrsVideoCodecIdAVC) {
return ret;
}

// ignore sequence header
if (format->video->avc_packet_type == SrsCodecVideoAVCTypeSequenceHeader) {
if (format->video->avc_packet_type == SrsVideoAvcFrameTraitSequenceHeader) {
return controller->on_sequence_header();
}

Expand Down
8 changes: 4 additions & 4 deletions trunk/src/app/srs_app_hls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class SrsHlsSegment
// whether current segement is sequence header.
bool is_sequence_header;
public:
SrsHlsSegment(SrsTsContext* c, SrsCodecAudio ac, SrsCodecVideo vc);
SrsHlsSegment(SrsTsContext* c, SrsAudioCodecId ac, SrsVideoCodecId vc);
virtual ~SrsHlsSegment();
public:
/**
Expand Down Expand Up @@ -179,7 +179,7 @@ class SrsHlsMuxer
* set the muxer audio codec.
* @see https://github.com/ossrs/srs/issues/301
*/
SrsCodecAudio acodec;
SrsAudioCodecId acodec;
/**
* the ts context, to keep cc continous between ts.
* @see https://github.com/ossrs/srs/issues/375
Expand Down Expand Up @@ -230,7 +230,7 @@ class SrsHlsMuxer
*/
virtual bool is_segment_absolutely_overflow();
public:
virtual int update_acodec(SrsCodecAudio ac);
virtual int update_acodec(SrsAudioCodecId ac);
/**
* whether current hls muxer is pure audio mode.
*/
Expand Down Expand Up @@ -278,7 +278,7 @@ class SrsHlsController
public:
virtual int initialize();
virtual void dispose();
virtual int update_acodec(SrsCodecAudio ac);
virtual int update_acodec(SrsAudioCodecId ac);
virtual int sequence_no();
virtual std::string ts_url();
virtual double duration();
Expand Down
2 changes: 1 addition & 1 deletion trunk/src/app/srs_app_http_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
return enc->write_metadata(SrsCodecFlvTagScript, data, size);
return enc->write_metadata(SrsFrameTypeScript, data, size);
}

bool SrsFlvStreamEncoder::has_cache()
Expand Down
16 changes: 8 additions & 8 deletions trunk/src/app/srs_app_mpegts_udp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ int SrsMpegtsOverUdp::write_h264_sps_pps(uint32_t dts, uint32_t pts)
}

// h264 packet to flv packet.
int8_t frame_type = SrsCodecVideoAVCFrameKeyFrame;
int8_t avc_packet_type = SrsCodecVideoAVCTypeSequenceHeader;
int8_t frame_type = SrsVideoAvcFrameTypeKeyFrame;
int8_t avc_packet_type = SrsVideoAvcFrameTraitSequenceHeader;
char* flv = NULL;
int nb_flv = 0;
if ((ret = avc->mux_avc2flv(sh, frame_type, avc_packet_type, dts, pts, &flv, &nb_flv)) != ERROR_SUCCESS) {
Expand All @@ -448,7 +448,7 @@ int SrsMpegtsOverUdp::write_h264_sps_pps(uint32_t dts, uint32_t pts)

// the timestamp in rtmp message header is 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;
}

Expand Down Expand Up @@ -476,17 +476,17 @@ int SrsMpegtsOverUdp::write_h264_ipb_frame(char* frame, int frame_size, uint32_t
SrsAvcNaluType nal_unit_type = (SrsAvcNaluType)(frame[0] & 0x1f);

// for IDR frame, the frame is keyframe.
SrsCodecVideoAVCFrame frame_type = SrsCodecVideoAVCFrameInterFrame;
SrsVideoAvcFrameType frame_type = SrsVideoAvcFrameTypeInterFrame;
if (nal_unit_type == SrsAvcNaluTypeIDR) {
frame_type = SrsCodecVideoAVCFrameKeyFrame;
frame_type = SrsVideoAvcFrameTypeKeyFrame;
}

std::string ibp;
if ((ret = avc->mux_ipb_frame(frame, frame_size, ibp)) != ERROR_SUCCESS) {
return ret;
}

int8_t avc_packet_type = SrsCodecVideoAVCTypeNALU;
int8_t avc_packet_type = SrsVideoAvcFrameTraitNALU;
char* flv = NULL;
int nb_flv = 0;
if ((ret = avc->mux_avc2flv(ibp, frame_type, avc_packet_type, dts, pts, &flv, &nb_flv)) != ERROR_SUCCESS) {
Expand All @@ -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.
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)
Expand Down Expand Up @@ -561,7 +561,7 @@ int SrsMpegtsOverUdp::write_audio_raw_frame(char* frame, int frame_size, SrsRawA
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)
Expand Down
Loading

0 comments on commit caf69f1

Please sign in to comment.