Commit 3c08e147 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

npapi: Fix track operations

parent c99183fe
...@@ -104,26 +104,20 @@ void vlc_player::play() ...@@ -104,26 +104,20 @@ void vlc_player::play()
int vlc_player::currentAudioTrack() int vlc_player::currentAudioTrack()
{ {
auto current = _mp.spu(); auto current = _mp.audioTrack();
if ( current < 0 ) auto tracks = _mp.audioTrackDescription();
return -1;
auto tracks = _mp.spuDescription();
return getTrack( current, tracks ); return getTrack( current, tracks );
} }
int vlc_player::currentSubtitleTrack() int vlc_player::currentSubtitleTrack()
{ {
auto current = _mp.spu(); auto current = _mp.spu();
if ( current < 0 )
return -1;
auto tracks = _mp.spuDescription(); auto tracks = _mp.spuDescription();
return getTrack( current, tracks ); return getTrack( current, tracks );
} }
int vlc_player::getTrack( int currentId, const std::vector<VLC::TrackDescription>& tracks ) int vlc_player::getTrack( int currentId, const std::vector<VLC::TrackDescription>& tracks )
{ {
if ( currentId < 0 )
return -1;
if ( tracks.empty() ) if ( tracks.empty() )
return -1; return -1;
......
...@@ -252,23 +252,8 @@ LibvlcAudioNPObject::getProperty(int index, NPVariant &result) ...@@ -252,23 +252,8 @@ LibvlcAudioNPObject::getProperty(int index, NPVariant &result)
} }
case ID_audio_track: case ID_audio_track:
{ {
/* get the current internal audio track ID */ int track = p_plugin->player().currentAudioTrack();
int actualTrack = mp.audioTrack(); INT32_TO_NPVARIANT(track, result);
int audioTrackCount = mp.audioTrackCount();
if (audioTrackCount < 0) {
INT32_TO_NPVARIANT(actualTrack, result);
return INVOKERESULT_NO_ERROR;
}
auto tracks = mp.audioTrackDescription();
auto t = std::find_if(begin(tracks), end(tracks), [actualTrack](const VLC::TrackDescription& td) {
return td.id() == actualTrack;
});
if ( t == end( tracks ) )
INT32_TO_NPVARIANT(tracks.size(), result);
else
INT32_TO_NPVARIANT(actualTrack, result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
case ID_audio_count: case ID_audio_count:
...@@ -324,8 +309,10 @@ LibvlcAudioNPObject::setProperty(int index, const NPVariant &value) ...@@ -324,8 +309,10 @@ LibvlcAudioNPObject::setProperty(int index, const NPVariant &value)
case ID_audio_track: case ID_audio_track:
if( v.is<int>() ) if( v.is<int>() )
{ {
int trackIdx = v; auto tracks = mp.audioTrackDescription();
if ( mp.setAudioTrack( trackIdx ) ) if ( v >= tracks.size() )
return INVOKERESULT_INVALID_VALUE;
if ( mp.setAudioTrack( tracks[v].id() ) )
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
return INVOKERESULT_INVALID_VALUE; return INVOKERESULT_INVALID_VALUE;
...@@ -383,18 +370,13 @@ LibvlcAudioNPObject::invoke(int index, const NPVariant *args, ...@@ -383,18 +370,13 @@ LibvlcAudioNPObject::invoke(int index, const NPVariant *args,
if ( argCount < 1 ) if ( argCount < 1 )
return INVOKERESULT_INVALID_ARGS; return INVOKERESULT_INVALID_ARGS;
auto v = npapi::Variant( args[0] ); auto v = npapi::Variant( args[0] );
if( !v.is<int>() ) if( v.is<int>() )
{ {
int fakeTrackIndex = v;
auto tracks = mp.audioTrackDescription(); auto tracks = mp.audioTrackDescription();
auto track = std::find_if( begin( tracks ), end( tracks ), [fakeTrackIndex](const VLC::TrackDescription& t) { if ( v >= tracks.size() )
return t.id() == fakeTrackIndex;
});
if (track == end( tracks ) )
return INVOKERESULT_INVALID_VALUE; return INVOKERESULT_INVALID_VALUE;
/* display the name of the track chosen */ /* display the name of the track chosen */
return invokeResultString( (*track).name().c_str(), result ); return invokeResultString( tracks[v].name().c_str(), result );
} }
return INVOKERESULT_NO_SUCH_METHOD; return INVOKERESULT_NO_SUCH_METHOD;
} }
...@@ -1217,7 +1199,7 @@ LibvlcSubtitleNPObject::getProperty(int index, NPVariant &result) ...@@ -1217,7 +1199,7 @@ LibvlcSubtitleNPObject::getProperty(int index, NPVariant &result)
case ID_subtitle_track: case ID_subtitle_track:
{ {
/* get the current internal subtitles track ID */ /* get the current internal subtitles track ID */
int actualTrack = mp.spu(); int actualTrack = p_plugin->player().currentSubtitleTrack();
INT32_TO_NPVARIANT(actualTrack, result); INT32_TO_NPVARIANT(actualTrack, result);
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
...@@ -1252,7 +1234,10 @@ LibvlcSubtitleNPObject::setProperty(int index, const NPVariant &value) ...@@ -1252,7 +1234,10 @@ LibvlcSubtitleNPObject::setProperty(int index, const NPVariant &value)
auto v = npapi::Variant( value ); auto v = npapi::Variant( value );
if( v.is<int>() ) if( v.is<int>() )
{ {
if ( mp.setSpu( v ) ) auto tracks = mp.spuDescription();
if ( v >= tracks.size() )
return INVOKERESULT_INVALID_ARGS;
if ( mp.setSpu( tracks[ v ].id() ) )
return INVOKERESULT_NO_ERROR; return INVOKERESULT_NO_ERROR;
} }
return INVOKERESULT_INVALID_VALUE; return INVOKERESULT_INVALID_VALUE;
...@@ -1294,16 +1279,11 @@ LibvlcSubtitleNPObject::invoke(int index, const NPVariant *args, ...@@ -1294,16 +1279,11 @@ LibvlcSubtitleNPObject::invoke(int index, const NPVariant *args,
auto v = npapi::Variant( args[0] ); auto v = npapi::Variant( args[0] );
if ( v.is<int>() ) if ( v.is<int>() )
{ {
int fakeTrackIndex = v;
auto tracks = mp.spuDescription(); auto tracks = mp.spuDescription();
auto track = std::find_if( begin( tracks ), end( tracks ), [fakeTrackIndex](const VLC::TrackDescription& t) { if ( v >= tracks.size() )
return t.id() == fakeTrackIndex;
});
if (track == end( tracks ) )
return INVOKERESULT_INVALID_VALUE; return INVOKERESULT_INVALID_VALUE;
/* display the name of the track chosen */ /* display the name of the track chosen */
return invokeResultString( (*track).name().c_str(), result ); return invokeResultString( tracks[v].name().c_str(), result );
} }
return INVOKERESULT_NO_SUCH_METHOD; return INVOKERESULT_NO_SUCH_METHOD;
} }
......
...@@ -97,7 +97,7 @@ protected: ...@@ -97,7 +97,7 @@ protected:
_class = const_cast<NPClass *>(aClass); _class = const_cast<NPClass *>(aClass);
referenceCount = 1; referenceCount = 1;
}; };
virtual ~RuntimeNPObject() {}; virtual ~RuntimeNPObject() = default;
friend void RuntimeNPClassDeallocate(NPObject *npobj); friend void RuntimeNPClassDeallocate(NPObject *npobj);
friend void RuntimeNPClassInvalidate(NPObject *npobj); friend void RuntimeNPClassInvalidate(NPObject *npobj);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment