Sha256: 636f3d2ca45dab9ef24014e56df9b6c8fd7dc9214a7e6af9630a726cf59f1caf

Contents?: true

Size: 1.68 KB

Versions: 1

Compression:

Stored size: 1.68 KB

Contents

module Ffmprb

  class File  # NOTE I would rather rename it to Stream at the moment

    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

1 entries across 1 versions & 1 rubygems

Version Path
ffmprb-0.11.4 lib/ffmprb/file/threaded_buffered.rb