Skip to content

Commit

Permalink
for ossrs#293, add http ts stream framework.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Jan 22, 2015
1 parent 0f59073 commit 77d78ea
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 5 deletions.
63 changes: 60 additions & 3 deletions trunk/src/kernel/srs_kernel_ts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,20 @@ using namespace std;

#include <srs_kernel_log.hpp>
#include <srs_kernel_error.hpp>
#include <srs_kernel_stream.hpp>
#include <srs_kernel_file.hpp>
#include <srs_kernel_avc.hpp>

SrsTsEncoder::SrsTsEncoder()
{
_fs = NULL;
tag_stream = new SrsStream();
codec = new SrsAvcAacCodec();
sample = new SrsCodecSample();
}

SrsTsEncoder::~SrsTsEncoder()
{
srs_freep(tag_stream);
srs_freep(codec);
srs_freep(sample);
}

int SrsTsEncoder::initialize(SrsFileWriter* fs)
Expand All @@ -68,12 +70,67 @@ int SrsTsEncoder::initialize(SrsFileWriter* fs)
int SrsTsEncoder::write_audio(int64_t timestamp, char* data, int size)
{
int ret = ERROR_SUCCESS;

sample->clear();
if ((ret = codec->audio_aac_demux(data, size, sample)) != ERROR_SUCCESS) {
srs_error("http: ts codec demux audio failed. ret=%d", ret);
return ret;
}

if (codec->audio_codec_id != SrsCodecAudioAAC) {
return ret;
}

// ignore sequence header
if (sample->aac_packet_type == SrsCodecAudioTypeSequenceHeader) {
return ret;
}

// the dts calc from rtmp/flv header.
// @remark for http ts stream, the timestamp is always monotonically increase,
// for the packet is filtered by consumer.
int64_t dts = timestamp * 90;

/*if ((ret = hls_cache->write_audio(codec, muxer, dts, sample)) != ERROR_SUCCESS) {
srs_error("http: ts cache write audio failed. ret=%d", ret);
return ret;
}*/

return ret;
}

int SrsTsEncoder::write_video(int64_t timestamp, char* data, int size)
{
int ret = ERROR_SUCCESS;

sample->clear();
if ((ret = codec->video_avc_demux(data, size, sample)) != ERROR_SUCCESS) {
srs_error("http: ts codec demux video failed. ret=%d", ret);
return ret;
}

// ignore info frame,
// @see https://github.com/winlinvip/simple-rtmp-server/issues/288#issuecomment-69863909
if (sample->frame_type == SrsCodecVideoAVCFrameVideoInfoFrame) {
return ret;
}

if (codec->video_codec_id != SrsCodecVideoAVC) {
return ret;
}

// ignore sequence header
if (sample->frame_type == SrsCodecVideoAVCFrameKeyFrame
&& sample->avc_packet_type == SrsCodecVideoAVCTypeSequenceHeader) {
return ret;
}

int64_t dts = timestamp * 90;
/*if ((ret = hls_cache->write_video(codec, muxer, dts, sample)) != ERROR_SUCCESS) {
srs_error("http: ts cache write video failed. ret=%d", ret);
return ret;
}*/

return ret;
}

Expand Down
6 changes: 4 additions & 2 deletions trunk/src/kernel/srs_kernel_ts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#include <string>

class SrsStream;
class SrsFileWriter;
class SrsFileReader;
class SrsAvcAacCodec;
class SrsCodecSample;

/**
* encode data to ts file.
Expand All @@ -43,7 +44,8 @@ class SrsTsEncoder
private:
SrsFileWriter* _fs;
private:
SrsStream* tag_stream;
SrsAvcAacCodec* codec;
SrsCodecSample* sample;
public:
SrsTsEncoder();
virtual ~SrsTsEncoder();
Expand Down

0 comments on commit 77d78ea

Please sign in to comment.