1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
//! Media samples and container I/O.
//!
//! The bridge between encoded media and RTP: a codec-agnostic [`Sample`] type, and readers
//! and writers for the container formats the examples and tests use.
//!
//! # Structure
//!
//! * [`Sample`] — one encoded unit of media (a video frame, an audio frame) with its
//! duration, timestamp and packet metadata. Hand these to a sample-based local track and
//! the RTP packetizer does the rest.
//! * [`io`] — the [`Writer`](io::Writer) trait plus concrete readers and writers for IVF
//! (VP8/VP9), Ogg (Opus) and H.264/H.265 Annex B — [`IVFReader`](io::ivf_reader::IVFReader),
//! [`OggReader`](io::ogg_reader::OggReader) and friends — enough to play media from disk or
//! record it to disk. [`SampleBuilder`](io::sample_builder::SampleBuilder) goes the other
//! way, reassembling inbound RTP into [`Sample`]s.
//! * [`audio`], [`video`] — per-codec helpers, including audio buffering and frame
//! inspection.
//!
//! # Example
//!
//! ```
//! use bytes::Bytes;
//! use rtci_media::Sample;
//! use std::time::{Duration, Instant};
//!
//! // The caller supplies the instant; `Sample` resolves no clock of its own.
//! let now = Instant::now();
//!
//! // One encoded frame, ready to hand to a sample-based local track.
//! let sample = Sample {
//! data: Bytes::from_static(&[0u8; 128]),
//! timestamp: now,
//! duration: Duration::from_millis(33), // ~30 fps
//! ..Sample::new(now)
//! };
//! assert_eq!(sample.data.len(), 128);
//! ```
//!
//! Most applications do not depend on this crate directly — the
//! [`rtci`](https://docs.rs/rtc) crate re-exports it as `rtci::media`.
/// Audio sample types and multi-channel buffers.
/// Container readers and writers, plus RTP sample reassembly.
/// Video frame helpers.
use Bytes;
use ;
/// A Sample contains encoded media and timing information