Commit 5c41616f authored by Matt Wolenetz's avatar Matt Wolenetz Committed by Commit Bot

MSE: Rename ChunkDemuxer::CanChangeTypeTo and other small clean-up

Renames this method, and renames its |type| parameter to |content_type|.
Similarly renames ChunkDemuxer::AddId, ChangeType, and static helper
methods' |type| parameter to |content_type|.

BUG=605134

Cq-Include-Trybots: luci.chromium.try:android_optional_gpu_tests_rel;luci.chromium.try:linux_optional_gpu_tests_rel;luci.chromium.try:mac_optional_gpu_tests_rel;luci.chromium.try:win_optional_gpu_tests_rel
Change-Id: I8b94452732a39157b5ddeba9e563f69aee033690
Reviewed-on: https://chromium-review.googlesource.com/1115704Reviewed-by: default avatarDan Sanders <sandersd@chromium.org>
Commit-Queue: Matthew Wolenetz <wolenetz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570554}
parent 40f45461
......@@ -165,7 +165,7 @@ void WebSourceBufferImpl::Remove(double start, double end) {
bool WebSourceBufferImpl::CanChangeType(const blink::WebString& content_type,
const blink::WebString& codecs) {
return demuxer_->CanChangeTypeTo(id_, content_type.Utf8(), codecs.Utf8());
return demuxer_->CanChangeType(id_, content_type.Utf8(), codecs.Utf8());
}
void WebSourceBufferImpl::ChangeType(const blink::WebString& content_type,
......
......@@ -54,26 +54,29 @@ using base::TimeDelta;
namespace {
// Helper to attempt construction of a StreamParser specific to |type| and
// |codecs|.
// Helper to attempt construction of a StreamParser specific to |content_type|
// and |codecs|.
// TODO(wolenetz): Consider relocating this to StreamParserFactory in
// conjunction with updating StreamParserFactory's isTypeSupported() to also
// parse codecs, rather than require preparsed vector.
std::unique_ptr<media::StreamParser> CreateParserForTypeAndCodecs(
const std::string& type,
const std::string& content_type,
const std::string& codecs,
media::MediaLog* media_log) {
std::vector<std::string> parsed_codec_ids;
media::SplitCodecsToVector(codecs, &parsed_codec_ids, false);
return media::StreamParserFactory::Create(type, parsed_codec_ids, media_log);
return media::StreamParserFactory::Create(content_type, parsed_codec_ids,
media_log);
}
// Helper to calculate the expected codecs parsed from initialization segments
// for a few mime types that have an implicit codec.
std::string ExpectedCodecs(const std::string& type, const std::string& codecs) {
if (codecs == "" && type == "audio/aac")
std::string ExpectedCodecs(const std::string& content_type,
const std::string& codecs) {
if (codecs == "" && content_type == "audio/aac")
return "aac";
if (codecs == "" && (type == "audio/mpeg" || type == "audio/mp3"))
if (codecs == "" &&
(content_type == "audio/mpeg" || content_type == "audio/mp3"))
return "mp3";
return codecs;
}
......@@ -644,9 +647,9 @@ void ChunkDemuxer::CancelPendingSeek(TimeDelta seek_time) {
}
ChunkDemuxer::Status ChunkDemuxer::AddId(const std::string& id,
const std::string& type,
const std::string& content_type,
const std::string& codecs) {
DVLOG(1) << __func__ << " id=" << id << " mime_type=" << type
DVLOG(1) << __func__ << " id=" << id << " content_type=" << content_type
<< " codecs=" << codecs;
base::AutoLock auto_lock(lock_);
......@@ -658,9 +661,9 @@ ChunkDemuxer::Status ChunkDemuxer::AddId(const std::string& id,
CHECK(!init_cb_.is_null());
std::unique_ptr<media::StreamParser> stream_parser(
CreateParserForTypeAndCodecs(type, codecs, media_log_));
CreateParserForTypeAndCodecs(content_type, codecs, media_log_));
if (!stream_parser) {
DVLOG(1) << __func__ << " failed: unsupported mime_type=" << type
DVLOG(1) << __func__ << " failed: unsupported content_type=" << content_type
<< " codecs=" << codecs;
return ChunkDemuxer::kNotSupported;
}
......@@ -691,7 +694,7 @@ ChunkDemuxer::Status ChunkDemuxer::AddId(const std::string& id,
source_state->Init(base::BindOnce(&ChunkDemuxer::OnSourceInitDone,
base::Unretained(this), id),
ExpectedCodecs(type, codecs),
ExpectedCodecs(content_type, codecs),
encrypted_media_init_data_cb_, new_text_track_cb);
// TODO(wolenetz): Change to DCHECKs once less verification in release build
......@@ -960,19 +963,19 @@ void ChunkDemuxer::Remove(const std::string& id, TimeDelta start,
host_->OnBufferedTimeRangesChanged(GetBufferedRanges_Locked());
}
bool ChunkDemuxer::CanChangeTypeTo(const std::string& id,
const std::string& type,
const std::string& codecs) {
// Note, Chromium currently will not compare type's codec parameters, if any,
// with previous type of the SourceBuffer.
// TODO(wolenetz): Consider returning false if the codec parameters
// are ever made to be precise such that they signal number of tracks of
bool ChunkDemuxer::CanChangeType(const std::string& id,
const std::string& content_type,
const std::string& codecs) {
// Note, Chromium currently will not compare content_type and codecs, if any,
// with previous content_type and codecs of the SourceBuffer.
// TODO(wolenetz): Consider returning false if the codecs parameters are ever
// made to be precise such that they signal that the number of tracks of
// various media types differ from the first initialization segment (if
// received already). Switching to an audio-only container, when the first
// received already). Switching to an audio-only container, when the first
// initialization segment only contained non-audio tracks, is one example we
// could enforce earlier here.
DVLOG(1) << __func__ << " id=" << id << " mime_type=" << type
DVLOG(1) << __func__ << " id=" << id << " content_type=" << content_type
<< " codecs=" << codecs;
base::AutoLock auto_lock(lock_);
......@@ -982,14 +985,14 @@ bool ChunkDemuxer::CanChangeTypeTo(const std::string& id,
// initialization segment for the source buffer corresponding to |id|.
std::unique_ptr<media::StreamParser> stream_parser(
CreateParserForTypeAndCodecs(type, codecs, media_log_));
CreateParserForTypeAndCodecs(content_type, codecs, media_log_));
return !!stream_parser;
}
void ChunkDemuxer::ChangeType(const std::string& id,
const std::string& type,
const std::string& content_type,
const std::string& codecs) {
DVLOG(1) << __func__ << " id=" << id << " mime_type=" << type
DVLOG(1) << __func__ << " id=" << id << " content_type=" << content_type
<< " codecs=" << codecs;
base::AutoLock auto_lock(lock_);
......@@ -998,11 +1001,11 @@ void ChunkDemuxer::ChangeType(const std::string& id,
DCHECK(IsValidId(id));
std::unique_ptr<media::StreamParser> stream_parser(
CreateParserForTypeAndCodecs(type, codecs, media_log_));
CreateParserForTypeAndCodecs(content_type, codecs, media_log_));
// Caller should query CanChangeType() first to protect from failing this.
DCHECK(stream_parser);
source_state_map_[id]->ChangeType(std::move(stream_parser),
ExpectedCodecs(type, codecs));
ExpectedCodecs(content_type, codecs));
}
double ChunkDemuxer::GetDuration() {
......
......@@ -222,15 +222,16 @@ class MEDIA_EXPORT ChunkDemuxer : public Demuxer {
void StartWaitingForSeek(base::TimeDelta seek_time) override;
void CancelPendingSeek(base::TimeDelta seek_time) override;
// Registers a new |id| to use for AppendData() calls. |type| indicates
// the MIME type for the data that we intend to append for this ID.
// kOk is returned if the demuxer has enough resources to support another ID
// and supports the format indicated by |type|.
// kNotSupported is returned if |type| is not a supported format.
// kReachedIdLimit is returned if the demuxer cannot handle another ID right
// now.
// Registers a new |id| to use for AppendData() calls. |content_type|
// indicates the MIME type's ContentType and |codecs| indicates the MIME
// type's "codecs" parameter string (if any) for the data that we intend to
// append for this ID. kOk is returned if the demuxer has enough resources to
// support another ID and supports the format indicated by |content_type| and
// |codecs|. kReachedIdLimit is returned if the demuxer cannot handle another
// ID right now. kNotSupported is returned if |content_type| and |codecs| is
// not a supported format.
Status AddId(const std::string& id,
const std::string& type,
const std::string& content_type,
const std::string& codecs);
// Notifies a caller via |tracks_updated_cb| that the set of media tracks
......@@ -290,20 +291,23 @@ class MEDIA_EXPORT ChunkDemuxer : public Demuxer {
base::TimeDelta end);
// Returns whether or not the source buffer associated with |id| can change
// its parser type to one which parses |type| and |codecs|. |type| indicates
// the MIME type for the data that we intend to append for this |id|.
bool CanChangeTypeTo(const std::string& id,
const std::string& type,
const std::string& codecs);
// its parser type to one which parses |content_type| and |codecs|.
// |content_type| indicates the ContentType of the MIME type for the data that
// we intend to append for this |id|; |codecs| similarly indicates the MIME
// type's "codecs" parameter, if any.
bool CanChangeType(const std::string& id,
const std::string& content_type,
const std::string& codecs);
// For the source buffer associated with |id|, changes its parser type to one
// which parses |type| and |codecs|. |type| indicates the MIME type for the
// data that we intend to append for this |id|. Caller must first ensure
// CanChangeTypeTo() returns true for the same parameters. Caller must also
// ensure that ResetParserState() is done before calling this, to flush any
// pending frames.
// which parses |content_type| and |codecs|. |content_type| indicates the
// ContentType of the MIME type for the data that we intend to append for this
// |id|; |codecs| similarly indicates the MIME type's "codecs" parameter, if
// any. Caller must first ensure CanChangeType() returns true for the same
// parameters. Caller must also ensure that ResetParserState() is done before
// calling this, to flush any pending frames.
void ChangeType(const std::string& id,
const std::string& type,
const std::string& content_type,
const std::string& codecs);
// If the buffer is full, attempts to try to free up space, as specified in
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment