annotate liboggplayer-src/src/oggplayer.cpp @ 59:3eacedd172ab

Fence some lingering audio code, based on fixes from visy.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 06 Aug 2013 23:27:37 +0300
parents 105513a2e3c9
children 9c63b355c82b
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>
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 #include "imp.hpp"
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 OggPlayer::~OggPlayer() {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 imp->refs--;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 if(imp->refs==0){
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 close();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 delete imp;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 OggPlayer::OggPlayer() {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 imp = new Imp;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 OggPlayer::OggPlayer(OggPlayer& os) {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 imp = os.imp;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 imp->refs++;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 OggPlayer& OggPlayer::operator =(OggPlayer& os){
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 if(this==&os) return *this;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 imp->refs--;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 if(imp->refs==0){
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 close();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 delete imp;
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 = os.imp;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 imp->refs++;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 return *this;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 }
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 OggPlayer::OggPlayer(std::string path, AudioFormat audio_format, int channels,
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 int rate, VideoFormat video_format){
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 imp = new Imp;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 open(path, audio_format, channels, rate, video_format);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 void OggPlayer::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 if(playing()) close();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 imp->open(path, audio_format, channels, rate, video_format);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 void OggPlayer::close() {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 imp->playing = false;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 // wait for play thread to terminate (if any)
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 imp->play_thread.join();
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
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 bool OggPlayer::fail() {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 return imp->failbit;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 }
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 void OggPlayer::play() {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 imp->play();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 bool OggPlayer::playing() {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 return imp->playing;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 }
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
59
3eacedd172ab Fence some lingering audio code, based on fixes from visy.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
64 #ifdef VORBIS_SUPPORT
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 int OggPlayer::audio_read(char* buf, unsigned int size) {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 if(NULL==buf || !imp->vorbis_p || !playing() || !imp->ready()) return 0;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 boost::unique_lock<boost::mutex> lock(imp->audio_mut);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 while ((imp->cirbuf.size() < size) && playing()) {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 if(imp->cirbuf.capacity()< size)
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 imp->cirbuf.set_capacity(2*size);
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 imp->audio_ready_cond.wait(lock);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 unsigned int k = 0;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 while (k < size && !imp->cirbuf.empty()) {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 buf[k++] = imp->cirbuf.front();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 imp->cirbuf.pop_front();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 imp->audio_bytes_played+=k;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 return k;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 }
59
3eacedd172ab Fence some lingering audio code, based on fixes from visy.
Matti Hamalainen <ccr@tnsp.org>
parents: 2
diff changeset
86 #endif
2
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 bool OggPlayer::yuv_buffer_try_lock(YUVBuffer *buffer) {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 if (!playing() || !imp->theora_p || !imp->ready())
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 return false;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91 // no new data, no reason to lock
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 if(imp->last_frame_read==imp->frame)
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 return false;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 imp->video_lock.lock();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 while (!imp->videobuf_ready && playing()) {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 imp->video_ready_cond.wait(imp->video_lock);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 //ready and locked!
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 yuv_buffer yuv;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 theora_decode_YUVout(&(imp->t_state), &yuv);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 buffer->y_width = yuv.y_width;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 buffer->y_height = yuv.y_height;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 buffer->y_stride = yuv.y_stride;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 buffer->uv_width = yuv.uv_width;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 buffer->uv_height = yuv.uv_height;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107 buffer->uv_stride = yuv.uv_stride;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 buffer->y = yuv.y;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 buffer->u = yuv.u;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 buffer->v = yuv.v;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 imp->last_frame_read = imp->frame;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 return true;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 }
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 void OggPlayer::yuv_buffer_unlock() {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 imp->video_lock.unlock();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 inline int clamp(int val){
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 if(val<0) return 0;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 if(val>255) return 255;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 return val;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 bool OggPlayer::video_read(char* buf, int stride) {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 YUVBuffer yuv;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 if(NULL==buf) return false;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 if (!yuv_buffer_try_lock(&yuv))
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 return false;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 if(0==stride) stride=width()*imp->pixel_format.bpp;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 int h = height(), w = width();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 int uv_ki=yuv.y_width/yuv.uv_width;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 int uv_kj=yuv.y_height/yuv.uv_height;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 int y_offset = offset_x() + yuv.y_stride * offset_y();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 int uv_offset = offset_x()/uv_ki+yuv.uv_stride * offset_y()/uv_kj;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 int y_p,uv_p,b_p;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 for(int j=0;j<h;j++){
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 y_p=y_offset+j*yuv.y_stride;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 b_p=j*stride;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 uv_p=uv_offset+j/uv_kj*yuv.uv_stride;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 for(int i=0;i<w;i++){
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148 //http://en.wikipedia.org/wiki/YUV
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 int y = yuv.y[y_p]-16;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 int u = yuv.u[uv_p]-128;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 int v = yuv.v[uv_p]-128;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 int r =clamp((y*298+409*v+128)>>8);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 int g =clamp((y*298-100*v-208*u+128)>>8);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 int b =clamp((y*298+516*u+128)>>8);
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 buf[b_p+imp->pixel_format.r_offset]=r;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 buf[b_p+imp->pixel_format.g_offset]=g;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 buf[b_p+imp->pixel_format.b_offset]=b;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 if(4==imp->pixel_format.bpp)
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 buf[b_p+3]=255;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 b_p+=imp->pixel_format.bpp;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 y_p++;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 if( i%uv_ki == uv_ki-1 ) uv_p++;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 yuv_buffer_unlock();
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 return true;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 int OggPlayer::width() {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 return imp->t_info.width;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173 int OggPlayer::height() {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 return imp->t_info.height;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 int OggPlayer::offset_x() {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 return imp->t_info.offset_x;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 int OggPlayer::offset_y() {
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 return imp->t_info.offset_y;
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 }
105513a2e3c9 Import liboggplayer source.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182