Move language tag convertion to packager.cc

This fixes shared_library not able to compile problem.

Also removed StreamDescriptorList and replaced with expicit
comparison to make the code clearer.

Also removed an out-dated DCHECK that mpd_notifier and hls_notifier
does not co-exist.

Change-Id: I3d04b8880741fecf0931a764cc12e50aa5e392b9
This commit is contained in:
KongQun Yang 2017-09-29 17:45:00 -07:00
parent 9a60760815
commit 937ecfbdcd
2 changed files with 41 additions and 48 deletions

View File

@ -9,7 +9,6 @@
#include "packager/base/logging.h" #include "packager/base/logging.h"
#include "packager/base/strings/string_number_conversions.h" #include "packager/base/strings/string_number_conversions.h"
#include "packager/base/strings/string_split.h" #include "packager/base/strings/string_split.h"
#include "packager/media/base/language_utils.h"
namespace shaka { namespace shaka {
@ -107,13 +106,7 @@ base::Optional<StreamDescriptor> ParseStreamDescriptor(
break; break;
} }
case kLanguageField: { case kLanguageField: {
// TODO(kqyang): Move to packager.cc. descriptor.language = iter->second;
std::string language = LanguageToISO_639_2(iter->second);
if (language == "und") {
LOG(ERROR) << "Unknown/invalid language specified: " << iter->second;
return base::nullopt;
}
descriptor.language = language;
break; break;
} }
case kOutputFormatField: { case kOutputFormatField: {

View File

@ -6,6 +6,8 @@
#include "packager/packager.h" #include "packager/packager.h"
#include <algorithm>
#include "packager/app/libcrypto_threading.h" #include "packager/app/libcrypto_threading.h"
#include "packager/app/packager_util.h" #include "packager/app/packager_util.h"
#include "packager/app/stream_descriptor.h" #include "packager/app/stream_descriptor.h"
@ -22,6 +24,7 @@
#include "packager/media/base/container_names.h" #include "packager/media/base/container_names.h"
#include "packager/media/base/fourccs.h" #include "packager/media/base/fourccs.h"
#include "packager/media/base/key_source.h" #include "packager/media/base/key_source.h"
#include "packager/media/base/language_utils.h"
#include "packager/media/base/muxer_options.h" #include "packager/media/base/muxer_options.h"
#include "packager/media/base/muxer_util.h" #include "packager/media/base/muxer_util.h"
#include "packager/media/chunking/chunking_handler.h" #include "packager/media/chunking/chunking_handler.h"
@ -208,30 +211,24 @@ Status ValidateParams(const PackagingParams& packaging_params,
return Status::OK; return Status::OK;
} }
class StreamDescriptorCompareFn { bool StreamDescriptorCompareFn(const StreamDescriptor& a,
public: const StreamDescriptor& b) {
bool operator()(const StreamDescriptor& a, const StreamDescriptor& b) { if (a.input == b.input) {
if (a.input == b.input) { if (a.stream_selector == b.stream_selector) {
if (a.stream_selector == b.stream_selector) { // The MPD notifier requires that the main track comes first, so make
// The MPD notifier requires that the main track comes first, so make // sure that happens.
// sure that happens. if (a.trick_play_factor == 0 || b.trick_play_factor == 0) {
if (a.trick_play_factor == 0 || b.trick_play_factor == 0) { return a.trick_play_factor == 0;
return a.trick_play_factor == 0;
} else {
return a.trick_play_factor > b.trick_play_factor;
}
} else { } else {
return a.stream_selector < b.stream_selector; return a.trick_play_factor > b.trick_play_factor;
} }
} else {
return a.stream_selector < b.stream_selector;
} }
return a.input < b.input;
} }
};
/// Sorted list of StreamDescriptor. return a.input < b.input;
typedef std::multiset<StreamDescriptor, StreamDescriptorCompareFn> }
StreamDescriptorList;
// A fake clock that always return time 0 (epoch). Should only be used for // A fake clock that always return time 0 (epoch). Should only be used for
// testing. // testing.
@ -440,15 +437,13 @@ std::shared_ptr<MediaHandler> CreateEncryptionHandler(
return std::make_shared<EncryptionHandler>(encryption_params, key_source); return std::make_shared<EncryptionHandler>(encryption_params, key_source);
} }
Status CreateRemuxJobs(const StreamDescriptorList& stream_descriptors, Status CreateRemuxJobs(const std::vector<StreamDescriptor> stream_descriptors,
const PackagingParams& packaging_params, const PackagingParams& packaging_params,
FakeClock* fake_clock, FakeClock* fake_clock,
KeySource* encryption_key_source, KeySource* encryption_key_source,
MpdNotifier* mpd_notifier, MpdNotifier* mpd_notifier,
hls::HlsNotifier* hls_notifier, hls::HlsNotifier* hls_notifier,
std::vector<std::unique_ptr<Job>>* jobs) { std::vector<std::unique_ptr<Job>>* jobs) {
// No notifiers OR (mpd_notifier XOR hls_notifier); which is NAND.
DCHECK(!(mpd_notifier && hls_notifier));
DCHECK(jobs); DCHECK(jobs);
// Demuxers are shared among all streams with the same input. // Demuxers are shared among all streams with the same input.
@ -737,29 +732,34 @@ Status Packager::Initialize(
master_playlist_name.AsUTF8Unsafe())); master_playlist_name.AsUTF8Unsafe()));
} }
media::StreamDescriptorList stream_descriptor_list; std::vector<StreamDescriptor> stream_descriptors_copy = stream_descriptors;
for (const StreamDescriptor& descriptor : stream_descriptors) { std::sort(stream_descriptors_copy.begin(), stream_descriptors_copy.end(),
if (internal->buffer_callback_params.read_func || media::StreamDescriptorCompareFn);
internal->buffer_callback_params.write_func) { for (StreamDescriptor& descriptor : stream_descriptors_copy) {
StreamDescriptor descriptor_copy = descriptor; if (internal->buffer_callback_params.read_func) {
if (internal->buffer_callback_params.read_func) { descriptor.input = File::MakeCallbackFileName(
descriptor_copy.input = File::MakeCallbackFileName( internal->buffer_callback_params, descriptor.input);
internal->buffer_callback_params, descriptor.input); }
if (internal->buffer_callback_params.write_func) {
descriptor.output = File::MakeCallbackFileName(
internal->buffer_callback_params, descriptor.output);
descriptor.segment_template = File::MakeCallbackFileName(
internal->buffer_callback_params, descriptor.segment_template);
}
// Update language to ISO_639_2 code if set.
if (!descriptor.language.empty()) {
descriptor.language = LanguageToISO_639_2(descriptor.language);
if (descriptor.language == "und") {
return Status(
error::INVALID_ARGUMENT,
"Unknown/invalid language specified: " + descriptor.language);
} }
if (internal->buffer_callback_params.write_func) {
descriptor_copy.output = File::MakeCallbackFileName(
internal->buffer_callback_params, descriptor.output);
descriptor_copy.segment_template = File::MakeCallbackFileName(
internal->buffer_callback_params, descriptor.segment_template);
}
stream_descriptor_list.insert(descriptor_copy);
} else {
stream_descriptor_list.insert(descriptor);
} }
} }
Status status = media::CreateRemuxJobs( Status status = media::CreateRemuxJobs(
stream_descriptor_list, packaging_params, &internal->fake_clock, stream_descriptors_copy, packaging_params, &internal->fake_clock,
internal->encryption_key_source.get(), internal->mpd_notifier.get(), internal->encryption_key_source.get(), internal->mpd_notifier.get(),
internal->hls_notifier.get(), &internal->jobs); internal->hls_notifier.get(), &internal->jobs);