Skip to content

Commit

Permalink
[video_player_avplayer] Fix dash live stream issues (#4)
Browse files Browse the repository at this point in the history
* Update plusplayer header file

* Fix cannot play live stream issue
  • Loading branch information
hyue7 authored Oct 24, 2023
1 parent 38c9d12 commit 3fe4631
Show file tree
Hide file tree
Showing 33 changed files with 122 additions and 27 deletions.
34 changes: 34 additions & 0 deletions packages/video_player_avplayer/tizen/inc/plusplayer/plusplayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -936,6 +936,40 @@ class PlusPlayer : private boost::noncopyable {
*/
virtual bool SetAntiAcousticShock() { return false; }

/**
* @brief Set dashplusplayer properties via json string
* @version 6.0
* @pre The player state required depends on the data that user try to
* Set, if multi keys are specified, the player state should satisfy all.
*
* Key name | Required state
* ---------------- | -------------------------
* "max-bandwidth" | #State::kTrackSourceReady
* @post same as @pre
* @exception N/A
* @param [in] Json formated string with { key1 : value1, key2 : value2 }
* pairs user MUST make sure all key:value pairs are valid.
* @note @c data is case-sensitive. If multi keys specified, even invalid
* key found, dashpp will still try to set the rest.
* @return If ALL Set action excuted successfully.
*/
virtual bool SetData(const std::string data) { return false; }

/**
* @brief Get dashplusplayer properties via json string
* @version 6.0
* @pre @see SetData()
* @post same as @pre
* @exception N/A
* @param data Json formated string with { key1 : value1, key2 : value2 }
* pairs, `keys` must be valid, `values` will be IGNORED as input and will be
* filled by dashplusplayer as output.
* @note @c data is case-sensitive
* @return If ALL Get action excuted successfully, if @c false user can still
* check the data to see if any value successfully returned.
*/
virtual bool GetData(std::string& data) { return false; }

/**
* @brief Set audio volume level
* @pre The player state can be #State::kPlaying or #State::kPaused
Expand Down
7 changes: 5 additions & 2 deletions packages/video_player_avplayer/tizen/inc/plusplayer/track.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ enum SubtitleAttrType {
kSubAttrTypeNone
};

enum class SubtitleType { kText, kPicture, kInvalid };
/**
* @brief Enumeration for player supported subtitle types
*/
enum class SubtitleType { kText, kPicture, kTTMLRender, kInvalid };

struct SubtitleAttr {
explicit SubtitleAttr(const SubtitleAttrType _type,
Expand All @@ -187,4 +190,4 @@ struct Rational {
};
} // namespace plusplayer

#endif // __PLUSPLAYER_TRACK_H__
#endif // __PLUSPLAYER_TRACK_H__
Binary file not shown.
Binary file not shown.
Binary file modified packages/video_player_avplayer/tizen/lib/armel/6.0/libdash.so
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified packages/video_player_avplayer/tizen/lib/armel/6.5/libdash.so
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified packages/video_player_avplayer/tizen/lib/armel/6.5/libgsthls.so
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified packages/video_player_avplayer/tizen/lib/armel/6.5/libhls.so
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified packages/video_player_avplayer/tizen/lib/armel/7.0/libdash.so
Binary file not shown.
Binary file not shown.
6 changes: 3 additions & 3 deletions packages/video_player_avplayer/tizen/src/media_player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ void MediaPlayer::SetPlaybackSpeed(double speed) {
}
}

void MediaPlayer::SeekTo(int32_t position, SeekCompletedCallback callback) {
void MediaPlayer::SeekTo(int64_t position, SeekCompletedCallback callback) {
LOG_INFO("[MediaPlayer] position: %d.", position);

on_seek_completed_ = std::move(callback);
Expand All @@ -236,7 +236,7 @@ void MediaPlayer::SeekTo(int32_t position, SeekCompletedCallback callback) {
}
}

int32_t MediaPlayer::GetPosition() {
int64_t MediaPlayer::GetPosition() {
int position = 0;
int ret = player_get_play_position(player_, &position);
if (ret != PLAYER_ERROR_NONE) {
Expand All @@ -247,7 +247,7 @@ int32_t MediaPlayer::GetPosition() {
return position;
}

int32_t MediaPlayer::GetDuration() {
int64_t MediaPlayer::GetDuration() {
int duration = 0;
int ret = player_get_duration(player_, &duration);
if (ret != PLAYER_ERROR_NONE) {
Expand Down
6 changes: 3 additions & 3 deletions packages/video_player_avplayer/tizen/src/media_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ class MediaPlayer : public VideoPlayer {
void SetLooping(bool is_looping) override;
void SetVolume(double volume) override;
void SetPlaybackSpeed(double speed) override;
void SeekTo(int32_t position, SeekCompletedCallback callback) override;
int32_t GetPosition() override;
int32_t GetDuration() override;
void SeekTo(int64_t position, SeekCompletedCallback callback) override;
int64_t GetPosition() override;
int64_t GetDuration() override;
void GetVideoSize(int32_t *width, int32_t *height) override;
bool isReady() override;
flutter::EncodableList getTrackInfo(int32_t track_type) override;
Expand Down
82 changes: 70 additions & 12 deletions packages/video_player_avplayer/tizen/src/plus_player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,20 @@
#include <system_info.h>
#include <unistd.h>

#include <sstream>

#include "log.h"

static std::vector<std::string> split(const std::string &s, char delim) {
std::stringstream ss(s);
std::string item;
std::vector<std::string> tokens;
while (getline(ss, item, delim)) {
tokens.push_back(item);
}
return tokens;
}

PlusPlayer::PlusPlayer(flutter::BinaryMessenger *messenger, void *native_window,
std::string &video_format)
: VideoPlayer(messenger),
Expand Down Expand Up @@ -38,6 +50,7 @@ int64_t PlusPlayer::Create(const std::string &uri, int drm_type,
LOG_ERROR("[PlusPlayer] Fail to open uri : %s.", uri.c_str());
return -1;
}
LOG_INFO("[PlusPlayer] Uri: %s", uri.c_str());

char *appId = nullptr;
int ret = app_manager_get_app_id(getpid(), &appId);
Expand Down Expand Up @@ -196,8 +209,8 @@ void PlusPlayer::SetPlaybackSpeed(double speed) {
}
}

void PlusPlayer::SeekTo(int32_t position, SeekCompletedCallback callback) {
LOG_INFO("PlusPlayer seeks to position(%d)", position);
void PlusPlayer::SeekTo(int64_t position, SeekCompletedCallback callback) {
LOG_INFO("PlusPlayer seeks to position(%lld)", position);
if (player_->GetState() < plusplayer::State::kReady) {
LOG_ERROR("[PlusPlayer] Player is not ready.");
return;
Expand All @@ -209,13 +222,39 @@ void PlusPlayer::SeekTo(int32_t position, SeekCompletedCallback callback) {
}

on_seek_completed_ = std::move(callback);
if (!player_->Seek(position)) {
on_seek_completed_ = nullptr;
LOG_ERROR("[PlusPlayer] Fail to seek.");
plusplayer::PlayerMemento memento;
if (!player_->GetMemento(&memento)) {
LOG_ERROR("[PlusPlayer] Fail to get player memento.");
}

if (memento.is_live) {
std::string str = player_->GetStreamingProperty("GET_LIVE_DURATION");
if (str.empty()) {
LOG_ERROR("[PlusPlayer] Fail to get live duration.");
}
std::vector<std::string> time_str = split(str, '|');
int64_t start_time = std::stoll(time_str[0].c_str());
int64_t end_time = std::stoll(time_str[1].c_str());

if (position < start_time || position > end_time) {
on_seek_completed_ = nullptr;
LOG_ERROR("[PlusPlayer] position out of range.");
return;
}

if (!player_->Seek(position)) {
on_seek_completed_ = nullptr;
LOG_ERROR("[PlusPlayer] Fail to seek.");
}
} else {
if (!player_->Seek(position)) {
on_seek_completed_ = nullptr;
LOG_ERROR("[PlusPlayer] Fail to seek.");
}
}
}

int32_t PlusPlayer::GetPosition() {
int64_t PlusPlayer::GetPosition() {
uint64_t position = 0;
plusplayer::State state = player_->GetState();
if (state == plusplayer::State::kPlaying ||
Expand All @@ -224,17 +263,36 @@ int32_t PlusPlayer::GetPosition() {
LOG_ERROR("[PlusPlayer] Fail to get the current playing time.");
}
}
return position;
return static_cast<int64_t>(position);
}

int32_t PlusPlayer::GetDuration() {
int64_t PlusPlayer::GetDuration() {
int64_t duration = 0;
if (player_->GetState() >= plusplayer::State::kTrackSourceReady) {
if (!player_->GetDuration(&duration)) {
LOG_ERROR("[PlusPlayer] Fail to get the duration.");
plusplayer::PlayerMemento memento;
if (!player_->GetMemento(&memento)) {
LOG_ERROR("[PlusPlayer] Fail to get player memento.");
}

if (memento.is_live) {
std::string str = player_->GetStreamingProperty("GET_LIVE_DURATION");
if (str.empty()) {
LOG_ERROR("[PlusPlayer] Fail to get live duration.");
return duration;
}
std::vector<std::string> time_str = split(str, '|');
int64_t start_time = std::stoll(time_str[0].c_str());
int64_t end_time = std::stoll(time_str[1].c_str());

duration = end_time - start_time;
} else {
if (!player_->GetDuration(&duration)) {
LOG_ERROR("[PlusPlayer] Fail to get the duration.");
}
}
LOG_INFO("[PlusPlayer] Video duration: %llu.", duration);
}

LOG_INFO("[PlusPlayer] Video duration: %lld.", duration);
return duration;
}

Expand Down Expand Up @@ -497,7 +555,7 @@ bool PlusPlayer::OnLicenseAcquired(int *drm_handle, unsigned int length,
}

void PlusPlayer::OnPrepareDone(bool ret, UserData userdata) {
LOG_DEBUG("[PlusPlayer] Prepare done, result: %d.", ret);
LOG_INFO("[PlusPlayer] Prepare done, result: %d.", ret);

if (!is_initialized_ && ret) {
SendInitialized();
Expand Down
6 changes: 3 additions & 3 deletions packages/video_player_avplayer/tizen/src/plus_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class PlusPlayer : public VideoPlayer, public plusplayer::EventListener {
void SetLooping(bool is_looping) override;
void SetVolume(double volume) override;
void SetPlaybackSpeed(double speed) override;
void SeekTo(int32_t position, SeekCompletedCallback callback) override;
int32_t GetPosition() override;
int32_t GetDuration() override;
void SeekTo(int64_t position, SeekCompletedCallback callback) override;
int64_t GetPosition() override;
int64_t GetDuration() override;
void GetVideoSize(int32_t *width, int32_t *height) override;
bool isReady() override;
flutter::EncodableList getTrackInfo(int32_t track_type) override;
Expand Down
2 changes: 1 addition & 1 deletion packages/video_player_avplayer/tizen/src/video_player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ void VideoPlayer::PushEvent(flutter::EncodableValue encodable_value) {
void VideoPlayer::SendInitialized() {
if (!is_initialized_ && event_sink_) {
int32_t width = 0, height = 0;
int32_t duration = GetDuration();
int64_t duration = GetDuration();
GetVideoSize(&width, &height);
is_initialized_ = true;
flutter::EncodableMap result = {
Expand Down
6 changes: 3 additions & 3 deletions packages/video_player_avplayer/tizen/src/video_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ class VideoPlayer {
virtual void SetLooping(bool is_looping) = 0;
virtual void SetVolume(double volume) = 0;
virtual void SetPlaybackSpeed(double speed) = 0;
virtual void SeekTo(int32_t position, SeekCompletedCallback callback) = 0;
virtual int32_t GetPosition() = 0;
virtual int32_t GetDuration() = 0;
virtual void SeekTo(int64_t position, SeekCompletedCallback callback) = 0;
virtual int64_t GetPosition() = 0;
virtual int64_t GetDuration() = 0;
virtual bool isReady() = 0;
virtual flutter::EncodableList getTrackInfo(int32_t track_type) = 0;
virtual bool SetTrackSelection(int32_t track_id, int32_t track_type) = 0;
Expand Down

0 comments on commit 3fe4631

Please sign in to comment.