Ardour
9.0-pre0-582-g084a23a80d
cmdpipe_writer.h
Go to the documentation of this file.
1
#ifndef AUDIOGRAPHER_CMDPIPE_WRITER_H
2
#define AUDIOGRAPHER_CMDPIPE_WRITER_H
3
4
#include <string>
5
6
#include <glib.h>
7
8
#include "
audiographer/flag_debuggable.h
"
9
#include "
audiographer/sink.h
"
10
#include "
audiographer/types.h
"
11
12
#include "
pbd/gstdio_compat.h
"
13
#include "
pbd/signals.h
"
14
15
#include "
ardour/system_exec.h
"
16
#include "
ardour/export_failed.h
"
17
18
namespace
AudioGrapher
19
{
20
24
template
<
typename
T = DefaultSampleType>
25
class
CmdPipeWriter
26
:
public
Sink
<T>
27
,
public
Throwing
<>
28
,
public
FlagDebuggable
<>
29
{
30
public
:
31
CmdPipeWriter
(
ARDOUR::SystemExec
* proc, std::string
const
& path,
int
tmp_fd = -1, gchar* tmp_file = 0)
32
:
samples_written
(0)
33
,
_proc
(proc)
34
,
_path
(path)
35
,
_tmp_fd
(tmp_fd)
36
,
_tmp_file
(tmp_file)
37
{
38
add_supported_flag
(
ProcessContext<T>::EndOfInput
);
39
40
if
(tmp_fd >= 0) {
41
;
42
}
else
if
(proc->
start
(
ARDOUR::SystemExec::ShareWithParent
)) {
43
throw
ARDOUR::ExportFailed
(
"External encoder (ffmpeg) cannot be started."
);
44
}
45
proc->
Terminated
.connect_same_thread (
exec_connections
, std::bind (&
CmdPipeWriter::encode_complete
,
this
));
46
}
47
48
virtual
~CmdPipeWriter
() {
49
delete
_proc
;
50
if
(
_tmp_fd
>= 0) {
51
::close
(
_tmp_fd
);
52
}
53
if
(
_tmp_file
) {
54
g_unlink (
_tmp_file
);
55
g_free (
_tmp_file
);
56
}
57
}
58
59
samplecnt_t
get_samples_written
()
const
{
return
samples_written
; }
60
void
reset_samples_written_count
() {
samples_written
= 0; }
61
62
void
flush
(
void
)
63
{
64
_proc
->
close_stdin
();
65
_proc
->
wait
();
66
}
67
68
void
close
(
void
)
69
{
70
_proc
->
terminate
();
71
}
72
73
virtual
void
process
(
ProcessContext<T>
const
& c)
74
{
75
check_flags
(*
this
, c);
76
77
if
(
_tmp_fd
< 0 && (!
_proc
|| !
_proc
->
is_running
())) {
78
throw
Exception
(*
this
,
"Target encoder process is not running"
);
79
}
80
81
const
size_t
bytes_per_sample =
sizeof
(T);
82
samplecnt_t
written;
83
if
(
_tmp_fd
>= 0) {
84
written = write (
_tmp_fd
, (
const
void
*) c.
data
(), c.
samples
() * bytes_per_sample) / bytes_per_sample;
85
}
else
{
86
written =
_proc
->
write_to_stdin
((
const
void
*) c.
data
(), c.
samples
() * bytes_per_sample) / bytes_per_sample;
87
}
88
89
samples_written
+= written;
90
91
if
(
throw_level
(
ThrowProcess
) && written != c.
samples
()) {
92
throw
Exception
(*
this
,
"Could not write data to output file"
);
93
}
94
95
if
(c.
has_flag
(
ProcessContext<T>::EndOfInput
)) {
96
if
(
_tmp_fd
>= 0) {
97
::close
(
_tmp_fd
);
98
_tmp_fd
= -1;
99
if
(
_proc
->
start
(
ARDOUR::SystemExec::ShareWithParent
)) {
100
throw
ARDOUR::ExportFailed
(
"External encoder (ffmpeg) cannot be started."
);
101
}
102
assert (
_proc
->
is_running
());
103
}
else
{
104
_proc
->
close_stdin
();
105
}
106
_proc
->
wait
();
107
}
108
}
109
110
using
Sink<T>::process
;
111
112
PBD::Signal
<void(std::string)>
FileWritten
;
113
114
private
:
115
CmdPipeWriter
(
CmdPipeWriter
const
& other) {}
116
117
samplecnt_t
samples_written
;
118
ARDOUR::SystemExec
*
_proc
;
119
std::string
_path
;
120
int
_tmp_fd
;
121
gchar*
_tmp_file
;
122
123
void
encode_complete
() {
124
if
(
_tmp_file
) {
125
g_unlink (
_tmp_file
);
126
g_free (
_tmp_file
);
127
_tmp_file
= NULL;
128
}
129
FileWritten
(
_path
);
130
}
131
132
PBD::ScopedConnectionList
exec_connections
;
133
};
134
135
}
// namespace
136
137
#endif
138
system_exec.h
types.h
ARDOUR::ExportFailed
Definition:
export_failed.h:32
ARDOUR::SystemExec
Definition:
ardour/ardour/system_exec.h:29
ARDOUR::SystemExec::start
int start(StdErrMode stderr_mode=IgnoreAndClose)
Definition:
ardour/ardour/system_exec.h:36
AudioGrapher::CmdPipeWriter
Definition:
cmdpipe_writer.h:29
AudioGrapher::CmdPipeWriter::get_samples_written
samplecnt_t get_samples_written() const
Definition:
cmdpipe_writer.h:59
AudioGrapher::CmdPipeWriter::_path
std::string _path
Definition:
cmdpipe_writer.h:119
AudioGrapher::CmdPipeWriter::close
void close(void)
Definition:
cmdpipe_writer.h:68
AudioGrapher::CmdPipeWriter::_tmp_file
gchar * _tmp_file
Definition:
cmdpipe_writer.h:121
AudioGrapher::CmdPipeWriter::CmdPipeWriter
CmdPipeWriter(CmdPipeWriter const &other)
Definition:
cmdpipe_writer.h:115
AudioGrapher::CmdPipeWriter::process
virtual void process(ProcessContext< T > const &c)
Definition:
cmdpipe_writer.h:73
AudioGrapher::CmdPipeWriter::CmdPipeWriter
CmdPipeWriter(ARDOUR::SystemExec *proc, std::string const &path, int tmp_fd=-1, gchar *tmp_file=0)
Definition:
cmdpipe_writer.h:31
AudioGrapher::CmdPipeWriter::samples_written
samplecnt_t samples_written
Definition:
cmdpipe_writer.h:117
AudioGrapher::CmdPipeWriter::encode_complete
void encode_complete()
Definition:
cmdpipe_writer.h:123
AudioGrapher::CmdPipeWriter::reset_samples_written_count
void reset_samples_written_count()
Definition:
cmdpipe_writer.h:60
AudioGrapher::CmdPipeWriter::FileWritten
PBD::Signal< void(std::string)> FileWritten
Definition:
cmdpipe_writer.h:112
AudioGrapher::CmdPipeWriter::exec_connections
PBD::ScopedConnectionList exec_connections
Definition:
cmdpipe_writer.h:132
AudioGrapher::CmdPipeWriter::flush
void flush(void)
Definition:
cmdpipe_writer.h:62
AudioGrapher::CmdPipeWriter::_tmp_fd
int _tmp_fd
Definition:
cmdpipe_writer.h:120
AudioGrapher::CmdPipeWriter::~CmdPipeWriter
virtual ~CmdPipeWriter()
Definition:
cmdpipe_writer.h:48
AudioGrapher::CmdPipeWriter::_proc
ARDOUR::SystemExec * _proc
Definition:
cmdpipe_writer.h:118
AudioGrapher::FlagDebuggable
A debugging class for nodes that support a certain set of flags.
Definition:
flag_debuggable.h:16
AudioGrapher::FlagDebuggable::check_flags
void check_flags(SelfType &self, ProcessContext< ContextType > context)
Prints debug output if context contains flags that are not supported by this class.
Definition:
flag_debuggable.h:30
AudioGrapher::FlagDebuggable::add_supported_flag
void add_supported_flag(Flag flag)
Adds a flag to the set of flags supported.
Definition:
flag_debuggable.h:23
AudioGrapher::ProcessContext
Definition:
process_context.h:25
AudioGrapher::ProcessContext::has_flag
bool has_flag(Flag flag) const
Definition:
process_context.h:100
AudioGrapher::ProcessContext::data
T const * data() const
data points to the array of data to process
Definition:
process_context.h:84
AudioGrapher::ProcessContext::samples
samplecnt_t const & samples() const
samples tells how many samples the array pointed by data contains
Definition:
process_context.h:88
AudioGrapher::Sink
Definition:
sink.h:17
AudioGrapher::Throwing
Definition:
throwing.h:44
AudioGrapher::Throwing::throw_level
bool throw_level(ThrowLevel level)
Definition:
throwing.h:47
PBD::ScopedConnectionList
Definition:
signals.h:269
PBD::Signal
Definition:
signals.h:169
PBD::SystemExec::wait
int wait(int options=0)
PBD::SystemExec::close_stdin
void close_stdin()
PBD::SystemExec::is_running
bool is_running()
PBD::SystemExec::Terminated
PBD::Signal< void()> Terminated
Definition:
pbd/pbd/system_exec.h:212
PBD::SystemExec::write_to_stdin
size_t write_to_stdin(std::string const &d, size_t len=0)
PBD::SystemExec::terminate
void terminate()
PBD::SystemExec::ShareWithParent
@ ShareWithParent
Definition:
pbd/pbd/system_exec.h:126
export_failed.h
flag_debuggable.h
gstdio_compat.h
AudioGrapher
Definition:
analysis_graph.h:33
AudioGrapher::ThrowProcess
@ ThrowProcess
Process cycle level stuff.
Definition:
throwing.h:23
AudioGrapher::samplecnt_t
int64_t samplecnt_t
Definition:
audiographer/audiographer/types.h:11
Select::Exception
@ Exception
Definition:
libs/pbd/pbd/selectable.h:35
signals.h
sink.h
libs
audiographer
audiographer
general
cmdpipe_writer.h
Generated on Thu Dec 26 2024 05:38:48 for Ardour by
1.9.1