annotate liboggplayer-src/src/imp.hpp @ 14:083c73ceb716

Get rid of the vorbis related code.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 05 Aug 2013 16:54:46 +0300
parents 105513a2e3c9
children 74b28a572438
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 #include <oggplayer.h>
14
083c73ceb716 Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
2 #ifdef VORBIS_SUPPORT
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 #include "SDL_audiocvt.hpp"
14
083c73ceb716 Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
4 #endif
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 #include <fstream>
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 #include <vector>
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #include <theora/theora.h>
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #include <vorbis/codec.h>
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #include <boost/thread.hpp>
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #include <boost/bind.hpp>
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #include <boost/thread/mutex.hpp>
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 #include <boost/thread/locks.hpp>
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 #include <boost/thread/condition.hpp>
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 #include <boost/circular_buffer.hpp>
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 #include <boost/timer.hpp>
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 struct OggPlayer::Imp {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 Imp() :
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 cirbuf(0),video_lock(video_mut, boost::defer_lock){
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 failbit = false;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 playing = false;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 need_close = false;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 time_factor = 1;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 refs = 1;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 ~Imp() {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 // open() tears down the partial setup on fail
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 if (!failbit)
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 close();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 int queue_page(ogg_page * page);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 bool buffer_data();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 double get_time();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 void close();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 bool init_decoders();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 bool parse_headers();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 void open(std::string path, AudioFormat audio_format, int channels,
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 int rate, VideoFormat video_format);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 bool decode_audio();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 bool decode_video();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 bool ready();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 void play();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 void play_loop();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 bool failbit;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 std::ifstream file_in;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 int theora_p;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 int vorbis_p;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 ogg_sync_state o_sync;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 vorbis_comment v_comment;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 theora_info t_info;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 theora_comment t_comment;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 vorbis_info v_info;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 ogg_page o_page;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 ogg_packet o_packet;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 ogg_stream_state o_tsstate;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 ogg_stream_state o_vsstate;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 theora_state t_state;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 vorbis_dsp_state v_state;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 vorbis_block v_block;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 int pp_level_max;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 int pp_level;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 int pp_inc;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 char* audio_buffer;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 boost::circular_buffer<char> cirbuf;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 unsigned int audio_buffer_size;
14
083c73ceb716 Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
77 #ifdef VORBIS_SUPPORT
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 SDL_AudioCVT cvt;
14
083c73ceb716 Get rid of the vorbis related code.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
79 #endif
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 bool playing;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 boost::thread play_thread;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 boost::mutex audio_mut;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 boost::mutex video_mut;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 boost::condition_variable audio_ready_cond;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 boost::condition_variable video_ready_cond;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 bool videobuf_ready;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 double videobuf_time;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 bool audio_cache_ready;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 // This lock should only be used from the main thread
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 boost::unique_lock<boost::mutex> video_lock;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 // These variables are used to identify the frames (not just count them, not a debug variable)
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 // see video_buffer_try_lock and video_read
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 int frame;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 int last_frame_read;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 int audio_bytes_played;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 struct AudioGranulePos {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 int pos;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 double set_time;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 };
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 std::deque<AudioGranulePos> audio_granule_poses;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 double time_factor;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 struct PixelFormat{
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 void set(int r,int g,int b,int bpp){
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 r_offset = r;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 g_offset = g;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 b_offset = b;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 this->bpp =bpp;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116 int r_offset;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 int g_offset;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 int b_offset;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 // if bpp=4 we have an alpha channel at offset 4
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 int bpp;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 } pixel_format;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 bool need_close;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 boost::timer timer;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 int refs;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 };