summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2015-10-13 01:17:54 -0300
committerJuan Linietsky <reduzio@gmail.com>2015-10-13 01:17:54 -0300
commit52e756752e1db9e4cf7c5bb7e92d44995ad674c4 (patch)
treefe9dc54a7efac116c61333c959c44a3afc4e5794
parentc858515785e2406bfc07da587ffc3bb353b7504c (diff)
ability to change audio track in theora video
-rw-r--r--drivers/theora/video_stream_theora.cpp15
-rw-r--r--drivers/theora/video_stream_theora.h9
-rw-r--r--scene/gui/video_player.cpp23
-rw-r--r--scene/gui/video_player.h6
-rw-r--r--scene/resources/video_stream.h1
5 files changed, 48 insertions, 6 deletions
diff --git a/drivers/theora/video_stream_theora.cpp b/drivers/theora/video_stream_theora.cpp
index 48529d563b..bea49e34b7 100644
--- a/drivers/theora/video_stream_theora.cpp
+++ b/drivers/theora/video_stream_theora.cpp
@@ -238,6 +238,8 @@ void VideoStreamPlaybackTheora::set_file(const String& p_file) {
/* Ogg file open; parse the headers */
/* Only interested in Vorbis/Theora streams */
int stateflag = 0;
+
+ int audio_track_skip=audio_track;
while(!stateflag){
int ret=buffer_data();
if(ret==0)break;
@@ -264,8 +266,14 @@ void VideoStreamPlaybackTheora::set_file(const String& p_file) {
theora_p=1;
}else if(!vorbis_p && vorbis_synthesis_headerin(&vi,&vc,&op)>=0){
/* it is vorbis */
- copymem(&vo,&test,sizeof(test));
- vorbis_p=1;
+ if (audio_track_skip) {
+ vorbis_info_clear(&vi);
+ vorbis_comment_clear(&vc);
+ audio_track_skip--;
+ } else {
+ copymem(&vo,&test,sizeof(test));
+ vorbis_p=1;
+ }
}else{
/* whatever it is, we don't care about it */
ogg_stream_clear(&test);
@@ -677,7 +685,7 @@ int VideoStreamPlaybackTheora::get_channels() const{
void VideoStreamPlaybackTheora::set_audio_track(int p_idx) {
-
+ audio_track=p_idx;
}
int VideoStreamPlaybackTheora::get_mix_rate() const{
@@ -701,6 +709,7 @@ VideoStreamPlaybackTheora::VideoStreamPlaybackTheora() {
texture = Ref<ImageTexture>( memnew(ImageTexture ));
mix_callback=NULL;
mix_udata=NULL;
+ audio_track=0;
delay_compensation=0;
};
diff --git a/drivers/theora/video_stream_theora.h b/drivers/theora/video_stream_theora.h
index 77a9ae8667..95c7fe88f6 100644
--- a/drivers/theora/video_stream_theora.h
+++ b/drivers/theora/video_stream_theora.h
@@ -65,6 +65,8 @@ class VideoStreamPlaybackTheora : public VideoStreamPlayback {
AudioMixCallback mix_callback;
void* mix_udata;
+ int audio_track;
+
protected:
void clear();
@@ -113,15 +115,22 @@ class VideoStreamTheora : public VideoStream {
OBJ_TYPE(VideoStreamTheora,VideoStream);
String file;
+ int audio_track;
+
+
public:
Ref<VideoStreamPlayback> instance_playback() {
Ref<VideoStreamPlaybackTheora> pb = memnew( VideoStreamPlaybackTheora );
+ pb->set_audio_track(audio_track);
pb->set_file(file);
return pb;
}
void set_file(const String& p_file) { file=p_file; }
+ void set_audio_track(int p_track) { audio_track=p_track; }
+
+ VideoStreamTheora() { audio_track=0; }
};
diff --git a/scene/gui/video_player.cpp b/scene/gui/video_player.cpp
index aa701ff7bc..f50552b32c 100644
--- a/scene/gui/video_player.cpp
+++ b/scene/gui/video_player.cpp
@@ -195,7 +195,12 @@ void VideoPlayer::set_stream(const Ref<VideoStream> &p_stream) {
stop();
stream=p_stream;
- playback=stream->instance_playback();
+ if (stream.is_valid()) {
+ stream->set_audio_track(audio_track);
+ playback=stream->instance_playback();
+ } else {
+ playback=Ref<VideoStreamPlayback>();
+ }
if (!playback.is_null()) {
playback->set_loop(loops);
@@ -280,6 +285,14 @@ int VideoPlayer::get_buffering_msec() const{
return buffering_ms;
}
+void VideoPlayer::set_audio_track(int p_track) {
+ audio_track=p_track;
+}
+
+int VideoPlayer::get_audio_track() const {
+
+ return audio_track;
+}
void VideoPlayer::set_volume(float p_vol) {
@@ -353,6 +366,9 @@ void VideoPlayer::_bind_methods() {
ObjectTypeDB::bind_method(_MD("set_volume_db","db"),&VideoPlayer::set_volume_db);
ObjectTypeDB::bind_method(_MD("get_volume_db"),&VideoPlayer::get_volume_db);
+ ObjectTypeDB::bind_method(_MD("set_audio_track","track"),&VideoPlayer::set_audio_track);
+ ObjectTypeDB::bind_method(_MD("get_audio_track"),&VideoPlayer::get_audio_track);
+
ObjectTypeDB::bind_method(_MD("get_stream_name"),&VideoPlayer::get_stream_name);
ObjectTypeDB::bind_method(_MD("get_stream_pos"),&VideoPlayer::get_stream_pos);
@@ -371,7 +387,8 @@ void VideoPlayer::_bind_methods() {
ADD_PROPERTY( PropertyInfo(Variant::REAL, "stream/volume_db", PROPERTY_HINT_RANGE,"-80,24,0.01"), _SCS("set_volume_db"), _SCS("get_volume_db") );
ADD_PROPERTY( PropertyInfo(Variant::BOOL, "stream/autoplay"), _SCS("set_autoplay"), _SCS("has_autoplay") );
ADD_PROPERTY( PropertyInfo(Variant::BOOL, "stream/paused"), _SCS("set_paused"), _SCS("is_paused") );
- ADD_PROPERTY( PropertyInfo( Variant::BOOL, "expand" ), _SCS("set_expand"),_SCS("has_expand") );
+ ADD_PROPERTY( PropertyInfo(Variant::INT, "stream/audio_track",PROPERTY_HINT_RANGE,"0,128,1"), _SCS("set_audio_track"), _SCS("get_audio_track") );
+ ADD_PROPERTY( PropertyInfo( Variant::BOOL, "expand" ), _SCS("set_expand"),_SCS("has_expand") );
}
@@ -384,6 +401,8 @@ VideoPlayer::VideoPlayer() {
expand = true;
loops = false;
+ audio_track=0;
+
buffering_ms=500;
server_mix_rate=44100;
diff --git a/scene/gui/video_player.h b/scene/gui/video_player.h
index a0eb46bcf6..c485e3d6b6 100644
--- a/scene/gui/video_player.h
+++ b/scene/gui/video_player.h
@@ -70,7 +70,8 @@ class VideoPlayer : public Control {
bool expand;
bool loops;
int buffering_ms;
- int server_mix_rate;
+ int server_mix_rate;
+ int audio_track;
static int _audio_mix_callback(void* p_udata,const int16_t *p_data,int p_frames);
@@ -109,6 +110,9 @@ public:
void set_autoplay(bool p_vol);
bool has_autoplay() const;
+ void set_audio_track(int p_track);
+ int get_audio_track() const;
+
void set_buffering_msec(int p_msec);
int get_buffering_msec() const;
diff --git a/scene/resources/video_stream.h b/scene/resources/video_stream.h
index 3664275c78..a23ef0c64f 100644
--- a/scene/resources/video_stream.h
+++ b/scene/resources/video_stream.h
@@ -82,6 +82,7 @@ class VideoStream : public Resource {
public:
+ virtual void set_audio_track(int p_track)=0;
virtual Ref<VideoStreamPlayback> instance_playback()=0;
VideoStream() {}