Commit Graph

29 Commits

Author SHA1 Message Date
Scott Lamb
b1e1fa9031 codec::Parameters -> codec::ParametersRef
This reduces copying. Part of #47.
2022-05-11 11:37:09 -07:00
Scott Lamb
56fde0d71b remove Bytes from public codec API
Part of #47

The main benefit is that `VideoFrame::into_data` can cheaply return a
`Vec<u8>` that the caller can mutate. In particular, they could convert
H.264 data from Annex B to AVC form or skip non-VCL NALs. Neither of
these transformations add bytes so they're both possible without
allocation.

Audio and message frames still use `Bytes` internally, as that allows
them to avoid copying when the frame is wholly contained in a packet.
I think this is much more common than for video. I didn't add an
`AudioFrame::into_data` or `VideoFrame::into_data`.
2022-05-11 10:43:58 -07:00
Scott Lamb
27c5ed5f04 expose RTCP compound packets
...and rename `PacketItem` variants to `Rtp` and `Rtcp` for brevity.

Fixes #59
2022-05-10 15:58:54 -07:00
Scott Lamb
06d7150989 fix inverted condition in mp4 bug
This caused it to say every video frame had new parameters.
2022-05-10 15:58:54 -07:00
Scott Lamb
a5e198b0cf use accessors for fields in Stream
* and take advantage of it to use `Box<str>` rather than `String`
  in a couple places (saving a couple words)
* also rename clock_rate to clock_rate_hz for clarity
2022-04-30 12:26:27 -07:00
Scott Lamb
2bbc847754 replace new_parameters with has_new_parameters
As described in #47
2022-04-30 12:08:01 -07:00
Scott Lamb
efc02236d5 use accessors for most codec fields for #47
I left alone `VideoFrame::new_parameters`, as I'll likely eliminate it
as described in #47.
2022-04-30 11:40:28 -07:00
Scott Lamb
1646142322 take transport options at setup time 2022-04-28 16:13:05 -07:00
Scott Lamb
1bbaf29dc9 setup should take a SetupOptions 2022-04-28 15:16:39 -07:00
Scott Lamb
c887998636 mp4 example: mid-stream video param changes
https://github.com/scottlamb/moonfire-nvr/issues/217
2022-04-11 21:47:46 -07:00
Scott Lamb
499d658352 mp4 example: allow in-band h264 params
Fixes #43
2022-01-30 21:18:47 -08:00
Scott Lamb
cd841b9f80 better error when no streams are selected
Fixes #41
2021-11-29 09:51:27 -08:00
Scott Lamb
0ddb1423c6 mp4 example: avoid panic with non-aac audio 2021-09-10 13:45:50 -07:00
Scott Lamb
1a72fce4de refine TEARDOWN logic
*   by default send a TEARDOWN even if we haven't sent a PLAY.
*   make the behavior more customizable. I want the ability to turn
    teardowns off for testing the live555 bug.
*   deprecate the older teardown method
2021-09-09 21:10:58 -07:00
Scott Lamb
62f6949873 new more reliable TEARDOWN mechanism 2021-09-09 17:34:49 -07:00
Scott Lamb
7141b8601b improve mp4 example error handling
* avoid half-written output (fixes #32)
* try to send TEARDOWN even on error while reading the stream.
  This isn't perfect as noted in the TODO. I think I'll want to
  change the API a bit, but not right now.
2021-09-08 13:25:08 -07:00
Scott Lamb
69f12bde8e cargo fmt 2021-09-07 19:37:33 -07:00
Scott Lamb
6f88161943 mp4 example: more verbose errors 2021-09-07 19:25:40 -07:00
Scott Lamb
60a253073c get rid of ignore_spurious_data
This was an attempt at #17 that didn't work out. Besides additionally
hitting the framing error, my Reolink test camera never timed out
the old session while the new one was in progress. This behavior is
different than the vanilla 2013.04.06 live555 server, so apparently
Reolink sprinkled in their own brokenness on top. In any case,
the other solutions described in that bug are more likely to work.

There's one narrow case I want to keep working: ignoring RTCP messages
immediately prior to the PLAY response. More recent Reolink cameras
do this. I just have this behavior on all the time now.
2021-08-31 06:48:23 -07:00
Scott Lamb
9e9366f115 experimental UDP support (fixes #30)
* support setting transport to UDP
* breaking change: use new PacketContext rather than RtspMessageContext
  in places where an RTP/RTCP packet is expected, as it can now be over
  UDP instead of via RTSP interleaved data
* send teardown, which is important with UDP sessions. (It also will
  help somewhat with Reolink TCP.) Along the way, make Session Unpin
  so that teardown can consume it without tripping over tokio::pin!().
* refactor to shrink the amount of data used by Session and how much
  gets memmoved around on the stack, instead of further growing it.

Because of missing RTCP RR and reorder buffer support, this is only
appropriate for using on a LAN. That's enough for me right now.
2021-08-30 21:40:51 -07:00
Scott Lamb
c9a1ec1912 mp4 --duration=secs (fixes #28)
also briefly document commandline options
2021-08-26 14:39:01 -07:00
Scott Lamb
4e52e7b19a mp4 example: option to allow packet loss 2021-08-22 08:08:09 -07:00
Scott Lamb
76b3a61eb7 mp4 example: fix panic on empty video
```
thread 'main' panicked at 'range start index 1 out of range for slice of length 0', examples/client/mp4.rs:171:44
stack backtrace:
   0: rust_begin_unwind
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:515:5
   1: core::panicking::panic_fmt
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/panicking.rs:92:14
   2: core::slice::index::slice_start_index_len_fail
             at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/slice/index.rs:34:5
   3: client::mp4::TrakTracker::write_common_stbl_parts
   4: client::mp4::Mp4Writer<W>::write_audio_trak
   5: client::mp4::run::{{closure}}
   6: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
   7: tokio::park:🧵:CachedParkThread::block_on
   8: tokio::runtime::thread_pool::ThreadPool::block_on
   9: tokio::runtime::Runtime::block_on
  10: client::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
```
2021-08-20 10:11:53 -07:00
Scott Lamb
d8aa4c6565 workaround for Reolink spurious data
Fixes #17

I'm accumulating unit testing debt, but I think I'd rather get this
quickly out in the field to test against scenarios I haven't anticipated
than get my unit tests in order for scenarios I have anticiapted.
2021-08-19 13:00:06 -07:00
Scott Lamb
41765007a6 remove rtcp dependency, prep v0.1.0
rtcp recently had an accidental semver break, so this fixes #8.
I also don't like that newer versions depend on several unnecessary
crates including tokio. retina also depends on tokio, but in the future
I want it to be IO library-agnostic.

I'm moving to v0.1.0 so I *can* release versions that claim semver
compatibility. There are still plenty of API changes to make but also
likely upcoming camera compatibility changes that won't break anything.
2021-08-13 11:37:53 -07:00
Scott Lamb
df47b6fa35 mp4 example: handle initial video param change
I've noticed some (buggy) cameras' out-of-band parameters don't quite
match the initial in-band parameters. Out-of-band parameters aren't
required anyway, and this is progress toward handling in-band only.
2021-07-08 15:19:38 -07:00
Scott Lamb
e9a5e4e34a overhaul error type
*   stop using deprecated failure crate and its deps

*   more uniformly detailed error messages

*   an enum of the type of error, currently internal-only. I'm not
    confident enough I understand what cases a caller might want to
    distinguish, so I added a comment inviting input instead of
    exposing it now.

*   while I'm at it, separate connection context and message contexts.
    This shrinks some of the data memmoved around in PacketItem and
    CodecItem.
2021-07-08 11:28:07 -07:00
Scott Lamb
af7e8a77fb refactor h264 depacketizer
* add a couple tests

* fix #4: put the whole video frame (including multiple NALs) into
  a single Bytes. This is simpler to use and speeds up the
  depacketize/h264_aac_writevideo benchmark. It's also a behavior
  change; now I include non-VUI data such as SPS/PPS/SEI into the
  data. I think this is a better default but it might be worth
  making customizable.
2021-06-24 22:18:39 -07:00
Scott Lamb
5cc69e751c initial commit 2021-06-03 16:49:53 -07:00