Skip to content

Commit

Permalink
(WIP) [media] Reduce implementation in global namespace
Browse files Browse the repository at this point in the history
b/327287075
  • Loading branch information
xiaomings committed Oct 14, 2024
1 parent a337e43 commit 7ca8668
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 174 deletions.
3 changes: 2 additions & 1 deletion starboard/android/shared/player_create.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "starboard/string.h"

using starboard::shared::starboard::player::PlayerWorker;
using starboard::shared::starboard::player::SbPlayerPrivateImpl;
using starboard::shared::starboard::player::filter::
FilterBasedPlayerWorkerHandler;

Expand Down Expand Up @@ -211,7 +212,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
88 changes: 0 additions & 88 deletions starboard/shared/starboard/media/media_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -470,91 +470,3 @@ int64_t AudioFramesToDuration(int frames, int samples_per_second) {
} // namespace starboard
} // namespace shared
} // namespace starboard

bool operator==(const SbMediaColorMetadata& metadata_1,
const SbMediaColorMetadata& metadata_2) {
return memcmp(&metadata_1, &metadata_2, sizeof(SbMediaColorMetadata)) == 0;
}

bool operator==(const SbMediaVideoSampleInfo& sample_info_1,
const SbMediaVideoSampleInfo& sample_info_2) {
#if SB_API_VERSION >= 15
const SbMediaVideoStreamInfo& stream_info_1 = sample_info_1.stream_info;
const SbMediaVideoStreamInfo& stream_info_2 = sample_info_2.stream_info;
#else // SB_API_VERSION >= 15
const SbMediaVideoStreamInfo& stream_info_1 = sample_info_1;
const SbMediaVideoStreamInfo& stream_info_2 = sample_info_2;
#endif // SB_API_VERSION >= 15

if (stream_info_1.codec != stream_info_2.codec) {
return false;
}
if (stream_info_1.codec == kSbMediaVideoCodecNone) {
return true;
}

if (strcmp(stream_info_1.mime, stream_info_2.mime) != 0) {
return false;
}
if (strcmp(stream_info_1.max_video_capabilities,
stream_info_2.max_video_capabilities) != 0) {
return false;
}

if (sample_info_1.is_key_frame != sample_info_2.is_key_frame) {
return false;
}
if (stream_info_1.frame_width != stream_info_2.frame_width) {
return false;
}
if (stream_info_1.frame_height != stream_info_2.frame_height) {
return false;
}
return stream_info_1.color_metadata == stream_info_2.color_metadata;
}

#if SB_API_VERSION >= 15

bool operator==(const SbMediaVideoStreamInfo& stream_info_1,
const SbMediaVideoStreamInfo& stream_info_2) {
if (stream_info_1.codec != stream_info_2.codec) {
return false;
}
if (stream_info_1.codec == kSbMediaVideoCodecNone) {
return true;
}

if (strcmp(stream_info_1.mime, stream_info_2.mime) != 0) {
return false;
}
if (strcmp(stream_info_1.max_video_capabilities,
stream_info_2.max_video_capabilities) != 0) {
return false;
}
if (stream_info_1.frame_width != stream_info_2.frame_width) {
return false;
}
if (stream_info_1.frame_height != stream_info_2.frame_height) {
return false;
}
return stream_info_1.color_metadata == stream_info_2.color_metadata;
}

#endif // SB_API_VERSION >= 15

bool operator!=(const SbMediaColorMetadata& metadata_1,
const SbMediaColorMetadata& metadata_2) {
return !(metadata_1 == metadata_2);
}

bool operator!=(const SbMediaVideoSampleInfo& sample_info_1,
const SbMediaVideoSampleInfo& sample_info_2) {
return !(sample_info_1 == sample_info_2);
}

#if SB_API_VERSION >= 15
bool operator!=(const SbMediaVideoStreamInfo& stream_info_1,
const SbMediaVideoStreamInfo& stream_info_2) {
return !(stream_info_1 == stream_info_2);
}
#endif // SB_API_VERSION >= 15
92 changes: 80 additions & 12 deletions starboard/shared/starboard/media/media_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#ifndef STARBOARD_SHARED_STARBOARD_MEDIA_MEDIA_UTIL_H_
#define STARBOARD_SHARED_STARBOARD_MEDIA_MEDIA_UTIL_H_

#include <string.h>

#include <ostream>
#include <string>
#include <vector>
Expand Down Expand Up @@ -173,24 +175,90 @@ int64_t AudioFramesToDuration(int frames, int samples_per_second);
} // namespace shared
} // namespace starboard

bool operator==(const SbMediaColorMetadata& metadata_1,
const SbMediaColorMetadata& metadata_2);
bool operator==(const SbMediaVideoSampleInfo& sample_info_1,
const SbMediaVideoSampleInfo& sample_info_2);
inline bool operator==(const SbMediaColorMetadata& metadata_1,
const SbMediaColorMetadata& metadata_2) {
return memcmp(&metadata_1, &metadata_2, sizeof(SbMediaColorMetadata)) == 0;
}

inline bool operator==(const SbMediaVideoSampleInfo& sample_info_1,
const SbMediaVideoSampleInfo& sample_info_2) {
#if SB_API_VERSION >= 15
const SbMediaVideoStreamInfo& stream_info_1 = sample_info_1.stream_info;
const SbMediaVideoStreamInfo& stream_info_2 = sample_info_2.stream_info;
#else // SB_API_VERSION >= 15
const SbMediaVideoStreamInfo& stream_info_1 = sample_info_1;
const SbMediaVideoStreamInfo& stream_info_2 = sample_info_2;
#endif // SB_API_VERSION >= 15

if (stream_info_1.codec != stream_info_2.codec) {
return false;
}
if (stream_info_1.codec == kSbMediaVideoCodecNone) {
return true;
}

if (strcmp(stream_info_1.mime, stream_info_2.mime) != 0) {
return false;
}
if (strcmp(stream_info_1.max_video_capabilities,
stream_info_2.max_video_capabilities) != 0) {
return false;
}

if (sample_info_1.is_key_frame != sample_info_2.is_key_frame) {
return false;
}
if (stream_info_1.frame_width != stream_info_2.frame_width) {
return false;
}
if (stream_info_1.frame_height != stream_info_2.frame_height) {
return false;
}
return stream_info_1.color_metadata == stream_info_2.color_metadata;
}

#if SB_API_VERSION >= 15
bool operator==(const SbMediaVideoStreamInfo& stream_info_1,
const SbMediaVideoStreamInfo& stream_info_2);
inline bool operator==(const SbMediaVideoStreamInfo& stream_info_1,
const SbMediaVideoStreamInfo& stream_info_2) {
if (stream_info_1.codec != stream_info_2.codec) {
return false;
}
if (stream_info_1.codec == kSbMediaVideoCodecNone) {
return true;
}

if (strcmp(stream_info_1.mime, stream_info_2.mime) != 0) {
return false;
}
if (strcmp(stream_info_1.max_video_capabilities,
stream_info_2.max_video_capabilities) != 0) {
return false;
}
if (stream_info_1.frame_width != stream_info_2.frame_width) {
return false;
}
if (stream_info_1.frame_height != stream_info_2.frame_height) {
return false;
}
return stream_info_1.color_metadata == stream_info_2.color_metadata;
}
#endif // SB_API_VERSION >= 15

bool operator!=(const SbMediaColorMetadata& metadata_1,
const SbMediaColorMetadata& metadata_2);
bool operator!=(const SbMediaVideoSampleInfo& sample_info_1,
const SbMediaVideoSampleInfo& sample_info_2);
inline bool operator!=(const SbMediaColorMetadata& metadata_1,
const SbMediaColorMetadata& metadata_2) {
return !(metadata_1 == metadata_2);
}

inline bool operator!=(const SbMediaVideoSampleInfo& sample_info_1,
const SbMediaVideoSampleInfo& sample_info_2) {
return !(sample_info_1 == sample_info_2);
}

#if SB_API_VERSION >= 15
bool operator!=(const SbMediaVideoStreamInfo& stream_info_1,
const SbMediaVideoStreamInfo& stream_info_2);
inline bool operator!=(const SbMediaVideoStreamInfo& stream_info_1,
const SbMediaVideoStreamInfo& stream_info_2) {
return !(stream_info_1 == stream_info_2);
}
#endif // SB_API_VERSION >= 15

#endif // STARBOARD_SHARED_STARBOARD_MEDIA_MEDIA_UTIL_H_
3 changes: 2 additions & 1 deletion starboard/shared/starboard/player/player_create.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ using ::starboard::shared::media_session::
UpdateActiveSessionPlatformPlaybackState;
using ::starboard::shared::starboard::media::MimeType;
using ::starboard::shared::starboard::player::PlayerWorker;
using ::starboard::shared::starboard::player::SbPlayerPrivateImpl;
using ::starboard::shared::starboard::player::filter::
FilterBasedPlayerWorkerHandler;

Expand Down Expand Up @@ -215,7 +216,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
Loading

0 comments on commit 7ca8668

Please sign in to comment.