使用 gstreamer 收听来自 kurento 媒体服务器的音频流

listen to audio stream from kurento media server with gstreamer

我正在尝试将音频流从 A 点发送到 kurento 媒体服务器,并在 B 点使用 gstreamer 接收该音频流。 我想要实现的目标应该是这样的:

(点 A)----使用 GSTREAMER 发送音频流--->(KURENTO)----音频流----->(点 B)---使用 GSTREMAER 获取音频- ---!

到目前为止我写了下面的代码:

function createOutGoingAudioStream() {

var sdpOffer = " v=0\r\n"
        + "o=- 0 0 IN IP4 0.0.0.0\r\n"
        + "c=IN IP4 0.0.0.0\r\n"
        + "t=0 0\r\n"
        + "m=audio 5005 RTP/AVP 0\r\n"
        + "a=rtpmap:0 PCMU/8000\r\n";

var pipeline;   
console.log();  
console.log("Starting Audio Stream from Command Post.....");    

// get kurento client
    getKurentoClient(function(error, kurentoClient) {
        if (error) {
            return callback(error);
        }


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

            // create first rtpEndpoint for the incoming audio stream    
        pipeline.create('RtpEndpoint', function(error, rtpEndpoint) {
                if (error) {
                    pipeline.release();
                return callback(error);
                }
            console.log('audio RTP Endpoint created successfully!');

            rtpEndpoint.processOffer(sdpOffer, function(error, sdpAnswer) {
                            if (error) {
                                    pipeline.release();
                                    return callback(error);
                            }
                console.log(sdpAnswer);
                console.log();
                        // Start a gstreamer audio stream over the audio port that we got from the kurento server
                        var jsonSdpAnswer = transform.parse(sdpAnswer);
                        var port = jsonSdpAnswer.media[0].port;

                console.log("Starting audio stream to the kurento server: ");
                                    console.log('sh gstreamer.sh ' + port +  ' > log.txt')

                exec('sh gstreamer.sh ' + port + ' > log.txt', function(err, stdout, stderr) {
                            if (err) {
                                    console.error(err);
                                    return;
                            }
                        //if all is ok nothing wil prompt to the console
                        console.log(stdout);
                        });
            });

            // create second rtpEndpoint for the outgoing to the odroid's audio stream    
                        pipeline.create('RtpEndpoint', function(error, outRtpEndpoint) {
                                if (error) {
                                        pipeline.release();
                                        return callback(error);
                                }
                                console.log('second RTP Endpoint created successfully!');


                rtpEndpoint.connect(outRtpEndpoint, function(error){
                        if(error) return onError(error);
                });
                outRtpEndpoint.generateOffer(function(error,offerSdp){
                    if(error) return onError(error);
                    console.log("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
                    console.log(offerSdp);
                });
                        });
        });
    });
});
}

我从 kurento 服务器获取 outRtpEndpoint 的 sdpOffer,它看起来像这样:

sdp Offer

为了收听该流我正在尝试做什么并不重要,它只是不想工作。我究竟做错了什么 ?

如果有任何帮助,我将不胜感激。

谢谢!!!

我能够解决问题。我在 A 点从浏览器 (webrtcEndpoint) 获取源音频流,并将该端点连接到 rtpEndpoint,然后从那里我获取到 B 点的流。 (A 点 - 网络浏览器 -> webrtcEndpoint) -> (Kurento -> rtpEndpoint) -> (B 点 - ffplay) .

function createOutGoingAudioStream(sessionId,ws, sdpOffer, callback){
if (!sessionId) {
    return callback('Cannot use undefined sessionId');
}

getKurentoClient(function(error, kurentoClient) {
    if (error) {
        return callback(error);
    }

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

        createMediaElements(pipeline, ws, function(error, webRtcEndpoint) {
            if (error) {
                pipeline.release();
                return callback(error);
            }

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

            connectMediaElements(webRtcEndpoint, function(error) {
               if (error) {
                    pipeline.release();
                    return callback(error);
                }

                webRtcEndpoint.on('OnIceCandidate', function(event) {
                    var candidate = kurento.getComplexType('IceCandidate')(event.candidate);
                   ws.send(JSON.stringify({
                       id : 'iceCandidate',
                        candidate : candidate
                    }));
                });

                webRtcEndpoint.processOffer(sdpOffer, function(error, sdpAnswer) {
                    if (error) {
                        pipeline.release();
                        return callback(error);
                    }

                    sessions[sessionId] = {
                        'pipeline' : pipeline,
                        'webRtcEndpoint' : webRtcEndpoint
                    }
                    return callback(null, sdpAnswer);
                });

                webRtcEndpoint.gatherCandidates(function(error) {
                    if (error) {
                        return callback(error);
                    }



                            var sdp = 'v=0';
                            sdp += '\nc=IN IP4 IP_WHERE_YOU_WANT_TO_GET_THE_STREAM'; // this is the ip where the kurento should stream to
                            sdp += '\nm=audio 8080 RTP/AVP 0'; // at port 8080 you will have an audio stream
                            sdp += '\na=rtpmap:0 PCMU/8000';
                            sdp += '\nm=video 9090 RTP/AVP 101'; // at port 9090 you will have a video stream 
                            sdp += '\na=rtpmap:101 H264/90000';

                            pipeline.create('RtpEndpoint', function(err, rtpEndpoint){
                            rtpEndpoint.processOffer(sdp, function(error, sdpAnswer) {
                                    if (error) {
                                            return callback(error);
                                    }

                console.log("################################################");
                console.log(sdpAnswer);
                console.log("################################################");
                             });


            webRtcEndpoint.connect(rtpEndpoint, function(err, rtpEndpoint) { if(err) { console.log("Error!"); } });
                            });

       });
            });
        });
    });
});
}

在您流式传输到的计算机上,您可以通过以下方式收听流式传输:

ffplay  rtp://IP_FROM_THE_SDP_OFFER_IN_THE_CODE_ABOVE:AUDIO_PORT_FROM_THE_SDP_OFFER_FROM_THE_CODE_ABOVE