diff command.c @ 32438:faefba58f413

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
author diego
date Thu, 21 Oct 2010 18:19:30 +0000
parents 8f35fc25523f
children bf593e3827d9
line wrap: on
line diff
--- a/command.c	Thu Oct 21 17:35:56 2010 +0000
+++ b/command.c	Thu Oct 21 18:19:30 2010 +0000
@@ -1109,6 +1109,48 @@
     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 @@
      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 @@
     { "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 },