1 // Copyright 2014 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CAST_STREAMING_ENCODED_FRAME_H_ 6 #define CAST_STREAMING_ENCODED_FRAME_H_ 7 8 #include <stdint.h> 9 10 #include <chrono> 11 #include <vector> 12 13 #include "absl/types/span.h" 14 #include "cast/streaming/frame_id.h" 15 #include "cast/streaming/rtp_time.h" 16 #include "platform/api/time.h" 17 #include "platform/base/macros.h" 18 19 namespace openscreen { 20 namespace cast { 21 22 // A combination of metadata and data for one encoded frame. This can contain 23 // audio data or video data or other. 24 struct EncodedFrame { 25 enum Dependency : int8_t { 26 // "null" value, used to indicate whether |dependency| has been set. 27 UNKNOWN_DEPENDENCY, 28 29 // Not decodable without the reference frame indicated by 30 // |referenced_frame_id|. 31 DEPENDS_ON_ANOTHER, 32 33 // Independently decodable. 34 INDEPENDENTLY_DECODABLE, 35 36 // Independently decodable, and no future frames will depend on any frames 37 // before this one. 38 KEY_FRAME, 39 }; 40 41 EncodedFrame(); 42 ~EncodedFrame(); 43 44 EncodedFrame(EncodedFrame&&) noexcept; 45 EncodedFrame& operator=(EncodedFrame&&); 46 47 // Copies all members except |data| to |dest|. Does not modify |dest->data|. 48 void CopyMetadataTo(EncodedFrame* dest) const; 49 50 // This frame's dependency relationship with respect to other frames. 51 Dependency dependency = UNKNOWN_DEPENDENCY; 52 53 // The label associated with this frame. Implies an ordering relative to 54 // other frames in the same stream. 55 FrameId frame_id; 56 57 // The label associated with the frame upon which this frame depends. If 58 // this frame does not require any other frame in order to become decodable 59 // (e.g., key frames), |referenced_frame_id| must equal |frame_id|. 60 FrameId referenced_frame_id; 61 62 // The stream timestamp, on the timeline of the signal data. For example, RTP 63 // timestamps for audio are usually defined as the total number of audio 64 // samples encoded in all prior frames. A playback system uses this value to 65 // detect gaps in the stream, and otherwise stretch the signal to gradually 66 // re-align towards playout targets when too much drift has occurred (see 67 // |reference_time|, below). 68 RtpTimeTicks rtp_timestamp; 69 70 // The common reference clock timestamp for this frame. Over a sequence of 71 // frames, this time value is expected to drift with respect to the elapsed 72 // time implied by the RTP timestamps; and this may not necessarily increment 73 // with precise regularity. 74 // 75 // This value originates from a sender, and is the time at which the frame was 76 // captured/recorded. In the receiver context, this value is the computed 77 // target playout time, which is used for guiding the timing of presentation 78 // (see |rtp_timestamp|, above). It is also meant to be used to synchronize 79 // the presentation of multiple streams (e.g., audio and video), commonly 80 // known as "lip-sync." It is NOT meant to be a mandatory/exact playout time. 81 Clock::time_point reference_time; 82 83 // Playout delay for this and all future frames. Used by the Adaptive 84 // Playout delay extension. Non-positive values means no change. 85 std::chrono::milliseconds new_playout_delay{}; 86 87 // Pointer to a buffer containing the encoded signal data for the frame. In 88 // the sender context, this points to the data to be sent, and nothing will be 89 // mutated. In the receiver context, this is set to the region of a 90 // client-provided buffer that was populated. 91 absl::Span<uint8_t> data; 92 93 OSP_DISALLOW_COPY_AND_ASSIGN(EncodedFrame); 94 }; 95 96 } // namespace cast 97 } // namespace openscreen 98 99 #endif // CAST_STREAMING_ENCODED_FRAME_H_ 100