Skip to content

Commit

Permalink
[videoplayer] Add video stream selection.
Browse files Browse the repository at this point in the history
  • Loading branch information
ace20022 authored and FernetMenta committed Nov 23, 2015
1 parent 5e0dc48 commit d05b884
Show file tree
Hide file tree
Showing 16 changed files with 334 additions and 14 deletions.
6 changes: 5 additions & 1 deletion addons/resource.language.en_gb/resources/strings.po
Original file line number Diff line number Diff line change
Expand Up @@ -2090,7 +2090,11 @@ msgctxt "#470"
msgid "Credits"
msgstr ""

#empty strings from id 471 to 473
msgctxt "#471"
msgid "Video stream"
msgstr ""

#empty strings from id 472 to 473

msgctxt "#474"
msgid "Off"
Expand Down
41 changes: 39 additions & 2 deletions xbmc/ApplicationPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,11 +501,11 @@ void CApplicationPlayer::OnNothingToQueueNotify()
player->OnNothingToQueueNotify();
}

void CApplicationPlayer::GetVideoStreamInfo(SPlayerVideoStreamInfo &info)
void CApplicationPlayer::GetVideoStreamInfo(int streamId, SPlayerVideoStreamInfo &info)
{
std::shared_ptr<IPlayer> player = GetInternal();
if (player)
player->GetVideoStreamInfo(info);
player->GetVideoStreamInfo(streamId, info);
}

void CApplicationPlayer::GetAudioStreamInfo(int index, SPlayerAudioStreamInfo &info)
Expand Down Expand Up @@ -536,6 +536,31 @@ int CApplicationPlayer::GetAudioStreamCount()
return 0;
}

int CApplicationPlayer::GetVideoStream()
{
if (!m_videoStreamUpdate.IsTimePast())
return m_iVideoStream;

std::shared_ptr<IPlayer> player = GetInternal();
if (player)
{
m_iVideoStream = player->GetVideoStream();
m_videoStreamUpdate.Set(1000);
return m_iVideoStream;
}
else
return 0;
}

int CApplicationPlayer::GetVideoStreamCount()
{
std::shared_ptr<IPlayer> player = GetInternal();
if (player)
return player->GetVideoStreamCount();
else
return 0;
}

void CApplicationPlayer::SetAudioStream(int iStream)
{
std::shared_ptr<IPlayer> player = GetInternal();
Expand Down Expand Up @@ -578,6 +603,18 @@ void CApplicationPlayer::SetSubtitleVisible(bool bVisible)
}
}

void CApplicationPlayer::SetVideoStream(int iStream)
{
std::shared_ptr<IPlayer> player = GetInternal();
if (player)
{
player->SetVideoStream(iStream);
m_iVideoStream = iStream;
m_videoStreamUpdate.Set(1000);
CMediaSettings::GetInstance().GetCurrentVideoSettings().m_VideoStream = iStream;
}
}

void CApplicationPlayer::AddSubtitle(const std::string& strSubPath)
{
std::shared_ptr<IPlayer> player = GetInternal();
Expand Down
7 changes: 6 additions & 1 deletion xbmc/ApplicationPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class CApplicationPlayer
// cache player state
XbmcThreads::EndTime m_audioStreamUpdate;
int m_iAudioStream;
XbmcThreads::EndTime m_videoStreamUpdate;
int m_iVideoStream;
XbmcThreads::EndTime m_subtitleStreamUpdate;
int m_iSubtitleStream;

Expand Down Expand Up @@ -141,7 +143,9 @@ class CApplicationPlayer
int64_t GetDisplayTime() const;
int64_t GetTotalTime() const;
void GetVideoInfo(std::string& strVideoInfo);
void GetVideoStreamInfo(SPlayerVideoStreamInfo &info);
int GetVideoStream();
int GetVideoStreamCount();
void GetVideoStreamInfo(int streamId, SPlayerVideoStreamInfo &info);
bool HasAudio() const;
bool HasMenu() const;
bool HasVideo() const;
Expand Down Expand Up @@ -176,6 +180,7 @@ class CApplicationPlayer
void SetSubtitle(int iStream);
void SetSubTitleDelay(float fValue = 0.0f);
void SetSubtitleVisible(bool bVisible);
void SetVideoStream(int iStream);
void SetVolume(float volume);
bool SwitchChannel(const PVR::CPVRChannelPtr &channel);
void ToFFRW(int iSpeed = 0);
Expand Down
2 changes: 1 addition & 1 deletion xbmc/GUIInfoManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4837,7 +4837,7 @@ void CGUIInfoManager::UpdateAVInfo()
SPlayerVideoStreamInfo video;
SPlayerAudioStreamInfo audio;

g_application.m_pPlayer->GetVideoStreamInfo(video);
g_application.m_pPlayer->GetVideoStreamInfo(CURRENT_STREAM, video);
g_application.m_pPlayer->GetAudioStreamInfo(CURRENT_STREAM, audio);

m_videoInfo = video;
Expand Down
7 changes: 6 additions & 1 deletion xbmc/cores/IPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ class IPlayer
virtual void SetAudioStream(int iStream){};
virtual void GetAudioStreamInfo(int index, SPlayerAudioStreamInfo &info){};

virtual int GetVideoStreamCount() { return 0; }
virtual int GetVideoStream() { return -1; }
virtual void SetVideoStream(int iStream) {}
virtual void GetVideoStreamInfo(int streamId, SPlayerVideoStreamInfo &info) {}


virtual TextCacheStruct_t* GetTeletextCache() { return NULL; };
virtual void LoadPage(int p, int sp, unsigned char* buffer) {};

Expand Down Expand Up @@ -336,7 +342,6 @@ class IPlayer
its not available in the underlaying decoder (airtunes for example)
*/
virtual void SetTotalTime(int64_t time) { }
virtual void GetVideoStreamInfo(SPlayerVideoStreamInfo &info){};
virtual int GetSourceBitrate(){ return 0;}
virtual bool GetStreamDetails(CStreamDetails &details){ return false;}
virtual void ToFFRW(int iSpeed = 0){};
Expand Down
10 changes: 10 additions & 0 deletions xbmc/cores/VideoPlayer/DVDMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class CDVDMsg : public IDVDResourceCounted<CDVDMsg>
// player core related messages (cVideoPlayer.cpp)

PLAYER_SET_AUDIOSTREAM, //
PLAYER_SET_VIDEOSTREAM, //
PLAYER_SET_SUBTITLESTREAM, //
PLAYER_SET_SUBTITLESTREAM_VISIBLE, //
PLAYER_SET_STATE, // restore the VideoPlayer to a certain state
Expand Down Expand Up @@ -185,6 +186,15 @@ class CDVDMsgPlayerSetAudioStream : public CDVDMsg
int m_streamId;
};

class CDVDMsgPlayerSetVideoStream : public CDVDMsg
{
public:
CDVDMsgPlayerSetVideoStream(int streamId) : CDVDMsg(PLAYER_SET_VIDEOSTREAM) { m_streamId = streamId; }
int GetStreamId() { return m_streamId; }
private:
int m_streamId;
};

class CDVDMsgPlayerSetSubtitleStream : public CDVDMsg
{
public:
Expand Down
63 changes: 58 additions & 5 deletions xbmc/cores/VideoPlayer/VideoPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2437,6 +2437,25 @@ void CVideoPlayer::HandleMessages()
}
}
}
else if (pMsg->IsType(CDVDMsg::PLAYER_SET_VIDEOSTREAM))
{
CDVDMsgPlayerSetVideoStream* pMsg2 = (CDVDMsgPlayerSetVideoStream*)pMsg;

SelectionStream& st = m_SelectionStreams.Get(STREAM_VIDEO, pMsg2->GetStreamId());
if (st.source != STREAM_SOURCE_NONE)
{
if (st.source == STREAM_SOURCE_NAV && m_pInputStream && m_pInputStream->IsStreamType(DVDSTREAM_TYPE_DVD))
{

}
else
{
CloseStream(m_CurrentVideo, false);
OpenStream(m_CurrentVideo, st.id, st.source);
m_messenger.Put(new CDVDMsgPlayerSeek((int)GetTime(), true, true, true, true, true));
}
}
}
else if (pMsg->IsType(CDVDMsg::PLAYER_SET_SUBTITLESTREAM))
{
CDVDMsgPlayerSetSubtitleStream* pMsg2 = (CDVDMsgPlayerSetSubtitleStream*)pMsg;
Expand Down Expand Up @@ -3174,6 +3193,22 @@ void CVideoPlayer::SetAudioStream(int iStream)
SynchronizeDemuxer(100);
}

int CVideoPlayer::GetVideoStreamCount()
{
return m_SelectionStreams.Count(STREAM_VIDEO);
}

int CVideoPlayer::GetVideoStream()
{
return m_SelectionStreams.IndexOf(STREAM_VIDEO, *this);
}

void CVideoPlayer::SetVideoStream(int iStream)
{
m_messenger.Put(new CDVDMsgPlayerSetVideoStream(iStream));
SynchronizeDemuxer(100);
}

TextCacheStruct_t* CVideoPlayer::GetTeletextCache()
{
if (m_CurrentTeletext.id < 0)
Expand Down Expand Up @@ -4273,28 +4308,46 @@ double CVideoPlayer::GetQueueTime()
return std::max(a, v) * 8000.0 / 100;
}

void CVideoPlayer::GetVideoStreamInfo(SPlayerVideoStreamInfo &info)
void CVideoPlayer::GetVideoStreamInfo(int streamId, SPlayerVideoStreamInfo &info)
{
info.bitrate = m_VideoPlayerVideo->GetVideoBitrate();
if (streamId == CURRENT_STREAM)
streamId = GetVideoStream();

if (streamId < 0 || streamId > GetAudioStreamCount() - 1)
return;

if (streamId == GetVideoStream())
{
info.bitrate = m_VideoPlayerVideo->GetVideoBitrate();
}

std::string retVal;
if (m_pDemuxer && (m_CurrentVideo.id != -1))
if (m_pDemuxer)
{
m_pDemuxer->GetStreamCodecName(m_CurrentVideo.id, retVal);
CDemuxStreamVideo* stream = static_cast<CDemuxStreamVideo*>(m_pDemuxer->GetStream(m_CurrentVideo.id));
CDemuxStreamVideo* stream = m_pDemuxer->GetStreamFromVideoId(streamId);
m_pDemuxer->GetStreamCodecName(stream->iId, retVal);

if (stream)
{
info.width = stream->iWidth;
info.height = stream->iHeight;
}
}

info.videoCodecName = retVal;
info.videoAspectRatio = m_renderManager.GetAspectRatio();
CRect viewRect;
m_renderManager.GetVideoRect(info.SrcRect, info.DestRect, viewRect);
info.stereoMode = m_VideoPlayerVideo->GetStereoMode();
if (info.stereoMode == "mono")
info.stereoMode = "";

SelectionStream& s = m_SelectionStreams.Get(STREAM_VIDEO, streamId);
if (s.language.length() > 0)
info.language = s.language;

if (s.name.length() > 0)
info.name = s.name;
}

int CVideoPlayer::GetSourceBitrate()
Expand Down
6 changes: 5 additions & 1 deletion xbmc/cores/VideoPlayer/VideoPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ class CVideoPlayer : public IPlayer, public CThread, public IVideoPlayer, public
virtual int GetAudioStream();
virtual void SetAudioStream(int iStream);

virtual int GetVideoStreamCount();
virtual int GetVideoStream();
virtual void SetVideoStream(int iStream);

virtual TextCacheStruct_t* GetTeletextCache();
virtual void LoadPage(int p, int sp, unsigned char* buffer);

Expand All @@ -281,7 +285,7 @@ class CVideoPlayer : public IPlayer, public CThread, public IVideoPlayer, public
virtual bool HasMenu();

virtual int GetSourceBitrate();
virtual void GetVideoStreamInfo(SPlayerVideoStreamInfo &info);
virtual void GetVideoStreamInfo(int streamId, SPlayerVideoStreamInfo &info);
virtual bool GetStreamDetails(CStreamDetails &details);
virtual void GetAudioStreamInfo(int index, SPlayerAudioStreamInfo &info);

Expand Down
65 changes: 65 additions & 0 deletions xbmc/interfaces/json-rpc/PlayerOperations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1555,6 +1555,71 @@ JSONRPC_STATUS CPlayerOperations::GetPropertyValue(PlayerType player, const std:
break;
}
}
else if (property == "currentvideostream")
{
switch (player)
{
case Video:
if (g_application.m_pPlayer->HasPlayer())
{
result = CVariant(CVariant::VariantTypeObject);
int index = g_application.m_pPlayer->GetVideoStream();
if (index >= 0)
{
SPlayerVideoStreamInfo info;
g_application.m_pPlayer->GetVideoStreamInfo(index, info);

result["index"] = index;
result["name"] = info.name;
result["language"] = info.language;
result["codec"] = info.videoCodecName;
result["width"] = info.width;
result["height"] = info.height;
}
}
else
result = CVariant(CVariant::VariantTypeNull);
break;

case Audio:
case Picture:
default:
result = CVariant(CVariant::VariantTypeNull);
break;
}
}
else if (property == "videostreams")
{
result = CVariant(CVariant::VariantTypeArray);
switch (player)
{
case Video:
if (g_application.m_pPlayer->HasPlayer())
{
for (int index = 0; index < g_application.m_pPlayer->GetVideoStreamCount(); index++)
{
SPlayerVideoStreamInfo info;
g_application.m_pPlayer->GetVideoStreamInfo(index, info);

CVariant videoStream(CVariant::VariantTypeObject);
videoStream["index"] = index;
videoStream["name"] = info.name;
videoStream["language"] = info.language;
videoStream["codec"] = info.videoCodecName;
videoStream["width"] = info.width;
videoStream["height"] = info.height;

result.append(videoStream);
}
}
break;

case Audio:
case Picture:
default:
break;
}
}
else if (property == "subtitleenabled")
{
switch (player)
Expand Down
14 changes: 14 additions & 0 deletions xbmc/interfaces/json-rpc/schema/types.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,17 @@
"channels": { "type": "integer", "required": true }
}
},
"Player.Video.Stream": {
"type": "object",
"properties": {
"index": { "type": "integer", "minimum": 0, "required": true },
"name": { "type": "string", "required": true },
"language": { "type": "string", "required": true },
"codec": { "type": "string", "required": true },
"width": { "type": "integer", "required": true },
"height": { "type": "integer", "required": true }
}
},
"Player.Subtitle": {
"type": "object",
"properties": {
Expand All @@ -223,6 +234,7 @@
"totaltime", "playlistid", "position", "repeat", "shuffled",
"canseek", "canchangespeed", "canmove", "canzoom", "canrotate",
"canshuffle", "canrepeat", "currentaudiostream", "audiostreams",
"currentvideostream", "videostreams",
"subtitleenabled", "currentsubtitle", "subtitles", "live" ]
},
"Player.Property.Value": {
Expand All @@ -247,6 +259,8 @@
"canrepeat": { "type": "boolean" },
"currentaudiostream": { "$ref": "Player.Audio.Stream" },
"audiostreams": { "type": "array", "items": { "$ref": "Player.Audio.Stream" } },
"currentvideostream": { "$ref": "Player.Video.Stream" },
"videostreams": { "type": "array", "items": { "$ref": "Player.Video.Stream" } },
"subtitleenabled": { "type": "boolean" },
"currentsubtitle": { "$ref": "Player.Subtitle" },
"subtitles": { "type": "array", "items": { "$ref": "Player.Subtitle" } },
Expand Down
Loading

0 comments on commit d05b884

Please sign in to comment.