Commit Graph

240 Commits

Author SHA1 Message Date
Shehriyar Qureshi
a2c24b0e94 Revert "feat(h264): handle annex b boundary b/w pkts"
This reverts commit 67c0070324.
2023-01-28 20:04:29 +05:00
Shehriyar Qureshi
728c6fc562 Revert "refactor(h264): add assert statements"
This reverts commit 7753c8966b.
2023-01-28 20:04:17 +05:00
Shehriyar Qureshi
d625e1d2f8 Revert "refactor(h264): replace unwrap with expects"
This reverts commit 41d0ae4628.
2023-01-28 20:04:07 +05:00
Shehriyar Qureshi
41d0ae4628 refactor(h264): replace unwrap with expects 2023-01-17 09:07:35 +05:00
Shehriyar Qureshi
7753c8966b refactor(h264): add assert statements 2023-01-17 09:07:35 +05:00
Shehriyar Qureshi
67c0070324 feat(h264): handle annex b boundary b/w pkts
If an Annex B boundary cuts off b/w pkts, `break_apart_nals` will handle
and split up nals just as if the boundary was inside single packet
2023-01-17 09:07:35 +05:00
Shehriyar Qureshi
1e1b40dd1f chore(h264): add comment to inform feature todo 2023-01-17 09:07:35 +05:00
Shehriyar Qureshi
c9057c9151 refactor(h264): redundant_slicing 2023-01-17 09:07:35 +05:00
Shehriyar Qureshi
096cd318e4 fix(h264): clippy op_ref
clippy warned that we don't need to take reference
2023-01-17 09:07:35 +05:00
Shehriyar Qureshi
27d85c0c7f chore(h264): comment to explain boundary split
if Annex B boundary cuts off b/w packets, explain how it'll be handled
2023-01-17 09:07:35 +05:00
Shehriyar Qureshi
2a776bfcf6 chore(gitignore): add out.mp4 2023-01-17 09:07:35 +05:00
Shehriyar Qureshi
e005a8a9e2 fix(h264): do not store boundary state in struct
boundary state is currently only used inside function body.

Removed it from struct because it isn't needed outside the function
2023-01-17 09:07:35 +05:00
Shehriyar Qureshi
231f56b504 fix(h264): do not store zero state
Annex B reader was storing indices of zeros when finding
boundaries.

Remove them from struct and rely handle this state inside function
2023-01-17 09:07:35 +05:00
Shehriyar Qureshi
d610fb5846 fix(h264): move annex b splitter into append
start_rtp_nal will now only create a new nal, and append_rtp_nal will be
responsible for appending data as well as splitting Annex B streams
2023-01-17 09:07:35 +05:00
Shehriyar Qureshi
bff6d32f47 refactor(h264): use bool for boundary tracking
instead of storing the index of zeros in NalParser, use bools to
simplify tracking, as we don't really need to use the zero indices
2023-01-17 09:07:35 +05:00
Shehriyar Qureshi
0e383aa7d2 refactor(h264): add docstring for NalParser struct 2023-01-17 09:07:35 +05:00
Shehriyar Qureshi
cda6808dda refactor(h264): replace is_some with variants 2023-01-17 09:07:35 +05:00
Shehriyar Qureshi
42282f1603 feat(h264): match starting headers b/w fu-a
instead of matching the starting header of a fu-a with the last
saved nal, match it with the first header of the starting fu-a

this removes the need to add a flag when an Annex B stream
is sent in FU-As

it will work for both compliant FU-As and for ones with Annex B stream
2023-01-17 09:07:35 +05:00
Shehriyar Qureshi
2972593e52 chore(h264): better error strings in .expect() 2023-01-17 09:07:35 +05:00
Shehriyar Qureshi
52f64719d1 chore(h264): make comment consistent 2023-01-17 09:07:35 +05:00
Shehriyar Qureshi
5a604e0249 refactor(h264): annex b split logic easier on eyes 2023-01-17 09:07:35 +05:00
Shehriyar Qureshi
e521168267 refactor(h264): update comments & rename fields 2023-01-17 09:07:35 +05:00
Shehriyar Qureshi
8bd45c7798 test(h264): add tests for annex b in fu-a 2023-01-17 09:07:35 +05:00
Shehriyar Qureshi
65ab3e899e feat(h264): move boundary bool into nalparser 2023-01-17 09:07:35 +05:00
Shehriyar Qureshi
36b19f0840 feat(h264): add delimiter watcher state in struct
move delimiter watcher state from inside fn to in struct
2023-01-17 09:07:35 +05:00
Shehriyar Qureshi
599006d554 feat(h264): handle annex b stream in FU-A
My v380 cam would send an annex b stream in the first FU-A, with wrong
headers in the middle and end frags for the first FU-A

Two cases are being modified:

a) disable FU-A header check b/w frags

add boolean flag to disable checking for the same header b/w FU-A frags
because the cam's first FU-A was like this:

1) FU-A (start) => SPS header - SPS - PPS header - PPS - IDR header -
   IDR
2) FU-A (...) => SPS header - IDR
3) FU-A (end) => SPS header - IDR

The headers all indicate for SPS, which is wrong, as SPS is defined in
annex b stream in the start packet. For this, we need to ignore the
subsequent headers after first packet, and append incoming data into the
last nal that we saved

b) break apart annex b stream

when adding FU-A, pass it through a fn that checks for delimiters (0x00
0x00 0x00) and breaks the NALs apart
2023-01-17 09:07:35 +05:00
Shehriyar Qureshi
f80577b03c feat(h264): move nal and pieces into own struct
create new struct that holds `nals` and `pieces`

struct owned by Depacketizer, makes it so we have RTP -> NAL logic
be in a separate struct
2023-01-17 09:07:35 +05:00
Scott Lamb
f403aecc50
Merge pull request #75 from scottlamb/release-0.4.4
release 0.4.4
2022-12-26 09:28:46 -05:00
Scott Lamb
6058bd89db
release 0.4.4 2022-12-26 09:21:42 -05:00
Scott Lamb
c27865aedf fix parsing of RTP packets with extensions 2022-12-26 09:19:21 -05:00
Scott Lamb
7472b6300e clippy 2022-12-26 09:19:21 -05:00
Scott Lamb
f69d746a42 Tolerate Ubiquiti's useless a=fmtp:96\r in SDP
See #65
2022-10-20 23:17:26 -07:00
Scott Lamb
021a572145 Address CI failures
I'm not sure what changed. We have a
`Cargo.lock`, and these runs were with identical code:

https://github.com/scottlamb/retina/actions/runs/3148795378 passed
https://github.com/scottlamb/retina/actions/runs/3148801810 failed

Nonetheless, the failures started happening on CI (and not my local
machine). Something changed with respect to the other futures are polled
or something. Not having a keepalive future prevents tokio from
"auto-advancing" the paused time (a misfeature IMHO). There's still
some advance I think from background_teardown's timeout_at, but that's late
enough to not cause the same test failure.

Failure below.

```
---- client::tests::simple stdout ----
thread 'client::tests::simple' panicked at 'assertion failed: `(left == right)`
  left: `Options`,
 right: `Teardown`', src/client/mod.rs:2547:17
stack backtrace:
   0: rust_begin_unwind
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/panicking.rs:584:5
   1: core::panicking::panic_fmt
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/panicking.rs:142:14
error: test failed, to rerun pass '-p retina --lib'
   2: core::panicking::assert_failed_inner
   3: core::panicking::assert_failed
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/panicking.rs:181:5
   4: retina::client::tests::req_response::{{closure}}
             at ./src/client/mod.rs:2547:17
   5: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/future/mod.rs:91:19
   6: <tokio::future::maybe_done::MaybeDone<Fut> as core::future::future::Future>::poll
             at /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/future/maybe_done.rs:68:48
   7: retina::client::tests::simple::{{closure}}::{{closure}}
             at /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/macros/join.rs:116:24
   8: <tokio::future::poll_fn::PollFn<F> as core::future::future::Future>::poll
             at /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/future/poll_fn.rs:38:9
   9: retina::client::tests::simple::{{closure}}
             at ./src/client/mod.rs:2651:9
  10: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/future/mod.rs:91:19
  11: <core::pin::Pin<P> as core::future::future::Future>::poll
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/future/future.rs:124:9
  12: tokio::runtime::basic_scheduler::CoreGuard::block_on::{{closure}}::{{closure}}::{{closure}}
             at /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/basic_scheduler.rs:508:48
  13: tokio::coop::with_budget::{{closure}}
             at /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/coop.rs:102:9
  14: std:🧵:local::LocalKey<T>::try_with
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/thread/local.rs:445:16
  15: std:🧵:local::LocalKey<T>::with
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/std/src/thread/local.rs:421:9
  16: tokio::coop::with_budget
             at /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/coop.rs:95:5
  17: tokio::coop::budget
             at /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/coop.rs:72:5
  18: tokio::runtime::basic_scheduler::CoreGuard::block_on::{{closure}}::{{closure}}
             at /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/basic_scheduler.rs:508:25
  19: tokio::runtime::basic_scheduler::Context::enter
             at /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/basic_scheduler.rs:362:19
  20: tokio::runtime::basic_scheduler::CoreGuard::block_on::{{closure}}
             at /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/basic_scheduler.rs:507:36
  21: tokio::runtime::basic_scheduler::CoreGuard::enter::{{closure}}
             at /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/basic_scheduler.rs:565:57
  22: tokio::macros::scoped_tls::ScopedKey<T>::set
             at /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/macros/scoped_tls.rs:61:9
  23: tokio::runtime::basic_scheduler::CoreGuard::enter
             at /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/basic_scheduler.rs:565:27
  24: tokio::runtime::basic_scheduler::CoreGuard::block_on
             at /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/basic_scheduler.rs:498:9
  25: tokio::runtime::basic_scheduler::BasicScheduler::block_on
             at /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/basic_scheduler.rs:174:24
  26: tokio::runtime::Runtime::block_on
             at /home/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.19.2/src/runtime/mod.rs:480:46
  27: retina::client::tests::simple
             at ./src/client/mod.rs:2664:9
  28: retina::client::tests::simple::{{closure}}
             at ./src/client/mod.rs:2561:11
  29: core::ops::function::FnOnce::call_once
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/ops/function.rs:248:5
  30: core::ops::function::FnOnce::call_once
             at /rustc/a55dd71d5fb0ec5a6a3a9e8c27b2127ba491ce52/library/core/src/ops/function.rs:248:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
```
2022-10-20 23:09:45 -07:00
Scott Lamb
b54ea3f4fd v0.4.3: upgrade h264-reader crate
* match a couple h264-reader semantic changes. E.g., decode_nal now
  expects the full NALU including header byte.

* adjust test data in depacketize_parameter_change. The SDP parameters
  I used were invalid in a way caught only by the new h264-reader crate.
  That's not the intended scenario, so use different parameters. But
  mention the accidental scenario in CHANGELOG.md.

* initialize logging in h264 tests to ease debugging problems like the
  bullet above.

* in AAC code, match h264-reader's switch from bitreader to
  bitstream-io. This keeps dependencies down, in addition to the reasons
  for h264-reader's switch, described here:
  7a02a3b7bd
2022-09-28 22:12:17 -07:00
Scott Lamb
67a6812379 fix clippy errors
These must have popped up with a new version of Rust since last commits.
2022-09-28 09:12:28 -07:00
Scott Lamb
bc03c61ae3 ignore unparseable SDP media
https://github.com/scottlamb/moonfire-nvr/issues/238
2022-09-28 09:12:28 -07:00
Scott Lamb
d6c0e84db8 prep v0.4.1 2022-08-09 07:40:46 -07:00
Scott Lamb
65c7cf8c5f cargo fmt 2022-08-09 06:37:14 -07:00
Scott Lamb
26a7e86076 add debug logs on conn error/eof
The caller gets this information and may do its own logging with more
context. But...sometimes the caller doesn't, and being able to turn
this on is handy then, so log at low priority. (debug; I considered
trace even.)
2022-08-09 06:31:45 -07:00
Scott Lamb
0d6784485b use keepalive compatible with simple-rtsp-server
https://github.com/scottlamb/moonfire-nvr/issues/234
2022-08-07 22:02:26 -07:00
Scott Lamb
da33dddbd7 compute keepalive interval from session timeout
Alessandro Ros
[asserts](https://github.com/aler9/rtsp-simple-server/issues/1066#issuecomment-1206405770)
that some servers have timeouts shorter than 30 seconds; this should
improve compatibility with them. Also add some debug logging around
keepalives.
2022-08-07 11:01:06 -07:00
Scott Lamb
bb3baf0329 unbreak client example 2022-07-15 16:30:54 -07:00
Scott Lamb
a7942f723f remove local debugging webrtc patches 2022-07-15 16:14:53 -07:00
Scott Lamb
692bfaa04e WebRTC proxy example (#60)
This is a very basic version, as a starting point.
2022-07-15 16:12:26 -07:00
Scott Lamb
fa372865e6 upgrade mylog dep to version without parking_lot 2022-07-13 11:48:30 -07:00
Scott Lamb
3a8f11450f clippy cleanup on client example 2022-07-13 11:44:53 -07:00
Scott Lamb
978d0d7791 fixes for workspace split 2022-07-13 11:17:28 -07:00
Scott Lamb
d75d5585f5 move the client example to its own crate
We're likely to add more examples with more dependencies (e.g. ffmpeg,
gstreamer, webrtc). Nice to not have their deps in the main crate's
dev-dependencies, and likewise to have each example show its true
dependencies.

As mentioned here:
https://github.com/scottlamb/retina/issues/19#issuecomment-902302720
2022-07-13 10:51:03 -07:00
Scott Lamb
33bd057ade update some deps 2022-07-11 11:59:40 -07:00
Scott Lamb
2b700fd32b prepare v0.4.0 2022-05-17 16:48:34 -07:00