[MPlayer-cvslog] r32524 - in trunk: DOCS/man/en/mplayer.1 DOCS/tech/slave.txt cfg-mplayer.h command.c help/help_mp-en.h help/help_mp-hu.h help/help_mp-it.h input/input.c input/input.h mplayer.c mplayer.h stream/cac...

diego subversion at mplayerhq.hu
Thu Oct 21 20:19:30 CEST 2010


Author: diego
Date: Thu Oct 21 20:19:30 2010
New Revision: 32524

Log:
Implement a basic capture feature, available through -capture.
If a specified key is pressed during playback, the current stream is
captured to a file, similar to what -dumpstream achieves.
patch by Pásztor Szilárd, don tricon hu

Modified:
   trunk/DOCS/tech/slave.txt
   trunk/cfg-mplayer.h
   trunk/command.c
   trunk/input/input.c
   trunk/input/input.h
   trunk/mplayer.c
   trunk/mplayer.h
   trunk/stream/cache2.c
   trunk/stream/stream.c
   trunk/stream/stream.h

Changes in other areas also in this revision:
Modified:
   trunk/DOCS/man/en/mplayer.1
   trunk/help/help_mp-en.h
   trunk/help/help_mp-hu.h
   trunk/help/help_mp-it.h

Modified: trunk/DOCS/tech/slave.txt
==============================================================================
--- trunk/DOCS/tech/slave.txt	Thu Oct 21 19:35:56 2010	(r32523)
+++ trunk/DOCS/tech/slave.txt	Thu Oct 21 20:19:30 2010	(r32524)
@@ -76,6 +76,10 @@ audio_delay <value> [abs]
     If [abs] is non-zero, parameter is set to <value>.
     <value> is in the range [-100, 100].
 
+capturing [value]
+    Toggle/set capturing the primary stream like -dumpstream.
+    Requires the -capture parameter to be given.
+
 change_rectangle <val1> <val2>
     Change the position of the rectangle filter rectangle.
         <val1>
@@ -537,6 +541,7 @@ channels           int                  
 switch_audio       int       -2      255     X   X   X    select audio stream
 switch_angle       int       -2      255     X   X   X    select DVD angle
 switch_title       int       -2      255     X   X   X    select DVD title
+capturing          flag      0       1       X   X   X    dump primary stream if enabled
 fullscreen         flag      0       1       X   X   X
 deinterlace        flag      0       1       X   X   X
 ontop              flag      0       1       X   X   X

Modified: trunk/cfg-mplayer.h
==============================================================================
--- trunk/cfg-mplayer.h	Thu Oct 21 19:35:56 2010	(r32523)
+++ trunk/cfg-mplayer.h	Thu Oct 21 20:19:30 2010	(r32524)
@@ -292,6 +292,8 @@ const m_option_t mplayer_opts[]={
     {"dumpjacosub", &stream_dump_type, CONF_TYPE_FLAG, 0, 0, 8, NULL},
     {"dumpsami", &stream_dump_type, CONF_TYPE_FLAG, 0, 0, 9, NULL},
 
+    {"capture", &capture_dump, CONF_TYPE_FLAG, 0, 0, 1, NULL},
+
 #ifdef CONFIG_LIRC
     {"lircconf", &lirc_configfile, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL},
 #endif

Modified: trunk/command.c
==============================================================================
--- trunk/command.c	Thu Oct 21 19:35:56 2010	(r32523)
+++ trunk/command.c	Thu Oct 21 20:19:30 2010	(r32524)
@@ -1109,6 +1109,48 @@ static int mp_property_deinterlace(m_opt
     return M_PROPERTY_NOT_IMPLEMENTED;
 }
 
+static int mp_property_capture(m_option_t *prop, int action,
+                               void *arg, MPContext *mpctx)
+{
+    int ret;
+    int capturing = !!mpctx->stream->capture_file;
+
+    if (!mpctx->stream)
+        return M_PROPERTY_UNAVAILABLE;
+
+    ret = m_property_flag(prop, action, arg, &capturing);
+    if (ret == M_PROPERTY_OK && capturing != !!mpctx->stream->capture_file) {
+        if (capturing) {
+            if (capture_dump && !(mpctx->stream->capture_file = fopen(stream_dump_name, "wb"))) {
+                mp_msg(MSGT_GLOBAL, MSGL_ERR,
+                       "Error opening capture file: %s\n", strerror(errno));
+                ret = M_PROPERTY_ERROR;
+            } else {
+                mp_msg(MSGT_GLOBAL, MSGL_ERR,
+                       "Capturing not enabled (forgot -capture parameter?)\n");
+                ret = M_PROPERTY_ERROR;
+            }
+        } else {
+            fclose(mpctx->stream->capture_file);
+            mpctx->stream->capture_file = NULL;
+        }
+    }
+
+    switch (ret) {
+    case M_PROPERTY_ERROR:
+        set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDCapturingFailure);
+        break;
+    case M_PROPERTY_OK:
+        set_osd_msg(OSD_MSG_SPEED, 1, osd_duration, MSGTR_OSDCapturing,
+                    mpctx->stream->capture_file ? MSGTR_Enabled : MSGTR_Disabled);
+        break;
+    default:
+        break;
+    }
+
+    return ret;
+}
+
 /// Panscan (RW)
 static int mp_property_panscan(m_option_t *prop, int action, void *arg,
                                MPContext *mpctx)
@@ -2097,6 +2139,8 @@ static const m_option_t mp_properties[] 
      0, 0, 0, NULL },
     { "pause", mp_property_pause, CONF_TYPE_FLAG,
      M_OPT_RANGE, 0, 1, NULL },
+    { "capturing", mp_property_capture, CONF_TYPE_FLAG,
+     M_OPT_RANGE, 0, 1, NULL },
 
     // Audio
     { "volume", mp_property_volume, CONF_TYPE_FLOAT,
@@ -2286,6 +2330,7 @@ static struct {
     { "loop", MP_CMD_LOOP, 0, 0, -1, MSGTR_LoopStatus },
     { "chapter", MP_CMD_SEEK_CHAPTER, 0, 0, -1, NULL },
     { "angle", MP_CMD_SWITCH_ANGLE, 0, 0, -1, NULL },
+    { "capturing", MP_CMD_CAPTURING, 1, 0, -1, NULL },
     // audio
     { "volume", MP_CMD_VOLUME, 0, OSD_VOLUME, -1, MSGTR_Volume },
     { "mute", MP_CMD_MUTE, 1, 0, -1, MSGTR_MuteStatus },

Modified: trunk/input/input.c
==============================================================================
--- trunk/input/input.c	Thu Oct 21 19:35:56 2010	(r32523)
+++ trunk/input/input.c	Thu Oct 21 20:19:30 2010	(r32524)
@@ -173,6 +173,7 @@ static const mp_cmd_t mp_cmds[] = {
   { MP_CMD_LOADFILE, "loadfile", 1, { {MP_CMD_ARG_STRING, {0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
   { MP_CMD_LOADLIST, "loadlist", 1, { {MP_CMD_ARG_STRING, {0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
   { MP_CMD_RUN, "run", 1, { {MP_CMD_ARG_STRING,{0}}, {-1,{0}} } },
+  { MP_CMD_CAPTURING, "capturing", 0, { {-1,{0}} } },
   { MP_CMD_VF_CHANGE_RECTANGLE, "change_rectangle", 2, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}}}},
   { MP_CMD_TV_TELETEXT_ADD_DEC, "teletext_add_dec", 1, { {MP_CMD_ARG_STRING,{0}}, {-1,{0}} } },
   { MP_CMD_TV_TELETEXT_GO_LINK, "teletext_go_link", 1, { {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
@@ -464,6 +465,7 @@ static const mp_cmd_bind_t def_cmd_binds
 #endif
   { { 'T', 0 }, "vo_ontop" },
   { { 'f', 0 }, "vo_fullscreen" },
+  { { 'c', 0 }, "capturing" },
   { { 's', 0 }, "screenshot 0" },
   { { 'S', 0 }, "screenshot 1" },
   { { 'w', 0 }, "panscan -0.1" },

Modified: trunk/input/input.h
==============================================================================
--- trunk/input/input.h	Thu Oct 21 19:35:56 2010	(r32523)
+++ trunk/input/input.h	Thu Oct 21 20:19:30 2010	(r32524)
@@ -43,6 +43,7 @@ typedef enum {
   MP_CMD_TV_STEP_CHANNEL,
   MP_CMD_TV_STEP_NORM,
   MP_CMD_TV_STEP_CHANNEL_LIST,
+  MP_CMD_CAPTURING,
   MP_CMD_VO_FULLSCREEN,
   MP_CMD_SUB_POS,
   MP_CMD_DVDNAV,

Modified: trunk/mplayer.c
==============================================================================
--- trunk/mplayer.c	Thu Oct 21 19:35:56 2010	(r32523)
+++ trunk/mplayer.c	Thu Oct 21 20:19:30 2010	(r32524)
@@ -263,8 +263,9 @@ float stream_cache_seek_min_percent=50.0
 #endif
 
 // dump:
-static char *stream_dump_name="stream.dump";
-       int stream_dump_type=0;
+char *stream_dump_name = "stream.dump";
+int stream_dump_type = 0;
+int capture_dump = 0;
 
 // A-V sync:
 static float default_max_pts_correction=-1;

Modified: trunk/mplayer.h
==============================================================================
--- trunk/mplayer.h	Thu Oct 21 19:35:56 2010	(r32523)
+++ trunk/mplayer.h	Thu Oct 21 20:19:30 2010	(r32524)
@@ -39,7 +39,10 @@ extern double start_pts;
 /* for the GUI */
 extern int auto_quality;
 extern int disable_gui_conf;
+
+extern int capture_dump;
 extern int stream_dump_type;
+extern char *stream_dump_name;
 
 void update_set_of_subtitles(void);
 

Modified: trunk/stream/cache2.c
==============================================================================
--- trunk/stream/cache2.c	Thu Oct 21 19:35:56 2010	(r32523)
+++ trunk/stream/cache2.c	Thu Oct 21 20:19:30 2010	(r32524)
@@ -510,6 +510,8 @@ int cache_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;
 
 }

Modified: trunk/stream/stream.c
==============================================================================
--- trunk/stream/stream.c	Thu Oct 21 19:35:56 2010	(r32523)
+++ trunk/stream/stream.c	Thu Oct 21 20:19:30 2010	(r32524)
@@ -179,6 +179,7 @@ static stream_t* open_stream_plugin(cons
     }
   }
   s = new_stream(-2,-2);
+  s->capture_file = NULL;
   s->url=strdup(filename);
   s->flags |= mode;
   *ret = sinfo->open(s,mode,arg,file_format);
@@ -269,6 +270,16 @@ stream_t* open_output_stream(const char*
 
 //=================== STREAMER =========================
 
+void stream_capture_do(stream_t *s)
+{
+  if (fwrite(s->buffer, s->buf_len, 1, s->capture_file) < 1) {
+    mp_msg(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.
@@ -300,6 +311,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 +476,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

Modified: trunk/stream/stream.h
==============================================================================
--- trunk/stream/stream.h	Thu Oct 21 19:35:56 2010	(r32523)
+++ trunk/stream/stream.h	Thu Oct 21 20:19:30 2010	(r32524)
@@ -23,6 +23,7 @@
 #include "m_option.h"
 #include "mp_msg.h"
 #include "url.h"
+#include <stdio.h>
 #include <string.h>
 #include <inttypes.h>
 #include <sys/types.h>
@@ -165,6 +166,7 @@ typedef struct stream {
   streaming_ctrl_t *streaming_ctrl;
 #endif
   unsigned char buffer[STREAM_BUFFER_SIZE>STREAM_MAX_SECTOR_SIZE?STREAM_BUFFER_SIZE:STREAM_MAX_SECTOR_SIZE];
+  FILE *capture_file;
 } stream_t;
 
 #ifdef CONFIG_NETWORKING
@@ -173,6 +175,7 @@ typedef struct stream {
 
 int stream_fill_buffer(stream_t *s);
 int stream_seek_long(stream_t *s, off_t pos);
+void stream_capture_do(stream_t *s);
 
 #ifdef CONFIG_STREAM_CACHE
 int stream_enable_cache(stream_t *stream,int size,int min,int prefill);


More information about the MPlayer-cvslog mailing list