Example #1
0
int RtspClientSession::handle_insession(RtspClientConnection * rcc,
									std::string & cmd, 
									std::string & urlPreSuffix, 
									std::string & urlSuffix, 
									std::string & fullRequestStr){

	if (!m_mediaSession){
		rcc->handleCmd_notSupported();
		return -1;
	}

	//Look up the media subsession whose track id is "urlSuffix":
	MediaSubSession *subsession = NULL;
	if (!urlSuffix.empty() && urlPreSuffix == m_mediaSession->StreamName()){
		//rtsp://192.168.20.136:5000/xxx666/trackID=0 RTSP/1.0 
		m_mediaSession->Lookup(urlSuffix);
	}
	else if(urlSuffix == m_mediaSession->StreamName() || 
		(urlSuffix.empty() && urlPreSuffix == m_mediaSession->StreamName())){
		//rtsp://192.168.20.136:5000/xxx666
		//rtsp://192.168.20.136:5000/xxx666/
		// Aggregated operation
		subsession = m_mediaSession->GetSubSession(0);
	}
	else if(!urlPreSuffix.empty() && !urlSuffix.empty()){
		//rtsp://192.168.20.136:5000/media/xxx666
		// Aggregated operation, if <urlPreSuffix>/<urlSuffix> is the session (stream) name:
		std::string streamName = urlPreSuffix + "/" + urlSuffix;
		if(streamName == m_mediaSession->StreamName()){
			subsession = m_mediaSession->GetSubSession(0);
		}
	}
	
	if (!subsession){
		return rcc->handleCmd_notFound();
	}

	if(cmd == "PLAY")
		handle_play(rcc, subsession, fullRequestStr);
	else if(cmd == "PAUSE")
		handle_pause(rcc, subsession);
	else if(cmd == "GET_PARAMETER")
		handle_getparameter(rcc, subsession, fullRequestStr);
	else if(cmd == "SET_PARAMETER")
		handle_setparameter(rcc, subsession, fullRequestStr);
	else if(cmd == "TEARDOWN")
		handle_teardown(rcc, subsession, fullRequestStr);

	return 0;
}
static void handle_uevent(hwc_context_t* ctx, const char* udata, int len)
{
    bool bpanelReset = getPanelResetStatus(ctx, udata, len);
    if (bpanelReset) {
        ctx->proc->invalidate(ctx->proc);
        return;
    }

    int dpy = getConnectedDisplay(udata);
    if(dpy < 0) {
        ALOGD_IF(UEVENT_DEBUG, "%s: Not disp Event ", __FUNCTION__);
        return;
    }

    int switch_state = getConnectedState(udata, len);

    ALOGE_IF(UEVENT_DEBUG,"%s: uevent recieved: %s switch state: %d",
             __FUNCTION__,udata, switch_state);

    switch(switch_state) {
    case EXTERNAL_OFFLINE:
        {
            /* Display not connected */
            if(!ctx->dpyAttr[dpy].connected){
                ALOGE_IF(UEVENT_DEBUG,"%s: Ignoring EXTERNAL_OFFLINE event"
                         "for display: %d", __FUNCTION__, dpy);
                break;
            }

            Locker::Autolock _l(ctx->mDrawLock);
            clear(ctx, dpy);
            ctx->dpyAttr[dpy].connected = false;
            ctx->dpyAttr[dpy].isActive = false;

            if(dpy == HWC_DISPLAY_EXTERNAL) {
                ctx->mExtDisplay->teardown();
            } else {
                ctx->mVirtualDisplay->teardown();
            }

            /* We need to send hotplug to SF only when we are disconnecting
             * (1) HDMI OR (2) proprietary WFD session */
            if(dpy == HWC_DISPLAY_EXTERNAL ||
               ctx->mVirtualonExtActive) {
                ALOGE_IF(UEVENT_DEBUG,"%s:Sending EXTERNAL OFFLINE hotplug"
                         "event", __FUNCTION__);
                ctx->proc->hotplug(ctx->proc, HWC_DISPLAY_EXTERNAL,
                                   EXTERNAL_OFFLINE);
                ctx->mVirtualonExtActive = false;
            }
            break;
        }
    case EXTERNAL_ONLINE:
        {
            /* Display already connected */
            if(ctx->dpyAttr[dpy].connected) {
                ALOGE_IF(UEVENT_DEBUG,"%s: Ignoring EXTERNAL_ONLINE event"
                         "for display: %d", __FUNCTION__, dpy);
                break;
            }
            {
                //Force composition to give up resources like pipes and
                //close fb. For example if assertive display is going on,
                //fb2 could be open, thus connecting Layer Mixer#0 to
                //WriteBack module. If HDMI attempts to open fb1, the driver
                //will try to attach Layer Mixer#0 to HDMI INT, which will
                //fail, since Layer Mixer#0 is still connected to WriteBack.
                //This block will force composition to close fb2 in above
                //example.
                Locker::Autolock _l(ctx->mDrawLock);
                ctx->dpyAttr[dpy].isConfiguring = true;
                ctx->proc->invalidate(ctx->proc);
            }
            //2 cycles for slower content
            usleep(ctx->dpyAttr[HWC_DISPLAY_PRIMARY].vsync_period
                   * 2 / 1000);

            if(dpy == HWC_DISPLAY_EXTERNAL) {
                if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected) {
                    // Triple Display is supported on 8084 target
                    // WFD can be initiated by Wfd-client or Settings app
                    // 1. wfd-client use hdmi hotplug mechanism.
                    //    If wfd is connected via wfd-client and if HDMI is
                    //    connected, we have to teardown wfd session.
                    //    (as SF support only one active External display
                    //     at a given time).
                    //    (ToDo: Once wfd-client migrates using virtual display
                    //     apis, second condition is redundant).
                    // 2. Settings app use virtual display mechanism.
                    //    In this approach, there is no limitation of supporting
                    //    triple display.
                    if(!(qdutils::MDPVersion::getInstance().is8084() &&
                                !ctx->mVirtualonExtActive)) {
                        teardownWfd(ctx);
                    }
                }
                ctx->mExtDisplay->configure();
            } else {
                {
                    Locker::Autolock _l(ctx->mDrawLock);
                    /* TRUE only when we are on proprietary WFD session */
                    ctx->mVirtualonExtActive = true;
                    char property[PROPERTY_VALUE_MAX];
                    if((property_get("persist.sys.wfd.virtual",
                                                  property, NULL) > 0) &&
                       (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
                       (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
                        // This means we are on Google's WFD session
                        ctx->mVirtualonExtActive = false;
                    }
                }
                ctx->mVirtualDisplay->configure();
            }

            Locker::Autolock _l(ctx->mDrawLock);
            setup(ctx, dpy);
            ctx->dpyAttr[dpy].isPause = false;
            ctx->dpyAttr[dpy].connected = true;
            ctx->dpyAttr[dpy].isConfiguring = true;

            if(dpy == HWC_DISPLAY_EXTERNAL ||
               ctx->mVirtualonExtActive) {
                /* External display is HDMI or non-hybrid WFD solution */
                ALOGE_IF(UEVENT_DEBUG, "%s: Sending EXTERNAL_OFFLINE ONLINE"
                         "hotplug event", __FUNCTION__);
                ctx->proc->hotplug(ctx->proc,HWC_DISPLAY_EXTERNAL,
                                   EXTERNAL_ONLINE);
            } else {
                /* We wont be getting unblank for VIRTUAL DISPLAY and its
                 * always guaranteed from WFD stack that CONNECT uevent for
                 * VIRTUAL DISPLAY will be triggered before creating
                 * surface for the same. */
                ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].isActive = true;
            }
            break;
        }
        case EXTERNAL_PAUSE:
            {   // pause case
                ALOGD("%s Received Pause event",__FUNCTION__);
                handle_pause(ctx, dpy);
                break;
            }
        case EXTERNAL_RESUME:
            {  // resume case
                ALOGD("%s Received resume event",__FUNCTION__);
                //Treat Resume as Online event
                //Since external didnt have any pipes, force primary to give up
                //its pipes; we don't allow inter-mixer pipe transfers.
                handle_resume(ctx, dpy);
                break;
            }
    default:
        {
            ALOGE("%s: Invalid state to swtich:%d", __FUNCTION__, switch_state);
            break;
        }
    }
}
Example #3
0
void parse_rtsp(){
	int str_len, cnt = 0;
	char *p, *q;
	char cmd[BUF_SIZE] = {0, };
	if((str_len = read(rtsp_sock, cmd, BUF_SIZE)) > 0){
		printf("-------------C -> S-------------\n"
			"%s\n", cmd);

		p = strtok(cmd, "\r\n");
		if (strstr(p,"OPTIONS") != NULL){
			rtspCmdType = RTSP_OPTIONS;
			p += 7;
		}else if (strstr(p,"DESCRIBE") != NULL){
			rtspCmdType = RTSP_DESCRIBE;
			p += 9;
		}else if (strstr(p,"SETUP") != NULL) {
			rtspCmdType = RTSP_SETUP;
			p += 6;
	   	}else if (strstr(p,"PLAY") != NULL) {
			rtspCmdType = RTSP_PLAY;
			p += 5;
   		}else if (strstr(p,"TEARDOWN") != NULL) {
			rtspCmdType = RTSP_TEARDOWN;
			p += 9;
		}else if(strstr(p, "PAUSE") != NULL){
			rtspCmdType = RTSP_PAUSE;
			p += 6;
		}else{
			printf("Command error\n");
			close(rtsp_sock);
			exit(-1);
		}
/*
		if(strstr(p, "rtsp://") != NULL && rtspCmdType == RTSP_OPTIONS)
        {
			p += 7;
			int i = 0;
			while(*p != '/')
				hostaddr[i++] = *(p++);
			hostaddr[i] = 0;

			i = 0;
			p++;
			while(*p != ' ')
				filename[i++] = *(p++);
			filename[i] = 0;
		}
        else
        {
			printf("URL error\n");
			close(rtsp_sock);
			exit(-1);
		}
*/
        hostaddr[0] = '1';
        hostaddr[1] = '9';
        hostaddr[2] = '2';
        hostaddr[3] = '.';
        hostaddr[4] = '1';
        hostaddr[5] = '6';
        hostaddr[6] = '8';
        hostaddr[7] = '.';
        hostaddr[8] = '5';
        hostaddr[9] = '6';
        hostaddr[10] = '.';
        hostaddr[11] = '1';
        hostaddr[12] = '0';
        hostaddr[13] = '2';
        hostaddr[14] = ':';
        hostaddr[15] = '3';
        hostaddr[16] = '0';
        hostaddr[17] = '0';
        hostaddr[18] = '5';
        hostaddr[19] = '\0';

        if(rtspCmdType == RTSP_OPTIONS)
        {
            char directive[32];
            char host[256];
            char version[32];
            char file_name[32];
            int pcnt;

            pcnt = sscanf(cmd, "%31s %255s %31s", directive, host, version);
            char *str_temp;
            str_temp = (char *) strrchr((char *)host, '/'); 
       
            file_name[0] = '.';
            file_name[1] = '.';
            file_name[2] = '/';
            file_name[3] = '.';
            file_name[4] = '.';
            file_name[5] = '/';
            file_name[6] = 'm';
            file_name[7] = 'e';
            file_name[8] = 'd';
            file_name[9] = 'i';
            file_name[10] = 'a';
            
            int i = 11;
            while(*str_temp != '\0')
            {
                file_name[i] = *(str_temp);
                
                if(i!=0)
                    filename[i-12]= *(str_temp);
                i++;
                str_temp++;
            }
            file_name[i] = '\0';
            filename[i-12]='\0';
            inputStream = fopen(file_name, "rb");
        }
		    
        p = strtok(NULL, "\r\n");
		
		if ((p = strstr(p, "CSeq")) != NULL)
        {
            p += 5;
			int i = 0;
			while(*p != 0)
			    cseq[i++] = *(p++);
			cseq[i] = 0;
		} 
        else
        {
            printf("CSeq error\n");
        }
		    

		if (rtspCmdType == RTSP_SETUP)
    	{
			p = strtok(NULL, "\r\n");
			p = strtok(NULL, "\r\n");
        	if ( strstr(p,"RTP/AVP/TCP") != NULL)
				transportMode = TCP;
			else
				transportMode = UDP;
			if((p = strstr(p, "client_port=")) != NULL){
				p += 12;
				int i = 0;
				char port[25] = {0, };
				while(*p != '-')
					port[i++] = *(p++);
				
				port[i] = 0;
				clientRTPPort = atoi(port);
				
				i = 0;
				p++;
				while(*p != 0){
					if(*p != '\r' || *p != '\n')
						port[i++] = *(p++);
				}
				port[i] = 0;
				clientRTCPPort = atoi(port);
			}	
		}
	}

/*	이게 이제 진짜로 읽을려고 해서, 이 부분도 fork로 따로 들어줘야 할 거 같음, 아니면 무한루프돔여기서 
 	if(streamer != NULL && streamer->rtcp_sock != 0)
    {
		while((str_len = read(streamer->rtcp_sock, cmd, BUF_SIZE)) > 0){
			printf("rtcp : %s\n", cmd);		
		}
	}
*/
	switch(rtspCmdType){
		case RTSP_OPTIONS : printf("option\n"); handle_option(); break;
		case RTSP_DESCRIBE : printf("describe\n"); handle_describe(); break;
		case RTSP_SETUP : printf("setup\n"); handle_setup(); break;
		case RTSP_PLAY : printf("play\n"); handle_play(); break;
		case RTSP_TEARDOWN : printf("teardown\n"); handle_teardown(); break;
		case RTSP_PAUSE : printf("pause\n"); handle_pause();break; 
		default : printf("Not implemented\n"); return;
	}
}