Add wav output capability to neteq_rtpplay
This CL makes neteq_rtpplay capable of writing to wav files as well as pcm files. This is done through the new class OutputWavFile, which wraps a WavWriter object in an AudioSink interface. BUG=2692 R=kwiberg@webrtc.org Review URL: https://webrtc-codereview.appspot.com/32139004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7740 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@ -26,6 +26,8 @@
|
||||
#include "webrtc/modules/audio_coding/codecs/pcm16b/include/pcm16b.h"
|
||||
#include "webrtc/modules/audio_coding/neteq/interface/neteq.h"
|
||||
#include "webrtc/modules/audio_coding/neteq/tools/input_audio_file.h"
|
||||
#include "webrtc/modules/audio_coding/neteq/tools/output_audio_file.h"
|
||||
#include "webrtc/modules/audio_coding/neteq/tools/output_wav_file.h"
|
||||
#include "webrtc/modules/audio_coding/neteq/tools/packet.h"
|
||||
#include "webrtc/modules/audio_coding/neteq/tools/rtp_file_source.h"
|
||||
#include "webrtc/modules/interface/module_common_types.h"
|
||||
@ -163,7 +165,7 @@ int main(int argc, char* argv[]) {
|
||||
std::string usage = "Tool for decoding an RTP dump file using NetEq.\n"
|
||||
"Run " + program_name + " --helpshort for usage.\n"
|
||||
"Example usage:\n" + program_name +
|
||||
" input.rtp output.pcm\n";
|
||||
" input.rtp output.{pcm, wav}\n";
|
||||
google::SetUsageMessage(usage);
|
||||
google::ParseCommandLineFlags(&argc, &argv, true);
|
||||
|
||||
@ -193,13 +195,6 @@ int main(int argc, char* argv[]) {
|
||||
file_source->SelectSsrc(ssrc);
|
||||
}
|
||||
|
||||
FILE* out_file = fopen(argv[2], "wb");
|
||||
if (!out_file) {
|
||||
std::cerr << "Cannot open output file " << argv[2] << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
std::cout << "Output file: " << argv[2] << std::endl;
|
||||
|
||||
// Check if a replacement audio file was provided, and if so, open it.
|
||||
bool replace_payload = false;
|
||||
webrtc::scoped_ptr<webrtc::test::InputAudioFile> replacement_audio_file;
|
||||
@ -209,19 +204,6 @@ int main(int argc, char* argv[]) {
|
||||
replace_payload = true;
|
||||
}
|
||||
|
||||
// Enable tracing.
|
||||
webrtc::Trace::CreateTrace();
|
||||
webrtc::Trace::SetTraceFile((webrtc::test::OutputPath() +
|
||||
"neteq_trace.txt").c_str());
|
||||
webrtc::Trace::set_level_filter(webrtc::kTraceAll);
|
||||
|
||||
// Initialize NetEq instance.
|
||||
int sample_rate_hz = 16000;
|
||||
NetEq::Config config;
|
||||
config.sample_rate_hz = sample_rate_hz;
|
||||
NetEq* neteq = NetEq::Create(config);
|
||||
RegisterPayloadTypes(neteq);
|
||||
|
||||
// Read first packet.
|
||||
webrtc::scoped_ptr<webrtc::test::Packet> packet(file_source->NextPacket());
|
||||
if (!packet) {
|
||||
@ -233,6 +215,44 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
bool packet_available = true;
|
||||
|
||||
// Check the sample rate.
|
||||
int sample_rate_hz = CodecSampleRate(packet->header().payloadType);
|
||||
if (sample_rate_hz <= 0) {
|
||||
printf("Warning: Invalid sample rate from RTP packet.\n");
|
||||
webrtc::Trace::ReturnTrace();
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Open the output file now that we know the sample rate. (Rate is only needed
|
||||
// for wav files.)
|
||||
// Check output file type.
|
||||
std::string output_file_name = argv[2];
|
||||
webrtc::scoped_ptr<webrtc::test::AudioSink> output;
|
||||
if (output_file_name.size() >= 4 &&
|
||||
output_file_name.substr(output_file_name.size() - 4) == ".wav") {
|
||||
// Open a wav file.
|
||||
output.reset(
|
||||
new webrtc::test::OutputWavFile(output_file_name, sample_rate_hz));
|
||||
} else {
|
||||
// Open a pcm file.
|
||||
output.reset(new webrtc::test::OutputAudioFile(output_file_name));
|
||||
}
|
||||
|
||||
std::cout << "Output file: " << argv[2] << std::endl;
|
||||
|
||||
// Enable tracing.
|
||||
webrtc::Trace::CreateTrace();
|
||||
webrtc::Trace::SetTraceFile((webrtc::test::OutputPath() +
|
||||
"neteq_trace.txt").c_str());
|
||||
webrtc::Trace::set_level_filter(webrtc::kTraceAll);
|
||||
|
||||
// Initialize NetEq instance.
|
||||
NetEq::Config config;
|
||||
config.sample_rate_hz = sample_rate_hz;
|
||||
NetEq* neteq = NetEq::Create(config);
|
||||
RegisterPayloadTypes(neteq);
|
||||
|
||||
|
||||
// Set up variables for audio replacement if needed.
|
||||
webrtc::scoped_ptr<webrtc::test::Packet> next_packet;
|
||||
bool next_packet_available = false;
|
||||
@ -349,8 +369,7 @@ int main(int argc, char* argv[]) {
|
||||
// Write to file.
|
||||
// TODO(hlundin): Make writing to file optional.
|
||||
size_t write_len = samples_per_channel * num_channels;
|
||||
if (fwrite(out_data, sizeof(out_data[0]), write_len, out_file) !=
|
||||
write_len) {
|
||||
if (!output->WriteArray(out_data, write_len)) {
|
||||
std::cerr << "Error while writing to file" << std::endl;
|
||||
webrtc::Trace::ReturnTrace();
|
||||
exit(1);
|
||||
@ -363,7 +382,6 @@ int main(int argc, char* argv[]) {
|
||||
|
||||
std::cout << "Simulation done" << std::endl;
|
||||
|
||||
fclose(out_file);
|
||||
delete neteq;
|
||||
webrtc::Trace::ReturnTrace();
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user