On Tue, Jun 14, 2016 at 06:47:25AM +0200, Sebastien Marie wrote:
> Hi,
> 
> First, a bump of library version would be required as you added new
> exported functions.
> 
> But I think your changes are too invasive for been patches for OpenBSD
> port tree.
> 
> You should first deal with upstream for these changes, else it will be a
> shame for us to deal with future upgrade.
> 

I doubt upstream would take it, the early libav calls are probably not
suitable for the library.

Would a simpler patch be acceptable?

This doesn't check for the entire kitchen-sink of protocols that libav
can use but does do a nice pledge for the typical use-cases, and I don't
think the fallback pledge is too bad (still avoids wpath and cpath).


--
Carlin



Index: graphics/ffmpegthumbnailer/Makefile
===================================================================
RCS file: /cvs/ports/graphics/ffmpegthumbnailer/Makefile,v
retrieving revision 1.27
diff -u -p -u -r1.27 Makefile
--- graphics/ffmpegthumbnailer/Makefile 11 Mar 2016 19:59:14 -0000      1.27
+++ graphics/ffmpegthumbnailer/Makefile 14 Jun 2016 08:37:32 -0000
@@ -3,17 +3,18 @@
 COMMENT=       lightweight video thumbnailer for file managers
 
 DISTNAME=      ffmpegthumbnailer-2.0.8
-REVISION=      3
+REVISION=      4
 CATEGORIES=    graphics multimedia
 MASTER_SITES=  https://ffmpegthumbnailer.googlecode.com/files/
 
-SHARED_LIBS=   ffmpegthumbnailer       4.1
+SHARED_LIBS=   ffmpegthumbnailer       4.2
 
 HOMEPAGE=      https://github.com/dirkvdb/ffmpegthumbnailer
 
 # GPLv2+
 PERMIT_PACKAGE_CDROM=  Yes
 
+# uses pledge()
 WANTLIB += avcodec avformat avutil c jpeg m png pthread stdc++
 WANTLIB += swscale x264
 
Index: 
graphics/ffmpegthumbnailer/patches/patch-libffmpegthumbnailer_videothumbnailer_cpp
===================================================================
RCS file: 
graphics/ffmpegthumbnailer/patches/patch-libffmpegthumbnailer_videothumbnailer_cpp
diff -N 
graphics/ffmpegthumbnailer/patches/patch-libffmpegthumbnailer_videothumbnailer_cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ 
graphics/ffmpegthumbnailer/patches/patch-libffmpegthumbnailer_videothumbnailer_cpp
  14 Jun 2016 08:37:32 -0000
@@ -0,0 +1,33 @@
+$OpenBSD$
+
+_generateThumbnail() provides a way to call the private
+generateThumbnail() method with a manually created ImageWriter, this is
+needed so pledge() can be called immediately after creating the
+ImageWriter but before the first frame of the video is decoded.
+
+Avoiding the stat() call on non-file protocols helps allow for dropping
+of the rpath promise when using sockets.
+
+--- libffmpegthumbnailer/videothumbnailer.cpp.orig     Sun Aug 26 00:07:44 2012
++++ libffmpegthumbnailer/videothumbnailer.cpp  Tue Jun 14 19:34:24 2016
+@@ -177,6 +177,11 @@ void VideoThumbnailer::generateSmartThumbnail(MovieDec
+     videoFrame = videoFrames[bestFrame];
+ }
+ 
++void VideoThumbnailer::_generateThumbnail(const string& videoFile, 
ImageWriter& imageWriter)
++{
++    generateThumbnail(videoFile, imageWriter, NULL);
++}
++
+ void VideoThumbnailer::generateThumbnail(const string& videoFile, 
ThumbnailerImageType type, const string& outputFile, AVFormatContext* 
pAvContext)
+ {
+     ImageWriter* imageWriter = ImageWriterFactory<const 
string&>::createImageWriter(type, outputFile);
+@@ -194,7 +199,7 @@ void VideoThumbnailer::generateThumbnail(const string&
+ 
+ void VideoThumbnailer::writeImage(const string& videoFile, ImageWriter& 
imageWriter, const VideoFrame& videoFrame, int duration, vector<uint8_t*>& 
rowPointers)
+ {
+-    if (videoFile != "-")
++    if (videoFile != "-" && (videoFile.find(":") == std::string::npos || 
videoFile.compare(0, 5, "file:") == 0))
+     {
+         struct stat statInfo;
+         if (stat(videoFile.c_str(), &statInfo) == 0)
Index: 
graphics/ffmpegthumbnailer/patches/patch-libffmpegthumbnailer_videothumbnailer_h
===================================================================
RCS file: 
graphics/ffmpegthumbnailer/patches/patch-libffmpegthumbnailer_videothumbnailer_h
diff -N 
graphics/ffmpegthumbnailer/patches/patch-libffmpegthumbnailer_videothumbnailer_h
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ 
graphics/ffmpegthumbnailer/patches/patch-libffmpegthumbnailer_videothumbnailer_h
    14 Jun 2016 08:37:32 -0000
@@ -0,0 +1,14 @@
+$OpenBSD$
+--- libffmpegthumbnailer/videothumbnailer.h.orig       Sun Aug 26 00:07:44 2012
++++ libffmpegthumbnailer/videothumbnailer.h    Tue Jun 14 19:17:04 2016
+@@ -46,6 +46,10 @@ class VideoThumbnailer (public)
+     void generateThumbnail(const std::string& videoFile, ThumbnailerImageType 
type, const std::string& outputFile, AVFormatContext* pAvContext = NULL);
+     void generateThumbnail(const std::string& videoFile, ThumbnailerImageType 
type, std::vector<uint8_t>& buffer, AVFormatContext* pAvContext = NULL);
+ 
++    /* this function is needed for pledge(2) and is not part of the
++       standard libffmpegthumbnailer interface */
++    void _generateThumbnail(const std::string& videoFile, ImageWriter& 
imageWriter);
++
+     void setThumbnailSize(int size);
+     void setSeekPercentage(int percentage);
+     void setSeekTime(const std::string& seekTime);
Index: graphics/ffmpegthumbnailer/patches/patch-main_cpp
===================================================================
RCS file: graphics/ffmpegthumbnailer/patches/patch-main_cpp
diff -N graphics/ffmpegthumbnailer/patches/patch-main_cpp
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ graphics/ffmpegthumbnailer/patches/patch-main_cpp   14 Jun 2016 08:37:32 
-0000
@@ -0,0 +1,90 @@
+$OpenBSD$
+
+pledge:
+    file - stdio rpath
+        reads a local file to produce the thumbnail
+
+    network - stdio dns inet
+        reads a remote file to produce the thumbnail
+
+    unix socket - stdio unix
+        reads data from a unix socket to produce the thumbnail
+
+In all cases cpath and wpath are avoided by calling pledge() after the
+ImageWriter has opened the file for writing.
+
+Calling av_register_all() early when inet/unix protocols are used
+avoids the need for rpath.
+
+
+--- main.cpp.orig      Sun Aug 26 00:07:44 2012
++++ main.cpp   Tue Jun 14 20:22:10 2016
+@@ -30,7 +30,12 @@
+ #include "libffmpegthumbnailer/videothumbnailer.h"
+ #include "libffmpegthumbnailer/stringoperations.h"
+ #include "libffmpegthumbnailer/filmstripfilter.h"
++#include "libffmpegthumbnailer/imagewriterfactory.h"
+ 
++extern "C" {
++#include <libavformat/avformat.h>
++}
++
+ using namespace std;
+ using namespace ffmpegthumbnailer;
+ 
+@@ -149,8 +154,54 @@ int main(int argc, char** argv)
+         {
+             videoThumbnailer.setSeekPercentage(seekPercentage);
+         }
+-        videoThumbnailer.generateThumbnail(inputFile, imageType, outputFile);
+ 
++        ImageWriter* imageWriter = ImageWriterFactory<const 
string&>::createImageWriter(imageType, outputFile);
++
++#ifdef __OpenBSD__
++        av_register_all();
++
++        if (inputFile.find(':') == std::string::npos ||
++            inputFile.compare(0, 5, "file:") == 0 ||
++            inputFile.compare(0, 5, "data:") == 0)
++        {
++            if (pledge("stdio rpath", NULL) == -1)
++            {
++                cerr << "pledge failed" << endl;
++                exit(-1);
++            }
++        }
++        else if (inputFile.compare(0, 5, "http:") == 0 ||
++                 inputFile.compare(0, 6, "https:") == 0 ||
++                 inputFile.compare(0, 4, "ftp:") == 0 ||
++                 inputFile.compare(0, 5, "sftp:") == 0)
++        {
++            if (pledge("stdio dns inet", NULL) == -1)
++            {
++                cerr << "pledge failed" << endl;
++                exit(-1);
++            }
++        }
++        else if (inputFile.compare(0, 5, "unix:") == 0)
++        {
++            if (pledge("stdio unix", NULL) == -1)
++            {
++                cerr << "pledge failed" << endl;
++                exit(-1);
++            }
++        }
++        else
++        {
++            if (pledge("stdio rpath dns inet unix", NULL) == -1)
++            {
++                cerr << "pledge failed" << endl;
++                exit(-1);
++            }
++        }
++#endif
++
++        videoThumbnailer._generateThumbnail(inputFile, *imageWriter);
++
++        delete imageWriter;
+         delete filmStripFilter;
+     }
+     catch (exception& e)

Reply via email to