Skip to content

Commit

Permalink
for #299, refine the encoder object name
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Feb 12, 2017
1 parent 2a4f57a commit 2fcd397
Show file tree
Hide file tree
Showing 17 changed files with 152 additions and 158 deletions.
4 changes: 2 additions & 2 deletions trunk/src/app/srs_app_dvr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ int SrsDvrSegmenter::on_reload_vhost_dvr(std::string vhost)

SrsDvrFlvSegmenter::SrsDvrFlvSegmenter()
{
enc = new SrsFlvEncoder();
enc = new SrsFlvTransmuxer();

duration_offset = 0;
filesize_offset = 0;
Expand Down Expand Up @@ -357,7 +357,7 @@ int SrsDvrFlvSegmenter::open_encoder()
filesize_offset = 0;

srs_freep(enc);
enc = new SrsFlvEncoder();
enc = new SrsFlvTransmuxer();

if ((ret = enc->initialize(fs)) != ERROR_SUCCESS) {
return ret;
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/app/srs_app_dvr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SrsBuffer;
class SrsRtmpJitter;
class SrsSharedPtrMessage;
class SrsFileWriter;
class SrsFlvEncoder;
class SrsFlvTransmuxer;
class SrsDvrPlan;
class SrsJsonAny;
class SrsJsonObject;
Expand Down Expand Up @@ -129,7 +129,7 @@ class SrsDvrFlvSegmenter : public SrsDvrSegmenter
{
private:
// The FLV encoder, for FLV target.
SrsFlvEncoder* enc;
SrsFlvTransmuxer* enc;
private:
// The offset of file for duration value.
// The next 8 bytes is the double value.
Expand Down
46 changes: 23 additions & 23 deletions trunk/src/app/srs_app_hls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ SrsHlsSegment::SrsHlsSegment(SrsTsContext* c, SrsAudioCodecId ac, SrsVideoCodecI
segment_start_dts = 0;
is_sequence_header = false;
writer = new SrsFileWriter();
muxer = new SrsTsMuxer(writer, c, ac, vc);
tscw = new SrsTsContextWriter(writer, c, ac, vc);
}

SrsHlsSegment::~SrsHlsSegment()
{
srs_freep(muxer);
srs_freep(tscw);
srs_freep(writer);
}

Expand Down Expand Up @@ -473,7 +473,7 @@ int SrsHlsMuxer::segment_open(int64_t segment_start_dts)

// open temp ts file.
std::string tmp_file = current->full_path + ".tmp";
if ((ret = current->muxer->open(tmp_file.c_str())) != ERROR_SUCCESS) {
if ((ret = current->tscw->open(tmp_file.c_str())) != ERROR_SUCCESS) {
srs_error("open hls muxer failed. ret=%d", ret);
return ret;
}
Expand Down Expand Up @@ -537,10 +537,10 @@ bool SrsHlsMuxer::is_segment_absolutely_overflow()

bool SrsHlsMuxer::pure_audio()
{
return current && current->muxer && current->muxer->video_codec() == SrsVideoCodecIdDisabled;
return current && current->tscw && current->tscw->video_codec() == SrsVideoCodecIdDisabled;
}

int SrsHlsMuxer::flush_audio(SrsTsCache* cache)
int SrsHlsMuxer::flush_audio(SrsTsMessageCache* cache)
{
int ret = ERROR_SUCCESS;

Expand All @@ -557,7 +557,7 @@ int SrsHlsMuxer::flush_audio(SrsTsCache* cache)
// update the duration of segment.
current->update_duration(cache->audio->pts);

if ((ret = current->muxer->write_audio(cache->audio)) != ERROR_SUCCESS) {
if ((ret = current->tscw->write_audio(cache->audio)) != ERROR_SUCCESS) {
return ret;
}

Expand All @@ -567,7 +567,7 @@ int SrsHlsMuxer::flush_audio(SrsTsCache* cache)
return ret;
}

int SrsHlsMuxer::flush_video(SrsTsCache* cache)
int SrsHlsMuxer::flush_video(SrsTsMessageCache* cache)
{
int ret = ERROR_SUCCESS;

Expand All @@ -586,7 +586,7 @@ int SrsHlsMuxer::flush_video(SrsTsCache* cache)
// update the duration of segment.
current->update_duration(cache->video->dts);

if ((ret = current->muxer->write_video(cache->video)) != ERROR_SUCCESS) {
if ((ret = current->tscw->write_video(cache->video)) != ERROR_SUCCESS) {
return ret;
}

Expand Down Expand Up @@ -639,7 +639,7 @@ int SrsHlsMuxer::segment_close(string log_desc)
current->segment_start_dts);

// close the muxer of finished segment.
srs_freep(current->muxer);
srs_freep(current->tscw);
std::string full_path = current->full_path;
current = NULL;

Expand Down Expand Up @@ -827,14 +827,14 @@ int SrsHlsMuxer::_refresh_m3u8(string m3u8_file)

SrsHlsController::SrsHlsController()
{
ts = new SrsTsCache();
tsmc = new SrsTsMessageCache();
muxer = new SrsHlsMuxer();
}

SrsHlsController::~SrsHlsController()
{
srs_freep(muxer);
srs_freep(ts);
srs_freep(tsmc);
}

int SrsHlsController::initialize()
Expand Down Expand Up @@ -920,7 +920,7 @@ int SrsHlsController::on_unpublish()
{
int ret = ERROR_SUCCESS;

if ((ret = muxer->flush_audio(ts)) != ERROR_SUCCESS) {
if ((ret = muxer->flush_audio(tsmc)) != ERROR_SUCCESS) {
srs_error("m3u8 muxer flush audio failed. ret=%d", ret);
return ret;
}
Expand Down Expand Up @@ -948,7 +948,7 @@ int SrsHlsController::write_audio(SrsAudioFrame* frame, int64_t pts)
int ret = ERROR_SUCCESS;

// write audio to cache.
if ((ret = ts->cache_audio(frame, pts)) != ERROR_SUCCESS) {
if ((ret = tsmc->cache_audio(frame, pts)) != ERROR_SUCCESS) {
return ret;
}

Expand All @@ -960,16 +960,16 @@ int SrsHlsController::write_audio(SrsAudioFrame* frame, int64_t pts)
// @see https://github.com/ossrs/srs/issues/151
// we use absolutely overflow of segment to make jwplayer/ffplay happy
// @see https://github.com/ossrs/srs/issues/151#issuecomment-71155184
if (ts->audio && muxer->is_segment_absolutely_overflow()) {
if (tsmc->audio && muxer->is_segment_absolutely_overflow()) {
srs_info("hls: absolute audio reap segment.");
if ((ret = reap_segment("audio", ts->audio->pts)) != ERROR_SUCCESS) {
if ((ret = reap_segment("audio", tsmc->audio->pts)) != ERROR_SUCCESS) {
return ret;
}
}

// for pure audio, aggregate some frame to one.
if (muxer->pure_audio() &&ts->audio) {
if (pts - ts->audio->start_pts < SRS_CONSTS_HLS_PURE_AUDIO_AGGREGATE) {
if (muxer->pure_audio() && tsmc->audio) {
if (pts - tsmc->audio->start_pts < SRS_CONSTS_HLS_PURE_AUDIO_AGGREGATE) {
return ret;
}
}
Expand All @@ -978,7 +978,7 @@ int SrsHlsController::write_audio(SrsAudioFrame* frame, int64_t pts)
// it's ok for the hls overload, or maybe cause the audio corrupt,
// which introduced by aggregate the audios to a big one.
// @see https://github.com/ossrs/srs/issues/512
if ((ret = muxer->flush_audio(ts)) != ERROR_SUCCESS) {
if ((ret = muxer->flush_audio(tsmc)) != ERROR_SUCCESS) {
return ret;
}

Expand All @@ -990,7 +990,7 @@ int SrsHlsController::write_video(SrsVideoFrame* frame, int64_t dts)
int ret = ERROR_SUCCESS;

// write video to cache.
if ((ret = ts->cache_video(frame, dts)) != ERROR_SUCCESS) {
if ((ret = tsmc->cache_video(frame, dts)) != ERROR_SUCCESS) {
return ret;
}

Expand All @@ -1001,14 +1001,14 @@ int SrsHlsController::write_video(SrsVideoFrame* frame, int64_t dts)
// b. always reap when not wait keyframe.
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) {
if ((ret = reap_segment("video", tsmc->video->dts)) != ERROR_SUCCESS) {
return ret;
}
}
}

// flush video when got one
if ((ret = muxer->flush_video(ts)) != ERROR_SUCCESS) {
if ((ret = muxer->flush_video(tsmc)) != ERROR_SUCCESS) {
srs_error("m3u8 muxer flush video failed. ret=%d", ret);
return ret;
}
Expand Down Expand Up @@ -1036,15 +1036,15 @@ int SrsHlsController::reap_segment(string log_desc, int64_t segment_start_dts)
}

// segment open, flush video first.
if ((ret = muxer->flush_video(ts)) != ERROR_SUCCESS) {
if ((ret = muxer->flush_video(tsmc)) != ERROR_SUCCESS) {
srs_error("m3u8 muxer flush video failed. ret=%d", ret);
return ret;
}

// segment open, flush the audio.
// @see: ngx_rtmp_hls_open_fragment
/* start fragment with audio to make iPhone happy */
if ((ret = muxer->flush_audio(ts)) != ERROR_SUCCESS) {
if ((ret = muxer->flush_audio(tsmc)) != ERROR_SUCCESS) {
srs_error("m3u8 muxer flush audio failed. ret=%d", ret);
return ret;
}
Expand Down
18 changes: 9 additions & 9 deletions trunk/src/app/srs_app_hls.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,16 @@ class SrsFormat;
class SrsSharedPtrMessage;
class SrsAmf0Object;
class SrsRtmpJitter;
class SrsTsMuxer;
class SrsTsContextWriter;
class SrsRequest;
class SrsPithyPrint;
class SrsSource;
class SrsOriginHub;
class SrsFileWriter;
class SrsSimpleStream;
class SrsTsAacJitter;
class SrsTsCache;
class SrsTsMessageCache;
class SrsHlsSegment;
class SrsTsCache;
class SrsTsContext;

/**
Expand All @@ -70,9 +69,10 @@ class SrsHlsSegment
std::string uri;
// ts full file to write.
std::string full_path;
// the muxer to write ts.
// the underlayer file writer.
SrsFileWriter* writer;
SrsTsMuxer* muxer;
// The TS context writer to write TS to file.
SrsTsContextWriter* tscw;
// current segment start dts for m3u8
int64_t segment_start_dts;
// whether current segement is sequence header.
Expand Down Expand Up @@ -228,8 +228,8 @@ class SrsHlsMuxer
* whether current hls muxer is pure audio mode.
*/
virtual bool pure_audio();
virtual int flush_audio(SrsTsCache* cache);
virtual int flush_video(SrsTsCache* cache);
virtual int flush_audio(SrsTsMessageCache* cache);
virtual int flush_video(SrsTsMessageCache* cache);
/**
* close segment(ts).
* @param log_desc the description for log.
Expand Down Expand Up @@ -261,10 +261,10 @@ class SrsHlsController
{
private:
// The HLS muxer to reap ts and m3u8.
// The TS is cached to SrsTsCache then flush to ts segment.
// The TS is cached to SrsTsMessageCache then flush to ts segment.
SrsHlsMuxer* muxer;
// The TS cache
SrsTsCache* ts;
SrsTsMessageCache* tsmc;
public:
SrsHlsController();
virtual ~SrsHlsController();
Expand Down
4 changes: 0 additions & 4 deletions trunk/src/app/srs_app_http_conn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ class SrsSource;
class SrsRequest;
class SrsConsumer;
class SrsStSocket;
class SrsTsEncoder;
class SrsAacEncoder;
class SrsMp3Encoder;
class SrsFlvEncoder;
class SrsHttpParser;
class ISrsHttpMessage;
class SrsHttpHandler;
Expand Down
8 changes: 4 additions & 4 deletions trunk/src/app/srs_app_http_stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ ISrsBufferEncoder::~ISrsBufferEncoder()

SrsTsStreamEncoder::SrsTsStreamEncoder()
{
enc = new SrsTsEncoder();
enc = new SrsTsTransmuxer();
}

SrsTsStreamEncoder::~SrsTsStreamEncoder()
Expand Down Expand Up @@ -230,7 +230,7 @@ int SrsTsStreamEncoder::dump_cache(SrsConsumer* /*consumer*/, SrsRtmpJitterAlgor

SrsFlvStreamEncoder::SrsFlvStreamEncoder()
{
enc = new SrsFlvEncoder();
enc = new SrsFlvTransmuxer();
}

SrsFlvStreamEncoder::~SrsFlvStreamEncoder()
Expand Down Expand Up @@ -298,7 +298,7 @@ int SrsFastFlvStreamEncoder::write_tags(SrsSharedPtrMessage** msgs, int count)

SrsAacStreamEncoder::SrsAacStreamEncoder()
{
enc = new SrsAacEncoder();
enc = new SrsAacTransmuxer();
cache = NULL;
}

Expand Down Expand Up @@ -350,7 +350,7 @@ int SrsAacStreamEncoder::dump_cache(SrsConsumer* consumer, SrsRtmpJitterAlgorith

SrsMp3StreamEncoder::SrsMp3StreamEncoder()
{
enc = new SrsMp3Encoder();
enc = new SrsMp3Transmuxer();
cache = NULL;
}

Expand Down
14 changes: 10 additions & 4 deletions trunk/src/app/srs_app_http_stream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#include <srs_app_http_conn.hpp>

class SrsAacTransmuxer;
class SrsMp3Transmuxer;
class SrsFlvTransmuxer;
class SrsTsTransmuxer;

/**
* for the srs http stream cache,
* for example, the audio stream cache to make android(weixin) happy.
Expand Down Expand Up @@ -98,7 +103,7 @@ class ISrsBufferEncoder
class SrsFlvStreamEncoder : public ISrsBufferEncoder
{
protected:
SrsFlvEncoder* enc;
SrsFlvTransmuxer* enc;
public:
SrsFlvStreamEncoder();
virtual ~SrsFlvStreamEncoder();
Expand Down Expand Up @@ -136,7 +141,7 @@ class SrsFastFlvStreamEncoder : public SrsFlvStreamEncoder
class SrsTsStreamEncoder : public ISrsBufferEncoder
{
private:
SrsTsEncoder* enc;
SrsTsTransmuxer* enc;
public:
SrsTsStreamEncoder();
virtual ~SrsTsStreamEncoder();
Expand All @@ -156,7 +161,7 @@ class SrsTsStreamEncoder : public ISrsBufferEncoder
class SrsAacStreamEncoder : public ISrsBufferEncoder
{
private:
SrsAacEncoder* enc;
SrsAacTransmuxer* enc;
SrsBufferCache* cache;
public:
SrsAacStreamEncoder();
Expand All @@ -177,7 +182,7 @@ class SrsAacStreamEncoder : public ISrsBufferEncoder
class SrsMp3StreamEncoder : public ISrsBufferEncoder
{
private:
SrsMp3Encoder* enc;
SrsMp3Transmuxer* enc;
SrsBufferCache* cache;
public:
SrsMp3StreamEncoder();
Expand Down Expand Up @@ -266,6 +271,7 @@ struct SrsLiveEntry
* the http stream server instance,
* serve http stream, for example, flv/ts/mp3/aac live stream.
*/
// TODO: Support multiple stream.
class SrsHttpStreamServer : virtual public ISrsReloadHandler
, virtual public ISrsHttpMatchHijacker
{
Expand Down
Loading

0 comments on commit 2fcd397

Please sign in to comment.