63
63
GPACCaptureHandler(GF_ClientService *service, LPNETCHANNEL channel)
64
: m_pService(service), m_pChannel(channel)
64
: m_pService(service), m_pChannel(channel), m_data(NULL)
66
66
memset(&m_pSLHeader, 0, sizeof(GF_SLHeader));
67
67
m_pSLHeader.compositionTimeStampFlag = 1;
69
virtual ~GPACCaptureHandler() {}
69
virtual ~GPACCaptureHandler() {
71
76
GF_ClientService *m_pService;
72
77
LPNETCHANNEL m_pChannel;
73
78
GF_SLHeader m_pSLHeader;
86
void AllocData(u32 height, u32 stride) {
89
m_data = (char*)gf_malloc(m_height * m_stride);
76
91
/* This method is called by the CaptureManager, when new data was captured.
77
92
* \param io_buf The buffer, that contains the captured data. */
78
93
void handleCaptureEvent(IOBuffer* io_buf);
82
97
void GPACCaptureHandler::handleCaptureEvent(IOBuffer* io_buf)
84
99
m_pSLHeader.compositionTimeStamp = io_buf->getTimestamp();
85
gf_term_on_sl_packet(m_pService, m_pChannel, (char *) io_buf->getPtr(), io_buf->getValidBytes(), &m_pSLHeader, GF_OK);
102
char* data = (char*)io_buf->getPtr();
103
for (u32 i=0; i<m_height; i++) {
104
memcpy(m_data + (m_height - 1 - i) * m_stride, data + i*m_stride, m_stride);
106
gf_term_on_sl_packet(m_pService, m_pChannel, m_data, (u32)io_buf->getValidBytes(), &m_pSLHeader, GF_OK);
108
gf_term_on_sl_packet(m_pService, m_pChannel, (char *) io_buf->getPtr(), (u32)io_buf->getValidBytes(), &m_pSLHeader, GF_OK);
86
110
io_buf->release();
123
147
GPACCaptureHandler *audio_handler;
125
149
u32 width, height, pixel_format, stride, out_size, fps;
129
155
Bool AVCap_CanHandleURL(GF_InputService *plug, const char *url)
131
if (!strnicmp(url, "camera://", 9)) return 1;
132
if (!strnicmp(url, "video://", 8)) return 1;
157
if (!strnicmp(url, "camera://", 9)) return GF_TRUE;
158
if (!strnicmp(url, "video://", 8)) return GF_TRUE;
147
174
vcap->service = serv;
176
opt = gf_modules_get_option((GF_BaseInterface *)plug, "AVCap", "FlipVideo");
177
if (opt && !strcmp(opt, "yes")) vcap->flip_video = GF_TRUE;
149
179
if (!vcap->device_desc) {
152
183
char *params = (char *) strchr(url, '?');
153
184
if (params) params[0] = 0;
163
194
if (!vcap->device_desc) {
164
GF_LOG(GF_LOG_ERROR, GF_LOG_MODULE, ("[VideoCapture]�Failed to instanciate AVCap\n"));
195
GF_LOG(GF_LOG_ERROR, GF_LOG_MODULE, ("[VideoCapture] Failed to instanciate AVCap\n"));
165
196
gf_term_on_connect(serv, NULL, GF_REMOTE_SERVICE_ERROR);
180
211
vcap->device = vcap->device_desc->getDevice();
181
212
if (!vcap->device) {
182
GF_LOG(GF_LOG_ERROR, GF_LOG_MODULE, ("[VideoCapture]�Failed to initialize capture device\n"));
213
GF_LOG(GF_LOG_ERROR, GF_LOG_MODULE, ("[VideoCapture] Failed to initialize capture device\n"));
183
214
vcap->device_desc->close();
184
215
gf_term_on_connect(serv, NULL, GF_SERVICE_ERROR);
187
218
vcap->device->getFormatMgr()->setFramerate(30);
221
opt = gf_modules_get_option((GF_BaseInterface *)plug, "AVCap", "Default4CC");
223
default_4cc = GF_4CC(opt[0], opt[1], opt[2], opt[3]);
224
vcap->device->getFormatMgr()->setFormat(default_4cc);
190
229
char *sep = (char *) strchr(params, '&');
191
230
if (sep) sep[0] = 0;
197
236
if (sscanf(params+11, "%dx%d", &w, &h)==2) {
198
237
vcap->device->getFormatMgr()->setResolution(w, h);
199
GF_LOG(GF_LOG_INFO, GF_LOG_MODULE, ("[VideoCapture]�Set resolution to %dx%d\n", w, h));
238
GF_LOG(GF_LOG_INFO, GF_LOG_MODULE, ("[VideoCapture] Set resolution to %dx%d\n", w, h));
202
241
else if (!strnicmp(params, "fps=", 4)) {
204
243
if (sscanf(params+4, "%d", &fps)==1) {
205
244
vcap->device->getFormatMgr()->setFramerate(fps);
206
GF_LOG(GF_LOG_INFO, GF_LOG_MODULE, ("[VideoCapture]�Set framerate to %d\n", fps));
245
GF_LOG(GF_LOG_INFO, GF_LOG_MODULE, ("[VideoCapture] Set framerate to %d\n", fps));
209
248
else if (!strnicmp(params, "stereo=", 7)) {
211
250
else if (!strnicmp(params, "mode=", 5)) {
252
else if (!strnicmp(params, "fmt=", 4)) {
253
if (!strnicmp(params+4, "rgb", 3)) {
254
default_4cc = GF_4CC('3', 'B', 'G', 'R');
256
else if (!strnicmp(params+4, "yuv", 3)) {
257
default_4cc = GF_4CC('V', 'Y', 'U', 'Y');
259
else if (strlen(params+4)>=4) {
260
default_4cc = GF_4CC(params[4], params[5], params[6], params[7]);
218
269
vcap->width = vcap->device->getFormatMgr()->getWidth();
219
270
vcap->height = vcap->device->getFormatMgr()->getHeight();
220
271
vcap->fps = vcap->device->getFormatMgr()->getFramerate();
274
vcap->device->getFormatMgr()->setFormat(default_4cc );
222
276
format = vcap->device->getFormatMgr()->getFormat();
223
277
switch (format->getFourcc()) {
224
278
case GF_4CC('V', 'Y', 'U', 'Y'):
227
281
vcap->stride = 2*vcap->width;
228
282
vcap->out_size = 2*vcap->width*vcap->height;
284
case GF_4CC('2', '1', 'U', 'Y'):
285
vcap->pixel_format = GF_PIXEL_I420;
286
vcap->stride = (u32)vcap->device->getFormatMgr()->getBytesPerLine();//1.5*vcap->width;//
287
vcap->out_size = (u32)vcap->device->getFormatMgr()->getImageSize();//1.5*vcap->width*vcap->height;//
289
case GF_4CC('3', 'B', 'G', 'R'):
290
vcap->pixel_format = GF_PIXEL_BGR_24;
291
vcap->stride = vcap->device->getFormatMgr()->getBytesPerLine();//1.5*vcap->width;//
292
vcap->out_size = (u32)vcap->device->getFormatMgr()->getImageSize();//1.5*vcap->width*vcap->height;//
231
GF_LOG(GF_LOG_ERROR, GF_LOG_MODULE, ("[VideoCapture]�Unsupported 4CC %s (%08x) from capture device\n", gf_4cc_to_str(format->getFourcc()), format->getFourcc()));
295
GF_LOG(GF_LOG_ERROR, GF_LOG_MODULE, ("[VideoCapture] Unsupported 4CC %s (%08x) from capture device\n", gf_4cc_to_str(format->getFourcc()), format->getFourcc()));
232
296
vcap->device_desc->close();
233
297
gf_term_on_connect(serv, NULL, GF_NOT_SUPPORTED);
236
GF_LOG(GF_LOG_INFO, GF_LOG_MODULE, ("[VideoCapture]�Device configured - resolution %dx%d - Frame Rate %d - Pixel Format %s (Device 4CC %08x) \n", vcap->width, vcap->height, vcap->fps, gf_4cc_to_str(vcap->pixel_format), format->getFourcc()));
300
GF_LOG(GF_LOG_INFO, GF_LOG_MODULE, ("[VideoCapture] Device configured - resolution %dx%d - Frame Rate %d - Pixel Format %s (Device 4CC %08x) \n", vcap->width, vcap->height, vcap->fps, gf_4cc_to_str(vcap->pixel_format), format->getFourcc()));
239
303
/*ACK connection is OK*/