Skip to content

Commit

Permalink
[h264] do not use deprecated Packet.to_bytes method
Browse files Browse the repository at this point in the history
  • Loading branch information
jlaine committed Apr 6, 2022
1 parent 6a0654d commit 8b0a2ce
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/aiortc/codecs/h264.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def _encode_frame(

data_to_send = b""
for package in self.codec.encode(frame):
package_bytes = package.to_bytes()
package_bytes = bytes(package)
if self.codec_buffering:
# delay sending to ensure we accumulate all packages
# for a given PTS
Expand Down
2 changes: 1 addition & 1 deletion stubs/av/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Packet:
pts: int
time_base: Fraction
def __init__(self, data: bytes) -> None: ...
def to_bytes(self) -> bytes: ...
def __bytes__(self) -> bytes: ...

class AudioFormat:
@property
Expand Down
15 changes: 5 additions & 10 deletions tests/test_h264.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
from contextlib import redirect_stderr
from unittest import TestCase

from av import Packet

from aiortc.codecs import get_decoder, get_encoder, h264
from aiortc.codecs.h264 import H264Decoder, H264Encoder, H264PayloadDescriptor
from aiortc.jitterbuffer import JitterFrame
Expand All @@ -16,22 +18,15 @@
)


class DummyPacket:
def __init__(self, dts, pts):
self.dts = dts
self.pts = pts

def to_bytes(self):
return b""


class FragmentedCodecContext:
def __init__(self, orig):
self.__orig = orig

def encode(self, frame):
packages = self.__orig.encode(frame)
packages.append(DummyPacket(packages[0].dts, packages[0].pts))
dummy = Packet()
dummy.pts = packages[0].pts
packages.append(dummy)
return packages

def __getattr__(self, name):
Expand Down

0 comments on commit 8b0a2ce

Please sign in to comment.