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

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

Introduction

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

Prototype

HttpResponseStatus OK

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

Click Source Link

Document

200 OK

Usage

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

License:Open Source License

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

    URI objUri = new URI(this.request.getUri());

    String srcUrl = objUri.getPath();
    MediaDescription description = rtspController.describe(srcUrl);

    /** not found */
    if (description == null) {
        logger.warn("No EndpointName passed in request " + srcUrl);
        response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.NOT_FOUND);
        response.headers().set(HttpHeaders.Names.SERVER, RtspController.SERVER);
        response.headers().set(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
        return response;
    }

    /***/
    String sdp = null;
    try {

    } catch (ResourceUnavailableException e) {
        logger.warn("There is no free endpoint: " + srcUrl);
        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;
    }

    //we hard-code here
    //      sdp = "v=0\n" +
    //      "o=- 3776780 3776780 IN IP4 127.0.0.1\n" +
    //      "s=Mobicents Media Server\n" +
    //      "c=IN IP4 127.0.0.1\n" +
    //      "t=0 0\n" +
    //      "m=audio 0 RTP/AVP 0 2 3 97 8\n" +
    //      "b=AS:20\n"+
    //      "a=rtpmap:0 pcmu/8000\n" +      
    //      "a=rtpmap:2 g729/8000\n" +
    //      "a=rtpmap:3 gsm/8000\n" +
    //      "a=rtpmap:97 speex/8000\n" +
    //      "a=rtpmap:8 pcma/8000\n" +
    //      "a=control:audio\n";

    //      sdp = "v=0\n" +
    //      "o=MobicentsMediaServer 6732605 6732605 IN IP4 127.0.0.1\n"+
    //      "s=session\n"+
    //      "c=IN IP4 127.0.0.1\n"+
    //      "t=0 0\n"+
    //      "m=audio 0 RTP/AVP 97\n"+
    //      "b=AS:20\n"+
    //      "a=rtpmap:97 mpeg4-generic/8000/2\n"+
    //      "a=control:trackID=4\n"+
    //      "a=fmtp:97 profile-level-id=15;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3;config=1590\n"+
    //      "a=mpeg4-esid:101\n"+
    //      "m=video 0 RTP/AVP 96\n"+
    //      "b=AS:76\n"+
    //      "a=rtpmap:96 MP4V-ES/90000\n"+
    //      "a=control:trackID=3\n"+
    //      "a=cliprect:0,0,242,192\n"+
    //      "a=framesize:96 192-242\n"+
    //      "a=fmtp:96 profile-level-id=1;config=000001B0F3000001B50EE040C0CF0000010000000120008440FA283020F2A21F\n"+
    //      "a=mpeg4-esid:201\n";

    System.out.println("sdp = " + sdp);
    // TODO get Description from Endpoint
    // sdp = endpoint.describe(reqParser.getMediaType(), reqParser.getMediaFile());

    // TODO : Shoud endpoint.describe() return Description object which has all parameters like lastModified, sdp
    // etc

    response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.OK,
            Unpooled.copiedBuffer(sdp.getBytes("UTF-8")));
    response.headers().add(HttpHeaders.Names.SERVER, RtspController.SERVER);
    response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
    response.headers().add(HttpHeaders.Names.CONTENT_TYPE, "application/sdp");
    response.headers().add(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(sdp.length()));
    // TODO CACHE_CONTROL must come from settings. Let user decide how they want CACHE_CONTROL
    response.headers().add(HttpHeaders.Names.CACHE_CONTROL, HttpHeaders.Values.MUST_REVALIDATE);

    return response;
}

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

License:Open Source License

public FullHttpResponse call() throws Exception {
    DefaultFullHttpResponse 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.PUBLIC, OPTIONS);
    return response;
}

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 .ja  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, 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;/*from w  ww  . j ava 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, 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 ww.  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, 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.DescribeAction.java

License:Open Source License

public FullHttpResponse call() throws Exception {
    FullHttpResponse response = null;//w ww  .j  av a2 s . co m

    URI objUri = new URI(this.request.getUri());
    String srcUri = objUri.getPath();
    SessionDescription sd = rtspProvider.getRtspManager().describe(srcUri);

    if (null == sd) {
        logger.warn("No srcUrl passed in request " + srcUri);
        response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.NOT_FOUND);
        response.headers().set(HttpHeaders.Names.SERVER, RtspProvider.SERVER);
        response.headers().set(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
        return response;
    }

    List<MediaDescription> mds = sd.getMediaDescriptions(false);
    if (null == mds || mds.isEmpty()) {
        logger.warn("No Media passed in request " + srcUri);
        response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.BAD_REQUEST);
        response.headers().set(HttpHeaders.Names.SERVER, RtspProvider.SERVER);
        response.headers().set(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
        return response;
    }

    //we hard-code here
    //        sdp = "v=0\n" +
    //        "o=- 3776780 3776780 IN IP4 127.0.0.1\n" +
    //        "s=Mobicents Media Server\n" +
    //        "c=IN IP4 127.0.0.1\n" +
    //        "t=0 0\n" +
    //        "m=audio 0 RTP/AVP 0 2 3 97 8\n" +
    //        "b=AS:20\n"+
    //        "a=rtpmap:0 pcmu/8000\n" +        
    //        "a=rtpmap:2 g729/8000\n" +
    //        "a=rtpmap:3 gsm/8000\n" +
    //        "a=rtpmap:97 speex/8000\n" +
    //        "a=rtpmap:8 pcma/8000\n" +
    //        "a=control:audio\n";

    //        sdp = "v=0\n" +
    //        "o=MobicentsMediaServer 6732605 6732605 IN IP4 127.0.0.1\n"+
    //        "s=session\n"+
    //        "c=IN IP4 127.0.0.1\n"+
    //        "t=0 0\n"+
    //        "m=audio 0 RTP/AVP 97\n"+
    //        "b=AS:20\n"+
    //        "a=rtpmap:97 mpeg4-generic/8000/2\n"+
    //        "a=control:trackID=4\n"+
    //        "a=fmtp:97 profile-level-id=15;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3;config=1590\n"+
    //        "a=mpeg4-esid:101\n"+
    //        "m=video 0 RTP/AVP 96\n"+
    //        "b=AS:76\n"+
    //        "a=rtpmap:96 MP4V-ES/90000\n"+
    //        "a=control:trackID=3\n"+
    //        "a=cliprect:0,0,242,192\n"+
    //        "a=framesize:96 192-242\n"+
    //        "a=fmtp:96 profile-level-id=1;config=000001B0F3000001B50EE040C0CF0000010000000120008440FA283020F2A21F\n"+
    //        "a=mpeg4-esid:201\n";
    StringBuilder sdp = new StringBuilder();
    try {
        // v=0\n
        sdp.append("v=").append("0").append("\n");

        // o=- 3776780 3776780 IN IP4 127.0.0.1\n
        long randomSessionId = RandomUtils.nextLong();
        sdp.append("o=").append("- ").append(randomSessionId).append(" ").append(randomSessionId).append(" ")
                .append(connection.getNetworkType()).append(" ").append(connection.getAddressType()).append(" ")
                .append(connection.getAddress()).append(" ").append("\n");

        // s=Mobicents Media Server\n
        sdp.append("s=").append("Mobiecnts Rtsp Media Server").append("\n");

        // c=IN IP4 127.0.0.1\n
        sdp.append("c=").append(connection.getNetworkType()).append(" ").append(connection.getAddressType())
                .append(" ").append(connection.getAddress()).append(" ").append("\n");

        // "t=0 0\n"
        sdp.append("t=").append("0 0").append("\n");

        int mediaIndex = -1;
        for (MediaDescription md : mds) {
            mediaIndex++;
            Media media = md.getMedia();
            String rtpmap = md.getAttribute("rtpmap");
            String fmtp = md.getAttribute("fmtp");
            String control = request.getUri() + "/trackID=" + mediaIndex;

            // m=audio 0 RTP/AVP 97\n
            sdp.append("m=").append(media.getMediaType()).append(" ").append("0 ").append("RTP/AVP");
            List<Object> formats = media.getMediaFormats(true);
            for (Object format : formats) {
                sdp.append(" ").append(format);
            }
            sdp.append("\n");

            // a=rtpmap:97 mpeg4-generic/8000/2\n
            sdp.append("a=").append(rtpmap).append("\n");

            // a=control:trackID=4\n
            sdp.append("a=").append("control:").append(control).append("\n");

            // a=rtpmap:96 MP4V-ES/90000\n
            sdp.append("a=").append("rtpmap:").append(rtpmap).append("\n");

            // a=fmtp:97 profile-level-id=15;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3;config=1590\n
            sdp.append("a=").append("fmtp:").append(fmtp).append("\n");
        }

    } catch (RuntimeException e) {
        logger.warn("There is no free endpoint: " + srcUri);
        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;
    }

    byte[] bytes = sdp.toString().getBytes("UTF-8");
    response = new DefaultFullHttpResponse(RtspVersions.RTSP_1_0, RtspResponseStatuses.OK,
            Unpooled.copiedBuffer(bytes));
    response.headers().add(HttpHeaders.Names.SERVER, RtspProvider.SERVER);
    response.headers().add(RtspHeaders.Names.CSEQ, this.request.headers().get(RtspHeaders.Names.CSEQ));
    response.headers().add(HttpHeaders.Names.CONTENT_TYPE, "application/sdp");
    response.headers().add(HttpHeaders.Names.CONTENT_LENGTH, String.valueOf(bytes.length));

    return response;
}

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

License:Open Source License

public FullHttpResponse call() throws Exception {
    DefaultFullHttpResponse 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.PUBLIC, OPTIONS);
    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  ww  w  .  j a  v a2  s  . co  m*/
    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  w  w.  ja v a  2  s .co  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;//  w  w w.  jav a 2s.  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;
    }
}