Skip to content

Commit

Permalink
(WIP) Make C24 ATV media stack build in C25
Browse files Browse the repository at this point in the history
b/327287075

Change-Id: Id64c88979358090596ad5684c7c667382b666184
  • Loading branch information
xiaomings committed Aug 29, 2024
1 parent dd1af1d commit 0908ac6
Show file tree
Hide file tree
Showing 10 changed files with 795 additions and 54 deletions.
1 change: 1 addition & 0 deletions starboard/android/shared/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,7 @@ static_library("starboard_platform") {
public_deps = [
":game_activity_sources",
":starboard_base_symbolize",
"//starboard/android/shared/media_2500:media_2500",
"//starboard/common",
"//starboard/shared/starboard/media:media_util",
"//starboard/shared/starboard/player/filter:filter_based_player_sources",
Expand Down
2 changes: 1 addition & 1 deletion starboard/android/shared/player_create.cc
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ SbPlayer SbPlayerCreate(SbWindow window,
new FilterBasedPlayerWorkerHandler(creation_param, provider));
handler->SetMaxVideoInputSize(
starboard::android::shared::GetMaxVideoInputSizeForCurrentThread());
SbPlayer player = SbPlayerPrivate::CreateInstance(
SbPlayer player = SbPlayerPrivateImpl::CreateInstance(
audio_codec, video_codec, sample_deallocate_func, decoder_status_func,
player_status_func, player_error_func, context, std::move(handler));

Expand Down
2 changes: 1 addition & 1 deletion starboard/shared/starboard/player/player_create.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ SbPlayer SbPlayerCreate(SbWindow window,
std::unique_ptr<PlayerWorker::Handler> handler(
new FilterBasedPlayerWorkerHandler(creation_param, provider));

SbPlayer player = SbPlayerPrivate::CreateInstance(
SbPlayer player = SbPlayerPrivateImpl::CreateInstance(
audio_codec, video_codec, sample_deallocate_func, decoder_status_func,
player_status_func, player_error_func, context, std::move(handler));

Expand Down
50 changes: 25 additions & 25 deletions starboard/shared/starboard/player/player_internal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ int64_t CalculateMediaTime(int64_t media_time,

} // namespace

int SbPlayerPrivate::number_of_players_ = 0;
int SbPlayerPrivateImpl::number_of_players_ = 0;

SbPlayerPrivate::SbPlayerPrivate(
SbPlayerPrivateImpl::SbPlayerPrivateImpl(
SbMediaAudioCodec audio_codec,
SbMediaVideoCodec video_codec,
SbPlayerDeallocateSampleFunc sample_deallocate_func,
Expand All @@ -58,17 +58,17 @@ SbPlayerPrivate::SbPlayerPrivate(
media_time_updated_at_(starboard::CurrentMonotonicTime()) {
worker_ = std::unique_ptr<PlayerWorker>(PlayerWorker::CreateInstance(
audio_codec, video_codec, std::move(player_worker_handler),
std::bind(&SbPlayerPrivate::UpdateMediaInfo, this, _1, _2, _3, _4),
std::bind(&SbPlayerPrivateImpl::UpdateMediaInfo, this, _1, _2, _3, _4),
decoder_status_func, player_status_func, player_error_func, this,
context));

++number_of_players_;
SB_DLOG(INFO) << "Creating SbPlayerPrivate. There are " << number_of_players_
<< " players.";
SB_DLOG(INFO) << "Creating SbPlayerPrivateImpl. There are "
<< number_of_players_ << " players.";
}

// static
SbPlayerPrivate* SbPlayerPrivate::CreateInstance(
SbPlayerPrivate* SbPlayerPrivateImpl::CreateInstance(
SbMediaAudioCodec audio_codec,
SbMediaVideoCodec video_codec,
SbPlayerDeallocateSampleFunc sample_deallocate_func,
Expand All @@ -77,7 +77,7 @@ SbPlayerPrivate* SbPlayerPrivate::CreateInstance(
SbPlayerErrorFunc player_error_func,
void* context,
std::unique_ptr<PlayerWorker::Handler> player_worker_handler) {
SbPlayerPrivate* ret = new SbPlayerPrivate(
SbPlayerPrivateImpl* ret = new SbPlayerPrivateImpl(
audio_codec, video_codec, sample_deallocate_func, decoder_status_func,
player_status_func, player_error_func, context,
std::move(player_worker_handler));
Expand All @@ -89,7 +89,7 @@ SbPlayerPrivate* SbPlayerPrivate::CreateInstance(
return nullptr;
}

void SbPlayerPrivate::Seek(int64_t seek_to_time, int ticket) {
void SbPlayerPrivateImpl::Seek(int64_t seek_to_time, int ticket) {
{
starboard::ScopedLock lock(mutex_);
SB_DCHECK(ticket_ != ticket);
Expand All @@ -102,24 +102,24 @@ void SbPlayerPrivate::Seek(int64_t seek_to_time, int ticket) {
worker_->Seek(seek_to_time, ticket);
}

void SbPlayerPrivate::WriteEndOfStream(SbMediaType stream_type) {
void SbPlayerPrivateImpl::WriteEndOfStream(SbMediaType stream_type) {
worker_->WriteEndOfStream(stream_type);
}

void SbPlayerPrivate::SetBounds(int z_index,
int x,
int y,
int width,
int height) {
void SbPlayerPrivateImpl::SetBounds(int z_index,
int x,
int y,
int width,
int height) {
PlayerWorker::Bounds bounds = {z_index, x, y, width, height};
worker_->SetBounds(bounds);
// TODO: Wait until a frame is rendered with the updated bounds.
}

#if SB_API_VERSION >= 15
void SbPlayerPrivate::GetInfo(SbPlayerInfo* out_player_info) {
void SbPlayerPrivateImpl::GetInfo(SbPlayerInfo* out_player_info) {
#else // SB_API_VERSION >= 15
void SbPlayerPrivate::GetInfo(SbPlayerInfo2* out_player_info) {
void SbPlayerPrivateImpl::GetInfo(SbPlayerInfo2* out_player_info) {
#endif // SB_API_VERSION >= 15
SB_DCHECK(out_player_info != NULL);

Expand All @@ -142,25 +142,25 @@ void SbPlayerPrivate::GetInfo(SbPlayerInfo2* out_player_info) {
out_player_info->playback_rate = playback_rate_;
}

void SbPlayerPrivate::SetPause(bool pause) {
void SbPlayerPrivateImpl::SetPause(bool pause) {
is_paused_ = pause;
worker_->SetPause(pause);
}

void SbPlayerPrivate::SetPlaybackRate(double playback_rate) {
void SbPlayerPrivateImpl::SetPlaybackRate(double playback_rate) {
playback_rate_ = playback_rate;
worker_->SetPlaybackRate(playback_rate);
}

void SbPlayerPrivate::SetVolume(double volume) {
void SbPlayerPrivateImpl::SetVolume(double volume) {
volume_ = volume;
worker_->SetVolume(volume_);
}

void SbPlayerPrivate::UpdateMediaInfo(int64_t media_time,
int dropped_video_frames,
int ticket,
bool is_progressing) {
void SbPlayerPrivateImpl::UpdateMediaInfo(int64_t media_time,
int dropped_video_frames,
int ticket,
bool is_progressing) {
starboard::ScopedLock lock(mutex_);
if (ticket_ != ticket) {
return;
Expand All @@ -171,11 +171,11 @@ void SbPlayerPrivate::UpdateMediaInfo(int64_t media_time,
dropped_video_frames_ = dropped_video_frames;
}

SbDecodeTarget SbPlayerPrivate::GetCurrentDecodeTarget() {
SbDecodeTarget SbPlayerPrivateImpl::GetCurrentDecodeTarget() {
return worker_->GetCurrentDecodeTarget();
}

bool SbPlayerPrivate::GetAudioConfiguration(
bool SbPlayerPrivateImpl::GetAudioConfiguration(
int index,
SbMediaAudioConfiguration* out_audio_configuration) {
SB_DCHECK(index >= 0);
Expand Down
94 changes: 67 additions & 27 deletions starboard/shared/starboard/player/player_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,35 @@
#endif // SB_PLAYER_ENABLE_VIDEO_DUMPER

struct SbPlayerPrivate {
public:
virtual ~SbPlayerPrivate() {}

virtual void Seek(int64_t seek_to_time, int ticket) = 0;
virtual void WriteSamples(const SbPlayerSampleInfo* sample_infos,
int number_of_sample_infos) = 0;
virtual void WriteSamples(
const CobaltExtensionEnhancedAudioPlayerSampleInfo* sample_infos,
int number_of_sample_infos) = 0;

virtual void WriteEndOfStream(SbMediaType stream_type) = 0;
virtual void SetBounds(int z_index, int x, int y, int width, int height) = 0;

#if SB_API_VERSION >= 15
virtual void GetInfo(SbPlayerInfo* out_player_info) = 0;
#else // SB_API_VERSION >= 15
virtual void GetInfo(SbPlayerInfo2* out_player_info) = 0;
#endif // SB_API_VERSION >= 15
virtual void SetPause(bool pause) = 0;
virtual void SetPlaybackRate(double playback_rate) = 0;
virtual void SetVolume(double volume) = 0;

virtual SbDecodeTarget GetCurrentDecodeTarget() = 0;
virtual bool GetAudioConfiguration(
int index,
SbMediaAudioConfiguration* out_audio_configuration) = 0;
};

struct SbPlayerPrivateImpl : public SbPlayerPrivate {
public:
typedef starboard::shared::starboard::media::AudioSampleInfo AudioSampleInfo;
typedef starboard::shared::starboard::player::PlayerWorker PlayerWorker;
Expand All @@ -47,45 +76,56 @@ struct SbPlayerPrivate {
void* context,
std::unique_ptr<PlayerWorker::Handler> player_worker_handler);

void Seek(int64_t seek_to_time, int ticket);
template <typename PlayerSampleInfo>
void WriteSamples(const PlayerSampleInfo* sample_infos,
int number_of_sample_infos);
void WriteEndOfStream(SbMediaType stream_type);
void SetBounds(int z_index, int x, int y, int width, int height);
void Seek(int64_t seek_to_time, int ticket) override;
void WriteSamples(
const CobaltExtensionEnhancedAudioPlayerSampleInfo* sample_infos,
int number_of_sample_infos) override {
return WriteSamplesInternal(sample_infos, number_of_sample_infos);
}
void WriteSamples(const SbPlayerSampleInfo* sample_infos,
int number_of_sample_infos) override {
return WriteSamplesInternal(sample_infos, number_of_sample_infos);
}
void WriteEndOfStream(SbMediaType stream_type) override;
void SetBounds(int z_index, int x, int y, int width, int height) override;

#if SB_API_VERSION >= 15
void GetInfo(SbPlayerInfo* out_player_info);
void GetInfo(SbPlayerInfo* out_player_info) override;
#else // SB_API_VERSION >= 15
void GetInfo(SbPlayerInfo2* out_player_info);
void GetInfo(SbPlayerInfo2* out_player_info) override;
#endif // SB_API_VERSION >= 15
void SetPause(bool pause);
void SetPlaybackRate(double playback_rate);
void SetVolume(double volume);
void SetPause(bool pause) override;
void SetPlaybackRate(double playback_rate) override;
void SetVolume(double volume) override;

SbDecodeTarget GetCurrentDecodeTarget();
SbDecodeTarget GetCurrentDecodeTarget() override;
bool GetAudioConfiguration(
int index,
SbMediaAudioConfiguration* out_audio_configuration);
SbMediaAudioConfiguration* out_audio_configuration) override;

~SbPlayerPrivate() {
~SbPlayerPrivateImpl() override {
--number_of_players_;
SB_DLOG(INFO) << "Destroying SbPlayerPrivate. There are "
<< number_of_players_ << " players.";
}

private:
SbPlayerPrivate(SbMediaAudioCodec audio_codec,
SbMediaVideoCodec video_codec,
SbPlayerDeallocateSampleFunc sample_deallocate_func,
SbPlayerDecoderStatusFunc decoder_status_func,
SbPlayerStatusFunc player_status_func,
SbPlayerErrorFunc player_error_func,
void* context,
std::unique_ptr<PlayerWorker::Handler> player_worker_handler);

SbPlayerPrivate(const SbPlayerPrivate&) = delete;
SbPlayerPrivate& operator=(const SbPlayerPrivate&) = delete;
SbPlayerPrivateImpl(
SbMediaAudioCodec audio_codec,
SbMediaVideoCodec video_codec,
SbPlayerDeallocateSampleFunc sample_deallocate_func,
SbPlayerDecoderStatusFunc decoder_status_func,
SbPlayerStatusFunc player_status_func,
SbPlayerErrorFunc player_error_func,
void* context,
std::unique_ptr<PlayerWorker::Handler> player_worker_handler);

SbPlayerPrivateImpl(const SbPlayerPrivateImpl&) = delete;
SbPlayerPrivateImpl& operator=(const SbPlayerPrivateImpl&) = delete;

template <typename PlayerSampleInfo>
void WriteSamplesInternal(const PlayerSampleInfo* sample_infos,
int number_of_sample_infos);

void UpdateMediaInfo(int64_t media_time,
int dropped_video_frames,
Expand Down Expand Up @@ -119,8 +159,8 @@ struct SbPlayerPrivate {
};

template <typename SampleInfo>
void SbPlayerPrivate::WriteSamples(const SampleInfo* sample_infos,
int number_of_sample_infos) {
void SbPlayerPrivateImpl::WriteSamplesInternal(const SampleInfo* sample_infos,
int number_of_sample_infos) {
using starboard::shared::starboard::player::InputBuffer;
using starboard::shared::starboard::player::InputBuffers;

Expand Down
68 changes: 68 additions & 0 deletions starboard/tools/media/find_dependency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env python3
# Copyright 2024 The Cobalt Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
'''Create a snapshot of an Starboard Android TV implementation under
'starboard/android/shared/media_<version>/'. This helps with running
multiple Starboard media implementations side by side.'''

import gn_utils
import os
import source_utils
import utils

_GN_TARGETS = [
'//starboard/common:common',
'//starboard/android/shared:starboard_platform',
'//starboard/shared/starboard/media:media_util',
'//starboard/shared/starboard/player/filter:filter_based_player_sources',
]


def find_inbound_dependencies(project_root_dir, ninja_output_pathname):
project_root_dir = os.path.abspath(os.path.expanduser(project_root_dir))
assert os.path.isdir(project_root_dir)
assert os.path.isdir(os.path.join(project_root_dir, ninja_output_pathname))

source_files = []

for target in _GN_TARGETS:
source_files += gn_utils.get_source_pathnames(project_root_dir,
ninja_output_pathname, target)

source_files.sort()

non_media_files = [f for f in source_files if not utils.is_media_file(f)]

inbound_dependencies = {}

for file in non_media_files:
with open(file, encoding='utf-8') as f:
content = f.read()

headers = source_utils.extract_project_includes(content)
for header in headers:
if utils.is_media_file(header):
if header in inbound_dependencies:
inbound_dependencies[header].append(file)
else:
inbound_dependencies[header] = [file]

for header, sources in inbound_dependencies.items():
print(header)
for source in sources:
print(' ', source)
print()


find_inbound_dependencies('~/cobalt', 'out/android-arm_devel')
Loading

0 comments on commit 0908ac6

Please sign in to comment.