sdl_context: sdl2::Sdl,
vsystem: sdl2::VideoSubsystem,
asystem: sdl2::AudioSubsystem,
- xpos: Option<i32>,
- ypos: Option<i32>,
acontrol: AudioControl,
vcontrol: VideoControl,
let vcontrol = VideoControl::new(None, 0, 0, 0, 0);
Self {
sdl_context, asystem, vsystem,
- xpos: None,
- ypos: None,
acontrol, vcontrol,
}
Ok(false)
}
- fn play(&mut self, name: &str, start_time: NATimePoint) {
+ fn play(&mut self, mut window: Window, name: &str, start_time: NATimePoint) -> Window {
debug_log!(self; {format!("Playing {}", name)});
// prepare data source
handle
} else {
println!("failed to open {}", name);
- return;
+ return window;
};
let mut fr = FileReader::new_read(&mut file);
let mut br = ByteReader::new(&mut fr);
let res = detect::detect_format(name, &mut br);
if res.is_none() {
println!("cannot detect format for {}", name);
- return;
+ return window;
}
let (dmx_name, _score) = res.unwrap();
debug_log!(self; {format!(" found demuxer {} with score {:?}", dmx_name, _score)});
let ret = dmx_reg.find_demuxer(dmx_name);
if ret.is_none() {
println!("error finding {} demuxer", dmx_name);
- return;
+ return window;
}
let dmx_fact = ret.unwrap();
br.seek(SeekFrom::Start(0)).expect("should be able to seek to the start");
let ret = create_demuxer(dmx_fact, &mut br);
if ret.is_err() {
println!("error creating demuxer");
- return;
+ return window;
}
let mut dmx = ret.unwrap();
if start_time != NATimePoint::None {
dsupp.pool_u32 = NAVideoBufferPool::new(reorder_depth);
if dec.init(&mut dsupp, info).is_err() {
println!("failed to initialise video decoder");
- return;
+ return window;
}
video_dec = Some(DecoderStuff{ dsupp, dec: DecoderType::Video(dec, reord) });
self.video_str = str_id;
}
if dec.init(&mut dsupp, info).is_err() {
println!("failed to initialise audio decoder");
- return;
+ return window;
}
audio_dec = Some(DecoderStuff{ dsupp, dec: DecoderType::Audio(dec) });
self.audio_str = str_id;
}
if !self.has_video && !self.has_audio {
println!("No playable streams found.");
- return;
+ return window;
}
while (width <= 384) && (height <= 288) {
} else {
"NihAV player".to_owned()
};
- let mut builder = self.vsystem.window(&wname, width as u32, height as u32);
- let window = if let (Some(xpos), Some(ypos)) = (self.xpos, self.ypos) {
- builder.position(xpos, ypos).build().expect("should be able to set window position")
- } else {
- builder.position_centered().build().expect("should be able to centre window")
- };
+ window.set_title(&wname).expect("set window title");
+ window.set_size(width as u32, height as u32).expect("resize window");
+ window.show();
let mut canvas = window.into_canvas().build().expect("should be able to build canvas");
let texture_creator = canvas.texture_creator();
let mut disp_q = DispQueue::new(&texture_creator, width, height, if self.has_video { FRAME_QUEUE_LEN } else { 0 });
self.has_audio = self.acontrol.has_audio();
if !self.has_video && !self.has_audio {
println!("No playable streams.");
- return;
+ return canvas.into_window();
}
// play
new_vcontrol.finish();
std::mem::swap(&mut self.acontrol, &mut new_acontrol);
new_acontrol.finish();
- return;
+ return canvas.into_window();
}
self.tkeep.reset_all(if !disp_q.is_empty() { disp_q.first_ts } else { 0 });
if !self.paused {
thread::sleep(Duration::from_millis(20));
}
}
- let (xpos, ypos) = canvas.into_window().position();
- self.xpos = Some(xpos);
- self.ypos = Some(ypos);
println!();
std::mem::swap(&mut self.vcontrol, &mut new_vcontrol);
new_vcontrol.finish();
std::mem::swap(&mut self.acontrol, &mut new_acontrol);
new_acontrol.finish();
+ canvas.into_window()
}
}
}
let mut player = Player::new();
+ let mut builder = player.vsystem.window("NihAV Player", 640, 480);
+ let mut window = builder.position_centered().hidden().build().expect("should be able to centre window");
let mut aiter = args.iter().skip(1);
let mut seek_time = NATimePoint::None;
}
},
_ => {
- player.play(arg, seek_time);
+ window = player.play(window, arg, seek_time);
if player.end { break; }
seek_time = NATimePoint::None;
},