Example usage for io.netty.handler.codec.rtsp RtspResponseStatuses SESSION_NOT_FOUND

List of usage examples for io.netty.handler.codec.rtsp RtspResponseStatuses SESSION_NOT_FOUND

Introduction

In this page you can find the example usage for io.netty.handler.codec.rtsp RtspResponseStatuses SESSION_NOT_FOUND.

Prototype

HttpResponseStatus SESSION_NOT_FOUND

To view the source code for io.netty.handler.codec.rtsp RtspResponseStatuses SESSION_NOT_FOUND.

Click Source Link

Document

454 Session Not Found

Usage

From source file:org.mobicents.media.server.ctrl.rtsp.PlayAction.java

License:Open Source License

public FullHttpResponse call() throws Exception {
    FullHttpResponse response = null;/* w w w  .j a  v a 2s  .com*/
    String sessionId = this.request.headers().get(RtspHeaders.Names.SESSION);
    String absolutePath = this.request.getUri();
    URI uri = new URI(absolutePath);

    String path = uri.getPath();
    String filePath = null;
    String trackID = null;

    int pos = path.indexOf("/trackID");
    if (pos > 0) {
        filePath = path.substring(0, pos);
        trackID = path.substring(pos + 1);
    } else {
        filePath = path;
    }

    File f = new File(filePath);
    if (f.isDirectory() || !f.exists()) {
        response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.NOT_FOUND);
        response.headers().add(HttpHeaders.Names.SERVER, RtspController.SERVER);
        response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
        return response;
    }

    String sessionID = this.request.headers().get(RtspHeaders.Names.SESSION);
    if (sessionID == null) {
        response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.BAD_REQUEST);
        response.headers().add(HttpHeaders.Names.SERVER, RtspController.SERVER);
        response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
        return response;
    }
    // determine session
    RtspSession session = rtspController.getSession(this.request.headers().get(RtspHeaders.Names.SESSION),
            false);
    if (session == null) {
        response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.SESSION_NOT_FOUND);
        response.headers().add(HttpHeaders.Names.SERVER, RtspController.SERVER);
        response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
        return response;
    }

    Endpoint endpoint = (Endpoint) session.getAttribute("endpoint");
    Player player = null;//(Player) endpoint.getComponent("player");
    String rtpInfo = "";
    double npt = 0;
    if (trackID != null) {
        //         player.getMediaSource(trackID).start();
        //TODO Add rtp-info field
    } else {

        List<String> trackIds = (List<String>) session.getAttribute("trackIds");

        boolean first = true;
        for (String trackId : trackIds) {
            int rtpTime = 268435456 + (int) (Math.random() * (Integer.MAX_VALUE - 268435456));
            //            player.setRtpTime(trackId, rtpTime);
            if (first) {
                rtpInfo += "url=" + absolutePath + "/" + trackId + ";seq=1;rtptime=" + rtpTime;
                first = false;
                //               npt = player.getNPT(trackId);
            } else {
                rtpInfo += ",url=" + absolutePath + "/" + trackId + ";seq=1;rtptime=" + rtpTime;
            }
        }

        //System.out.println("RTP-INfo = "+ rtpInfo+ " NPT = "+ npt);
        //         player.start();
    }

    response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.OK);
    response.headers().add(HttpHeaders.Names.SERVER, RtspController.SERVER);
    response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
    response.headers().add(RtspHeaders.Names.SESSION, session.getId());
    response.headers().add(RtspHeaders.Names.RTP_INFO, rtpInfo);
    response.headers().add("Range", "npt=0.00000-" + npt);

    session.setState(SessionState.PLAYING);
    return response;
}

From source file:org.mobicents.media.server.ctrl.rtsp.SetupAction.java

License:Open Source License

public FullHttpResponse call() throws Exception {
    FullHttpResponse response = null;//  w w w. j a v  a2 s .com

    //determine session
    RtspSession session = getSession(this.request.headers().get(RtspHeaders.Names.SESSION));
    if (session == null) {
        response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.SESSION_NOT_FOUND);
        response.headers().add(HttpHeaders.Names.SERVER, RtspController.SERVER);
        response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
        return response;
    }

    String filePath = null;
    String trackID = null;

    URI uri = new URI(this.request.getUri());
    String path = uri.getPath();

    int pos = path.indexOf("/trackID");
    if (pos > 0) {
        filePath = path.substring(0, pos);
        trackID = path.substring(pos + 1);
    } else {
        filePath = path;
    }

    File f = new File(filePath);
    if (f.isDirectory() || !f.exists()) {
        response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.NOT_FOUND);
        response.headers().add(HttpHeaders.Names.SERVER, RtspController.SERVER);
        response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
        return response;
    }

    int remotePort = this.getRemotePort();
    InetSocketAddress remoteAddress = new InetSocketAddress(remoteHost, remotePort);

    if (session.getState() == SessionState.PLAYING || session.getState() == SessionState.RECORDING) {
        // We don't support changing the Transport while state is PLAYING or RECORDING
        response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.METHOD_NOT_VALID);
        response.headers().add(HttpHeaders.Names.SERVER, RtspController.SERVER);
        response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
        return response;
    }

    Endpoint endpoint = (Endpoint) session.getAttribute("endpoint");
    if (endpoint == null) {
        try {
            endpoint = rtspController.lookup(ENDPOINT_NAME);
            session.setAttribute("endpoint", endpoint);
        } catch (ResourceUnavailableException e) {
            logger.warn("There is no free endpoint: " + ENDPOINT_NAME);
            response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0,
                    RtspResponseStatuses.SERVICE_UNAVAILABLE);
            response.headers().add(HttpHeaders.Names.SERVER, RtspController.SERVER);
            response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
            return response;
        }
    }

    Connection connection = (Connection) session.getAttribute("connection");
    if (connection == null) {
        try {
            connection = endpoint.createConnection(ConnectionType.RTP, false);

            connection.setMode(mode);
            session.setAttribute("connection", connection);
        } catch (Exception e) {
            logger.error(e);
            response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0,
                    RtspResponseStatuses.SERVICE_UNAVAILABLE);
            response.headers().add(HttpHeaders.Names.SERVER, RtspController.SERVER);
            response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
            return response;
        }
    }

    int ssrc = 268435456 + (int) (Math.random() * (Integer.MAX_VALUE - 268435456));

    Player player = null;//(Player) endpoint.getComponent("player");
    player.setURL(f.getAbsolutePath());
    //        player.setSSRC(trackID, ssrc);

    List<String> trackIds = (List<String>) session.getAttribute("trackIds");
    if (trackIds == null) {
        trackIds = new ArrayList<String>();
        session.setAttribute("trackIds", trackIds);
    }
    trackIds.add(trackID);

    // connection.setOtherParty(trackID, remoteAddress);

    int port = 0;//endpoint.getLocalPort(trackID);
    String source = null;//endpoint.getLocalAddress(trackID);
    String lastModified = formatter.format(new Date(f.lastModified()));
    String date = formatter.format(new Date());

    String transport = "RTP/AVP/UDP;unicast;source=" + source + ";" + this.clientPort + ";server_port=" + port
            + "-" + port + ";ssrc=" + Integer.toHexString(ssrc);
    response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.OK);
    response.headers().add(HttpHeaders.Names.SERVER, RtspController.SERVER);
    response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
    response.headers().add(RtspHeaders.Names.SESSION, session.getId());
    response.headers().add(RtspHeaders.Names.TRANSPORT, transport);
    response.headers().add(HttpHeaders.Names.LAST_MODIFIED, lastModified);
    //TODO CACHE_CONTROL must come from settings. Let user decide how they want CACHE_CONTROL
    response.headers().add(HttpHeaders.Names.CACHE_CONTROL, "must-revalidate");
    response.headers().add(HttpHeaders.Names.DATE, date);
    //TODO EXPIRES must come from settings. Also depends on CACHE_CONTRL
    response.headers().add(HttpHeaders.Names.EXPIRES, date);
    session.setState(SessionState.READY);
    //ConnectionActivity connectionActivity = session.addConnection(connection);

    return response;
}

From source file:org.mobicents.media.server.ctrl.rtsp.TeardownAction.java

License:Open Source License

public FullHttpResponse call() throws Exception {
    FullHttpResponse response = null;//from w  w w  .j a  va2s  .  c o m
    String sessionId = this.request.headers().get(RtspHeaders.Names.SESSION);
    if (sessionId != null) {
        RtspSession session = this.rtspController.getSession(sessionId, false);
        if (session != null) {

            Endpoint endpoint = (Endpoint) session.getAttribute("endpoint");
            if (endpoint != null) {
                endpoint.deleteAllConnections();
            }

            response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.OK);
            response.headers().add(HttpHeaders.Names.SERVER, RtspController.SERVER);
            response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
            response.headers().add(RtspHeaders.Names.SESSION, session.getId());

            session = null;

            return response;

        } else {
            response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0,
                    RtspResponseStatuses.SESSION_NOT_FOUND);
            response.headers().add(HttpHeaders.Names.SERVER, RtspController.SERVER);
            response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
            response.headers().add(RtspHeaders.Names.SESSION, sessionId);
            return response;
        }

    } else {
        response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.BAD_REQUEST);
        response.headers().add(HttpHeaders.Names.SERVER, RtspController.SERVER);
        response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
        return response;
    }
}

From source file:org.mobicents.media.server.rtsp.action.PlayAction.java

License:Open Source License

public FullHttpResponse call() throws Exception {
    FullHttpResponse response = null;//from  w  w w  .  j a v a 2 s . c om
    String sessionId = this.request.headers().get(RtspHeaders.Names.SESSION);
    String absolutePath = this.request.getUri();
    URI uri = new URI(absolutePath);

    String path = uri.getPath();
    String filePath = null;
    String trackID = null;

    int pos = path.indexOf("/trackID");
    if (pos > 0) {
        filePath = path.substring(0, pos);
        trackID = path.substring(pos + 1);
    } else {
        filePath = path;
    }

    File f = new File(filePath);
    if (f.isDirectory() || !f.exists()) {
        response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.NOT_FOUND);
        response.headers().add(HttpHeaders.Names.SERVER, RtspProvider.SERVER);
        response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
        return response;
    }

    String sessionID = this.request.headers().get(RtspHeaders.Names.SESSION);
    if (sessionID == null) {
        response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.BAD_REQUEST);
        response.headers().add(HttpHeaders.Names.SERVER, RtspProvider.SERVER);
        response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
        return response;
    }
    // determine session
    RtspSession session = rtspController.getSession(this.request.headers().get(RtspHeaders.Names.SESSION),
            false);
    if (session == null) {
        response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.SESSION_NOT_FOUND);
        response.headers().add(HttpHeaders.Names.SERVER, RtspProvider.SERVER);
        response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
        return response;
    }

    Endpoint endpoint = (Endpoint) session.getAttribute("endpoint");
    Player player = null;//(Player) endpoint.getComponent("player");
    String rtpInfo = "";
    double npt = 0;
    if (trackID != null) {
        //         player.getMediaSource(trackID).start();
        //TODO Add rtp-info field
    } else {

        List<String> trackIds = (List<String>) session.getAttribute("trackIds");

        boolean first = true;
        for (String trackId : trackIds) {
            int rtpTime = 268435456 + (int) (Math.random() * (Integer.MAX_VALUE - 268435456));
            //            player.setRtpTime(trackId, rtpTime);
            if (first) {
                rtpInfo += "url=" + absolutePath + "/" + trackId + ";seq=1;rtptime=" + rtpTime;
                first = false;
                //               npt = player.getNPT(trackId);
            } else {
                rtpInfo += ",url=" + absolutePath + "/" + trackId + ";seq=1;rtptime=" + rtpTime;
            }
        }

        //System.out.println("RTP-INfo = "+ rtpInfo+ " NPT = "+ npt);
        //         player.start();
    }

    response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.OK);
    response.headers().add(HttpHeaders.Names.SERVER, RtspProvider.SERVER);
    response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
    response.headers().add(RtspHeaders.Names.SESSION, session.getId());
    response.headers().add(RtspHeaders.Names.RTP_INFO, rtpInfo);
    response.headers().add("Range", "npt=0.00000-" + npt);

    session.setState(SessionState.PLAYING);
    return response;
}

From source file:org.mobicents.media.server.rtsp.action.SetupAction.java

License:Open Source License

public FullHttpResponse call() throws Exception {
    FullHttpResponse response = null;//from  w ww. ja  va  2 s  .c  o m

    //determine session
    RtspSession session = getSession(this.request.headers().get(RtspHeaders.Names.SESSION));
    if (session == null) {
        response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.SESSION_NOT_FOUND);
        response.headers().add(HttpHeaders.Names.SERVER, RtspProvider.SERVER);
        response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
        return response;
    }

    String filePath = null;
    String trackID = null;

    URI uri = new URI(this.request.getUri());
    String path = uri.getPath();

    int pos = path.indexOf("/trackID");
    if (pos > 0) {
        filePath = path.substring(0, pos);
        trackID = path.substring(pos + 1);
    } else {
        filePath = path;
    }

    File f = new File(filePath);
    if (f.isDirectory() || !f.exists()) {
        response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.NOT_FOUND);
        response.headers().add(HttpHeaders.Names.SERVER, RtspProvider.SERVER);
        response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
        return response;
    }

    int remotePort = this.getRemotePort();
    InetSocketAddress remoteAddress = new InetSocketAddress(remoteHost, remotePort);

    if (session.getState() == SessionState.PLAYING || session.getState() == SessionState.RECORDING) {
        // We don't support changing the Transport while state is PLAYING or RECORDING
        response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.METHOD_NOT_VALID);
        response.headers().add(HttpHeaders.Names.SERVER, RtspProvider.SERVER);
        response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
        return response;
    }

    Endpoint endpoint = (Endpoint) session.getAttribute("endpoint");
    /**if (endpoint == null) {
    try {
        endpoint = rtspController.lookup(ENDPOINT_NAME);
        session.setAttribute("endpoint", endpoint);
    } catch (ResourceUnavailableException e) {
        logger.warn("There is no free endpoint: " + ENDPOINT_NAME);
        response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.SERVICE_UNAVAILABLE);
        response.headers().add(HttpHeaders.Names.SERVER, RtspController.SERVER);
        response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
        return response;
    }
    }*/

    Connection connection = (Connection) session.getAttribute("connection");
    if (connection == null) {
        try {
            connection = endpoint.createConnection(ConnectionType.RTP, false);

            connection.setMode(mode);
            session.setAttribute("connection", connection);
        } catch (Exception e) {
            logger.error(e);
            response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0,
                    RtspResponseStatuses.SERVICE_UNAVAILABLE);
            response.headers().add(HttpHeaders.Names.SERVER, RtspProvider.SERVER);
            response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
            return response;
        }
    }

    int ssrc = 268435456 + (int) (Math.random() * (Integer.MAX_VALUE - 268435456));

    Player player = null;//(Player) endpoint.getComponent("player");
    player.setURL(f.getAbsolutePath());
    //        player.setSSRC(trackID, ssrc);

    List<String> trackIds = (List<String>) session.getAttribute("trackIds");
    if (trackIds == null) {
        trackIds = new ArrayList<String>();
        session.setAttribute("trackIds", trackIds);
    }
    trackIds.add(trackID);

    // connection.setOtherParty(trackID, remoteAddress);

    int port = 0;//endpoint.getLocalPort(trackID);
    String source = null;//endpoint.getLocalAddress(trackID);
    String lastModified = formatter.format(new Date(f.lastModified()));
    String date = formatter.format(new Date());

    String transport = "RTP/AVP/UDP;unicast;source=" + source + ";" + this.clientPort + ";server_port=" + port
            + "-" + port + ";ssrc=" + Integer.toHexString(ssrc);
    response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.OK);
    response.headers().add(HttpHeaders.Names.SERVER, RtspProvider.SERVER);
    response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
    response.headers().add(RtspHeaders.Names.SESSION, session.getId());
    response.headers().add(RtspHeaders.Names.TRANSPORT, transport);
    response.headers().add(HttpHeaders.Names.LAST_MODIFIED, lastModified);
    //TODO CACHE_CONTROL must come from settings. Let user decide how they want CACHE_CONTROL
    response.headers().add(HttpHeaders.Names.CACHE_CONTROL, "must-revalidate");
    response.headers().add(HttpHeaders.Names.DATE, date);
    //TODO EXPIRES must come from settings. Also depends on CACHE_CONTRL
    response.headers().add(HttpHeaders.Names.EXPIRES, date);
    session.setState(SessionState.READY);
    //ConnectionActivity connectionActivity = session.addConnection(connection);

    return response;
}

From source file:org.mobicents.media.server.rtsp.action.TeardownAction.java

License:Open Source License

public FullHttpResponse call() throws Exception {
    FullHttpResponse response = null;//from  ww w. j  a v  a2s.c o m
    String sessionId = this.request.headers().get(RtspHeaders.Names.SESSION);
    if (sessionId != null) {
        RtspSession session = this.rtspController.getSession(sessionId, false);
        if (session != null) {

            Endpoint endpoint = (Endpoint) session.getAttribute("endpoint");
            if (endpoint != null) {
                endpoint.deleteAllConnections();
            }

            response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.OK);
            response.headers().add(HttpHeaders.Names.SERVER, RtspProvider.SERVER);
            response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
            response.headers().add(RtspHeaders.Names.SESSION, session.getId());

            session = null;

            return response;

        } else {
            response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0,
                    RtspResponseStatuses.SESSION_NOT_FOUND);
            response.headers().add(HttpHeaders.Names.SERVER, RtspProvider.SERVER);
            response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
            response.headers().add(RtspHeaders.Names.SESSION, sessionId);
            return response;
        }

    } else {
        response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.BAD_REQUEST);
        response.headers().add(HttpHeaders.Names.SERVER, RtspProvider.SERVER);
        response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
        return response;
    }
}

From source file:sas.systems.imflux.session.rtsp.SimpleRtspSession.java

License:Apache License

/**
 * Handles a TEARDOWN request by checking the request headers and sending a corresponding response.
 * This method does not take care of stopping any RTP streams.
 * /*from   w w  w . j  a  v  a  2  s  . c  o  m*/
 * @param channel
 * @param request
 */
private void handleTeardownRequest(Channel channel, HttpRequest request) {
    if (!automatedRtspHandling) {
        // forward messages
        for (RtspRequestListener listener : this.requestListener) {
            listener.teardownRequestReceived(request, RtspParticipant.newInstance(channel, request));
        }
        return;
    }

    // handle teardown request
    final HttpHeaders reqHeaders = request.headers();
    final String cseq = reqHeaders.get(RtspHeaders.Names.CSEQ);
    final RtspParticipant participant = this.participantSessions.get(reqHeaders.get(RtspHeaders.Names.SESSION));

    // return session not found if we do not have received a SETUP before
    if (participant == null) {
        sendResponse(RtspResponseStatuses.SESSION_NOT_FOUND, cseq, channel);
        return;
    }

    participant.teardown();
    sendResponse(RtspResponseStatuses.OK, cseq, channel);
}

From source file:sas.systems.unveiled.server.RtspMessageHandler.java

License:Apache License

@Override
public void setupRequestReceived(HttpRequest message, RtspParticipant participant) {
    final String seq = message.headers().get(RtspHeaders.Names.CSEQ);
    final String session = message.headers().get(RtspHeaders.Names.SESSION);
    final String authorization = message.headers().get(RtspHeaders.Names.AUTHORIZATION);
    final String transport = message.headers().get(RtspHeaders.Names.TRANSPORT);

    System.out.println(message);//from   www. j  a v a2  s.co m

    // check authorization
    if (authorization == null) {
        participant.sendMessage(createErrorResponse(RtspResponseStatuses.UNAUTHORIZED, message.headers()));
        return;
    } else {
        if (!isAuthorized(authorization)) {
            participant.sendMessage(createErrorResponse(RtspResponseStatuses.UNAUTHORIZED, message.headers()));
            return;
        }
    }

    // extract transport information
    if (seq != null && session != null && transport != null) {
        int cseq = 0;
        try {
            cseq = Integer.valueOf(seq);
        } catch (NumberFormatException e) {
            participant.sendMessage(
                    createErrorResponse(RtspResponseStatuses.HEADER_FIELD_NOT_VALID, message.headers()));
            return;
        }
        FileStreamHandler handler = this.sessions.get(session);
        if (handler == null) {
            participant.sendMessage(
                    createErrorResponse(RtspResponseStatuses.SESSION_NOT_FOUND, message.headers()));
            return;
        }

        // parse transport header and validate entries
        final InetSocketAddress remote = (InetSocketAddress) participant.getRemoteAddress();
        final boolean validationError = parseTransportHeader(transport, handler.getParticipant(),
                remote.getHostName());
        if (!validationError) {
            participant.sendMessage(
                    createErrorResponse(RtspResponseStatuses.HEADER_FIELD_NOT_VALID, message.headers()));
            return;
        }

        participant.sendMessage(
                createSetupResponse(cseq, session, buildTransportString(transport, handler.getSsrc() + "")));
    }

    // send error message
    participant.sendMessage(createErrorResponse(RtspResponseStatuses.BAD_REQUEST, message.headers()));
}

From source file:sas.systems.unveiled.server.RtspMessageHandler.java

License:Apache License

@Override
public void teardownRequestReceived(HttpRequest message, RtspParticipant participant) {
    final String seq = message.headers().get(RtspHeaders.Names.CSEQ);
    final String session = message.headers().get(RtspHeaders.Names.SESSION);
    final String authorization = message.headers().get(RtspHeaders.Names.AUTHORIZATION);

    System.out.println(message);//from   w  w  w.  j  a v a 2  s.  c o  m

    // check authorization
    if (authorization == null) {
        participant.sendMessage(createErrorResponse(RtspResponseStatuses.UNAUTHORIZED, message.headers()));
        return;
    } else {
        if (!isAuthorized(authorization)) {
            participant.sendMessage(createErrorResponse(RtspResponseStatuses.UNAUTHORIZED, message.headers()));
            return;
        }
    }

    // extract transport information
    if (seq != null && session != null) {
        int cseq = 0;
        try {
            cseq = Integer.valueOf(seq);
        } catch (NumberFormatException e) {
            participant.sendMessage(
                    createErrorResponse(RtspResponseStatuses.HEADER_FIELD_NOT_VALID, message.headers()));
            return;
        }
        FileStreamHandler handler = this.sessions.get(session);
        if (handler == null) {
            participant.sendMessage(
                    createErrorResponse(RtspResponseStatuses.SESSION_NOT_FOUND, message.headers()));
            return;
        }

        // stop receiving data and close all resources
        handler.tieUp();

        // send response
        participant.sendMessage(createTeardownResponse(cseq, session));
    }
    participant.sendMessage(createErrorResponse(RtspResponseStatuses.BAD_REQUEST, message.headers()));
}

From source file:sas.systems.unveiled.server.RtspMessageHandler.java

License:Apache License

@Override
public void recordRequestReceived(HttpRequest message, RtspParticipant participant) {
    final String seq = message.headers().get(RtspHeaders.Names.CSEQ);
    final String session = message.headers().get(RtspHeaders.Names.SESSION);
    final String authorization = message.headers().get(RtspHeaders.Names.AUTHORIZATION);
    final String range = message.headers().get(RtspHeaders.Names.RANGE);

    System.out.println(message);//from w  ww  . j ava2  s. c  om

    // check authorization
    if (authorization == null) {
        participant.sendMessage(createErrorResponse(RtspResponseStatuses.UNAUTHORIZED, message.headers()));
        return;
    } else {
        if (!isAuthorized(authorization)) {
            participant.sendMessage(createErrorResponse(RtspResponseStatuses.UNAUTHORIZED, message.headers()));
            return;
        }
    }

    // extract transport information
    if (seq != null && session != null) {
        int cseq = 0;
        try {
            cseq = Integer.valueOf(seq);
        } catch (NumberFormatException e) {
            participant.sendMessage(
                    createErrorResponse(RtspResponseStatuses.HEADER_FIELD_NOT_VALID, message.headers()));
            return;
        }
        FileStreamHandler handler = this.sessions.get(session);
        if (handler == null) {
            participant.sendMessage(
                    createErrorResponse(RtspResponseStatuses.SESSION_NOT_FOUND, message.headers()));
            return;
        }

        if (range == null || range.startsWith("npt=0.0") || range.startsWith("npt=now")) {
            // start receiving data
            handler.initialize();

            // send response
            participant.sendMessage(createRecordResponse(cseq, session));
        }

        participant.sendMessage(
                createErrorResponse(RtspResponseStatuses.HEADER_FIELD_NOT_VALID, message.headers()));
    }
    participant.sendMessage(createErrorResponse(RtspResponseStatuses.BAD_REQUEST, message.headers()));
}