diff options
author | oskwon <kos@dev3> | 2014-06-23 09:37:16 (GMT) |
---|---|---|
committer | oskwon <kos@dev3> | 2014-06-23 09:42:43 (GMT) |
commit | b623b15cc8748385041804644384a9cd19e967d3 (patch) | |
tree | c88e4a5b7df6346e5fd450e7dc1831e7e32ba879 | |
parent | 796c4be3eaac0bbad7173814fc8d03a29c9cd3d3 (diff) |
Improve performance for seeking and starting transcoding.
-rw-r--r-- | src/Mpeg.cpp | 90 | ||||
-rw-r--r-- | src/Mpeg.h | 4 | ||||
-rw-r--r-- | src/main.cpp | 1 |
3 files changed, 28 insertions, 67 deletions
diff --git a/src/Mpeg.cpp b/src/Mpeg.cpp index 431652e..772cb6f 100644 --- a/src/Mpeg.cpp +++ b/src/Mpeg.cpp @@ -13,48 +13,6 @@ void Mpeg::seek(HttpHeader &header) { -#ifdef USE_EXTERNAL_SEEK_TIME - try { - std::string position = header.page_params["position"]; - std::string relative = header.page_params["relative"]; - - if (position.empty() && relative.empty()) { - off_t byte_offset = 0; - std::string range = header.params["Range"]; - if((range.length() > 7) && (range.substr(0, 6) == "bytes=")) { - range = range.substr(6); - if(range.find('-') == (range.length() - 1)) { - byte_offset = Util::strtollu(range); - } - } - if (is_time_seekable && byte_offset > 0) { - DEBUG("seek to byte_offset %llu", byte_offset); - seek_absolute(byte_offset); - DEBUG("seek ok"); - } - } - else { - unsigned int position_offset; - if (!relative.empty()) { - int dur = duration(); - DEBUG("duration : %d", dur); - position_offset = (dur * Util::strtollu(relative)) / 100; - } - else { - position_offset = Util::strtollu(position); - } - - if (is_time_seekable && position_offset > 0) { - DEBUG("seek to position_offset %ds", position_offset); - seek_time((position_offset * 1000) + first_pcr_ms); - DEBUG("seek ok"); - } - } - } - catch (const trap &e) { - WARNING("Exception : %s", e.what()); - } -#else try { off_t byte_offset = 0; std::string position = header.page_params["position"]; @@ -93,7 +51,6 @@ void Mpeg::seek(HttpHeader &header) catch (...) { WARNING("seek fail."); } -#endif } //---------------------------------------------------------------------- @@ -299,39 +256,38 @@ int Mpeg::take_sample(off_t off, pts_t &p) int Mpeg::calc_bitrate() { - calc_begin(); calc_end(); - if (!(m_begin_valid && m_end_valid)) + calc_length(); + if (!m_begin_valid || !m_end_valid) { return -1; + } pts_t len_in_pts = m_pts_end - m_pts_begin; /* wrap around? */ - if (len_in_pts < 0) + if (len_in_pts < 0) { len_in_pts += 0x200000000LL; + } off_t len_in_bytes = m_offset_end - m_offset_begin; - - if (!len_in_pts) - return -1; + if (!len_in_pts) return -1; unsigned long long bitrate = len_in_bytes * 90000 * 8 / len_in_pts; - if ((bitrate < 10000) || (bitrate > 100000000)) + if ((bitrate < 10000) || (bitrate > 100000000)) { return -1; - + } return bitrate; } //---------------------------------------------------------------------- int Mpeg::get_offset(off_t &offset, pts_t &pts, int marg) { - calc_begin(); calc_end(); - - if (!m_begin_valid) - return -1; - if (!m_end_valid) + calc_length(); + if (!m_begin_valid || !m_end_valid) { return -1; + } - if (!m_samples_taken) + if (!m_samples_taken) { take_samples(); + } if (!m_samples.empty()) { int maxtries = 5; @@ -536,15 +492,19 @@ int Mpeg::get_pts(off_t &offset, pts_t &pts, int fixed) int Mpeg::calc_length() { - calc_begin(); calc_end(); - if (!(m_begin_valid && m_end_valid)) - return -1; - pts_t len = m_pts_end - m_pts_begin; + if (m_duration <= 0) { + calc_begin(); calc_end(); + if (!(m_begin_valid && m_end_valid)) + return -1; + pts_t len = m_pts_end - m_pts_begin; - if (len < 0) - len += 0x200000000LL; + if (len < 0) + len += 0x200000000LL; - len = len / 90000; - return int(len); + len = len / 90000; + + m_duration = int(len); + } + return m_duration; } //---------------------------------------------------------------------- @@ -32,6 +32,8 @@ private: int m_samples_taken; std::map<pts_t, off_t> m_samples; + int m_duration; + void scan(); int switch_offset(off_t off); @@ -60,7 +62,7 @@ public: m_pts_begin = m_pts_end = m_offset_begin = m_offset_end = 0; m_last_filelength = m_begin_valid = m_end_valid = m_futile =0; - m_samples_taken = 0; + m_duration = m_samples_taken = 0; } virtual ~Mpeg() throw () {} diff --git a/src/main.cpp b/src/main.cpp index b8474e0..4d5da36 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -155,7 +155,6 @@ int main(int argc, char **argv) } else { pthread_detach(source_thread_handle); - sleep(1); if (!encoder.ioctl(Encoder::IOCTL_START_TRANSCODING, 0)) { is_terminated = true; throw(http_trap("start transcoding fail.", 503, "Service Unavailable")); |