[MPlayer-dev-eng] [PATCH] Capture feature

Pásztor Szilárd bartosteka at freemail.hu
Mon Sep 6 17:12:50 CEST 2010


Reimar Döffinger:
> If this was implemented as a property, users would also have the choice
> between using this as a toggle or have separate keys for on and off.
> It would also allow a proper return value in slave mode when this
> is not available (which should be used if mpctx->stream is NULL as e.g.
> with -idle, instead of crashing which I think your code currently does).

Propertified.
(Hope this lame mailer will set now text/plain, but I'm forced to use
this because my server tricon.hu is refused from lists.mplayerhq.hu for
some unknown reason.)
-------------- next part --------------
diff -NurpabB mplayer-export-2010-09-06/cfg-mplayer.h mplayer-export-2010-09-06-capture/cfg-mplayer.h
--- mplayer-export-2010-09-06/cfg-mplayer.h	2010-09-04 01:49:35.000000000 +0200
+++ mplayer-export-2010-09-06-capture/cfg-mplayer.h	2010-09-06 11:21:41.504192264 +0200
@@ -288,6 +288,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},
 
+    {"capturefile", &capture_dump_name, CONF_TYPE_STRING, 0, 0, 0, NULL},
+
 #ifdef CONFIG_LIRC
     {"lircconf", &lirc_configfile, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL},
 #endif
diff -NurpabB mplayer-export-2010-09-06/command.c mplayer-export-2010-09-06-capture/command.c
--- mplayer-export-2010-09-06/command.c	2010-09-04 01:49:35.000000000 +0200
+++ mplayer-export-2010-09-06-capture/command.c	2010-09-06 16:57:44.141193379 +0200
@@ -71,6 +71,7 @@
 #define ROUND(x) ((int)((x)<0 ? (x)-0.5 : (x)+0.5))
 
 extern int use_menu;
+char *capture_dump_name=NULL;
 
 static void rescale_input_coordinates(int ix, int iy, double *dx, double *dy)
 {
@@ -1110,6 +1111,68 @@ 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 capturing = -1;
+    int ret = M_PROPERTY_NOT_IMPLEMENTED;
+
+    if (!mpctx->stream)
+        return M_PROPERTY_UNAVAILABLE;
+
+    switch (action) {
+    case M_PROPERTY_GET:
+        if (arg) {
+	    *(int *)arg = !!mpctx->stream->capture_file;
+	    return M_PROPERTY_OK;
+	} else
+            return M_PROPERTY_ERROR;
+    case M_PROPERTY_SET:
+        if (!arg) {
+            ret = M_PROPERTY_ERROR;
+	    break;
+	}
+	M_PROPERTY_CLAMP(prop, *(int *) arg);
+	capturing = *(int *)arg;
+	// fall through
+    case M_PROPERTY_STEP_UP:
+    case M_PROPERTY_STEP_DOWN:
+	if (capturing < 0)
+	    capturing = !mpctx->stream->capture_file;
+
+	if (capturing) {
+	    if (capture_dump_name && !mpctx->stream->capture_file &&
+		!(mpctx->stream->capture_file = fopen(capture_dump_name, "wb"))) {
+		mp_msg(MSGT_GLOBAL, MSGL_ERR, "Error opening capture file: %s\n", strerror(errno));
+		ret = M_PROPERTY_ERROR;
+	    } else
+		ret = M_PROPERTY_OK;
+	} else {
+	    if (mpctx->stream->capture_file) {
+		fclose(mpctx->stream->capture_file);
+		mpctx->stream->capture_file = NULL;
+		ret = M_PROPERTY_OK;
+	    }
+	    else
+		return M_PROPERTY_OK;
+	}
+    }
+
+    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)
@@ -2098,6 +2161,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,
@@ -2287,6 +2352,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 },
diff -NurpabB mplayer-export-2010-09-06/help/help_mp-en.h mplayer-export-2010-09-06-capture/help/help_mp-en.h
--- mplayer-export-2010-09-06/help/help_mp-en.h	2010-09-03 20:50:03.000000000 +0200
+++ mplayer-export-2010-09-06-capture/help/help_mp-en.h	2010-09-06 11:21:41.537193524 +0200
@@ -211,6 +211,8 @@ static const char help_text[]=
 #define MSGTR_OSDChapter "Chapter: (%d) %s"
 #define MSGTR_OSDAngle "Angle: %d/%d"
 #define MSGTR_OSDDeinterlace "Deinterlace: %s"
+#define MSGTR_OSDCapturing "Capturing: %s"
+#define MSGTR_OSDCapturingFailure "Capturing failed"
 
 // property values
 #define MSGTR_Enabled "enabled"
diff -NurpabB mplayer-export-2010-09-06/help/help_mp-hu.h mplayer-export-2010-09-06-capture/help/help_mp-hu.h
--- mplayer-export-2010-09-06/help/help_mp-hu.h	2010-07-27 23:23:19.000000000 +0200
+++ mplayer-export-2010-09-06-capture/help/help_mp-hu.h	2010-09-06 11:21:41.553193749 +0200
@@ -209,6 +209,8 @@ static const char help_text[]=
 #define MSGTR_OSDChapter "Fejezet: (%d) %s"
 #define MSGTR_OSDAngle "SzĂśg: %d/%d"
 #define MSGTR_OSDDeinterlace "Deinterlace: %s"
+#define MSGTR_OSDCapturing "MentĂŠs: %s"
+#define MSGTR_OSDCapturingFailure "MentĂŠs sikertelen"
 
 // property values
 #define MSGTR_Enabled "bekapcsolva"
diff -NurpabB mplayer-export-2010-09-06/help/help_mp-it.h mplayer-export-2010-09-06-capture/help/help_mp-it.h
--- mplayer-export-2010-09-06/help/help_mp-it.h	2010-08-18 19:23:21.000000000 +0200
+++ mplayer-export-2010-09-06-capture/help/help_mp-it.h	2010-09-06 11:21:41.556193507 +0200
@@ -208,6 +208,8 @@ static const char help_text[]=
 #define MSGTR_OSDChapter "Capitolo: (%d) %s"
 #define MSGTR_OSDAngle "Angolazione: %d/%d"
 #define MSGTR_OSDDeinterlace "Deinterlacciamento: %s"
+#define MSGTR_OSDCapturing "Registrazione: %s"
+#define MSGTR_OSDCapturingFailure "Registrazione fallito"
 
 // property values
 #define MSGTR_Enabled "abilitat"
diff -NurpabB mplayer-export-2010-09-06/input/input.c mplayer-export-2010-09-06-capture/input/input.c
--- mplayer-export-2010-09-06/input/input.c	2010-09-03 20:50:03.000000000 +0200
+++ mplayer-export-2010-09-06-capture/input/input.c	2010-09-06 14:51:06.015443248 +0200
@@ -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}} } },
@@ -461,6 +462,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" },
diff -NurpabB mplayer-export-2010-09-06/input/input.h mplayer-export-2010-09-06-capture/input/input.h
--- mplayer-export-2010-09-06/input/input.h	2010-09-03 20:50:03.000000000 +0200
+++ mplayer-export-2010-09-06-capture/input/input.h	2010-09-06 11:21:41.583192525 +0200
@@ -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,
diff -NurpabB mplayer-export-2010-09-06/mplayer.c mplayer-export-2010-09-06-capture/mplayer.c
--- mplayer-export-2010-09-06/mplayer.c	2010-09-04 21:24:34.000000000 +0200
+++ mplayer-export-2010-09-06-capture/mplayer.c	2010-09-06 17:09:25.156193405 +0200
@@ -4086,6 +4086,11 @@ goto_next_file:  // don't jump here afte
 
 mp_msg(MSGT_CPLAYER,MSGL_INFO,"\n");
 
+if (mpctx->stream && mpctx->stream->capture_file) {
+    fclose(mpctx->stream->capture_file);
+    mpctx->stream->capture_file = NULL;
+}
+
 if(benchmark){
     double tot=video_time_usage+vout_time_usage+audio_time_usage;
     double total_time_usage;
diff -NurpabB mplayer-export-2010-09-06/mplayer.h mplayer-export-2010-09-06-capture/mplayer.h
--- mplayer-export-2010-09-06/mplayer.h	2010-09-03 20:50:03.000000000 +0200
+++ mplayer-export-2010-09-06-capture/mplayer.h	2010-09-06 15:59:13.819195625 +0200
@@ -42,6 +42,8 @@ extern int    sub_auto;
 
 extern char * filename;
 
+extern char *capture_dump_name;
+
 extern int stream_cache_size;
 extern int autosync;
 extern double start_pts;
diff -NurpabB mplayer-export-2010-09-06/stream/cache2.c mplayer-export-2010-09-06-capture/stream/cache2.c
--- mplayer-export-2010-09-06/stream/cache2.c	2010-08-26 23:06:24.000000000 +0200
+++ mplayer-export-2010-09-06-capture/stream/cache2.c	2010-09-06 12:33:11.211443346 +0200
@@ -520,6 +520,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;
 
 }
diff -NurpabB mplayer-export-2010-09-06/stream/stream.c mplayer-export-2010-09-06-capture/stream/stream.c
--- mplayer-export-2010-09-06/stream/stream.c	2010-08-21 12:08:29.000000000 +0200
+++ mplayer-export-2010-09-06-capture/stream/stream.c	2010-09-06 12:33:01.216442903 +0200
@@ -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,14 @@ 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 +309,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;
 }
 
diff -NurpabB mplayer-export-2010-09-06/stream/stream.h mplayer-export-2010-09-06-capture/stream/stream.h
--- mplayer-export-2010-09-06/stream/stream.h	2010-08-03 18:26:50.000000000 +0200
+++ mplayer-export-2010-09-06-capture/stream/stream.h	2010-09-06 14:37:15.649443059 +0200
@@ -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-dev-eng mailing list