ability to change audio track in theora video

This commit is contained in:
Juan Linietsky 2015-10-13 01:17:54 -03:00
parent c858515785
commit 52e756752e
5 changed files with 48 additions and 6 deletions

View file

@ -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 */
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;
};

View file

@ -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; }
};

View file

@ -195,7 +195,12 @@ void VideoPlayer::set_stream(const Ref<VideoStream> &p_stream) {
stop();
stream=p_stream;
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,6 +387,7 @@ 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::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;

View file

@ -71,6 +71,7 @@ class VideoPlayer : public Control {
bool loops;
int buffering_ms;
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;

View file

@ -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() {}