Skip to content

Commit

Permalink
Initial patch supporting media element playback
Browse files Browse the repository at this point in the history
- Added interface for castanets WebMediaPlayer
- Added renderer manager for managing WebMediaPlayer objects
- Added IPCs

Signed-off-by: Venugopal S M <[email protected]>
  • Loading branch information
sm-venugopal committed Oct 10, 2019
1 parent 90d4ade commit be6456e
Show file tree
Hide file tree
Showing 19 changed files with 1,816 additions and 3 deletions.
8 changes: 8 additions & 0 deletions content/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,14 @@ source_set("common") {
"//content/public/common:interfaces",
]

if (enable_castanets) {
sources += [
"media/castanets_media_param_traits.cc",
"media/castanets_media_param_traits.h",
"media/castanets_media_player_messages.h",
]
}

if (is_android && use_seccomp_bpf) {
set_sources_assignment_filter([])
sources += [
Expand Down
9 changes: 9 additions & 0 deletions content/common/content_message_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,12 @@
#error "Failed to include content/common/media/media_player_messages_android.h"
#endif
#endif // defined(OS_ANDROID)

#if defined(CASTANETS)
#undef CONTENT_COMMON_MEDIA_CASTANETS_MEDIA_PLAYER_MESSAGES_H_
#include "content/common/media/castanets_media_player_messages.h"
#ifndef CONTENT_COMMON_MEDIA_CASTANETS_MEDIA_PLAYER_MESSAGES_H_
#error \
"Failed to include content/common/media/castanets_media_player_messages.h"
#endif
#endif
52 changes: 52 additions & 0 deletions content/common/media/castanets_media_param_traits.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright 2019 Samsung Electronics Inc. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/common/media/castanets_media_param_traits.h"

#include "base/strings/stringprintf.h"
#include "ipc/ipc_message_utils.h"

namespace IPC {

void ParamTraits<media::Ranges<base::TimeDelta>>::Write(
base::Pickle* pickle,
const media::Ranges<base::TimeDelta>& range) {
WriteParam(pickle, static_cast<int>(range.size()));
for (size_t i = 0; i < range.size(); ++i) {
WriteParam(pickle, range.start(i));
WriteParam(pickle, range.end(i));
}
}

bool ParamTraits<media::Ranges<base::TimeDelta>>::Read(
const base::Pickle* pickle,
base::PickleIterator* iter,
media::Ranges<base::TimeDelta>* range) {
int size = 0;

// ReadLength() checks for < 0 itself.
if (!iter->ReadLength(&size))
return false;
for (int i = 0; i < size; i++) {
base::TimeDelta start, end;
if (!ReadParam(pickle, iter, &start) || !ReadParam(pickle, iter, &end))
return false;
range->Add(start, end);
}
return true;
}

void ParamTraits<media::Ranges<base::TimeDelta>>::Log(
const media::Ranges<base::TimeDelta>& pickle,
std::string* str) {
str->append("TimeRanges:[");
for (size_t i = 0u; i < pickle.size(); ++i) {
str->append(base::StringPrintf("{%zu:{%lf,%lf}}, ", i,
pickle.start(i).InSecondsF(),
pickle.end(i).InSecondsF()));
}
str->append("]");
}

} // namespace IPC
23 changes: 23 additions & 0 deletions content/common/media/castanets_media_param_traits.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef CONTENT_COMMON_MEDIA_CASTANETS_MEDIA_PARAM_TRAITS_H_
#define CONTENT_COMMON_MEDIA_CASTANETS_MEDIA_PARAM_TRAITS_H_

#include "base/pickle.h"
#include "content/common/content_export.h"
#include "ipc/ipc_param_traits.h"
#include "media/base/ranges.h"

namespace IPC {

template <>
struct CONTENT_EXPORT ParamTraits<media::Ranges<base::TimeDelta>> {
typedef media::Ranges<base::TimeDelta> param_type;
static void Write(base::Pickle* pickle, const param_type& ptype);
static bool Read(const base::Pickle* pickle,
base::PickleIterator* iter,
param_type* ptype);
static void Log(const param_type& ptype, std::string* str);
};

} // namespace IPC

#endif // CONTENT_COMMON_MEDIA_CASTANETS_MEDIA_PARAM_TRAITS_H_
24 changes: 24 additions & 0 deletions content/common/media/castanets_media_player_init_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright 2019 Samsung Electronics Inc. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CONTENT_COMMON_MEDIA_CASTANETS_MEDIA_PLAYER_INIT_CONFIG_H_
#define CONTENT_COMMON_MEDIA_CASTANETS_MEDIA_PLAYER_INIT_CONFIG_H_

#include <string>
#include "media/blink/renderer_media_player_interface.h"
#include "url/gurl.h"

namespace content {

struct MediaPlayerInitConfig {
MediaPlayerHostMsg_Initialize_Type type;
GURL url;
std::string mime_type;
int demuxer_client_id;
bool has_encrypted_listener_or_cdm;
};

} // namespace content

#endif // CONTENT_COMMON_MEDIA_CASTANETS_MEDIA_PLAYER_INIT_CONFIG_H_
148 changes: 148 additions & 0 deletions content/common/media/castanets_media_player_messages.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
// Copyright 2019 Samsung Electronics Inc. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// IPC messages for castanets player.
#ifndef CONTENT_COMMON_MEDIA_CASTANETS_MEDIA_PLAYER_MESSAGES_H_
#define CONTENT_COMMON_MEDIA_CASTANETS_MEDIA_PLAYER_MESSAGES_H_

#include "content/common/media/castanets_media_param_traits.h"
#include "content/common/media/castanets_media_player_init_config.h"
#include "ipc/ipc_message_macros.h"
#include "media/blink/renderer_media_player_interface.h"
#include "ui/gfx/geometry/rect_f.h"

#undef IPC_MESSAGE_EXPORT
#define IPC_MESSAGE_EXPORT CONTENT_EXPORT
#define IPC_MESSAGE_START MediaPlayerCastanetsMsgStart

IPC_ENUM_TRAITS(blink::WebMediaPlayer::ReadyState)
IPC_ENUM_TRAITS(blink::WebMediaPlayer::NetworkState)
#if !defined(OS_ANDROID)
IPC_ENUM_TRAITS(MediaPlayerHostMsg_Initialize_Type)
#endif

// Should be same as castanets player.
IPC_STRUCT_TRAITS_BEGIN(content::MediaPlayerInitConfig)
IPC_STRUCT_TRAITS_MEMBER(type)
IPC_STRUCT_TRAITS_MEMBER(url)
IPC_STRUCT_TRAITS_MEMBER(mime_type)
IPC_STRUCT_TRAITS_MEMBER(demuxer_client_id)
IPC_STRUCT_TRAITS_MEMBER(has_encrypted_listener_or_cdm)
IPC_STRUCT_TRAITS_END()

// TODO (sm.venugopal): Rename the IPCs.
// Initialize Efl player.
IPC_MESSAGE_ROUTED2(MediaPlayerEflHostMsg_Init,
int /* player_id */,
content::MediaPlayerInitConfig /* config */)

// Requests the player to enter fullscreen.
IPC_MESSAGE_ROUTED1(MediaPlayerEflHostMsg_EnteredFullscreen,
int /* player_id */)

// Requests the player to exit fullscreen.
IPC_MESSAGE_ROUTED1(MediaPlayerEflHostMsg_ExitedFullscreen, int /* player_id */)

// Deinitialize Gst player.
IPC_MESSAGE_ROUTED1(MediaPlayerEflHostMsg_DeInit, int /* player_id */)

// Start playback.
IPC_MESSAGE_ROUTED1(MediaPlayerEflHostMsg_Play, int /* player_id */)

// Pause playback.
IPC_MESSAGE_ROUTED2(MediaPlayerEflHostMsg_Pause,
int /* player_id */,
bool /* is_media_related_action */)

// Suspend media player.
IPC_MESSAGE_ROUTED1(MediaPlayerEflHostMsg_Suspend, int /* player_id */)

// Resume media player.
IPC_MESSAGE_ROUTED1(MediaPlayerEflHostMsg_Resume, int /* player_id*/)

// Player was activated by an user or an app.
IPC_MESSAGE_ROUTED1(MediaPlayerEflHostMsg_Activate, int /* player_id*/)

// Player should deactivate (ex. save power).
IPC_MESSAGE_ROUTED1(MediaPlayerEflHostMsg_Deactivate, int /* player_id*/)

// Set volume.
IPC_MESSAGE_ROUTED2(MediaPlayerEflHostMsg_SetVolume,
int /* player_id */,
double /* volume */)

// Set playback rate.
IPC_MESSAGE_ROUTED2(MediaPlayerEflHostMsg_SetRate,
int /* player_id */,
double /* rate */)

// Playback duration.
IPC_MESSAGE_ROUTED2(MediaPlayerEflMsg_DurationChanged,
int /* player_id */,
base::TimeDelta /* time */)

// Current duration.
IPC_MESSAGE_ROUTED2(MediaPlayerEflMsg_TimeUpdate,
int /* player_id */,
base::TimeDelta /* time */)

// Pause state.
IPC_MESSAGE_ROUTED2(MediaPlayerEflMsg_PauseStateChanged,
int /* player_id */,
bool /* state */)

// Seek state.
IPC_MESSAGE_ROUTED1(MediaPlayerEflMsg_OnSeekComplete, int /* player_id */)

// Current buffer range.
IPC_MESSAGE_ROUTED2(MediaPlayerEflMsg_BufferUpdate,
int /* player_id */,
int /* buffering_percentage */)

// Playback completed.
IPC_MESSAGE_ROUTED1(MediaPlayerEflMsg_TimeChanged, int /* player_id */)

IPC_MESSAGE_ROUTED1(MediaPlayerEflMsg_PlayerDestroyed, int /* player_id */)

// Ready state change.
IPC_MESSAGE_ROUTED2(MediaPlayerEflMsg_ReadyStateChange,
int /* player_id */,
blink::WebMediaPlayer::ReadyState /* state */)

// Network state change.
IPC_MESSAGE_ROUTED2(MediaPlayerEflMsg_NetworkStateChange,
int /* player_id */,
blink::WebMediaPlayer::NetworkState /* state */)

// Gst media data has changed.
IPC_MESSAGE_ROUTED4(MediaPlayerEflMsg_MediaDataChanged,
int /* player_id */,
int /* width */,
int /* height */,
int /* media */)

// Set geometry.
IPC_MESSAGE_ROUTED2(MediaPlayerEflHostMsg_SetGeometry,
int /* player_id */,
gfx::RectF /* position and size */)
// Seek.
IPC_MESSAGE_ROUTED2(MediaPlayerEflHostMsg_Seek,
int /* player_id */,
base::TimeDelta /* time */)

IPC_MESSAGE_ROUTED2(MediaPlayerEflMsg_SeekRequest,
int /* player_id */,
base::TimeDelta /* time_to_seek */)

// Player has begun suspend procedure
IPC_MESSAGE_ROUTED2(MediaPlayerEflMsg_PlayerSuspend,
int /* player_id */,
bool /* is_preempted */)

// Player has resumed
IPC_MESSAGE_ROUTED2(MediaPlayerEflMsg_PlayerResumed,
int /* player_id */,
bool /* is_preempted */)

#endif // CONTENT_COMMON_MEDIA_CASTANETS_MEDIA_PLAYER_MESSAGES_H_
9 changes: 9 additions & 0 deletions content/renderer/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,15 @@ target(link_target_type, "renderer") {
"worker_thread_registry.h",
]

if (enable_castanets) {
sources += [
"media/castanets/castanets_renderer_media_player_manager.cc",
"media/castanets/castanets_renderer_media_player_manager.h",
"media/castanets/castanets_webmediaplayer_impl.cc",
"media/castanets/castanets_webmediaplayer_impl.h",
]
}

if (!is_component_build) {
if (is_win && is_official_build) {
split_count = 2 # In certain configurations a full renderer.lib can
Expand Down
Loading

0 comments on commit be6456e

Please sign in to comment.