// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Protocol for audio messages.

syntax = "proto2";

option optimize_for = LITE_RUNTIME;

package media.cast.proto;

// Keep in sync with media/cast/logging/logging_defines.h.
// For compatibility reasons, existing values in this enum must not be changed.
enum EventType {
  UNKNOWN = 0;
  
  // Note: 1-28 are deprecated in favor of unified event types. Do not use.
  // Generic events. No longer used.
  RTT_MS = 1;
  PACKET_LOSS = 2;
  JITTER_MS = 3;
  VIDEO_ACK_RECEIVED = 4;  // Sender side frame event.
  REMB_BITRATE = 5;        // Generic event. No longer used.
  // Audio receiver.
  AUDIO_ACK_SENT = 6;
  // Video receiver.
  VIDEO_ACK_SENT = 7;
  // Audio sender.
  AUDIO_FRAME_CAPTURE_END = 8;
  AUDIO_FRAME_CAPTURE_BEGIN = 9;
  AUDIO_FRAME_ENCODED = 10;
  // Audio receiver.
  AUDIO_PLAYOUT_DELAY = 11;
  AUDIO_FRAME_DECODED = 12;
  // Video sender.
  VIDEO_FRAME_CAPTURE_BEGIN = 13;
  VIDEO_FRAME_CAPTURE_END = 14;
  VIDEO_FRAME_SENT_TO_ENCODER = 15;  // Deprecated
  VIDEO_FRAME_ENCODED = 16;
  // Video receiver.
  VIDEO_FRAME_DECODED = 17;
  VIDEO_RENDER_DELAY = 18;
  // Send-side packet events.
  // AUDIO_PACKET_SENT_TO_PACER = 19;  // Deprecated
  // VIDEO_PACKET_SENT_TO_PACER = 20;  // Deprecated
  AUDIO_PACKET_SENT_TO_NETWORK = 21;
  VIDEO_PACKET_SENT_TO_NETWORK = 22;
  AUDIO_PACKET_RETRANSMITTED = 23;
  VIDEO_PACKET_RETRANSMITTED = 24;
  // Receiver-side packet events.
  AUDIO_PACKET_RECEIVED = 25;
  VIDEO_PACKET_RECEIVED = 26;
  DUPLICATE_AUDIO_PACKET_RECEIVED = 27;
  DUPLICATE_VIDEO_PACKET_RECEIVED = 28;
  
  
  // New, unified event types.
  FRAME_CAPTURE_BEGIN = 29;
  FRAME_CAPTURE_END = 30;
  FRAME_ENCODED = 31;
  FRAME_ACK_RECEIVED = 32;
  FRAME_ACK_SENT = 33;
  FRAME_DECODED = 34;
  FRAME_PLAYOUT = 35;
  PACKET_SENT_TO_NETWORK = 36;
  PACKET_RETRANSMITTED = 37;
  PACKET_RECEIVED = 38;
  PACKET_RTX_REJECTED = 39;
}

// Contains information independent of the stream that describes the system
// setup, e.g. OS and hardware info.
message GeneralDescription {
  optional string product = 1;
  optional string product_version = 2;
  optional string os = 3;
}

// Each log will contain one |LogMetadata|.
message LogMetadata {
  // |true| if the events are related to audio. |false| if they are related to
  // video.
  optional bool is_audio = 1;

  // Used as a reference for all event entries.
  // i.e. the original RTP timestamp for each event will be
  // |first_rtp_timestamp| + |relative_rtp_timestamp|.
  optional uint32 first_rtp_timestamp = 2;

  // Number of AggregatedFrameEvent's.
  optional int32 num_frame_events = 3;

  // Number of AggregatedPacketEvent's.
  optional int32 num_packet_events = 4;

  // The internal timestamp value in milliseconds that represents the time
  // of the Unix epoch. This is used for relating the timestamps in the events
  // to a real time and date.
  optional int64 reference_timestamp_ms_at_unix_epoch = 5;

  // Extra data to attach to the log, e.g. experiment tags,
  // in key-value JSON string format. The data is supplied by the application.
  optional string extra_data = 6;

  optional GeneralDescription general_description = 7;
}

message AggregatedFrameEvent {
  optional uint32 relative_rtp_timestamp = 1;

  repeated EventType event_type = 2 [packed = true];
  
  // The internal timestamp value in milliseconds. Use
  // LogMetadata.reference_timestamp_ms_at_unix_epoch to relate to a real time
  // and date.
  repeated int64 event_timestamp_ms = 3 [packed = true];

  // Only set if there is a frame encoded event.
  optional int32 encoded_frame_size = 4;

  // Only set if there is a frame playout event.
  optional int32 delay_millis = 5;

  // Only set if there is a video frame encoded event.
  optional bool key_frame = 6;
  
  // Only set if there is a video frame encoded event.
  optional int32 target_bitrate = 7;
};

message BasePacketEvent {
  optional int32 packet_id = 1;
  repeated EventType event_type = 2 [packed = true];
  
  // The internal timestamp value in milliseconds. Use
  // LogMetadata.reference_timestamp_ms_at_unix_epoch to relate to a real time
  // and date.
  repeated int64 event_timestamp_ms = 3 [packed = true];

  // Size of the packet.
  optional int32 size = 4;
}

message AggregatedPacketEvent {
  optional uint32 relative_rtp_timestamp = 1;
  repeated BasePacketEvent base_packet_event = 2;
};