Skip to content

Commit

Permalink
[android] Switch from scoped_ptr to std::unique_ptr (#3550)
Browse files Browse the repository at this point in the history
b/291356560
Test-On-Device: True
  • Loading branch information
alexanderbobrovnik committed Jun 13, 2024
1 parent ed62b35 commit 0c0ab1c
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 72 deletions.
4 changes: 2 additions & 2 deletions starboard/android/shared/application_android.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <android/looper.h>
#include <android/native_window.h>
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>
Expand All @@ -28,7 +29,6 @@
#include "starboard/common/atomic.h"
#include "starboard/common/condition_variable.h"
#include "starboard/common/mutex.h"
#include "starboard/common/scoped_ptr.h"
#include "starboard/configuration.h"
#include "starboard/shared/internal_only.h"
#include "starboard/shared/starboard/application.h"
Expand Down Expand Up @@ -155,7 +155,7 @@ class ApplicationAndroid
// |input_events_generator_| is accessed from multiple threads, so use a mutex
// to safely access it.
Mutex input_mutex_;
scoped_ptr<InputEventsGenerator> input_events_generator_;
std::unique_ptr<InputEventsGenerator> input_events_generator_;

bool last_is_accessibility_high_contrast_text_enabled_;

Expand Down
3 changes: 2 additions & 1 deletion starboard/android/shared/audio_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <jni.h>

#include <memory>
#include <queue>
#include <string>

Expand Down Expand Up @@ -93,7 +94,7 @@ class AudioDecoder
std::queue<scoped_refptr<DecodedAudio> > decoded_audios_;

AudioFrameDiscarder audio_frame_discarder_;
scoped_ptr<MediaDecoder> media_decoder_;
std::unique_ptr<MediaDecoder> media_decoder_;
};

} // namespace shared
Expand Down
2 changes: 1 addition & 1 deletion starboard/android/shared/audio_renderer_passthrough.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ AudioRendererPassthrough::AudioRendererPassthrough(
audio_stream_info_.codec == kSbMediaAudioCodecEac3);
if (SbDrmSystemIsValid(drm_system)) {
SB_LOG(INFO) << "Creating AudioDecoder as decryptor.";
scoped_ptr<AudioDecoder> audio_decoder(new AudioDecoder(
std::unique_ptr<AudioDecoder> audio_decoder(new AudioDecoder(
audio_stream_info, drm_system, enable_flush_during_seek));
if (audio_decoder->is_valid()) {
decoder_.reset(audio_decoder.release());
Expand Down
2 changes: 2 additions & 0 deletions starboard/android/shared/configuration_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
#ifndef STARBOARD_ANDROID_SHARED_CONFIGURATION_PUBLIC_H_
#define STARBOARD_ANDROID_SHARED_CONFIGURATION_PUBLIC_H_

#define DEPRECATED_SCOPED_PTR

// --- System Header Configuration -------------------------------------------

// Any system headers listed here that are not provided by the platform will be
Expand Down
28 changes: 14 additions & 14 deletions starboard/android/shared/media_codec_bridge.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ Java_dev_cobalt_media_MediaCodecBridge_nativeOnMediaCodecOutputFormatChanged(
}

// static
scoped_ptr<MediaCodecBridge> MediaCodecBridge::CreateAudioMediaCodecBridge(
std::unique_ptr<MediaCodecBridge> MediaCodecBridge::CreateAudioMediaCodecBridge(
const AudioStreamInfo& audio_stream_info,
Handler* handler,
jobject j_media_crypto) {
Expand All @@ -165,7 +165,7 @@ scoped_ptr<MediaCodecBridge> MediaCodecBridge::CreateAudioMediaCodecBridge(
SupportedAudioCodecToMimeType(audio_stream_info.codec, &is_passthrough);
if (!mime) {
SB_LOG(ERROR) << "Unsupported codec " << audio_stream_info.codec << ".";
return scoped_ptr<MediaCodecBridge>(NULL);
return std::unique_ptr<MediaCodecBridge>();
}

std::string decoder_name =
Expand All @@ -175,7 +175,7 @@ scoped_ptr<MediaCodecBridge> MediaCodecBridge::CreateAudioMediaCodecBridge(
if (decoder_name.empty()) {
SB_LOG(ERROR) << "Failed to find decoder for " << audio_stream_info.codec
<< ".";
return scoped_ptr<MediaCodecBridge>(NULL);
return std::unique_ptr<MediaCodecBridge>();
}

if (MediaCodecBridgeEradicator::GetInstance()->IsEnabled()) {
Expand All @@ -195,7 +195,7 @@ scoped_ptr<MediaCodecBridge> MediaCodecBridge::CreateAudioMediaCodecBridge(
ScopedLocalJavaRef<jstring> j_mime(env->NewStringStandardUTFOrAbort(mime));
ScopedLocalJavaRef<jstring> j_decoder_name(
env->NewStringStandardUTFOrAbort(decoder_name.c_str()));
scoped_ptr<MediaCodecBridge> native_media_codec_bridge(
std::unique_ptr<MediaCodecBridge> native_media_codec_bridge(
new MediaCodecBridge(handler));
jobject j_media_codec_bridge = env->CallStaticObjectMethodOrAbort(
"dev/cobalt/media/MediaCodecBridgeBuilder", "createAudioDecoder",
Expand All @@ -209,16 +209,16 @@ scoped_ptr<MediaCodecBridge> MediaCodecBridge::CreateAudioMediaCodecBridge(
if (!j_media_codec_bridge) {
SB_LOG(ERROR) << "Failed to create codec bridge for "
<< audio_stream_info.codec << ".";
return scoped_ptr<MediaCodecBridge>(NULL);
return std::unique_ptr<MediaCodecBridge>();
}

j_media_codec_bridge = env->ConvertLocalRefToGlobalRef(j_media_codec_bridge);
native_media_codec_bridge->Initialize(j_media_codec_bridge);
return native_media_codec_bridge.Pass();
return native_media_codec_bridge;
}

// static
scoped_ptr<MediaCodecBridge> MediaCodecBridge::CreateVideoMediaCodecBridge(
std::unique_ptr<MediaCodecBridge> MediaCodecBridge::CreateVideoMediaCodecBridge(
SbMediaVideoCodec video_codec,
int width_hint,
int height_hint,
Expand All @@ -243,7 +243,7 @@ scoped_ptr<MediaCodecBridge> MediaCodecBridge::CreateVideoMediaCodecBridge(
const char* mime = SupportedVideoCodecToMimeType(video_codec);
if (!mime) {
*error_message = FormatString("Unsupported mime for codec %d", video_codec);
return scoped_ptr<MediaCodecBridge>(NULL);
return std::unique_ptr<MediaCodecBridge>();
}

const bool must_support_secure = require_secured_decoder;
Expand Down Expand Up @@ -274,7 +274,7 @@ scoped_ptr<MediaCodecBridge> MediaCodecBridge::CreateVideoMediaCodecBridge(
*error_message =
FormatString("Failed to find decoder: %s, mustSupportSecure: %d.", mime,
!!j_media_crypto);
return scoped_ptr<MediaCodecBridge>(NULL);
return std::unique_ptr<MediaCodecBridge>();
}

if (MediaCodecBridgeEradicator::GetInstance()->IsEnabled()) {
Expand Down Expand Up @@ -321,7 +321,7 @@ scoped_ptr<MediaCodecBridge> MediaCodecBridge::CreateVideoMediaCodecBridge(
"dev/cobalt/media/MediaCodecBridge$CreateMediaCodecBridgeResult",
"()V"));

scoped_ptr<MediaCodecBridge> native_media_codec_bridge(
std::unique_ptr<MediaCodecBridge> native_media_codec_bridge(
new MediaCodecBridge(handler));
env->CallStaticVoidMethodOrAbort(
"dev/cobalt/media/MediaCodecBridge", "createVideoMediaCodecBridge",
Expand All @@ -346,12 +346,12 @@ scoped_ptr<MediaCodecBridge> MediaCodecBridge::CreateVideoMediaCodecBridge(
env->CallObjectMethodOrAbort(j_create_media_codec_bridge_result.Get(),
"errorMessage", "()Ljava/lang/String;"));
*error_message = env->GetStringStandardUTFOrAbort(j_error_message.Get());
return scoped_ptr<MediaCodecBridge>(NULL);
return std::unique_ptr<MediaCodecBridge>();
}

j_media_codec_bridge = env->ConvertLocalRefToGlobalRef(j_media_codec_bridge);
native_media_codec_bridge->Initialize(j_media_codec_bridge);
return native_media_codec_bridge.Pass();
return native_media_codec_bridge;
}

MediaCodecBridge::~MediaCodecBridge() {
Expand Down Expand Up @@ -413,8 +413,8 @@ jint MediaCodecBridge::QueueSecureInputBuffer(
// Reshape the sub sample mapping like this:
// [(c0, e0), (c1, e1), ...] -> [c0, c1, ...] and [e0, e1, ...]
int32_t subsample_count = drm_sample_info.subsample_count;
scoped_array<jint> clear_bytes(new jint[subsample_count]);
scoped_array<jint> encrypted_bytes(new jint[subsample_count]);
std::unique_ptr<jint[]> clear_bytes(new jint[subsample_count]);
std::unique_ptr<jint[]> encrypted_bytes(new jint[subsample_count]);
for (int i = 0; i < subsample_count; ++i) {
clear_bytes[i] = drm_sample_info.subsample_mapping[i].clear_byte_count;
encrypted_bytes[i] =
Expand Down
6 changes: 3 additions & 3 deletions starboard/android/shared/media_codec_bridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
#ifndef STARBOARD_ANDROID_SHARED_MEDIA_CODEC_BRIDGE_H_
#define STARBOARD_ANDROID_SHARED_MEDIA_CODEC_BRIDGE_H_

#include <memory>
#include <string>

#include "starboard/android/shared/jni_env_ext.h"
#include "starboard/android/shared/jni_utils.h"
#include "starboard/android/shared/media_common.h"
#include "starboard/common/optional.h"
#include "starboard/common/scoped_ptr.h"
#include "starboard/shared/starboard/media/media_util.h"

namespace starboard {
Expand Down Expand Up @@ -144,7 +144,7 @@ class MediaCodecBridge {
~Handler() {}
};

static scoped_ptr<MediaCodecBridge> CreateAudioMediaCodecBridge(
static std::unique_ptr<MediaCodecBridge> CreateAudioMediaCodecBridge(
const AudioStreamInfo& audio_stream_info,
Handler* handler,
jobject j_media_crypto);
Expand All @@ -155,7 +155,7 @@ class MediaCodecBridge {
// resolutions the platform can decode.
// Both of them have to be set at the same time (i.e. we cannot set one of
// them without the other), which will be checked in the function.
static scoped_ptr<MediaCodecBridge> CreateVideoMediaCodecBridge(
static std::unique_ptr<MediaCodecBridge> CreateVideoMediaCodecBridge(
SbMediaVideoCodec video_codec,
// `width_hint` and `height_hint` are used to create the Android video
// format, which don't have to be directly related to the resolution of
Expand Down
3 changes: 2 additions & 1 deletion starboard/android/shared/media_decoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <jni.h>

#include <deque>
#include <memory>
#include <string>
#include <vector>

Expand Down Expand Up @@ -206,7 +207,7 @@ class MediaDecoder

// Working thread to avoid lengthy decoding work block the player thread.
pthread_t decoder_thread_ = 0;
scoped_ptr<MediaCodecBridge> media_codec_bridge_;
std::unique_ptr<MediaCodecBridge> media_codec_bridge_;
};

} // namespace shared
Expand Down
4 changes: 2 additions & 2 deletions starboard/android/shared/microphone_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

#include <algorithm>
#include <cstddef>
#include <memory>
#include <queue>

#include "starboard/android/shared/jni_env_ext.h"
#include "starboard/common/log.h"
#include "starboard/common/mutex.h"
#include "starboard/common/scoped_ptr.h"
#include "starboard/memory.h"
#include "starboard/shared/starboard/thread_checker.h"

Expand Down Expand Up @@ -251,7 +251,7 @@ int SbMicrophoneImpl::Read(void* out_audio_data, int audio_data_size) {
}

int read_bytes = 0;
scoped_ptr<int16_t> buffer;
std::unique_ptr<int16_t> buffer;
{
ScopedLock lock(ready_queue_mutex_);
// Go through the ready queue, reading and sending audio data.
Expand Down
4 changes: 2 additions & 2 deletions starboard/android/shared/player_components_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ namespace player {
namespace filter {

// static
scoped_ptr<PlayerComponents::Factory> PlayerComponents::Factory::Create() {
return make_scoped_ptr<PlayerComponents::Factory>(
std::unique_ptr<PlayerComponents::Factory> PlayerComponents::Factory::Create() {
return std::unique_ptr<PlayerComponents::Factory>(
new android::shared::PlayerComponentsFactory);
}

Expand Down
Loading

0 comments on commit 0c0ab1c

Please sign in to comment.