From 5d71d8cc9f447dc9747a0222a1531c0a2cb36503 Mon Sep 17 00:00:00 2001 From: Kongqun Yang Date: Tue, 28 Mar 2017 12:31:32 -0700 Subject: [PATCH] Move demuxer.cc/h to packager/media/demuxer - Also fix the misleading error if an invalid input is provided The command line app now correctly reports that the file is not found instead of stream not available. Change-Id: I8cfccb62d7a50de57766666f126cf061e3df5ded --- packager/app/packager_main.cc | 2 +- packager/media/base/media_base.gyp | 2 - packager/media/{base => demuxer}/demuxer.cc | 4 +- packager/media/demuxer/demuxer.gyp | 42 +++++++++++++++++++++ packager/media/{base => demuxer}/demuxer.h | 0 packager/media/demuxer/demuxer_unittest.cc | 22 +++++++++++ packager/media/test/packager_test.cc | 2 +- packager/packager.gyp | 3 ++ 8 files changed, 72 insertions(+), 5 deletions(-) rename packager/media/{base => demuxer}/demuxer.cc (99%) create mode 100644 packager/media/demuxer/demuxer.gyp rename packager/media/{base => demuxer}/demuxer.h (100%) create mode 100644 packager/media/demuxer/demuxer_unittest.cc diff --git a/packager/app/packager_main.cc b/packager/app/packager_main.cc index 6c68868e09..eff0038aaa 100644 --- a/packager/app/packager_main.cc +++ b/packager/app/packager_main.cc @@ -29,13 +29,13 @@ #include "packager/hls/base/hls_notifier.h" #include "packager/hls/base/simple_hls_notifier.h" #include "packager/media/base/container_names.h" -#include "packager/media/base/demuxer.h" #include "packager/media/base/fourccs.h" #include "packager/media/base/key_source.h" #include "packager/media/base/muxer_options.h" #include "packager/media/base/muxer_util.h" #include "packager/media/chunking/chunking_handler.h" #include "packager/media/crypto/encryption_handler.h" +#include "packager/media/demuxer/demuxer.h" #include "packager/media/event/hls_notify_muxer_listener.h" #include "packager/media/event/mpd_notify_muxer_listener.h" #include "packager/media/event/vod_media_info_dump_muxer_listener.h" diff --git a/packager/media/base/media_base.gyp b/packager/media/base/media_base.gyp index 9fb2d46000..283bcef768 100644 --- a/packager/media/base/media_base.gyp +++ b/packager/media/base/media_base.gyp @@ -37,8 +37,6 @@ 'closure_thread.h', 'container_names.cc', 'container_names.h', - 'demuxer.cc', - 'demuxer.h', 'decrypt_config.cc', 'decrypt_config.h', 'decryptor_source.cc', diff --git a/packager/media/base/demuxer.cc b/packager/media/demuxer/demuxer.cc similarity index 99% rename from packager/media/base/demuxer.cc rename to packager/media/demuxer/demuxer.cc index 8f59c4676b..6751b29d1d 100644 --- a/packager/media/base/demuxer.cc +++ b/packager/media/demuxer/demuxer.cc @@ -4,7 +4,7 @@ // license that can be found in the LICENSE file or at // https://developers.google.com/open-source/licenses/bsd -#include "packager/media/base/demuxer.h" +#include "packager/media/demuxer/demuxer.h" #include @@ -95,6 +95,8 @@ Status Demuxer::Run() { // info. if (all_streams_ready_ && output_handlers().empty()) return Status::OK; + if (!status.ok()) + return status; // Check if all specified outputs exists. for (const auto& pair : output_handlers()) { if (std::find(stream_indexes_.begin(), stream_indexes_.end(), pair.first) == diff --git a/packager/media/demuxer/demuxer.gyp b/packager/media/demuxer/demuxer.gyp new file mode 100644 index 0000000000..36177edfd4 --- /dev/null +++ b/packager/media/demuxer/demuxer.gyp @@ -0,0 +1,42 @@ +# Copyright 2017 Google Inc. All rights reserved. +# +# Use of this source code is governed by a BSD-style +# license that can be found in the LICENSE file or at +# https://developers.google.com/open-source/licenses/bsd + +{ + 'includes': [ + '../../common.gypi', + ], + 'targets': [ + { + 'target_name': 'demuxer', + 'type': '<(component)', + 'sources': [ + 'demuxer.cc', + 'demuxer.h', + ], + 'dependencies': [ + '../base/media_base.gyp:media_base', + '../formats/mp2t/mp2t.gyp:mp2t', + '../formats/mp4/mp4.gyp:mp4', + '../formats/mpeg/mpeg.gyp:mpeg', + '../formats/webm/webm.gyp:webm', + '../formats/webvtt/webvtt.gyp:webvtt', + '../formats/wvm/wvm.gyp:wvm', + ], + }, + { + 'target_name': 'demuxer_unittest', + 'type': '<(gtest_target_type)', + 'sources': [ + 'demuxer_unittest.cc', + ], + 'dependencies': [ + '../../testing/gtest.gyp:gtest', + '../test/media_test.gyp:media_test_support', + 'demuxer', + ] + }, + ], +} diff --git a/packager/media/base/demuxer.h b/packager/media/demuxer/demuxer.h similarity index 100% rename from packager/media/base/demuxer.h rename to packager/media/demuxer/demuxer.h diff --git a/packager/media/demuxer/demuxer_unittest.cc b/packager/media/demuxer/demuxer_unittest.cc new file mode 100644 index 0000000000..2421f2900e --- /dev/null +++ b/packager/media/demuxer/demuxer_unittest.cc @@ -0,0 +1,22 @@ +// Copyright 2017 Google Inc. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file or at +// https://developers.google.com/open-source/licenses/bsd + +#include "packager/media/demuxer/demuxer.h" + +#include + +namespace shaka { +namespace media { + +TEST(DemuxerTest, FileNotFound) { + Demuxer demuxer("file_not_exist.mp4"); + EXPECT_EQ(error::FILE_FAILURE, demuxer.Run().error_code()); +} + +// TODO(kqyang): Add more tests. + +} // namespace media +} // namespace shaka diff --git a/packager/media/test/packager_test.cc b/packager/media/test/packager_test.cc index ed428839eb..e45e0ee6a6 100644 --- a/packager/media/test/packager_test.cc +++ b/packager/media/test/packager_test.cc @@ -10,7 +10,6 @@ #include "packager/base/strings/string_number_conversions.h" #include "packager/base/strings/stringprintf.h" #include "packager/base/time/clock.h" -#include "packager/media/base/demuxer.h" #include "packager/media/base/fixed_key_source.h" #include "packager/media/base/fourccs.h" #include "packager/media/base/muxer.h" @@ -19,6 +18,7 @@ #include "packager/media/base/test/status_test_util.h" #include "packager/media/chunking/chunking_handler.h" #include "packager/media/crypto/encryption_handler.h" +#include "packager/media/demuxer/demuxer.h" #include "packager/media/formats/mp4/mp4_muxer.h" #include "packager/media/test/test_data_util.h" diff --git a/packager/packager.gyp b/packager/packager.gyp index 09a21fde6e..c91cdc8d28 100644 --- a/packager/packager.gyp +++ b/packager/packager.gyp @@ -45,6 +45,7 @@ 'hls/hls.gyp:hls_builder', 'media/codecs/codecs.gyp:codecs', 'media/chunking/chunking.gyp:chunking', + 'media/demuxer/demuxer.gyp:demuxer', 'media/event/media_event.gyp:media_event', 'media/file/file.gyp:file', 'media/formats/mp2t/mp2t.gyp:mp2t', @@ -89,6 +90,7 @@ 'dependencies': [ 'media/codecs/codecs.gyp:codecs', 'media/chunking/chunking.gyp:chunking', + 'media/demuxer/demuxer.gyp:demuxer', 'media/file/file.gyp:file', 'media/formats/mp2t/mp2t.gyp:mp2t', 'media/formats/mp4/mp4.gyp:mp4', @@ -122,6 +124,7 @@ 'media/chunking/chunking.gyp:chunking_unittest', 'media/codecs/codecs.gyp:codecs_unittest', 'media/crypto/crypto.gyp:crypto_unittest', + 'media/demuxer/demuxer.gyp:demuxer_unittest', 'media/event/media_event.gyp:media_event_unittest', 'media/file/file.gyp:file_unittest', 'media/formats/mp2t/mp2t.gyp:mp2t_unittest',