]> git.nihav.org Git - nihav-player.git/blob - old/src/main.rs
hwdec-vaapi: align back kodaed frame dimensions
[nihav-player.git] / old / src / main.rs
1 extern crate sdl;
2 extern crate nihav_core;
3 extern crate nihav_registry;
4 extern crate nihav_allstuff;
5
6 use sdl::video::*;
7 use sdl::audio::{DesiredAudioSpec, Channels, AudioFormat, AudioCallback};
8 use sdl::event::{Event, Key};
9
10 use std::env;
11 use std::fs::File;
12 use std::path::Path;
13 use std::time::{Duration, SystemTime};
14 use std::thread;
15 use std::sync::mpsc;
16 use std::sync::{Arc, Mutex};
17 use std::sync::atomic::{AtomicBool, Ordering};
18 use std::str::FromStr;
19
20 use nihav_registry::detect;
21 use nihav_core::formats::*;
22 use nihav_core::frame::*;
23 use nihav_core::io::byteio::{FileReader, ByteReader};
24 use nihav_core::reorder::*;
25 use nihav_core::codecs::*;
26 use nihav_core::demuxers::*;
27 use nihav_core::scale::*;
28 use nihav_core::soundcvt::*;
29 use nihav_allstuff::*;
30
31 const AUDIO_BUF_SIZE: usize = 1024;
32
33 struct AudioFIFO {
34 data: Vec<u8>,
35 max_len: usize,
36 pos: usize,
37 end: usize,
38 done: bool,
39 full: bool,
40 }
41
42 impl AudioFIFO {
43 fn new(len: usize, max_len: usize) -> Self {
44 Self { data: vec![0; len], max_len, pos: 0, end: 0, done: false, full: false }
45 }
46 fn add(&mut self, src: &[u8]) -> bool {
47 if self.done || self.full { return true; }
48 if self.pos > 0 {
49 for i in 0..(self.end - self.pos) {
50 self.data[i] = self.data[i + self.pos];
51 }
52 self.end -= self.pos;
53 self.pos = 0;
54 }
55 if self.end + src.len() > self.max_len {
56 self.full = true;
57 return false;
58 }
59 if self.end + src.len() > self.data.len() { self.data.resize(self.end + src.len(), 0); }
60 (&mut self.data[self.end..][..src.len()]).copy_from_slice(src);
61 self.end += src.len();
62 true
63 }
64 fn consume(&mut self, dst: &mut [u8]) -> bool {
65 if self.done { for el in dst.iter_mut() { *el = 0; } return true; }
66 let size = dst.len();
67 if self.end - self.pos < size { return false; }
68 dst.copy_from_slice(&self.data[self.pos..][..size]);
69 self.pos += size;
70 if self.pos >= self.max_len / 2 { self.full = false; }
71 true
72 }
73 fn finish(&mut self) {
74 self.done = true;
75 }
76 }
77
78 struct AudioConsumer {
79 afifo: Arc<Mutex<AudioFIFO>>,
80 }
81
82 impl AudioConsumer {
83 fn new(afifo: Arc<Mutex<AudioFIFO>>) -> Self { Self { afifo } }
84 }
85
86 impl AudioCallback for AudioConsumer {
87 fn callback(&mut self, out: &mut [u8]) {
88 let mut done = false;
89 while !done {
90 let ret = self.afifo.lock();
91 if let Ok(mut afifo) = ret {
92 done = afifo.consume(out);
93 }
94 if !done { thread::sleep(Duration::from_millis(400)); }
95 }
96 }
97 }
98
99 impl Drop for AudioConsumer {
100 fn drop(&mut self) {
101 let ret = self.afifo.lock();
102 if let Ok(mut afifo) = ret {
103 afifo.finish();
104 }
105 }
106 }
107
108 struct DecoderStuff {
109 dsupp: Box<NADecoderSupport>,
110 dec: Box<dyn NADecoder + Send>,
111 reord: Box<dyn FrameReorderer + Send>,
112 }
113
114 enum SendEvent {
115 Packet(NAPacket),
116 EOF,
117 }
118
119 enum DisplayEvent {
120 RGB(u64, NABufferRef<Surface>),
121 YUV(u64, NABufferRef<Overlay>),
122 Audio(NABufferType),
123 }
124
125 impl DisplayEvent {
126 fn get_time(&self) -> u64 {
127 match *self {
128 DisplayEvent::RGB(time, _) => time,
129 DisplayEvent::YUV(time, _) => time,
130 _ => 0,
131 }
132 }
133 }
134
135 struct CommonMessages {
136 receiver: mpsc::Receiver<SendEvent>,
137 esend: mpsc::SyncSender<DisplayEvent>,
138 ev_mtx: Arc<Mutex<isize>>,
139 finished: Arc<AtomicBool>,
140 }
141
142 fn add_audio<T:Copy>(amtx: &mut Arc<Mutex<AudioFIFO>>, data: &[T]) {
143 let len = std::mem::size_of::<T>() * data.len();
144 let mut done = false;
145 while !done {
146 let ret = amtx.try_lock();
147 if let Ok(mut afifo) = ret {
148 unsafe {
149 let u8_ptr = data.as_ptr();
150 let u8_data = std::mem::transmute((u8_ptr, len));
151 done = afifo.add(u8_data);
152 }
153 }
154 if !done { std::thread::sleep(Duration::from_millis(100)); }
155 }
156 }
157
158 fn open_audio(arate: u32, amtx: Arc<Mutex<AudioFIFO>>) -> NAAudioInfo {
159 let dspec = DesiredAudioSpec {
160 freq: arate as i32, format: AudioFormat::S16Lsb, channels: Channels::Stereo, samples: AUDIO_BUF_SIZE as u16,
161 callback: Box::new(AudioConsumer::new(amtx))
162 };
163 let tspec = sdl::audio::open(dspec).unwrap();
164 //println!("target spec: {} Hz fmt {:X} {} ch {} samp {} size", tspec.freq, tspec.format as u32, if tspec.channels == Channels::Stereo { 2 } else { 1 }, tspec.samples, tspec.size);
165 sdl::audio::pause(true);
166 let dst_ch = if tspec.channels == Channels::Stereo { 2 } else { 1 };
167 let snd_fmt = match tspec.format {
168 AudioFormat::U8 => SND_U8_FORMAT,
169 AudioFormat::S8 => unimplemented!(),
170 AudioFormat::U16Lsb => unimplemented!(),
171 AudioFormat::S16Lsb => SND_S16_FORMAT,
172 AudioFormat::U16Msb => unimplemented!(),
173 AudioFormat::S16Msb => NASoniton { bits: 16, be: true, packed: false, planar: false, float: false, signed: true },
174 };
175 NAAudioInfo { sample_rate: tspec.freq as u32, channels: dst_ch, format: snd_fmt, block_len: 1024 }
176 }
177
178 fn start_audio_dec(audio_dec: Option<DecoderStuff>, dst_info: NAAudioInfo, cmsg: CommonMessages) -> thread::JoinHandle<()> {
179 thread::spawn(move || {
180 let mut audio_dec = audio_dec.unwrap();
181 let dst_chmap = if dst_info.channels == 2 {
182 NAChannelMap::from_str("L,R").unwrap()
183 } else {
184 NAChannelMap::from_str("C").unwrap()
185 };
186 loop {
187 let ret = cmsg.receiver.recv();
188 if ret.is_err() { break; }
189 if let Ok(SendEvent::EOF) = ret { break; }
190 let pkt = if let Ok(SendEvent::Packet(pkt)) = ret { pkt } else { unreachable!(); };
191 let ret = audio_dec.dec.decode(&mut audio_dec.dsupp, &pkt);
192 if let Ok(frm) = ret {
193 let buf = frm.get_buffer();
194 let out_buf = convert_audio_frame(&buf, &dst_info, &dst_chmap).unwrap();
195 cmsg.esend.send(DisplayEvent::Audio(out_buf)).unwrap();
196 let mut count = cmsg.ev_mtx.lock().unwrap();
197 *count += 1;
198 drop(count);
199 thread::yield_now();
200 } else {
201 println!("error decoding audio");
202 }
203 }
204 cmsg.finished.store(true, Ordering::Relaxed);
205 })
206 }
207
208 fn start_video_dec(video_dec: Option<DecoderStuff>, ifmt: Option<NAVideoInfo>, width: usize, height: usize, tb_num: u32, tb_den: u32, cmsg: CommonMessages, scr_mtx: Arc<Mutex<NABufferRef<Surface>>>) -> thread::JoinHandle<()> {
209 thread::spawn(move || {
210 let mut ifmt = ifmt.unwrap();
211 let mut video_dec = video_dec.unwrap();
212 let rgb32_fmt = NAPixelFormaton { model: ColorModel::RGB(RGBSubmodel::RGB), components: 3,
213 comp_info: [
214 Some(NAPixelChromaton { h_ss: 0, v_ss: 0, packed: true, depth: 8, shift: 0, comp_offs: 0, next_elem: 4 }),
215 Some(NAPixelChromaton { h_ss: 0, v_ss: 0, packed: true, depth: 8, shift: 0, comp_offs: 1, next_elem: 4 }),
216 Some(NAPixelChromaton { h_ss: 0, v_ss: 0, packed: true, depth: 8, shift: 0, comp_offs: 2, next_elem: 4 }),
217 None, None
218 ], elem_size: 4, be: false, alpha: false, palette: false };
219 let ofmt_rgb = ScaleInfo { width, height, fmt: rgb32_fmt };
220 let ofmt_yuv = ScaleInfo { width, height, fmt: YUV420_FORMAT };
221
222 let sc_ifmt = ScaleInfo { width: ifmt.get_width(), height: ifmt.get_height(), fmt: ifmt.get_format() };
223 let mut do_yuv = if let ColorModel::YUV(_) = ifmt.get_format().get_model() { true } else { false };
224 let ofmt = if do_yuv { ofmt_yuv } else { ofmt_rgb };
225 let mut opic = alloc_video_buffer(NAVideoInfo::new(width, height, false, ofmt.fmt), 4).unwrap();
226 let mut scaler = NAScale::new(sc_ifmt, ofmt).unwrap();
227 loop {
228 let ret = cmsg.receiver.recv();
229 if ret.is_err() { break; }
230 if let Ok(SendEvent::EOF) = ret { break; }
231 let pkt = if let Ok(SendEvent::Packet(pkt)) = ret { pkt } else { unreachable!() };
232 let ret = video_dec.dec.decode(&mut video_dec.dsupp, &pkt);
233 if let Ok(frm) = ret {
234 video_dec.reord.add_frame(frm);
235 while let Some(frm) = video_dec.reord.get_frame() {
236 let bt = frm.get_buffer();
237 if let NABufferType::None = bt { continue; }
238 let vinfo = bt.get_video_info().unwrap();
239 if ifmt.get_width() != vinfo.get_width() ||
240 ifmt.get_height() != vinfo.get_height() ||
241 ifmt.get_format() != vinfo.get_format() {
242 println!("reinit scaler!");
243 ifmt = vinfo.clone();
244 let sc_ifmt = ScaleInfo { width: ifmt.get_width(), height: ifmt.get_height(), fmt: ifmt.get_format() };
245 do_yuv = if let ColorModel::YUV(_) = ifmt.get_format().get_model() { true } else { false };
246 let ofmt = if do_yuv { ofmt_yuv } else { ofmt_rgb };
247 opic = alloc_video_buffer(NAVideoInfo::new(width, height, false, ofmt.fmt), 4).unwrap();
248 scaler = NAScale::new(sc_ifmt, ofmt).unwrap();
249 }
250 let ret = scaler.convert(&bt, &mut opic);
251 if ret.is_err() { println!(" scaler error {:?}", ret.err()); continue; }
252 ret.unwrap();
253 let ts = frm.get_dts().unwrap_or(frm.get_pts().unwrap_or(0));
254 let time = NATimeInfo::ts_to_time(ts, 1000, tb_num, tb_den);
255
256 let buf = opic.get_vbuf().unwrap();
257 if !do_yuv {
258 let sstride = buf.get_stride(0);
259 let src = buf.get_data();
260 let surface = Surface::new(&[SurfaceFlag::SWSurface], width as isize, height as isize, 32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0x00000000).unwrap();
261 let pitch = unsafe { (*surface.raw).pitch } as usize;
262 surface.with_lock(|x: &mut [u8]| -> bool {
263 let csize = sstride.min(pitch);
264 for (dst, src) in x.chunks_mut(pitch).zip(src.chunks(sstride)) {
265 (&mut dst[..csize]).copy_from_slice(&src[..csize]);
266 }
267 true
268 });
269 let mut count = cmsg.ev_mtx.lock().unwrap();
270 cmsg.esend.send(DisplayEvent::RGB(time, NABufferRef::new(surface))).unwrap();
271 *count += 1;
272 } else {
273 let screen = scr_mtx.lock().unwrap();
274 let overlay = screen.create_overlay(width as isize, height as isize, OverlayFormat::YV12).unwrap();
275 drop(screen);
276 while !overlay.lock() {}
277 let src = buf.get_data();
278 let ysstride = buf.get_stride(0);
279 let ysrc = &src[buf.get_offset(0)..];
280 let usstride = buf.get_stride(2);
281 let usrc = &src[buf.get_offset(2)..];
282 let vsstride = buf.get_stride(1);
283 let vsrc = &src[buf.get_offset(1)..];
284 unsafe {
285 let ydst = overlay.get_pixel_ptr(0);
286 let ydstride = overlay.get_pitch(0);
287 let udst = overlay.get_pixel_ptr(1);
288 let udstride = overlay.get_pitch(1);
289 let vdst = overlay.get_pixel_ptr(2);
290 let vdstride = overlay.get_pitch(2);
291 for (ydst, ysrc) in ydst.chunks_mut(ydstride).take(height).zip(ysrc.chunks(ysstride)) {
292 (&mut ydst[..width]).copy_from_slice(&ysrc[..width]);
293 }
294 for (udst, usrc) in udst.chunks_mut(udstride).take(height).zip(usrc.chunks(usstride)) {
295 (&mut udst[..width / 2]).copy_from_slice(&usrc[..width / 2]);
296 }
297 for (vdst, vsrc) in vdst.chunks_mut(vdstride).take(height).zip(vsrc.chunks(vsstride)) {
298 (&mut vdst[..width / 2]).copy_from_slice(&vsrc[..width / 2]);
299 }
300 }
301 overlay.unlock();
302 let mut count = cmsg.ev_mtx.lock().unwrap();
303 cmsg.esend.send(DisplayEvent::YUV(time, NABufferRef::new(overlay))).unwrap();
304 *count += 1;
305 }
306 }
307 } else {
308 println!("error decoding video");
309 }
310 }
311 cmsg.finished.store(true, Ordering::Relaxed);
312 })
313 }
314
315 fn play_file(args: Vec<String>) {
316
317 let mut cur_arg: usize = 1;
318 let mut decode_audio = true;
319 while (cur_arg < args.len()) && args[cur_arg].starts_with('-') {
320 match args[cur_arg].as_str() {
321 "--" => { break; },
322 "-an" => { decode_audio = false; },
323 _ => { println!("unknown option {}", args[cur_arg]); return; },
324 }
325 cur_arg += 1;
326 }
327 let name = args[cur_arg].as_str();
328
329 let path = Path::new(name);
330 let mut file = File::open(path).unwrap();
331 let dmx_fact;
332 let mut fr = FileReader::new_read(&mut file);
333 let mut br = ByteReader::new(&mut fr);
334 let res = detect::detect_format(name, &mut br);
335 if res.is_none() {
336 println!("cannot detect format for {}", name);
337 return;
338 }
339 let (dmx_name, _) = res.unwrap();
340 println!("trying demuxer {} on {}", dmx_name, name);
341
342 let mut dmx_reg = RegisteredDemuxers::new();
343 nihav_register_all_demuxers(&mut dmx_reg);
344 let mut dec_reg = RegisteredDecoders::new();
345 nihav_register_all_decoders(&mut dec_reg);
346
347 dmx_fact = dmx_reg.find_demuxer(dmx_name).unwrap();
348 br.seek(SeekFrom::Start(0)).unwrap();
349 let mut dmx = create_demuxer(dmx_fact, &mut br).unwrap();
350
351 let mut width = 640;
352 let mut height = 480;
353 let mut ifmt = None;
354 let mut tb_num = 0;
355 let mut tb_den = 0;
356 let mut arate = 0;
357 let mut video_str = 0;
358 let mut audio_str = 0;
359
360 let mut video_dec: Option<DecoderStuff> = None;
361 let mut audio_dec: Option<DecoderStuff> = None;
362
363 for i in 0..dmx.get_num_streams() {
364 let s = dmx.get_stream(i).unwrap();
365 let info = s.get_info();
366 let decfunc = dec_reg.find_decoder(info.get_name());
367 println!("stream {} - {} {}", i, s, info.get_name());
368 let str_id = s.get_id();
369 if info.is_video() {
370 if video_dec.is_none() {
371 if decfunc.is_none() {
372 println!("no video decoder for {} found!", info.get_name());
373 return;
374 }
375 let mut dec = (decfunc.unwrap())();
376 let mut dsupp = Box::new(NADecoderSupport::new());
377 let props = info.get_properties().get_video_info().unwrap();
378 if props.get_width() != 0 {
379 width = props.get_width();
380 height = props.get_height();
381 ifmt = Some(props.clone());
382 }
383 let reorder_depth = 3;
384 dsupp.pool_u8 = NAVideoBufferPool::new(reorder_depth);
385 dsupp.pool_u16 = NAVideoBufferPool::new(reorder_depth);
386 dsupp.pool_u32 = NAVideoBufferPool::new(reorder_depth);
387 dec.init(&mut dsupp, info).unwrap();
388 let reord = Box::new(IPBReorderer::new());
389 video_dec = Some(DecoderStuff{ dsupp, dec, reord });
390 video_str = str_id;
391 let (tbn, tbd) = s.get_timebase();
392 tb_num = tbn;
393 tb_den = tbd;
394 }
395 } else if info.is_audio() {
396 if audio_dec.is_none() && decode_audio {
397 if decfunc.is_none() {
398 println!("no audio decoder for {} found!", info.get_name());
399 } else {
400 let mut dec = (decfunc.unwrap())();
401 let mut dsupp = Box::new(NADecoderSupport::new());
402 let props = info.get_properties().get_audio_info().unwrap();
403 arate = props.get_sample_rate();
404 dec.init(&mut dsupp, info).unwrap();
405 let reord = Box::new(NoReorderer::new());
406 audio_dec = Some(DecoderStuff{ dsupp, dec, reord });
407 audio_str = str_id;
408 }
409 }
410 } else {
411 println!("decoder {} not found", info.get_name());
412 }
413 }
414
415 while (width <= 384) && (height <= 288) {
416 width <<= 1;
417 height <<= 1;
418 }
419
420 sdl::init(&[sdl::InitFlag::Video, sdl::InitFlag::Audio]);
421 sdl::wm::set_caption("NihAV Player", "nihav-player");
422 let screen = match sdl::video::set_video_mode(width as isize, height as isize, 32,
423 &[SurfaceFlag::HWSurface, SurfaceFlag::AsyncBlit, SurfaceFlag::HWAccel],
424 &[VideoFlag::DoubleBuf]) {
425 Ok(screen) => screen,
426 Err(err) => panic!("failed to set video mode: {}", err)
427 };
428
429 let (vsend, vrecv) = mpsc::sync_channel::<SendEvent>(0);
430 let (asend, arecv) = mpsc::sync_channel::<SendEvent>(0);
431 let (esend, erecv) = mpsc::sync_channel::<DisplayEvent>(50);
432 let events_mtx = Arc::new(Mutex::new(0isize));
433
434 let has_audio = audio_dec.is_some();
435 let mut amtx = Arc::new(Mutex::new(AudioFIFO::new((arate * 8) as usize, (arate * 80) as usize)));
436 let aud_finished = Arc::new(AtomicBool::new(!has_audio));
437 let audio_thread = if has_audio {
438 let ainfo = open_audio(arate, amtx.clone());
439 let cmsg = CommonMessages {
440 receiver: arecv,
441 esend: esend.clone(),
442 ev_mtx: events_mtx.clone(),
443 finished: aud_finished.clone(),
444 };
445 Some(start_audio_dec(audio_dec, ainfo, cmsg))
446 } else { None };
447
448 let has_video = video_dec.is_some();
449 let video_thread: Option<thread::JoinHandle<()>>;
450 let scr_mtx = Arc::new(Mutex::new(NABufferRef::new(screen)));
451 let vid_finished = Arc::new(AtomicBool::new(!has_video));
452 if has_video {
453 let cmsg = CommonMessages {
454 receiver: vrecv,
455 esend: esend,
456 ev_mtx: events_mtx.clone(),
457 finished: vid_finished.clone(),
458 };
459 video_thread = Some(start_video_dec(video_dec, ifmt, width, height, tb_num, tb_den, cmsg, scr_mtx.clone()));
460 } else {
461 video_thread = None;
462 };
463
464 let mut frame_queue: Vec<DisplayEvent> = Vec::new();
465
466 let systime = SystemTime::now();
467 let mut has_data = true;
468
469 'main : loop {
470 'event : loop {
471 match sdl::event::poll_event() {
472 Event::Quit => break 'main,
473 Event::None => break 'event,
474 Event::Key(k, _, _, _)
475 if k == Key::Escape || k == Key::Q
476 => break 'main,
477 Event::Key(k, _, _, _)
478 if k == Key::Space
479 => continue 'event,
480 _ => {}
481 }
482 }
483 if has_data {
484 let pktres = dmx.get_frame();
485 if let Err(DemuxerError::EOF) = pktres {
486 has_data = false;
487 if has_video {
488 vsend.send(SendEvent::EOF).unwrap();
489 }
490 if has_audio {
491 asend.send(SendEvent::EOF).unwrap();
492 }
493 } else if let Err(_) = pktres {
494 break;
495 } else if let Ok(pkt) = pktres {
496 let streamno = pkt.get_stream().get_id();
497
498 if has_video && streamno == video_str {
499 vsend.send(SendEvent::Packet(pkt)).unwrap();
500 } else if has_audio && streamno == audio_str {
501 asend.send(SendEvent::Packet(pkt)).unwrap();
502 }
503 }
504 }
505
506 let mut nevents = events_mtx.lock().unwrap();
507 while *nevents > 0 {
508 *nevents -= 1;
509 let ret = erecv.recv();
510 if ret.is_err() { break 'main; }
511 let mut disp_evt = ret.unwrap();
512 match disp_evt {
513 DisplayEvent::Audio(ref mut out_buf) => {
514 unsafe { sdl::audio::ll::SDL_LockAudio(); }
515 match out_buf {
516 NABufferType::AudioPacked(buf) => add_audio(&mut amtx, buf.get_data()),
517 NABufferType::AudioU8(buf) => add_audio(&mut amtx, buf.get_data()),
518 NABufferType::AudioI16(buf) => add_audio(&mut amtx, buf.get_data()),
519 NABufferType::AudioI32(buf) => add_audio(&mut amtx, buf.get_data()),
520 NABufferType::AudioF32(buf) => add_audio(&mut amtx, buf.get_data()),
521 _ => unreachable!(),
522 };
523 unsafe { sdl::audio::ll::SDL_UnlockAudio(); }
524 sdl::audio::pause(false);
525 },
526 _ => { frame_queue.push(disp_evt); },
527 };
528 }
529 drop(nevents);
530 if vid_finished.load(Ordering::Relaxed) &&
531 aud_finished.load(Ordering::Relaxed) && frame_queue.len() == 0 {
532 break;
533 }
534
535 if frame_queue.len() > 0 {
536 let cur_time = systime.elapsed().unwrap();
537 let disp_time = Duration::from_millis(frame_queue[0].get_time());
538
539 //println!("cur time {:?} disp time {:?}", cur_time, disp_time);
540 if (disp_time <= cur_time + Duration::from_millis(10)) && disp_time + Duration::from_millis(10) >= cur_time {
541 let screen = scr_mtx.lock().unwrap();
542 let disp_evt = frame_queue.remove(0);
543 match disp_evt {
544 DisplayEvent::RGB(_, ref surf) => {
545 screen.blit(surf);
546 screen.flip();
547 },
548 DisplayEvent::YUV(_, ref ovl) => {
549 ovl.display(Some(screen.get_rect()));
550 },
551 _ => {},
552 };
553 } else if disp_time > cur_time {
554 let diff = disp_time - cur_time;
555 if diff > Duration::from_millis(20) {
556 thread::sleep(Duration::from_millis(20));
557 } else {
558 thread::sleep(diff);
559 }
560 } else {
561 frame_queue.remove(0);
562 }
563 }
564 }
565
566 if has_audio {
567 unsafe { sdl::audio::ll::SDL_LockAudio(); }
568 let mut afifo = amtx.lock().unwrap();
569 afifo.finish();
570 drop(afifo);
571 unsafe { sdl::audio::ll::SDL_UnlockAudio(); }
572 sdl::audio::pause(true);
573 }
574 drop(vsend);
575 drop(asend);
576 if let Some(vthread) = video_thread {
577 vthread.join().unwrap();
578 }
579 if let Some(athread) = audio_thread {
580 athread.join().unwrap();
581 }
582
583 if has_audio {
584 sdl::audio::close();
585 }
586 }
587
588 fn main() {
589 let args: Vec<String> = env::args().collect();
590
591 if args.len() == 1 {
592 println!("usage: nihav-player input");
593 return;
594 }
595
596 play_file(args);
597
598 sdl::quit();
599 }