diff options
author | oskwon <kos@dev3> | 2014-06-17 14:39:16 (GMT) |
---|---|---|
committer | oskwon <kos@dev3> | 2014-06-17 14:39:16 (GMT) |
commit | cdddeb93b8a0f475e8e451188f6f04dc94355770 (patch) | |
tree | 43cebddb48c2c4c7ee6b5df612e609e69d1fc7ce | |
parent | 0b0e8a65cf3bfa7fc5eb557ce25b98d038dc37dc (diff) |
Implement file seek using PCR offset.
-rw-r--r-- | src/Utils.cpp | 33 | ||||
-rw-r--r-- | src/Utils.h | 2 | ||||
-rw-r--r-- | src/main.cpp | 28 |
3 files changed, 46 insertions, 17 deletions
diff --git a/src/Utils.cpp b/src/Utils.cpp index fa31a85..af7ac4b 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -110,20 +110,33 @@ bool RequestHeader::parse_header(std::string header) method = infos[0]; path = infos[1]; version = infos[2]; - decoded_path = path; if (strncmp(path.c_str(), "/file", 5) == 0) { - std::string key = "", value = ""; - if (!split_key_value(path, "=", key, value)) { - ERROR("fail to parse path(file) : %s", path.c_str()); - return false; - } - if (key != "/file?file") { - ERROR("unknown request file path (key : %s, value : %s)", key.c_str(), value.c_str()); - return false; + std::vector<std::string> tokens; + if (split(path.substr(6), '&', tokens) > 0) { + for (int i = 0; i < tokens.size(); ++i) { + std::string data = tokens[i]; + std::string key = "", value = ""; + if (!split_key_value(data, "=", key, value)) { + ERROR("fail to request : %s", data.c_str()); + continue; + } + if (key == "file") { + extension[key] = UriDecoder().decode(value.c_str());; + continue; + } + extension[key] = value; + } } type = REQ_TYPE_TRANSCODING_FILE; - decoded_path = UriDecoder().decode(value.c_str()); + +// DEBUG(":: HEADER :: %s", extension["file"].c_str()); +// std::map<std::string, std::string>::iterator iter = extension.begin(); +// for (; iter != extension.end(); ++iter) { +// std::string key = iter->first; +// std::string value = iter->second; +// DEBUG("[%s] -> [%s]", key.c_str(), value.c_str()); +// } } DEBUG("info (%d) -> type : [%s], path : [%s], version : [%s]", infos.size(), method.c_str(), path.c_str(), version.c_str()); diff --git a/src/Utils.h b/src/Utils.h index aa8a131..a64a780 100644 --- a/src/Utils.h +++ b/src/Utils.h @@ -42,9 +42,9 @@ public: RequestType type; std::string method; std::string path; - std::string decoded_path; std::string version; std::map<std::string, std::string> params; + std::map<std::string, std::string> extension; public: bool parse_header(std::string header); diff --git a/src/main.cpp b/src/main.cpp index 1f14efd..42bed62 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -68,6 +68,7 @@ void *streaming_thread_main(void *params) } else if (rc > 0) { wc = write(RESPONSE_FD, buffer, rc); + //DEBUG("write : %d", wc); if (wc < rc) { //DEBUG("need rewrite.. remain (%d)", rc - wc); int retry_wc = 0; @@ -145,7 +146,7 @@ void *source_thread_main(void *params) } else if (rc > 0) { wc = write(encoder->get_fd(), buffer, rc); - + //DEBUG("write : %d", wc); if (wc < rc) { //DEBUG("need rewrite.. remain (%d)", rc - wc); int retry_wc = 0; @@ -198,7 +199,6 @@ int main(int argc, char **argv) if (header.parse_header(req)) { Encoder encoder; Source *source = 0; - ThreadParams thread_params = { 0, &encoder, &header }; int video_pid = 0, audio_pid = 0, pmt_pid = 0; @@ -206,7 +206,7 @@ int main(int argc, char **argv) switch(header.type) { case REQ_TYPE_TRANSCODING_FILE: try { - MpegTS *ts = new MpegTS(header.decoded_path, false); + MpegTS *ts = new MpegTS(header.extension["file"], true); pmt_pid = ts->pmt_pid; video_pid = ts->video_pid; audio_pid = ts->audio_pid; @@ -252,9 +252,25 @@ int main(int argc, char **argv) DEBUG("response data :\n%s", response.c_str()); if (header.type == REQ_TYPE_TRANSCODING_FILE) { - DEBUG("seek to %llu", byte_offset); - ((MpegTS*)source)->seek_absolute(byte_offset); - DEBUG("seek ok"); + try { + std::string position = header.extension["position"]; + if (position == "") { + DEBUG("seek to byte_offset %llu", byte_offset); + ((MpegTS*)source)->seek_absolute(byte_offset); + DEBUG("seek ok"); + } + else { + unsigned int position_offset = strtollu(position); + if(((MpegTS*)source)->is_time_seekable && (position_offset > 0)) { + DEBUG("seek to position_offset %ds", position_offset); + ((MpegTS*)source)->seek_time((position_offset * 1000) + ((MpegTS*)source)->first_pcr_ms); + DEBUG("seek ok"); + } + } + } + catch (const trap &e) { + WARNING("Exception : %s", e.what()); + } } if (!encoder.ioctl(Encoder::IOCTL_SET_VPID, video_pid)) { |