From 3cb3bbbddc1d09dab1471a3630f1a9aa4392ed50 Mon Sep 17 00:00:00 2001 From: Uoti Urpala Date: Tue, 2 Nov 2010 03:17:41 +0200 Subject: Add a simple capture feature (-capture) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If a specified key is pressed during playback, the current stream is captured to a file, similar to what -dumpstream achieves. original patch by Pásztor Szilárd, don tricon hu Taken from the following svn commits, but with several fixes and modifications (one obvious user-visible difference is that the default key binding is 'C', not 'c'): git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32524 b3059339-0415-0410-9bf9-f77b7e298cf2 git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32529 b3059339-0415-0410-9bf9-f77b7e298cf2 git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@32530 b3059339-0415-0410-9bf9-f77b7e298cf2 --- stream/stream.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'stream/stream.c') diff --git a/stream/stream.c b/stream/stream.c index 8b325a24d1..ca45f511e5 100644 --- a/stream/stream.c +++ b/stream/stream.c @@ -265,6 +265,16 @@ stream_t *open_output_stream(const char *filename, struct MPOpts *options) //=================== STREAMER ========================= +void stream_capture_do(stream_t *s) +{ + if (fwrite(s->buffer, s->buf_len, 1, s->capture_file) < 1) { + mp_tmsg(MSGT_GLOBAL, MSGL_ERR, "Error writing capture file: %s\n", + strerror(errno)); + fclose(s->capture_file); + s->capture_file = NULL; + } +} + int stream_fill_buffer(stream_t *s){ int len; // we will retry even if we already reached EOF previously. @@ -296,6 +306,8 @@ int stream_fill_buffer(stream_t *s){ s->buf_len=len; s->pos+=len; // printf("[%d]",len);fflush(stdout); + if (s->capture_file) + stream_capture_do(s); return len; } @@ -463,6 +475,11 @@ void free_stream(stream_t *s){ #ifdef CONFIG_STREAM_CACHE cache_uninit(s); #endif + if (s->capture_file) { + fclose(s->capture_file); + s->capture_file = NULL; + } + if(s->close) s->close(s); if(s->fd>0){ /* on unix we define closesocket to close -- cgit v1.2.3