Mercurial > hg > forks > bilotrip-mj12
annotate liboggplayer-src/src/play.cpp @ 60:9c63b355c82b
Remove the audio code completely.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 06 Aug 2013 23:45:05 +0300 |
parents | 3eacedd172ab |
children |
rev | line source |
---|---|
2 | 1 #include "imp.hpp" |
2 | |
3 bool OggPlayer::Imp::ready() { | |
14
083c73ceb716
Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents:
2
diff
changeset
|
4 return true; |
2 | 5 } |
6 // similar to decode_audio | |
7 bool OggPlayer::Imp::decode_video() { | |
8 bool was_ready=videobuf_ready; | |
9 boost::unique_lock<boost::mutex> lock(video_mut, boost::defer_lock); | |
10 ogg_int64_t videobuf_granulepos = -1; | |
11 if (!videobuf_ready){ | |
12 if(!lock.try_lock()) | |
13 return false; | |
14 } | |
15 while (!videobuf_ready) { | |
16 // theora is one in, one out... | |
17 if (ogg_stream_packetout(&o_tsstate, &o_packet) > 0) { | |
18 | |
19 if(pp_inc){ | |
20 pp_level+=pp_inc; | |
21 theora_control(&t_state,TH_DECCTL_SET_PPLEVEL,&pp_level,sizeof(pp_level)); | |
22 pp_inc=0; | |
23 } | |
24 if (o_packet.granulepos >= 0) { | |
25 theora_control(&t_state, TH_DECCTL_SET_GRANPOS, | |
26 &o_packet.granulepos, sizeof(o_packet.granulepos)); | |
27 } | |
28 if (theora_decode_packetin(&t_state, &o_packet) == 0) { | |
29 videobuf_granulepos = t_state.granulepos; | |
30 videobuf_time = theora_granule_time(&t_state, videobuf_granulepos); | |
31 | |
32 if (videobuf_time >= get_time()){ | |
33 videobuf_ready = true; | |
34 frame++; | |
35 } | |
36 else { | |
37 // If we are too slow, reduce the pp level. | |
38 pp_inc=pp_level>0?-1:0; | |
39 } | |
40 } | |
41 | |
42 } else | |
43 break; | |
44 } | |
45 lock.unlock(); | |
46 if(videobuf_ready!=was_ready) | |
47 video_ready_cond.notify_one(); | |
48 | |
49 return !videobuf_ready; | |
50 } | |
51 | |
52 void OggPlayer::Imp::play_loop() { | |
53 if(!file_in.is_open()) return; | |
54 bool video_need_data = theora_p; | |
55 timer.restart(); | |
56 // buffer_data() will close the file on eof | |
60
9c63b355c82b
Remove the audio code completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
57 while ((file_in.is_open() || !video_need_data) && playing) { |
2 | 58 if (theora_p && !videobuf_ready) { |
59 video_need_data = decode_video(); | |
60 } | |
61 | |
62 // are we at or past time for this video frame? | |
63 if (videobuf_ready && videobuf_time <= get_time()) { | |
64 videobuf_ready = false; | |
65 } | |
66 // if no data yet for somebody, grab another page | |
60
9c63b355c82b
Remove the audio code completely.
Matti Hamalainen <ccr@tnsp.org>
parents:
59
diff
changeset
|
67 if (file_in.is_open() && (video_need_data)) { |
2 | 68 // buffer_data() can handle eof itself |
69 buffer_data(); | |
70 while (ogg_sync_pageout(&o_sync, &o_page) > 0) { | |
71 queue_page(&o_page); | |
72 } | |
73 video_need_data = false; | |
74 } | |
75 } | |
76 playing = false; | |
77 | |
78 // do not risk a lock | |
79 video_ready_cond.notify_one(); | |
80 | |
81 // cleanup | |
82 close(); | |
83 } | |
84 | |
85 void OggPlayer::Imp::play() { | |
86 playing = true; | |
87 play_thread = boost::thread(boost::bind(&OggPlayer::Imp::play_loop, this)); | |
88 } | |
89 |