~ubuntu-branches/debian/experimental/gpac/experimental

« back to all changes in this revision

Viewing changes to modules/avcap/avcap.cpp

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2014-02-22 18:15:00 UTC
  • mfrom: (1.2.2) (3.1.6 sid)
  • Revision ID: package-import@ubuntu.com-20140222181500-b4phupo05gjpmopa
Tags: 0.5.0+svn5104~dfsg1-1
* New  upstream version 0.5.0+svn5104~dfsg1:
  - src/utils/sha1.c is relicensed under LGPLv2.1, Closes: #730759
* Don't install modules in multi-arch directories, Closes: #730497
* Add libusb-1.0.0-dev headers because libfreenect requires this
* Fix install rule
* Follow upstream soname bump
  - Drop the symbols file for now until it has been revised thourougly
* Let binaries produce the correct svn revision
* Refresh patches
* Patch and build against libav10, Closes: #739321
* Bump standards version, no changes necessary

Show diffs side-by-side

added added

removed removed

Lines of Context:
61
61
{
62
62
public:
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)
65
65
        {
66
66
                memset(&m_pSLHeader, 0, sizeof(GF_SLHeader));
67
67
                m_pSLHeader.compositionTimeStampFlag = 1;
68
68
        }
69
 
        virtual ~GPACCaptureHandler() {}
 
69
        virtual ~GPACCaptureHandler() {
 
70
                if (m_data != NULL) {
 
71
                        gf_free(m_data);
 
72
                        m_data=NULL;
 
73
                }
 
74
        }
70
75
 
71
76
        GF_ClientService *m_pService;
72
77
        LPNETCHANNEL m_pChannel;
73
78
        GF_SLHeader m_pSLHeader;
74
79
 
 
80
        u32 m_height;
 
81
        u32 m_stride;
 
82
 
 
83
        char* m_data;
 
84
 
75
85
public:
 
86
        void AllocData(u32 height, u32 stride) {
 
87
                m_height = height;
 
88
                m_stride = stride;
 
89
                m_data = (char*)gf_malloc(m_height * m_stride);
 
90
        }
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)
83
98
{
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);
 
100
 
 
101
        if (m_data) {
 
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);
 
105
                }
 
106
                gf_term_on_sl_packet(m_pService, m_pChannel, m_data, (u32)io_buf->getValidBytes(), &m_pSLHeader, GF_OK);
 
107
        } else {
 
108
                gf_term_on_sl_packet(m_pService, m_pChannel, (char *) io_buf->getPtr(), (u32)io_buf->getValidBytes(), &m_pSLHeader, GF_OK);
 
109
        }
86
110
        io_buf->release();
87
111
}
88
112
 
123
147
        GPACCaptureHandler *audio_handler;
124
148
 
125
149
        u32 width, height, pixel_format, stride, out_size, fps;
 
150
        u32 default_4cc;
 
151
        Bool flip_video;
126
152
} AVCapIn;
127
153
 
128
154
 
129
155
Bool AVCap_CanHandleURL(GF_InputService *plug, const char *url)
130
156
{
131
 
        if (!strnicmp(url, "camera://", 9)) return 1;
132
 
        if (!strnicmp(url, "video://", 8)) return 1;
133
 
        return 0;
 
157
        if (!strnicmp(url, "camera://", 9)) return GF_TRUE;
 
158
        if (!strnicmp(url, "video://", 8)) return GF_TRUE;
 
159
        return GF_FALSE;
134
160
}
135
161
 
136
162
 
139
165
        GF_ESD *esd;
140
166
        GF_BitStream *bs;
141
167
        GF_ObjectDescriptor *od;
 
168
        const char *opt;
142
169
        AVCapIn *vcap = (AVCapIn *) plug->priv;
143
170
 
144
171
        if (!vcap || !serv || !url) return GF_BAD_PARAM;
146
173
        vcap->state = 0;
147
174
        vcap->service = serv;
148
175
 
 
176
        opt = gf_modules_get_option((GF_BaseInterface *)plug, "AVCap", "FlipVideo");
 
177
        if (opt && !strcmp(opt, "yes")) vcap->flip_video = GF_TRUE;
 
178
 
149
179
        if (!vcap->device_desc) {
150
180
                Format *format;
 
181
                u32 default_4cc;
151
182
                char *name;
152
183
                char *params = (char *) strchr(url, '?');
153
184
                if (params) params[0] = 0;
161
192
                }
162
193
 
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);
166
197
                        return GF_OK;
167
198
                }
179
210
                }
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);
185
216
                        return GF_OK;
186
217
                }
187
218
                vcap->device->getFormatMgr()->setFramerate(30);
188
219
 
 
220
                default_4cc = 0;
 
221
                opt = gf_modules_get_option((GF_BaseInterface *)plug, "AVCap", "Default4CC");
 
222
                if (opt) {
 
223
                        default_4cc = GF_4CC(opt[0], opt[1], opt[2], opt[3]);
 
224
                        vcap->device->getFormatMgr()->setFormat(default_4cc);
 
225
                }
 
226
 
 
227
 
189
228
                while (params) {
190
229
                        char *sep = (char *) strchr(params, '&');
191
230
                        if (sep) sep[0] = 0;
196
235
                                u32 w, h;
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));
200
239
                                }
201
240
                        }
202
241
                        else if (!strnicmp(params, "fps=", 4)) {
203
242
                                u32 fps;
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));
207
246
                                }
208
247
                        }
209
248
                        else if (!strnicmp(params, "stereo=", 7)) {
210
249
                        }
211
250
                        else if (!strnicmp(params, "mode=", 5)) {
212
251
                        }
 
252
                        else if (!strnicmp(params, "fmt=", 4)) {
 
253
                                if (!strnicmp(params+4, "rgb", 3)) {
 
254
                                        default_4cc = GF_4CC('3', 'B', 'G', 'R');
 
255
                                }
 
256
                                else if (!strnicmp(params+4, "yuv", 3)) {
 
257
                                        default_4cc = GF_4CC('V', 'Y', 'U', 'Y');
 
258
                                }
 
259
                                else if (strlen(params+4)>=4) {
 
260
                                        default_4cc = GF_4CC(params[4], params[5], params[6], params[7]);
 
261
                                }
 
262
                        }
213
263
 
214
264
                        if (!sep) break;
215
265
                        sep[0] = '&';
216
266
                        params = sep+1;
217
267
                }
 
268
 
218
269
                vcap->width = vcap->device->getFormatMgr()->getWidth();
219
270
                vcap->height = vcap->device->getFormatMgr()->getHeight();
220
271
                vcap->fps = vcap->device->getFormatMgr()->getFramerate();
221
 
                
 
272
 
 
273
                if (default_4cc )
 
274
                        vcap->device->getFormatMgr()->setFormat(default_4cc );
 
275
        
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;
229
283
                        break;
 
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;//
 
288
                        break;
 
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;//
 
293
                        break;
230
294
                default:
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);
234
298
                        return GF_OK;
235
299
                }
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()));
237
301
        }
238
302
 
239
303
        /*ACK connection is OK*/
266
330
        gf_bs_del(bs);
267
331
 
268
332
        gf_list_add(od->ESDescriptors, esd);
269
 
        gf_term_add_media(vcap->service, (GF_Descriptor*)od, 0);
 
333
        gf_term_add_media(vcap->service, (GF_Descriptor*)od, GF_FALSE);
270
334
 
271
335
        return GF_OK;
272
336
}
334
398
                com->get_dsi.dsi = NULL;
335
399
                com->get_dsi.dsi_len = 0;
336
400
                return GF_OK;
 
401
        default:
 
402
                break;
337
403
        }
338
404
        return GF_OK;
339
405
}
347
413
        if (ESID == 1) {
348
414
                /*video connect*/
349
415
                vcap->video_handler = new GPACCaptureHandler(vcap->service, channel);
 
416
 
 
417
                if (vcap->flip_video)
 
418
                        vcap->video_handler->AllocData(vcap->height, vcap->stride);
 
419
 
350
420
                gf_term_on_connect(vcap->service, channel, GF_OK);
351
421
        } else if (ESID == 2) {
352
422
                /*audio connect*/
375
445
 
376
446
Bool AVCap_CanHandleURLInService(GF_InputService *plug, const char *url)
377
447
{
378
 
        return 0;
 
448
        return GF_FALSE;
379
449
}
380
450
 
381
451
 
382
 
GF_EXPORT
 
452
GPAC_MODULE_EXPORT
383
453
const u32 *QueryInterfaces() 
384
454
{
385
455
        static u32 si [] = {
389
459
        return si;
390
460
}
391
461
 
392
 
GF_EXPORT
 
462
GPAC_MODULE_EXPORT
393
463
GF_BaseInterface *LoadInterface(u32 InterfaceType)
394
464
{
395
465
        if (InterfaceType == GF_NET_CLIENT_INTERFACE) {
416
486
        return NULL;
417
487
}
418
488
 
419
 
GF_EXPORT
 
489
GPAC_MODULE_EXPORT
420
490
void ShutdownInterface(GF_BaseInterface *bi)
421
491
{
422
492
        if (bi->InterfaceType==GF_NET_CLIENT_INTERFACE) {
427
497
        }
428
498
}
429
499
 
 
500
GPAC_MODULE_STATIC_DELARATION( avcap )
430
501
 
431
502
#ifdef __cplusplus
432
503
}