Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
audiowmark
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Stefan Westerfeld
audiowmark
Commits
45e64803
Commit
45e64803
authored
Dec 11, 2019
by
Stefan Westerfeld
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improved error handling. Handle errors during output stream close.
Signed-off-by:
Stefan Westerfeld
<
stefan@space.twc.de
>
parent
fa259ba4
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
42 additions
and
11 deletions
+42
-11
audiostream.hh
src/audiostream.hh
+1
-0
rawoutputstream.cc
src/rawoutputstream.cc
+14
-2
rawoutputstream.hh
src/rawoutputstream.hh
+1
-1
sfoutputstream.cc
src/sfoutputstream.cc
+4
-2
sfoutputstream.hh
src/sfoutputstream.hh
+1
-1
stdoutwavoutputstream.cc
src/stdoutwavoutputstream.cc
+15
-4
stdoutwavoutputstream.hh
src/stdoutwavoutputstream.hh
+1
-1
wmadd.cc
src/wmadd.cc
+5
-0
No files found.
src/audiostream.hh
View file @
45e64803
...
...
@@ -28,6 +28,7 @@ class AudioOutputStream : public AudioStream
{
public
:
virtual
Error
write_frames
(
const
std
::
vector
<
float
>&
frames
)
=
0
;
virtual
Error
close
()
=
0
;
};
#endif
/* AUDIOWMARK_AUDIO_STREAM_HH */
src/rawoutputstream.cc
View file @
45e64803
...
...
@@ -74,22 +74,34 @@ RawOutputStream::write_frames (const vector<float>& samples)
m_raw_converter
->
to_raw
(
samples
,
bytes
);
fwrite
(
&
bytes
[
0
],
1
,
bytes
.
size
(),
m_output_file
);
if
(
ferror
(
m_output_file
))
return
Error
(
"write sample data failed"
);
return
Error
::
Code
::
NONE
;
}
void
Error
RawOutputStream
::
close
()
{
if
(
m_state
==
State
::
OPEN
)
{
if
(
m_output_file
)
{
fflush
(
m_output_file
);
if
(
ferror
(
m_output_file
))
return
Error
(
"error during flush"
);
}
if
(
m_close_file
&&
m_output_file
)
{
fclose
(
m_output_file
);
if
(
fclose
(
m_output_file
)
!=
0
)
return
Error
(
"error during close"
);
m_output_file
=
nullptr
;
m_close_file
=
false
;
}
m_state
=
State
::
CLOSED
;
}
return
Error
::
Code
::
NONE
;
}
src/rawoutputstream.hh
View file @
45e64803
...
...
@@ -28,7 +28,7 @@ public:
Error
open
(
const
std
::
string
&
filename
,
const
RawFormat
&
format
);
Error
write_frames
(
const
std
::
vector
<
float
>&
frames
)
override
;
void
close
();
Error
close
();
};
#endif
/* AUDIOWMARK_RAW_OUTPUT_STREAM_HH */
src/sfoutputstream.cc
View file @
45e64803
...
...
@@ -49,16 +49,18 @@ SFOutputStream::open (const string& filename, int n_channels, int sample_rate, i
return
Error
::
Code
::
NONE
;
}
void
Error
SFOutputStream
::
close
()
{
if
(
m_state
==
State
::
OPEN
)
{
assert
(
m_sndfile
);
sf_close
(
m_sndfile
);
if
(
sf_close
(
m_sndfile
))
return
Error
(
"sf_close returned an error"
);
m_state
=
State
::
CLOSED
;
}
return
Error
::
Code
::
NONE
;
}
Error
...
...
src/sfoutputstream.hh
View file @
45e64803
...
...
@@ -26,7 +26,7 @@ public:
Error
open
(
const
std
::
string
&
filename
,
int
n_channels
,
int
sample_rate
,
int
bit_depth
,
size_t
n_frames
);
Error
write_frames
(
const
std
::
vector
<
float
>&
frames
)
override
;
void
close
()
;
Error
close
()
override
;
int
bit_depth
()
const
override
;
int
sample_rate
()
const
override
;
int
n_channels
()
const
override
;
...
...
src/stdoutwavoutputstream.cc
View file @
45e64803
...
...
@@ -101,6 +101,8 @@ StdoutWavOutputStream::open (int n_channels, int sample_rate, int bit_depth, siz
header_append_u32
(
header_bytes
,
data_size
);
fwrite
(
&
header_bytes
[
0
],
1
,
header_bytes
.
size
(),
stdout
);
if
(
ferror
(
stdout
))
return
Error
(
"write wav header failed"
);
m_bit_depth
=
bit_depth
;
m_sample_rate
=
sample_rate
;
...
...
@@ -118,19 +120,28 @@ StdoutWavOutputStream::write_frames (const vector<float>& samples)
m_raw_converter
->
to_raw
(
samples
,
output_bytes
);
fwrite
(
&
output_bytes
[
0
],
1
,
output_bytes
.
size
(),
stdout
);
if
(
ferror
(
stdout
))
return
Error
(
"write sample data failed"
);
return
Error
::
Code
::
NONE
;
}
void
Error
StdoutWavOutputStream
::
close
()
{
if
(
m_state
==
State
::
OPEN
)
{
for
(
size_t
i
=
0
;
i
<
m_close_padding
;
i
++
)
fputc
(
0
,
stdout
);
{
fputc
(
0
,
stdout
);
if
(
ferror
(
stdout
))
return
Error
(
"write wav padding failed"
);
}
fflush
(
stdout
);
if
(
ferror
(
stdout
))
return
Error
(
"error during flush"
);
m_state
=
State
::
CLOSED
;
}
return
Error
::
Code
::
NONE
;
}
src/stdoutwavoutputstream.hh
View file @
45e64803
...
...
@@ -28,7 +28,7 @@ public:
Error
open
(
int
n_channels
,
int
sample_rate
,
int
bit_depth
,
size_t
n_frames
);
Error
write_frames
(
const
std
::
vector
<
float
>&
frames
)
override
;
void
close
();
Error
close
();
int
sample_rate
()
const
override
;
int
bit_depth
()
const
override
;
int
n_channels
()
const
override
;
...
...
src/wmadd.cc
View file @
45e64803
...
...
@@ -718,6 +718,11 @@ add_watermark (const string& infile, const string& outfile, const string& bits)
total_output_frames
+=
samples
.
size
()
/
n_channels
;
}
fprintf
(
stderr
,
"total output: %zd, expected: %zd
\n
"
,
total_output_frames
,
in_stream
->
n_frames
());
Error
err
=
out_stream
->
close
();
if
(
err
)
error
(
"audiowmark: closing output stream failed: %s
\n
"
,
err
.
message
());
#if 0
if (Params::snr)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment