Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -481,14 +481,17 @@ public static void createVideoMediaCodecBridge(
boolean shouldConfigureHdr =
colorInfo != null && MediaCodecUtil.isHdrCapableVideoDecoder(mime, codecCapabilities);
if (shouldConfigureHdr) {
Log.d(TAG, "Setting HDR info.");
Log.d(TAG, "Setting color info.");
mediaFormat.setInteger(MediaFormat.KEY_COLOR_TRANSFER, colorInfo.colorTransfer);
mediaFormat.setInteger(MediaFormat.KEY_COLOR_STANDARD, colorInfo.colorStandard);
// If color range is unspecified, don't set it.
if (colorInfo.colorRange != 0) {
mediaFormat.setInteger(MediaFormat.KEY_COLOR_RANGE, colorInfo.colorRange);
}
mediaFormat.setByteBuffer(MediaFormat.KEY_HDR_STATIC_INFO, colorInfo.hdrStaticInfo);
// Only set HDR static metadata for HDR transfer functions (6 = ST2084, 7 = HLG)
if (colorInfo.colorTransfer == 6 || colorInfo.colorTransfer == 7) {
mediaFormat.setByteBuffer(MediaFormat.KEY_HDR_STATIC_INFO, colorInfo.hdrStaticInfo);
}
}

if (tunnelModeAudioSessionId != TunnelModeAudioSessionId.NONE) {
Expand Down
5 changes: 5 additions & 0 deletions media/base/audio_decoder_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,12 @@ std::string AudioDecoderConfig::AsHumanReadableString() const {
<< ", target_output_channel_layout: "
<< ChannelLayoutToString(target_output_channel_layout())
<< ", target_output_sample_format: "
#if BUILDFLAG(USE_STARBOARD_MEDIA)
<< SampleFormatToString(target_output_sample_format())
<< ", is_change_type_transition: " << base::ToString(is_change_type_transition());
#else // BUILDFLAG(USE_STARBOARD_MEDIA)
<< SampleFormatToString(target_output_sample_format());
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
return s.str();
}

Expand Down
11 changes: 11 additions & 0 deletions media/base/audio_decoder_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ class MEDIA_EXPORT AudioDecoderConfig {
return target_output_sample_format_;
}

#if BUILDFLAG(USE_STARBOARD_MEDIA)
void set_is_change_type_transition(bool value) { is_change_type_transition_ = value; }
bool is_change_type_transition() const { return is_change_type_transition_; }
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)

private:
// WARNING: When modifying or adding any parameters, update the following:
// - AudioDecoderConfig::AsHumanReadableString()
Expand Down Expand Up @@ -171,6 +176,12 @@ class MEDIA_EXPORT AudioDecoderConfig {
// be manually set in `SetChannelsForDiscrete()`;
int channels_ = 0;

#if BUILDFLAG(USE_STARBOARD_MEDIA)
// Designates whether the received config was caused by a
// SourceBuffer.changeType() call.
bool is_change_type_transition_ = false;
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)

// Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
// generated copy constructor and assignment operator. Since the extra data is
// typically small, the performance impact is minimal.
Expand Down
4 changes: 4 additions & 0 deletions media/base/video_decoder_config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ std::string VideoDecoderConfig::AsHumanReadableString() const {
<< ", encryption scheme: " << encryption_scheme()
<< ", rotation: " << VideoRotationToString(video_transformation().rotation)
<< ", flipped: " << video_transformation().mirrored
#if BUILDFLAG(USE_STARBOARD_MEDIA)
<< ", is_change_type_transition: "
<< base::ToString(is_change_type_transition())
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
<< ", color space: " << color_space_info().ToGfxColorSpace().ToString();

if (hdr_metadata().has_value()) {
Expand Down
11 changes: 11 additions & 0 deletions media/base/video_decoder_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,11 @@ class MEDIA_EXPORT VideoDecoderConfig {
// useful for decryptors that decrypts an encrypted stream to a clear stream.
void SetIsEncrypted(bool is_encrypted);

#if BUILDFLAG(USE_STARBOARD_MEDIA)
void set_is_change_type_transition(bool value) { is_change_type_transition_ = value; }
bool is_change_type_transition() const { return is_change_type_transition_; }
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)

private:
VideoCodec codec_ = VideoCodec::kUnknown;
VideoCodecProfile profile_ = VIDEO_CODEC_PROFILE_UNKNOWN;
Expand All @@ -190,6 +195,12 @@ class MEDIA_EXPORT VideoDecoderConfig {
VideoColorSpace color_space_info_;
std::optional<gfx::HDRMetadata> hdr_metadata_;

#if BUILDFLAG(USE_STARBOARD_MEDIA)
// Designates whether the received config was caused by a
// SourceBuffer.changeType() call.
bool is_change_type_transition_ = false;

#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
// Not using DISALLOW_COPY_AND_ASSIGN here intentionally to allow the compiler
// generated copy constructor and assignment operator. Since the extra data is
// typically small, the performance impact is minimal.
Expand Down
4 changes: 4 additions & 0 deletions media/filters/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ source_set("filters") {
"//ui/gfx/geometry:geometry",
]

if (use_starboard_media) {
deps += [ "//starboard:starboard_headers_only" ]
}

libs = []

if (proprietary_codecs) {
Expand Down
60 changes: 60 additions & 0 deletions media/filters/chunk_demuxer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#if BUILDFLAG(USE_STARBOARD_MEDIA)
#include "base/containers/contains.h"
#include "base/strings/string_split.h"
#include "starboard/media.h" // nogncheck
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)

namespace {
Expand Down Expand Up @@ -338,8 +339,14 @@ void ChunkDemuxerStream::UnmarkEndOfStream() {
// DemuxerStream methods.
#if BUILDFLAG(USE_STARBOARD_MEDIA)
std::string ChunkDemuxerStream::mime_type() const {
base::AutoLock auto_lock(lock_);
return mime_type_;
}

void ChunkDemuxerStream::SetMimeType(std::string_view mime_type) {
base::AutoLock auto_lock(lock_);
mime_type_ = mime_type;
}
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)

void ChunkDemuxerStream::Read(uint32_t count, ReadCB read_cb) {
Expand Down Expand Up @@ -1276,6 +1283,58 @@ void ChunkDemuxer::Remove(const std::string& id,
host_->OnBufferedTimeRangesChanged(GetBufferedRanges_Locked());
}

#if BUILDFLAG(USE_STARBOARD_MEDIA)
bool ChunkDemuxer::CanChangeType(const std::string& id,
const std::string& new_mime) {
base::AutoLock auto_lock(lock_);
CHECK(IsValidId_Locked(id));

if (!supports_change_type_) {
return false;
}

auto iter = id_to_mime_map_.find(id);
std::string current_mime = iter != id_to_mime_map_.end() ? iter->second : "";

if (!SbMediaCanChangeType(current_mime.c_str(), new_mime.c_str())) {
LOG(INFO) << "Codec transition for " << current_mime << " to "
<< new_mime << " is not supported."
<< " ChunkDemuxer::CanChangeType returns false.";
return false;
}

std::string type, codecs;
if (!ParseMimeType(new_mime, &type, &codecs)) {
return false;
}

std::unique_ptr<media::StreamParser> stream_parser(
CreateParserForTypeAndCodecs(type, codecs, media_log_));
return !!stream_parser;
}

void ChunkDemuxer::ChangeType(const std::string& id,
const std::string& new_mime) {
DVLOG(1) << __func__ << " id=" << id << " new_mime=" << new_mime;

base::AutoLock auto_lock(lock_);

DCHECK(state_ == INITIALIZING || state_ == INITIALIZED) << state_;
CHECK(IsValidId_Locked(id));

std::string type, codecs;
CHECK(ParseMimeType(new_mime, &type, &codecs));

std::unique_ptr<media::StreamParser> stream_parser(
CreateParserForTypeAndCodecs(type, codecs, media_log_));
// Caller should query CanChangeType() first to protect from failing this.
DCHECK(stream_parser);

id_to_mime_map_[id] = new_mime;
source_state_map_[id]->ChangeType(
std::move(stream_parser), ExpectedCodecs(type, codecs), new_mime);
}
#else // BUILDFLAG(USE_STARBOARD_MEDIA)
bool ChunkDemuxer::CanChangeType(const std::string& id,
const std::string& content_type,
const std::string& codecs) {
Expand Down Expand Up @@ -1324,6 +1383,7 @@ void ChunkDemuxer::ChangeType(const std::string& id,
source_state_map_[id]->ChangeType(std::move(stream_parser),
ExpectedCodecs(content_type, codecs));
}
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)

double ChunkDemuxer::GetDuration() {
base::AutoLock auto_lock(lock_);
Expand Down
14 changes: 12 additions & 2 deletions media/filters/chunk_demuxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
#include "media/filters/source_buffer_stream.h"
#include "media/filters/stream_parser_factory.h"

#if BUILDFLAG(USE_STARBOARD_MEDIA)
#include <string_view>
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)

namespace media {

class SourceBufferStream;
Expand Down Expand Up @@ -88,6 +92,7 @@ class MEDIA_EXPORT ChunkDemuxerStream : public DemuxerStream {
// Returns the latest presentation timestamp of the buffers queued in the
// stream.
base::TimeDelta GetWriteHead() const;
void SetMimeType(std::string_view mime_type);
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)

void OnMemoryPressure(
Expand Down Expand Up @@ -191,7 +196,7 @@ class MEDIA_EXPORT ChunkDemuxerStream : public DemuxerStream {
GetPendingBuffers_Locked() EXCLUSIVE_LOCKS_REQUIRED(lock_);

#if BUILDFLAG(USE_STARBOARD_MEDIA)
const std::string mime_type_;
std::string mime_type_ GUARDED_BY(lock_);
base::TimeDelta write_head_ GUARDED_BY(lock_);
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)

Expand Down Expand Up @@ -299,9 +304,12 @@ class MEDIA_EXPORT ChunkDemuxer : public Demuxer {
#endif

#if BUILDFLAG(USE_STARBOARD_MEDIA)
// Special version of AddId() that retains the |mime_type| from the web app.
// Special versions of AddId(), CanChangeType(), and ChangeType() that retain
// the |mime_type| from the web app.
[[nodiscard]] Status AddId(const std::string& id,
const std::string& mime_type);
bool CanChangeType(const std::string& id, const std::string& new_mime);
void ChangeType(const std::string& id, const std::string& new_mime);
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)

// Notifies a caller via `tracks_updated_cb` that the set of media tracks
Expand Down Expand Up @@ -398,6 +406,7 @@ class MEDIA_EXPORT ChunkDemuxer : public Demuxer {
void Remove(const std::string& id, base::TimeDelta start,
base::TimeDelta end);

#if !BUILDFLAG(USE_STARBOARD_MEDIA)
// Returns whether or not the source buffer associated with |id| can change
// its parser type to one which parses |content_type| and |codecs|.
// |content_type| indicates the ContentType of the MIME type for the data that
Expand All @@ -417,6 +426,7 @@ class MEDIA_EXPORT ChunkDemuxer : public Demuxer {
void ChangeType(const std::string& id,
const std::string& content_type,
const std::string& codecs);
#endif // !BUILDFLAG(USE_STARBOARD_MEDIA)

// If the buffer is full, attempts to try to free up space, as specified in
// the "Coded Frame Eviction Algorithm" in the Media Source Extensions Spec.
Expand Down
29 changes: 29 additions & 0 deletions media/filters/source_buffer_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,16 @@ void SourceBufferState::Init(StreamParser::InitCB init_cb,
InitializeParser(expected_codecs);
}

#if BUILDFLAG(USE_STARBOARD_MEDIA)
void SourceBufferState::ChangeType(
std::unique_ptr<StreamParser> new_stream_parser,
const std::string& new_expected_codecs,
const std::string& new_mime_type) {
#else // BUILDFLAG(USE_STARBOARD_MEDIA)
void SourceBufferState::ChangeType(
std::unique_ptr<StreamParser> new_stream_parser,
const std::string& new_expected_codecs) {
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
DCHECK_GE(state_, PENDING_PARSER_CONFIG);
DCHECK_NE(state_, PENDING_PARSER_INIT);
DCHECK(!parsing_media_segment_);
Expand All @@ -177,6 +184,14 @@ void SourceBufferState::ChangeType(
state_ = PENDING_PARSER_RECONFIG;

stream_parser_ = std::move(new_stream_parser);
#if BUILDFLAG(USE_STARBOARD_MEDIA)
for (auto& stream : audio_streams_) {
stream.second->SetMimeType(new_mime_type);
}
for (auto& stream : video_streams_) {
stream.second->SetMimeType(new_mime_type);
}
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
InitializeParser(new_expected_codecs);
}

Expand Down Expand Up @@ -666,6 +681,13 @@ bool SourceBufferState::OnNewConfigs(std::unique_ptr<MediaTracks> tracks) {
}

track->set_id(stream->media_track_id());
#if BUILDFLAG(USE_STARBOARD_MEDIA)
// Currently, |PENDING_PARSER_RECONFIG| is only set when a changeType
// call occurs, so we're safe to update the config's value.
if (state_ == PENDING_PARSER_RECONFIG) {
audio_config.set_is_change_type_transition(true);
}
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
frame_processor_->OnPossibleAudioConfigUpdate(audio_config);
success &= stream->UpdateAudioConfig(audio_config, allow_codec_changes,
media_log_);
Expand Down Expand Up @@ -751,6 +773,13 @@ bool SourceBufferState::OnNewConfigs(std::unique_ptr<MediaTracks> tracks) {
}

track->set_id(stream->media_track_id());
#if BUILDFLAG(USE_STARBOARD_MEDIA)
// Currently, |PENDING_PARSER_RECONFIG| is only set when a changeType
// call occurs, so we're safe to update the config's value.
if (state_ == PENDING_PARSER_RECONFIG) {
video_config.set_is_change_type_transition(true);
}
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
success &= stream->UpdateVideoConfig(video_config, allow_codec_changes,
media_log_);
} else {
Expand Down
6 changes: 6 additions & 0 deletions media/filters/source_buffer_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,14 @@ class MEDIA_EXPORT SourceBufferState {
// Reconfigures this source buffer to use |new_stream_parser|. Caller must
// first ensure that ResetParserState() was done to flush any pending frames
// from the old stream parser.
#if BUILDFLAG(USE_STARBOARD_MEDIA)
void ChangeType(std::unique_ptr<StreamParser> new_stream_parser,
const std::string& new_expected_codecs,
const std::string& new_mime_type);
#else // BUILDFLAG(USE_STARBOARD_MEDIA)
void ChangeType(std::unique_ptr<StreamParser> new_stream_parser,
const std::string& new_expected_codecs);
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)

// Appends media data to the StreamParser, but no parsing is done of it yet,
// just buffering the media data for future parsing via RunSegmentParserLoop()
Expand Down
19 changes: 19 additions & 0 deletions media/mojo/clients/mojo_demuxer_stream_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,23 @@ void MojoDemuxerStreamImpl::OnBufferReady(
NOTREACHED() << "Unsupported config change encountered for type: "
<< stream_->type();
}
#if BUILDFLAG(USE_STARBOARD_MEDIA)
std::optional<std::string> mime_type = stream_->mime_type();
std::move(callback).Run(Status::kConfigChanged, {}, audio_config,
video_config, mime_type);
#else // BUILDFLAG(USE_STARBOARD_MEDIA)
std::move(callback).Run(Status::kConfigChanged, {}, audio_config,
video_config);
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
return;
}

if (status == Status::kAborted) {
#if BUILDFLAG(USE_STARBOARD_MEDIA)
std::move(callback).Run(Status::kAborted, {}, audio_config, video_config, /*mime_type=*/std::nullopt);
#else // BUILDFLAG(USE_STARBOARD_MEDIA)
std::move(callback).Run(Status::kAborted, {}, audio_config, video_config);
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
return;
}

Expand All @@ -110,7 +120,11 @@ void MojoDemuxerStreamImpl::OnBufferReady(
mojom::DecoderBufferPtr mojo_buffer =
mojo_decoder_buffer_writer_->WriteDecoderBuffer(std::move(buffer));
if (!mojo_buffer) {
#if BUILDFLAG(USE_STARBOARD_MEDIA)
std::move(callback).Run(Status::kAborted, {}, audio_config, video_config, /*mime_type=*/std::nullopt);
#else // BUILDFLAG(USE_STARBOARD_MEDIA)
std::move(callback).Run(Status::kAborted, {}, audio_config, video_config);
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
return;
}
output_mojo_buffers.emplace_back(std::move(mojo_buffer));
Expand All @@ -119,8 +133,13 @@ void MojoDemuxerStreamImpl::OnBufferReady(
// TODO(dalecurtis): Once we can write framed data to the DataPipe, fill via
// the producer handle and then read more to keep the pipe full. Waiting for
// space can be accomplished using an AsyncWaiter.
#if BUILDFLAG(USE_STARBOARD_MEDIA)
std::move(callback).Run(status, std::move(output_mojo_buffers), audio_config,
video_config, /*mime_type=*/std::nullopt);
#else // BUILDFLAG(USE_STARBOARD_MEDIA)
std::move(callback).Run(status, std::move(output_mojo_buffers), audio_config,
video_config);
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
}

} // namespace media
3 changes: 3 additions & 0 deletions media/mojo/mojom/audio_decoder_config_mojom_traits.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ bool StructTraits<media::mojom::AudioDecoderConfigDataView,
output->Initialize(codec, sample_format, channel_layout,
input.samples_per_second(), std::move(extra_data),
encryption_scheme, seek_preroll, input.codec_delay());
#if BUILDFLAG(USE_STARBOARD_MEDIA)
output->set_is_change_type_transition(input.is_change_type_transition());
#endif // BUILDFLAG(USE_STARBOARD_MEDIA)
output->set_profile(profile);
output->set_target_output_channel_layout(target_output_channel_layout);
output->set_target_output_sample_format(target_output_sample_format);
Expand Down
Loading
Loading