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

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

Introduction

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

Prototype

HttpResponseStatus AGGREGATE_OPERATION_NOT_ALLOWED

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

Click Source Link

Document

459 Aggregate operation not allowed

Usage

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

License:Apache License

/**
 * Handles a SETUP request by checking the specified headers and sending a corresponding response. 
 * There is no logic for setting up the the RTP stream or something else, because we do not know the details
 * about it.//from   w  w w  .ja  va2s  . com
 * 
 * @param channel
 * @param request
 */
private void handleSetupRequest(Channel channel, HttpRequest request) {
    if (!automatedRtspHandling) {
        // forward messages
        for (RtspRequestListener listener : this.requestListener) {
            listener.setupRequestReceived(request, RtspParticipant.newInstance(channel));
        }
        return;
    }

    // handle setup request
    RtspParticipant participant;
    final HttpHeaders reqHeaders = request.headers();
    final String cseq = reqHeaders.get(RtspHeaders.Names.CSEQ);
    final String transport = reqHeaders.get(RtspHeaders.Names.TRANSPORT);

    // if client already has a session id, this server does not allow aggregation
    final String session = reqHeaders.get(RtspHeaders.Names.SESSION);
    if (session != null) {
        sendResponse(RtspResponseStatuses.AGGREGATE_OPERATION_NOT_ALLOWED, cseq, channel);
        return;
    }

    // create participant and session id
    participant = RtspParticipant.newInstance(channel);
    final String sessionId = participant.setup();
    this.participantSessions.put(sessionId, participant);

    // parse transport header and validate entries
    boolean validationError = false;
    final String[] entries = transport.split(";");
    /* 
     * this server expects at least 3 information strings:
     *  - underlying streaming protocol: RTP
     *  - a unicast connection
     *  - the client ports for the data and control information
     */
    if (entries.length < 3) {
        validationError = true;
    }
    if (!entries[0].contains("RTP")) {
        validationError = true;
    }
    if (!"unicast".equals(entries[1])) {
        validationError = true;
    }
    final int iOfEQ = entries[2].indexOf("=");
    final int iOfMin = entries[2].indexOf("-");
    final int iEnd = entries[2].length();
    final String dataPortString = entries[2].substring(iOfEQ + 1, iOfMin);
    final String controlPortString = entries[2].substring(iOfMin + 1, iEnd);
    int clientDataPort = 0, clientControlPort = 0;
    try {
        clientDataPort = Integer.valueOf(dataPortString);
        clientControlPort = Integer.valueOf(controlPortString);
    } catch (NumberFormatException e) {
        validationError = true;
    }

    if (validationError) {
        sendResponse(RtspResponseStatuses.BAD_REQUEST, cseq, channel);
        // or:
        //         participant.sendMessage(aggOpNotAllowed);
        return;
    }

    // create transport string for response
    final int rtpDataPort = ((InetSocketAddress) localRtpParticipant.getDataDestination()).getPort();
    final int rtpControlPort = ((InetSocketAddress) localRtpParticipant.getControlDestination()).getPort();
    final StringBuilder transportResponse = new StringBuilder();
    transportResponse.append(entries[0]).append(";").append(entries[1]).append(";")
            .append(RtspHeaders.Values.CLIENT_PORT + "=").append(clientDataPort).append("-")
            .append(clientControlPort).append(";").append(RtspHeaders.Values.SERVER_PORT + "=")
            .append(rtpDataPort).append("-").append(rtpControlPort);

    // send response
    final HttpResponse response = new DefaultHttpResponse(rtspVersion, RtspResponseStatuses.OK);
    final HttpHeaders headers = response.headers();
    headers.add(RtspHeaders.Names.CSEQ, cseq);
    headers.add(RtspHeaders.Names.SESSION, sessionId);
    headers.add(RtspHeaders.Names.TRANSPORT, transportResponse.toString());
    headers.add(RtspHeaders.Names.DATE, new Date()); // HttpHeaders takes care of formatting the date

    sendResponse(response, channel);
}