无法使用Kurento录制音频/视频

时间:2018-09-15 17:03:58

标签: javascript java webrtc kurento

我正在尝试使用Kurento录制音频和视频。但是我不知道问题出在哪里,媒体只是没有录制。我只看到空文件。

此外,当我尝试通过致电recorder.stop()停止录音时,我在kms中看到记录以下消息:KurentoUriEndpointImpl UriEndpointImpl.cpp:180:stop:<kmsrecorderendpoint8> Error: Already in state stop。 通过调用pipeline.release()也是一样,我在kms中看到了以下消息:Object 'OBJECT_UUID_HERE_kurento.MediaPipeline' not found (Code:40101, Type:null, Data: {"type":"MEDIA_OBJECT_NOT_FOUND"})。我似乎已经创建了对象,但是找不到它们。

这是我对kms的docker-compose定义:

version: '3'
services:
  kms:
      image: kurento/kurento-media-server:6.7.2-trusty
      network_mode: host
      ports:
          - '8888:8888'
      volumes:
          - ./data/recordings:/var/kurento

这是我的应用程序代码:

public Recording start(StartRecording message) {
    MediaPipeline pipeline = kurentoClient.createMediaPipeline();

    WebRtcEndpoint webRtcEndpoint = new WebRtcEndpoint.Builder(pipeline).build();

    MediaProfileSpecType profile = buildMediaProfile(message.getType()); // I'm sure that the profile is correct.
    RecorderEndpoint recorder = new RecorderEndpoint.Builder(pipeline, "file:///var/kurento/Recorded.webm")
            .withMediaProfile(profile)
            .build();
    recorder.addTag(TAG_KEY_ID, UUID.randomUUID().toString());

    switch (profile) {
        case WEBM:
            webRtcEndpoint.connect(recorder, MediaType.VIDEO);
            webRtcEndpoint.connect(recorder, MediaType.AUDIO);
        case WEBM_VIDEO_ONLY:
            webRtcEndpoint.connect(recorder, MediaType.VIDEO);
        case WEBM_AUDIO_ONLY:
            webRtcEndpoint.connect(recorder, MediaType.AUDIO);
    }

    // Never actually calling.
    webRtcEndpoint.addMediaStateChangedListener(event -> {
        log.info("Media state changed");
        if (event.getNewState() == MediaState.CONNECTED) {
            log.info("Trying to start recording");
            //recorder.record();
        }
    });
    String sdpAnswer = webRtcEndpoint.processOffer(message.getSdpOffer());

    recorder.record();

    recorders.put(recorder.getTag(TAG_KEY_ID), recorder);

    log.debug("The record have been requested to start");

    Recording recording = Recording.withStatus(Recording.Status.STARTING);
    recording.setRecordingId(recorder.getTag(TAG_KEY_ID));
    recording.setSdpAnswer(sdpAnswer);

    return recording;
}

还有我的前端代码:

const client = Stomp.client('ws://127.0.0.1:8080/recording');
client.connect(
  {},
  () => {
    const webRtcPeer = KurentoUtils.WebRtcPeer.WebRtcPeerSendonly(
      {
        mediaConstraints: {
          audio: true,
          video: false,
        },
      },
      error => {
        if (error) {
          console.error(error);
          return;
        }

        webRtcPeer.generateOffer((error, sdpOffer) => {
          if (error) {
            console.error('Error occurred while generating SDP offer');
            console.error(error);
            return;
          }

          console.log('SDP offer generated');

          client.send('/recording/start', {}, JSON.stringify({sdpOffer: sdpOffer, type: 'AUDIO'}));

          client.subscribe('/topic/recordings', (message) => {
            const body = JSON.parse(message.body);
            if (body.status === 'STARTING') {
              webRtcPeer.processAnswer(body.sdpAnswer, error => {
                if (error) {
                  console.error('Error occurred while precessing SDP answer');
                  console.error(error);
                  return;
                }

                console.log('SDP answer processed');
              });
            }
          });
        });
      }
    );
  }
);

谢谢您的帮助!

0 个答案:

没有答案