mirror of
https://github.com/ossrs/srs.git
synced 2025-03-09 15:49:59 +00:00
Refine get_dash_fragment to time unit
This commit is contained in:
parent
bb6389143f
commit
4302ab7708
10 changed files with 99 additions and 21 deletions
2
trunk/configure
vendored
2
trunk/configure
vendored
|
@ -203,7 +203,7 @@ if [ $SRS_EXPORT_LIBRTMP_PROJECT = NO ]; then
|
||||||
MODULE_ID="SERVICE"
|
MODULE_ID="SERVICE"
|
||||||
MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL")
|
MODULE_DEPENDS=("CORE" "KERNEL" "PROTOCOL")
|
||||||
ModuleLibIncs=(${LibSTRoot} ${SRS_OBJS_DIR} ${LibSSLRoot})
|
ModuleLibIncs=(${LibSTRoot} ${SRS_OBJS_DIR} ${LibSSLRoot})
|
||||||
MODULE_FILES=("srs_service_log" "srs_service_st" "srs_service_http_client"
|
MODULE_FILES=("srs_service_log" "srs_service_time" "srs_service_st" "srs_service_http_client"
|
||||||
"srs_service_http_conn" "srs_service_rtmp_conn" "srs_service_utility"
|
"srs_service_http_conn" "srs_service_rtmp_conn" "srs_service_utility"
|
||||||
"srs_service_conn")
|
"srs_service_conn")
|
||||||
DEFINES=""
|
DEFINES=""
|
||||||
|
|
|
@ -5895,9 +5895,9 @@ bool SrsConfig::get_dash_enabled(string vhost)
|
||||||
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
return SRS_CONF_PERFER_FALSE(conf->arg0());
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsConfig::get_dash_fragment(string vhost)
|
srs_utime_t SrsConfig::get_dash_fragment(string vhost)
|
||||||
{
|
{
|
||||||
static int DEFAULT = 3 * 1000;
|
static int DEFAULT = 3 * SRS_UTIME_SECONDS;
|
||||||
|
|
||||||
SrsConfDirective* conf = get_dash(vhost);
|
SrsConfDirective* conf = get_dash(vhost);
|
||||||
if (!conf) {
|
if (!conf) {
|
||||||
|
@ -5909,7 +5909,7 @@ int SrsConfig::get_dash_fragment(string vhost)
|
||||||
return DEFAULT;
|
return DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (int)(1000 * ::atof(conf->arg0().c_str()));
|
return (srs_utime_t)(::atof(conf->arg0().c_str()) * SRS_UTIME_SECONDS);
|
||||||
}
|
}
|
||||||
|
|
||||||
int SrsConfig::get_dash_update_period(string vhost)
|
int SrsConfig::get_dash_update_period(string vhost)
|
||||||
|
|
|
@ -34,7 +34,7 @@
|
||||||
#include <srs_app_reload.hpp>
|
#include <srs_app_reload.hpp>
|
||||||
#include <srs_app_async_call.hpp>
|
#include <srs_app_async_call.hpp>
|
||||||
#include <srs_app_thread.hpp>
|
#include <srs_app_thread.hpp>
|
||||||
#include <srs_service_st.hpp>
|
#include <srs_service_time.hpp>
|
||||||
|
|
||||||
class SrsRequest;
|
class SrsRequest;
|
||||||
class SrsFileWriter;
|
class SrsFileWriter;
|
||||||
|
@ -1152,7 +1152,7 @@ public:
|
||||||
// Whether DASH is enabled.
|
// Whether DASH is enabled.
|
||||||
virtual bool get_dash_enabled(std::string vhost);
|
virtual bool get_dash_enabled(std::string vhost);
|
||||||
// Get the duration of segment in milliseconds.
|
// Get the duration of segment in milliseconds.
|
||||||
virtual int get_dash_fragment(std::string vhost);
|
virtual srs_utime_t get_dash_fragment(std::string vhost);
|
||||||
// Get the period to update MPD in milliseconds.
|
// Get the period to update MPD in milliseconds.
|
||||||
virtual int get_dash_update_period(std::string vhost);
|
virtual int get_dash_update_period(std::string vhost);
|
||||||
// Get the depth of timeshift buffer in milliseconds.
|
// Get the depth of timeshift buffer in milliseconds.
|
||||||
|
|
|
@ -212,12 +212,12 @@ srs_error_t SrsMpdWriter::write(SrsFormat* format)
|
||||||
<< " xmlns=\"urn:mpeg:dash:schema:mpd:2011\" xmlns:ns1=\"http://www.w3.org/2001/XMLSchema-instance\" " << endl
|
<< " xmlns=\"urn:mpeg:dash:schema:mpd:2011\" xmlns:ns1=\"http://www.w3.org/2001/XMLSchema-instance\" " << endl
|
||||||
<< " type=\"dynamic\" minimumUpdatePeriod=\"PT" << update_period / 1000 << "S\" " << endl
|
<< " type=\"dynamic\" minimumUpdatePeriod=\"PT" << update_period / 1000 << "S\" " << endl
|
||||||
<< " timeShiftBufferDepth=\"PT" << timeshit / 1000 << "S\" availabilityStartTime=\"1970-01-01T00:00:00Z\" " << endl
|
<< " timeShiftBufferDepth=\"PT" << timeshit / 1000 << "S\" availabilityStartTime=\"1970-01-01T00:00:00Z\" " << endl
|
||||||
<< " maxSegmentDuration=\"PT" << fragment / 1000 << "S\" minBufferTime=\"PT" << fragment / 1000 << "S\" >" << endl
|
<< " maxSegmentDuration=\"PT" << fragment / SRS_UTIME_SECONDS << "S\" minBufferTime=\"PT" << fragment / SRS_UTIME_SECONDS << "S\" >" << endl
|
||||||
<< " <BaseURL>" << req->stream << "/" << "</BaseURL>" << endl
|
<< " <BaseURL>" << req->stream << "/" << "</BaseURL>" << endl
|
||||||
<< " <Period start=\"PT0S\">" << endl;
|
<< " <Period start=\"PT0S\">" << endl;
|
||||||
if (format->acodec) {
|
if (format->acodec) {
|
||||||
ss << " <AdaptationSet mimeType=\"audio/mp4\" segmentAlignment=\"true\" startWithSAP=\"1\">" << endl;
|
ss << " <AdaptationSet mimeType=\"audio/mp4\" segmentAlignment=\"true\" startWithSAP=\"1\">" << endl;
|
||||||
ss << " <SegmentTemplate duration=\"" << fragment / 1000 << "\" "
|
ss << " <SegmentTemplate duration=\"" << fragment / SRS_UTIME_SECONDS << "\" "
|
||||||
<< "initialization=\"$RepresentationID$-init.mp4\" "
|
<< "initialization=\"$RepresentationID$-init.mp4\" "
|
||||||
<< "media=\"$RepresentationID$-$Number$.m4s\" />" << endl;
|
<< "media=\"$RepresentationID$-$Number$.m4s\" />" << endl;
|
||||||
ss << " <Representation id=\"audio\" bandwidth=\"48000\" codecs=\"mp4a.40.2\" />" << endl;
|
ss << " <Representation id=\"audio\" bandwidth=\"48000\" codecs=\"mp4a.40.2\" />" << endl;
|
||||||
|
@ -227,7 +227,7 @@ srs_error_t SrsMpdWriter::write(SrsFormat* format)
|
||||||
int w = format->vcodec->width;
|
int w = format->vcodec->width;
|
||||||
int h = format->vcodec->height;
|
int h = format->vcodec->height;
|
||||||
ss << " <AdaptationSet mimeType=\"video/mp4\" segmentAlignment=\"true\" startWithSAP=\"1\">" << endl;
|
ss << " <AdaptationSet mimeType=\"video/mp4\" segmentAlignment=\"true\" startWithSAP=\"1\">" << endl;
|
||||||
ss << " <SegmentTemplate duration=\"" << fragment / 1000 << "\" "
|
ss << " <SegmentTemplate duration=\"" << fragment / SRS_UTIME_SECONDS << "\" "
|
||||||
<< "initialization=\"$RepresentationID$-init.mp4\" "
|
<< "initialization=\"$RepresentationID$-init.mp4\" "
|
||||||
<< "media=\"$RepresentationID$-$Number$.m4s\" />" << endl;
|
<< "media=\"$RepresentationID$-$Number$.m4s\" />" << endl;
|
||||||
ss << " <Representation id=\"video\" bandwidth=\"800000\" codecs=\"avc1.64001e\" "
|
ss << " <Representation id=\"video\" bandwidth=\"800000\" codecs=\"avc1.64001e\" "
|
||||||
|
@ -265,8 +265,8 @@ srs_error_t SrsMpdWriter::get_fragment(bool video, std::string& home, std::strin
|
||||||
|
|
||||||
home = fragment_home;
|
home = fragment_home;
|
||||||
|
|
||||||
sn = srs_update_system_time_ms() / fragment;
|
sn = srs_update_system_time_ms() * SRS_UTIME_MILLISECONDS / fragment;
|
||||||
basetime = sn * fragment;
|
basetime = sn * fragment / SRS_UTIME_MILLISECONDS;
|
||||||
|
|
||||||
if (video) {
|
if (video) {
|
||||||
file_name = "video-" + srs_int2str(sn) + ".m4s";
|
file_name = "video-" + srs_int2str(sn) + ".m4s";
|
||||||
|
@ -335,7 +335,7 @@ srs_error_t SrsDashController::on_audio(SrsSharedPtrMessage* shared_audio, SrsFo
|
||||||
return refresh_init_mp4(shared_audio, format);
|
return refresh_init_mp4(shared_audio, format);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (acurrent->duration() >= fragment) {
|
if (acurrent->duration() >= fragment / SRS_UTIME_MILLISECONDS) {
|
||||||
if ((err = acurrent->reap(audio_dts)) != srs_success) {
|
if ((err = acurrent->reap(audio_dts)) != srs_success) {
|
||||||
return srs_error_wrap(err, "reap current");
|
return srs_error_wrap(err, "reap current");
|
||||||
}
|
}
|
||||||
|
@ -367,7 +367,7 @@ srs_error_t SrsDashController::on_video(SrsSharedPtrMessage* shared_video, SrsFo
|
||||||
return refresh_init_mp4(shared_video, format);
|
return refresh_init_mp4(shared_video, format);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool reopen = format->video->frame_type == SrsVideoAvcFrameTypeKeyFrame && vcurrent->duration() >= fragment;
|
bool reopen = format->video->frame_type == SrsVideoAvcFrameTypeKeyFrame && vcurrent->duration() >= fragment / SRS_UTIME_MILLISECONDS;
|
||||||
if (reopen) {
|
if (reopen) {
|
||||||
if ((err = vcurrent->reap(video_dts)) != srs_success) {
|
if ((err = vcurrent->reap(video_dts)) != srs_success) {
|
||||||
return srs_error_wrap(err, "reap current");
|
return srs_error_wrap(err, "reap current");
|
||||||
|
|
|
@ -30,6 +30,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <srs_app_fragment.hpp>
|
#include <srs_app_fragment.hpp>
|
||||||
|
#include <srs_service_time.hpp>
|
||||||
|
|
||||||
class SrsRequest;
|
class SrsRequest;
|
||||||
class SrsOriginHub;
|
class SrsOriginHub;
|
||||||
|
@ -86,7 +87,7 @@ private:
|
||||||
int64_t last_update_mpd;
|
int64_t last_update_mpd;
|
||||||
private:
|
private:
|
||||||
// The duration of fragment in ms.
|
// The duration of fragment in ms.
|
||||||
int fragment;
|
srs_utime_t fragment;
|
||||||
// The period to update the mpd in ms.
|
// The period to update the mpd in ms.
|
||||||
int update_period;
|
int update_period;
|
||||||
// The timeshift buffer depth.
|
// The timeshift buffer depth.
|
||||||
|
@ -128,7 +129,7 @@ private:
|
||||||
uint64_t video_dts;
|
uint64_t video_dts;
|
||||||
private:
|
private:
|
||||||
// The fragment duration in ms to reap it.
|
// The fragment duration in ms to reap it.
|
||||||
int fragment;
|
srs_utime_t fragment;
|
||||||
private:
|
private:
|
||||||
std::string home;
|
std::string home;
|
||||||
int video_tack_id;
|
int video_tack_id;
|
||||||
|
|
|
@ -52,6 +52,7 @@ public:
|
||||||
// @dts The dts of frame in ms.
|
// @dts The dts of frame in ms.
|
||||||
virtual void append(int64_t dts);
|
virtual void append(int64_t dts);
|
||||||
// Get the duration of fragment in ms.
|
// Get the duration of fragment in ms.
|
||||||
|
// TODO: FIXME: Refine to time unit.
|
||||||
virtual int64_t duration();
|
virtual int64_t duration();
|
||||||
// Whether the fragment contains any sequence header.
|
// Whether the fragment contains any sequence header.
|
||||||
virtual bool is_sequence_header();
|
virtual bool is_sequence_header();
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <srs_protocol_io.hpp>
|
#include <srs_protocol_io.hpp>
|
||||||
|
#include <srs_service_time.hpp>
|
||||||
|
|
||||||
// Wrap for coroutine.
|
// Wrap for coroutine.
|
||||||
typedef void* srs_netfd_t;
|
typedef void* srs_netfd_t;
|
||||||
|
|
25
trunk/src/service/srs_service_time.cpp
Normal file
25
trunk/src/service/srs_service_time.cpp
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
/**
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013-2019 Winlin
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <srs_service_time.hpp>
|
||||||
|
|
48
trunk/src/service/srs_service_time.hpp
Normal file
48
trunk/src/service/srs_service_time.hpp
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
/**
|
||||||
|
* The MIT License (MIT)
|
||||||
|
*
|
||||||
|
* Copyright (c) 2013-2019 Winlin
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||||
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
||||||
|
* subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||||
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||||
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||||
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||||
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SRS_SERVICE_TIME_HPP
|
||||||
|
#define SRS_SERVICE_TIME_HPP
|
||||||
|
|
||||||
|
#include <srs_core.hpp>
|
||||||
|
|
||||||
|
// Wrap for coroutine.
|
||||||
|
typedef uint64_t srs_utime_t;
|
||||||
|
|
||||||
|
// The time unit in ms, for example 100 * SRS_UTIME_MILLISECONDS means 100ms.
|
||||||
|
#define SRS_UTIME_MILLISECONDS 1000
|
||||||
|
|
||||||
|
// The time unit in ms, for example 120 * SRS_UTIME_SECONDS means 120s.
|
||||||
|
#define SRS_UTIME_SECONDS 1000000
|
||||||
|
|
||||||
|
// The time unit in minutes, for example 3 * SRS_UTIME_MINUTES means 3m.
|
||||||
|
#define SRS_UTIME_MINUTES 60000000LL
|
||||||
|
|
||||||
|
// The time unit in hours, for example 2 * SRS_UTIME_HOURS means 2h.
|
||||||
|
#define SRS_UTIME_HOURS 3600000000LL
|
||||||
|
|
||||||
|
// Never timeout.
|
||||||
|
#define SRS_UTIME_NO_TIMEOUT ((srs_utime_t) -1LL)
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -1811,14 +1811,16 @@ VOID TEST(ConfigUnitTest, CheckDefaultValues)
|
||||||
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF));
|
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF));
|
||||||
EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_bw_check_interval(""));
|
EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_bw_check_interval(""));
|
||||||
|
|
||||||
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{}"));
|
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{bandcheck{interval 4;}}"));
|
||||||
EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_bw_check_interval("v"));
|
EXPECT_EQ(4 * SRS_UTIME_SECONDS, conf.get_bw_check_interval("v"));
|
||||||
|
}
|
||||||
|
|
||||||
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{bandcheck{}}"));
|
if (true) {
|
||||||
EXPECT_EQ(30 * SRS_UTIME_SECONDS, conf.get_bw_check_interval("v"));
|
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF));
|
||||||
|
EXPECT_EQ(3 * SRS_UTIME_SECONDS, conf.get_dash_fragment(""));
|
||||||
|
|
||||||
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{bandcheck{interval 1.1;}}"));
|
EXPECT_TRUE(ERROR_SUCCESS == conf.parse(_MIN_OK_CONF"vhost v{dash{dash_fragment 4;}}"));
|
||||||
EXPECT_EQ(srs_utime_t(1.1 * SRS_UTIME_SECONDS), conf.get_bw_check_interval("v"));
|
EXPECT_EQ(4 * SRS_UTIME_SECONDS, conf.get_dash_fragment("v"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue