Skip to content

Commit

Permalink
For #299, use format for v/a sequence header.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Jun 4, 2017
1 parent 9ca3697 commit 69374c8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 19 deletions.
40 changes: 23 additions & 17 deletions trunk/src/app/srs_app_source.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1279,24 +1279,14 @@ int SrsOriginHub::on_dvr_request_sh()
}

if (cache_sh_video) {
// TODO: Use cached format for sh.
if ((ret = format->on_video(cache_sh_video)) != ERROR_SUCCESS) {
return ret;
}

if ((ret = dvr->on_video(cache_sh_video, format)) != ERROR_SUCCESS) {
if ((ret = dvr->on_video(cache_sh_video, source->meta->vsh_format())) != ERROR_SUCCESS) {
srs_error("dvr process video sequence header message failed. ret=%d", ret);
return ret;
}
}

if (cache_sh_audio) {
// TODO: Use cached format for sh.
if ((ret = format->on_audio(cache_sh_audio)) != ERROR_SUCCESS) {
return ret;
}

if ((ret = dvr->on_audio(cache_sh_audio, format)) != ERROR_SUCCESS) {
if ((ret = dvr->on_audio(cache_sh_audio, source->meta->ash_format())) != ERROR_SUCCESS) {
srs_error("dvr process audio sequence header message failed. ret=%d", ret);
return ret;
}
Expand Down Expand Up @@ -1601,6 +1591,8 @@ void SrsOriginHub::destroy_forwarders()
SrsMetaCache::SrsMetaCache()
{
meta = video = audio = NULL;
vformat = new SrsRtmpFormat();
aformat = new SrsRtmpFormat();
}

SrsMetaCache::~SrsMetaCache()
Expand All @@ -1625,11 +1617,21 @@ SrsSharedPtrMessage* SrsMetaCache::vsh()
return video;
}

SrsFormat* SrsMetaCache::vsh_format()
{
return vformat;
}

SrsSharedPtrMessage* SrsMetaCache::ash()
{
return audio;
}

SrsFormat* SrsMetaCache::ash_format()
{
return aformat;
}

int SrsMetaCache::dumps(SrsConsumer* consumer, bool atc, SrsRtmpJitterAlgorithm ag, bool dm, bool ds)
{
int ret = ERROR_SUCCESS;
Expand Down Expand Up @@ -1728,16 +1730,18 @@ int SrsMetaCache::update_data(SrsMessageHeader* header, SrsOnMetaDataPacket* met
return ret;
}

void SrsMetaCache::update_ash(SrsSharedPtrMessage* msg)
int SrsMetaCache::update_ash(SrsSharedPtrMessage* msg)
{
srs_freep(audio);
audio = msg->copy();
return aformat->on_audio(msg);
}

void SrsMetaCache::update_vsh(SrsSharedPtrMessage* msg)
int SrsMetaCache::update_vsh(SrsSharedPtrMessage* msg)
{
srs_freep(video);
video = msg->copy();
return vformat->on_video(msg);
}

std::map<std::string, SrsSource*> SrsSource::pool;
Expand Down Expand Up @@ -2236,7 +2240,9 @@ int SrsSource::on_audio_imp(SrsSharedPtrMessage* msg)
// for example, the mp3 is used for hls to write the "right" audio codec.
// TODO: FIXME: to refine the stream info system.
if (is_aac_sequence_header || !meta->ash()) {
meta->update_ash(msg);
if ((ret = meta->update_ash(msg)) != ERROR_SUCCESS) {
return ret;
}
}

// when sequence header, donot push to gop cache and adjust the timestamp.
Expand Down Expand Up @@ -2342,8 +2348,8 @@ int SrsSource::on_video_imp(SrsSharedPtrMessage* msg)

// cache the sequence header if h264
// donot cache the sequence header to gop_cache, return here.
if (is_sequence_header) {
meta->update_vsh(msg);
if (is_sequence_header && (ret = meta->update_vsh(msg)) != ERROR_SUCCESS) {
return ret;
}

// Copy to hub to all utilities.
Expand Down
10 changes: 8 additions & 2 deletions trunk/src/app/srs_app_source.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <srs_app_reload.hpp>
#include <srs_core_performance.hpp>

class SrsFormat;
class SrsRtmpFormat;
class SrsConsumer;
class SrsPlayEdge;
Expand Down Expand Up @@ -496,6 +497,9 @@ class SrsMetaCache
SrsSharedPtrMessage* video;
// The cached audio sequence header, for example, asc for aac.
SrsSharedPtrMessage* audio;
// The format for sequence header.
SrsRtmpFormat* vformat;
SrsRtmpFormat* aformat;
public:
SrsMetaCache();
virtual ~SrsMetaCache();
Expand All @@ -507,8 +511,10 @@ class SrsMetaCache
virtual SrsSharedPtrMessage* data();
// Get the cached vsh(video sequence header).
virtual SrsSharedPtrMessage* vsh();
virtual SrsFormat* vsh_format();
// Get the cached ash(audio sequence header).
virtual SrsSharedPtrMessage* ash();
virtual SrsFormat* ash_format();
// Dumps cached metadata to consumer.
// @param dm Whether dumps the metadata.
// @param ds Whether dumps the sequence header.
Expand All @@ -517,9 +523,9 @@ class SrsMetaCache
// Update the cached metadata by packet.
virtual int update_data(SrsMessageHeader* header, SrsOnMetaDataPacket* metadata, bool& updated);
// Update the cached audio sequence header.
virtual void update_ash(SrsSharedPtrMessage* msg);
virtual int update_ash(SrsSharedPtrMessage* msg);
// Update the cached video sequence header.
virtual void update_vsh(SrsSharedPtrMessage* msg);
virtual int update_vsh(SrsSharedPtrMessage* msg);
};

/**
Expand Down

0 comments on commit 69374c8

Please sign in to comment.