1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* RTVideoRec Realtime video recoder and encoder for Linux
*
* Copyright (C) 2004 Bent Bisballe
* Copyright (C) 2004 B. Stultiens
* Copyright (C) 2004 Koen Otter and Glenn van der Meyden
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <config.h>
#ifdef USE_GUI
#include "player.h"
// Use libdv
#include <libdv/dv.h>
#include <libdv/dv_types.h>
Player::Player(Error *err,
volatile int *grunning,
sem_t *gsem,
Queue<Frame> *gqueue,
pthread_mutex_t *gmutex)
{
// No errors has ocurred... yet!
noErrors = true;
char errbuf[256];
errobj = err;
running = grunning;
sem = gsem;
queue = gqueue;
mutex = gmutex;
sem_init(&play_sem, 0, 1);
if(SDL_Init(SDL_INIT_VIDEO) < 0) {
sprintf(errbuf, "Unable to init SDL: %s.", SDL_GetError());
errobj->pushError(errbuf);
noErrors = false;
return;
}
screen = SDL_SetVideoMode(DISPLAYWIDTH,
DISPLAYHEIGHT,
0, // 0 bpp means 'use current display depth'
SDL_HWSURFACE | SDL_ANYFORMAT | SDL_HWACCEL);
if(!screen) {
sprintf(errbuf, "Unable to set %dx%d video: %s.",
DISPLAYWIDTH, DISPLAYHEIGHT, SDL_GetError());
errobj->pushError(errbuf);
noErrors = false;
return;
}
overlay = SDL_CreateYUVOverlay(DISPLAYWIDTH,
DISPLAYHEIGHT,
SDL_IYUV_OVERLAY, screen);
if(!overlay) {
sprintf(errbuf, "Unable to create SDL overlay: %s.", SDL_GetError());
errobj->pushError(errbuf);
noErrors = false;
return;
}
}
Player::~Player()
{
SDL_FreeYUVOverlay(overlay);
SDL_Quit();
}
void Player::player()
{
SDL_Event event;
SDL_Rect rect;
Frame *frame;
// AVPicture pict;
unsigned char pixel_buffer[720 * 576][3];
// int pitches[3];
int i;
struct timespec ts;
if(!noErrors) return; // FIXME: Gracefully exit...
// Setup the displayarea.
rect.x = 0;
rect.y = 0;
rect.w = DISPLAYWIDTH;
rect.h = DISPLAYHEIGHT;
/*
//+++++Reference to the overlay pixels/pitches, only after creating a new overlay+++++
// ?????????
for(i = 0; i < 3; i++) {
pict.data[i] = overlay->pixels[i];
pict.linesize[i] = overlay->pitches[i];
}
*/
dv_decoder_t *decoder = NULL;
decoder = dv_decoder_new(FALSE, FALSE, FALSE);
decoder->quality = DV_QUALITY_BEST;
decoder->clamp_luma = FALSE;
decoder->clamp_chroma = FALSE;
while(*running) {
// Wait for the semaphore to be free... then run
sem_wait(&play_sem);
sem_post(&play_sem);
if(!SDL_WaitEvent(&event)) break; // FIXME: Gracefully exit...
switch(event.type) {
case SDL_KEYDOWN:
switch(event.key.keysym.sym) {
case SDLK_q:
case SDLK_ESCAPE:
goto quitit;
default:
break;
}
break;
case SDL_USEREVENT:
pthread_mutex_lock(mutex);
frame = queue->pop();
pthread_mutex_unlock(mutex);
if(!frame) break;
// img_convert(&pict, PIX_FMT_YUV420P, (AVPicture *)f->frame,
// PIX_FMT_YUV420P, DISPLAYWIDTH, DISPLAYHEIGHT);
SDL_LockYUVOverlay(overlay);
// libdv img decode
dv_decode_full_frame(decoder,
(const uint8_t*)frame->data,
e_dv_color_yuv,
overlay->pixels,
(int*)overlay->pitches);
// SDL_LockYUVOverlay(overlay);
// overlay->pixels = (Uint8**)pixel_buffer;
SDL_UnlockYUVOverlay(overlay);
SDL_DisplayYUVOverlay(overlay, &rect);
// delete f;
break;
case SDL_QUIT:
quitit:
*running = 0;
break;
default:
break;
}
}
/* Remove any late buffer */
/* We don't care, the encoder finishes them all */
ts.tv_sec = 0;
ts.tv_nsec = 100000000L; // 100ms
nanosleep(&ts, NULL);
pthread_mutex_lock(mutex);
frame = queue->pop();
pthread_mutex_unlock(mutex);
// if(f) delete f;
}
void Player::run()
{
player();
}
void Player::start()
{
sem_post(&play_sem);
}
void Player::stop()
{
sem_wait(&play_sem);
}
#endif /* USE_GUI */
|