@@ -93,6 +93,7 @@ def seek(self, offset: int, whence: int) -> bytes:
93
93
decoder = Decoder (source )
94
94
assert isinstance (decoder .metadata , _core ._metadata .StreamMetadata )
95
95
96
+
96
97
@pytest .mark .parametrize ("Decoder" , (VideoDecoder , AudioDecoder ))
97
98
def test_create_fails (self , Decoder ):
98
99
with pytest .raises (TypeError , match = "Unknown source type" ):
@@ -126,6 +127,22 @@ def test_metadata(self, seek_mode):
126
127
assert decoder .metadata .height == 270
127
128
assert decoder .metadata .width == 480
128
129
130
+ def test_create_bytes_ownership (self ):
131
+ # Note that the bytes object we use to instantiate the decoder does not
132
+ # live past the VideoDecoder destructor. That is what we're testing:
133
+ # that the VideoDecoder takes ownership of the bytes. If it does not,
134
+ # then we will hit errors when we try to actually decode from the bytes
135
+ # later on. By the time we actually decode, the reference on the Python
136
+ # side has gone away, and if we don't have ownership on the C++ side, we
137
+ # will hit runtime errors or segfaults.
138
+ with open (NASA_VIDEO .path , "rb" ) as f :
139
+ decoder = VideoDecoder (f .read ())
140
+
141
+ assert decoder [0 ] is not None
142
+ assert decoder [len (decoder )// 2 ] is not None
143
+ assert decoder [- 1 ] is not None
144
+
145
+
129
146
def test_create_fails (self ):
130
147
with pytest .raises (ValueError , match = "Invalid seek mode" ):
131
148
VideoDecoder (NASA_VIDEO .path , seek_mode = "blah" )
0 commit comments