summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoroskwon <kos@dev3>2014-06-12 13:24:09 (GMT)
committeroskwon <kos@dev3>2014-06-12 13:24:09 (GMT)
commit0b0e8a65cf3bfa7fc5eb557ce25b98d038dc37dc (patch)
tree390fb7c09b56a5c8e81114b162383ef043292c15
parentf85f176807216ef64881289a4278abb9fc741eba (diff)
Fix seek bug.
-rw-r--r--src/Encoder.cpp3
-rw-r--r--src/Utils.cpp21
-rw-r--r--src/Utils.h2
-rw-r--r--src/main.cpp27
4 files changed, 25 insertions, 28 deletions
diff --git a/src/Encoder.cpp b/src/Encoder.cpp
index 37d7a83..3b59b07 100644
--- a/src/Encoder.cpp
+++ b/src/Encoder.cpp
@@ -7,9 +7,11 @@
#include <stdio.h>
#include <fcntl.h>
+#include <errno.h>
#include <dirent.h>
#include <string.h>
#include <unistd.h>
+#include <string.h>
#include <sys/ioctl.h>
#include "Utils.h"
@@ -110,6 +112,7 @@ bool Encoder::retry_open(int retry_count, int sleep_time)
WARNING("encoder%d open fail, retry count : %d/%d", encoder_id, i, retry_count);
sleep(sleep_time);
}
+ ERROR("encoder open fail : %s (%d)", strerror(errno), errno);
return false;
}
//----------------------------------------------------------------------
diff --git a/src/Utils.cpp b/src/Utils.cpp
index 6da67f2..fa31a85 100644
--- a/src/Utils.cpp
+++ b/src/Utils.cpp
@@ -35,9 +35,9 @@ std::string ultostr(int64_t data)
}
//----------------------------------------------------------------------
-int strtoi(std::string data)
+int strtollu(std::string data)
{
- int retval;
+ long long retval;
std::stringstream ss;
try {
ss.str(data);
@@ -161,14 +161,25 @@ off_t make_response(ThreadParams *params, std::string& response)
if((range.length() > 7) && (range.substr(0, 6) == "bytes=")) {
range = range.substr(6);
if(range.find('-') == (range.length() - 1)) {
- byte_offset = strtoi(range);
+ byte_offset = strtollu(range);
}
}
- response += (byte_offset > 0) ? HTTP_PARTIAL : HTTP_OK;
+ off_t content_length = source->stream_length - byte_offset;
+ if (byte_offset > 0) {
+ content_length += 1;
+ response += HTTP_PARTIAL;
+ }
+ else {
+ response += HTTP_OK;
+ }
response += HTTP_PARAMS;
response += "Accept-Ranges: bytes\r\n"
- "Content-Length: " + ultostr(source->stream_length) + "\r\n";
+ "Content-Length: " + ultostr(content_length) + "\r\n";
+ response += string("Content-Range: bytes ") +
+ ultostr(byte_offset) + "-" +
+ ultostr(source->stream_length - 1) + "/" +
+ ultostr(source->stream_length) + "\r\n";
response += HTTP_DONE;
}
break;
diff --git a/src/Utils.h b/src/Utils.h
index 3208357..aa8a131 100644
--- a/src/Utils.h
+++ b/src/Utils.h
@@ -18,7 +18,7 @@
#include "Encoder.h"
//----------------------------------------------------------------------
-int strtoi(std::string data);
+int strtollu(std::string data);
std::string ultostr(int64_t data);
std::string trim(std::string& s, const std::string& drop = " \t\n\v\r");
int split(std::string data, const char delimiter, std::vector<std::string>& tokens);
diff --git a/src/main.cpp b/src/main.cpp
index da17119..1f14efd 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -30,9 +30,7 @@ using namespace std;
#define RESPONSE_FD (1)
#define BUFFFER_SIZE (188 * 256)
-void signal_setting();
void signal_handler(int sig_no);
-
void do_exit(const char *message);
static bool is_terminated = true;
@@ -79,7 +77,7 @@ void *streaming_thread_main(void *params)
retry_wc = write(RESPONSE_FD, (buffer + rc - remain_len), remain_len);
wc += retry_wc;
}
- DEBUG("re-write result : %d - %d", wc, rc);
+ LOG("re-write result : %d - %d", wc, rc);
}
}
}
@@ -160,7 +158,7 @@ void *source_thread_main(void *params)
wc += retry_wc;
}
}
- DEBUG("re-write result : %d - %d", wc, rc);
+ LOG("re-write result : %d - %d", wc, rc);
usleep(500000);
}
}
@@ -187,7 +185,7 @@ int main(int argc, char **argv)
else {
Logger::instance()->init("/tmp/transtreamproxy", Logger::WARNING, false, "3.0");
}
- signal_setting();
+ signal(SIGINT, signal_handler);
RequestHeader header;
@@ -254,8 +252,9 @@ 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 to %ld", byte_offset);
+ DEBUG("seek ok");
}
if (!encoder.ioctl(Encoder::IOCTL_SET_VPID, video_pid)) {
@@ -310,25 +309,9 @@ void do_exit(const char *message)
}
//----------------------------------------------------------------------
-void signal_setting()
-{
- signal(SIGHUP, signal_handler);
- signal(SIGINT, signal_handler);
- signal(SIGQUIT, signal_handler);
- signal(SIGILL, signal_handler);
- signal(SIGABRT, signal_handler);
- signal(SIGKILL, signal_handler);
- signal(SIGBUS, signal_handler);
- signal(SIGSEGV, signal_handler);
- signal(SIGTERM, signal_handler);
-}
-//----------------------------------------------------------------------
-
void signal_handler(int sig_no)
{
INFO("signal no : %d", sig_no);
do_exit("signal detected..");
- usleep(500000);
- exit(0);
}
//----------------------------------------------------------------------