将面部叠加过滤器添加到Kurento应用程序

时间:2016-05-12 07:20:39

标签: kurento

我想在我的Kurento应用程序中添加自定义OpenCV模块,但首先,出于培训目的,我想尝试集成FaceOverlay过滤器

当我把它放在One2One教程中时,我遇到了问题。本教程本身运行良好但当我创建过滤器并将其连接到端点时,无法建立通信,有时与Kurento Media Server的连接无缘无故关闭。

如果有人可以帮助我,我将不胜感激。要重现我的问题,您可以获取One2One tutorial的node.js版本,并将CallMediaPipeline.prototype.createPipeline替换为我附加的代码。

感谢。

CallMediaPipeline.prototype.createPipeline = function(callerId, calleeId, ws, callback) {
    var self = this;
    getKurentoClient(function(error, kurentoClient) {
        if (error) {
            return callback(error);
        }

        kurentoClient.create('MediaPipeline', function(error, pipeline) {
            if (error) {
                return callback(error);
            }

            pipeline.create('WebRtcEndpoint', {useDataChannels: true}, function(error, callerWebRtcEndpoint) {
                if (error) {
                    pipeline.release();
                    return callback(error);
                }

                pipeline.create('FaceOverlayFilter', function(error, faceOverlayFilter) {
                    if (error) {
                        return callback(error);
                    }
                    faceOverlayFilter.setOverlayedImage(url.format(asUrl) + 'img/mario-wings.png',
                            -0.35, -1.2, 1.6, 1.6, function(error) {
                        if (error) {
                            console.log("Error assigning image to filter");
                            return callback(error);
                        }
                    });
                    if (candidatesQueue[callerId]) {
                        while(candidatesQueue[callerId].length) {
                            var candidate = candidatesQueue[callerId].shift();
                            callerWebRtcEndpoint.addIceCandidate(candidate);
                        }
                    }

                    callerWebRtcEndpoint.on('OnIceCandidate', function(event) {
                        var candidate = kurento.register.complexTypes.IceCandidate(event.candidate);
                        userRegistry.getById(callerId).ws.send(JSON.stringify({
                            id : 'iceCandidate',
                            candidate : candidate
                        }));
                    });

                    pipeline.create('WebRtcEndpoint', {useDataChannels: true}, function(error, calleeWebRtcEndpoint) {
                        if (error) {
                            pipeline.release();
                            return callback(error);
                        }

                        if (candidatesQueue[calleeId]) {
                            while(candidatesQueue[calleeId].length) {
                                var candidate = candidatesQueue[calleeId].shift();
                                calleeWebRtcEndpoint.addIceCandidate(candidate);
                            }
                        }

                        calleeWebRtcEndpoint.on('OnIceCandidate', function(event) {
                            var candidate = kurento.register.complexTypes.IceCandidate(event.candidate);
                            userRegistry.getById(calleeId).ws.send(JSON.stringify({
                                id : 'iceCandidate',
                                candidate : candidate
                            }));
                        });

                        callerWebRtcEndpoint.connect(faceOverlayFilter, function(error) {
                            if (error) {
                                pipeline.release();
                                return callback(error);
                            }
                            faceOverlayFilter.connect(calleeWebRtcEndpoint, function(error) {
                                if (error) {
                                    pipeline.release();
                                    return callback(error);
                                }
                                calleeWebRtcEndpoint.connect(callerWebRtcEndpoint, function(error) {
                                    if (error) {
                                        pipeline.release();
                                        return callback(error);
                                    }
                                });
                                self.pipeline = pipeline;
                                self.webRtcEndpoint[callerId] = callerWebRtcEndpoint;
                                self.webRtcEndpoint[calleeId] = calleeWebRtcEndpoint;
                                callback(null);
                            });
                        });
                    });
                });
            });
        });
    })
}

0 个答案:

没有答案