From b592d39bfd393a272db94dcee4f97c597795630f Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Tue, 28 Aug 2012 16:47:36 +0200 Subject: [PATCH] player: require "seek" before outputting --- src/conn_http_dynamic.cpp | 1 + src/conn_http_progressive.cpp | 1 + src/conn_rtmp.cpp | 1 + src/player.cpp | 14 ++++++++++++++ 4 files changed, 17 insertions(+) diff --git a/src/conn_http_dynamic.cpp b/src/conn_http_dynamic.cpp index c1e7a22f..8014ef56 100644 --- a/src/conn_http_dynamic.cpp +++ b/src/conn_http_dynamic.cpp @@ -184,6 +184,7 @@ namespace Connector_HTTP{ #if DEBUG >= 3 fprintf(stderr, "Everything connected, starting to send video data...\n"); #endif + ss.Send("play\n");ss.flush(); inited = true; } if ((Flash_RequestPending > 0) && !Flash_FragBuffer.empty()){ diff --git a/src/conn_http_progressive.cpp b/src/conn_http_progressive.cpp index b13fe460..6c588994 100644 --- a/src/conn_http_progressive.cpp +++ b/src/conn_http_progressive.cpp @@ -74,6 +74,7 @@ namespace Connector_HTTP{ #if DEBUG >= 3 fprintf(stderr, "Everything connected, starting to send video data...\n"); #endif + ss.Send("play\n");ss.flush(); inited = true; } unsigned int now = time(0); diff --git a/src/conn_rtmp.cpp b/src/conn_rtmp.cpp index 34ffd789..ea15fc81 100644 --- a/src/conn_rtmp.cpp +++ b/src/conn_rtmp.cpp @@ -89,6 +89,7 @@ int Connector_RTMP::Connector_RTMP(Socket::Connection conn){ #if DEBUG >= 3 fprintf(stderr, "Everything connected, starting to send video data...\n"); #endif + SS.Send("play\n");SS.flush(); inited = true; } if (inited && !nostats){ diff --git a/src/player.cpp b/src/player.cpp index 26e4a5cf..5ba085fb 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -147,9 +147,14 @@ seekDone: /// Reads a command from stdin. Returns true if a command was read. bool File::readCommand() { char line[512]; + size_t line_len; if (fgets(line, sizeof(line), stdin) == NULL){ return false; } + line_len = strlen(line); + if (line[line_len - 1] == '\n'){ + line[--line_len] = 0; + } { int position = INT_MAX;// special value that says "invalid" if (!strncmp("seek ", line, sizeof("seek ") - 1)){ @@ -164,6 +169,9 @@ seekDone: return true; } } + if (!strcmp("play", line)){ + playing = true; + } return false; } @@ -173,6 +181,12 @@ seekDone: if (readCommand()) { continue; } + if (!playing){ + setBlocking(STDIN_FILENO, true); + continue; + }else{ + setBlocking(STDIN_FILENO, false); + } now = getNowMS(); if (now - timeDiff >= lastTime || lastTime - (now - timeDiff) > 5000) { if (nextPacket()) {