> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XGameStreamingSetResolution

> XGameStreamingSetResolution

# XGameStreamingSetResolution

Establece la resolución de la transmisión.

## Sintaxis

```cpp theme={null}
HRESULT XGameStreamingSetResolution(
        uint32_t width,
        uint32_t height
)
```

### Parámetros

*width*   \_In\_\
Tipo: uint32\_t

El ancho en el que se establecerá la resolución de la transmisión.

*height*   \_In\_\
Tipo: uint32\_t

El alto en el que se establecerá la resolución de la transmisión.

### Valor devuelto

Tipo: HRESULT

Devuelve **S\_OK** si se realiza correctamente; de lo contrario, devuelve un código de error.

#### Posibles errores

| Código de error                    | Valor de error | Motivo del error                                                                                                               |
| ---------------------------------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------ |
| E\_GAMESTREAMING\_NOT\_INITIALIZED | 0x89245400     | No se ha inicializado el entorno de ejecución de XGameStreaming. Llame a XGameStreamingInitialize antes de llamar a otras API. |
| E\_INVALIDARG                      | 0x80070057     | El parámetro *width* o *height*, o el hardware, no cumplieron los requisitos.                                                  |

Para obtener una lista de códigos de error, consulte [Códigos de error](/reference/errorcodes).

## Comentarios

Esta API con resoluciones no estándar solo se ejecutará correctamente en servidores de XBOX Game Streaming, en el kit de desarrollo XBOX Series X y en el kit de pruebas XBOX Series S. Las resoluciones estándar como 720p y 1080p se ejecutarán correctamente independientemente del hardware. El motivo es que una XBOX comercial solo puede transmitir mediante Remote Play y es posible que siga emitiendo vídeo al televisor, por lo que usar una resolución no estándar produciría una imagen distorsionada.

El ancho y el alto deben ser como mínimo de 640x360, y el máximo se puede encontrar en los campos `maxWidth` y `maxHeight` de [XGameStreamingDisplayDetails](/reference/system/xgamestreaming/structs/xgamestreamingdisplaydetails), que se puede recuperar desde [XGameStreamingGetDisplayDetails](/reference/system/xgamestreaming/functions/xgamestreaminggetdisplaydetails).

Los píxeles máximos, calculados a partir de `width` \* `height`, deben ser iguales o inferiores al máximo del codificador. El máximo se puede encontrar mediante la API [XGameStreamingGetDisplayDetails](/reference/system/xgamestreaming/functions/xgamestreaminggetdisplaydetails). Este valor puede aumentar en el futuro.

`width` y `height` deben ser divisibles por 8.

Se puede llamar a la API con la frecuencia que se desee; sin embargo, la resolución de la transmisión solo puede cambiar una vez cada 200 ms. La última resolución de todas las llamadas que se produzcan dentro de esa ventana de 200 ms se aplicará una vez transcurrida dicha ventana.

Tenga en cuenta que esta API establecerá la resolución de la transmisión para todos los clientes conectados. Esto significa que se debe prestar especial atención para determinar cuál es la mejor opción para el juego cuando hay varios clientes conectados. Puede significar usar una resolución estándar de 16:9 o puede significar intentar encontrar la resolución que mejor se adapte a todos los clientes.

<Note>Cambiar la resolución de la transmisión modifica el escalado del rectángulo de vista en ID3D12CommandQueue::PresentX. Los factores de escala de 0.0 a 1.0 de D3D12XBOX\_PRESENT\_PLANE\_PARAMETERS.pDestPlacementBase se refieren al alto y al ancho pasados a XGameStreamingSetResolution, en lugar de a la resolución estándar de 1920x1080 o 3840x2160 a la que se referirían en caso contrario.</Note>

## Ejemplo

```C++ theme={null}

#define DEFAULT_GAME_WIDTH 1920
#define DEFAULT_GAME_HEIGHT 1080

#define GAME_WIDEST_SUPPORTED_ASPECT_RATIO 21.5f / 9.0f
#define GAME_TALLEST_SUPPORTED_ASPECT_RATIO 16.0f / 10.0f

static uint32_t s_currentStreamWidth = DEFAULT_GAME_WIDTH;
static uint32_t s_currentStreamHeight = DEFAULT_GAME_HEIGHT;

// Option 1: Event driven. Note: be aware of potential threading issues when using the task queue.
void GameStreamingClientManager::OnConnectionStateChanged(XGameStreamingClientId client, XGameStreamingConnectionState connected)
{
    // Other connection work like registering or unregistering for the client properties change events.
    ...

    UpdateResolutionIfNeeded();
}

void GameStreamingClientManager::OnClientPropertiesChanged(
    XGameStreamingClientId client,
    uint32_t updatedPropertiesCount,
    XGameStreamingClientProperty* updatedProperties)
{
    for (uint32_t i = 0; i < updatedPropertiesCount; ++i)
    {
        switch (updatedProperties[i])
        {
        case XGameStreamingClientProperty::DisplayDetails:
        {
            UpdateResolutionIfNeeded();
            break;
        }

        default:
            // A characteristic we are not tracking - do nothing
            break;
        }
    }
}

// Option 2: Polling.

void Game::Update(DX::StepTimer const& timer)
{
    ...

    gameStreamingClientManager->UpdateResolutionIfNeeded();

    ...
}

void GameStreamingClientManager::UpdateResolutionIfNeeded()
{
    bool changeResolution = false;
    bool useDefaultResolution = true;

    // Only use custom resolution when there is only one streaming client connected.
    if (XGameStreamingGetClientCount() == 1)
    {
        XGameStreamingClientId client;
        uint32_t clientsUsed = 0;
        HRESULT hr = XGameStreamingGetClients(1, &client, &clientsUsed);
        if (SUCCEEDED(hr) && clientsUsed == 1)
        {
            XGameStreamingDisplayDetails displayDetails = {};
            hr = XGameStreamingGetDisplayDetails(client, DEFAULT_GAME_WIDTH * DEFAULT_GAME_HEIGHT, GAME_WIDEST_SUPPORTED_ASPECT_RATIO, GAME_TALLEST_SUPPORTED_ASPECT_RATIO, &displayDetails);

            if (SUCCEEDED(hr))
            {
                useDefaultResolution = false;

                // Assuming the game supports all resolutions, use the stream resolution to the preferred dimensions as provided.
                if (s_currentStreamWidth != displayDetails.preferredWidth || s_currentStreamHeight != displayDetails.preferredHeight)
                {
                    changeResolution = true;
                    s_currentStreamWidth = displayDetails.preferredWidth;
                    s_currentStreamHeight = displayDetails.preferredHeight;
                }
            }
            else
            {
                LogFormat(L"XGameStreamingGetDisplayDetails failed %x", hr);
            }
        }
        else
        {
            LogFormat(L"XGameStreamingGetClients failed hr=%x clientsUsed=%d", hr, clientsUsed);
        }
    }

    if (useDefaultResolution)
    {
        if (s_currentStreamWidth != DEFAULT_GAME_WIDTH || s_currentStreamHeight != DEFAULT_GAME_HEIGHT)
        {
            changeResolution = true;
            s_currentStreamWidth = DEFAULT_GAME_WIDTH;
            s_currentStreamHeight = DEFAULT_GAME_HEIGHT;
        }
    }

    if (changeResolution)
    {
        // Update the stream to the new resolution.
        HRESULT hr = XGameStreamingSetResolution(s_currentStreamWidth, s_currentStreamHeight);
        if (SUCCEEDED(hr))
        {
            // Update the game to render at the new resolution.
        }
        else
        {
            LogFormat(L"XGameStreamingSetResolution failed %x", hr);
        }
    }
}

```

## Requisitos

**Encabezado:** xgamestreaming.h\
**Biblioteca:** xgameruntime.lib\
**Plataformas compatibles:** Windows, consolas de la familia XBOX One y consolas XBOX Series

## Consulte también

[XGameStreaming](/reference/system/xgamestreaming/xgamestreaming_members)\
[XGameStreamingDisplayDetails](/reference/system/xgamestreaming/structs/xgamestreamingdisplaydetails)\
[XGameStreamingGetDisplayDetails](/reference/system/xgamestreaming/functions/xgamestreaminggetdisplaydetails)\
[Información general sobre resolución personalizada](/build/core-features/common/game-streaming/game-streaming-custom-resolution-overview)
