Sha256: e9c368b8d08b399410fe87f3509d793f04d309f643eb1972ad633afc6a86b72a

Contents?: true

Size: 1.62 KB

Versions: 3

Compression:

Stored size: 1.62 KB

Contents

module Ffmprb

  class File

    class << self

      def threaded_buffered_fifo(extname='.tmp', reader_open_on_writer_idle_limit: nil, proc_vis: nil)
        input_fifo_file = temp_fifo(extname)
        output_fifo_file = temp_fifo(extname)
        Ffmprb.logger.debug{"Opening #{input_fifo_file.path}>#{output_fifo_file.path} for buffering"}
        Util::Thread.new do
          begin
            io_buff = Util::ThreadedIoBuffer.new(opener(input_fifo_file, 'r'), opener(output_fifo_file, 'w'), keep_outputs_open_on_input_idle_limit: reader_open_on_writer_idle_limit)
            if proc_vis
              proc_vis.proc_vis_edge input_fifo_file, io_buff
              proc_vis.proc_vis_edge io_buff, output_fifo_file
            end
            begin
              # yield input_fifo_file, output_fifo_file, io_buff  if block_given?
            ensure
              Util::Thread.join_children!
            end
            Ffmprb.logger.debug{"IoBuffering from #{input_fifo_file.path} to #{output_fifo_file.path} ended"}
          ensure
            input_fifo_file.unlink  if input_fifo_file
            output_fifo_file.unlink  if output_fifo_file
          end
        end
        Ffmprb.logger.debug{"IoBuffering from #{input_fifo_file.path} to #{output_fifo_file.path} started"}

        [input_fifo_file, output_fifo_file]
      end

    end

    def threaded_buffered_copy_to(*dsts)
      Util::ThreadedIoBuffer.new(
        self.class.opener(self, 'r'),
        *dsts.map{|io| self.class.opener io, 'w'}
      ).tap do |io_buff|
        proc_vis_edge self, io_buff
        dsts.each{ |dst| proc_vis_edge io_buff, dst }
      end
    end

  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ffmprb-0.12.3 lib/ffmprb/file/threaded_buffered.rb
ffmprb-0.12.2 lib/ffmprb/file/threaded_buffered.rb
ffmprb-0.12.1 lib/ffmprb/file/threaded_buffered.rb