Skip to content

Commit 22be6aa

Browse files
authored
Revert "Add probing a stream (#23)" (#26)
1 parent cc03552 commit 22be6aa

File tree

6 files changed

+14
-259
lines changed

6 files changed

+14
-259
lines changed

go2rtc_client/models.py

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from __future__ import annotations
44

55
from dataclasses import dataclass, field
6-
from typing import Generic, Literal, TypeVar
6+
from typing import Any, Literal
77

88
from awesomeversion import AwesomeVersion
99
from mashumaro import field_options
@@ -19,20 +19,6 @@ def deserialize(self, value: str) -> AwesomeVersion:
1919
return AwesomeVersion(value)
2020

2121

22-
_T = TypeVar("_T")
23-
24-
25-
class _EmptyListInsteadNoneSerializer(SerializationStrategy, Generic[_T]):
26-
def serialize(self, value: list[_T]) -> list[_T]:
27-
return value
28-
29-
def deserialize(self, value: list[_T] | None) -> list[_T]:
30-
if value is None:
31-
return []
32-
33-
return value
34-
35-
3622
@dataclass
3723
class ApplicationInfo(DataClassORJSONMixin):
3824
"""Application info model.
@@ -53,22 +39,26 @@ class Streams(DataClassORJSONMixin):
5339

5440

5541
@dataclass
56-
class Stream(DataClassORJSONMixin):
42+
class Stream:
5743
"""Stream model."""
5844

59-
producers: list[Producer] = field(
60-
metadata=field_options(serialization_strategy=_EmptyListInsteadNoneSerializer())
61-
)
45+
producers: list[Producer]
46+
47+
@classmethod
48+
def __pre_deserialize__(cls, d: dict[Any, Any]) -> dict[Any, Any]:
49+
"""Pre deserialize."""
50+
# Ensure producers is always a list
51+
if "producers" in d and d["producers"] is None:
52+
d["producers"] = []
53+
54+
return d
6255

6356

6457
@dataclass
6558
class Producer:
6659
"""Producer model."""
6760

6861
url: str
69-
medias: list[str] = field(
70-
metadata=field_options(serialization_strategy=_EmptyListInsteadNoneSerializer())
71-
)
7262

7363

7464
@dataclass

go2rtc_client/rest.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -133,19 +133,6 @@ async def list(self) -> dict[str, Stream]:
133133
resp = await self._client.request("GET", self.PATH)
134134
return _GET_STREAMS_DECODER.decode(await resp.json())
135135

136-
@handle_error
137-
async def probe(
138-
self, stream_name: str, *, audio: str | None = None, video: str | None = None
139-
) -> Stream:
140-
"""Probe a stream."""
141-
params = {"src": stream_name}
142-
if audio:
143-
params["audio"] = audio
144-
if video:
145-
params["video"] = video
146-
resp = await self._client.request("GET", self.PATH, params=params)
147-
return Stream.from_dict(await resp.json())
148-
149136

150137
class Go2RtcRestClient:
151138
"""Rest client for go2rtc server."""

tests/__snapshots__/test_rest.ambr

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -9,57 +9,6 @@
99
'version': '1.9.4',
1010
})
1111
# ---
12-
# name: test_probe_success[audio and video][deserialized]
13-
dict({
14-
'producers': list([
15-
dict({
16-
'medias': list([
17-
'video, recvonly, H264',
18-
'audio, recvonly, MPEG4-GENERIC/16000',
19-
'audio, sendonly, PCMU/8000',
20-
]),
21-
'url': 'rtsp://x:[email protected]:554/Preview_01_sub',
22-
}),
23-
]),
24-
})
25-
# ---
26-
# name: test_probe_success[audio and video][serialized]
27-
'{"producers":[{"url":"rtsp://x:[email protected]:554/Preview_01_sub","medias":["video, recvonly, H264","audio, recvonly, MPEG4-GENERIC/16000","audio, sendonly, PCMU/8000"]}]}'
28-
# ---
29-
# name: test_probe_success[audio only][deserialized]
30-
dict({
31-
'producers': list([
32-
dict({
33-
'medias': list([
34-
'video, recvonly, H264',
35-
'audio, recvonly, MPEG4-GENERIC/16000',
36-
'audio, sendonly, PCMU/8000',
37-
]),
38-
'url': 'rtsp://x:[email protected]:554/Preview_01_sub',
39-
}),
40-
]),
41-
})
42-
# ---
43-
# name: test_probe_success[audio only][serialized]
44-
'{"producers":[{"url":"rtsp://x:[email protected]:554/Preview_01_sub","medias":["video, recvonly, H264","audio, recvonly, MPEG4-GENERIC/16000","audio, sendonly, PCMU/8000"]}]}'
45-
# ---
46-
# name: test_probe_success[video only][deserialized]
47-
dict({
48-
'producers': list([
49-
dict({
50-
'medias': list([
51-
'video, recvonly, H264',
52-
'audio, recvonly, MPEG4-GENERIC/16000',
53-
'audio, sendonly, PCMU/8000',
54-
]),
55-
'url': 'rtsp://x:[email protected]:554/Preview_01_sub',
56-
}),
57-
]),
58-
})
59-
# ---
60-
# name: test_probe_success[video only][serialized]
61-
'{"producers":[{"url":"rtsp://x:[email protected]:554/Preview_01_sub","medias":["video, recvonly, H264","audio, recvonly, MPEG4-GENERIC/16000","audio, sendonly, PCMU/8000"]}]}'
62-
# ---
6312
# name: test_streams_get[empty]
6413
dict({
6514
})
@@ -69,10 +18,6 @@
6918
'camera.12mp_fluent': dict({
7019
'producers': list([
7120
dict({
72-
'medias': list([
73-
'video, recvonly, H264',
74-
'audio, recvonly, MPEG4-GENERIC/16000',
75-
]),
7621
'url': 'rtsp://test:[email protected]:554/Preview_06_sub',
7722
}),
7823
]),

tests/fixtures/probe_camera_offline.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/fixtures/probe_success.json

Lines changed: 0 additions & 95 deletions
This file was deleted.

tests/test_rest.py

Lines changed: 2 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
from awesomeversion import AwesomeVersion
1212
import pytest
1313

14-
from go2rtc_client.exceptions import Go2RtcClientError, Go2RtcVersionError
15-
from go2rtc_client.models import Stream, WebRTCSdpOffer
14+
from go2rtc_client.exceptions import Go2RtcVersionError
15+
from go2rtc_client.models import WebRTCSdpOffer
1616
from go2rtc_client.rest import _ApplicationClient, _StreamClient, _WebRTCClient
1717
from tests import load_fixture
1818

@@ -179,74 +179,3 @@ async def test_webrtc_offer(
179179
WebRTCSdpOffer("v=0..."),
180180
)
181181
assert resp == snapshot
182-
183-
184-
async def _test_probe(
185-
responses: aioresponses,
186-
rest_client: Go2RtcRestClient,
187-
filename: str,
188-
status_code: int,
189-
additional_params: dict[str, str],
190-
) -> Stream:
191-
"""Test probing a stream."""
192-
camera = "camera.test"
193-
params = [f"{k}={v}" for k, v in additional_params.items()]
194-
responses.get(
195-
f"{URL}{_StreamClient.PATH}?src={camera}&{'&'.join(params)}",
196-
status=status_code,
197-
body=load_fixture(filename),
198-
)
199-
return await rest_client.streams.probe(camera, **additional_params)
200-
201-
202-
@pytest.mark.parametrize(
203-
"additional_params",
204-
[
205-
{"audio": "all", "video": "all"},
206-
{"audio": "all"},
207-
{"video": "all"},
208-
],
209-
ids=[
210-
"audio and video",
211-
"audio only",
212-
"video only",
213-
],
214-
)
215-
async def test_probe_success(
216-
responses: aioresponses,
217-
rest_client: Go2RtcRestClient,
218-
snapshot: SnapshotAssertion,
219-
additional_params: dict[str, str],
220-
) -> None:
221-
"""Test probing a stream."""
222-
resp = await _test_probe(
223-
responses, rest_client, "probe_success.json", 200, additional_params
224-
)
225-
assert resp == snapshot(name="deserialized")
226-
assert isinstance(resp, Stream)
227-
assert resp.to_json() == snapshot(name="serialized")
228-
229-
230-
@pytest.mark.parametrize(
231-
"additional_params",
232-
[
233-
{"audio": "all", "video": "all"},
234-
{"audio": "all"},
235-
{"video": "all"},
236-
],
237-
ids=[
238-
"audio and video",
239-
"audio only",
240-
"video only",
241-
],
242-
)
243-
async def test_probe_camera_offline(
244-
responses: aioresponses,
245-
rest_client: Go2RtcRestClient,
246-
additional_params: dict[str, str],
247-
) -> None:
248-
"""Test probing a stream, where the camera is offline."""
249-
with pytest.raises(Go2RtcClientError):
250-
await _test_probe(
251-
responses, rest_client, "probe_camera_offline.txt", 500, additional_params
252-
)

0 commit comments

Comments
 (0)