[libcamera-devel] Video recording on PinePhone Re: libcamera on pinephone

Pavel Machek pavel at ucw.cz
Wed Jul 13 00:49:10 CEST 2022


Hi!

> > > 74020.783102 (30.01 fps) cam0-stream0 seq: 000001 bytesused: 2073600
> > > 74020.883095 (10.00 fps) cam0-stream0 seq: 000004 bytesused: 2073600
> > > 74020.949774 (15.00 fps) cam0-stream0 seq: 000006 bytesused: 2073600
> > > 74021.016443 (15.00 fps) cam0-stream0 seq: 000008 bytesused: 2073600
> > > 74021.049787 (29.99 fps) cam0-stream0 seq: 000009 bytesused: 2073600
> > > 74021.116423 (15.01 fps) cam0-stream0 seq: 000011 bytesused: 2073600
> > > 74021.183135 (14.99 fps) cam0-stream0 seq: 000013 bytesused: 2073600
> > 
> > I just noticed that if I don't enable file output, I'm geting nice
> > 30fps. Hmm. I am outputting 60MB/sec, but with 3GB RAM, it should be
> > possible to sustain that for a while...

There's something wrong with buffer memory. It is way slower than it
should be.

write() speed is not limiting, but memcpy() from the buffer is way too
slow. And yes, memcpy+write is still faster than passing the buffer
directly.

Trying to sum the buffer with byte accesses is total disaster. Is it
possible that the buffer is uncached or something like that? All I
need is 60MB RAM to disk cache throughput. That should not be hard
even for a phone with in-order CPU...

Best regards,
								Pavel


diff --git a/src/cam/file_sink.cpp b/src/cam/file_sink.cpp
index 45213d4a..0f7dda23 100644
--- a/src/cam/file_sink.cpp
+++ b/src/cam/file_sink.cpp
@@ -60,7 +60,8 @@ void FileSink::writeBuffer(const Stream *stream, FrameBuffer *buffer)
 {
 	std::string filename;
 	size_t pos;
-	int fd, ret = 0;
+	static int fd;
+	int ret = 0;
 
 	if (!pattern_.empty())
 		filename = pattern_;
@@ -76,7 +77,8 @@ void FileSink::writeBuffer(const Stream *stream, FrameBuffer *buffer)
 		filename.replace(pos, 1, ss.str());
 	}
 
-	fd = open(filename.c_str(), O_CREAT | O_WRONLY |
+	if (pos != std::string::npos || !fd)
+	    fd = open(filename.c_str(), O_CREAT | O_WRONLY |
 		  (pos == std::string::npos ? O_APPEND : O_TRUNC),
 		  S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
 	if (fd == -1) {
@@ -98,8 +100,28 @@ void FileSink::writeBuffer(const Stream *stream, FrameBuffer *buffer)
 			std::cerr << "payload size " << meta.bytesused
 				  << " larger than plane size " << data.size()
 				  << std::endl;
-
+#if 0
+		{
+		  unsigned int j, r = 0;
+		  static unsigned char dummy[2073600];
+		  //unsigned char *p = data.data();
+		  unsigned char *p = dummy;
+		  for (j = 0; j < length; j++) {
+		    r += p[j];
+		  }
+		  volatile int foo = r;
+
+		  (void) foo;
+		}
+		continue;
+#endif		
+#if 0
 		ret = ::write(fd, data.data(), length);
+#else
+		static unsigned char dummy[2073600];
+		//memcpy(dummy, data.data(), length);
+		ret = ::write(fd, dummy, length);
+#endif
 		if (ret < 0) {
 			ret = -errno;
 			std::cerr << "write error: " << strerror(-ret)
@@ -113,5 +135,6 @@ void FileSink::writeBuffer(const Stream *stream, FrameBuffer *buffer)
 		}
 	}
 
-	close(fd);
+	if (pos != std::string::npos)	
+	    close(fd);
 }

-- 
People of Russia, stop Putin before his war on Ukraine escalates.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://lists.libcamera.org/pipermail/libcamera-devel/attachments/20220713/d342fb6f/attachment.sig>


More information about the libcamera-devel mailing list