winlin

add ts muxer to write hls/ts file

... ... @@ -223,7 +223,7 @@ int SrsClient::check_vhost()
}
SrsConfDirective* conf = NULL;
if ((conf = vhost->get(RTMP_VHOST_ENABLED)) != NULL && conf->arg0() != "on") {
if ((conf = config->get_vhost_enabled(req->vhost)) != NULL && conf->arg0() != "on") {
ret = ERROR_RTMP_VHOST_NOT_FOUND;
srs_error("vhost %s disabled. ret=%d", req->vhost.c_str(), ret);
return ret;
... ... @@ -336,7 +336,7 @@ int SrsClient::publish(SrsSource* source, bool is_fmle)
SrsHLS* hls = source->get_hls();
// notify the hls to prepare when publish start.
if ((ret = hls->on_publish()) != ERROR_SUCCESS) {
if ((ret = hls->on_publish(req->vhost)) != ERROR_SUCCESS) {
srs_error("hls on_publish failed. ret=%d", ret);
return ret;
}
... ...
... ... @@ -551,6 +551,17 @@ SrsConfDirective* SrsConfig::get_vhost(std::string vhost)
return NULL;
}
SrsConfDirective* SrsConfig::get_vhost_enabled(std::string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return NULL;
}
return conf->get("enabled");
}
SrsConfDirective* SrsConfig::get_gop_cache(std::string vhost)
{
SrsConfDirective* conf = get_vhost(vhost);
... ... @@ -668,6 +679,8 @@ int SrsConfig::parse_file(const char* filename)
"directive \"listen\" is empty, ret=%d", (conf? conf->conf_line:0), ret);
return ret;
}
// TODO: check the hls.
// TODO: check other config.
return ret;
}
... ...
... ... @@ -37,8 +37,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
// default vhost for rtmp
#define RTMP_VHOST_DEFAULT "__defaultVhost__"
// conf node: enabled.
#define RTMP_VHOST_ENABLED "enabled"
#define SRS_CONF_DEFAULT_HLS_PATH "./hls"
class SrsFileBuffer
{
... ... @@ -108,6 +107,7 @@ public:
public:
virtual int parse_options(int argc, char** argv);
virtual SrsConfDirective* get_vhost(std::string vhost);
virtual SrsConfDirective* get_vhost_enabled(std::string vhost);
virtual SrsConfDirective* get_gop_cache(std::string vhost);
virtual SrsConfDirective* get_hls(std::string vhost);
virtual SrsConfDirective* get_hls_path(std::string vhost);
... ...
... ... @@ -109,5 +109,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#define ERROR_HLS_METADATA 600
#define ERROR_HLS_DECODE_ERROR 601
#define ERROR_HLS_BUSY 602
#endif
\ No newline at end of file
... ...
... ... @@ -27,27 +27,62 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <srs_core_codec.hpp>
#include <srs_core_amf0.hpp>
#include <srs_core_protocol.hpp>
#include <srs_core_config.hpp>
SrsHLS::SrsHLS()
{
hls_enabled = false;
codec = new SrsCodec();
sample = new SrsCodecSample();
muxer = NULL;
}
SrsHLS::~SrsHLS()
{
srs_freep(codec);
srs_freep(sample);
srs_freep(muxer);
}
int SrsHLS::on_publish()
int SrsHLS::on_publish(std::string _vhost)
{
int ret = ERROR_SUCCESS;
if (muxer) {
ret = ERROR_HLS_BUSY;
srs_error("hls is busy, something error, "
"vhost=%s, ret=%d", _vhost.c_str(), ret);
return ret;
}
vhost = _vhost;
muxer = new SrsTSMuxer();
// try to open the HLS muxer
SrsConfDirective* conf = config->get_hls(vhost);
if (!conf && conf->arg0() == "off") {
return ret;
}
hls_enabled = true;
std::string path = SRS_CONF_DEFAULT_HLS_PATH;
if ((conf = config->get_hls_path(vhost)) != NULL) {
path = conf->arg0();
}
if ((ret = muxer->open(path)) != ERROR_SUCCESS) {
srs_error("open hls muxer failed. ret=%d", ret);
return ret;
}
return ret;
}
void SrsHLS::on_unpublish()
{
hls_enabled = false;
srs_freep(muxer);
}
int SrsHLS::on_meta_data(SrsOnMetaDataPacket* metadata)
... ... @@ -145,6 +180,11 @@ int SrsHLS::on_audio(SrsCommonMessage* audio)
return ret;
}
// TODO: maybe donot need to demux the aac?
if (!hls_enabled) {
return ret;
}
return ret;
}
... ... @@ -161,6 +201,25 @@ int SrsHLS::on_video(SrsCommonMessage* video)
return ret;
}
// TODO: maybe donot need to demux the avc?
if (!hls_enabled) {
return ret;
}
return ret;
}
SrsTSMuxer::SrsTSMuxer()
{
}
SrsTSMuxer::~SrsTSMuxer()
{
}
int SrsTSMuxer::open(std::string path)
{
int ret = ERROR_SUCCESS;
return ret;
}
... ...
... ... @@ -29,25 +29,40 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <srs_core.hpp>
#include <string>
class SrsOnMetaDataPacket;
class SrsCommonMessage;
class SrsCodecSample;
class SrsTSMuxer;
class SrsCodec;
class SrsHLS
{
private:
std::string vhost;
bool hls_enabled;
SrsCodec* codec;
SrsCodecSample* sample;
SrsTSMuxer* muxer;
public:
SrsHLS();
virtual ~SrsHLS();
public:
virtual int on_publish();
virtual int on_publish(std::string _vhost);
virtual void on_unpublish();
virtual int on_meta_data(SrsOnMetaDataPacket* metadata);
virtual int on_audio(SrsCommonMessage* audio);
virtual int on_video(SrsCommonMessage* video);
};
class SrsTSMuxer
{
public:
SrsTSMuxer();
virtual ~SrsTSMuxer();
public:
virtual int open(std::string path);
};
#endif
\ No newline at end of file
... ...