[FFmpeg-devel] [PATCH] avformat: added named pipe protocol

Martin Sliwka martin.sliwka at gmail.com
Thu Jun 14 13:10:30 CEST 2012


The new 'npipe' protocol is copy of 'file' protocol with two modifications:
1) URLProtocol::url_seek is not set
2) URLProtocol::url_open is set to npipe_open(...) which is same as
file_open(...)
except for protocol name it stripes from file name.

New protocol is also very similar to already included 'pipe' protocol
which unfortunately can not be safely modified without breaking backward
compatibility.

Reason for this change is that named pipes are not wokring as seekable 
inputs.
Problem is that ffio_limit(...) incorrectly limits requested read size 
because
avio_size(...) (it's fstat(...) in file_seek(...) in fact) can not
report correct
file size.

Martin

---
  libavformat/Makefile     |    1 +
  libavformat/allformats.c |    1 +
  libavformat/file.c       |   37 +++++++++++++++++++++++++++++++++++++
  3 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/libavformat/Makefile b/libavformat/Makefile
index 6e3742f..a929bad 100644
--- a/libavformat/Makefile
+++ b/libavformat/Makefile
@@ -372,6 +372,7 @@ OBJS-$(CONFIG_MMSH_PROTOCOL)             += mmsh.o
mms.o asf.o
  OBJS-$(CONFIG_MMST_PROTOCOL)             += mmst.o mms.o asf.o
  OBJS-$(CONFIG_MD5_PROTOCOL)              += md5proto.o
  OBJS-$(CONFIG_PIPE_PROTOCOL)             += file.o
+OBJS-$(CONFIG_NPIPE_PROTOCOL)            += file.o
  OBJS-$(CONFIG_RTMP_PROTOCOL)             += rtmpproto.o rtmppkt.o
  OBJS-$(CONFIG_RTP_PROTOCOL)              += rtpproto.o
  OBJS-$(CONFIG_SCTP_PROTOCOL)             += sctp.o
diff --git a/libavformat/allformats.c b/libavformat/allformats.c
index 1862449..fa04b7a 100644
--- a/libavformat/allformats.c
+++ b/libavformat/allformats.c
@@ -276,6 +276,7 @@ void av_register_all(void)
      REGISTER_PROTOCOL (MMST, mmst);
      REGISTER_PROTOCOL (MD5,  md5);
      REGISTER_PROTOCOL (PIPE, pipe);
+    REGISTER_PROTOCOL (NPIPE, npipe);
      REGISTER_PROTOCOL (RTMP, rtmp);
      REGISTER_PROTOCOL (RTP, rtp);
      REGISTER_PROTOCOL (SCTP, sctp);
diff --git a/libavformat/file.c b/libavformat/file.c
index 1352bcc..db79b5c 100644
--- a/libavformat/file.c
+++ b/libavformat/file.c
@@ -157,3 +157,40 @@ URLProtocol ff_pipe_protocol = {
  };

  #endif /* CONFIG_PIPE_PROTOCOL */
+
+#if CONFIG_NPIPE_PROTOCOL
+
+static int npipe_open(URLContext *h, const char *filename, int flags)
+{
+    int access;
+    int fd;
+
+    av_strstart(filename, "npipe:", &filename);
+
+    if (flags & AVIO_FLAG_WRITE && flags & AVIO_FLAG_READ) {
+        access = O_CREAT | O_TRUNC | O_RDWR;
+    } else if (flags & AVIO_FLAG_WRITE) {
+        access = O_CREAT | O_TRUNC | O_WRONLY;
+    } else {
+        access = O_RDONLY;
+    }
+#ifdef O_BINARY
+    access |= O_BINARY;
+#endif
+    fd = open(filename, access, 0666);
+    if (fd == -1)
+        return AVERROR(errno);
+    h->priv_data = (void *) (intptr_t) fd;
+    return 0;
+}
+
+URLProtocol ff_npipe_protocol = {
+    .name                = "npipe",
+    .url_open            = npipe_open,
+    .url_read            = file_read,
+    .url_write           = file_write,
+    .url_get_file_handle = file_get_handle,
+    .url_check           = file_check,
+};
+
+#endif /* CONFIG_NPIPE_PROTOCOL */
-- 
1.7.4.1


More information about the ffmpeg-devel mailing list