/*----------------------------------------------------------------------
|   PLT_MediaRenderer::OnSetAVTransportURI
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaRenderer::OnSetAVTransportURI(PLT_ActionReference& action)
{
    if (m_Delegate) {
        return m_Delegate->OnSetAVTransportURI(action);
    }

    // default implementation is using state variable
    NPT_String uri;
    NPT_CHECK_WARNING(action->GetArgumentValue("CurrentURI", uri));

    NPT_String metadata;
    NPT_CHECK_WARNING(action->GetArgumentValue("CurrentURIMetaData", metadata));

    PLT_Service* serviceAVT;
    NPT_CHECK_WARNING(FindServiceByType("urn:schemas-upnp-org:service:AVTransport:1", serviceAVT));

    // update service state variables
    serviceAVT->SetStateVariable("AVTransportURI", uri);
    serviceAVT->SetStateVariable("AVTransportURIMetaData", metadata);

    serviceAVT->SetStateVariable("TransportState", "STOPPED");
    serviceAVT->SetStateVariable("TransportStatus", "OK");
    serviceAVT->SetStateVariable("TransportPlaySpeed", "1");


    NPT_CHECK_SEVERE(action->SetArgumentsOutFromStateVariable());


    return NPT_SUCCESS;
}
/*----------------------------------------------------------------------
|   PLT_MediaController::OnGetVolumeResponse
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaController::OnGetVolumeResponse(NPT_Result               res, 
										 PLT_DeviceDataReference& device, 
										 PLT_ActionReference&	  action, 
										 void*                    userdata) 
{
	NPT_String channel;
	NPT_String current_volume;
	NPT_UInt32 volume;
	
	if (NPT_FAILED(res) || action->GetErrorCode() != 0) {
        goto bad_action;
    }

	if (NPT_FAILED(action->GetArgumentValue("Channel", channel))) {
        goto bad_action;
    }

	if (NPT_FAILED(action->GetArgumentValue("CurrentVolume", current_volume))) {
        goto bad_action;
    }

	if (NPT_FAILED(current_volume.ToInteger(volume))) {
		  goto bad_action;
	}

	m_Delegate->OnGetVolumeResult(NPT_SUCCESS, device, channel, volume, userdata);
	return NPT_SUCCESS;

bad_action:
    m_Delegate->OnGetVolumeResult(NPT_FAILURE, device, "", 0, userdata);
    return NPT_FAILURE;
}
/*----------------------------------------------------------------------
|   PLT_MediaController::OnGetProtocolInfoResponse
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaController::OnGetProtocolInfoResponse(NPT_Result               res, 
                                               PLT_DeviceDataReference& device, 
                                               PLT_ActionReference&     action, 
                                               void*                    userdata)
{
    NPT_String     source_info, sink_info;
    PLT_StringList sources, sinks;

    if (NPT_FAILED(res) || action->GetErrorCode() != 0) {
        goto bad_action;
    }

    if (NPT_FAILED(action->GetArgumentValue("Source", source_info))) {
        goto bad_action;
    }
    ParseCSV(source_info, sources);

    if (NPT_FAILED(action->GetArgumentValue("Sink", sink_info))) {
        goto bad_action;
    }
    ParseCSV(sink_info, sinks);

    m_Delegate->OnGetProtocolInfoResult(NPT_SUCCESS, device, &sources, &sinks, userdata);
    return NPT_SUCCESS;

bad_action:
    m_Delegate->OnGetProtocolInfoResult(NPT_FAILURE, device, NULL, NULL, userdata);
    return NPT_FAILURE;
}
/*----------------------------------------------------------------------
|   PLT_MediaController::OnGetMuteResponse
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaController::OnGetMuteResponse(NPT_Result               res, 
                                       PLT_DeviceDataReference& device, 
                                       PLT_ActionReference&     action, 
                                       void*                    userdata)
{
    NPT_String channel, mute;

    if (NPT_FAILED(res) || action->GetErrorCode() != 0) {
        goto bad_action;
    }

    if (NPT_FAILED(action->GetArgumentValue("Channel", channel))) {
        goto bad_action;
    }

    if (NPT_FAILED(action->GetArgumentValue("CurrentMute", mute))) {
        goto bad_action;
    }

    m_Delegate->OnGetMuteResult(
        NPT_SUCCESS, 
        device, 
        channel, 
        PLT_Service::IsTrue(mute)?true:false, 
        userdata);
    return NPT_SUCCESS;

bad_action:
    m_Delegate->OnGetMuteResult(NPT_FAILURE, device, "", false, userdata);
    return NPT_FAILURE;
}
/*----------------------------------------------------------------------
|   PLT_MediaController::OnGetTransportSettingsResponse
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaController::OnGetTransportSettingsResponse(NPT_Result               res, 
                                                    PLT_DeviceDataReference& device, 
                                                    PLT_ActionReference&     action, 
                                                    void*                    userdata)
{
    PLT_TransportSettings settings;

    if (NPT_FAILED(res) || action->GetErrorCode() != 0) {
        goto bad_action;
    }

    if (NPT_FAILED(action->GetArgumentValue("PlayMode", settings.play_mode))) {
        goto bad_action;
    }    
    if (NPT_FAILED(action->GetArgumentValue("RecQualityMode", settings.rec_quality_mode))) {
        goto bad_action;
    }    

    m_Delegate->OnGetTransportSettingsResult(NPT_SUCCESS, device, &settings, userdata);
    return NPT_SUCCESS;

bad_action:
    m_Delegate->OnGetTransportSettingsResult(NPT_FAILURE, device, NULL, userdata);
    return NPT_FAILURE;
}
Beispiel #6
0
/*----------------------------------------------------------------------
|   CUPnPRenderer::OnSetAVTransportURI
+---------------------------------------------------------------------*/
NPT_Result
CUPnPRenderer::OnSetAVTransportURI(PLT_ActionReference& action)
{
    NPT_String uri, meta;
    PLT_Service* service;
    NPT_CHECK_SEVERE(FindServiceByType("urn:schemas-upnp-org:service:AVTransport:1", service));

    NPT_CHECK_SEVERE(action->GetArgumentValue("CurrentURI", uri));
    NPT_CHECK_SEVERE(action->GetArgumentValue("CurrentURIMetaData", meta));

    // if not playing already, just keep around uri & metadata
    // and wait for play command
    if (!g_application.m_pPlayer->IsPlaying() && g_windowManager.GetActiveWindow() != WINDOW_SLIDESHOW) {
        service->SetStateVariable("TransportState", "STOPPED");
        service->SetStateVariable("TransportStatus", "OK");
        service->SetStateVariable("TransportPlaySpeed", "1");
        service->SetStateVariable("AVTransportURI", uri);
        service->SetStateVariable("AVTransportURIMetaData", meta);
        service->SetStateVariable("NextAVTransportURI", "");
        service->SetStateVariable("NextAVTransportURIMetaData", "");

        NPT_CHECK_SEVERE(action->SetArgumentsOutFromStateVariable());
        return NPT_SUCCESS;
    }

    return PlayMedia(uri, meta, action.AsPointer());
}
/*----------------------------------------------------------------------
|   PLT_MediaRenderer::OnSetAVTransportURI
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaRenderer::OnSetAVTransportURI(PLT_ActionReference& action)
{
	/*test*/
	PLT_Service* serviceAVT;
	NPT_CHECK_WARNING(FindServiceByType("urn:schemas-upnp-org:service:AVTransport:1", serviceAVT));

	// update service state variables
	//serviceAVT->SetStateVariable("TransportState", "TRANSITIONING");
	/*test*/
    if (m_Delegate) {
        return m_Delegate->OnSetAVTransportURI(action);
    }
    
    // default implementation is using state variable
	NPT_String uri;
	NPT_CHECK_WARNING(action->GetArgumentValue("CurrentURI", uri));

    NPT_String metadata;
    NPT_CHECK_WARNING(action->GetArgumentValue("CurrentURIMetaData", metadata));
    
    //PLT_Service* serviceAVT;
    //NPT_CHECK_WARNING(FindServiceByType("urn:schemas-upnp-org:service:AVTransport:1", serviceAVT));

    // update service state variables
    serviceAVT->SetStateVariable("AVTransportURI", uri);
    serviceAVT->SetStateVariable("AVTransportURIMetaData", metadata);

	//serviceAVT->SetStateVariable("TransportState", "PLAYING");//test
	OutputDebugString(uri.GetChars());

    return NPT_SUCCESS;
}
/*----------------------------------------------------------------------
|   PLT_MediaController::OnGetTransportInfoResponse
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaController::OnGetTransportInfoResponse(NPT_Result               res, 
                                                PLT_DeviceDataReference& device, 
                                                PLT_ActionReference&     action, 
                                                void*                    userdata)
{
    PLT_TransportInfo info;

    if (NPT_FAILED(res) || action->GetErrorCode() != 0) {
        goto bad_action;
    }

    if (NPT_FAILED(action->GetArgumentValue("CurrentTransportState", info.cur_transport_state))) {
        goto bad_action;
    }    
    if (NPT_FAILED(action->GetArgumentValue("CurrentTransportStatus", info.cur_transport_status))) {
        goto bad_action;
    }    
    if (NPT_FAILED(action->GetArgumentValue("CurrentSpeed", info.cur_speed))) {
        goto bad_action;
    }    

    m_Delegate->OnGetTransportInfoResult(NPT_SUCCESS, device, &info, userdata);
    return NPT_SUCCESS;

bad_action:
    m_Delegate->OnGetTransportInfoResult(NPT_FAILURE, device, NULL, userdata);
    return NPT_FAILURE;
}
Beispiel #9
0
/*----------------------------------------------------------------------
|   PLT_MediaController::OnGetPositionInfoResponse
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaController::OnGetPositionInfoResponse(NPT_Result res, 
                                               PLT_DeviceDataReference& device, 
                                               PLT_ActionReference& action, 
                                               void* userdata)
{
    NPT_String       value;
    PLT_PositionInfo info;

    if (NPT_FAILED(res) || action->GetErrorCode() != 0) {
        goto bad_action;
    }

    if (NPT_FAILED(action->GetArgumentValue("Track", info.track))) {
        goto bad_action;
    }

    if (NPT_FAILED(action->GetArgumentValue("TrackDuration", value))) {
        goto bad_action;
    }
    if (NPT_FAILED(PLT_Didl::ParseTimeStamp(value, info.track_duration))) {
        goto bad_action;
    }

    if (NPT_FAILED(action->GetArgumentValue("TrackMetaData", info.track_metadata))) {
        goto bad_action;
    }    
    
    if (NPT_FAILED(action->GetArgumentValue("TrackURI", info.track_uri))) {
        goto bad_action;
    }

    if (NPT_FAILED(action->GetArgumentValue("RelTime", value))) {
        goto bad_action;
    }
    if (NPT_FAILED(PLT_Didl::ParseTimeStamp(value, info.rel_time))) {
        goto bad_action;
    }

    if (NPT_FAILED(action->GetArgumentValue("AbsTime", value))) {
        goto bad_action;
    }
    if (NPT_FAILED(PLT_Didl::ParseTimeStamp(value, info.abs_time))) {
        goto bad_action;
    }

    if (NPT_FAILED(action->GetArgumentValue("RelCount", info.rel_count))) {
        goto bad_action;
    }    
    if (NPT_FAILED(action->GetArgumentValue("AbsCount", info.abs_count))) {
        goto bad_action;
    }

    m_Listener->OnGetPositionInfoResult(NPT_SUCCESS, device, &info, userdata);
    return NPT_SUCCESS;

bad_action:
    m_Listener->OnGetPositionInfoResult(NPT_FAILURE, device, NULL, userdata);
    return NPT_FAILURE;
}
Beispiel #10
0
/*----------------------------------------------------------------------
|   PLT_MediaBrowser::OnSearchResponse
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaBrowser::OnSearchResponse(NPT_Result               res, 
                                   PLT_DeviceDataReference& device, 
                                   PLT_ActionReference&     action, 
                                   void*                    userdata)
{
    NPT_String     value;
    PLT_BrowseInfo info;
    NPT_String     unescaped;

    if (NPT_FAILED(res) || action->GetErrorCode() != 0) {
        goto bad_action;
    }

    if (NPT_FAILED(action->GetArgumentValue("ContainerId", info.object_id)))  {
        goto bad_action;
    }
    if (NPT_FAILED(action->GetArgumentValue("UpdateID", value)) || 
        value.GetLength() == 0 || 
        NPT_FAILED(value.ToInteger(info.uid))) {
        goto bad_action;
    }
    if (NPT_FAILED(action->GetArgumentValue("NumberReturned", value)) || 
        value.GetLength() == 0 || 
        NPT_FAILED(value.ToInteger(info.nr))) {
        goto bad_action;
    }
    if (NPT_FAILED(action->GetArgumentValue("TotalMatches", value)) || 
        value.GetLength() == 0 || 
        NPT_FAILED(value.ToInteger(info.tm))) {
        goto bad_action;
    }
    if (NPT_FAILED(action->GetArgumentValue("Result", value)) || 
        value.GetLength() == 0) {
        goto bad_action;
    }
    
    if (NPT_FAILED(PLT_Didl::FromDidl(value, info.items))) {
        goto bad_action;
    }

    if (m_Delegate) m_Delegate->OnSearchResult(NPT_SUCCESS, device, &info, userdata);
    return NPT_SUCCESS;

bad_action:
    if (m_Delegate) m_Delegate->OnSearchResult(NPT_FAILURE, device, NULL, userdata);
    return NPT_FAILURE;
}
/*----------------------------------------------------------------------
 |   CUPnPRenderer::OnSetAVTransportURI
 +---------------------------------------------------------------------*/
NPT_Result
CUPnPRenderer::OnSetNextAVTransportURI(PLT_ActionReference& action)
{
    NPT_String uri, meta;
    PLT_Service* service;
    NPT_CHECK_SEVERE(FindServiceByType("urn:schemas-upnp-org:service:AVTransport:1", service));

    NPT_CHECK_SEVERE(action->GetArgumentValue("NextURI", uri));
    NPT_CHECK_SEVERE(action->GetArgumentValue("NextURIMetaData", meta));

    CFileItemPtr item = GetFileItem(uri, meta);
    if (!item) {
        return NPT_FAILURE;
    }
#if 0
    if (g_application.m_pPlayer->IsPlaying()) {

        int playlist = PLAYLIST_MUSIC;
        if(item->IsVideo())
          playlist = PLAYLIST_VIDEO;

        {   CSingleLock lock(g_graphicsContext);
            g_playlistPlayer.ClearPlaylist(playlist);
            g_playlistPlayer.Add(playlist, item);

            g_playlistPlayer.SetCurrentSong(-1);
            g_playlistPlayer.SetCurrentPlaylist(playlist);
        }

        CGUIMessage msg(GUI_MSG_PLAYLIST_CHANGED, 0, 0);
        g_windowManager.SendThreadMessage(msg);


        service->SetStateVariable("NextAVTransportURI", uri);
        service->SetStateVariable("NextAVTransportURIMetaData", meta);

        NPT_CHECK_SEVERE(action->SetArgumentsOutFromStateVariable());

        return NPT_SUCCESS;

  } else if (g_windowManager.GetActiveWindow() == WINDOW_SLIDESHOW) {
        return NPT_FAILURE;
  } else {
        return NPT_FAILURE;
  }
#endif
  return NPT_SUCCESS;
}
/*----------------------------------------------------------------------
|   PLT_MediaController::OnGetCurrentTransportActionsResponse
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaController::OnGetCurrentTransportActionsResponse(NPT_Result               res, 
                                                          PLT_DeviceDataReference& device, 
                                                          PLT_ActionReference&     action, 
                                                          void*                    userdata)
{
    NPT_String actions;
    PLT_StringList values;

    if (NPT_FAILED(res) || action->GetErrorCode() != 0) {
        goto bad_action;
    }

    if (NPT_FAILED(action->GetArgumentValue("Actions", actions))) {
        goto bad_action;
    }

    // parse the list of actions and return a list to listener
    ParseCSV(actions, values);

    m_Delegate->OnGetCurrentTransportActionsResult(NPT_SUCCESS, device, &values, userdata);
    return NPT_SUCCESS;

bad_action:
    m_Delegate->OnGetCurrentTransportActionsResult(NPT_FAILURE, device, NULL, userdata);
    return NPT_FAILURE;
}
Beispiel #13
0
/*----------------------------------------------------------------------
|   PLT_MediaController::OnGetCurrentConnectionIDsResponse
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaController::OnGetCurrentConnectionIDsResponse(NPT_Result res, 
                                                       PLT_DeviceDataReference& device, 
                                                       PLT_ActionReference& action, 
                                                       void* userdata)
{
    NPT_String value;
    PLT_StringList IDs;

    if (NPT_FAILED(res) || action->GetErrorCode() != 0) {
        goto bad_action;
    }

    if (NPT_FAILED(action->GetArgumentValue("ConnectionIDs", value))) {
        goto bad_action;
    }
    // parse the list of medias and return a list to listener
    ParseCSV(value, IDs);

    m_Listener->OnGetCurrentConnectionIDsResult(NPT_SUCCESS, device, &IDs, userdata);
    return NPT_SUCCESS;

bad_action:
    m_Listener->OnGetCurrentConnectionIDsResult(NPT_FAILURE, device, NULL, userdata);
    return NPT_FAILURE;
}
Beispiel #14
0
/*----------------------------------------------------------------------
|       PLT_MediaConnect::OnIsValidated
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaConnect::OnIsValidated(PLT_ActionReference&  action, 
                                PLT_MediaConnectInfo* mc_info)
{
    bool validated = true;

    NPT_String deviceID;
    action->GetArgumentValue("DeviceID", deviceID);

    /* is there a device ID passed ? */
    if (deviceID.GetLength()) {
        /* lookup the MediaConnectInfo from the UDN */
        NPT_String MAC;
        PLT_MediaConnectInfo* device_info;
        if (NPT_FAILED(LookUpMediaConnectInfo(deviceID, device_info))) {
            validated = false;
        } else {
            validated = device_info->m_Validated;
        }
    } else {
        validated = mc_info?mc_info->m_Validated:true;
    }

    action->SetArgumentValue("Result", validated?"1":"0");
    return NPT_SUCCESS;
}
Beispiel #15
0
/*----------------------------------------------------------------------
|   PLT_LightSampleDevice::OnAction
+---------------------------------------------------------------------*/
NPT_Result
PLT_LightSampleDevice::OnAction(PLT_ActionReference& action, NPT_SocketInfo* /* info */)
{
    /* parse the action name */
    NPT_String name = action->GetActionDesc()->GetName();
    if (name.Compare("SetTarget") == 0) {
        NPT_String value;
        action->GetArgumentValue("newTargetValue", value);

        PLT_StateVariable* variable = action->GetActionDesc()->GetService()->FindStateVariable("Status");
        if (NPT_FAILED(variable->SetValue(value))) {
            action->SetError(402, "Invalid Args");
            return NPT_FAILURE;
        }
        return NPT_SUCCESS;
    } else if (name.Compare("GetStatus") == 0) {
        PLT_StateVariable* variable = action->GetActionDesc()->GetService()->FindStateVariable("Status");
        if (variable) {
            action->SetArgumentValue("ResultStatus", variable->GetValue());
            return NPT_SUCCESS;
        }
    }
    
    action->SetError(501, "Action Failed");
    return NPT_FAILURE;
}
/*----------------------------------------------------------------------
|   PLT_MediaController::OnGetMediaInfoResponse
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaController::OnGetMediaInfoResponse(NPT_Result               res, 
                                            PLT_DeviceDataReference& device, 
                                            PLT_ActionReference&     action, 
                                            void*                    userdata)
{
    NPT_String      value;
    PLT_MediaInfo   info;

    if (NPT_FAILED(res) || action->GetErrorCode() != 0) {
        goto bad_action;
    }

    if (NPT_FAILED(action->GetArgumentValue("NrTracks", info.num_tracks))) {
        goto bad_action;
    }
    if (NPT_FAILED(action->GetArgumentValue("MediaDuration", value))) {
        goto bad_action;
    }
    if (NPT_FAILED(PLT_Didl::ParseTimeStamp(value, info.media_duration))) {
        goto bad_action;
    }

    if (NPT_FAILED(action->GetArgumentValue("CurrentURI", info.cur_uri))) {
        goto bad_action;
    }
    if (NPT_FAILED(action->GetArgumentValue("CurrentURIMetaData", info.cur_metadata))) {
        goto bad_action;
    }
    if (NPT_FAILED(action->GetArgumentValue("NextURI", info.next_uri))) {
        goto bad_action;
    }
    if (NPT_FAILED(action->GetArgumentValue("NextURIMetaData",  info.next_metadata))) {
        goto bad_action;
    }
    if (NPT_FAILED(action->GetArgumentValue("PlayMedium", info.play_medium))) {
        goto bad_action;
    }
    if (NPT_FAILED(action->GetArgumentValue("RecordMedium", info.rec_medium))) {
        goto bad_action;
    }
    if (NPT_FAILED(action->GetArgumentValue("WriteStatus", info.write_status))) {
        goto bad_action;
    }

    m_Delegate->OnGetMediaInfoResult(NPT_SUCCESS, device, &info, userdata);
    return NPT_SUCCESS;

bad_action:
    m_Delegate->OnGetMediaInfoResult(NPT_FAILURE, device, NULL, userdata);
    return NPT_FAILURE;
}
Beispiel #17
0
/*----------------------------------------------------------------------
|   PLT_MediaServer::OnUpdate
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaServer::OnUpdate(PLT_ActionReference&          action,
                          const PLT_HttpRequestContext& context)
{
    if (!m_Delegate)
        return NPT_ERROR_NOT_IMPLEMENTED;

    int err;
    const char* msg = NULL;

    NPT_String object_id, current_xml, new_xml;
    NPT_Map<NPT_String,NPT_String> curr_values;
    NPT_Map<NPT_String,NPT_String> new_values;

    NPT_CHECK_LABEL(action->GetArgumentValue("ObjectID", object_id), args);
    NPT_CHECK_LABEL(object_id.IsEmpty(),args);
    NPT_CHECK_LABEL(action->GetArgumentValue("CurrentTagValue", current_xml), args);
    NPT_CHECK_LABEL(action->GetArgumentValue("NewTagValue",  new_xml), args);

    if (NPT_FAILED(ParseTagList(current_xml, curr_values))) {
        err = 702;
        msg = "Invalid currentTagvalue";
        goto failure;
    }
    if (NPT_FAILED(ParseTagList(new_xml, new_values))) {
        err = 703;
        msg = "Invalid newTagValue";
        goto failure;
    }

    if (curr_values.GetEntryCount() != new_values.GetEntryCount()) {
        err = 706;
        msg = "Paramater mismatch";
        goto failure;
    }

    return m_Delegate->OnUpdateObject(action, object_id, curr_values, new_values, context);

args:
    err = 402;
    msg = "Invalid args";

failure:
    NPT_LOG_WARNING(msg);
    action->SetError(err, msg);
    return NPT_FAILURE;
}
Beispiel #18
0
/*----------------------------------------------------------------------
|   CUPnPRenderer::OnSetVolume
+---------------------------------------------------------------------*/
NPT_Result
CUPnPRenderer::OnSetVolume(PLT_ActionReference& action)
{
    NPT_String volume;
    NPT_CHECK_SEVERE(action->GetArgumentValue("DesiredVolume", volume));
    g_application.SetVolume((float)strtod((const char*)volume, NULL));
    return NPT_SUCCESS;
}
Beispiel #19
0
/*----------------------------------------------------------------------
|   CUPnPRenderer::OnSeek
+---------------------------------------------------------------------*/
NPT_Result
CUPnPRenderer::OnSeek(PLT_ActionReference& action)
{
    if (!g_application.m_pPlayer->IsPlaying()) return NPT_ERROR_INVALID_STATE;

    NPT_String unit, target;
    NPT_CHECK_SEVERE(action->GetArgumentValue("Unit", unit));
    NPT_CHECK_SEVERE(action->GetArgumentValue("Target", target));

    if (!unit.Compare("REL_TIME")) {
        // converts target to seconds
        NPT_UInt32 seconds;
        NPT_CHECK_SEVERE(PLT_Didl::ParseTimeStamp(target, seconds));
        g_application.SeekTime(seconds);
    }

    return NPT_SUCCESS;
}
Beispiel #20
0
/*----------------------------------------------------------------------
|   CUPnPRenderer::OnSetMute
+---------------------------------------------------------------------*/
NPT_Result
CUPnPRenderer::OnSetMute(PLT_ActionReference& action)
{
    NPT_String mute;
    NPT_CHECK_SEVERE(action->GetArgumentValue("DesiredMute",mute));
    if((mute == "1") ^ g_application.IsMuted())
        g_application.ToggleMute();
    return NPT_SUCCESS;
}
Beispiel #21
0
/*----------------------------------------------------------------------
|   CMediaCrawler::OnBrowseResponse
+---------------------------------------------------------------------*/
NPT_Result
CMediaCrawler::OnBrowseResponse(NPT_Result               res, 
                                PLT_DeviceDataReference& device, 
                                PLT_ActionReference&     action, 
                                void*                    userdata)
{
    NPT_COMPILER_UNUSED(device);

    if (!userdata) return NPT_FAILURE;

    CMediaCrawlerBrowseInfoReference* info = (CMediaCrawlerBrowseInfoReference*) userdata;
    (*info)->res = res;
    (*info)->code = action->GetErrorCode();

    if (NPT_FAILED(res) || action->GetErrorCode() != 0) {
        goto bad_action;
    }

    if (NPT_FAILED(action->GetArgumentValue("ObjectID", (*info)->object_id)))  {
        goto bad_action;
    }
    if (NPT_FAILED(action->GetArgumentValue("UpdateID", (*info)->uid))) {
        goto bad_action;
    }
    if (NPT_FAILED(action->GetArgumentValue("NumberReturned", (*info)->nr))) {
        goto bad_action;
    }
    if (NPT_FAILED(action->GetArgumentValue("TotalMatches", (*info)->tm))) {
        goto bad_action;
    }
    if (NPT_FAILED(action->GetArgumentValue("Result", (*info)->didl))) {
        goto bad_action;
    }
    goto done;

bad_action:
    if (NPT_SUCCEEDED((*info)->res)) (*info)->res = NPT_FAILURE;

done:
    (*info)->shared_var.SetValue(1);
    delete info;

    return NPT_SUCCESS;
}
Beispiel #22
0
/*----------------------------------------------------------------------
|       PLT_MediaConnect::OnRegisterDevice
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaConnect::OnRegisterDevice(PLT_ActionReference&  action)
{
    NPT_String reqMsgBase64;
    NPT_CHECK_WARNING(action->GetArgumentValue("RegistrationReqMsg", reqMsgBase64));

    NPT_String respMsgBase64;
    NPT_CHECK_WARNING(action->SetArgumentValue("RegistrationRespMsg", respMsgBase64));
    return NPT_SUCCESS;
}
Beispiel #23
0
NPT_Result GPAC_MediaRenderer::OnSeek(PLT_ActionReference& action)
{
	u32 h, m, s;
	Double time;
    NPT_String unit, target;
    if (NPT_FAILED(action->GetArgumentValue("Unit", unit))) {
        return NPT_FAILURE;
	}
    if (NPT_FAILED(action->GetArgumentValue("Target", target))) {
        return NPT_FAILURE;
	}
	if ((unit!="ABS_TIME") && (unit!="REL_TIME")) {
		action->SetError(710,"Seek mode not supported");
        return NPT_FAILURE;
	}
	sscanf(target, "%d:%d:%d", &h, &m, &s);
	time = h*3600.0 + m*60.0 + s;
	m_pUPnP->OnSeek(time);
    return NPT_SUCCESS;
}
Beispiel #24
0
/*----------------------------------------------------------------------
|       PLT_MediaConnect::OnRegisterDevice
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaConnect::OnRegisterDevice(PLT_ActionReference&  action, 
                                   PLT_MediaConnectInfo* mc_info)
{
    NPT_COMPILER_UNUSED(mc_info);

    NPT_String reqMsgBase64;
    action->GetArgumentValue("RegistrationReqMsg", reqMsgBase64);

    NPT_String respMsgBase64;
    action->SetArgumentValue("RegistrationRespMsg", respMsgBase64);
    return NPT_SUCCESS;
}
/*----------------------------------------------------------------------
|   PLT_MediaController::OnGetDeviceCapabilitiesResponse
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaController::OnGetDeviceCapabilitiesResponse(NPT_Result               res, 
                                                     PLT_DeviceDataReference& device, 
                                                     PLT_ActionReference&     action, 
                                                     void*                    userdata)
{
    NPT_String value;
    PLT_DeviceCapabilities capabilities;

    if (NPT_FAILED(res) || action->GetErrorCode() != 0) {
        goto bad_action;
    }

    if (NPT_FAILED(action->GetArgumentValue("PlayMedia", value))) {
        goto bad_action;
    }
    // parse the list of medias and return a list to listener
    ParseCSV(value, capabilities.play_media);

    if (NPT_FAILED(action->GetArgumentValue("RecMedia", value))) {
        goto bad_action;
    }
    // parse the list of rec and return a list to listener
    ParseCSV(value, capabilities.rec_media);

    if (NPT_FAILED(action->GetArgumentValue("RecQualityModes", value))) {
        goto bad_action;
    }
    // parse the list of modes and return a list to listener
    ParseCSV(value, capabilities.rec_quality_modes);

    m_Delegate->OnGetDeviceCapabilitiesResult(NPT_SUCCESS, device, &capabilities, userdata);
    return NPT_SUCCESS;

bad_action:
    m_Delegate->OnGetDeviceCapabilitiesResult(NPT_FAILURE, device, NULL, userdata);
    return NPT_FAILURE;
}
Beispiel #26
0
/*----------------------------------------------------------------------
|   PLT_FileMediaServer::OnBrowseMetadata
+---------------------------------------------------------------------*/
NPT_Result
PLT_FileMediaServer::OnBrowseMetadata(PLT_ActionReference&          action, 
                                      const char*                   object_id, 
                                      const NPT_HttpRequestContext& context)
{
    NPT_String didl;
    PLT_MediaObjectReference item;

    /* locate the file from the object ID */
    NPT_String filepath;
    if (NPT_FAILED(GetFilePath(object_id, filepath))) {
        /* error */
        NPT_LOG_WARNING("PLT_FileMediaServer::OnBrowse - ObjectID not found.");
        action->SetError(701, "No Such Object.");
        return NPT_FAILURE;
    }

    item = BuildFromFilePath(
        filepath, 
        true,
        &context.GetLocalAddress());

    if (item.IsNull()) return NPT_FAILURE;

    NPT_String filter;
    NPT_CHECK_SEVERE(action->GetArgumentValue("Filter", filter));

    NPT_String tmp;    
    NPT_CHECK_SEVERE(PLT_Didl::ToDidl(*item.AsPointer(), filter, tmp));

    /* add didl header and footer */
    didl = didl_header + tmp + didl_footer;

    NPT_CHECK_SEVERE(action->SetArgumentValue("Result", didl));
    NPT_CHECK_SEVERE(action->SetArgumentValue("NumberReturned", "1"));
    NPT_CHECK_SEVERE(action->SetArgumentValue("TotalMatches", "1"));

    // update ID may be wrong here, it should be the one of the container?
    // TODO: We need to keep track of the overall updateID of the CDS
    NPT_CHECK_SEVERE(action->SetArgumentValue("UpdateId", "1"));

    return NPT_SUCCESS;
}
Beispiel #27
0
/*----------------------------------------------------------------------
|   PLT_MediaServer::OnBrowse
+---------------------------------------------------------------------*/
NPT_Result
CMediaCrawler::OnBrowse(PLT_ActionReference&          action, 
                        const NPT_HttpRequestContext& context)
{
    NPT_Result res;

    NPT_String object_id;
    if (NPT_FAILED(action->GetArgumentValue("ObjectId", object_id))) {
        NPT_LOG_WARNING("PLT_FileMediaServer::OnBrowse - invalid arguments.");
        return NPT_FAILURE;
    }

    NPT_LOG_FINE_1("PLT_FileMediaServer::OnOnBrowse - id = %s\r\n", (const char*)object_id);

    // extract server uuid and server object id from our object id
    NPT_String server_uuid;
    NPT_String server_object_id;
    if (NPT_FAILED(SplitObjectId(object_id, server_uuid, server_object_id))) {
        /* error */
        NPT_LOG_WARNING("CMediaCrawler::OnBrowse - ObjectID not found.");
        action->SetError(701, "No Such Object.");
        return NPT_FAILURE;
    }

    // root ?
    if (server_uuid.GetLength() == 0) {
        res = OnBrowseRoot(action);
    } else {
        // we have a device to browse
        // is it device root?
        if (server_object_id.GetLength() == 0) {
            server_object_id = "0";
        }
        res = OnBrowseDevice(action, server_uuid, server_object_id, context);
    }

    if (NPT_FAILED(res) && (action->GetErrorCode() == 0)) {
        action->SetError(800, "Internal error");
    }

    return res;
}
Beispiel #28
0
NPT_Result GPAC_MediaRenderer::OnSetAVTransportURI(PLT_ActionReference& action)
{
	char the_url[4096], szVal[100];
    NPT_String url_id;
	const char *MediaUri;
    if (NPT_FAILED(action->GetArgumentValue("CurrentURI", url_id))) {
        return NPT_FAILURE;
	}
	MediaUri = url_id;
	if (!MediaUri) return NPT_FAILURE;

	GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, ("[UPnP] Request: change media\n"));

	if (m_connected) {
		m_connected = GF_FALSE;
		m_pUPnP->OnStop(m_ip_src);
	}
	const char *ext = strrchr(MediaUri, '.');
	if (ext && !stricmp(ext, ".m3u")) {
		GF_LOG(GF_LOG_ERROR, GF_LOG_NETWORK, ("[UPnP] M3U playlists not supported yet\n"));
		return NPT_SUCCESS;
	}

	/* Load and add to mediaHistoryList */
	strcpy(the_url, MediaUri);
	GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, ("[UPnP] Adding media to the list : %s\n", MediaUri));
	gf_list_add(m_mediaHistoryList, gf_strdup(MediaUri));
	GF_LOG(GF_LOG_INFO, GF_LOG_NETWORK, ("[UPnP] Opening URL %s\n", the_url));
	m_track_pos = gf_list_count(m_mediaHistoryList);

	m_connected = GF_TRUE;
	m_pUPnP->OnConnect(the_url, m_ip_src);
	/* Set UPnP datas */
    m_pAVService->SetStateVariable("TransportState", "PLAYING");
    m_pAVService->SetStateVariable("AVTransportURI", the_url);

	sprintf(szVal, "%d", gf_list_count(m_mediaHistoryList));
    m_pAVService->SetStateVariable("NumberOfTracks", szVal);
	sprintf(szVal, "%d", m_track_pos);
    m_pAVService->SetStateVariable("CurrentTrack", szVal);
	return NPT_SUCCESS;
}
/*----------------------------------------------------------------------
|   PLT_MediaController::OnGetCurrentConnectionInfoResponse
+---------------------------------------------------------------------*/
NPT_Result
PLT_MediaController::OnGetCurrentConnectionInfoResponse(NPT_Result               res, 
                                                        PLT_DeviceDataReference& device, 
                                                        PLT_ActionReference&     action, 
                                                        void*                    userdata)
{
    NPT_String value;
    PLT_ConnectionInfo info;

    if (NPT_FAILED(res) || action->GetErrorCode() != 0) {
        goto bad_action;
    }

    if (NPT_FAILED(action->GetArgumentValue("RcsID", info.rcs_id))) {
        goto bad_action;
    }
    if (NPT_FAILED(action->GetArgumentValue("AVTransportID", info.avtransport_id))) {
        goto bad_action;
    }
    if (NPT_FAILED(action->GetArgumentValue("ProtocolInfo", info.protocol_info))) {
        goto bad_action;
    }
    if (NPT_FAILED(action->GetArgumentValue("PeerConnectionManager", info.peer_connection_mgr))) {
        goto bad_action;
    }
    if (NPT_FAILED(action->GetArgumentValue("PeerConnectionID", info.peer_connection_id))) {
        goto bad_action;
    }
    if (NPT_FAILED(action->GetArgumentValue("Direction", info.direction))) {
        goto bad_action;
    }
    if (NPT_FAILED(action->GetArgumentValue("Status", info.status))) {
        goto bad_action;
    }
    m_Delegate->OnGetCurrentConnectionInfoResult(NPT_SUCCESS, device, &info, userdata);
    return NPT_SUCCESS;

bad_action:
    m_Delegate->OnGetCurrentConnectionInfoResult(NPT_FAILURE, device, NULL, userdata);
    return NPT_FAILURE;
}
Beispiel #30
0
/*----------------------------------------------------------------------
|   PLT_FileMediaServer::OnBrowseDirectChildren
+---------------------------------------------------------------------*/
NPT_Result
PLT_FileMediaServer::OnBrowseDirectChildren(PLT_ActionReference&          action, 
                                            const char*                   object_id, 
                                            const NPT_HttpRequestContext& context)
{
    /* locate the file from the object ID */
    NPT_String dir;
    if (NPT_FAILED(GetFilePath(object_id, dir))) {
        /* error */
        NPT_LOG_WARNING("PLT_FileMediaServer::OnBrowse - ObjectID not found.");
        action->SetError(701, "No Such Object.");
        return NPT_FAILURE;
    }

    /* retrieve the item type */
    NPT_FileInfo info;
    NPT_Result res = NPT_File::GetInfo(dir, &info);
    if (NPT_FAILED(res)) {
        /* Object does not exist */
        NPT_LOG_WARNING_1("PLT_FileMediaServer::OnBrowse - BROWSEDIRECTCHILDREN failed for item %s", dir.GetChars());
        action->SetError(800, "Can't retrieve info " + dir);
        return NPT_FAILURE;
    }

    if (info.m_Type != NPT_FileInfo::FILE_TYPE_DIRECTORY) {
        /* error */
        NPT_LOG_WARNING("PLT_FileMediaServer::OnBrowse - BROWSEDIRECTCHILDREN not allowed on an item.");
        action->SetError(710, "item is not a container.");
        return NPT_FAILURE;
    }

    NPT_String filter;
    NPT_String startingInd;
    NPT_String reqCount;

    NPT_CHECK_SEVERE(action->GetArgumentValue("Filter", filter));
    NPT_CHECK_SEVERE(action->GetArgumentValue("StartingIndex", startingInd));
    NPT_CHECK_SEVERE(action->GetArgumentValue("RequestedCount", reqCount));   

    NPT_UInt32 start_index, req_count;
    if (NPT_FAILED(startingInd.ToInteger(start_index)) ||
        NPT_FAILED(reqCount.ToInteger(req_count))) {        
        action->SetError(412, "Precondition failed");
        return NPT_FAILURE;
    }

    NPT_List<NPT_String> entries;
    res = NPT_File::ListDirectory(dir, entries, 0, 0);
    if (NPT_FAILED(res)) {
        NPT_LOG_WARNING_1("PLT_FileMediaServer::OnBrowseDirectChildren - failed to open dir %s", (const char*) dir);
        return res;
    }

    unsigned long cur_index = 0;
    unsigned long num_returned = 0;
    unsigned long total_matches = 0;
    NPT_String didl = didl_header;

    PLT_MediaObjectReference item;
    for (NPT_List<NPT_String>::Iterator it = entries.GetFirstItem();
        it;
        ++it) {
        NPT_String& filename = *it;
        item = BuildFromFilePath(
            NPT_FilePath::Create(dir, filename), 
            true, 
            &context.GetLocalAddress());

        if (!item.IsNull()) {
            if ((cur_index >= start_index) && ((num_returned < req_count) || (req_count == 0))) {
                NPT_String tmp;
                NPT_CHECK_SEVERE(PLT_Didl::ToDidl(*item.AsPointer(), filter, tmp));

                didl += tmp;
                num_returned++;
            }
            cur_index++;
            total_matches++;        
        }
    };

    didl += didl_footer;

    NPT_CHECK_SEVERE(action->SetArgumentValue("Result", didl));
    NPT_CHECK_SEVERE(action->SetArgumentValue("NumberReturned", NPT_String::FromInteger(num_returned)));
    NPT_CHECK_SEVERE(action->SetArgumentValue("TotalMatches", NPT_String::FromInteger(total_matches))); // 0 means we don't know how many we have but most browsers don't like that!!
    NPT_CHECK_SEVERE(action->SetArgumentValue("UpdateId", "1"));

    return NPT_SUCCESS;
}