Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
joaoantoniocardoso committed Jul 18, 2024
1 parent 465a8ce commit 16ee51a
Showing 1 changed file with 57 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ fn get_loopback_device() -> Result<VideoSourceType> {

false
})
.unwrap()
.expect("No v4l2loopback device found.")
.to_owned();

Ok(loopback_device)
Expand All @@ -65,6 +65,12 @@ impl V4l2LoopBack {
unreachable!();
};

let endpoint = video_and_stream_information
.stream_information
.endpoints
.first()
.unwrap();

let pipeline_description = match configuration.encode {
VideoEncodeType::H264 => format!(
concat!(
Expand Down Expand Up @@ -113,6 +119,7 @@ impl V4l2LoopBack {
),
_ => unimplemented!(),
};

dbg!(&pipeline_description);

let pipeline = gst::parse::launch(&pipeline_description)?
Expand Down Expand Up @@ -163,10 +170,18 @@ impl QrTimeStampSink {
let address = endpoint.host_str().unwrap();
let port = endpoint.port().unwrap();

let source_description = match endpoint.scheme().to_lowercase().as_str() {
"udp" => format!("udpsrc address={address} port={port} do-timestamp=true"),
"rtsp" => {
format!("rtspsrc location={endpoint} is-live=true latency=0")
}
_ => unimplemented!(),
};

let pipeline_description = match configuration.encode {
VideoEncodeType::H264 => format!(
concat!(
"udpsrc do-timestamp=true address={address} port={port}",
"{source_description}",
" ! application/x-rtp,payload=96",
" ! rtph264depay",
" ! h264parse",
Expand All @@ -175,16 +190,15 @@ impl QrTimeStampSink {
" ! videoconvert",
" ! qrtimestampsink name=qrsink",
),
address = address,
port = port,
source_description = source_description,
width = configuration.width,
height = configuration.height,
framerate_num = configuration.frame_interval.denominator,
framerate_den = configuration.frame_interval.numerator,
),
VideoEncodeType::Mjpg => format!(
concat!(
"udpsrc do-timestamp=true address={address} port={port}",
"{source_description}",
" ! application/x-rtp,payload=96",
" ! rtpjpegdepay",
" ! jpegparse",
Expand All @@ -193,8 +207,7 @@ impl QrTimeStampSink {
" ! videoconvert",
" ! qrtimestampsink name=qrsink",
),
address = address,
port = port,
source_description = source_description,
width = configuration.width,
height = configuration.height,
// For some reason, rtpjpegpay is making the framerate to be 0/1
Expand All @@ -205,7 +218,7 @@ impl QrTimeStampSink {
),
VideoEncodeType::Yuyv => format!(
concat!(
"udpsrc do-timestamp=true address={address} port={port}",
"{source_description}",
" ! capsfilter caps=\"application/x-rtp, media=(string)video, clock-rate=(int)90000, encoding-name=(string)RAW, sampling=(string)YCbCr-4:2:0, depth=(string)8, width=(string)320, height=(string)320, colorimetry=(string)BT601-5, payload=(int)96, a-framerate=(string)30\"",
" ! rtpvrawdepay",
" ! videorate skip-to-first=true silent=true",
Expand All @@ -214,8 +227,7 @@ impl QrTimeStampSink {
" ! videoconvert",
" ! qrtimestampsink name=qrsink",
),
address = address,
port = port,
source_description = source_description,
width = configuration.width,
height = configuration.height,
framerate_num = configuration.frame_interval.denominator,
Expand Down Expand Up @@ -414,9 +426,6 @@ async fn get_latencies(
// Cleanup
debug!("Setting qrtimestamp to Null...");
pipeline.set_state(gst::State::Null).unwrap();
while pipeline.current_state() != gst::State::Null {
std::thread::sleep(std::time::Duration::from_millis(10));
}

Ok(Latencies::new(
latencies
Expand Down Expand Up @@ -544,22 +553,34 @@ async fn main() {
let width = 320;
let height = width;
let address = "127.0.0.1";
let port = 5600;
let buffers = 100;

let test_cases = [
(VideoEncodeType::H264, "udp", 4.),
(VideoEncodeType::Mjpg, "udp", 4.),
(VideoEncodeType::Yuyv, "udp", 8.),
(VideoEncodeType::H264, format!("udp://{address}:5600"), 5.),
(VideoEncodeType::Mjpg, format!("udp://{address}:5600"), 5.),
(VideoEncodeType::Yuyv, format!("udp://{address}:5600"), 8.),
(
VideoEncodeType::H264,
format!("rtsp://{address}:8554/test"),
80.,
),
// (
// VideoEncodeType::Mjpg,
// format!("rtsp://{address}:8554/test"),
// 80.,
// ),
// (
// VideoEncodeType::Yuyv,
// format!("rtsp://{address}:8554/test"),
// 80.,
// ),
];

for (encode, scheme, expected_pipeline_latency) in test_cases {
for (encode, endpoint, expected_pipeline_latency) in test_cases {
let video_and_stream_information = VideoAndStreamInformation {
name: "QRTimeStamp - QR".to_string(),
stream_information: StreamInformation {
endpoints: vec![
Url::from_str(format!("{scheme}://{address}:{port}").as_str()).unwrap(),
],
endpoints: vec![Url::from_str(endpoint.as_str()).unwrap()],
configuration: CaptureConfiguration::Video(VideoCaptureConfiguration {
encode,
height,
Expand All @@ -578,6 +599,17 @@ async fn main() {
};
info!("Testing for: {video_and_stream_information:#?}");

info!("Building v4lloopback pipeline (video generation with qrtimestampsrc)...");
let loopback = V4l2LoopBack::try_new(&video_and_stream_information).unwrap();
start_pipeline(&loopback.pipeline, true).await.unwrap();

info!("Building MCM stream...");
let stream = Stream::try_new(&video_and_stream_information)
.await
.unwrap();
let stream_id = stream.id().await.unwrap();
stream::manager::Manager::add_stream(stream).await.unwrap();

info!("Getting baseline latency...");
let baseline_latencies =
compute_baseline_latency(&video_and_stream_information, buffers).await;
Expand All @@ -586,25 +618,15 @@ async fn main() {
info!("Baseline latency: {:#?}", &baseline_latencies.stats);

info!("Building qrtimestamp pipeline (video receiver with qrtimestampsink)...");
let qrtimestamp = QrTimeStampSink::try_new(&video_and_stream_information, buffers)
let qrtimestampsink = QrTimeStampSink::try_new(&video_and_stream_information, buffers)
.await
.unwrap();
start_pipeline(&qrtimestamp.pipeline, false).await.unwrap();

info!("Building v4lloopback pipeline (video generation with qrtimestampsrc)...");
let loopback = V4l2LoopBack::try_new(&video_and_stream_information).unwrap();
start_pipeline(&loopback.pipeline, true).await.unwrap();

info!("Building MCM stream...");
let stream = Stream::try_new(&video_and_stream_information)
start_pipeline(&qrtimestampsink.pipeline, false)
.await
.unwrap();
let stream_id = stream.id().await.unwrap();
stream::manager::Manager::add_stream(stream).await.unwrap();

info!("Waiting for qrtimestamp pipeline to finish...");
let latencies_result = qrtimestamp.get_latencies().await;
tokio::time::sleep(tokio::time::Duration::from_secs(1)).await;
info!("Waiting for qrtimestampsink pipeline to finish...");
let latencies_result = qrtimestampsink.get_latencies().await;

info!("Finishing loopback pipeline...");
let loopback_result = loopback.finish().await;
Expand Down

0 comments on commit 16ee51a

Please sign in to comment.