mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
add ts muxer to write hls/ts file
This commit is contained in:
parent
3623af8ae4
commit
4af3982721
6 changed files with 94 additions and 6 deletions
|
@ -223,7 +223,7 @@ int SrsClient::check_vhost()
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsConfDirective* conf = NULL;
|
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;
|
ret = ERROR_RTMP_VHOST_NOT_FOUND;
|
||||||
srs_error("vhost %s disabled. ret=%d", req->vhost.c_str(), ret);
|
srs_error("vhost %s disabled. ret=%d", req->vhost.c_str(), ret);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -336,7 +336,7 @@ int SrsClient::publish(SrsSource* source, bool is_fmle)
|
||||||
SrsHLS* hls = source->get_hls();
|
SrsHLS* hls = source->get_hls();
|
||||||
|
|
||||||
// notify the hls to prepare when publish start.
|
// 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);
|
srs_error("hls on_publish failed. ret=%d", ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -551,6 +551,17 @@ SrsConfDirective* SrsConfig::get_vhost(std::string vhost)
|
||||||
return NULL;
|
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* SrsConfig::get_gop_cache(std::string vhost)
|
||||||
{
|
{
|
||||||
SrsConfDirective* conf = get_vhost(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);
|
"directive \"listen\" is empty, ret=%d", (conf? conf->conf_line:0), ret);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
// TODO: check the hls.
|
||||||
|
// TODO: check other config.
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,8 +37,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
// default vhost for rtmp
|
// default vhost for rtmp
|
||||||
#define RTMP_VHOST_DEFAULT "__defaultVhost__"
|
#define RTMP_VHOST_DEFAULT "__defaultVhost__"
|
||||||
|
|
||||||
// conf node: enabled.
|
#define SRS_CONF_DEFAULT_HLS_PATH "./hls"
|
||||||
#define RTMP_VHOST_ENABLED "enabled"
|
|
||||||
|
|
||||||
class SrsFileBuffer
|
class SrsFileBuffer
|
||||||
{
|
{
|
||||||
|
@ -108,6 +107,7 @@ public:
|
||||||
public:
|
public:
|
||||||
virtual int parse_options(int argc, char** argv);
|
virtual int parse_options(int argc, char** argv);
|
||||||
virtual SrsConfDirective* get_vhost(std::string vhost);
|
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_gop_cache(std::string vhost);
|
||||||
virtual SrsConfDirective* get_hls(std::string vhost);
|
virtual SrsConfDirective* get_hls(std::string vhost);
|
||||||
virtual SrsConfDirective* get_hls_path(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_METADATA 600
|
||||||
#define ERROR_HLS_DECODE_ERROR 601
|
#define ERROR_HLS_DECODE_ERROR 601
|
||||||
|
#define ERROR_HLS_BUSY 602
|
||||||
|
|
||||||
#endif
|
#endif
|
|
@ -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_codec.hpp>
|
||||||
#include <srs_core_amf0.hpp>
|
#include <srs_core_amf0.hpp>
|
||||||
#include <srs_core_protocol.hpp>
|
#include <srs_core_protocol.hpp>
|
||||||
|
#include <srs_core_config.hpp>
|
||||||
|
|
||||||
SrsHLS::SrsHLS()
|
SrsHLS::SrsHLS()
|
||||||
{
|
{
|
||||||
|
hls_enabled = false;
|
||||||
codec = new SrsCodec();
|
codec = new SrsCodec();
|
||||||
sample = new SrsCodecSample();
|
sample = new SrsCodecSample();
|
||||||
|
muxer = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
SrsHLS::~SrsHLS()
|
SrsHLS::~SrsHLS()
|
||||||
{
|
{
|
||||||
srs_freep(codec);
|
srs_freep(codec);
|
||||||
srs_freep(sample);
|
srs_freep(sample);
|
||||||
|
srs_freep(muxer);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsHLS::on_publish()
|
int SrsHLS::on_publish(std::string _vhost)
|
||||||
{
|
{
|
||||||
int ret = ERROR_SUCCESS;
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SrsHLS::on_unpublish()
|
void SrsHLS::on_unpublish()
|
||||||
{
|
{
|
||||||
|
hls_enabled = false;
|
||||||
|
srs_freep(muxer);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsHLS::on_meta_data(SrsOnMetaDataPacket* metadata)
|
int SrsHLS::on_meta_data(SrsOnMetaDataPacket* metadata)
|
||||||
|
@ -145,6 +180,11 @@ int SrsHLS::on_audio(SrsCommonMessage* audio)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: maybe donot need to demux the aac?
|
||||||
|
if (!hls_enabled) {
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,6 +201,25 @@ int SrsHLS::on_video(SrsCommonMessage* video)
|
||||||
return ret;
|
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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,25 +29,40 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
*/
|
*/
|
||||||
#include <srs_core.hpp>
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
class SrsOnMetaDataPacket;
|
class SrsOnMetaDataPacket;
|
||||||
class SrsCommonMessage;
|
class SrsCommonMessage;
|
||||||
class SrsCodecSample;
|
class SrsCodecSample;
|
||||||
|
class SrsTSMuxer;
|
||||||
class SrsCodec;
|
class SrsCodec;
|
||||||
|
|
||||||
class SrsHLS
|
class SrsHLS
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
std::string vhost;
|
||||||
|
bool hls_enabled;
|
||||||
SrsCodec* codec;
|
SrsCodec* codec;
|
||||||
SrsCodecSample* sample;
|
SrsCodecSample* sample;
|
||||||
|
SrsTSMuxer* muxer;
|
||||||
public:
|
public:
|
||||||
SrsHLS();
|
SrsHLS();
|
||||||
virtual ~SrsHLS();
|
virtual ~SrsHLS();
|
||||||
public:
|
public:
|
||||||
virtual int on_publish();
|
virtual int on_publish(std::string _vhost);
|
||||||
virtual void on_unpublish();
|
virtual void on_unpublish();
|
||||||
virtual int on_meta_data(SrsOnMetaDataPacket* metadata);
|
virtual int on_meta_data(SrsOnMetaDataPacket* metadata);
|
||||||
virtual int on_audio(SrsCommonMessage* audio);
|
virtual int on_audio(SrsCommonMessage* audio);
|
||||||
virtual int on_video(SrsCommonMessage* video);
|
virtual int on_video(SrsCommonMessage* video);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class SrsTSMuxer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SrsTSMuxer();
|
||||||
|
virtual ~SrsTSMuxer();
|
||||||
|
public:
|
||||||
|
virtual int open(std::string path);
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
Add table
Add a link
Reference in a new issue