syntax = "proto3";

package livekit;

import "livekit_models.proto";

option go_package = "github.com/livekit/protocol/livekit";
option csharp_namespace = "LiveKit.Proto";
option ruby_package = "LiveKit::Proto";

service Ingress {
    // Create a new Ingress
    rpc CreateIngress(CreateIngressRequest) returns (IngressInfo);
    // Update an existing Ingress. Ingress can only be updated when it's in ENDPOINT_WAITING state.
    rpc UpdateIngress(UpdateIngressRequest) returns (IngressInfo);
    rpc ListIngress(ListIngressRequest) returns (ListIngressResponse);
    rpc DeleteIngress(DeleteIngressRequest) returns (IngressInfo);
}

message CreateIngressRequest {
    IngressInput input_type = 1;
    // User provided identifier for the ingress
    string name = 2;
    // room to publish to
    string room_name = 3;
    // publish as participant
    string participant_identity = 4;
    // name of publishing participant (used for display only)
    string participant_name = 5;
    IngressAudioOptions audio = 6;
    IngressVideoOptions video = 7;
}

enum IngressInput {
    RTMP_INPUT = 0;
    //    FILE_INPUT = 1;
    //    SRT_INPUT = 2;
    //    URL_INPUT = 3;
}

message IngressAudioOptions {
    string name = 1;
    TrackSource source = 2;
    // desired mime_type to publish to room
    string mime_type = 3;
    uint32 bitrate = 4;
    bool disable_dtx = 5;
    uint32 channels = 6;
}

message IngressVideoOptions {
    string name = 1;
    TrackSource source = 2;
    // desired mime_type to publish to room
    string mime_type = 3;
    // simulcast layers to publish, when empty, it'll pick default simulcast
    // layers at 1/2 and 1/4 of the dimensions
    repeated VideoLayer layers = 4;
}

message IngressInfo {
    string ingress_id = 1;
    string name = 2;
    string stream_key = 3;
    string url = 4;
    // for RTMP input, it'll be a rtmp:// URL
    // for FILE input, it'll be a http:// URL
    // for SRT input, it'll be a srt:// URL
    IngressInput input_type = 5;
    IngressAudioOptions audio = 6;
    IngressVideoOptions video = 7;
    string room_name = 8;
    string participant_identity = 9;
    string participant_name = 10;
    bool reusable = 11;
    IngressState state = 12; // Description of error/stream non compliance and debug info for publisher otherwise (received bitrate, resolution, bandwidth)

    // NEXT_ID: 13
}

message IngressState {
    enum Status {
        ENDPOINT_INACTIVE = 0;
        ENDPOINT_BUFFERING = 1;
        ENDPOINT_PUBLISHING = 2;
        ENDPOINT_ERROR = 3;
    }

    Status status = 1;
    string error = 2; // Error/non compliance description if any
    InputVideoState video = 3;
    InputAudioState audio = 4;
    string room_id = 5; // ID of the current/previous room published to
    int64 started_at = 7;
    repeated TrackInfo tracks = 6;
}

message InputVideoState {
    uint32 mime_type = 1;
//  uint32 bitrate = 2;
    uint32 width = 3;
    uint32 height = 4;
    uint32 framerate = 5;
}

message InputAudioState {
    uint32 mime_type = 1;
//  uint32 bitrate = 2;
    uint32 channels = 3;
    uint32 sample_rate = 4;
}

message UpdateIngressRequest {
    string ingress_id = 1;
    string name = 2;
    string room_name = 3;
    string participant_identity = 4;
    string participant_name = 5;
    IngressAudioOptions audio = 6;
    IngressVideoOptions video = 7;
}

message ListIngressRequest {
    // when blank, lists all ingress endpoints
    string room_name = 1;
}

message ListIngressResponse {
    repeated IngressInfo items = 1;
}

message DeleteIngressRequest {
    string ingress_id = 1;
}
