diff --git a/webrtc/modules/audio_coding/neteq/tools/neteq_rtpplay.cc b/webrtc/modules/audio_coding/neteq/tools/neteq_rtpplay.cc index 0aaf8c71fd..adce1cfd79 100644 --- a/webrtc/modules/audio_coding/neteq/tools/neteq_rtpplay.cc +++ b/webrtc/modules/audio_coding/neteq/tools/neteq_rtpplay.cc @@ -399,23 +399,12 @@ int main(int argc, char* argv[]) { printf("Input file: %s\n", argv[1]); - // TODO(ivoc): Modify the RtpFileSource::Create and RtcEventLogSource::Create - // functions to return a nullptr on failure instead of crashing - // the program. - - // This temporary solution uses a RtpFileReader directly to check if the file - // is a valid RtpDump file. bool is_rtp_dump = false; - { - rtc::scoped_ptr rtp_reader( - webrtc::test::RtpFileReader::Create( - webrtc::test::RtpFileReader::kRtpDump, argv[1])); - if (rtp_reader) - is_rtp_dump = true; - } rtc::scoped_ptr file_source; webrtc::test::RtcEventLogSource* event_log_source = nullptr; - if (is_rtp_dump) { + if (webrtc::test::RtpFileSource::ValidRtpDump(argv[1]) || + webrtc::test::RtpFileSource::ValidPcap(argv[1])) { + is_rtp_dump = true; file_source.reset(webrtc::test::RtpFileSource::Create(argv[1])); } else { event_log_source = webrtc::test::RtcEventLogSource::Create(argv[1]); diff --git a/webrtc/modules/audio_coding/neteq/tools/rtp_file_source.cc b/webrtc/modules/audio_coding/neteq/tools/rtp_file_source.cc index 9681ad17ea..e3a829bd24 100644 --- a/webrtc/modules/audio_coding/neteq/tools/rtp_file_source.cc +++ b/webrtc/modules/audio_coding/neteq/tools/rtp_file_source.cc @@ -32,6 +32,18 @@ RtpFileSource* RtpFileSource::Create(const std::string& file_name) { return source; } +bool RtpFileSource::ValidRtpDump(const std::string& file_name) { + rtc::scoped_ptr temp_file( + RtpFileReader::Create(RtpFileReader::kRtpDump, file_name)); + return !!temp_file; +} + +bool RtpFileSource::ValidPcap(const std::string& file_name) { + rtc::scoped_ptr temp_file( + RtpFileReader::Create(RtpFileReader::kPcap, file_name)); + return !!temp_file; +} + RtpFileSource::~RtpFileSource() { } diff --git a/webrtc/modules/audio_coding/neteq/tools/rtp_file_source.h b/webrtc/modules/audio_coding/neteq/tools/rtp_file_source.h index d0856a819c..cd7d7e874c 100644 --- a/webrtc/modules/audio_coding/neteq/tools/rtp_file_source.h +++ b/webrtc/modules/audio_coding/neteq/tools/rtp_file_source.h @@ -34,6 +34,10 @@ class RtpFileSource : public PacketSource { // opened, or has the wrong format, NULL will be returned. static RtpFileSource* Create(const std::string& file_name); + // Checks whether a files is a valid RTP dump or PCAP (Wireshark) file. + static bool ValidRtpDump(const std::string& file_name); + static bool ValidPcap(const std::string& file_name); + virtual ~RtpFileSource(); // Registers an RTP header extension and binds it to |id|.