Java Code Examples for org.red5.server.api.service.IPendingServiceCall#getResult()

The following examples show how to use org.red5.server.api.service.IPendingServiceCall#getResult() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StreamingProxy.java    From red5-client with Apache License 2.0 6 votes vote down vote up
@Override
public void resultReceived(IPendingServiceCall call) {
    String method = call.getServiceMethodName();
    log.debug("resultReceived: {}", method);
    if ("connect".equals(method)) {
        //rtmpClient.releaseStream(this, new Object[] { publishName });
        timer.schedule(new BandwidthStatusTask(), 2000L);
    } else if ("releaseStream".equals(method)) {
        //rtmpClient.invoke("FCPublish", new Object[] { publishName }, this);
    } else if ("createStream".equals(method)) {
        setState(StreamState.PUBLISHING);
        Object result = call.getResult();
        if (result instanceof Number) {
            streamId = (Number) result;
            log.debug("Publishing: {}", state);
            rtmpClient.publish(streamId, publishName, publishMode, this);
        } else {
            rtmpClient.disconnect();
            setState(StreamState.STOPPED);
        }
    } else if ("FCPublish".equals(method)) {

    }
}
 
Example 2
Source File: BaseRTMPClientHandler.java    From red5-client with Apache License 2.0 6 votes vote down vote up
@Override
public void resultReceived(IPendingServiceCall call) {
    Number streamId = (Number) call.getResult();
    log.debug("CreateStreamCallBack resultReceived - stream id: {} call: {} connection: {}", streamId, call, conn);
    if (conn != null && streamId != null) {
        log.debug("Setting new net stream");
        NetStream stream = new NetStream(streamEventDispatcher);
        stream.setConnection(conn);
        stream.setStreamId(streamId);
        conn.addClientStream(stream);
        NetStreamPrivateData streamData = new NetStreamPrivateData();
        streamData.outputStream = conn.createOutputStream(streamId);
        streamData.connConsumer = new ConnectionConsumer(conn, streamData.outputStream.getVideo(), streamData.outputStream.getAudio(), streamData.outputStream.getData());
        streamDataMap.put(streamId, streamData);
        log.debug("streamDataMap: {}", streamDataMap);
    }
    wrapped.resultReceived(call);
}
 
Example 3
Source File: RTMPTClientTest.java    From red5-client with Apache License 2.0 5 votes vote down vote up
@Override
public void resultReceived(IPendingServiceCall call) {
    int streamId = (Integer) call.getResult();
    // live buffer 0.5s / vod buffer 4s
    if (Boolean.valueOf(PropertiesReader.getProperty("rtmpt.live"))) {
        conn.ping(new Ping(Ping.CLIENT_BUFFER, streamId, 500));
        play(streamId, PropertiesReader.getProperty("rtmpt.name"), -1, -1);
    } else {
        conn.ping(new Ping(Ping.CLIENT_BUFFER, streamId, 4000));
        play(streamId, PropertiesReader.getProperty("rtmpt.name"), 0, -1);
    }
}
 
Example 4
Source File: RTMPTClientTest.java    From red5-client with Apache License 2.0 5 votes vote down vote up
@Override
public void resultReceived(IPendingServiceCall call) {
    System.out.println("connectCallback");
    ObjectMap<?, ?> map = (ObjectMap<?, ?>) call.getResult();
    String code = (String) map.get("code");
    System.out.printf("Response code: %s\n", code);
    if ("NetConnection.Connect.Rejected".equals(code)) {
        System.out.printf("Rejected: %s\n", map.get("description"));
        disconnect();
        synchronized (RTMPTClientTest.class) {
            finished = true;
            RTMPTClientTest.class.notifyAll();
        }
    } else if ("NetConnection.Connect.Failed".equals(code)) {
        System.out.printf("Failed: %s\n", map.get("description"));
        disconnect();
        synchronized (RTMPTClientTest.class) {
            finished = true;
            RTMPTClientTest.class.notifyAll();
        }
    } else if ("NetConnection.Connect.Success".equals(code)) {
        test();
        createStream(createStreamCallback);
    } else {
        System.out.printf("Unhandled response code: %s\n", code);
    }
}
 
Example 5
Source File: RTMPTSClientTest.java    From red5-client with Apache License 2.0 5 votes vote down vote up
@Override
public void resultReceived(IPendingServiceCall call) {
    int streamId = (Integer) call.getResult();
    // live buffer 0.5s / vod buffer 4s
    if (Boolean.valueOf(PropertiesReader.getProperty("rtmpts.live"))) {
        conn.ping(new Ping(Ping.CLIENT_BUFFER, streamId, 500));
        play(streamId, PropertiesReader.getProperty("rtmpts.name"), -1, -1);
    } else {
        conn.ping(new Ping(Ping.CLIENT_BUFFER, streamId, 4000));
        play(streamId, PropertiesReader.getProperty("rtmpts.name"), 0, -1);
    }
}
 
Example 6
Source File: RTMPTSClientTest.java    From red5-client with Apache License 2.0 5 votes vote down vote up
@Override
public void resultReceived(IPendingServiceCall call) {
    System.out.println("connectCallback");
    ObjectMap<?, ?> map = (ObjectMap<?, ?>) call.getResult();
    String code = (String) map.get("code");
    System.out.printf("Response code: %s\n", code);
    if ("NetConnection.Connect.Rejected".equals(code)) {
        System.out.printf("Rejected: %s\n", map.get("description"));
        disconnect();
        synchronized (RTMPTSClientTest.class) {
            finished = true;
            RTMPTSClientTest.class.notifyAll();
        }
    } else if ("NetConnection.Connect.Failed".equals(code)) {
        System.out.printf("Failed: %s\n", map.get("description"));
        disconnect();
        synchronized (RTMPTSClientTest.class) {
            finished = true;
            RTMPTSClientTest.class.notifyAll();
        }
    } else if ("NetConnection.Connect.Success".equals(code)) {
        test();
        createStream(createStreamCallback);
    } else {
        System.out.printf("Unhandled response code: %s\n", code);
    }
}
 
Example 7
Source File: RTMPClientTest.java    From red5-client with Apache License 2.0 5 votes vote down vote up
@Override
public void resultReceived(IPendingServiceCall call) {
    System.out.println("resultReceived: " + call);
    Double streamId = (Double) call.getResult();
    System.out.println("stream id: " + streamId);
    // send our buffer size request
    client.play(streamId, sourceStreamName, 0, -1);
}
 
Example 8
Source File: SharedObjectClient.java    From red5-client with Apache License 2.0 5 votes vote down vote up
@Override
public void resultReceived(IPendingServiceCall call) {
    log.debug("Received pending call: {}", call);
    Object result = call.getResult();
    if (result instanceof ObjectMap) {
        obj = getSharedObject(soName, false);
        obj.connect(Red5.getConnectionLocal());
        obj.addSharedObjectListener(this);
    }
}
 
Example 9
Source File: ClientTest.java    From red5-client with Apache License 2.0 5 votes vote down vote up
@Override
public void resultReceived(IPendingServiceCall call) {
    Number streamId = (Number) call.getResult();
    // live buffer 0.5s / vod buffer 4s
    if (Boolean.valueOf(PropertiesReader.getProperty("live"))) {
        conn.ping(new Ping(Ping.CLIENT_BUFFER, streamId, 500));
        play(streamId, PropertiesReader.getProperty("name"), -1, -1);
    } else {
        conn.ping(new Ping(Ping.CLIENT_BUFFER, streamId, 4000));
        play(streamId, PropertiesReader.getProperty("name"), 0, -1);
    }
}
 
Example 10
Source File: ClientTest.java    From red5-client with Apache License 2.0 5 votes vote down vote up
@Override
public void resultReceived(IPendingServiceCall call) {
    System.out.println("connectCallback");
    ObjectMap<?, ?> map = (ObjectMap<?, ?>) call.getResult();
    String code = (String) map.get("code");
    System.out.printf("Response code: %s\n", code);
    if ("NetConnection.Connect.Rejected".equals(code)) {
        System.out.printf("Rejected: %s\n", map.get("description"));
        disconnect();
        finished = true;
    } else if ("NetConnection.Connect.Success".equals(code)) {
        invoke("demoService.getListOfAvailableFLVs", new Object[] {}, methodCallCallback);
        createStream(createStreamCallback);
    }
}
 
Example 11
Source File: StreamRelay.java    From red5-client with Apache License 2.0 5 votes vote down vote up
@Override
public void resultReceived(IPendingServiceCall call) {
    System.out.println("resultReceived: " + call);
    Double streamId = (Double) call.getResult();
    System.out.println("stream id: " + streamId);
    // send our buffer size request
    if (sourceStreamName.endsWith(".flv") || sourceStreamName.endsWith(".f4v") || sourceStreamName.endsWith(".mp4")) {
        client.play(streamId, sourceStreamName, 0, -1);
    } else {
        client.play(streamId, sourceStreamName, -1, 0);
    }
}
 
Example 12
Source File: BaseRTMPClientHandler.java    From red5-client with Apache License 2.0 5 votes vote down vote up
@Override
public void resultReceived(IPendingServiceCall call) {
    log.debug("resultReceived", call);
    if (call.getResult() instanceof ObjectMap<?, ?>) {
        ObjectMap<?, ?> map = (ObjectMap<?, ?>) call.getResult();
        if (map.containsKey("code")) {
            String code = (String) map.get("code");
            log.debug("Code: {}", code);
            if (StatusCodes.NS_PLAY_START.equals(code)) {
                subscribed = true;
            }
        }
    }
    wrapped.resultReceived(call);
}
 
Example 13
Source File: BaseRTMPClientHandler.java    From red5-client with Apache License 2.0 5 votes vote down vote up
@Override
public void resultReceived(IPendingServiceCall call) {
    Number streamId = (Number) call.getResult();
    log.debug("Stream id: {} connection: {}", streamId, conn);
    log.debug("DeleteStreamCallBack resultReceived - stream id: {}", streamId);
    if (conn != null && streamId != null) {
        log.debug("Deleting net stream");
        conn.removeClientStream(streamId);
        // send a delete notify?
        //NetStreamPrivateData streamData = streamDataMap.get(streamId);
        //streamData.handler.onStreamEvent(notify)
        streamDataMap.remove(streamId);
    }
    wrapped.resultReceived(call);
}
 
Example 14
Source File: ClientTest.java    From red5-client with Apache License 2.0 4 votes vote down vote up
@Override
public void resultReceived(IPendingServiceCall call) {
    System.out.println("methodCallCallback");
    Map<?, ?> map = (Map<?, ?>) call.getResult();
    System.out.printf("Response %s\n", map);
}
 
Example 15
Source File: RTMPClientTest.java    From red5-client with Apache License 2.0 4 votes vote down vote up
@Test
public void test26() throws InterruptedException {
    client.setStreamEventHandler(new INetStreamEventHandler() {
        @Override
        public void onStreamEvent(Notify notify) {
            log.info("ClientStream.dispachEvent: {}", notify);
        }
    });
    client.setServiceProvider(new ClientMethodHander());
    client.setConnectionClosedHandler(new Runnable() {
        @Override
        public void run() {
            System.out.println("Connection closed");
        }
    });
    client.setExceptionHandler(new ClientExceptionHandler() {
        @Override
        public void handleException(Throwable throwable) {
            throwable.printStackTrace();
        }
    });

    IPendingServiceCallback connectCallback = new IPendingServiceCallback() {
        @Override
        public void resultReceived(IPendingServiceCall call) {
            log.info("connectCallback");
            ObjectMap<?, ?> map = (ObjectMap<?, ?>) call.getResult();
            String code = (String) map.get("code");
            log.info("Response code: {}", code);
            if ("NetConnection.Connect.Rejected".equals(code)) {
                System.out.printf("Rejected: %s\n", map.get("description"));
                client.disconnect();
            } else if ("NetConnection.Connect.Success".equals(code)) {
                // 1. Wait for onBWDone
                timer.schedule(new BandwidthStatusTask(), 2000L);
            }
        }
    };

    /*
     * client.connect("localhost", 1935, "live/remote/0586e318-6277-11e3-adc2-22000a1d91fe", new IPendingServiceCallback() {
     * @Override public void resultReceived(IPendingServiceCall result) { System.out.println("resultReceived: " + result); ObjectMap<?, ?> map = (ObjectMap<?, ?>) result.getResult();
     * String code = (String) map.get("code"); System.out.printf("Response code: %s\n", code); if ("NetConnection.Connect.Rejected".equals(code)) { System.out.printf("Rejected: %s\n",
     * map.get("description")); client.disconnect(); } else if ("NetConnection.Connect.Success".equals(code)) { System.out.println("success: " + result.isSuccess()); ArrayList<Object>
     * list = new ArrayList<>(); list.add(new Object[] { "fujifilm-x100s-video-test-1080p-full-hd-hdmp4_720.mp4" }); list.add(new Object[] {
     * "canon-500d-test-video-720-hd-30-fr-hdmp4_720.mp4" }); Object[] params = { "64", "cc-video-processed/", list }; //Object[] params = { "64", "cc-video-processed/" };
     * client.invoke("loadPlaylist", params, new IPendingServiceCallback() {
     * @Override public void resultReceived(IPendingServiceCall result) { System.out.println(result); } }); } } });
     */
    client.connect("localhost", 1935, "vod", connectCallback);

    do {
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
        }
    } while (!client.conn.isClosed());
    log.debug("Client not connected");
    timer.cancel();
    log.info("Exit");
}
 
Example 16
Source File: RTMPTSClientTest.java    From red5-client with Apache License 2.0 4 votes vote down vote up
@Override
public void resultReceived(IPendingServiceCall call) {
    System.out.println("methodCallCallback");
    Map<?, ?> map = (Map<?, ?>) call.getResult();
    System.out.printf("Response %s\n", map);
}
 
Example 17
Source File: RTMPTClientTest.java    From red5-client with Apache License 2.0 4 votes vote down vote up
@Override
public void resultReceived(IPendingServiceCall call) {
    System.out.println("methodCallCallback");
    Map<?, ?> map = (Map<?, ?>) call.getResult();
    System.out.printf("Response %s\n", map);
}
 
Example 18
Source File: RTMPClientProtocolEncoder.java    From red5-client with Apache License 2.0 4 votes vote down vote up
/**
 * Encode notification event and fill given byte buffer.
 *
 * @param out
 *            Byte buffer to fill
 * @param command
 *            Notification event
 */
@Override
protected void encodeCommand(IoBuffer out, ICommand command) {
    log.debug("encodeCommand - command: {}", command);
    RTMPConnection conn = (RTMPConnection) Red5.getConnectionLocal();
    Output output = new org.red5.io.amf.Output(out);
    final IServiceCall call = command.getCall();
    final boolean isPending = (call.getStatus() == Call.STATUS_PENDING);
    log.debug("Call: {} pending: {}", call, isPending);
    if (!isPending) {
        log.debug("Call has been executed, send result");
        Serializer.serialize(output, call.isSuccess() ? "_result" : "_error");
    } else {
        log.debug("This is a pending call, send request");
        // for request we need to use AMF3 for client mode if the connection is AMF3
        if (conn.getEncoding() == Encoding.AMF3) {
            output = new org.red5.io.amf3.Output(out);
        }
        final String action = (call.getServiceName() == null) ? call.getServiceMethodName() : call.getServiceName() + '.' + call.getServiceMethodName();
        Serializer.serialize(output, action);
    }
    if (command instanceof Invoke) {
        Serializer.serialize(output, Integer.valueOf(command.getTransactionId()));
        Serializer.serialize(output, command.getConnectionParams());
    }
    if (call.getServiceName() == null && "connect".equals(call.getServiceMethodName())) {
        // response to initial connect, always use AMF0
        output = new org.red5.io.amf.Output(out);
    } else {
        if (conn.getEncoding() == Encoding.AMF3) {
            output = new org.red5.io.amf3.Output(out);
        } else {
            output = new org.red5.io.amf.Output(out);
        }
    }
    if (!isPending && (command instanceof Invoke)) {
        IPendingServiceCall pendingCall = (IPendingServiceCall) call;
        if (!call.isSuccess()) {
            log.debug("Call was not successful");
            StatusObject status = generateErrorResult(StatusCodes.NC_CALL_FAILED, call.getException());
            pendingCall.setResult(status);
        }
        Object res = pendingCall.getResult();
        log.debug("Writing result: {}", res);
        Serializer.serialize(output, res);
    } else {
        log.debug("Writing params");
        final Object[] args = call.getArguments();
        if (args != null) {
            for (Object element : args) {
                Serializer.serialize(output, element);
            }
        }
    }
    if (command.getData() != null) {
        out.setAutoExpand(true);
        out.put(command.getData());
    }
}
 
Example 19
Source File: RTMPProtocolEncoder.java    From red5-server-common with Apache License 2.0 4 votes vote down vote up
/**
 * Encode command event and fill given byte buffer.
 *
 * @param out
 *            Buffer to fill
 * @param command
 *            Command event
 */
protected void encodeCommand(IoBuffer out, ICommand command) {
    // TODO: tidy up here
    Output output = new org.red5.io.amf.Output(out);
    final IServiceCall call = command.getCall();
    final boolean isPending = (call.getStatus() == Call.STATUS_PENDING);
    log.debug("Call: {} pending: {}", call, isPending);
    if (!isPending) {
        log.debug("Call has been executed, send result");
        Serializer.serialize(output, call.isSuccess() ? "_result" : "_error");
    } else {
        log.debug("This is a pending call, send request");
        final String action = (call.getServiceName() == null) ? call.getServiceMethodName() : call.getServiceName() + '.' + call.getServiceMethodName();
        Serializer.serialize(output, action); // seems right
    }
    if (command instanceof Invoke) {
        Serializer.serialize(output, Integer.valueOf(command.getTransactionId()));
        Serializer.serialize(output, command.getConnectionParams());
    }
    if (call.getServiceName() == null && "connect".equals(call.getServiceMethodName())) {
        // response to initial connect, always use AMF0
        output = new org.red5.io.amf.Output(out);
    } else {
        if (Red5.getConnectionLocal().getEncoding() == Encoding.AMF3) {
            output = new org.red5.io.amf3.Output(out);
        } else {
            output = new org.red5.io.amf.Output(out);
        }
    }
    if (!isPending && (command instanceof Invoke)) {
        IPendingServiceCall pendingCall = (IPendingServiceCall) call;
        if (!call.isSuccess() && (call.getException() != null || pendingCall.getResult() == null)) {
            log.debug("Call was not successful");
            StatusObject status = generateErrorResult(StatusCodes.NC_CALL_FAILED, call.getException());
            pendingCall.setResult(status);
        }
        Object res = pendingCall.getResult();
        log.debug("Writing result: {}", res);
        Serializer.serialize(output, res);
    } else {
        log.debug("Writing params");
        final Object[] args = call.getArguments();
        if (args != null) {
            for (Object element : args) {
                if (element instanceof ByteBuffer) {
                    // a byte buffer indicates that serialization is already complete, send raw
                    final ByteBuffer buf = (ByteBuffer) element;
                    buf.mark();
                    try {
                        out.put(buf);
                    } finally {
                        buf.reset();
                    }
                } else {
                    // standard serialize
                    Serializer.serialize(output, element);
                }
            }
        }
    }
    if (command.getData() != null) {
        out.setAutoExpand(true);
        out.put(command.getData());
    }
}