Skip to content

Commit

Permalink
[media] Fix non-guarded customizations in //third_party/chromium/media
Browse files Browse the repository at this point in the history
All modification to Chromium media code is guarded by `#if defined(STARBOARD)`.

b/329702113
  • Loading branch information
borongc committed Mar 26, 2024
1 parent 1821279 commit eafedd1
Show file tree
Hide file tree
Showing 36 changed files with 160 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if !defined(STARBOARD)
#error "This file only works with Cobalt/Starboard."
#endif // !defined(STARBOARD)

#include "media/base/demuxer_memory_limit.h"

#include "media/base/decoder_buffer.h"
Expand Down
6 changes: 3 additions & 3 deletions third_party/chromium/media/base/demuxer_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class MEDIA_EXPORT DemuxerStream {

#if defined(STARBOARD)
virtual std::string mime_type() const { return ""; }
#endif // defined (STARBOARD)
#endif // defined(STARBOARD)

// Request a buffer to returned via the provided callback.
//
Expand All @@ -80,10 +80,10 @@ class MEDIA_EXPORT DemuxerStream {
#if defined(STARBOARD)
typedef base::OnceCallback<void(Status, const std::vector<scoped_refptr<DecoderBuffer>>&)> ReadCB;
virtual void Read(int max_number_of_buffers_to_read, ReadCB read_cb) = 0;
#else // defined (STARBOARD)
#else // defined(STARBOARD)
typedef base::OnceCallback<void(Status, scoped_refptr<DecoderBuffer>)> ReadCB;
virtual void Read(ReadCB read_cb) = 0;
#endif // defined (STARBOARD)
#endif // defined(STARBOARD)

// Returns the audio/video decoder configuration. It is an error to call the
// audio method on a video stream and vice versa. After |kConfigChanged| is
Expand Down
4 changes: 4 additions & 0 deletions third_party/chromium/media/base/starboard_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if !defined(STARBOARD)
#error "This file only works with Cobalt/Starboard."
#endif // !defined(STARBOARD)

#include "media/base/starboard_utils.h"

#include <algorithm>
Expand Down
4 changes: 4 additions & 0 deletions third_party/chromium/media/base/starboard_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#ifndef MEDIA_BASE_STARBOARD_UTILS_H_
#define MEDIA_BASE_STARBOARD_UTILS_H_

#if !defined(STARBOARD)
#error "This file only works with Cobalt/Starboard."
#endif // !defined(STARBOARD)

#include "starboard/drm.h"
#include "starboard/media.h"
#include "media/base/audio_codecs.h"
Expand Down
4 changes: 4 additions & 0 deletions third_party/chromium/media/base/starboard_utils_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#if !defined(STARBOARD)
#error "This file only works with Cobalt/Starboard."
#endif // !defined(STARBOARD)

#include "media/base/starboard_utils.h"

#include "testing/gtest/include/gtest/gtest.h"
Expand Down
2 changes: 2 additions & 0 deletions third_party/chromium/media/base/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
#include "media/base/media_export.h"
#include "media/base/media_serializers_base.h"
#include "media/base/status_codes.h"
#if defined(STARBOARD)
#include "third_party/abseil-cpp/absl/types/optional.h"
#endif // defined(STARBOARD)

// Mojo namespaces for serialization friend declarations.
namespace mojo {
Expand Down
4 changes: 4 additions & 0 deletions third_party/chromium/media/cobalt/base/bind_post_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#ifndef BASE_BIND_POST_TASK_H_
#define BASE_BIND_POST_TASK_H_

#if !defined(STARBOARD)
#error "This file only works with Cobalt/Starboard."
#endif // !defined(STARBOARD)

#include "base/location.h"

namespace base {
Expand Down
4 changes: 4 additions & 0 deletions third_party/chromium/media/cobalt/base/check.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#ifndef BASE_CHECK_H_
#define BASE_CHECK_H_

#if !defined(STARBOARD)
#error "This file only works with Cobalt/Starboard."
#endif // !defined(STARBOARD)

#include "base/logging.h"

#endif // BASE_CHECK_H_
4 changes: 4 additions & 0 deletions third_party/chromium/media/cobalt/base/check_op.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#ifndef BASE_CHECK_OP_H_
#define BASE_CHECK_OP_H_

#if !defined(STARBOARD)
#error "This file only works with Cobalt/Starboard."
#endif // !defined(STARBOARD)

#include "base/logging.h"

#endif // BASE_CHECK_OP_H_
4 changes: 4 additions & 0 deletions third_party/chromium/media/cobalt/base/cxx17_backports.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#ifndef BASE_CXX17_BACKPORTS_H_
#define BASE_CXX17_BACKPORTS_H_

#if !defined(STARBOARD)
#error "This file only works with Cobalt/Starboard."
#endif // !defined(STARBOARD)

#include "base/stl_util.h"

#endif // BASE_CXX17_BACKPORTS_H_
4 changes: 4 additions & 0 deletions third_party/chromium/media/cobalt/base/hash/md5.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#ifndef BASE_HASH_MD5_H_
#define BASE_HASH_MD5_H_

#if !defined(STARBOARD)
#error "This file only works with Cobalt/Starboard."
#endif // !defined(STARBOARD)

#include "base/md5.h"

#endif // BASE_HASH_MD5_H_
4 changes: 4 additions & 0 deletions third_party/chromium/media/cobalt/base/notreached.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
#ifndef BASE_NOTREACHED_H_
#define BASE_NOTREACHED_H_

#if !defined(STARBOARD)
#error "This file only works with Cobalt/Starboard."
#endif // !defined(STARBOARD)

#include "base/logging.h"

#endif // BASE_NOTREACHED_H_
4 changes: 4 additions & 0 deletions third_party/chromium/media/cobalt/base/types/strong_alias.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#ifndef BASE_TYPES_STRONG_ALIAS_H_
#define BASE_TYPES_STRONG_ALIAS_H_

#if !defined(STARBOARD)
#error "This file only works with Cobalt/Starboard."
#endif // !defined(STARBOARD)

#include <ostream>
#include <type_traits>
#include <utility>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
#ifndef NET_SITE_FOR_COOKIES_H
#define NET_SITE_FOR_COOKIES_H

#if !defined(STARBOARD)
#error "This file only works with Cobalt/Starboard."
#endif // !defined(STARBOARD)

namespace net {

// Reduced version enough to make media code depending on it to be built.
Expand Down
39 changes: 15 additions & 24 deletions third_party/chromium/media/filters/chunk_demuxer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#include "base/strings/string_number_conversions.h"
#if defined(STARBOARD)
#include "base/strings/string_split.h"
#endif // defined (STARBOARD)
#endif // defined(STARBOARD)
#include "base/threading/thread_task_runner_handle.h"
#include "base/trace_event/trace_event.h"
#include "media/base/audio_decoder_config.h"
Expand Down Expand Up @@ -63,7 +63,6 @@ std::string ExpectedCodecs(const std::string& content_type,
}

#if defined(STARBOARD)

// Parse type and codecs from mime type. It will return "video/mp4" and
// "avc1.42E01E, mp4a.40.2" for "video/mp4; codecs="avc1.42E01E, mp4a.40.2".
// Note that this function does minimum validation as the media stack will check
Expand Down Expand Up @@ -95,8 +94,7 @@ bool ParseMimeType(const std::string& mime_type, std::string* type,
// underlying parsers.
return true;
}

#endif // defined (STARBOARD)
#endif // defined(STARBOARD)

} // namespace

Expand All @@ -107,10 +105,10 @@ ChunkDemuxerStream::ChunkDemuxerStream(const std::string& mime_type, Type type,
MediaTrack::Id media_track_id)
: mime_type_(mime_type),
type_(type),
#else // defined (STARBOARD)
#else // defined(STARBOARD)
ChunkDemuxerStream::ChunkDemuxerStream(Type type, MediaTrack::Id media_track_id)
: type_(type),
#endif // defined (STARBOARD)
#endif // defined(STARBOARD)
liveness_(DemuxerStream::LIVENESS_UNKNOWN),
media_track_id_(media_track_id),
state_(UNINITIALIZED),
Expand All @@ -132,9 +130,9 @@ void ChunkDemuxerStream::AbortReads() {
if (read_cb_) {
#if defined(STARBOARD)
std::move(read_cb_).Run(kAborted, {});
#else // defined (STARBOARD)
#else // defined(STARBOARD)
std::move(read_cb_).Run(kAborted, nullptr);
#endif // defined (STARBOARD)
#endif // defined(STARBOARD)
}
}

Expand All @@ -156,10 +154,10 @@ void ChunkDemuxerStream::Shutdown() {
if (read_cb_) {
#if defined(STARBOARD)
std::move(read_cb_).Run(DemuxerStream::kOk, {StreamParserBuffer::CreateEOSBuffer()});
#else // defined (STARBOARD)
#else // defined(STARBOARD)
std::move(read_cb_).Run(DemuxerStream::kOk,
StreamParserBuffer::CreateEOSBuffer());
#endif // defined (STARBOARD)
#endif // defined(STARBOARD)
}
}

Expand All @@ -182,7 +180,7 @@ void ChunkDemuxerStream::Seek(base::TimeDelta time) {

#if defined(STARBOARD)
write_head_ = time;
#endif // defined (STARBOARD)
#endif // defined(STARBOARD)
stream_->Seek(time);
}

Expand Down Expand Up @@ -229,7 +227,6 @@ bool ChunkDemuxerStream::EvictCodedFrames(base::TimeDelta media_time,
}

#if defined(STARBOARD)

base::TimeDelta ChunkDemuxerStream::GetWriteHead() const {
base::AutoLock auto_lock(lock_);
return write_head_;
Expand All @@ -246,8 +243,6 @@ void ChunkDemuxerStream::SetStreamMemoryLimitOverride(size_t memory_limit) {
base::AutoLock auto_lock(lock_);
stream_->set_memory_limit_override(memory_limit);
}


#endif // defined(STARBOARD)

void ChunkDemuxerStream::OnMemoryPressure(
Expand Down Expand Up @@ -335,9 +330,9 @@ bool ChunkDemuxerStream::UpdateAudioConfig(const AudioDecoderConfig& config,
DCHECK_EQ(state_, UNINITIALIZED);
#if defined(STARBOARD)
stream_ = std::make_unique<SourceBufferStream>(mime_type_, config, media_log);
#else // defined (STARBOARD)
#else // defined(STARBOARD)
stream_ = std::make_unique<SourceBufferStream>(config, media_log);
#endif // defined (STARBOARD)
#endif // defined(STARBOARD)
return true;
}

Expand All @@ -355,9 +350,9 @@ bool ChunkDemuxerStream::UpdateVideoConfig(const VideoDecoderConfig& config,
DCHECK_EQ(state_, UNINITIALIZED);
#if defined(STARBOARD)
stream_ = std::make_unique<SourceBufferStream>(mime_type_, config, media_log);
#else // defined (STARBOARD)
#else // defined(STARBOARD)
stream_ = std::make_unique<SourceBufferStream>(config, media_log);
#endif // defined (STARBOARD)
#endif // defined(STARBOARD)
return true;
}

Expand Down Expand Up @@ -889,7 +884,6 @@ ChunkDemuxer::Status ChunkDemuxer::AddId(const std::string& id,
}

#if defined(STARBOARD)

ChunkDemuxer::Status ChunkDemuxer::AddId(const std::string& id,
const std::string& mime_type) {
std::string type, codecs;
Expand All @@ -901,8 +895,7 @@ ChunkDemuxer::Status ChunkDemuxer::AddId(const std::string& id,
id_to_mime_map_[id] = mime_type;
return AddId(id, type, codecs);
}

#endif // defined (STARBOARD)
#endif // defined(STARBOARD)

ChunkDemuxer::Status ChunkDemuxer::AddIdInternal(
const std::string& id,
Expand Down Expand Up @@ -1107,7 +1100,6 @@ bool ChunkDemuxer::EvictCodedFrames(const std::string& id,
}

#if defined(STARBOARD)

base::TimeDelta ChunkDemuxer::GetWriteHead(const std::string& id) const {
base::AutoLock auto_lock(lock_);
DCHECK(IsValidId(id));
Expand Down Expand Up @@ -1138,7 +1130,6 @@ size_t ChunkDemuxer::GetSourceBufferStreamMemoryLimit(const std::string& id) {
}
return source_state_map_[id]->GetSourceBufferStreamMemoryLimit();
}

#endif // defined(STARBOARD)

bool ChunkDemuxer::AppendData(const std::string& id,
Expand Down Expand Up @@ -1689,7 +1680,7 @@ ChunkDemuxerStream* ChunkDemuxer::CreateDemuxerStream(
#else // defined(STARBOARD)
std::unique_ptr<ChunkDemuxerStream> stream =
std::make_unique<ChunkDemuxerStream>(type, media_track_id);
#endif // defined (STARBOARD)
#endif // defined(STARBOARD)

DCHECK(track_id_to_demux_stream_map_.find(media_track_id) ==
track_id_to_demux_stream_map_.end());
Expand Down
19 changes: 7 additions & 12 deletions third_party/chromium/media/filters/chunk_demuxer.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ class MEDIA_EXPORT ChunkDemuxerStream : public DemuxerStream {

#if defined(STARBOARD)
ChunkDemuxerStream(const std::string& mime_type, Type type, MediaTrack::Id media_track_id);
#else // defined (STARBOARD)
#else // defined(STARBOARD)
ChunkDemuxerStream(Type type, MediaTrack::Id media_track_id);
#endif // defined (STARBOARD)
#endif // defined(STARBOARD)
~ChunkDemuxerStream() override;

// ChunkDemuxerStream control methods.
Expand Down Expand Up @@ -134,14 +134,10 @@ class MEDIA_EXPORT ChunkDemuxerStream : public DemuxerStream {
std::string mime_type() const override { return mime_type_; }
size_t GetStreamMemoryLimit();
void SetStreamMemoryLimitOverride(size_t memory_limit);
#endif // defined (STARBOARD)

#if defined(STARBOARD)
void Read(int max_number_of_buffers_to_read, ReadCB read_cb) override;
#else // defined (STARBOARD)
#else // defined(STARBOARD)
void Read(ReadCB read_cb) override;
#endif // defined (STARBOARD)

#endif // defined(STARBOARD)
Type type() const override;
Liveness liveness() const override;
AudioDecoderConfig audio_decoder_config() override;
Expand Down Expand Up @@ -193,7 +189,7 @@ class MEDIA_EXPORT ChunkDemuxerStream : public DemuxerStream {
const std::string mime_type_;
int max_number_of_buffers_to_read_{1};
bool pending_config_change_ {false};
#endif // defined (STARBOARD)
#endif // defined(STARBOARD)

// Specifies the type of the stream.
const Type type_;
Expand Down Expand Up @@ -295,7 +291,7 @@ class MEDIA_EXPORT ChunkDemuxer : public Demuxer {
// Special version of AddId() that retains the |mime_type| from the web app.
Status AddId(const std::string& id, const std::string& mime_type)
WARN_UNUSED_RESULT;
#endif // defined (STARBOARD)
#endif // defined(STARBOARD)

// Notifies a caller via |tracks_updated_cb| that the set of media tracks
// for a given |id| has changed. This callback must be set before any calls to
Expand Down Expand Up @@ -394,7 +390,6 @@ class MEDIA_EXPORT ChunkDemuxer : public Demuxer {

#if defined(STARBOARD)
base::TimeDelta GetWriteHead(const std::string& id) const;

void SetSourceBufferStreamMemoryLimit(const std::string& guid, size_t limit);
size_t GetSourceBufferStreamMemoryLimit(const std::string& guid);
#endif // defined(STARBOARD)
Expand Down Expand Up @@ -600,7 +595,7 @@ class MEDIA_EXPORT ChunkDemuxer : public Demuxer {

#if defined(STARBOARD)
std::map<std::string, std::string> id_to_mime_map_;
#endif // defined (STARBOARD)
#endif // defined(STARBOARD)
};

} // namespace media
Expand Down
Loading

0 comments on commit eafedd1

Please sign in to comment.