mediakit 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -3
- data/lib/mediakit/utils/process_runner.rb +15 -10
- data/lib/mediakit/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e69a57c2b1c2be72c69e94c1b49a7039a1942dbf
|
4
|
+
data.tar.gz: f384688fb09a6175228e424ec1700273b5831978
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4447c23bfcc32517c129afc8214516ee3b9eee786acec729f31b34c37ea1b7136b0cd70f78dabe98ccccf47a5cf4df303b9a9dec228c37561ad481404d8c4cdd
|
7
|
+
data.tar.gz: 3400a0614adf0534f43b2965053b1bba5e0d89c1758cd5e8572e46a15e4d01f5c05a21fffa91753bf4a271f9e7ec866604cbfba723b36fd3bc49ba465c6ca9d3
|
data/README.md
CHANGED
@@ -12,14 +12,15 @@ I've design this library for following purpose.
|
|
12
12
|
|
13
13
|
Currently you can use low-level inteface of mediakit!
|
14
14
|
|
15
|
-
* [
|
15
|
+
* [x] low-level interface
|
16
16
|
* [x] execute command for ffmpeg
|
17
17
|
* [x] unit testing supports (fake driver)
|
18
18
|
* [x] nice command setting
|
19
19
|
* [x] read timeout setting
|
20
20
|
* [x] shell escape for security
|
21
|
-
* [
|
22
|
-
* [
|
21
|
+
* [x] ffmpeg instropection (retrive supported formats, codecs, encoders and decoders)
|
22
|
+
* [x] logger support
|
23
|
+
* [ ] low-level ffprobe interface
|
23
24
|
* [ ] high-level interface for ffmpeg
|
24
25
|
* [ ] low-level interface for sox
|
25
26
|
* [ ] high-level interface for sox
|
@@ -2,6 +2,7 @@ require 'open3'
|
|
2
2
|
require 'thread'
|
3
3
|
require 'timeout'
|
4
4
|
require 'cool.io'
|
5
|
+
require 'logger'
|
5
6
|
require 'mediakit/utils/shell_escape'
|
6
7
|
|
7
8
|
module Mediakit
|
@@ -14,9 +15,12 @@ module Mediakit
|
|
14
15
|
|
15
16
|
DEFAULT_READ_TIMEOUT_INTERVAL = 30
|
16
17
|
|
17
|
-
|
18
|
+
attr_reader(:logger)
|
19
|
+
|
20
|
+
def initialize(timeout: nil, nice: 0, logger: nil)
|
18
21
|
@timeout = timeout
|
19
22
|
@nice = nice
|
23
|
+
@logger = logger || Logger.new(STDOUT)
|
20
24
|
end
|
21
25
|
|
22
26
|
# @overload run(command, *args)
|
@@ -62,7 +66,6 @@ module Mediakit
|
|
62
66
|
raise(error)
|
63
67
|
ensure
|
64
68
|
teardown_watchers
|
65
|
-
loop_thread.join if loop_thread
|
66
69
|
end
|
67
70
|
|
68
71
|
[@out_watcher.data, @err_watcher.data, exit_status]
|
@@ -84,9 +87,8 @@ module Mediakit
|
|
84
87
|
|
85
88
|
def setup_watchers(stdout, stderr)
|
86
89
|
@timer = TimeoutTimer.new(@timeout, Thread.current)
|
87
|
-
@out_watcher = IOWatcher.new(stdout) { @timer.update }
|
88
|
-
@err_watcher = IOWatcher.new(stderr) { @timer.update }
|
89
|
-
|
90
|
+
@out_watcher = IOWatcher.new(stdout) { |data| @timer.update; logger.info(data) }
|
91
|
+
@err_watcher = IOWatcher.new(stderr) { |data| @timer.update; logger.error(data) }
|
90
92
|
@loop = Coolio::Loop.new
|
91
93
|
@out_watcher.attach(@loop)
|
92
94
|
@err_watcher.attach(@loop)
|
@@ -98,8 +100,8 @@ module Mediakit
|
|
98
100
|
rescue => e
|
99
101
|
# workaround for ambiguous RuntimeError
|
100
102
|
# TODO: replace logger method
|
101
|
-
warn(e.message)
|
102
|
-
warn(e.backtrace)
|
103
|
+
logger.warn(e.message)
|
104
|
+
logger.warn(e.backtrace.join("\n"))
|
103
105
|
end
|
104
106
|
|
105
107
|
def teardown_watchers
|
@@ -107,12 +109,15 @@ module Mediakit
|
|
107
109
|
@out_watcher.close if @out_watcher && !@out_watcher.closed?
|
108
110
|
@err_watcher.close if @err_watcher && !@err_watcher.closed?
|
109
111
|
@loop.stop if @loop.has_active_watchers?
|
112
|
+
rescue RuntimeError => e
|
113
|
+
logger.warn(e.message)
|
114
|
+
logger.warn(e.backtrace.join("\n"))
|
110
115
|
end
|
111
116
|
|
112
117
|
def force_kill_process(pid)
|
113
118
|
Process.kill('SIGKILL', pid)
|
114
|
-
rescue Errno::ESRCH
|
115
|
-
warn
|
119
|
+
rescue Errno::ESRCH => e
|
120
|
+
logger.warn("fail SIGKILL pid=#{pid} - #{e.message}, #{e.backtrace.join("\n")}")
|
116
121
|
end
|
117
122
|
|
118
123
|
class IOWatcher < Coolio::IO
|
@@ -126,7 +131,7 @@ module Mediakit
|
|
126
131
|
|
127
132
|
def on_read(data)
|
128
133
|
@data << data
|
129
|
-
@block.call(
|
134
|
+
@block.call(data)
|
130
135
|
end
|
131
136
|
|
132
137
|
def on_close
|
data/lib/mediakit/version.rb
CHANGED